@steedos-labs/plugin-workflow 3.0.49 → 3.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -96,6 +96,33 @@ function todayISODate() {
|
|
|
96
96
|
|
|
97
97
|
// ─── 检测规则 ─────────────────────────────────────────────────────────────────
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* 从原始公式中提取聚合函数引用的字段名列表。
|
|
101
|
+
* 支持所有变体:sum({code}), sum{code}, sum({code}), sum{(code)}
|
|
102
|
+
* @param {string} formula 原始公式文本
|
|
103
|
+
* @returns {string[]} 去重的字段名数组
|
|
104
|
+
*/
|
|
105
|
+
function extractAggregationFieldRefs(formula) {
|
|
106
|
+
const fieldNames = new Set();
|
|
107
|
+
const aggFuncs = 'sum|average|count|max|min|numToRMB';
|
|
108
|
+
|
|
109
|
+
// Standard: func({code})
|
|
110
|
+
const p1 = new RegExp(`(?:${aggFuncs})\\(\\{([^}]+)\\}\\)`, 'gi');
|
|
111
|
+
// Fullwidth: func({code})
|
|
112
|
+
const p2 = new RegExp(`(?:${aggFuncs})(\\{([^}]+)\\})`, 'gi');
|
|
113
|
+
// Missing parens: func{code} or func{(code)}
|
|
114
|
+
const p3 = new RegExp(`(?:${aggFuncs})\\{\\(?([^})]+?)\\)?\\}`, 'gi');
|
|
115
|
+
|
|
116
|
+
for (const pattern of [p1, p2, p3]) {
|
|
117
|
+
let m;
|
|
118
|
+
while ((m = pattern.exec(formula)) !== null) {
|
|
119
|
+
if (m[1]) fieldNames.add(m[1].trim());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return [...fieldNames];
|
|
124
|
+
}
|
|
125
|
+
|
|
99
126
|
/**
|
|
100
127
|
* 对单个公式字段执行所有检测规则,返回 issues 数组(可能为空)。
|
|
101
128
|
*
|
|
@@ -186,6 +213,27 @@ function checkFormula({ formula, tableFieldMap, formId, formName, formVersionTyp
|
|
|
186
213
|
siblingFields: siblingCodes,
|
|
187
214
|
});
|
|
188
215
|
}
|
|
216
|
+
|
|
217
|
+
// E5: 聚合函数引用子表字段但转换结果不含对应 ARRAYMAP(子表识别失败)
|
|
218
|
+
if (tableFieldMap && Object.keys(tableFieldMap).length > 0) {
|
|
219
|
+
const aggFieldNames = extractAggregationFieldRefs(formula);
|
|
220
|
+
for (const refName of aggFieldNames) {
|
|
221
|
+
const tableName = tableFieldMap[refName];
|
|
222
|
+
if (tableName) {
|
|
223
|
+
const safeTableCode = getSafeCode(tableName);
|
|
224
|
+
if (!convertedResult.includes(`ARRAYMAP(${safeTableCode}`)) {
|
|
225
|
+
issues.push({
|
|
226
|
+
level: 'ERROR',
|
|
227
|
+
ruleId: 'E5',
|
|
228
|
+
...baseInfo,
|
|
229
|
+
convertedResult,
|
|
230
|
+
errorDetail: `聚合函数引用子表字段「${refName}」(所属子表「${tableName}」),但转换结果不含 ARRAYMAP(${safeTableCode}...),子表识别失败`,
|
|
231
|
+
siblingFields: siblingCodes,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
189
237
|
}
|
|
190
238
|
|
|
191
239
|
// W1: 除零风险(含除法且除数是字段引用)
|