|
@@ -5871,119 +5871,82 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
//多条件判断
|
|
|
if (f.contains("ifelseMulti")){
|
|
|
- int max = 0;
|
|
|
- do {
|
|
|
- // 修改正则表达式,使用非贪婪匹配来处理嵌套情况
|
|
|
- Matcher m = RegexUtils.matcher(FC_REG + "(ifelseMulti)\\(((?:[^()]++|\\([^()]*\\))*?)\\)", f);
|
|
|
- boolean found = false;
|
|
|
-
|
|
|
- while (m.find()) {
|
|
|
- found = true;
|
|
|
- String el = m.group();
|
|
|
-
|
|
|
- try {
|
|
|
- // 提取括号内的内容(去掉外层的ifelse())
|
|
|
- String content = el.replaceFirst("^" + FC_REG + "ifelseMulti\\(", "").replaceFirst("\\)$", "");
|
|
|
-
|
|
|
- // 解析参数,处理嵌套逗号(在括号内的逗号不应该作为分隔符)
|
|
|
- List<String> pa = parseParameters(content);
|
|
|
-
|
|
|
- if (pa.size() == 3) {
|
|
|
- Map<String, Object> currentMap = createCurrentMap(el, tec);
|
|
|
- //判断 为
|
|
|
- String falseStr = pa.get(2);;
|
|
|
- if(pa.get(2).contains("(")){
|
|
|
- pa.set(2,"-10086");
|
|
|
- }
|
|
|
- String string = pa.get(0) + "?" + pa.get(1) + ":" + pa.get(2);
|
|
|
- Expression parse = Expression.parse(string);
|
|
|
- Object data = parse.calculate(currentMap);
|
|
|
- //递归计算
|
|
|
- if(Objects.equals(String.valueOf(data),"-10086")){
|
|
|
- //进入递归算法
|
|
|
- data = multipleIfElse(falseStr,currentMap);
|
|
|
- }
|
|
|
- f = f.replace(el, putDataWithKey(data, tec));
|
|
|
- } else {
|
|
|
- f = f.replace(el, "参数格式错误");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- f = f.replace(el, "解析错误");
|
|
|
+ try {
|
|
|
+ // 提取括号内的内容(去掉外层的ifelse())
|
|
|
+ String content = f.replaceFirst("^" + FC_REG + "ifelseMulti\\(", "").replaceFirst("\\)$", "");
|
|
|
+
|
|
|
+ // 解析参数,处理嵌套逗号(在括号内的逗号不应该作为分隔符)
|
|
|
+ List<String> pa = parseParameters(content);
|
|
|
+
|
|
|
+ if (pa.size() == 3) {
|
|
|
+ Map<String, Object> currentMap = createCurrentMap(f, tec);
|
|
|
+ //判断 为
|
|
|
+ String falseStr = pa.get(2);;
|
|
|
+ if(pa.get(2).contains("(") && pa.get(2).contains(",") && pa.get(2).split(",").length == 3){
|
|
|
+ pa.set(2,"-10086");
|
|
|
}
|
|
|
+ String string = pa.get(0) + "?" + pa.get(1) + ":(" + pa.get(2) + ")";
|
|
|
+ Expression parse = Expression.parse(string);
|
|
|
+ Object data = parse.calculate(currentMap);
|
|
|
+ //递归计算
|
|
|
+ if(Objects.equals(String.valueOf(data),"-10086")){
|
|
|
+ //进入递归算法
|
|
|
+ data = multipleIfElse(falseStr,currentMap);
|
|
|
+ }
|
|
|
+ f = f.replace(f, putDataWithKey(data, tec));
|
|
|
+ } else {
|
|
|
+ f = f.replace(f, "参数格式错误");
|
|
|
}
|
|
|
-
|
|
|
- max++;
|
|
|
- // 如果没有找到匹配项,提前退出循环
|
|
|
- if (!found) {
|
|
|
- break;
|
|
|
- }
|
|
|
- } while (f.contains("ifelseMulti") && max < 20);
|
|
|
+ } catch (Exception e) {
|
|
|
+ f = f.replace(f, "解析错误");
|
|
|
+ }
|
|
|
}
|
|
|
// switch-case 选择公式
|
|
|
if (f.contains("switchCase")){
|
|
|
- int max = 0;
|
|
|
- do {
|
|
|
- // 修改正则表达式,使用非贪婪匹配来处理嵌套情况
|
|
|
- Matcher m = RegexUtils.matcher(FC_REG + "(switchCase)\\(((?:[^()]++|\\([^()]*\\))*?)\\)", f);
|
|
|
- boolean found = false;
|
|
|
+ try {
|
|
|
+ // 提取括号内的内容(去掉外层的ifelse())
|
|
|
+ String content = f.replaceFirst("^" + FC_REG + "switchCase\\(", "").replaceFirst("\\)$", "");
|
|
|
|
|
|
- while (m.find()) {
|
|
|
- found = true;
|
|
|
- String el = m.group();
|
|
|
+ String key = null;
|
|
|
+ String value = null;
|
|
|
|
|
|
- try {
|
|
|
- // 提取括号内的内容(去掉外层的ifelse())
|
|
|
- String content = el.replaceFirst("^" + FC_REG + "switchCase\\(", "").replaceFirst("\\)$", "");
|
|
|
+ Map<String, Object> currentMap = createCurrentMap(f, tec);
|
|
|
|
|
|
-
|
|
|
- //
|
|
|
- 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(",");
|
|
|
- if(ruleArray.length % 2 != 0){
|
|
|
- throw new ServiceException("数据格式错误");
|
|
|
- }
|
|
|
- List<String> list = Arrays.asList(ruleArray);
|
|
|
- //2条数据为一组
|
|
|
- List<List<String>> partition = Lists.partition(list, 2);
|
|
|
- for (List<String> strings : partition) {
|
|
|
- String s = strings.get(0);
|
|
|
- String s1 = strings.get(1);
|
|
|
- String[] action = s1.split("=");
|
|
|
- if ("else".equals(s)) {
|
|
|
- key = action[0];
|
|
|
- value = action[1];
|
|
|
- break;
|
|
|
- }
|
|
|
- Expression parse = Expression.parse(s + "?1:0");
|
|
|
- Object data = parse.calculate(currentMap);
|
|
|
- if(Objects.equals("1",String.valueOf(data))){
|
|
|
- key = action[0];
|
|
|
- value = action[1];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- f = "";
|
|
|
- if(key != null && value != null){
|
|
|
- /*数据回写*/
|
|
|
- write(key,value,tec);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- f = f.replace(el, "解析错误");
|
|
|
+ //根据分号分组 数据样例:a=x -> b=0; a=y -> c=1; else -> d=2
|
|
|
+ String[] ruleArray = content.trim().split(",");
|
|
|
+ if(ruleArray.length % 2 != 0){
|
|
|
+ throw new ServiceException("数据格式错误");
|
|
|
+ }
|
|
|
+ List<String> list = Arrays.asList(ruleArray);
|
|
|
+ //2条数据为一组
|
|
|
+ List<List<String>> partition = Lists.partition(list, 2);
|
|
|
+ for (List<String> strings : partition) {
|
|
|
+ String s = strings.get(0);
|
|
|
+ String s1 = strings.get(1);
|
|
|
+ String[] action = s1.split("=");
|
|
|
+ if ("else".equals(s)) {
|
|
|
+ key = action[0];
|
|
|
+ value = action[1];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Expression parse = Expression.parse(s + "?1:0");
|
|
|
+ Object data = parse.calculate(currentMap);
|
|
|
+ if(Objects.equals("1",String.valueOf(data))){
|
|
|
+ key = action[0];
|
|
|
+ value = action[1];
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- max++;
|
|
|
- // 如果没有找到匹配项,提前退出循环
|
|
|
- if (!found) {
|
|
|
- break;
|
|
|
+ f = "";
|
|
|
+ if(key != null && value != null){
|
|
|
+ /*数据回写*/
|
|
|
+ write(key,value,tec);
|
|
|
}
|
|
|
- } while (f.contains("switchCase") && max < 20);
|
|
|
+ } catch (Exception e) {
|
|
|
+ f = f.replace(f, "解析错误");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
if (f.contains("avg4segment")) {
|
|
|
Matcher m = RegexUtils.matcher(FC_REG + "(avg4segment)\\(([^)]+)\\)", f);
|
|
|
while (m.find()) {
|
|
@@ -6051,10 +6014,10 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if (pa.size() == 3) {
|
|
|
String s = pa.get(2);;
|
|
|
//
|
|
|
- if(pa.get(2).contains("(")){
|
|
|
+ if(pa.get(2).contains("(") && pa.get(2).contains(",") && pa.get(2).split(",").length == 3){
|
|
|
pa.set(2,"-10086");
|
|
|
}
|
|
|
- String string = pa.get(0) + "?" + pa.get(1) + ":" + pa.get(2);
|
|
|
+ String string = pa.get(0) + "?" + pa.get(1) + ":(" + pa.get(2) + ")";
|
|
|
Expression parse = Expression.parse(string);
|
|
|
Object data = parse.calculate(currentMap);
|
|
|
//递归计算
|