|
@@ -5710,6 +5710,63 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
} while (f.contains("ifelseMulti") && max < 20);
|
|
|
}
|
|
|
+ // switch-case 选择公式
|
|
|
+ if (f.contains("switchCase")){
|
|
|
+ int max = 0;
|
|
|
+ do {
|
|
|
+ // 修改正则表达式,使用非贪婪匹配来处理嵌套情况
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG + "(switchCase)\\(((?:[^()]++|\\([^()]*\\))*?)\\)", f);
|
|
|
+ boolean found = false;
|
|
|
+
|
|
|
+ while (m.find()) {
|
|
|
+ found = true;
|
|
|
+ String el = m.group();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 提取括号内的内容(去掉外层的ifelse())
|
|
|
+ String content = el.replaceFirst("^" + FC_REG + "ifelseMulti\\(", "").replaceFirst("\\)$", "");
|
|
|
+
|
|
|
+
|
|
|
+ //
|
|
|
+ String key = null;
|
|
|
+ String value = null;
|
|
|
+
|
|
|
+ Map<String, Object> currentMap = createCurrentMap(el, tec);
|
|
|
+
|
|
|
+ //根据分号分组 数据样例:a=x -> b=0; a=y -> c=1; else -> d=2
|
|
|
+ String[] ruleArray = content.trim().split(";");
|
|
|
+ for (String rule : ruleArray) {
|
|
|
+ if (rule.startsWith("else")) {
|
|
|
+ String[] parts = rule.split(" -> ");
|
|
|
+ String[] action = parts[1].split("=");
|
|
|
+ key = action[0];
|
|
|
+ value = action[1];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String[] parts = rule.split("->");
|
|
|
+ String[] action = parts[1].split("=");
|
|
|
+ Expression parse = Expression.parse(parts[0] + "?1:0");
|
|
|
+ Object data = parse.calculate(currentMap);
|
|
|
+ if(Objects.equals("1",String.valueOf(data))){
|
|
|
+ key = action[0];
|
|
|
+ value = action[1];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ f = f.replace(el, putDataWithKey(value, tec));
|
|
|
+ } catch (Exception e) {
|
|
|
+ f = f.replace(el, "解析错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ max++;
|
|
|
+ // 如果没有找到匹配项,提前退出循环
|
|
|
+ if (!found) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } while (f.contains("switchCase") && max < 20);
|
|
|
+ }
|
|
|
if (f.contains("avg4segment")) {
|
|
|
Matcher m = RegexUtils.matcher(FC_REG + "(avg4segment)\\(([^)]+)\\)", f);
|
|
|
while (m.find()) {
|