1
This commit is contained in:
@@ -208,9 +208,55 @@ class PlaAccountService {
|
||||
}
|
||||
});
|
||||
|
||||
// 深度合并 JSON 配置字段(deliver_config、chat_strategy、active_actions)
|
||||
const jsonConfigFields = ['deliver_config', 'chat_strategy', 'active_actions'];
|
||||
jsonConfigFields.forEach(field => {
|
||||
if (processedData[field] !== undefined && processedData[field] !== null) {
|
||||
// 获取原有配置
|
||||
const originalConfig = account[field] || {};
|
||||
const newConfig = processedData[field];
|
||||
|
||||
// 深度合并配置(只覆盖传入的字段,保留原有的其他字段)
|
||||
if (typeof newConfig === 'object' && !Array.isArray(newConfig)) {
|
||||
// 对于对象类型,深度合并
|
||||
processedData[field] = this.deepMerge(originalConfig, newConfig);
|
||||
} else {
|
||||
// 对于非对象类型(如 null、数组等),直接使用新值
|
||||
processedData[field] = newConfig;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await pla_account.update(processedData, { where: { id } });
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度合并对象(只合并一层,用于 JSON 配置字段)
|
||||
* @param {Object} target - 目标对象(原有配置)
|
||||
* @param {Object} source - 源对象(新配置)
|
||||
* @returns {Object} 合并后的对象
|
||||
*/
|
||||
deepMerge(target, source) {
|
||||
const result = { ...target };
|
||||
|
||||
// 遍历源对象的所有键
|
||||
Object.keys(source).forEach(key => {
|
||||
const sourceValue = source[key];
|
||||
const targetValue = target[key];
|
||||
|
||||
// 如果源值是对象且目标值也是对象,递归合并
|
||||
if (sourceValue && typeof sourceValue === 'object' && !Array.isArray(sourceValue) &&
|
||||
targetValue && typeof targetValue === 'object' && !Array.isArray(targetValue)) {
|
||||
result[key] = this.deepMerge(targetValue, sourceValue);
|
||||
} else {
|
||||
// 否则直接覆盖(包括 null、undefined、数组等)
|
||||
result[key] = sourceValue;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除账号(软删除)
|
||||
* @param {number} id - 账号ID
|
||||
|
||||
Reference in New Issue
Block a user