更新各项内容
This commit is contained in:
@@ -132,4 +132,50 @@ func Init(_ string) {
|
||||
EnsureAdminRoleTenantColumn()
|
||||
EnsureAdminRoleCustomColumn()
|
||||
EnsureTenantUserOrgColumn()
|
||||
EnsureCrmCustomerPoolColumns()
|
||||
EnsureCrmCreateUserColumn()
|
||||
}
|
||||
|
||||
|
||||
// EnsureCrmCreateUserColumn 补齐客户/供应商的创建人字段(用于删除权限校验)。
|
||||
// 同样兼容历史表名差异,表不存在或列已存在时忽略错误。
|
||||
func EnsureCrmCreateUserColumn() {
|
||||
tables := []string{
|
||||
new(TenantCrmCustomer).TableName(), "yz_tenant_crm_customer",
|
||||
new(TenantCrmSupplier).TableName(), "yz_tenant_crm_supplier",
|
||||
}
|
||||
for _, table := range tables {
|
||||
sql := "ALTER TABLE " + table +
|
||||
" ADD COLUMN create_user_id varchar(64) NOT NULL DEFAULT '' COMMENT '创建人用户ID,用于删除权限校验'"
|
||||
if _, err := Orm.Raw(sql).Exec(); err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureCrmCustomerPoolColumns 补齐客户公海相关字段。
|
||||
// 兼容历史表名差异:模型 TableName 为 yz_backend_erp_customer,初始化 SQL 中为 yz_tenant_crm_customer,
|
||||
// 对两个候选表名都执行 ALTER(表不存在或列已存在时忽略错误)。
|
||||
func EnsureCrmCustomerPoolColumns() {
|
||||
candidates := []string{
|
||||
new(TenantCrmCustomer).TableName(),
|
||||
"yz_tenant_crm_customer",
|
||||
}
|
||||
cols := []string{
|
||||
"in_pool tinyint NOT NULL DEFAULT 0 COMMENT '是否在公海:0-否 1-是'",
|
||||
"owner_user_id varchar(64) NOT NULL DEFAULT '' COMMENT '负责人ID,公海中为空'",
|
||||
"owner_user_name varchar(128) NOT NULL DEFAULT '' COMMENT '负责人姓名'",
|
||||
"last_owner_name varchar(128) NOT NULL DEFAULT '' COMMENT '移入公海前的原负责人'",
|
||||
"pool_in_time datetime DEFAULT NULL COMMENT '进入公海时间'",
|
||||
"pool_reason varchar(200) NOT NULL DEFAULT '' COMMENT '移入公海原因'",
|
||||
}
|
||||
for _, table := range candidates {
|
||||
for _, col := range cols {
|
||||
sql := fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s", table, col)
|
||||
if _, err := Orm.Raw(sql).Exec(); err != nil {
|
||||
// 列已存在或表不存在时忽略
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user