|
@@ -74,10 +74,10 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
public static final String IF_REG= "(?<=T\\(com.mixsmart.utils.CustomFunction\\).ifelse\\()[^,]+(?=,)";
|
|
public static final String IF_REG= "(?<=T\\(com.mixsmart.utils.CustomFunction\\).ifelse\\()[^,]+(?=,)";
|
|
public static final Pattern IF = Pattern.compile(IF_REG);
|
|
public static final Pattern IF = Pattern.compile(IF_REG);
|
|
|
|
|
|
- public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=\\])";
|
|
|
|
|
|
+ public static final String ELE_CODE_REG= "(?<=E\\[)[^]]+(?=])";
|
|
public static final Pattern P = Pattern.compile(ELE_CODE_REG);
|
|
public static final Pattern P = Pattern.compile(ELE_CODE_REG);
|
|
- public static final Pattern P2= Pattern.compile("(?<=E\\[)[^];]+:[^];]+:[^];]+(?=\\])");
|
|
|
|
- public static final String POLY_REG= "(checkpoints|quantity|avg|min|max|sum|join|repeat|removeEmpty|listAt)\\(([^)]+)\\)";
|
|
|
|
|
|
+ public static final Pattern P2= Pattern.compile("(?<=E\\[)[^];]+:[^];]+:[^];]+(?=])");
|
|
|
|
+ public static final String POLY_REG= "(quantity)\\(([^)]+)\\)";
|
|
public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
public static final Pattern POLY = Pattern.compile(POLY_REG);
|
|
public final static String CTI="ContractInfo";
|
|
public final static String CTI="ContractInfo";
|
|
public final static String PJI="ProjectInfo";
|
|
public final static String PJI="ProjectInfo";
|
|
@@ -128,7 +128,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
List<AppWbsTreeContractVO> tableList =wbsTreeContractService.searchNodeAllTable(primaryKeyId.toString(), "1", contractId.toString(),info.getPId());
|
|
List<AppWbsTreeContractVO> tableList =wbsTreeContractService.searchNodeAllTable(primaryKeyId.toString(), "1", contractId.toString(),info.getPId());
|
|
this.constantMap.put(TABLE_LIST,tableList);
|
|
this.constantMap.put(TABLE_LIST,tableList);
|
|
/*通过判断元素名称来确定,加入汇总公式延后执行*/
|
|
/*通过判断元素名称来确定,加入汇总公式延后执行*/
|
|
- this.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
|
|
|
|
+ this.constantMap.put("tableNames",tableList.stream().filter(e->StringUtils.isEquals(e.getIsBussShow(),1)).map(WbsTreeContract::getFullName).collect(Collectors.toList()));
|
|
/*检查是否有跨节点数据*/
|
|
/*检查是否有跨节点数据*/
|
|
List<String> missingList = new ArrayList<>();
|
|
List<String> missingList = new ArrayList<>();
|
|
this.formDataList.forEach(fd->{
|
|
this.formDataList.forEach(fd->{
|
|
@@ -421,8 +421,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
String f=formula.getFormula();
|
|
String f=formula.getFormula();
|
|
if(Func.isNotBlank(f)){
|
|
if(Func.isNotBlank(f)){
|
|
try{
|
|
try{
|
|
- /*聚合运算*/
|
|
|
|
- polymerization(fd);
|
|
|
|
|
|
+ /*非解析器自定义运算*/
|
|
|
|
+ preCalc(fd);
|
|
|
|
+ tmpFc(fd);
|
|
Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
List<String> relyList = fd.getFormula().getRelyList();
|
|
List<String> relyList = fd.getFormula().getRelyList();
|
|
if(CollectionUtil.isNotEmpty(relyList)){
|
|
if(CollectionUtil.isNotEmpty(relyList)){
|
|
@@ -675,58 +676,73 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
/**
|
|
/**
|
|
* 先把公式脚本需要聚合部分预处理
|
|
* 先把公式脚本需要聚合部分预处理
|
|
* */
|
|
* */
|
|
- public void polymerization(FormData fd){
|
|
|
|
|
|
+ public void preCalc(FormData fd){
|
|
|
|
+ try{
|
|
|
|
+ Formula formula=fd.getFormula();
|
|
|
|
+ String f=formula.getFormula();
|
|
|
|
+ if (f.contains("converge")){
|
|
|
|
+ Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(\\w+)\\(([^]]+)\\)",f);
|
|
|
|
+ while (m.find()){
|
|
|
|
+ List<FormData> target = getFormDataByCode(m.group(2));
|
|
|
|
+ Object data =target.stream().flatMap(e->e.getValues().stream()).map(ElementData::getValue).collect(Collectors.toList());
|
|
|
|
+ f=f.replace(m.group(),putDataWithKey(data));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(f.contains("compound")){
|
|
|
|
+ Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(compound)\\(([^]]+)\\)",f);
|
|
|
|
+ while (m.find()){
|
|
|
|
+ List<FormData> target = getFormDataByCode(m.group(2));
|
|
|
|
+ Object data =target.stream().map(e->e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList())).collect(Collectors.toList());
|
|
|
|
+ String key =putDataWithKey(data);
|
|
|
|
+ String key2 =putDataWithKey(target.stream().map(FormData::getEName).collect(Collectors.toList()));
|
|
|
|
+ String func = CustomFunction.CLASS_CALL+"compound("+key+","+key2+")";
|
|
|
|
+ f=f.replace(m.group(),func);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(f.contains("quantity")){
|
|
|
|
+ /*聚合*/
|
|
|
|
+ Matcher m = RegexUtils.matcher("T\\(com.mixsmart.utils.CustomFunction\\)\\.(quantity)\\(([^]]+)\\)",f);
|
|
|
|
+ while (m.find()) {
|
|
|
|
+ Object data=null;
|
|
|
|
+ List<String> codeList = getCodeList(m.group(2));
|
|
|
|
+ Map<String,List<Map<String,Object>>> textInfoMap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault(TEXT_INFO_MAP,new HashMap<>());
|
|
|
|
+ List<Map<String,Object>> tableColKeyVal= textInfoMap.get(codeList.get(0));
|
|
|
|
+ if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
|
+ Optional<RangeInfo> op=tableColKeyVal.stream().map(map-> BeanUtil.toBean(JSON.parseObject(map.get("val").toString()),RangeInfo.class)).findFirst();
|
|
|
|
+ if(op.isPresent()){
|
|
|
|
+ RangeInfo d = op.get();
|
|
|
|
+ d.build();
|
|
|
|
+ data= d.getPassList().stream().mapToInt(Func::toInt).count();
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ FormData dataFd=this.formDataMap.get(codeList.get(0));
|
|
|
|
+ FormData designFd=this.formDataMap.get(codeList.get(1));
|
|
|
|
+ if(dataFd!=null&&designFd!=null){
|
|
|
|
+ List<Object> result = CustomFunction.b445check(dataFd.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()),designFd.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()),formula.getDev(),1 );
|
|
|
|
+ data=result.get(1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ f = f.replace(m.group(),putDataWithKey(data));
|
|
|
|
+ }
|
|
|
|
+ fd.getFormula().setFormula(f);
|
|
|
|
+ }
|
|
|
|
+ formula.setFormula(f);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ tec.getLog().append(e.getMessage());
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void tmpFc(FormData fd){
|
|
|
|
+ /*临时代码,牛皮癣的存在,替代后删除*/
|
|
Formula formula = fd.getFormula();
|
|
Formula formula = fd.getFormula();
|
|
if(Func.isNotEmpty(formula)){
|
|
if(Func.isNotEmpty(formula)){
|
|
String f=formula.getFormula();
|
|
String f=formula.getFormula();
|
|
try {
|
|
try {
|
|
if(Func.isNotBlank(f)) {
|
|
if(Func.isNotBlank(f)) {
|
|
- if (f.contains(CustomFunction.CLASS_CALL+"quantity(")) {
|
|
|
|
- /*聚合*/
|
|
|
|
- Matcher m = POLY.matcher(f);
|
|
|
|
- while (m.find()) {
|
|
|
|
- Object data=null;
|
|
|
|
- if(f.contains("quantity(")){
|
|
|
|
- String s = m.group(2).split(",")[0].replaceAll("[E\\[\\]']","");
|
|
|
|
- Map<String,List<Map<String,Object>>> textInfoMap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault(TEXT_INFO_MAP,new HashMap<>());
|
|
|
|
- List<Map<String,Object>> tableColKeyVal= textInfoMap.get(s);
|
|
|
|
- if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
|
- data = tableColKeyVal.stream().map(map-> BeanUtil.toBean(JSON.parseObject(map.get("val").toString()),RangeInfo.class)).map(RangeInfo::getPass).findFirst().orElseGet(String::new);
|
|
|
|
- }else{
|
|
|
|
- /*手动计算*/
|
|
|
|
- System.out.println("");
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
|
- List<String> relyList = fd.getFormula().getRelyList();
|
|
|
|
- Map<String, Object> E = getMap(currentMap, "E");
|
|
|
|
- for(String k:relyList){
|
|
|
|
- FormData e=this.formDataMap.get(k);
|
|
|
|
- if(e==null){
|
|
|
|
- this.tec.getLog().append(fd.getEName()).append("缺失依赖:").append(k).append(";");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- E.put(e.getCode(),e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()));
|
|
|
|
- }
|
|
|
|
- data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
|
|
|
|
- }
|
|
|
|
- String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
|
- this.constantMap.put(key,data);
|
|
|
|
- f = f.replace(CustomFunction.CLASS_CALL + m.group(), key);
|
|
|
|
- }
|
|
|
|
- fd.getFormula().setFormula(f);
|
|
|
|
- }else if(f.contains(CustomFunction.CLASS_CALL+"proportion(")||f.contains(CustomFunction.CLASS_CALL+"ladder(")||f.contains(CustomFunction.CLASS_CALL+"major(")||f.contains(CustomFunction.CLASS_CALL+"reasonable(")
|
|
|
|
- ||f.contains(CustomFunction.CLASS_CALL+"goodSize(")){
|
|
|
|
|
|
+ if(f.contains(CustomFunction.CLASS_CALL+"proportion(")||f.contains(CustomFunction.CLASS_CALL+"ladder(")||f.contains(CustomFunction.CLASS_CALL+"major(")||f.contains(CustomFunction.CLASS_CALL+"reasonable(") ||f.contains(CustomFunction.CLASS_CALL+"goodSize(")){
|
|
String tf=f.replaceAll("^T\\(com.mixsmart.utils.CustomFunction\\)\\.\\w+\\(","").replaceAll("[)]$","");
|
|
String tf=f.replaceAll("^T\\(com.mixsmart.utils.CustomFunction\\)\\.\\w+\\(","").replaceAll("[)]$","");
|
|
- List<FormData> target = new ArrayList<>();
|
|
|
|
- String[] tfa=tf.split(",");
|
|
|
|
- for(String code:tfa){
|
|
|
|
- code=code.replace("E['","").replace("']","");
|
|
|
|
- FormData fdt=this.formDataMap.get(code);
|
|
|
|
- if(fdt!=null){
|
|
|
|
- target.add(fdt);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<FormData> target = getFormDataByCode(tf);
|
|
if(Func.isNotEmpty(target)){
|
|
if(Func.isNotEmpty(target)){
|
|
if(StringUtils.isEmpty(formula.getScale())){
|
|
if(StringUtils.isEmpty(formula.getScale())){
|
|
formula.setScale(2);
|
|
formula.setScale(2);
|
|
@@ -753,7 +769,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
Matcher im =IF.matcher(f);
|
|
Matcher im =IF.matcher(f);
|
|
while (im.find()){
|
|
while (im.find()){
|
|
String rep =im.group();
|
|
String rep =im.group();
|
|
- //Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
|
Matcher fm=P.matcher(rep);
|
|
Matcher fm=P.matcher(rep);
|
|
while (fm.find()){
|
|
while (fm.find()){
|
|
FormData kf= this.formDataMap.get(fm.group().replaceAll("'",""));
|
|
FormData kf= this.formDataMap.get(fm.group().replaceAll("'",""));
|
|
@@ -782,113 +797,36 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void polymerizationBak(FormData fd){
|
|
|
|
- Formula formula = fd.getFormula();
|
|
|
|
- if(Func.isNotEmpty(formula)){
|
|
|
|
- String f=formula.getFormula();
|
|
|
|
- try {
|
|
|
|
- if(Func.isNotBlank(f)) {
|
|
|
|
- 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(")
|
|
|
|
- ||f.contains(CustomFunction.CLASS_CALL+"quantity(")||f.contains(CustomFunction.CLASS_CALL+"listAt(")||f.contains(CustomFunction.CLASS_CALL+"join(")||f.contains(CustomFunction.CLASS_CALL+"repeat(")||f.contains(CustomFunction.CLASS_CALL+"removeEmpty(")
|
|
|
|
- ) {
|
|
|
|
- /*聚合*/
|
|
|
|
- Matcher m = POLY.matcher(f);
|
|
|
|
- while (m.find()) {
|
|
|
|
- Object data=null;
|
|
|
|
- if(f.contains("quantity(")){
|
|
|
|
- String s = m.group(2).split(",")[0].replaceAll("[E\\[\\]']","");
|
|
|
|
- Map<String,List<Map<String,Object>>> textInfoMap= (Map<String, List<Map<String, Object>>>) this.constantMap.getOrDefault(TEXT_INFO_MAP,new HashMap<>());
|
|
|
|
- List<Map<String,Object>> tableColKeyVal= textInfoMap.get(s);
|
|
|
|
- if(Func.isNotEmpty(tableColKeyVal)){
|
|
|
|
- data = tableColKeyVal.stream().map(map-> BeanUtil.toBean(JSON.parseObject(map.get("val").toString()),RangeInfo.class)).map(RangeInfo::getPass).findFirst().orElseGet(String::new);
|
|
|
|
- }else{
|
|
|
|
- /*手动计算*/
|
|
|
|
- System.out.println("");
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
|
- List<String> relyList = fd.getFormula().getRelyList();
|
|
|
|
- Map<String, Object> E = getMap(currentMap, "E");
|
|
|
|
- for(String k:relyList){
|
|
|
|
- FormData e=this.formDataMap.get(k);
|
|
|
|
- if(e==null){
|
|
|
|
- this.tec.getLog().append(fd.getEName()).append("缺失依赖:").append(k).append(";");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- E.put(e.getCode(),e.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()));
|
|
|
|
- }
|
|
|
|
- data = Expression.parse(CustomFunction.CLASS_CALL + m.group()).calculate(currentMap);
|
|
|
|
- }
|
|
|
|
- String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
|
- this.constantMap.put(key,data);
|
|
|
|
- f = f.replace(CustomFunction.CLASS_CALL + m.group(), key);
|
|
|
|
- }
|
|
|
|
- fd.getFormula().setFormula(f);
|
|
|
|
- }else if(f.contains(CustomFunction.CLASS_CALL+"proportion(")||f.contains(CustomFunction.CLASS_CALL+"ladder(")||f.contains(CustomFunction.CLASS_CALL+"major(")||f.contains(CustomFunction.CLASS_CALL+"reasonable(")
|
|
|
|
- ||f.contains(CustomFunction.CLASS_CALL+"goodSize(")){
|
|
|
|
- String tf=f.replaceAll("^T\\(com.mixsmart.utils.CustomFunction\\)\\.\\w+\\(","").replaceAll("[)]$","");
|
|
|
|
- List<FormData> target = new ArrayList<>();
|
|
|
|
- String[] tfa=tf.split(",");
|
|
|
|
- for(String code:tfa){
|
|
|
|
- code=code.replace("E['","").replace("']","");
|
|
|
|
- FormData fdt=this.formDataMap.get(code);
|
|
|
|
- if(fdt!=null){
|
|
|
|
- target.add(fdt);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(Func.isNotEmpty(target)){
|
|
|
|
- if(StringUtils.isEmpty(formula.getScale())){
|
|
|
|
- formula.setScale(2);
|
|
|
|
- }
|
|
|
|
- Object data=null;
|
|
|
|
- if(f.contains("proportion")){
|
|
|
|
- data= CustomFunction.proportion(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()), "优良");
|
|
|
|
- }else if(f.contains("ladder")){
|
|
|
|
- data= CustomFunction.ladder(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()));
|
|
|
|
- }else if(f.contains("major")){
|
|
|
|
- data= CustomFunction.major(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()));
|
|
|
|
- }else if(f.contains("reasonable")){
|
|
|
|
- data= CustomFunction.reasonable(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()));
|
|
|
|
- }else if(f.contains("goodSize")){
|
|
|
|
- data= CustomFunction.goodSize(target.stream().map(FormData::getValues).filter(Func::isNotEmpty).map(e->e.get(0).getValue()).collect(Collectors.toList()),"优良");
|
|
|
|
- }
|
|
|
|
- String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
|
- fd.getFormula().setFormula(key);
|
|
|
|
- this.constantMap.put(key,data);
|
|
|
|
- }else{
|
|
|
|
- fd.getFormula().setFormula(StringPool.EMPTY);
|
|
|
|
- }
|
|
|
|
- }else if(f.contains(CustomFunction.CLASS_CALL+"ifelse(")){
|
|
|
|
- Matcher im =IF.matcher(f);
|
|
|
|
- while (im.find()){
|
|
|
|
- String rep =im.group();
|
|
|
|
- //Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
|
- Matcher fm=P.matcher(rep);
|
|
|
|
- while (fm.find()){
|
|
|
|
- FormData kf= this.formDataMap.get(fm.group().replaceAll("'",""));
|
|
|
|
- if(kf!=null&&!kf.empty()){
|
|
|
|
- ElementData ed= kf.getValues().get(0);
|
|
|
|
- if(ed!=null&&Func.isNotEmpty(ed.getValue())){
|
|
|
|
- rep= rep.replace("E["+fm.group()+"]",ed.getValue().toString());
|
|
|
|
- rep="'"+rep+"'";
|
|
|
|
- f=f.replace(im.group(),rep);
|
|
|
|
- }else{
|
|
|
|
- f="";
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- f="";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- formula.setFormula(f);
|
|
|
|
- }
|
|
|
|
- relyParse(fd.getFormula());
|
|
|
|
- StaticLog.info("聚合处理");
|
|
|
|
- }
|
|
|
|
- }catch (Exception e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+
|
|
|
|
+ /*从方法参数中获取全部code*/
|
|
|
|
+ public List<String> getCodeList(String param){
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
+ if(StringUtils.isNotEmpty(param)){
|
|
|
|
+ Arrays.stream(param.split(",")).forEach(s->{
|
|
|
|
+ list.add(s.replaceAll("[E\\[\\]']",""));
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+ /**把计算结果放入固定常量集,创建key来引用*/
|
|
|
|
+ public String putDataWithKey(Object data){
|
|
|
|
+ String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
|
+ this.constantMap.put(key,data);
|
|
|
|
+ return key;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*根据参数获取所有的元素*/
|
|
|
|
+ public List<FormData> getFormDataByCode(String codes){
|
|
|
|
+ List<FormData> target = new ArrayList<>();
|
|
|
|
+ String[] tfa=codes.split(",");
|
|
|
|
+ for(String code:tfa){
|
|
|
|
+ code=code.replace("E['","").replace("']","");
|
|
|
|
+ FormData fdt=this.formDataMap.get(code);
|
|
|
|
+ if(fdt!=null){
|
|
|
|
+ target.add(fdt);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ return target;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|