This commit is contained in:
张成
2025-12-24 22:47:18 +08:00
parent 8f4e2df19b
commit 5acf0a52cc
2 changed files with 123 additions and 22 deletions

View File

@@ -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