Browse Source

公式相关:合格率bug

yangyj 1 year ago
parent
commit
2e91985adf

+ 4 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/FormulaController.java

@@ -515,8 +515,11 @@ public class FormulaController {
             String parentId = one.getParentId().toString();
             while (loop < max && StringUtils.isNotEquals(0, parentId)) {
                 WbsTreeContract next = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getContractId, one.getContractId()).eq(WbsTreeContract::getId, parentId));
+                if(next==null){
+                    return R.fail("断链");
+                }
                 parentId = next.getParentId().toString();
-                list.add(Func.isNotBlank(next.getNodeName()) ? next.getNodeName() : next.getFullName());
+                list.add(Func.isNotBlank(next.getFullName()) ? next.getFullName() : next.getNodeName());
                 loop++;
             }
             ContractInfo info = contractInfoService.getById(one.getContractId());

+ 48 - 144
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -1973,113 +1973,10 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                          }
                      }
                  }
+                 formula.setFormula(f);
                  if(f.contains("quantity")){
-                     /*聚合*/
-              /*       Matcher m = RegexUtils.matcher(FC_REG+"(quantity)\\(([^)]+)\\)",f);
-                     while (m.find()) {
-                         Object data=null;
-                         List<String> codeList = FormulaUtils.getCodeList(m.group(2));
-                       {
-                             FormData dataFd=tec.formDataMap.get(codeList.get(0));
-                             String designStr=codeList.get(1);
-                             FormData designFd=tec.formDataMap.get(designStr);
-                             String devStr=StringUtils.isNotEmpty(formula.getDev())?formula.getDev():fd.getEAllowDeviation();
-                             if(StringUtils.isEmpty(devStr)){
-                                 *//*数据库找不到的情况就读取Excel*//*
-                                 if(tec.wkbMap.isEmpty()){
-                                     *//*初始化*//*
-                                    List<String> tableNames4Excel=  tec.getFormDataList().stream().filter(FormData::executable).filter(e->e.info().contains("quantity")).map(FormData::getTableName).distinct().collect(Collectors.toList());
-                                    if(!tableNames4Excel.isEmpty()){
-                                        List<String> ids =tec.getTableAll().stream().filter(e->tableNames4Excel.contains(e.getInitTableName())).map(NodeTable::getPKeyId).map(String::valueOf).collect(Collectors.toList());
-                                        List<Map<String,Object>> listMaps=  this.jdbcTemplate.queryForList("select a.p_key_id pkeyId,a.init_table_name tableName,b.file_url url from m_wbs_tree_contract a join m_excel_tab b on a.excel_id=b.id where a.p_key_id in("+String.join(",",ids)+")");
-                                        listMaps.forEach(mp->{
-                                            try {
-                                                Workbook wb = WorkbookFactory.create(Objects.requireNonNull(CommonUtil.getOSSInputStream(StringUtils.handleNull(mp.get("url")))));
-                                                tec.wkbMap.put(mp.get("pkeyId").toString(),wb);
-                                            } catch (Exception e) {
-                                                e.printStackTrace();
-                                            }
-                                        });
-                                    }
-                                 }
-                                Optional<NodeTable> nodeTableOp =tec.getTableAll().stream().filter(e->e.getInitTableName().equals(fd.getTableName())).findFirst();
-                                 if(nodeTableOp.isPresent()){
-                                     Workbook wb = tec.wkbMap.get(nodeTableOp.get().getPKeyId().toString());
-                                     if(wb!=null){
-                                         Cell deCell=null;
-                                         Sheet sheet = wb.getSheetAt(0);
-                                         outerLoop: for(int y=3;y<35;y++){
-                                             for(int x=0;x<35;x++){
-                                                 Row row = sheet.getRow(y);
-                                                 Cell cell=  row.getCell(x);
-                                                 String sv=StringUtils.handleNull(FormulaUtils.getValue(cell)).replaceAll("[^\u4e00-\u9fa5]+","");
-                                                 if(sv.contains("规定")&&sv.contains("偏差")){
-                                                     deCell=cell;
-                                                     break outerLoop;
-                                                 }
-                                             }
-                                         }
-                                         if(deCell!=null) {
-                                             int min = 0;
-                                             Optional<Integer> op = fd.getCoordsList().stream().map(Coords::getY).distinct().min(Comparator.comparingInt(e -> e));
-                                             if (op.isPresent()) {
-                                                 min = op.get();
-                                             }
-                                             Row row = sheet.getRow(min);
-                                             Cell cell = row.getCell(deCell.getColumnIndex());
-                                             devStr = FormulaUtils.getValue(cell).toString();
-                                         }
-                                     }
-                                 }
-                             }
-                             if(CustomFunction.containsZH(devStr)||StringUtils.isEmpty(devStr)||StringUtils.handleNull(devStr).contains("/")){
-                                 devStr="±100000";
-                             }
-                             if(devStr.contains("E[")){
-                                List<String> codes= getCodeByEl(devStr);
-                                Map<String,Object> map = new HashMap<>();
-                                boolean isNull=false;
-                                for (String c:codes){
-                                    FormData ffd= tec.getFormDataMap().get(c);
-                                    if(ffd.empty()){
-                                        isNull=true;
-                                        break;
-                                    } else{
-                                        map.put("E["+c+"]",ffd.getRawValue().stream().filter(StringUtils::isNotEmpty).findFirst().orElse(null)) ;
-                                    }
-                                }
-                               if(isNull){
-                                   devStr="±100000";
-                               }
-                               devStr= Arrays.stream(devStr.replaceAll("^\\[|\\]$","").split(",")).map(s->map.getOrDefault(s,s)).map(StringUtils::handleNull).collect(Collectors.joining(","));
-                             }
-                             *//*设计值可以是数值类型,或空(等效0)*//*
-                             if(dataFd!=null){
-                                    List<Object> values= dataFd.getRawValue();
-                                    boolean nonNumeric=values.stream().filter(StringUtils::isNotEmpty).anyMatch(e->!StringUtils.isNumber(e));
-                                 if(nonNumeric){
-                                   data=values.stream().filter(StringUtils::isNotEmpty).count();
-                                 }else if(designFd!=null){
-                                     if(dataFd.getValues().stream().map(ElementData::getValue).anyMatch(StringUtils::isNotEmpty)&&(designFd.getValues().size()>1||designFd.getValues().stream().map(ElementData::getValue).anyMatch(StringUtils::isEmpty))){
-                                         *//*多少个设计值暂时默认全部合格,满足绝大部分结果*//*
-                                         data=dataFd.getValues().stream().map(ElementData::getValue).filter(StringUtils::isNotEmpty).count();
-                                     }else{
-                                         List<Object>  result =  CustomFunction.b445check(dataFd.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()),designFd.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()),devStr,1 );
-                                         data=result.get(1);
-                                     }
-                                 }else if(BaseUtils.isNumber(designStr)) {
-                                     List<Object> result = CustomFunction.b445check(dataFd.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()), 0, devStr, 1);
-                                     data = result.get(1);
-                                 }
-                             }
-                         }
-                         f = f.replace(m.group(),putDataWithKey(BaseUtils.isNumber(data)?Double.parseDouble(data.toString()):data));
-                     }
-                     fd.getFormula().setFormula(f);
-                     formula.setScale(1);*/
                      quantity(formula,fd,f);
                  }
-                 formula.setFormula(f);
              }catch (Exception e){
                  tec.getLog().put(FormulaLog.OTHER,e.getMessage());
                  e.printStackTrace();
@@ -2362,10 +2259,14 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             fds.removeIf(f->f.getCoordsList().size()!=1);
             /*工序节点*/
             WbsTreeContract node = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getId, wtc.getParentId()).eq(WbsTreeContract::getContractId,wtc.getContractId()));
+            Long privatePkeyId=node.getIsTypePrivatePid();
             /*项目节点*/
-            WbsTreePrivate wtp = this.wtpId(node.getPKeyId());
+            if(privatePkeyId==null) {
+                WbsTreePrivate wtp = this.wtpId(node.getPKeyId());
+                privatePkeyId=wtp.getPKeyId();
+            }
             /*WBS*/
-            WbsTreePrivate publicWtp = this.getOriginWtp(wtp.getPKeyId());
+            WbsTreePrivate publicWtp = this.getOriginWtp(privatePkeyId);
 
             Map<String,Object> result = new HashMap<>(100);
             List<WbsParam> total = new ArrayList<>();
@@ -2373,7 +2274,7 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
             if(Func.isNotEmpty(wpsPublic)){
                 total.addAll(wpsPublic);
             }
-            List<WbsParam> wpsPrivate = this.wpService.list(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getNodeId,wtp.getPKeyId()).eq(WbsParam::getType,1));
+            List<WbsParam> wpsPrivate = this.wpService.list(Wrappers.<WbsParam>lambdaQuery().eq(WbsParam::getNodeId,privatePkeyId).eq(WbsParam::getType,1));
             if(Func.isNotEmpty(wpsPrivate)){
                 total.addAll(wpsPrivate);
             }
@@ -2382,25 +2283,25 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                 for(WbsParam p:total){
                     result.put(p.getK(),p.getV());
                 }
+            }else{
+                return;
             }
-          Map<Long,String> paramIdKeyMap=  total.stream().collect(Collectors.toMap(WbsParam::getId,WbsParam::getK));
             /*元素动态绑定*/
             Map<String,Formula> formulaIdMap = this.wpService.formulaKeyMap(total.stream().map(WbsParam::getK).collect(Collectors.toList()));
             /*获取已配置节点公式*/
-            if(Func.isNotEmpty(total)){
-                List<ElementFormulaMapping> mappingList =  this.elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery().in(ElementFormulaMapping::getParamId,total.stream().map(WbsParam::getId).collect(Collectors.toList())));
-                if(Func.isNotEmpty(mappingList)){
-                    fds.forEach(e->{
-                        mappingList.stream().filter(m->StringUtils.isEquals(m.getElementId(),e.getId())).findAny().ifPresent(d->{
-                            String key = paramIdKeyMap.get(d.getParamId());
-                            Formula formula=formulaIdMap.computeIfAbsent(key,k->this.getById(d.getFormulaId()));
-                            if(formula!=null){
-                                e.setFormulaId(formula.getId());
-                                e.setFormula(formula);
-                            }
-                        });
+            Map<Long,String> paramIdKeyMap=  total.stream().collect(Collectors.toMap(WbsParam::getId,WbsParam::getK));
+            List<ElementFormulaMapping> mappingList =  this.elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery().in(ElementFormulaMapping::getParamId,total.stream().map(WbsParam::getId).collect(Collectors.toList())));
+            if(Func.isNotEmpty(mappingList)){
+                fds.forEach(e->{
+                    mappingList.stream().filter(m->StringUtils.isEquals(m.getElementId(),e.getId())).findAny().ifPresent(d->{
+                        String key = paramIdKeyMap.get(d.getParamId());
+                        Formula formula=formulaIdMap.computeIfAbsent(key,k->this.getById(d.getFormulaId()));
+                        if(formula!=null){
+                            e.setFormulaId(formula.getId());
+                            e.setFormula(formula);
+                        }
                     });
-                }
+                });
             }
             /*检查是否可以自动绑定参数公式*/
             List<FormData> notFormulaFds=fds.stream().filter(f->f.getFormulaId()==null).collect(Collectors.toList());
@@ -2421,31 +2322,34 @@ public class FormulaServiceImpl extends BaseServiceImpl<FormulaMapper, Formula>
                     });
                 });
             }
-            /*执行结果放回数据集合*/
-            Map<String,Object> currentMap = new HashMap<>(30);
-            /*获取祖先联链*/
-            List<WbsTreeContract> nodes =this.wpService.tracing(node.getPKeyId());
-            currentMap.put(CHAIN,nodes.stream().map(e->StringUtils.isNotEmpty(e.getFullName())?e.getFullName():e.getNodeName()).collect(Collectors.toList()));
-            /*节点参数*/
-            currentMap.put(WP,result);
-            fds.forEach(fd->{
-                if(fd.executable()){
-                    String tmp =fd.getFormula().getFormula().replaceAll("[\\s]+","");
-                    tmp = tmp.replace(FC, CustomFunction.CLASS_CALL);
-                    if(tmp.contains("WP[")){
-                        Matcher am = AP.matcher(tmp);
-                        while (am.find()){
-                            tmp = tmp.replace(am.group(),am.group(1)+"['"+am.group(2)+"']");
+            fds.removeIf(f->f.getFormula()==null);
+            if(fds.size()>0) {
+                /*执行结果放回数据集合*/
+                Map<String, Object> currentMap = new HashMap<>(30);
+                /*获取祖先联链*/
+                List<WbsTreeContract> nodes = this.wpService.tracing(node.getPKeyId());
+                currentMap.put(CHAIN, nodes.stream().map(e -> StringUtils.isNotEmpty(e.getFullName()) ? e.getFullName() : e.getNodeName()).collect(Collectors.toList()));
+                /*节点参数*/
+                currentMap.put(WP, result);
+                fds.forEach(fd -> {
+                    if (fd.executable()) {
+                        String tmp = fd.getFormula().getFormula().replaceAll("[\\s]+", "");
+                        tmp = tmp.replace(FC, CustomFunction.CLASS_CALL);
+                        if (tmp.contains("WP[")) {
+                            Matcher am = AP.matcher(tmp);
+                            while (am.find()) {
+                                tmp = tmp.replace(am.group(), am.group(1) + "['" + am.group(2) + "']");
+                            }
+                        }
+                        Object data = Expression.parse(tmp).calculate(currentMap);
+                        if (StringUtils.isNotEmpty(data)) {
+                            Coords coords = fd.getCoordsList().get(0);
+                            /*计算结果放回结果集 */
+                            dataMap.put(fd.getKey() + "__" + coords.getY() + "_" + coords.getX(), data);
                         }
                     }
-                    Object data =Expression.parse(tmp).calculate(currentMap);
-                    if(StringUtils.isNotEmpty(data)){
-                        Coords coords=fd.getCoordsList().get(0);
-                        /*计算结果放回结果集 */
-                        dataMap.put(fd.getKey()+"__"+coords.getY()+"_"+coords.getX(),data);
-                    }
-                }
-            });
+                });
+            }
             stopWatch.stop();
             long totalTime = stopWatch.getTotalTimeMillis();
             StaticLog.info("表单公式执行用时:{}", totalTime);