fix(admin): 修复零值字段无法保存的问题
- 用户允许分组:前端发送空数组而非 null 表示"允许全部" - 账户代理:前端发送 0 而非 null 表示"无代理" - 后端 UpdateAccount/BulkUpdate 正确处理 ProxyID=0 为清除代理
This commit is contained in:
@@ -773,9 +773,14 @@ func (r *accountRepository) BulkUpdate(ctx context.Context, ids []int64, updates
|
||||
idx++
|
||||
}
|
||||
if updates.ProxyID != nil {
|
||||
setClauses = append(setClauses, "proxy_id = $"+itoa(idx))
|
||||
args = append(args, *updates.ProxyID)
|
||||
idx++
|
||||
// 0 表示清除代理(前端发送 0 而不是 null 来表达清除意图)
|
||||
if *updates.ProxyID == 0 {
|
||||
setClauses = append(setClauses, "proxy_id = NULL")
|
||||
} else {
|
||||
setClauses = append(setClauses, "proxy_id = $"+itoa(idx))
|
||||
args = append(args, *updates.ProxyID)
|
||||
idx++
|
||||
}
|
||||
}
|
||||
if updates.Concurrency != nil {
|
||||
setClauses = append(setClauses, "concurrency = $"+itoa(idx))
|
||||
|
||||
@@ -702,7 +702,12 @@ func (s *adminServiceImpl) UpdateAccount(ctx context.Context, id int64, input *U
|
||||
account.Extra = input.Extra
|
||||
}
|
||||
if input.ProxyID != nil {
|
||||
account.ProxyID = input.ProxyID
|
||||
// 0 表示清除代理(前端发送 0 而不是 null 来表达清除意图)
|
||||
if *input.ProxyID == 0 {
|
||||
account.ProxyID = nil
|
||||
} else {
|
||||
account.ProxyID = input.ProxyID
|
||||
}
|
||||
account.Proxy = nil // 清除关联对象,防止 GORM Save 时根据 Proxy.ID 覆盖 ProxyID
|
||||
}
|
||||
// 只在指针非 nil 时更新 Concurrency(支持设置为 0)
|
||||
|
||||
Reference in New Issue
Block a user