|
@@ -37,12 +37,14 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
|
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -74,16 +76,11 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
/** private final Container env;*/
|
|
|
private TableElementConverter tec;
|
|
|
- private Map<String,Object> constantMap;
|
|
|
- private List<FormData> formDataList;
|
|
|
+// private Map<String,Object> constantMap;
|
|
|
+// private List<FormData> formDataList;
|
|
|
private Map<String,FormData> formDataMap;
|
|
|
private Map<String,Map<String,Object>> tableDataMaps;
|
|
|
|
|
|
- private List<FormData> checkItems;
|
|
|
- private List<FormData> checkDate;
|
|
|
- private List<FormData> summary;
|
|
|
-
|
|
|
-
|
|
|
|
|
|
public final static String WP="WP";
|
|
|
public final static String CHAIN="trees";
|
|
@@ -119,9 +116,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public IFormulaService init() {
|
|
|
- this.checkItems= new ArrayList<>();
|
|
|
- this.checkDate= new ArrayList<>();
|
|
|
- this.summary = new ArrayList<>();
|
|
|
this.tableDataMaps=this.tec.getTableDataMaps();
|
|
|
this.formDataMap=this.tec.getFormDataMap();
|
|
|
List<FormData> list =this.tec.getFds();
|
|
@@ -129,17 +123,17 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
CurrentNode one=this.tec.getCurrentNode();
|
|
|
Long id =one.getId();
|
|
|
Long primaryKeyId=one.getPkId();
|
|
|
- this.constantMap=tec.getConstantMap();
|
|
|
- this.formDataList=list;
|
|
|
- this.constantMap.put("contractId",contractId);
|
|
|
- keyWord(this.constantMap);
|
|
|
+// tec.constantMap=tec.getConstantMap();
|
|
|
+ tec.formDataList=list;
|
|
|
+ tec.constantMap.put("contractId",contractId);
|
|
|
+ keyWord(tec.constantMap);
|
|
|
ContractInfo info =this.contractInfoService.getById(contractId);
|
|
|
/*合同段信息*/
|
|
|
- this.constantMap.put(CTI,info);
|
|
|
+ tec.constantMap.put(CTI,info);
|
|
|
/*项目信息*/
|
|
|
ProjectInfo pji=this.projectInfoService.getById(info.getPId());
|
|
|
tec.setProjectId(pji.getId());
|
|
|
- this.constantMap.put(PJI,pji);
|
|
|
+ tec.constantMap.put(PJI,pji);
|
|
|
/*wbs节点链*/
|
|
|
List<WbsTreeContract> nodes = wpService.chain(contractId,id,primaryKeyId,null);
|
|
|
if(Func.isEmpty(nodes)){
|
|
@@ -148,18 +142,18 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(Func.isEmpty(nodes)){
|
|
|
this.tec.getLog().append("【WBS信息缺失】");
|
|
|
}
|
|
|
- this.constantMap.put(CHAIN,nodes.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList()));
|
|
|
+ tec.constantMap.put(CHAIN,nodes.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList()));
|
|
|
/*节点参数*/
|
|
|
- this.constantMap.put(WP,getWpMap(one));
|
|
|
+ tec.constantMap.put(WP,getWpMap(one));
|
|
|
/*表格名称*/
|
|
|
List<AppWbsTreeContractVO> tableList =wbsTreeContractService.searchNodeAllTable(primaryKeyId.toString(), "1", contractId.toString(),info.getPId());
|
|
|
- this.constantMap.put(TABLE_LIST,tableList);
|
|
|
+ tec.constantMap.put(TABLE_LIST,tableList);
|
|
|
/*通过判断元素名称来确定,加入汇总公式延后执行*/
|
|
|
- // this.constantMap.put("tableNames",tableList.stream().filter(e->StringUtils.isEquals(e.getIsBussShow(),1)).map(WbsTreeContract::getNodeName).collect(Collectors.toList()));
|
|
|
- this.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList()));
|
|
|
+ // tec.constantMap.put("tableNames",tableList.stream().filter(e->StringUtils.isEquals(e.getIsBussShow(),1)).map(WbsTreeContract::getNodeName).collect(Collectors.toList()));
|
|
|
+ tec.constantMap.put("tableNames",tableList.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList()));
|
|
|
|
|
|
List<String> missingList = new ArrayList<>();
|
|
|
- this.formDataList.forEach(fd->{
|
|
|
+ tec.formDataList.forEach(fd->{
|
|
|
if(fd.executable()){
|
|
|
relyParse(fd.getFormula());
|
|
|
Formula f= fd.getFormula();
|
|
@@ -185,56 +179,67 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
"where a.p_key_id in("+this.tec.getTableAll().stream().map(AppWbsTreeContractVO::getPKeyId).map(Func::toStr).collect(Collectors.joining(","))+") and b.type=8 ");
|
|
|
if(Func.isNotEmpty(textInfoMap)){
|
|
|
Map<String,List<Map<String,Object>>> tmap = textInfoMap.stream().collect(Collectors.groupingBy(m->m.get("code").toString()));
|
|
|
- this.constantMap.put(TEXT_INFO_MAP,tmap);
|
|
|
+ tec.constantMap.put(TEXT_INFO_MAP,tmap);
|
|
|
}
|
|
|
/*公式参数*/
|
|
|
FormulaOption formulaOption = this.formulaOptionService.getOne(Wrappers.<FormulaOption>lambdaQuery().eq(FormulaOption::getParentId,one.getRelateId()).eq(FormulaOption::getContractId,contractId));
|
|
|
if(formulaOption!=null){
|
|
|
/*数据格式 {tablename:{keyxxx:{option:[1|0]}}}*/
|
|
|
- this.constantMap.put(FMOT,JSON.parseObject(formulaOption.getVal(),LinkedHashMap.class));
|
|
|
+ tec.constantMap.put(FMOT,JSON.parseObject(formulaOption.getVal(),LinkedHashMap.class));
|
|
|
}
|
|
|
/*评定表*/
|
|
|
assessmentForm();
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public FormulaDataBlock findFdb(){
|
|
|
+ AppWbsTreeContractVO one =tec.getTableAll().get(0);
|
|
|
+ List<String> ancestor=new ArrayList<>(Arrays.asList(one.getAncestors().split(",")));
|
|
|
+ Collections.reverse(ancestor);
|
|
|
+ FormulaDataBlock fdb= this.formulaDataBlockService.queryOption(Long.parseLong(one.getContractId()),Long.parseLong(ancestor.get(1)),0);
|
|
|
+ if(fdb==null){
|
|
|
+ fdb=new FormulaDataBlock();
|
|
|
+ fdb.setContractId(tec.getContractId());
|
|
|
+ fdb.setSwId(Long.parseLong(ancestor.get(1)));
|
|
|
+ fdb.setType(0);
|
|
|
+ fdb.setVal("[]");
|
|
|
+ }
|
|
|
+ return fdb;
|
|
|
+ }
|
|
|
public void assessmentForm(){
|
|
|
if(tec.getTableAll().stream().anyMatch(e->StringUtils.isEquals(e.getTableType(),5))){
|
|
|
/*评定节点*/
|
|
|
- AppWbsTreeContractVO one =tec.getTableAll().get(0);
|
|
|
- List<String> ancestor=new ArrayList<>(Arrays.asList(one.getAncestors().split(",")));
|
|
|
- Collections.reverse(ancestor);
|
|
|
- FormulaDataBlock fdb = this.formulaDataBlockService.queryOption(Long.parseLong(one.getContractId()),Long.parseLong(ancestor.get(1)),0);
|
|
|
- if(fdb!=null&&Func.isNotBlank(fdb.getVal())){
|
|
|
+ FormulaDataBlock fdb = findFdb();
|
|
|
+ if(!StringUtils.isEquals("[]",fdb.getVal())){
|
|
|
List<ElementBlock> elementBlockList =JSON.parseArray(fdb.getVal(),ElementBlock.class);
|
|
|
Map<String, Measurement> itemsMap = new HashMap<>();
|
|
|
this.formDataMap.values().forEach(e->{
|
|
|
String eName=e.getEName();
|
|
|
- if(eName.contains("实测")&&!eName.contains("平均")){
|
|
|
+ if(eName.contains("实测")&&!eName.contains("平均")&&!eName.contains("率")&&!eName.contains("判")){
|
|
|
String point =FormulaUtils.parseItemName(eName);
|
|
|
Measurement measurement = itemsMap.computeIfAbsent(point,k->new Measurement(point));
|
|
|
- if(eName.contains("偏差")){
|
|
|
- measurement.setValue(e);
|
|
|
- }else if(eName.contains("率")){
|
|
|
- measurement.setPass(e);
|
|
|
- }else if(eName.contains("判")){
|
|
|
- measurement.setJudge(e);
|
|
|
- }
|
|
|
+ measurement.setValue(e);
|
|
|
}
|
|
|
});
|
|
|
if(itemsMap.size()>0){
|
|
|
- itemsMap.values().forEach(i->{
|
|
|
- FormData vf=i.getValue();
|
|
|
- if(vf!=null){
|
|
|
- if(i.getPass()==null){
|
|
|
- i.setPass(tec.getFormDataMap().values().stream().filter(v->v.getTableName().equals(vf.getTableName())&&!v.getCode().equals(vf.getCode())).filter(v->v.getEName().contains(i.getPoint())&&v.getEName().contains("率")).findAny().orElse(null));
|
|
|
- }
|
|
|
- if(i.getJudge()==null){
|
|
|
- i.setJudge(tec.getFormDataMap().values().stream().filter(v->v.getTableName().equals(vf.getTableName())&&!v.getCode().equals(vf.getCode())).filter(v->v.getEName().contains(i.getPoint())&&v.getEName().contains("判")).findAny().orElse(null));
|
|
|
- }
|
|
|
- }
|
|
|
+ tec.getFormDataMap().values().stream()
|
|
|
+ .filter(v -> v.getEName().contains("率") || v.getEName().contains("判"))
|
|
|
+ .forEach(v -> {
|
|
|
+ itemsMap.values().stream()
|
|
|
+ .filter(i -> i.getPass() == null || i.getJudge() == null)
|
|
|
+ .filter(i -> {
|
|
|
+ FormData vf = i.getValue();
|
|
|
+ return vf != null && vf.getTableName().equals(v.getTableName()) && !vf.getCode().equals(v.getCode())&&FormulaUtils.similarity(v.getEName(),vf.getEName())>0.75;
|
|
|
+ }).max(Comparator.comparingDouble((Measurement i)->FormulaUtils.similarity(v.getEName(),i.getValue().getEName())))
|
|
|
+ .ifPresent(i->{
|
|
|
+ if (v.getEName().contains("率") && i.getPass() == null) {
|
|
|
+ i.setPass(v);
|
|
|
+ } else if (v.getEName().contains("判") && i.getJudge() == null) {
|
|
|
+ i.setJudge(v);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
|
|
|
- });
|
|
|
AtomicBoolean update= new AtomicBoolean(false);
|
|
|
itemsMap.values().stream().filter(Measurement::isMatching).forEach(t->{
|
|
|
ElementBlock g=null;
|
|
@@ -247,7 +252,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
if(g==null){
|
|
|
- Optional<ElementBlock> op= elementBlockList.stream().filter(w->FormulaUtils.similarity(w.getEName(),t.getPoint())>0.6).reduce((a, b) -> Comparator.<Double>reverseOrder().compare(FormulaUtils.similarity(a.getEName(),t.getPoint()), FormulaUtils.similarity(b.getEName(),t.getPoint())) <= 0 ? a : b);
|
|
|
+ Optional<ElementBlock> op= elementBlockList.stream().filter(w->FormulaUtils.similarity(w.getEName(),t.getPoint())>0.6).reduce((a, b) -> Comparator.<Double>reverseOrder().compare(FormulaUtils.similarity(a.getEName(),t.getPoint()), FormulaUtils.similarity(b.getEName(),t.getPoint())) <= 0 ? a : b);
|
|
|
if(op.isPresent()){
|
|
|
g=op.get();
|
|
|
}
|
|
@@ -298,7 +303,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
this.formulaDataBlockService.saveOrUpdate(fdb);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -523,7 +527,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*元素动态绑定*/
|
|
|
this.formDataMap.values().stream().filter(e->e.getIsCurrentNodeElement()&&e.getFormula()==null).forEach(e->{
|
|
|
/*执行列表里不存在,且元素的名称和节点参数名称匹配成功*/
|
|
|
- total.stream().filter(p->e.getEName().contains(p.getName().replace("【水】","").trim())&&!this.formDataList.contains(e)).findAny().ifPresent(d->{
|
|
|
+ total.stream().filter(p->e.getEName().contains(p.getName().replace("【水】","").trim())&&!tec.formDataList.contains(e)).findAny().ifPresent(d->{
|
|
|
Formula formula=new Formula();
|
|
|
formula.setOutm(Formula.FULL);
|
|
|
if(RegexUtil.match(ParamElements.LEVEL_REG,d.getV().trim())){
|
|
@@ -535,7 +539,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
e.setFormula(formula);
|
|
|
tec.getLog().append("动态绑定参数:").append(e.getEName()).append(";");
|
|
|
- this.formDataList.add(e);
|
|
|
+ tec.formDataList.add(e);
|
|
|
});
|
|
|
});
|
|
|
return result;
|
|
@@ -543,22 +547,22 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public IFormulaService sort() {
|
|
|
- Map<Boolean,List<FormData>> map = this.formDataList.stream().collect(Collectors.partitioningBy(e->Func.isNotEmpty(e.getFormula())&&e.getFormula().getFormula().contains("E[")));
|
|
|
- this.formDataList.clear();
|
|
|
+ Map<Boolean,List<FormData>> map = tec.formDataList.stream().collect(Collectors.partitioningBy(e->Func.isNotEmpty(e.getFormula())&&e.getFormula().getFormula().contains("E[")));
|
|
|
+ tec.formDataList.clear();
|
|
|
/*没有依赖的*/
|
|
|
List<FormData> simple=map.get(false);
|
|
|
if(CollectionUtil.isNotEmpty(simple)){
|
|
|
- this.formDataList.addAll(simple);
|
|
|
+ tec.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);
|
|
|
+ tec.formDataList.addAll(rely);
|
|
|
}
|
|
|
/*初始化排序值,每个点间隔1000,方便插入*/
|
|
|
AtomicInteger sort= new AtomicInteger();
|
|
|
- this.formDataList.forEach(e->e.setSort(sort.getAndAdd(1000)));
|
|
|
+ tec.formDataList.forEach(e->e.setSort(sort.getAndAdd(1000)));
|
|
|
/*汇总阶段执行的公式*/
|
|
|
summaryPre();
|
|
|
return this;
|
|
@@ -566,20 +570,20 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
/*汇总阶段执行的公式*/
|
|
|
public void summaryPre(){
|
|
|
- this.formDataList.stream().filter(FormData::executable).filter(e->StringUtils.isEquals("CKI",e.getFormula().getNumber())||StringUtils.isEquals("CKD",e.getFormula().getNumber())).forEach(t->this.summary.add(t));
|
|
|
- this.formDataList.removeAll(this.summary);
|
|
|
+ tec.formDataList.stream().filter(FormData::executable).filter(e->StringUtils.isEquals("CKI",e.getFormula().getNumber())||StringUtils.isEquals("CKD",e.getFormula().getNumber())).forEach(t->tec.summary.add(t));
|
|
|
+ tec.formDataList.removeAll(tec.summary);
|
|
|
/*监表的处理*/
|
|
|
Optional<AppWbsTreeContractVO> aop=tec.getTableAll().stream().filter(e->e.getNodeName().contains("A15")).findAny();
|
|
|
if(aop.isPresent()){
|
|
|
/*存在监表,则需要收集检查项目和检查时间等元素*/
|
|
|
- Optional<AppWbsTreeContractVO> wop=tec.getTableAll().stream().filter(e->e.getNodeName().contains("检验单")||e.getNodeName().contains("检验表")).findAny();
|
|
|
- if(wop.isPresent()){
|
|
|
+ List<String> wop=tec.getTableAll().stream().filter(e->e.getNodeName().contains("检验单")||e.getNodeName().contains("检验表")).map(AppWbsTreeContractVO::getInitTableName).distinct().collect(Collectors.toList());
|
|
|
+ if(wop.size()>0){
|
|
|
/*存在检验表*/
|
|
|
- tec.getKeyMappers().stream().filter(e->StringUtils.isEquals(wop.get().getInitTableName(),e.getTableName())&&this.formDataMap.containsKey(e.getCode())).forEach(k->{
|
|
|
+ tec.getKeyMappers().stream().filter(e->wop.contains(e.getTableName())&&this.formDataMap.containsKey(e.getCode())).forEach(k->{
|
|
|
if(k.getEName().contains("实测值")&&k.getEName().contains("偏差值")){
|
|
|
- this.checkItems.add(this.formDataMap.get(k.getCode()));
|
|
|
+ tec.checkItems.add(this.formDataMap.get(k.getCode()));
|
|
|
}else if(k.getEName().contains("检验日期")){
|
|
|
- this.checkDate.add(this.formDataMap.get(k.getCode()));
|
|
|
+ tec.checkDate.add(this.formDataMap.get(k.getCode()));
|
|
|
}
|
|
|
});
|
|
|
}else{
|
|
@@ -588,20 +592,27 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
tec.getKeyMappers().stream().filter(k->recordTable.contains(k.getTableName())).map(k->k.getCode()+"@"+k.getEName()).distinct().forEach(k->{
|
|
|
String[] ka=k.split("@");
|
|
|
if(ka[1].contains("实测值")){
|
|
|
- this.checkItems.add(this.formDataMap.get(ka[0]));
|
|
|
+ tec.checkItems.add(this.formDataMap.get(ka[0]));
|
|
|
}else if(ka[1].contains("日期")||ka[1].contains("年月日")){
|
|
|
- this.checkDate.add(this.formDataMap.get(ka[0]));
|
|
|
+ tec.checkDate.add(this.formDataMap.get(ka[0]));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ if(tec.checkItems.size()>0){
|
|
|
+ /**排序*/
|
|
|
+ List<String> iniTableNames=tec.getTableAll().stream().map(AppWbsTreeContractVO::getInitTableName).distinct().collect(Collectors.toList());
|
|
|
+ tec.checkItems= tec.checkItems.stream().sorted(Comparator.comparingInt((FormData i)->iniTableNames.indexOf(i.getTableName())).thenComparingInt(FormData::getMaxRow)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ System.out.println();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public IFormulaService pre() {
|
|
|
- if(CollectionUtil.isNotEmpty(this.formDataList)){
|
|
|
- for(FormData fd:this.formDataList){
|
|
|
+ if(CollectionUtil.isNotEmpty(tec.formDataList)){
|
|
|
+ for(FormData fd:tec.formDataList){
|
|
|
/*预处理公式脚本,只做文本转换不做计算*/
|
|
|
if(!fd.executable()){
|
|
|
/*不存公式,则认为执行完成,不会再主动执行*/
|
|
@@ -644,7 +655,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public IFormulaService special() {
|
|
|
- for(FormData fd:this.formDataList) {
|
|
|
+ for(FormData fd:tec.formDataList) {
|
|
|
try {
|
|
|
if(Func.isNotEmpty(fd.getFormula())) {
|
|
|
formulaStrategyFactory.get(fd).forEach(e -> e.execute(tec));
|
|
@@ -675,7 +686,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(op.isPresent()){
|
|
|
checkTable=op.get().getInitTableName();
|
|
|
}
|
|
|
- for(FormData fd:this.formDataList){
|
|
|
+ for(FormData fd:tec.formDataList){
|
|
|
if(fd.verify()){
|
|
|
Formula formula =fd.getFormula();
|
|
|
String f=formula.getFormula();
|
|
@@ -684,7 +695,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*非解析器自定义运算*/
|
|
|
preCalc(fd);
|
|
|
tmpFc(fd);
|
|
|
- Map<String, Object> currentMap = new HashMap<>(this.constantMap);
|
|
|
+ Map<String, Object> currentMap = new HashMap<>(tec.constantMap);
|
|
|
List<String> relyList = fd.getFormula().getRelyList();
|
|
|
if(CollectionUtil.isNotEmpty(relyList)){
|
|
|
List<FormData> ele = new ArrayList<>();
|
|
@@ -716,7 +727,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
List<LocalVariable> local= new ArrayList<>();
|
|
|
while (cda.hasNext()){
|
|
|
LinkedHashMap<String,ElementData> tip= cda.next();
|
|
|
- Map<String, Object> variable = new HashMap<>(this.constantMap);
|
|
|
+ Map<String, Object> variable = new HashMap<>(tec.constantMap);
|
|
|
Map<String,Object> em= (Map<String, Object>) variable.computeIfAbsent(E, k->new HashMap<>());
|
|
|
int index= new ArrayList<>(tip.values()).get(0).getIndex();
|
|
|
for(Map.Entry<String,ElementData> se:tip.entrySet()){
|
|
@@ -731,7 +742,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
local.add(new LocalVariable(index,f,variable));
|
|
|
}
|
|
|
if(local.size()>0){
|
|
|
- List<Object> values = slice(local,this.constantMap,f);
|
|
|
+ List<Object> values = slice(local,tec.constantMap,f);
|
|
|
if(fd.getTableName().equals(checkTable)){
|
|
|
FormulaUtils.write(fd,values,false);
|
|
|
}else{
|
|
@@ -836,7 +847,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
if(tmp!=null){
|
|
|
tmp.setIsCurrentNodeElement(true);
|
|
|
this.formDataMap.put(tmp.getCode(),tmp);
|
|
|
- this.formDataList.add(tmp);
|
|
|
+ tec.formDataList.add(tmp);
|
|
|
}
|
|
|
});
|
|
|
/*生成元素映射关系*/
|
|
@@ -883,11 +894,11 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
Map<String,Object> copyMap= new HashMap<>();
|
|
|
if(sourceFds.size()>0){
|
|
|
sourceFds.forEach(d->{
|
|
|
- copyMap.put(d.getEName().trim(),d.getValues().stream().map(ElementData::getValue).filter(StringUtils::isNotEmpty).findAny().orElse(""));
|
|
|
+ copyMap.put(d.getSimplifyName(),d.getValues().stream().map(ElementData::getValue).filter(StringUtils::isNotEmpty).findAny().orElse(""));
|
|
|
});
|
|
|
}
|
|
|
- subTableFds.stream().filter(s-> !SubTable.KEYS.contains(s.getEName().trim())).filter(s->copyMap.containsKey(s.getEName().trim())).forEach(t->{
|
|
|
- Object val = copyMap.get(t.getEName().trim());
|
|
|
+ subTableFds.stream().filter(s-> !SubTable.KEYS.contains(s.getEName().trim())).filter(s->copyMap.containsKey(s.getSimplifyName())).forEach(t->{
|
|
|
+ Object val = copyMap.get(t.getSimplifyName());
|
|
|
t.getValues().forEach(e->e.setValue(val));
|
|
|
t.setUpdate(1);
|
|
|
});
|
|
@@ -905,29 +916,29 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/**汇总处理*/
|
|
|
public void summaryCalc(){
|
|
|
try{
|
|
|
- if(this.summary.size()>0){
|
|
|
+ if(tec.summary.size()>0){
|
|
|
/**/
|
|
|
- List<String> result=this.checkItems.stream().filter(fdTmp->fdTmp.getValues().stream().map(ElementData::getValue).anyMatch(e->StringUtils.isNotEmpty(e)&&StringUtils.isNotEquals("/",e))).map(FormData::getEName).map(FormulaUtils::parseItemName).distinct().collect(Collectors.toList());
|
|
|
- Optional<FormData> opk= this.summary.stream().filter(FormData::executable).filter(f->StringUtils.isEquals(f.getFormula().getNumber(),CHECK_ITEMS)).findAny();
|
|
|
+ List<String> result=tec.checkItems.stream().filter(fdTmp->fdTmp.getValues().stream().map(ElementData::getValue).anyMatch(e->StringUtils.isNotEmpty(e)&&StringUtils.isNotEquals("/",e))).map(FormData::getEName).map(FormulaUtils::parseItemName).distinct().collect(Collectors.toList());
|
|
|
+ Optional<FormData> opk= tec.summary.stream().filter(FormData::executable).filter(f->StringUtils.isEquals(f.getFormula().getNumber(),CHECK_ITEMS)).findAny();
|
|
|
List<String> history=null;
|
|
|
if(opk.isPresent()&&!opk.get().empty()){
|
|
|
/*假如已经存在内容,则需要筛选出手填部分*/
|
|
|
history= Arrays.asList(opk.get().getValues().get(0).stringValue().replaceAll("[\\s\\n]+","").split("[,、,]"));
|
|
|
}
|
|
|
if(history!=null&&history.size()>0){
|
|
|
- List<String> itemAll=this.checkItems.stream().map(FormData::getEName).map(FormulaUtils::parseItemName).distinct().collect(Collectors.toList());
|
|
|
+ List<String> itemAll=tec.checkItems.stream().map(FormData::getEName).map(FormulaUtils::parseItemName).distinct().collect(Collectors.toList());
|
|
|
List<String> customize=history.stream().filter(s->!itemAll.contains(s)).collect(Collectors.toList());
|
|
|
result.addAll(customize);
|
|
|
}
|
|
|
- this.constantMap.put(CHECK_ITEMS,result);
|
|
|
- this.constantMap.put("CKD",this.checkDate.stream().flatMap(k->k.getValues().stream()).map(ElementData::stringValue).filter(StringUtils::isNotEmpty).reduce((a, b) -> Comparator.<DateTime>reverseOrder().compare(new DateTime(a), new DateTime(b)) <= 0 ? a : b).orElse(null));
|
|
|
- this.summary.forEach(e->{
|
|
|
+ tec.constantMap.put(CHECK_ITEMS,result);
|
|
|
+ tec.constantMap.put("CKD",tec.checkDate.stream().flatMap(k->k.getValues().stream()).map(ElementData::stringValue).filter(StringUtils::isNotEmpty).reduce((a, b) -> Comparator.<DateTime>reverseOrder().compare(new DateTime(a), new DateTime(b)) <= 0 ? a : b).orElse(null));
|
|
|
+ tec.summary.forEach(e->{
|
|
|
/*处理脚本*/
|
|
|
e.getFormula().setFormula(e.getFormula().getNumber());
|
|
|
});
|
|
|
- this.summary.forEach(e->{
|
|
|
+ tec.summary.forEach(e->{
|
|
|
/*执行公式*/
|
|
|
- Object data = Expression.parse(e.getFormula().getFormula()).calculate(this.constantMap);
|
|
|
+ Object data = Expression.parse(e.getFormula().getFormula()).calculate(tec.constantMap);
|
|
|
if(data!=null){
|
|
|
FormulaUtils.write(e,data,false);
|
|
|
e.setUpdate(1);
|
|
@@ -947,20 +958,10 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/**分项汇总数据*/
|
|
|
public void doForDataBlock(){
|
|
|
try {
|
|
|
- AppWbsTreeContractVO one =tec.getTableAll().get(0);
|
|
|
- List<String> ancestor=new ArrayList<>(Arrays.asList(one.getAncestors().split(",")));
|
|
|
- Collections.reverse(ancestor);
|
|
|
- FormulaDataBlock fdb = this.formulaDataBlockService.queryOption(Long.parseLong(one.getContractId()),Long.parseLong(ancestor.get(1)),0);
|
|
|
+ FormulaDataBlock fdb=findFdb();
|
|
|
List<ElementBlock> elementBlockList=new ArrayList<>();
|
|
|
Map<String,ElementBlock> elementBlockMap =new HashMap<>();
|
|
|
Map<String,ItemBlock>itemBlockMap =new HashMap<>();
|
|
|
- if(fdb==null){
|
|
|
- fdb=new FormulaDataBlock();
|
|
|
- fdb.setContractId(tec.getContractId());
|
|
|
- fdb.setSwId(Long.parseLong(ancestor.get(1)));
|
|
|
- fdb.setType(0);
|
|
|
- fdb.setVal("[]");
|
|
|
- }
|
|
|
if(Func.isNotBlank(fdb.getVal())) {
|
|
|
elementBlockList = JSON.parseArray(fdb.getVal(), ElementBlock.class);
|
|
|
elementBlockList.forEach(eb->{
|
|
@@ -975,14 +976,14 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
});
|
|
|
}
|
|
|
List<ElementBlock> finalElementBlockList = elementBlockList;
|
|
|
- this.checkItems.stream().filter(e->!e.empty()).forEach(c->{
|
|
|
+ tec.checkItems.stream().filter(e->!e.empty()).forEach(c->{
|
|
|
ElementBlock eb =elementBlockMap.get(c.getCode());
|
|
|
ItemBlock targetItem=itemBlockMap.get(c.getCode()+":"+tec.getCurrentNode().getPkId());
|
|
|
List<Object> list = c.getValues().stream().map(ElementData::getValue).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
|
|
|
/*1.无任何记录,当前页无数据,则不需要处理 2.存在记录当前无数据,则要消除 3.没有记录当前有数据,则需要增加 4.有记录有当前记录,则需更新*/
|
|
|
if(Func.isNotEmpty(list)||targetItem!=null){
|
|
|
- FormData designList=tec.getFormDataMap().values().stream().filter(t->t.getEName().contains(FormulaUtils.parseItemName(c.getEName()))&&t.getEName().contains("设计")&&StringUtils.isEquals(t.getTableName(),c.getTableName())).collect(Collectors.toList()).get(0);
|
|
|
- FormData pass=tec.getFormDataMap().values().stream().filter(t->t.getEName().contains(FormulaUtils.parseItemName(c.getEName()))&&t.getEName().contains("合格")&&StringUtils.isEquals(t.getTableName(),c.getTableName())).collect(Collectors.toList()).get(0);
|
|
|
+ FormData designList=itemMatch(c,0);
|
|
|
+ FormData pass=itemMatch(c,1);
|
|
|
if(targetItem==null){
|
|
|
if(eb==null){
|
|
|
eb=new ElementBlock();
|
|
@@ -1036,6 +1037,23 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Description 根据实测值元素匹配相关联的元素如设计值合格率
|
|
|
+ * @Param [measured:实测值, type:0设计值 1合格率]
|
|
|
+ * @Date 2023.04.25 14:41
|
|
|
+ **/
|
|
|
+ public FormData itemMatch(FormData measured,@NotNull Integer type){
|
|
|
+ Predicate<FormData> predicate =(FormData t)-> StringUtils.isEquals(t.getTableName(),measured.getTableName());
|
|
|
+ if(type ==0){
|
|
|
+ predicate= predicate.and((FormData t)->t.getEName().contains("设计"));
|
|
|
+ }else {
|
|
|
+ predicate= predicate.and((FormData t)->t.getEName().contains("合格"));
|
|
|
+ }
|
|
|
+ predicate= predicate.and((FormData t)->FormulaUtils.similarity(t.getEName(),measured.getEName())>0.75);
|
|
|
+ //FormData target=tec.getFormDataMap().values().stream().filter(t->StringUtils.isEquals(t.getTableName(),measured.getTableName())&&t.getEName().contains("设计")&&FormulaUtils.similarity(t.getEName(),measured.getEName())>0.75).max(Comparator.comparingDouble((FormData t)->FormulaUtils.similarity(t.getEName(),measured.getEName()))).orElse(null);
|
|
|
+ return tec.getFormDataMap().values().stream().filter(predicate).max(Comparator.comparingDouble((FormData t)->FormulaUtils.similarity(t.getEName(),measured.getEName()))).orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
public void write(FormData fd,Object data){
|
|
|
/*如果需要向额外元素或对象输出数据,在此处修改*/
|
|
|
fd.setUpdate(1);
|
|
@@ -1128,7 +1146,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
@Override
|
|
|
public void format() {
|
|
|
/*数据格式化*/
|
|
|
- for(FormData fd:this.formDataList){
|
|
|
+ for(FormData fd:tec.formDataList){
|
|
|
if(fd.verify()){
|
|
|
/*保留小数位*/
|
|
|
if(fd.getFormula()!=null&&!fd.empty()&&fd.getValues().stream().map(ElementData::getValue).anyMatch(StringUtils::isDouble)){
|
|
@@ -1341,7 +1359,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
if(kOp.isPresent()){
|
|
|
/*表名+合同段+父节点*/
|
|
|
String findStr="OP['"+fd.getTableName()+"']['"+fd.getKey()+"']['TF']";
|
|
|
- flag=StringUtils.handleNull(Expression.parse(findStr).calculate(this.constantMap));
|
|
|
+ flag=StringUtils.handleNull(Expression.parse(findStr).calculate(tec.constantMap));
|
|
|
}
|
|
|
}else if(flag.contains("E[")){
|
|
|
List<FormData> target = getFormDataByCode(flag);
|
|
@@ -1385,7 +1403,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
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<>());
|
|
|
+ Map<String,List<Map<String,Object>>> textInfoMap= (Map<String, List<Map<String, Object>>>) tec.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();
|
|
@@ -1422,7 +1440,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
|
|
|
|
|
|
public Map<String,Object> createCurrentMap(String el){
|
|
|
- Map<String,Object> currentMap= new HashMap<String,Object>(this.constantMap);
|
|
|
+ Map<String,Object> currentMap= new HashMap<String,Object>(tec.constantMap);
|
|
|
List<FormData> fds= getFormDataByCode(String.join(",", getCodeByEl(el)));
|
|
|
if(Func.isNotEmpty(fds)){
|
|
|
Map<String,Object> Em= (Map<String, Object>) currentMap.computeIfAbsent(E, k->new HashMap<String,Object>());
|
|
@@ -1460,7 +1478,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
}
|
|
|
String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
fd.getFormula().setFormula(key);
|
|
|
- this.constantMap.put(key,data);
|
|
|
+ tec.constantMap.put(key,data);
|
|
|
}else{
|
|
|
fd.getFormula().setFormula(StringPool.EMPTY);
|
|
|
}
|
|
@@ -1498,7 +1516,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
/**把计算结果放入固定常量集,创建key来引用*/
|
|
|
public String putDataWithKey(Object data){
|
|
|
String key ="HA"+HashUtil.identityHashCode(data);
|
|
|
- this.constantMap.put(key,data);
|
|
|
+ tec.constantMap.put(key,data);
|
|
|
return key;
|
|
|
}
|
|
|
|