66 lines
2.8 KiB
Go
66 lines
2.8 KiB
Go
package models
|
||
|
||
import (
|
||
"sync"
|
||
"time"
|
||
)
|
||
|
||
type SystemTenantUser struct {
|
||
ID uint64 `orm:"column(id);pk;auto" json:"id"`
|
||
Tid uint64 `orm:"column(tid)" json:"tid"`
|
||
Uid uint64 `orm:"column(uid)" json:"uid"`
|
||
GroupID uint64 `orm:"column(group_id);default(0)" json:"group_id"` // 角色ID:关联 yz_system_admin_role(id, cid=2);0=未分配(视为全权限)
|
||
Account *string `orm:"column(account);size(64);null" json:"account"`
|
||
Name *string `orm:"column(name);size(64);null" json:"name"`
|
||
Phone *string `orm:"column(phone);size(20);null" json:"phone"`
|
||
Email *string `orm:"column(email);size(128);null" json:"email"`
|
||
Sex uint8 `orm:"column(sex);default(0)" json:"sex"`
|
||
Birth *string `orm:"column(birth);size(20);null" json:"birth"`
|
||
Password *string `orm:"column(password);size(255);null" json:"password"`
|
||
IsDefault int8 `orm:"column(is_default);default(0)" json:"is_default"`
|
||
Status int8 `orm:"column(status);default(1)" json:"status"`
|
||
// OrgID 所属组织(部门),关联 yz_backend_organization(id);0 表示未分配。
|
||
// 用于文档私密共享等需要按部门判定可见性的场景。
|
||
OrgID uint64 `orm:"column(org_id);default(0)" json:"org_id"`
|
||
Remark *string `orm:"column(remark);size(255);null" json:"remark"`
|
||
CreateTime time.Time `orm:"column(create_time);auto_now_add;type(datetime)" json:"create_time"`
|
||
UpdateTime *time.Time `orm:"column(update_time);auto_now;type(datetime);null" json:"update_time"`
|
||
DeleteTime *time.Time `orm:"column(delete_time);type(datetime);null" json:"delete_time"`
|
||
}
|
||
|
||
func (m *SystemTenantUser) TableName() string {
|
||
return "yz_system_tenant_user"
|
||
}
|
||
|
||
var tenantUserGroupColOnce sync.Once
|
||
|
||
// EnsureTenantUserGroupColumn 为租户用户表补齐 group_id(角色)列。
|
||
// 历史库可能早于"用户-角色"特性建表,字段已存在时 MySQL 报 duplicate column,统一忽略。
|
||
func EnsureTenantUserGroupColumn() {
|
||
if Orm == nil {
|
||
return
|
||
}
|
||
tenantUserGroupColOnce.Do(func() {
|
||
_, _ = Orm.Raw(`
|
||
ALTER TABLE yz_system_tenant_user
|
||
ADD COLUMN group_id bigint unsigned NOT NULL DEFAULT 0 COMMENT '角色ID 关联 yz_system_admin_role(cid=2)'
|
||
`).Exec()
|
||
})
|
||
}
|
||
|
||
var tenantUserOrgColOnce sync.Once
|
||
|
||
// EnsureTenantUserOrgColumn 为租户用户表补齐 org_id(所属部门)列。
|
||
// 与 group_id 同样的幂等策略:字段已存在时 MySQL 报 duplicate column,统一忽略。
|
||
func EnsureTenantUserOrgColumn() {
|
||
if Orm == nil {
|
||
return
|
||
}
|
||
tenantUserOrgColOnce.Do(func() {
|
||
_, _ = Orm.Raw(`
|
||
ALTER TABLE yz_system_tenant_user
|
||
ADD COLUMN org_id bigint unsigned NOT NULL DEFAULT 0 COMMENT '所属组织ID 关联 yz_backend_organization(id),0-未分配'
|
||
`).Exec()
|
||
})
|
||
}
|