|
@@ -1,12 +1,10 @@
|
|
|
package org.springblade.manager.service.impl;
|
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.jfireel.expression.Expression;
|
|
|
import com.mixsmart.utils.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
-import org.springblade.business.feign.MileageClient;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
import org.springblade.core.tool.utils.CollectionUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
@@ -16,7 +14,7 @@ import org.springblade.manager.dto.LocalVariable;
|
|
|
import org.springblade.manager.entity.Formula;
|
|
|
import org.springblade.manager.entity.WbsParam;
|
|
|
import org.springblade.manager.entity.WbsTreeContract;
|
|
|
-import org.springblade.manager.formula.IFcHandler;
|
|
|
+import org.springblade.manager.formula.Container;
|
|
|
import org.springblade.manager.formula.FormulaStrategyFactory;
|
|
|
import org.springblade.manager.formula.impl.TableElementConverter;
|
|
|
import org.springblade.manager.mapper.FormulaMapper;
|
|
@@ -41,20 +39,24 @@ import java.util.stream.Collectors;
|
|
|
public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula> implements IFormulaService {
|
|
|
|
|
|
private final IWbsParamService wpService;
|
|
|
- private final MileageClient mileageClient;
|
|
|
private final IWbsTreeContractService treeContractService;
|
|
|
private final FormulaStrategyFactory formulaStrategyFactory;
|
|
|
+ private final Container env;
|
|
|
+
|
|
|
|
|
|
|
|
|
public final static String WP="WP";
|
|
|
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 static final Pattern MILE_P = Pattern.compile("(?<=MILE<)([^,]+),([^,]+)(?=,)");
|
|
|
- private Map<String,Object> constantMap;
|
|
|
- private List<FormData> formDataList;
|
|
|
+ public static final Pattern AP=Pattern.compile("(E|WP)\\[([^]]+)]");
|
|
|
+
|
|
|
+ public static final String IF_REG= "(?<=T\\(com.mixsmart.utils.CustomFunction\\).ifelse\\()[^,]+(?=,)";
|
|
|
+ public static final Pattern IF = Pattern.compile(IF_REG);
|
|
|
+
|
|
|
+ public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=\\])";
|
|
|
+ public static final Pattern P = Pattern.compile(ELE_CODE_REG);
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -65,8 +67,8 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
**/
|
|
|
@Override
|
|
|
public void execute(List<FormData> list ,Long contractId,Long primaryKeyId){
|
|
|
- /*初始化变量>>依赖排序>>预处理>>特殊公式>>通用公式执行*/
|
|
|
-// this.init(list,contractId,primaryKeyId).sort().pre().special().calculate();
|
|
|
+ /*初始化变量>>依赖排序>>预处理>>特殊公式>>通用公式执行*/
|
|
|
+ this.init(list,contractId,primaryKeyId).sort().pre().special().calculate();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -76,12 +78,12 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void init(List<FormData> list,Long contractId,Long primaryKeyId) {
|
|
|
- this.constantMap=new HashMap<>(100);
|
|
|
- this.formDataList=list;
|
|
|
- this.constantMap.put("contractId",contractId);
|
|
|
+ public IFormulaService init(List<FormData> list,Long contractId,Long primaryKeyId) {
|
|
|
+ this.env.constantMap=new HashMap<>(100);
|
|
|
+ this.env.formDataList=list;
|
|
|
+ this.env.constantMap.put("contractId",contractId);
|
|
|
List<WbsTreeContract> nodes = treeContractService.searchParentAllNode(primaryKeyId,contractId);
|
|
|
- this.constantMap.put(CHAIN,nodes.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
|
+ this.env.constantMap.put(CHAIN,nodes.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
|
List<WbsParam> wps = this.wpService.list(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getWbsId,primaryKeyId));
|
|
|
Map<String,Object> wpMap= new HashMap<>(wps.size()*2);
|
|
|
if(CollectionUtil.isNotEmpty(wps)){
|
|
@@ -89,32 +91,32 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
wpMap.put(p.getK(),p.getV());
|
|
|
}
|
|
|
}
|
|
|
- this.constantMap.put(WP,wpMap);
|
|
|
-// return this;
|
|
|
+ this.env.constantMap.put(WP,wpMap);
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void sort() {
|
|
|
- Map<Boolean,List<FormData>> map = this.formDataList.stream().collect(Collectors.partitioningBy(e->e!=null&&e.getFormula().getFormula().contains("E[")));
|
|
|
- this.formDataList.clear();
|
|
|
+ public IFormulaService sort() {
|
|
|
+ Map<Boolean,List<FormData>> map = this.env.formDataList.stream().collect(Collectors.partitioningBy(e->e!=null&&e.getFormula().getFormula().contains("E[")));
|
|
|
+ this.env.formDataList.clear();
|
|
|
/*没有依赖的*/
|
|
|
List<FormData> simple=map.get(false);
|
|
|
if(CollectionUtil.isNotEmpty(simple)){
|
|
|
- this.formDataList.addAll(simple);
|
|
|
+ this.env.formDataList.addAll(simple);
|
|
|
}
|
|
|
/*有依赖的*/
|
|
|
List<FormData> rely= map.get(true);
|
|
|
if(CollectionUtil.isNotEmpty(rely)){
|
|
|
sort(rely,((rely.size()+1)/2)*rely.size());
|
|
|
- this.formDataList.addAll(rely);
|
|
|
+ this.env.formDataList.addAll(rely);
|
|
|
}
|
|
|
-// return this;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void pre() {
|
|
|
- if(CollectionUtil.isNotEmpty(this.formDataList)){
|
|
|
- for(FormData fd:this.formDataList){
|
|
|
+ public IFormulaService pre() {
|
|
|
+ if(CollectionUtil.isNotEmpty(this.env.formDataList)){
|
|
|
+ for(FormData fd:this.env.formDataList){
|
|
|
/*预处理公式脚本*/
|
|
|
String tmp =fd.getFormula().getFormula();
|
|
|
tmp = tmp.replace(FC, CustomFunction.CLASS_CALL);
|
|
@@ -133,21 +135,21 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(tmp.contains("E[")||tmp.contains("WP[")){
|
|
|
Matcher am = AP.matcher(tmp);
|
|
|
while (am.find()){
|
|
|
- tmp = tmp.replace(am.group(),am.group(1)+"['"+am.group(2)+"']");
|
|
|
+ tmp = tmp.replace(am.group(),am.group(1)+"['"+am.group(2)+"']");
|
|
|
}
|
|
|
}
|
|
|
fd.getFormula().setFormula(tmp);
|
|
|
}
|
|
|
}
|
|
|
-// return this;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void special() {
|
|
|
- for(FormData fd:this.formDataList) {
|
|
|
- formulaStrategyFactory.get(fd).forEach(e->e.execute(this.formDataList,constantMap));
|
|
|
+ public IFormulaService special() {
|
|
|
+ for(FormData fd:this.env.formDataList) {
|
|
|
+ formulaStrategyFactory.get(fd).forEach(e->e.execute(this.env.formDataList,this.env.constantMap));
|
|
|
}
|
|
|
-// return this;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -155,15 +157,15 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*公式执行*/
|
|
|
/*先处理聚合类的方法*/
|
|
|
/*每次执行都会构造一个只有依赖的的集合*/
|
|
|
- for(FormData fd:this.formDataList){
|
|
|
+ for(FormData fd:this.env.formDataList){
|
|
|
Formula formula= fd.getFormula();
|
|
|
if(formula!=null){
|
|
|
String f=formula.getFormula();
|
|
|
if(Func.isNotBlank(f)){
|
|
|
- Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
+ Map<String, Object> currentMap = new HashMap<>(this.env.constantMap);
|
|
|
List<String> relyList = fd.getFormula().getRelyList();
|
|
|
if(CollectionUtil.isNotEmpty(relyList)){
|
|
|
- List<FormData> ele = this.formDataList.stream().filter(e->relyList.contains(e.getCode())).collect(Collectors.toList());
|
|
|
+ List<FormData> ele = this.env.formDataList.stream().filter(e->relyList.contains(e.getCode())).collect(Collectors.toList());
|
|
|
if(CollectionUtil.isNotEmpty(ele)){
|
|
|
/*每一组依赖的数据*/
|
|
|
Map<Integer,Map<String,List<Object>>> dataSource = new HashMap<>(20);
|
|
@@ -179,7 +181,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(dataSource.size()>0){
|
|
|
for(Map.Entry<Integer,Map<String,List<Object>>> entry:dataSource.entrySet()){
|
|
|
if(entry.getValue().keySet().size()>=ele.size()){
|
|
|
- List<ElementData> eds = slice(entry.getValue(),this.constantMap,f,entry.getKey());
|
|
|
+ List<ElementData> eds = slice(entry.getValue(),this.env.constantMap,f,entry.getKey());
|
|
|
fd.setValues(eds);
|
|
|
}
|
|
|
}
|
|
@@ -239,19 +241,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public static final String WP_REG= "(?<=P\\[)[^]]+(?=\\])";
|
|
|
- public static final Pattern PP = Pattern.compile(WP_REG);
|
|
|
-
|
|
|
- public static final Pattern AP=Pattern.compile("(E|WP)\\[([^]]+)]");
|
|
|
-
|
|
|
- public static final String IF_REG= "(?<=T\\(com.mixsmart.utils.CustomFunction\\).ifelse\\()[^,]+(?=,)";
|
|
|
- public static final Pattern IF = Pattern.compile(IF_REG);
|
|
|
- /**
|
|
|
- * 依赖排序
|
|
|
- */
|
|
|
- public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=\\])";
|
|
|
- public static final Pattern P = Pattern.compile(ELE_CODE_REG);
|
|
|
public static void sort( List<FormData> list,int n){
|
|
|
/*System.out.println("剩余计算次数:"+n+"次");*/
|
|
|
if(move(list)&&n>0){
|
|
@@ -304,7 +293,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
|
|
|
|
|
|
-public void polymerization(){
|
|
|
+ public void polymerization(){
|
|
|
// if(f.contains(CustomFunction.CLASS_CALL+"avg(")||f.contains(CustomFunction.CLASS_CALL+"min(")||f.contains(CustomFunction.CLASS_CALL+"max(")||f.contains(CustomFunction.CLASS_CALL+"sum(")){
|
|
|
// /*聚合*/
|
|
|
// Matcher m = POLY.matcher(f);
|
|
@@ -321,7 +310,7 @@ public void polymerization(){
|
|
|
// fd.getFormula().setFormula(f);
|
|
|
// }
|
|
|
// }
|
|
|
-}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|