feat: 添加租户ID字段并重构文件上传逻辑

This commit is contained in:
2026-03-24 16:17:22 +08:00
parent bb88eb1e47
commit 3cf301275f
5 changed files with 67 additions and 43 deletions

View File

@@ -173,12 +173,25 @@ func insertHook(ctx context.Context, in *gdb.HookInsertInput) (result sql.Result
if _, ok := in.Data[i]["id"]; ok {
in.Data[i]["id"] = node.Generate().Int64()
}
if !g.IsEmpty(userInfo.UserName) {
if _, ok := in.Data[i]["creator"]; ok {
in.Data[i]["creator"] = userInfo.UserName
if _, ok := in.Data[i]["tenant_id"]; ok {
if !g.IsEmpty(userInfo.TenantId) {
in.Data[i]["tenant_id"] = userInfo.TenantId
} else {
return nil, fmt.Errorf("tenantId cannot be empty")
}
if _, ok := in.Data[i]["updater"]; ok {
}
if _, ok := in.Data[i]["creator"]; ok {
if !g.IsEmpty(userInfo.UserName) {
in.Data[i]["creator"] = userInfo.UserName
} else {
return nil, fmt.Errorf("user info cannot be empty")
}
}
if _, ok := in.Data[i]["updater"]; ok {
if !g.IsEmpty(userInfo.UserName) {
in.Data[i]["updater"] = userInfo.UserName
} else {
return nil, fmt.Errorf("user info cannot be empty")
}
}
}
@@ -207,16 +220,22 @@ func updateHook(ctx context.Context, in *gdb.HookUpdateInput) (result sql.Result
switch data := in.Data.(type) {
case gdb.Map:
if !g.IsEmpty(userInfo.UserName) {
if _, ok := data["updater"]; ok {
if _, ok := data["updater"]; ok {
if !g.IsEmpty(userInfo.UserName) {
data["updater"] = userInfo.UserName
} else {
return nil, fmt.Errorf("user info cannot be empty")
}
}
case gdb.List:
for i := range data {
if !g.IsEmpty(userInfo.UserName) {
if _, ok := data[i]["updater"]; ok {
data[i]["updater"] = userInfo.UserName
if !g.IsEmpty(userInfo.UserName) {
data[i]["updater"] = userInfo.UserName
} else {
return nil, fmt.Errorf("user info cannot be empty")
}
}
}
}