|
@@ -7,6 +7,7 @@ import com.mixsmart.utils.CustomFunction;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
+import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.manager.dto.FormData;
|
|
|
import org.springblade.manager.entity.Formula;
|
|
|
import org.springblade.manager.entity.WbsParam;
|
|
@@ -37,6 +38,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
public final static String CHAIN="trees";
|
|
|
public final static String FC="FC.";
|
|
|
|
|
|
+
|
|
|
+ public static final String POLY_REG= "(avg|min|max|sum)\\([^)]+\\)";
|
|
|
+ public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
|
public void execute( List<FormData> list ){
|
|
|
Map<Boolean,List<FormData>> map = list.stream().collect(Collectors.partitioningBy(e->e!=null&&e.getFormula().getFormula().contains("E[")));
|
|
|
List<FormData>total = new ArrayList<>();
|
|
@@ -75,7 +79,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);
|
|
|
for(FormData fd:total){
|
|
|
/*存入数据*/
|
|
|
if(CollectionUtil.isNotEmpty(fd.getValues())){
|
|
@@ -83,6 +88,7 @@ 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));
|
|
|
Map<String,Object> tableMap = (Map<String, Object>) variables.get(fd.getCode());
|
|
|
if(tableMap==null){
|
|
|
tableMap= new HashMap<>();
|
|
@@ -97,12 +103,29 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
while (m.find()){
|
|
|
tmp= tmp.replace(m.group(),"'"+m.group()+"'");
|
|
|
}
|
|
|
+ Matcher m2 = P.matcher(tmp);
|
|
|
+ while (m2.find()){
|
|
|
+ tmp= tmp.replace(m2.group(),"'"+m2.group()+"'");
|
|
|
+ }
|
|
|
fd.getFormula().setFormula(tmp);
|
|
|
}
|
|
|
/*执行公式*/
|
|
|
+ /*集合公式预处理*/
|
|
|
+ for(FormData fd:total){
|
|
|
+ String formula=fd.getFormula().getFormula();
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
for(FormData fd:total){
|
|
|
- Object data = Expression.parse(fd.getFormula().getFormula()).calculate(currentMap);
|
|
|
- fd.getValues().add(new ArrayList<>(Collections.singletonList(data)));
|
|
|
+ if(Func.isNotBlank(fd.getFormula().getFormula())){
|
|
|
+ Object data = Expression.parse(fd.getFormula().getFormula()).calculate(currentMap);
|
|
|
+ fd.getValues().add(new ArrayList<>(Collections.singletonList(data)));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
System.out.println();
|