fix: 修复租户ID和创建者覆盖逻辑

This commit is contained in:
2026-04-22 09:43:18 +08:00
parent 2d2a43a4f4
commit 38f5d74f4a

View File

@@ -179,19 +179,23 @@ func insertHook(ctx context.Context, in *gdb.HookInsertInput) (result sql.Result
in.Data[i]["id"] = node.Generate().Int64() in.Data[i]["id"] = node.Generate().Int64()
} }
if _, ok := in.Data[i]["tenant_id"]; ok { if _, ok := in.Data[i]["tenant_id"]; ok {
if g.IsEmpty(in.Data[i]["tenant_id"]) {
if !g.IsEmpty(userInfo.TenantId) { if !g.IsEmpty(userInfo.TenantId) {
in.Data[i]["tenant_id"] = userInfo.TenantId in.Data[i]["tenant_id"] = userInfo.TenantId
} else { } else {
return nil, fmt.Errorf("tenantId cannot be empty") return nil, fmt.Errorf("tenantId cannot be empty")
} }
} }
}
if _, ok := in.Data[i]["creator"]; ok { if _, ok := in.Data[i]["creator"]; ok {
if g.IsEmpty(in.Data[i]["tenant_id"]) {
if !g.IsEmpty(userInfo.UserName) { if !g.IsEmpty(userInfo.UserName) {
in.Data[i]["creator"] = userInfo.UserName in.Data[i]["creator"] = userInfo.UserName
} else { } else {
return nil, fmt.Errorf("user info cannot be empty") return nil, fmt.Errorf("user info cannot be empty")
} }
} }
}
if _, ok := in.Data[i]["updater"]; ok { if _, ok := in.Data[i]["updater"]; ok {
if !g.IsEmpty(userInfo.UserName) { if !g.IsEmpty(userInfo.UserName) {
in.Data[i]["updater"] = userInfo.UserName in.Data[i]["updater"] = userInfo.UserName