Răsfoiți Sursa

公式相关:合格率优化,增加从模版获取偏差的能力

yangyj 2 ani în urmă
părinte
comite
fbe64aac0b

+ 1 - 152
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/DatumPointService.java

@@ -2,15 +2,10 @@ package org.springblade.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
-import io.reactivex.Single;
 import lombok.AllArgsConstructor;
-import org.apache.poi.ss.usermodel.*;
 import org.springblade.business.entity.DatumPoint;
-import org.springblade.business.excel.DatumPointExcel;
 import org.springblade.business.excel.DatumPointxyExcel;
-import org.springblade.business.excel.MileageExcel;
 import org.springblade.business.mapper.DatumPointMapper;
-import org.springblade.business.utils.ExcelUtil;
 import org.springblade.common.utils.BaseUtils;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.tool.api.R;
@@ -141,154 +136,8 @@ public class DatumPointService extends BaseServiceImpl<DatumPointMapper, DatumPo
         return R.fail("导入失败");
     }
 
-//    public R importData_bak(MultipartFile file, Long contractId, Long projectId, Integer dataType) throws Exception {
-//        List<String> level=new ArrayList<>();
-//        level.add("一级");
-//        level.add("二级");
-//        level.add("三级");
-//        level.add("四级");
-//        try {
-//            Workbook wb = WorkbookFactory.create(file.getInputStream());
-//            Sheet sheet = wb.getSheetAt(0);
-//            List<DatumPoint> importList = new ArrayList<>();
-//            Row row1=sheet.getRow(0);
-//            if(dataType==0){
-//                String dengji= ExcelUtil.getValue(row1.getCell(2)).toString();
-//                String beizhu=ExcelUtil.getValue(row1.getCell(3)).toString();
-//                if( !"等级".equals(dengji)||!"备注".equals(beizhu)){
-//                    return  R.fail("导入的数据格式有错,请对准导入模板确认!");
-//                }
-//            }
-//            if(dataType==1){
-//                String dengji=ExcelUtil.getValue(row1.getCell(4)).toString();
-//                String beizhu=ExcelUtil.getValue(row1.getCell(5)).toString();
-//                if( !"等级".equals(dengji)||!"备注".equals(beizhu)){
-//                    return  R.fail("导入的数据格式有错,请对准导入模板确认!");
-//                }
-//            }
-//
-//            for (int i = 1; ; i++) {
-//                Row row = sheet.getRow(i);
-//                if(row == null) {
-//                    break;
-//                }
-//                if(dataType==0) {
-//                    DatumPoint obj = new DatumPoint();
-//                    for (int j = 0; j < 4; j++) {
-//                        String value = (String) ExcelUtil.getValue(row.getCell(j));
-//                        if (StringUtil.isEmpty(value)) {
-//                            value = "";
-//                        }
-//                        String msg="";
-//                        //判断测站点名称是否为空
-//                        String name=(String)ExcelUtil.getValue(row.getCell(0));
-//                        if(StringUtil.isEmpty(name)){
-//                            msg="第"+i+"行,测站点名称为空,请输入!";
-//                            return  R.fail(msg);
-//                        }
-//                        //判断,同一合同段下,测站点名称是否重复
-//                        if(this.count(Wrappers.<DatumPoint>lambdaQuery().eq(DatumPoint::getName,name).eq(DatumPoint::getContractId,contractId).eq(DatumPoint::getType,dataType))>0){
-//                            msg="第"+i+"行,测站点:"+name+"已存在,请修改";
-//                            return  R.fail(msg);
-//                        }
-//                        switch (j) {
-//                            case 0:
-//                                obj.setName(value);
-//                                break;
-//                            case 1:
-//                                obj.setH(Double.parseDouble(value));
-//                                break;
-//                            case 2:
-//                                //判断等级是否为:一级、二级、三级、四级
-//                                if(StringUtil.isNotBlank((String) ExcelUtil.getValue(row.getCell(j)))) {
-//                                    if(!level.contains(value)){
-//                                        msg="第"+i+"行,等级应该为:一级、二级、三级 或 四级,请修改!";
-//                                        return  R.fail(msg);
-//                                    }
-//                                    obj.setLevel(value);
-//                                }
-//                                break;
-//                            case 3:
-//                                obj.setRemark(value);
-//                                break;
-//                            default:
-//                                break;
-//                        }
-//
-//                    }
-//                    obj.setContractId(contractId);
-//                    obj.setProjectId(projectId);
-//                    obj.setCreateTime(new Date());
-//                    obj.setType(dataType);
-//                    importList.add(obj);
-//                }
-//                if(dataType==1){
-//                    DatumPoint obj = new DatumPoint();
-//                    for (int j = 0; j < 6; j++) {
-//                        String value = (String) ExcelUtil.getValue(row.getCell(j));
-//                        if (StringUtil.isEmpty(value)) {
-//                            value = "";
-//                        }
-//                        String msg="";
-//                        //判断测站点名称是否为空
-//                        String name=(String)ExcelUtil.getValue(row.getCell(0));
-//                        if(StringUtil.isEmpty(name)){
-//                            msg="第"+i+"行,测站点名称为空,请输入!";
-//                            return  R.fail(msg);
-//                        }
-//                        //判断,同一合同段下,测站点名称是否重复
-//                        if(this.count(Wrappers.<DatumPoint>lambdaQuery().eq(DatumPoint::getName,name).eq(DatumPoint::getContractId,contractId).eq(DatumPoint::getType,dataType))>0){
-//                            msg="第"+i+"行,测站点:"+name+"已存在,请修改";
-//                            return  R.fail(msg);
-//                        }
-//                        switch (j) {
-//                            case 0:
-//                                obj.setName(value);
-//                                break;
-//                            case 1:
-//                                obj.setX(Double.parseDouble(value));
-//                                break;
-//                            case 2:
-//                                obj.setY(Double.parseDouble(value));
-//                                break;
-//                            case 3:
-//                                obj.setH(Double.parseDouble(value));
-//                                break;
-//                            case 4:
-//                                //判断等级是否为:一级、二级、三级、四级
-//                                if(StringUtil.isNotBlank((String) ExcelUtil.getValue(row.getCell(j)))) {
-//                                    if(!level.contains(value)){
-//                                        msg="第"+i+"行,等级应该为:一级、二级、三级 或 四级,请修改!";
-//                                        return  R.fail(msg);
-//                                    }
-//                                    obj.setLevel(value);
-//                                }
-//                                break;
-//                            case 5:
-//                                obj.setRemark(value);
-//                                break;
-//                            default:
-//                                break;
-//                        }
-//
-//                    }
-//                    obj.setContractId(contractId);
-//                    obj.setProjectId(projectId);
-//                    obj.setCreateTime(new Date());
-//                    obj.setType(dataType);
-//                    importList.add(obj);
-//                }
-//            }
-//            //批量保存
-//            this.saveBatch(importList);
-//            return   R.success("导入成功");
-//        } catch (Exception e){
-//            e.printStackTrace();
-//        }
-//        return  R.fail("执行异常");
-//    }
 
-    /*导出数据*/
+    /**导出数据*/
     public List<DatumPoint> exportExcel(String contractId, Integer type, String search) {
         if (StringUtil.isBlank(search)) {
             search = "";

+ 0 - 38
blade-service/blade-business/src/main/java/org/springblade/business/utils/ExcelUtil.java

@@ -1,38 +0,0 @@
-package org.springblade.business.utils;
-
-import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellType;
-
-/**
- * @author yangyj
- * @Date 2022/6/8 11:18
- * @description TODO
- */
-public class ExcelUtil {
-    public static Object getValue(Cell cell) {
-        if (cell != null) {
-            switch (cell.getCellTypeEnum()) {
-                case STRING:
-                    return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
-                case NUMERIC:
-                    HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
-                    return dataFormatter.formatCellValue(cell);
-                case BOOLEAN:
-                    return cell.getBooleanCellValue();
-                case ERROR:
-                    return cell.getErrorCellValue();
-                case FORMULA:
-                    try {
-                        return cell.getStringCellValue();
-                    } catch (IllegalStateException e) {
-                        return cell.getNumericCellValue();
-                    }
-                default:
-                    cell.setCellType(CellType.STRING);
-                    return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
-            }
-        }
-        return null;
-    }
-}

+ 1 - 0
blade-service/blade-manager/src/main/java/com/mixsmart/utils/CustomFunction.java

@@ -1499,6 +1499,7 @@ public class CustomFunction {
     }
 
 
+
     public static Double[] scopeParse(Object dev, Object design, Object xN) {
         if (StringUtils.isNotEmpty(dev)) {
             Double[] result = new Double[2];

+ 29 - 0
blade-service/blade-manager/src/main/java/com/mixsmart/utils/FormulaUtils.java

@@ -14,6 +14,7 @@ import com.aliyun.oss.model.ObjectMetadata;
 import com.aliyun.oss.model.PutObjectRequest;
 import com.aliyun.oss.model.PutObjectResult;
 import com.jfireel.expression.Expression;
+import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.*;
 import java.awt.Color;
@@ -458,6 +459,34 @@ public class FormulaUtils {
         return null;
     }
 
+
+
+    public static Object getValue(Cell cell) {
+        if (cell != null) {
+            switch (cell.getCellTypeEnum()) {
+                case STRING:
+                    return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
+                case NUMERIC:
+                    HSSFDataFormatter dataFormatter = new HSSFDataFormatter();
+                    return dataFormatter.formatCellValue(cell);
+                case BOOLEAN:
+                    return cell.getBooleanCellValue();
+                case ERROR:
+                    return cell.getErrorCellValue();
+                case FORMULA:
+                    try {
+                        return cell.getStringCellValue();
+                    } catch (IllegalStateException e) {
+                        return cell.getNumericCellValue();
+                    }
+                default:
+                    cell.setCellType(CellType.STRING);
+                    return cell.getStringCellValue() == null ? null : cell.getStringCellValue().trim();
+            }
+        }
+        return null;
+    }
+
     /**
      * @Description  Poi 动态执行公式 测试
      * @Param [url]

+ 3 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/formula/impl/TableElementConverter.java

@@ -4,6 +4,7 @@ package org.springblade.manager.formula.impl;
 import cn.hutool.log.StaticLog;
 import com.mixsmart.utils.StringUtils;
 import lombok.Data;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.springblade.common.utils.BaseUtils;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.StringPool;
@@ -36,7 +37,6 @@ public class TableElementConverter implements ITableElementConverter {
     public static String JOIN_REG = "__\\d+_\\d+,?";
     public static Pattern RP = Pattern.compile("(?<=E\\[)[^]]+(?=])");
 
-
     private List<TableInfo> tableInfoList;
     private Long contractId;
     private Long projectId;
@@ -58,6 +58,8 @@ public class TableElementConverter implements ITableElementConverter {
      * {tableName:{key:val}}
      */
     Map<String, Map<String, String>> coordinateMap = new HashMap<>();
+    /**表单对应的Excel对象*/
+    public Map<String, Workbook> wkbMap = new HashMap<>();
     /**
      * {code:List<ElementData>}
      */

+ 63 - 2
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/FormulaServiceImpl.java

@@ -12,10 +12,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.jfireel.expression.Expression;
 import com.mixsmart.utils.*;
 import lombok.RequiredArgsConstructor;
+import org.apache.poi.ss.usermodel.*;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
 import org.jsoup.select.Elements;
+import org.springblade.common.utils.BaseUtils;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.tool.api.R;
@@ -1527,6 +1530,7 @@ public  List<ElementData> setScale(Integer scale,List<ElementData> data){
                          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)){
+                             /*TODO 允许多次右键插入之后,就无法满足计算要求*/
                              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();
@@ -1535,15 +1539,72 @@ public  List<ElementData> setScale(Integer scale,List<ElementData> data){
                              }
                          }else{
                              FormData dataFd=tec.formDataMap.get(codeList.get(0));
-                             FormData designFd=tec.formDataMap.get(codeList.get(1));
+                             String designStr=codeList.get(1);
+                             FormData designFd=tec.formDataMap.get(designStr);
+                             String devStr=StringUtils.isEmpty(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";
+                             }
+                             /*设计值可以是数值类型,或空(等效0)*/
                              if(dataFd!=null&&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()),formula.getDev(),1 );
+                                     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(dataFd!=null&& BaseUtils.isNumber(designStr)){
+                                     List<Object>  result =  CustomFunction.b445check(dataFd.getValues().stream().map(ElementData::getValue).collect(Collectors.toList()),0,devStr,1 );
+                                     data=result.get(1);
                              }
                          }