修复个人中心问题
This commit is contained in:
@@ -233,7 +233,14 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
|
||||
}
|
||||
p.Password = &hashed
|
||||
if p.Uid == 0 {
|
||||
uid, err := generateTenantUID(p.Tid)
|
||||
uid, err := ensureTenantUIDForNewUser(
|
||||
p.Tid,
|
||||
strOrEmpty(p.Account),
|
||||
strOrEmpty(p.Name),
|
||||
strOrEmpty(p.Phone),
|
||||
strOrEmpty(p.Email),
|
||||
strOrEmpty(p.Password),
|
||||
)
|
||||
if err != nil {
|
||||
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "生成租户用户ID失败"}
|
||||
_ = c.ServeJSON()
|
||||
@@ -417,6 +424,41 @@ func (c *PlatformTenantUserController) parsePayload() (tenantUserPayload, bool)
|
||||
return p, true
|
||||
}
|
||||
|
||||
// ensureTenantUIDForNewUser 新增租户用户时确定 uid。
|
||||
//
|
||||
// 统一走 uid:优先取认证中心 identity_id —— 业务表(文件/客户/合同/日程…)
|
||||
// 已在 uid 全量迁移中统一成 identity_id,老表 uid 与它一致,业务侧就无需任何换算。
|
||||
// 认证中心不可用时退回随机 uid(generateTenantUID),保证新增流程不中断。
|
||||
func ensureTenantUIDForNewUser(tid uint64, account, name, phone, email, passwordHash string) (uint64, error) {
|
||||
if tid == 0 {
|
||||
return 0, errors.New("tid 不能为空")
|
||||
}
|
||||
id, err := authsvc.SyncTenantUserAndGetIdentity(authsvc.SyncTenantUserInput{
|
||||
Tid: tid,
|
||||
Account: strings.TrimSpace(account),
|
||||
Name: strings.TrimSpace(name),
|
||||
Phone: strings.TrimSpace(phone),
|
||||
Email: strings.TrimSpace(email),
|
||||
PasswordHash: strings.TrimSpace(passwordHash),
|
||||
Status: 1,
|
||||
})
|
||||
if err == nil && id > 0 {
|
||||
return id, nil
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("[auth] 预建身份失败,退回随机 uid: %v", err)
|
||||
}
|
||||
return generateTenantUID(tid)
|
||||
}
|
||||
|
||||
// strOrEmpty 取指针字符串的值,nil 时返回空串
|
||||
func strOrEmpty(p *string) string {
|
||||
if p == nil {
|
||||
return ""
|
||||
}
|
||||
return *p
|
||||
}
|
||||
|
||||
func generateTenantUID(tid uint64) (uint64, error) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
for i := 0; i < 8; i++ {
|
||||
|
||||
Reference in New Issue
Block a user