|
@@ -46,8 +46,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
List<FormData>total = new ArrayList<>();
|
|
|
/*用来保存所有变量*/
|
|
|
Map<String,Object> variables = new HashMap<>();
|
|
|
-
|
|
|
- Map<String,Object> currentMap = new HashMap<>();
|
|
|
+ Map<String,Object> constantMap = new HashMap<>();
|
|
|
/*预设变量start*/
|
|
|
List<WbsTree> trees = new ArrayList<>();
|
|
|
for(int i=0;i<6;i++){
|
|
@@ -77,10 +76,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
if(CollectionUtil.isNotEmpty(total)){
|
|
|
- currentMap.put(WP,wpMap);
|
|
|
- currentMap.put(CHAIN,trees.stream().map(WbsTree::getDeptName).collect(Collectors.toList()));
|
|
|
- Map<String,Object> E=new HashMap<>();
|
|
|
- currentMap.put("E",E);
|
|
|
+ constantMap.put(WP,wpMap);
|
|
|
+ constantMap.put(CHAIN,trees.stream().map(WbsTree::getDeptName).collect(Collectors.toList()));
|
|
|
for(FormData fd:total){
|
|
|
/*存入数据*/
|
|
|
if(CollectionUtil.isNotEmpty(fd.getValues())){
|
|
@@ -88,7 +85,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
for(int i=0;i<fd.getValues().size();i++){
|
|
|
tmpMap.put("p"+i,fd.getValues().get(i));
|
|
|
}
|
|
|
- E.put(fd.getCode(),fd.getValues().get(0));
|
|
|
+ variables.put(fd.getCode(),fd.getValues().get(0));
|
|
|
+
|
|
|
Map<String,Object> tableMap = (Map<String, Object>) variables.get(fd.getCode());
|
|
|
if(tableMap==null){
|
|
|
tableMap= new HashMap<>();
|
|
@@ -106,6 +104,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
Matcher m2 = P.matcher(tmp);
|
|
|
while (m2.find()){
|
|
|
tmp= tmp.replace(m2.group(),"'"+m2.group()+"'");
|
|
|
+ fd.getRely().add(m2.group());
|
|
|
}
|
|
|
fd.getFormula().setFormula(tmp);
|
|
|
}
|
|
@@ -113,46 +112,67 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*集合公式预处理*/
|
|
|
for(FormData fd:total){
|
|
|
String formula=fd.getFormula().getFormula();
|
|
|
+ Map<String,Object> currentMap = new HashMap<>(constantMap);
|
|
|
+ currentMap.put("E",variables);
|
|
|
if(formula.contains(CustomFunction.CLASS_CALL+"avg(")||formula.contains(CustomFunction.CLASS_CALL+"min(")||formula.contains(CustomFunction.CLASS_CALL+"max(")||formula.contains(CustomFunction.CLASS_CALL+"sum(")){
|
|
|
Matcher m = POLY.matcher(formula);
|
|
|
while (m.find()){
|
|
|
- Object data = Expression.parse(m.group()).calculate(currentMap);
|
|
|
- formula = formula.replace(m.group(),data.toString());
|
|
|
+ Object data = Expression.parse(CustomFunction.CLASS_CALL+m.group()).calculate(currentMap);
|
|
|
+ formula = formula.replace(CustomFunction.CLASS_CALL+m.group(),data.toString());
|
|
|
+ fd.getFormula().setFormula(formula);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for(FormData fd:total){
|
|
|
if(Func.isNotBlank(fd.getFormula().getFormula())){
|
|
|
- Object data = Expression.parse(fd.getFormula().getFormula()).calculate(currentMap);
|
|
|
- fd.getValues().add(new ArrayList<>(Collections.singletonList(data)));
|
|
|
+ Map<String, Object> currentMap = new HashMap<>();
|
|
|
+ Map<String,Object> elementMap = getMap(variables,"E");
|
|
|
+ Map<String,Object> tmp = getMap(currentMap,"E");
|
|
|
+ for(String key:fd.getRely()){
|
|
|
+ tmp.put(key,elementMap.get(key));
|
|
|
+ }
|
|
|
+ System.out.println(slice(currentMap,constantMap,fd.getFormula().getFormula()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
System.out.println("执行结束");
|
|
|
}
|
|
|
|
|
|
+ public Map<String,Object> getMap(Map<String,Object> variables,String key){
|
|
|
+ Map<String,Object> CNDMap = (Map<String, Object>) variables.get(key);
|
|
|
+ if(CNDMap==null){
|
|
|
+ CNDMap = new HashMap<>();
|
|
|
+ variables.put(key,CNDMap);
|
|
|
+ }
|
|
|
+ CNDMap.put("A",100);
|
|
|
+ return CNDMap;
|
|
|
+ }
|
|
|
|
|
|
- public static List<Object> slice(Map<String,Object> variables,String formula){
|
|
|
- int min =0;
|
|
|
+ public List<Object> slice(Map<String,Object> variables,Map<String,Object> constantMap,String formula){
|
|
|
+ int min =1;
|
|
|
List<Object> result = new ArrayList<>();
|
|
|
Map<String,Object> currentMap = new HashMap<>();
|
|
|
Map<String,List<Object>> massMap = new HashMap<>();
|
|
|
- for(Map.Entry<String,Object> entry:variables.entrySet()){
|
|
|
+ Map<String,Object> E=getMap(variables,"E");
|
|
|
+ Map<String,Object> E2=getMap(currentMap,"E");
|
|
|
+
|
|
|
+ for(Map.Entry<String,Object> entry:E.entrySet()){
|
|
|
if(entry.getValue() instanceof List){
|
|
|
List<Object> tmp = (List<Object>) entry.getValue();
|
|
|
- if(min==0){
|
|
|
- min=tmp.size();
|
|
|
+ if(min==1){
|
|
|
+ min= Math.max(tmp.size(), 1);
|
|
|
}else{
|
|
|
min= Math.min(min,tmp.size());
|
|
|
}
|
|
|
massMap.put(entry.getKey(),tmp);
|
|
|
}else{
|
|
|
- currentMap.put(entry.getKey(),entry.getValue());
|
|
|
+ E2.put(entry.getKey(),entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
+ currentMap.putAll(constantMap);
|
|
|
for(int i=0;i<min;i++){
|
|
|
for(Map.Entry<String,List<Object>> e:massMap.entrySet()){
|
|
|
- currentMap.put(e.getKey(),e.getValue().get(i));
|
|
|
+ E2.put(e.getKey(),e.getValue().get(i));
|
|
|
}
|
|
|
Object data = Expression.parse(formula).calculate(currentMap);
|
|
|
result.add(data);
|