类目更新接口修改,三个平台同时更新-->只修改传入的平台的类目

This commit is contained in:
97694731 2026-05-08 16:49:19 +08:00
parent ce1261dcbf
commit d52c24edf5

View File

@ -527,13 +527,30 @@ func (svc *BookService) UpdateBookCatIdByISBNHandler(request *request.BookUpdate
return nil, fmt.Errorf("没有有效的更新字段") return nil, fmt.Errorf("没有有效的更新字段")
} }
// 构建更新脚本,只更新传入的字段,保留现有字段
var scriptParts []string
params := make(map[string]interface{})
// 转换为 map 以便访问
newCatId, ok := catIdValue.(map[string]interface{})
if ok {
for key, value := range newCatId {
scriptParts = append(scriptParts, fmt.Sprintf("ctx._source.cat_id.%s = params.%s;", key, key))
params[key] = value
}
}
if len(scriptParts) == 0 {
return nil, fmt.Errorf("没有有效的 cat_id 字段")
}
script := strings.Join(scriptParts, " ")
body := map[string]interface{}{ body := map[string]interface{}{
"script": map[string]interface{}{ "script": map[string]interface{}{
"source": "ctx._source.cat_id = params.cat_id;", "source": script,
"lang": "painless", "lang": "painless",
"params": map[string]interface{}{ "params": params,
"cat_id": catIdValue,
},
}, },
"query": map[string]interface{}{ "query": map[string]interface{}{
"term": map[string]interface{}{ "term": map[string]interface{}{