|
@@ -75,7 +75,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
private final ITextdictInfoService textDictInfoService;
|
|
|
private final IFormulaDataBlockService formulaDataBlockService;
|
|
|
|
|
|
- /** private final Container env;*/
|
|
|
private TableElementConverter tec;
|
|
|
// private Map<String,Object> constantMap;
|
|
|
// private List<FormData> formDataList;
|
|
@@ -184,7 +183,6 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
/*公式参数*/
|
|
|
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]}}}*/
|
|
|
tec.constantMap.put(FMOT,JSON.parseObject(formulaOption.getVal(),LinkedHashMap.class));
|
|
|
}
|
|
|
/*评定表*/
|
|
@@ -207,6 +205,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
|
|
|
public Long findFirstParentId(){
|
|
|
+ /*分项实测项目锚定点*/
|
|
|
int max=10;
|
|
|
int loop=0;
|
|
|
Long parentId= tec.getCurrentNode().getParentId();
|
|
@@ -223,72 +222,73 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
return parentId;
|
|
|
}
|
|
|
-
|
|
|
+ /*评定表处理*/
|
|
|
public void assessmentForm(){
|
|
|
- if(tec.getTableAll().stream().anyMatch(e->StringUtils.isEquals(e.getTableType(),5))){
|
|
|
- /*评定节点*/
|
|
|
- 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("平均")&&!eName.contains("率")&&!eName.contains("判")){
|
|
|
- String point =FormulaUtils.parseItemName(eName);
|
|
|
- /*评定匹配检验单的元素用相似匹配*/
|
|
|
- Measurement measurement = itemsMap.computeIfAbsent(point,k->new Measurement(point));
|
|
|
- measurement.setValue(e);
|
|
|
- }
|
|
|
- });
|
|
|
- if(itemsMap.size()>0){
|
|
|
- /*表内用同行匹配*/
|
|
|
- List<FormData> primary = tec.getFormDataMap().values().stream().filter(v -> v.getEName().contains("率") || v.getEName().contains("判")).collect(Collectors.toList());
|
|
|
- itemsMap.values().forEach(i->{
|
|
|
- FormData vf = i.getValue();
|
|
|
- primary.stream().filter(p->vf.getMaxRow().equals(p.getMaxRow()) && vf.getTableName().equals(p.getTableName())).forEach(t->{
|
|
|
- if (t.getEName().contains("率") ) {
|
|
|
- i.setPass(t);
|
|
|
- } else if (t.getEName().contains("判")) {
|
|
|
- i.setJudge(t);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- AtomicBoolean update= new AtomicBoolean(false);
|
|
|
- itemsMap.values().stream().filter(Measurement::isMatching).forEach(t->{
|
|
|
- ElementBlock g=null;
|
|
|
- FormData vfd=t.getValue();
|
|
|
- if(vfd.executable()&&vfd.getFormula().getRelyList()!=null){
|
|
|
- List<String> relyList = vfd.getFormula().getRelyList();
|
|
|
- /*先从公式去匹配*/
|
|
|
- Optional<ElementBlock> op= elementBlockList.stream().filter(e->relyList.contains(e.getCode())).findAny();
|
|
|
- if(op.isPresent()){
|
|
|
- g=op.get();
|
|
|
- }
|
|
|
+ try {
|
|
|
+ if (tec.getTableAll().stream().anyMatch(e -> StringUtils.isEquals(e.getTableType(), 5))) {
|
|
|
+ /*评定节点*/
|
|
|
+ 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("平均") && !eName.contains("率") && !eName.contains("判")) {
|
|
|
+ String point = FormulaUtils.parseItemName(eName);
|
|
|
+ /*评定匹配检验单的元素用相似匹配*/
|
|
|
+ Measurement measurement = itemsMap.computeIfAbsent(point, k -> new Measurement(point));
|
|
|
+ measurement.setValue(e);
|
|
|
}
|
|
|
- if(g==null){
|
|
|
- Optional<ElementBlock> op= elementBlockList.stream().filter(w->FormulaUtils.similarity(w.getEName(),t.getPoint())>0.6).max(Comparator.comparingDouble((ElementBlock b)->FormulaUtils.similarity(b.getEName(),t.getPoint())));
|
|
|
- /*相似匹配*/
|
|
|
- if(op.isPresent()){
|
|
|
- g=op.get();
|
|
|
+ });
|
|
|
+ if (itemsMap.size() > 0) {
|
|
|
+ /*表内用同行匹配*/
|
|
|
+ List<FormData> primary = tec.getFormDataMap().values().stream().filter(v -> v.getEName().contains("率") || v.getEName().contains("判")).collect(Collectors.toList());
|
|
|
+ itemsMap.values().forEach(i -> {
|
|
|
+ FormData vf = i.getValue();
|
|
|
+ primary.stream().filter(p -> vf.getMaxRow().equals(p.getMaxRow()) && vf.getTableName().equals(p.getTableName())).forEach(t -> {
|
|
|
+ if (t.getEName().contains("率")) {
|
|
|
+ i.setPass(t);
|
|
|
+ } else if (t.getEName().contains("判")) {
|
|
|
+ i.setJudge(t);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ AtomicBoolean update = new AtomicBoolean(false);
|
|
|
+ itemsMap.values().stream().filter(Measurement::isMatching).forEach(t -> {
|
|
|
+ ElementBlock g = null;
|
|
|
+ FormData vfd = t.getValue();
|
|
|
+ if (vfd.executable() && vfd.getFormula().getRelyList() != null) {
|
|
|
+ List<String> relyList = vfd.getFormula().getRelyList();
|
|
|
+ /*先从公式去匹配*/
|
|
|
+ Optional<ElementBlock> op = elementBlockList.stream().filter(e -> relyList.contains(e.getCode())).findAny();
|
|
|
+ if (op.isPresent()) {
|
|
|
+ g = op.get();
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if(g!=null){
|
|
|
- List<ItemBlock> itemBlockList =g.getList();
|
|
|
- int originSize=itemBlockList.size();
|
|
|
- List<Long> ids = this.jdbcTemplate.queryForList("select b.p_key_id from m_wbs_tree_contract a join m_wbs_tree_contract b on (a.parent_id=b.parent_id and a.contract_id=b.contract_id) where a.p_key_id="+tec.getCurrentNode().getPkId()+" and b.is_deleted=0 and b.node_type=6",Long.class);
|
|
|
- itemBlockList.removeIf(ik->!ids.contains(ik.getPkeyId()));
|
|
|
- if(itemBlockList.size()>0){
|
|
|
- int total=itemBlockList.stream().mapToInt(ItemBlock::getSubTotal).sum();
|
|
|
- int passNum=itemBlockList.stream().mapToInt(ItemBlock::getSubPass).sum();
|
|
|
- double passRate=100*(double)passNum/(double) total;
|
|
|
- FormulaUtils.write(t.getPass(),StringUtils.number2String(passRate,1),false);
|
|
|
- if(passRate>=60){
|
|
|
- FormulaUtils.write(t.getJudge(),"合格",false);
|
|
|
+ if (g == null) {
|
|
|
+ Optional<ElementBlock> op = elementBlockList.stream().filter(w -> FormulaUtils.similarity(w.getEName(), t.getPoint()) > 0.6).max(Comparator.comparingDouble((ElementBlock b) -> FormulaUtils.similarity(b.getEName(), t.getPoint())));
|
|
|
+ /*相似匹配*/
|
|
|
+ if (op.isPresent()) {
|
|
|
+ g = op.get();
|
|
|
}
|
|
|
- itemBlockList.sort(Comparator.comparingInt(a->ids.indexOf(a.getPkeyId())));
|
|
|
- List<String> values=itemBlockList.stream().map(ItemBlock::getData).flatMap(v->v.stream().flatMap(Collection::stream)).map(Object::toString).collect(Collectors.toList());
|
|
|
- int scale = StringUtils.getScale(values);
|
|
|
- FormulaUtils.write(t.getValue(),values.stream().map(u->StringUtils.number2String(u,scale)).collect(Collectors.toList()), true);
|
|
|
+ }
|
|
|
+ if (g != null) {
|
|
|
+ List<ItemBlock> itemBlockList = g.getList();
|
|
|
+ int originSize = itemBlockList.size();
|
|
|
+ List<Long> ids = this.jdbcTemplate.queryForList("select b.p_key_id from m_wbs_tree_contract a join m_wbs_tree_contract b on (a.parent_id=b.parent_id and a.contract_id=b.contract_id) where a.p_key_id=" + tec.getCurrentNode().getPkId() + " and b.is_deleted=0 and b.node_type=6", Long.class);
|
|
|
+ itemBlockList.removeIf(ik -> !ids.contains(ik.getPkeyId()));
|
|
|
+ if (itemBlockList.size() > 0) {
|
|
|
+ int total = itemBlockList.stream().mapToInt(ItemBlock::getSubTotal).sum();
|
|
|
+ int passNum = itemBlockList.stream().mapToInt(ItemBlock::getSubPass).sum();
|
|
|
+ double passRate = 100 * (double) passNum / (double) total;
|
|
|
+ FormulaUtils.write(t.getPass(), StringUtils.number2String(passRate, 1), false);
|
|
|
+ if (passRate >= 60) {
|
|
|
+ FormulaUtils.write(t.getJudge(), "合格", false);
|
|
|
+ }
|
|
|
+ itemBlockList.sort(Comparator.comparingInt(a -> ids.indexOf(a.getPkeyId())));
|
|
|
+ List<String> values = itemBlockList.stream().map(ItemBlock::getData).flatMap(v -> v.stream().flatMap(Collection::stream)).map(Object::toString).collect(Collectors.toList());
|
|
|
+ int scale = StringUtils.getScale(values);
|
|
|
+ FormulaUtils.write(t.getValue(), values.stream().map(u -> StringUtils.number2String(u, scale)).collect(Collectors.toList()), true);
|
|
|
|
|
|
// if(t.getValue().getEName().contains("±")){
|
|
|
// /*存在偏差范围则获取的是偏差值:实测-设计*/
|
|
@@ -306,19 +306,22 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
// }else{
|
|
|
// FormulaUtils.write(t.getValue(),itemBlockList.stream().map(ItemBlock::getData).flatMap(v->v.stream().flatMap(Collection::stream)).collect(Collectors.toList()),true);
|
|
|
// }
|
|
|
+ }
|
|
|
+ t.flush();
|
|
|
+ if (originSize > 0 && originSize != itemBlockList.size()) {
|
|
|
+ g.setList(itemBlockList);
|
|
|
+ update.set(true);
|
|
|
+ }
|
|
|
}
|
|
|
- t.flush();
|
|
|
- if(originSize>0&&originSize!=itemBlockList.size()){
|
|
|
- g.setList(itemBlockList);
|
|
|
- update.set(true);
|
|
|
- }
|
|
|
+ });
|
|
|
+ if (update.get()) {
|
|
|
+ this.formulaDataBlockService.saveOrUpdate(fdb);
|
|
|
}
|
|
|
- });
|
|
|
- if(update.get()){
|
|
|
- this.formulaDataBlockService.saveOrUpdate(fdb);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -562,24 +565,28 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
|
|
|
@Override
|
|
|
public IFormulaService sort() {
|
|
|
- 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)){
|
|
|
- tec.formDataList.addAll(simple);
|
|
|
- }
|
|
|
- /*有依赖的*/
|
|
|
- List<FormData> rely= map.get(true);
|
|
|
- if(CollectionUtil.isNotEmpty(rely)){
|
|
|
- sort(rely,((rely.size()+1)/2)*rely.size());
|
|
|
- tec.formDataList.addAll(rely);
|
|
|
+ try {
|
|
|
+ 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)) {
|
|
|
+ tec.formDataList.addAll(simple);
|
|
|
+ }
|
|
|
+ /*有依赖的*/
|
|
|
+ List<FormData> rely = map.get(true);
|
|
|
+ if (CollectionUtil.isNotEmpty(rely)) {
|
|
|
+ sort(rely, ((rely.size() + 1) / 2) * rely.size());
|
|
|
+ tec.formDataList.addAll(rely);
|
|
|
+ }
|
|
|
+ /*初始化排序值,每个点间隔1000,方便插入*/
|
|
|
+ AtomicInteger sort = new AtomicInteger();
|
|
|
+ tec.formDataList.forEach(e -> e.setSort(sort.getAndAdd(1000)));
|
|
|
+ /*汇总阶段执行的公式*/
|
|
|
+ summaryPre();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- /*初始化排序值,每个点间隔1000,方便插入*/
|
|
|
- AtomicInteger sort= new AtomicInteger();
|
|
|
- tec.formDataList.forEach(e->e.setSort(sort.getAndAdd(1000)));
|
|
|
- /*汇总阶段执行的公式*/
|
|
|
- summaryPre();
|
|
|
return this;
|
|
|
}
|
|
|
|
|
@@ -1030,7 +1037,9 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
|
|
|
}
|
|
|
if(Func.isNotEmpty(list)){
|
|
|
targetItem.setSubTotal(list.size());
|
|
|
- targetItem.setDesigns(designList.getValues().stream().map(ElementData::getValue).flatMap(e->CustomFunction.obj2ListNe(e).stream()).filter(StringUtils::isNumber).map(StringUtils::obj2Double).collect(Collectors.toList()));
|
|
|
+ if(Func.isNotEmpty(designList)) {
|
|
|
+ targetItem.setDesigns(designList.getValues().stream().map(ElementData::getValue).flatMap(e -> CustomFunction.obj2ListNe(e).stream()).filter(StringUtils::isNumber).map(StringUtils::obj2Double).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
AtomicInteger index= new AtomicInteger();
|
|
|
int len=targetItem.getDesigns().size();
|
|
|
if(len>0){
|
|
@@ -1414,7 +1423,7 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
while (m.find()){
|
|
|
String el=m.group();
|
|
|
String pstr=el.replaceAll("^"+FC_REG+"ifelse\\(","").replaceAll("\\)$","");
|
|
|
- String pa[]=pstr.split(",");
|
|
|
+ String[] pa =pstr.split(",");
|
|
|
if(pa.length==3){
|
|
|
Object data = Expression.parse(pa[0]+"?"+pa[1]+":"+pa[2]).calculate(createCurrentMap(el));
|
|
|
f=f.replace(el,putDataWithKey(data));
|
|
@@ -1426,12 +1435,38 @@ public List<ElementData> setScale(Integer scale,List<ElementData> data){
|
|
|
max++;
|
|
|
}while (f.contains("ifelse")&&max<20);
|
|
|
}
|
|
|
+ if(f.contains("avg4segment")){
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(avg4segment)\\(([^)]+)\\)",f);
|
|
|
+ while (m.find()){
|
|
|
+ String[] args=m.group(2).split(",");
|
|
|
+ List<FormData> target = getFormDataByCode(args[0]);
|
|
|
+ if(!target.isEmpty()){
|
|
|
+ FormData a=target.get(0);
|
|
|
+ int n=Math.max(1,a.coordsList.size()/fd.getCoordsList().size());
|
|
|
+ List<Object> data=CustomFunction.avg4segment(a.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()),n);
|
|
|
+ f=f.replace(m.group(),putDataWithKey(data));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(f.contains("skip")){
|
|
|
+ Matcher m = RegexUtils.matcher(FC_REG+"(skip)\\(([^)]+)\\)",f);
|
|
|
+ while (m.find()){
|
|
|
+ String[] args=m.group(2).split(",");
|
|
|
+ List<FormData> target = getFormDataByCode(args[0]);
|
|
|
+ if(!target.isEmpty()){
|
|
|
+ FormData a=target.get(0);
|
|
|
+ a.setOffset(StringUtils.handleObj2Integer(args[1]));
|
|
|
+ f=f.replace(m.group(),args[0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
if(f.contains("quantity")){
|
|
|
/*聚合*/
|
|
|
Matcher m = RegexUtils.matcher(FC_REG+"(quantity)\\(([^)]+)\\)",f);
|
|
|
while (m.find()) {
|
|
|
Object data=null;
|
|
|
List<String> codeList = getCodeList(m.group(2));
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
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)){
|