Przeglądaj źródła

公式相关:测量相关元素名称规则

yangyj 2 lat temu
rodzic
commit
4062340738

+ 78 - 73
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -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();
         }
     }
 
@@ -1034,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){