|
@@ -5915,17 +5915,74 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
//判断 为
|
|
|
String falseStr = pa.get(2);;
|
|
|
if(pa.get(2).contains("(") && pa.get(2).contains(",") && pa.get(2).split(",").length == 3){
|
|
|
- pa.set(2,"-10086");
|
|
|
+ pa.set(2,"(-10086)");
|
|
|
+ }else{
|
|
|
+ if(pa.get(2).isEmpty()){
|
|
|
+ pa.set(2, "''");
|
|
|
+ }else{
|
|
|
+ if(!pa.get(2).contains("(")){
|
|
|
+ pa.set(2, "(" + pa.get(2) + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- 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);
|
|
|
- //递归计算
|
|
|
- if(Objects.equals(String.valueOf(data),"-10086")){
|
|
|
- //进入递归算法
|
|
|
- data = multipleIfElse(falseStr,currentMap);
|
|
|
+
|
|
|
+ // 针对一个元素多个单元格的数据单独处理
|
|
|
+ Object o = currentMap.get("E");
|
|
|
+ if(o != null){
|
|
|
+ Map<String, List<String>> tableDataMap = (Map<String, List<String>>) o;
|
|
|
+
|
|
|
+ Set<Integer> set = tableDataMap.values().stream().map(List::size).filter(size -> size != 1).collect(Collectors.toSet());
|
|
|
+ List<Integer> collect = new ArrayList<>(set);
|
|
|
+ if(collect.size() > 1){
|
|
|
+ throw new com.alibaba.nacos.shaded.com.google.protobuf.ServiceException("计算单元格不一致 无法计算");
|
|
|
+ }
|
|
|
+ //一个元素存在多单元格
|
|
|
+ if(collect.size() == 1){
|
|
|
+ List<List<String>> collect1 = tableDataMap.values().stream().filter(x -> x.size() > 1).collect(Collectors.toList());
|
|
|
+ //复制一份
|
|
|
+ List<List<String>> lists = collect1.stream().map(ArrayList::new).collect(Collectors.toList());
|
|
|
+ List<Object> dataAll = new ArrayList<>();
|
|
|
+ //数据按 行单独计算
|
|
|
+ for (int i = 0; i < collect.get(0); i++) {
|
|
|
+ for (int j = 0; j < lists.size(); j++) {
|
|
|
+ List<String> strings = collect1.get(j);
|
|
|
+ strings.clear();
|
|
|
+ strings.add(lists.get(j).get(i).toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ Object data = parse.calculate(currentMap);
|
|
|
+ //递归计算
|
|
|
+ if(Objects.equals(String.valueOf(data),"-10086")){
|
|
|
+ //进入递归算法
|
|
|
+ data = multipleIfElse(falseStr,currentMap);
|
|
|
+ }
|
|
|
+ if("".equals(data)){
|
|
|
+ data = "/";
|
|
|
+ }
|
|
|
+ dataAll.add(data);
|
|
|
+ }
|
|
|
+ //赋值元素是否是多个单元格
|
|
|
+ if(fd.getValues().size() > 1){
|
|
|
+ f = f.replace(f, putDataWithKey(dataAll, tec));
|
|
|
+ } else {
|
|
|
+ //计算平均值
|
|
|
+ OptionalDouble op = dataAll.stream().filter(StringUtils::isNumber).map(StringUtils::handleNull).mapToDouble(Double::parseDouble).average();
|
|
|
+ if (op.isPresent()) {
|
|
|
+ f = f.replace(f, putDataWithKey(op.getAsDouble(), tec));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Object data = parse.calculate(currentMap);
|
|
|
+ //递归计算
|
|
|
+ if(Objects.equals(String.valueOf(data),"-10086")){
|
|
|
+ //进入递归算法
|
|
|
+ data = multipleIfElse(falseStr,currentMap);
|
|
|
+ }
|
|
|
+ f = f.replace(f, putDataWithKey(data, tec));
|
|
|
+ }
|
|
|
}
|
|
|
- f = f.replace(f, putDataWithKey(data, tec));
|
|
|
} else {
|
|
|
f = f.replace(f, "参数格式错误");
|
|
|
}
|