|
@@ -57,7 +57,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=\\])";
|
|
|
public static final Pattern P = Pattern.compile(ELE_CODE_REG);
|
|
|
- public static final String POLY_REG= "(avg|min|max|sum)\\(([^)]+)\\)";
|
|
|
+ public static final String POLY_REG= "(checkpoints|avg|min|max|sum)\\(([^)]+)\\)";
|
|
|
public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
|
public final static String CTI="ContractInfo";
|
|
|
public final static String PJI="ProjectInfo";
|
|
@@ -72,9 +72,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
* @Date 2022.08.03 14:03
|
|
|
**/
|
|
|
@Override
|
|
|
- public void execute(List<FormData> list ,Long contractId,Long primaryKeyId){
|
|
|
+ public void execute(List<FormData> list ,Long contractId,Long id ,Long primaryKeyId){
|
|
|
/*初始化变量>>依赖排序>>预处理>>特殊公式>>通用公式执行>>数据格式化*/
|
|
|
- this.init(list,contractId,primaryKeyId)
|
|
|
+ this.init(list,contractId,id,primaryKeyId)
|
|
|
.sort()
|
|
|
.pre()
|
|
|
.special()
|
|
@@ -84,12 +84,12 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public void execute(TableElementConverter tec) {
|
|
|
- WbsTreeContract one= this.treeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,tec.getTableInfoList().get(0).getPkeyId()));
|
|
|
- this.execute(tec.getFds(),tec.getContractId(),Func.isNotEmpty(one.getOldId())?Long.parseLong(one.getOldId()):one.getParentId());
|
|
|
+ WbsTreeContract one= this.treeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId,tec.getNodeId()));
|
|
|
+ this.execute(tec.getFds(),tec.getContractId(),Func.isNotEmpty(one.getOldId())?Long.parseLong(one.getOldId()):one.getParentId(),one.getPKeyId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IFormulaService init(List<FormData> list,Long contractId,Long primaryKeyId) {
|
|
|
+ public IFormulaService init(List<FormData> list,Long contractId,Long id,Long primaryKeyId) {
|
|
|
this.env.constantMap=new HashMap<>(100);
|
|
|
this.env.formDataList=list;
|
|
|
this.env.constantMap.put("contractId",contractId);
|
|
@@ -98,17 +98,38 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
this.env.constantMap.put(CTI,info);
|
|
|
/*项目信息*/
|
|
|
this.env.constantMap.put(PJI,this.projectInfoService.getById(info.getPId()));
|
|
|
- List<WbsTreeContract> nodes = treeContractService.searchParentAllNode(primaryKeyId,contractId);
|
|
|
+ /*wbs节点链*/
|
|
|
+ List<WbsTreeContract> nodes = wpService.chain(contractId,id,primaryKeyId,null);
|
|
|
this.env.constantMap.put(CHAIN,nodes.stream().map(WbsTreeContract::getNodeName).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)){
|
|
|
- for(WbsParam p:wps){
|
|
|
- wpMap.put(p.getK(),p.getV());
|
|
|
+ /*节点参数*/
|
|
|
+ this.env.constantMap.put(WP,getWpMap(id,primaryKeyId));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description 获取节点参数
|
|
|
+ * @return java.util.Map<java.lang.String,java.lang.Object>
|
|
|
+ * @Author yangyj
|
|
|
+ * @Date 2022.10.09 11:11
|
|
|
+ **/
|
|
|
+ public Map<String,Object> getWpMap(Long id,Long primaryKeyId){
|
|
|
+ Map<String,Object> result = new HashMap<>(100);
|
|
|
+ List<WbsParam> total = new ArrayList<>();
|
|
|
+ List<WbsParam> wpsPublic = this.wpService.list(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getWbsId,id));
|
|
|
+ if(Func.isNotEmpty(wpsPublic)){
|
|
|
+ total.addAll(wpsPublic);
|
|
|
+ }
|
|
|
+ List<WbsParam> wpsPrivate = this.wpService.list(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getWbsId,primaryKeyId));
|
|
|
+ if(Func.isNotEmpty(wpsPrivate)){
|
|
|
+ total.addAll(wpsPrivate);
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(total)){
|
|
|
+ /*同名参数私有覆盖公用*/
|
|
|
+ for(WbsParam p:total){
|
|
|
+ result.put(p.getK(),p.getV());
|
|
|
}
|
|
|
}
|
|
|
- this.env.constantMap.put(WP,wpMap);
|
|
|
- return this;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -352,13 +373,16 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 先把公式脚本需要聚合部分预处理
|
|
|
+ * */
|
|
|
public void polymerization(){
|
|
|
for(FormData fd:this.env.formDataList){
|
|
|
Formula formula = fd.getFormula();
|
|
|
if(Func.isNotEmpty(formula)){
|
|
|
String f=formula.getFormula();
|
|
|
if(Func.isNotBlank(f)) {
|
|
|
- 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(")) {
|
|
|
+ if (f.contains(CustomFunction.CLASS_CALL + "checkpoints(") ||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);
|
|
|
while (m.find()) {
|
|
@@ -369,9 +393,15 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
Map<String, Object> E = getMap(currentMap, "E");
|
|
|
tmp.forEach(e -> E.put(e.getCode(), e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())));
|
|
|
Object data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
|
|
|
- data=StringUtils.number2String(data,StringUtils.getScale(data));
|
|
|
+ if(StringUtils.isNotEmpty(data)) {
|
|
|
+ data = CustomFunction.setScale(data, StringUtils.getScale(data));
|
|
|
+ }
|
|
|
/*必须要用括号套壳,不然无法处理负数*/
|
|
|
- f = f.replace(CustomFunction.CLASS_CALL + m.group(), "("+data.toString()+")");
|
|
|
+ if(StringUtils.isNumber(data)){
|
|
|
+ f = f.replace(CustomFunction.CLASS_CALL + m.group(), "("+data.toString()+")");
|
|
|
+ }else{
|
|
|
+ f = f.replace(CustomFunction.CLASS_CALL + m.group(), "'"+data.toString()+"'");
|
|
|
+ }
|
|
|
fd.getFormula().setFormula(f);
|
|
|
}
|
|
|
}
|