|
@@ -4951,140 +4951,140 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
if (f.contains(".ifelse")) {
|
|
|
- int max = 0;
|
|
|
- do {
|
|
|
- Matcher m = RegexUtils.matcher(FC_REG + "(ifelse)\\(([^)]+)\\)", f);
|
|
|
- while (m.find()) {
|
|
|
- String el = m.group();
|
|
|
- String pstr = el.replaceAll("^" + FC_REG + "ifelse\\(", "").replaceAll("\\)$", "");
|
|
|
- String[] pa = pstr.split(",");
|
|
|
- if (pa.length == 3) {
|
|
|
- Object data = Expression.parse(pa[0] + "?" + pa[1] + ":" + pa[2]).calculate(createCurrentMap(el, tec));
|
|
|
- f = f.replace(el, putDataWithKey(data, tec));
|
|
|
- } else {
|
|
|
- f = f.replace(el, "参数格式错误");
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- max++;
|
|
|
- } while (f.contains("ifelse") && max < 20);
|
|
|
- }
|
|
|
-
|
|
|
- //试验-判断
|
|
|
- if (f.contains(".syifelse")) {
|
|
|
- int max = 0;
|
|
|
- Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
|
|
|
- do {
|
|
|
- Matcher m = RegexUtils.matcher(FC_REG + "(syifelse)\\(([^)]+)\\)", f);
|
|
|
- while (m.find()) {
|
|
|
- String el = m.group();
|
|
|
- String pstr = el.replaceAll("^" + FC_REG + "syifelse\\(", "").replaceAll("\\)$", "");
|
|
|
- String[] pa = pstr.split(",");
|
|
|
- if (pa.length == 3) {
|
|
|
- String s2 = pa[0];
|
|
|
- String[] split = pa[0].split("&");
|
|
|
- //处理位置
|
|
|
- //试验-处理数据
|
|
|
- Map<String, Object> currentMap = createCurrentMap(el, tec);
|
|
|
- Map<String,List<String>> map = (HashMap<String, List<String>>) currentMap.get("E");
|
|
|
-
|
|
|
- //匹配成功的计数
|
|
|
- Integer count = 0;
|
|
|
- for (String s : split) {
|
|
|
- String[] split1 = s.split("\\|");
|
|
|
- String s0 = split1[0].replaceAll("E\\[", "").replaceAll("'", "").replaceAll("]", "");
|
|
|
- String s1 = split1[1].replaceAll("E\\[", "").replaceAll("'", "").replaceAll("]", "");
|
|
|
- List<String> list1 = map.get(s0);
|
|
|
- List<String> list2 = map.get(s1);
|
|
|
-
|
|
|
- if(CollectionUtils.isEmpty(list1) || CollectionUtils.isEmpty(list2)){
|
|
|
- f = f.replace(el, "缺少数据无法匹配");
|
|
|
- break;
|
|
|
- }
|
|
|
- //带后缀的数据去掉留纯数据
|
|
|
- String strings1 = extractPureNumbers(list1.get(0));
|
|
|
- String strings2 = extractPureNumbers(list2.get(0));
|
|
|
+ //试验-判断
|
|
|
+ if(f.contains("|")){
|
|
|
+ int max = 0;
|
|
|
+ Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");
|
|
|
+ do {
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG + "(ifelse)\\(([^)]+)\\)", f);
|
|
|
+ while (m.find()) {
|
|
|
+ String el = m.group();
|
|
|
+ String pstr = el.replaceAll("^" + FC_REG + "ifelse\\(", "").replaceAll("\\)$", "");
|
|
|
+ String[] pa = pstr.split(",");
|
|
|
+ if (pa.length == 3) {
|
|
|
+ String s2 = pa[0];
|
|
|
+ String[] split = pa[0].split("&");
|
|
|
+ //处理位置
|
|
|
+ //试验-处理数据
|
|
|
+ Map<String, Object> currentMap = createCurrentMap(el, tec);
|
|
|
+ Map<String,List<String>> map = (HashMap<String, List<String>>) currentMap.get("E");
|
|
|
+
|
|
|
+ //匹配成功的计数
|
|
|
+ Integer count = 0;
|
|
|
+ for (String s : split) {
|
|
|
+ String[] split1 = s.split("\\|");
|
|
|
+ String s0 = split1[0].replaceAll("E\\[", "").replaceAll("'", "").replaceAll("]", "");
|
|
|
+ String s1 = split1[1].replaceAll("E\\[", "").replaceAll("'", "").replaceAll("]", "");
|
|
|
+ List<String> list1 = map.get(s0);
|
|
|
+ List<String> list2 = map.get(s1);
|
|
|
+
|
|
|
+ if(CollectionUtils.isEmpty(list1) || CollectionUtils.isEmpty(list2)){
|
|
|
+ f = f.replace(el, "缺少数据无法匹配");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //带后缀的数据去掉留纯数据
|
|
|
+ String strings1 = extractPureNumbers(list1.get(0));
|
|
|
+ String strings2 = extractPureNumbers(list2.get(0));
|
|
|
|
|
|
|
|
|
- String s3 = list1.get(0);
|
|
|
- String s4 = list2.get(0);
|
|
|
- if(StringUtils.isNotEmpty(strings1)){
|
|
|
- s3 = strings1;
|
|
|
- }
|
|
|
- if(StringUtils.isNotEmpty(strings2)){
|
|
|
- s4 = strings2;
|
|
|
- }
|
|
|
+ String s3 = list1.get(0);
|
|
|
+ String s4 = list2.get(0);
|
|
|
+ if(StringUtils.isNotEmpty(strings1)){
|
|
|
+ s3 = strings1;
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotEmpty(strings2)){
|
|
|
+ s4 = strings2;
|
|
|
+ }
|
|
|
|
|
|
- //比较符
|
|
|
- String operator = "";
|
|
|
- //公式组装
|
|
|
- String formulaData = "";
|
|
|
- //不是纯数字
|
|
|
- if(!pattern.matcher(s3).matches() && pattern.matcher(s4).matches()){
|
|
|
- //如果有特殊后缀,把值替换为纯数字
|
|
|
- list2.set(0,s4);
|
|
|
- if(s3.contains(" ")){
|
|
|
- String[] split2 = s3.split(" ");
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- for (String string : split2) {
|
|
|
+ //比较符
|
|
|
+ String operator = "";
|
|
|
+ //公式组装
|
|
|
+ String formulaData = "";
|
|
|
+ //不是纯数字
|
|
|
+ if(!pattern.matcher(s3).matches() && pattern.matcher(s4).matches()){
|
|
|
+ //如果有特殊后缀,把值替换为纯数字
|
|
|
+ list2.set(0,s4);
|
|
|
+ if(s3.contains(" ")){
|
|
|
+ String[] split2 = s3.split(" ");
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String string : split2) {
|
|
|
+ //获取比较符
|
|
|
+ operator = string.substring(0, 1);
|
|
|
+ String number = string.substring(1);
|
|
|
+ operator = strReplace(operator);
|
|
|
+ String str = split1[1] + operator + extractPureNumbers(number);
|
|
|
+ list.add(str);
|
|
|
+ }
|
|
|
+ formulaData = String.join("&&",list);
|
|
|
+ }else{
|
|
|
//获取比较符
|
|
|
- operator = string.substring(0, 1);
|
|
|
- String number = string.substring(1);
|
|
|
+ operator = s3.substring(0, 1);
|
|
|
+ String number = s3.substring(1);
|
|
|
operator = strReplace(operator);
|
|
|
- String str = split1[1] + operator + extractPureNumbers(number);
|
|
|
- list.add(str);
|
|
|
+
|
|
|
+ formulaData = split1[1] + operator + extractPureNumbers(number);
|
|
|
}
|
|
|
- formulaData = String.join("&&",list);
|
|
|
- }else{
|
|
|
- //获取比较符
|
|
|
- operator = s3.substring(0, 1);
|
|
|
- String number = s3.substring(1);
|
|
|
- operator = strReplace(operator);
|
|
|
-
|
|
|
- formulaData = split1[1] + operator + extractPureNumbers(number);
|
|
|
- }
|
|
|
- }else if (pattern.matcher(s3).matches() && !pattern.matcher(s4).matches()){
|
|
|
- list1.set(0,s3);
|
|
|
- if(s4.contains(" ")){
|
|
|
- String[] split2 = s4.split(" ");
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- for (String string : split2) {
|
|
|
+ }else if (pattern.matcher(s3).matches() && !pattern.matcher(s4).matches()){
|
|
|
+ list1.set(0,s3);
|
|
|
+ if(s4.contains(" ")){
|
|
|
+ String[] split2 = s4.split(" ");
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (String string : split2) {
|
|
|
+ //获取比较符
|
|
|
+ operator = string.substring(0, 1);
|
|
|
+ String number = string.substring(1);
|
|
|
+ operator = strReplace(operator);
|
|
|
+ String str = split1[0] + operator + extractPureNumbers(number);
|
|
|
+ list.add(str);
|
|
|
+ }
|
|
|
+ formulaData = String.join("&&",list);
|
|
|
+ }else{
|
|
|
//获取比较符
|
|
|
- operator = string.substring(0, 1);
|
|
|
- String number = string.substring(1);
|
|
|
+ operator = s4.substring(0, 1);
|
|
|
+ String number = s4.substring(1);
|
|
|
operator = strReplace(operator);
|
|
|
- String str = split1[0] + operator + extractPureNumbers(number);
|
|
|
- list.add(str);
|
|
|
+ formulaData = split1[0] + operator + extractPureNumbers(number);
|
|
|
}
|
|
|
- formulaData = String.join("&&",list);
|
|
|
- }else{
|
|
|
- //获取比较符
|
|
|
- operator = s4.substring(0, 1);
|
|
|
- String number = s4.substring(1);
|
|
|
- operator = strReplace(operator);
|
|
|
- formulaData = split1[0] + operator + extractPureNumbers(number);
|
|
|
+ } else{
|
|
|
+ f = f.replace(el, "数据错误,无法比较");
|
|
|
+ break;
|
|
|
}
|
|
|
- } else{
|
|
|
- f = f.replace(el, "数据错误,无法比较");
|
|
|
- break;
|
|
|
+ Integer ist = Expression.parse(formulaData + "?1:0").calculate(currentMap);
|
|
|
+ count += ist;
|
|
|
}
|
|
|
- Integer ist = Expression.parse(formulaData + "?1:0").calculate(currentMap);
|
|
|
- count += ist;
|
|
|
- }
|
|
|
- Object data = null;
|
|
|
- if(count == split.length){
|
|
|
- data = pa[1];
|
|
|
- }else{
|
|
|
- data = pa[2];
|
|
|
+ Object data = null;
|
|
|
+ if(count == split.length){
|
|
|
+ data = pa[1];
|
|
|
+ }else{
|
|
|
+ data = pa[2];
|
|
|
+ }
|
|
|
+ f = f.replace(el, putDataWithKey(data, tec));
|
|
|
+ } else {
|
|
|
+ f = f.replace(el, "参数格式错误");
|
|
|
}
|
|
|
- f = f.replace(el, putDataWithKey(data, tec));
|
|
|
- } else {
|
|
|
- f = f.replace(el, "参数格式错误");
|
|
|
+
|
|
|
}
|
|
|
+ max++;
|
|
|
+ } while (f.contains("ifelse") && max < 20);
|
|
|
+ }else{
|
|
|
+ int max = 0;
|
|
|
+ do {
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG + "(ifelse)\\(([^)]+)\\)", f);
|
|
|
+ while (m.find()) {
|
|
|
+ String el = m.group();
|
|
|
+ String pstr = el.replaceAll("^" + FC_REG + "ifelse\\(", "").replaceAll("\\)$", "");
|
|
|
+ String[] pa = pstr.split(",");
|
|
|
+ if (pa.length == 3) {
|
|
|
+ Object data = Expression.parse(pa[0] + "?" + pa[1] + ":" + pa[2]).calculate(createCurrentMap(el, tec));
|
|
|
+ f = f.replace(el, putDataWithKey(data, tec));
|
|
|
+ } else {
|
|
|
+ f = f.replace(el, "参数格式错误");
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- max++;
|
|
|
- } while (f.contains("syifelse") && max < 20);
|
|
|
+ }
|
|
|
+ max++;
|
|
|
+ } while (f.contains("ifelse") && max < 20);
|
|
|
+ }
|
|
|
}
|
|
|
if (f.contains("avg4segment")) {
|
|
|
Matcher m = RegexUtils.matcher(FC_REG + "(avg4segment)\\(([^)]+)\\)", f);
|