feat: 增加transformRecognizeNodeData
This commit is contained in:
parent
998d7d3826
commit
6cefb1a636
@ -367,4 +367,72 @@ export const transformSdAgentNodeData = (source) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const transformRecognizeNodeData = (source) => {
|
||||||
|
// 初始化结果对象
|
||||||
|
const result = {
|
||||||
|
nodeParams: [],
|
||||||
|
alarmRules: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// 遍历每一个顶级节点
|
||||||
|
source.forEach(item => {
|
||||||
|
const { name, children } = item;
|
||||||
|
if (!name) return; // 过滤无name的无效节点
|
||||||
|
|
||||||
|
// 处理普通节点(config/headers/params):直接取 children 数组
|
||||||
|
if (name !== 'alarmRules') {
|
||||||
|
result['nodeParams'].push(item);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name === 'alarmRules') {
|
||||||
|
if (Array.isArray(item.input)) {
|
||||||
|
result[name] = item.input;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 兼容旧数据:旧结构把 level/operator/threshold/message
|
||||||
|
// 作为 alarmRules.children 中的字段描述保存。
|
||||||
|
const legacyRule = Object.fromEntries(
|
||||||
|
(children || [])
|
||||||
|
.filter(child => ['level', 'operator', 'threshold', 'message'].includes(child.name))
|
||||||
|
.map(child => [child.name, child.input])
|
||||||
|
);
|
||||||
|
result[name] = Object.keys(legacyRule).length ? [legacyRule] : [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 专门处理 tts 节点(特殊结构)
|
||||||
|
// if (name === 'alarmRules') {
|
||||||
|
// const bodyObj = {
|
||||||
|
// level: '',
|
||||||
|
// operator: '',
|
||||||
|
// threshold: '',
|
||||||
|
// message: ''
|
||||||
|
// };
|
||||||
|
|
||||||
|
// // 遍历body的子项,赋值到对应字段
|
||||||
|
// children?.forEach(child => {
|
||||||
|
// const childName = child.name;
|
||||||
|
// if (childName === 'level') {
|
||||||
|
// bodyObj.level = child.input;
|
||||||
|
// }
|
||||||
|
// if (childName === 'operator') {
|
||||||
|
// bodyObj.operator = child.input;
|
||||||
|
// }
|
||||||
|
// if (childName === 'threshold') {
|
||||||
|
// bodyObj.threshold = child.input;
|
||||||
|
// }
|
||||||
|
// if (childName === 'message') {
|
||||||
|
// bodyObj.message = child.input;
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// result.alarmRules = bodyObj;
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user