Browse Source

试验bug

liuyc 1 year ago
parent
commit
94164ad8b1

+ 1 - 1
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ExcelTabClient.java

@@ -26,7 +26,7 @@ public interface ExcelTabClient {
                        @RequestParam Integer type,
                        @RequestParam String tableType,
                        @RequestParam Long id,
-                       @RequestParam String tabIds) throws Exception;
+                       @RequestParam String tabIds) throws RuntimeException;
 
     @PostMapping(API_PREFIX + "/getBussPDFTrial")
     void getBussPDFTrial(@RequestParam Long pkeyId,

+ 0 - 1
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialDeviceUseServiceImpl.java

@@ -372,7 +372,6 @@ public class TrialDeviceUseServiceImpl extends BaseServiceImpl<TrialDeviceUseMap
         return null;
     }
 
-    @Async
     public void addDeviceUseInfo(TrialSelfInspectionRecordDTO dto) {
         if (StringUtils.isNotEmpty(dto.getDeviceUseIds())) {
             //获取进场记录

+ 18 - 12
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialSelfInspectionRecordServiceImpl.java

@@ -872,8 +872,7 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class)
-    public String selfSubmit(TrialSelfInspectionRecordDTO dto){
+    public String selfSubmit(TrialSelfInspectionRecordDTO dto) {
         //------初始当前填报的表pKeyIds------
         this.initTrialTabIds(dto);
 
@@ -902,9 +901,12 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
                 //------关联新增设备使用记录信息------
                 this.trialDeviceUseService.addDeviceUseInfo(dto);
 
-            } catch (Exception e) {
+            } catch (RuntimeException e) {
                 e.printStackTrace();
-                throw new RuntimeException(e.getMessage());
+                throw new RuntimeException("保存实体表数据、试验记录信息、生成PDF失败:" + e.getMessage());
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+                throw new RuntimeException("关联原材料检测报告失败:" + e.getMessage());
             }
         }
         return dto.getId().toString();
@@ -940,16 +942,21 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
         }
     }
 
-    @Async
-    public void submitTrialData(TrialSelfInspectionRecord obj, TrialSelfInspectionRecordDTO dto) throws Exception {
-        String pdfURL = excelTabClient.saveTabData(dto, dto.getIsBatchSave(), dto.getType(), dto.getTableType(), dto.getId(), obj.getTableIds());
-        if (StringUtils.isNotEmpty(pdfURL)) {
-            this.update(Wrappers.<TrialSelfInspectionRecord>lambdaUpdate().set(TrialSelfInspectionRecord::getPdfUrl, pdfURL).eq(TrialSelfInspectionRecord::getId, dto.getId()));
+    public void submitTrialData(TrialSelfInspectionRecord obj, TrialSelfInspectionRecordDTO dto) throws RuntimeException {
+        try {
+            String pdfURL = excelTabClient.saveTabData(dto, dto.getIsBatchSave(), dto.getType(), dto.getTableType(), dto.getId(), obj.getTableIds());
+            if (StringUtils.isNotEmpty(pdfURL)) {
+                this.update(Wrappers.<TrialSelfInspectionRecord>lambdaUpdate().set(TrialSelfInspectionRecord::getPdfUrl, pdfURL).eq(TrialSelfInspectionRecord::getId, dto.getId()));
+            }
+        } catch (RuntimeException e) {
+            if (e.getMessage().contains("字段过长")) {
+                //字段过长,新增失败的异常处理
+                jdbcTemplate.execute("delete from u_trial_self_inspection_record where id = " + dto.getId());
+            }
+            throw new RuntimeException("原因:" + e.getMessage());
         }
     }
 
-    @Async
-    @Transactional(rollbackFor = Exception.class)
     public boolean recordSampleSubmit(TrialSelfInspectionRecordDTO dto1, TrialSelfInspectionRecord obj) {
         RecordSampleSubmitDTO dto = new RecordSampleSubmitDTO();
         dto.setId(obj.getId());
@@ -992,7 +999,6 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
         return true;
     }
 
-    @Async
     public boolean rawMaterialSubmitRelation(TrialSelfInspectionRecordDTO dto1, TrialSelfInspectionRecord obj) throws FileNotFoundException {
         RawMaterialSubmitRelationDTO dto = new RawMaterialSubmitRelationDTO();
         dto.setId(dto1.getId().toString());

+ 52 - 41
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/ExcelTabClientImpl.java

@@ -2,8 +2,11 @@ package org.springblade.manager.feign;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import feign.FeignException;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springblade.business.dto.TrialSelfInspectionRecordDTO;
 import org.springblade.business.entity.InformationQuery;
 import org.springblade.business.entity.TrialSelfInspectionRecord;
@@ -46,6 +49,7 @@ public class ExcelTabClientImpl implements ExcelTabClient {
     private final JdbcTemplate jdbcTemplate;
     private final NewIOSSClient newIOSSClient;
     private final InformationQueryClient informationQueryClient;
+    private static final Logger logger = LoggerFactory.getLogger(ExcelTabClientImpl.class);
 
     @Override
     public ExcelTab getById(String id) {
@@ -53,7 +57,7 @@ public class ExcelTabClientImpl implements ExcelTabClient {
     }
 
     @Override
-    public String saveTabData(TrialSelfInspectionRecordDTO dto, Integer isBatchSave, Integer type, String tableType, Long id, String tabIds) throws Exception {
+    public String saveTabData(TrialSelfInspectionRecordDTO dto, Integer isBatchSave, Integer type, String tableType, Long id, String tabIds) throws RuntimeException {
         //通用参数
         String pdfUrl = "";
         JSONArray dataArray = dto.getDataInfo().getJSONArray("orderList");
@@ -61,54 +65,61 @@ public class ExcelTabClientImpl implements ExcelTabClient {
         String nodeId = table.getString("nodeId");
         String projectId = table.getString("projectId");
         String contractId = table.getString("contractId");
-
-        //获取表模板,已处理隐藏表问题
-        List<TableInfo> tableInfoList = this.excelTabService.getTableInfoListTrial(dataArray, tabIds);
-
-        //------公式填充------
         try {
+            //获取表模板,已处理隐藏表问题
+            List<TableInfo> tableInfoList = this.excelTabService.getTableInfoListTrial(dataArray, tabIds);
+
+            //------公式填充------
             this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeId), ExecuteType.TESTING);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        //------试验填报数据保存,当前记录id作为groupId------
-        this.excelTabService.saveOrUpdateInfoTrial(tableInfoList, id);
 
-        if (isBatchSave == 0) {
-            //------单表PDF保存------
-            TableInfo tableInfo = tableInfoList.stream().findAny().orElse(null);
-            if (tableInfo != null && tabIds.contains(tableInfo.getPkeyId())) {
-                //构造pdf
-                String bussPDFTrial = excelTabService.getBussPDFTrial(Long.valueOf(tableInfo.getPkeyId()), contractId, id, 0, 0, dto);
-                if (StringUtils.isNotEmpty(bussPDFTrial)) {
-                    //重新合并pdf
-                    List<TrialSelfDataRecord> query = jdbcTemplate.query("select pdf_url from u_trial_self_data_record where record_id = " + id, new BeanPropertyRowMapper<>(TrialSelfDataRecord.class));
-                    List<String> pdfList = query.stream().map(TrialSelfDataRecord::getPdfUrl).collect(Collectors.toList());
-                    String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
-                    String pdfPath = file_path + "/pdf//" + id + "_2.pdf";
-                    File tabPdf = ResourceUtil.getFile(pdfPath);
-                    if (tabPdf.exists()) {
-                        tabPdf.delete();
-                    }
-                    FileUtils.mergePdfPublicMethods(pdfList, pdfPath);
-                    BladeFile bladeFile = newIOSSClient.uploadFile(id + "2.pdf", pdfPath);
-                    if (bladeFile != null) {
-                        //重新合并pdf集合(解决单表保存后上报找不到题名问题)
-                        List<InformationQuery> query2 = jdbcTemplate.query("select id from u_information_query where classify ='" + type + "' and wbs_id ='" + id + "' and contract_id ='" + contractId + "'", new BeanPropertyRowMapper<>(InformationQuery.class));
-                        if (query2.size() > 0) {
-                            jdbcTemplate.execute("update u_information_query set pdf_url ='" + bladeFile.getLink() + "', name ='" + (StringUtils.isNotEmpty(dto.getTrialProjectName()) ? dto.getTrialProjectName() : "") + "'  where classify='" + type + "' and  wbs_id='" + id + "' and contract_id ='" + contractId + "'");
-                        } else {
-                            informationQueryClient.saveData(id.toString(), projectId, contractId, type.toString(), bladeFile.getLink(), (StringUtils.isNotEmpty(dto.getTrialProjectName()) ? dto.getTrialProjectName() : ""));
+            //------试验填报数据保存,当前记录id作为groupId------
+            this.excelTabService.saveOrUpdateInfoTrial(tableInfoList, id);
+
+            if (isBatchSave == 0) {
+                //------单表PDF保存------
+                TableInfo tableInfo = tableInfoList.stream().findAny().orElse(null);
+                if (tableInfo != null && tabIds.contains(tableInfo.getPkeyId())) {
+                    //构造pdf
+                    String bussPDFTrial = excelTabService.getBussPDFTrial(Long.valueOf(tableInfo.getPkeyId()), contractId, id, 0, 0, dto);
+                    if (StringUtils.isNotEmpty(bussPDFTrial)) {
+                        //重新合并pdf
+                        List<TrialSelfDataRecord> query = jdbcTemplate.query("select pdf_url from u_trial_self_data_record where record_id = " + id, new BeanPropertyRowMapper<>(TrialSelfDataRecord.class));
+                        List<String> pdfList = query.stream().map(TrialSelfDataRecord::getPdfUrl).collect(Collectors.toList());
+                        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+                        String pdfPath = file_path + "/pdf//" + id + "_2.pdf";
+                        File tabPdf = ResourceUtil.getFile(pdfPath);
+                        if (tabPdf.exists()) {
+                            tabPdf.delete();
+                        }
+                        FileUtils.mergePdfPublicMethods(pdfList, pdfPath);
+                        BladeFile bladeFile = newIOSSClient.uploadFile(id + "2.pdf", pdfPath);
+                        if (bladeFile != null) {
+                            //重新合并pdf集合(解决单表保存后上报找不到题名问题)
+                            List<InformationQuery> query2 = jdbcTemplate.query("select id from u_information_query where classify ='" + type + "' and wbs_id ='" + id + "' and contract_id ='" + contractId + "'", new BeanPropertyRowMapper<>(InformationQuery.class));
+                            if (query2.size() > 0) {
+                                jdbcTemplate.execute("update u_information_query set pdf_url ='" + bladeFile.getLink() + "', name ='" + (StringUtils.isNotEmpty(dto.getTrialProjectName()) ? dto.getTrialProjectName() : "") + "'  where classify='" + type + "' and  wbs_id='" + id + "' and contract_id ='" + contractId + "'");
+                            } else {
+                                informationQueryClient.saveData(id.toString(), projectId, contractId, type.toString(), bladeFile.getLink(), (StringUtils.isNotEmpty(dto.getTrialProjectName()) ? dto.getTrialProjectName() : ""));
+                            }
+                            pdfUrl = bladeFile.getLink();
                         }
-                        pdfUrl = bladeFile.getLink();
                     }
                 }
-            }
 
-        } else if (isBatchSave == 1) {
-            //------多表PDF保存------
-            pdfUrl = excelTabService.getBussPDFSTrial(nodeId, tableType, String.valueOf(type), contractId, projectId, id, tabIds, dto);
+            } else if (isBatchSave == 1) {
+                //------多表PDF保存------
+                pdfUrl = excelTabService.getBussPDFSTrial(nodeId, tableType, String.valueOf(type), contractId, projectId, id, tabIds, dto);
+            }
+        } catch (Exception e) {
+            if (e.getMessage().contains("字段过长")) {
+                //字段过长,新增失败的异常处理
+                throw new RuntimeException("字段过长,新增失败");
+            } else {
+                //其他类型的异常处理
+                throw new RuntimeException("保存数据出错");
+            }
         }
+
         return pdfUrl;
     }
 

+ 1 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IExcelTabService.java

@@ -125,7 +125,7 @@ public interface IExcelTabService extends BaseService<ExcelTab> {
     /**
      * 结果信息持久化 - 试验
      */
-    void saveOrUpdateInfoTrial(List<TableInfo> tableInfoList, Long groupId) throws SQLException;
+    void saveOrUpdateInfoTrial(List<TableInfo> tableInfoList, Long groupId);
 
     /**
      * 获取试验用户端 单个表单接口数据

+ 82 - 41
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -19,6 +19,7 @@ import lombok.AllArgsConstructor;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.poi.ss.formula.functions.T;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Font;
 import org.apache.poi.ss.usermodel.*;
@@ -41,6 +42,7 @@ import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.common.vo.DataVO;
 import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.base.BaseEntity;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.core.oss.model.BladeFile;
 import org.springblade.core.secure.utils.AuthUtil;
@@ -310,9 +312,9 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                     } else {
                         String dataVal = dataInfo2.getString(dataMap.get(k).get(0));
                         if (StringUtils.isNotEmpty(dataVal)) {
-                            if (dataVal.contains("Ljava")){
+                            if (dataVal.contains("Ljava")) {
                                 Object o = dataInfo2.get(dataMap.get(k).get(0));
-                                dataVal = JSON.toJSONString(o).replace("\"","");
+                                dataVal = JSON.toJSONString(o).replace("\"", "");
                             }
                             dataMap2.put(k, dataVal + "_^_" + dataMap.get(k).get(0).split("__")[1]);
                         }
@@ -341,9 +343,19 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                     Map<String, Map<String, String>> coordinateMap = createCoordinateMap(keyMappers, type);
                     stopWatch.start("公式处理");
                     List<Formula> formulas = this.formulaService.getFormulaList(keyMappers);
-                    WbsTreeContract wtc = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, nodeId));
-                    if (wtc != null) {
-                        CurrentNode currentNode = createCurrentNode(wtc);
+
+                    CurrentNode currentNode = null;
+                    Long pKeyId = null;
+                    if (type.equals(ExecuteType.INSPECTION)) {
+                        WbsTreeContract wtc = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, nodeId));
+                        pKeyId = wtc.getPKeyId();
+                        currentNode = createCurrentNode(wtc);
+                    } else if (type.equals(ExecuteType.TESTING)) {
+                        WbsTreePrivate wtp = this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, nodeId));
+                        pKeyId = wtp.getPKeyId();
+                        currentNode = createCurrentNode(wtp);
+                    }
+                    if (currentNode != null) {
                         TableElementConverter tec = new TableElementConverter(tableInfoList, keyMappers, formulas, coordinateMap, currentNode, tableAll);
                         tec.setExecuteType(type);
                         tec.setLog(log);
@@ -358,7 +370,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                         Long totalTime = stopWatch.getTotalTimeMillis();
                         log.append("公式执行消耗时间:").append(totalTime);
                         StaticLog.info("公式执行用时:{}", totalTime);
-                        updateFormulaLog(log, wtc);
+                        updateFormulaLog(log, pKeyId);
                     }
                 }
             } catch (Exception e) {
@@ -399,11 +411,11 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         return coordinateMap;
     }
 
-    private void updateFormulaLog(StringBuilder log, WbsTreeContract wtc) {
+    private void updateFormulaLog(StringBuilder log, Long pKeyId) {
         try {
             String[] sql = new String[]{
-                    "delete from m_formula_log where id =" + wtc.getPKeyId(),
-                    "INSERT INTO m_formula_log (id,content) VALUES (" + wtc.getPKeyId() + ", '" + log + "')"
+                    "delete from m_formula_log where id =" + pKeyId,
+                    "INSERT INTO m_formula_log (id,content) VALUES (" + pKeyId + ", '" + log + "')"
             };
             this.jdbcTemplate.batchUpdate(sql);
         } catch (Exception e) {
@@ -429,6 +441,39 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         return null;
     }
 
+    public <T extends BaseEntity> CurrentNode createCurrentNode(T entity) {
+        if (entity instanceof WbsTreeContract) {
+            WbsTreeContract wtc = (WbsTreeContract) entity;
+            /*当前工序节点*/
+            CurrentNode currentNode = new CurrentNode();
+            currentNode.setPkId(wtc.getPKeyId());
+            currentNode.setParentId(wtc.getParentId());
+            currentNode.setWbsId(Long.parseLong(wtc.getWbsId()));
+            currentNode.setId(StringUtils.isNotEmpty(wtc.getOldId()) ? Long.valueOf(wtc.getOldId()) : wtc.getId());
+            currentNode.setRelateId(wtc.getId());
+            List<Long> privateIds = this.jdbcTemplate.queryForList("select p_key_id from m_wbs_tree_private where id=" + currentNode.getRelateId() + " and  project_id=" + wtc.getProjectId() + " and wbs_id=" + wtc.getWbsId(), Long.class);
+            if (Func.isNotEmpty(privateIds)) {
+                currentNode.setPrivateId(privateIds.get(0));
+            }
+            return currentNode;
+        } else if (entity instanceof WbsTreePrivate) {
+            WbsTreePrivate wtc = (WbsTreePrivate) entity;
+            /*当前工序节点*/
+            CurrentNode currentNode = new CurrentNode();
+            currentNode.setPkId(wtc.getPKeyId());
+            currentNode.setParentId(wtc.getParentId());
+            currentNode.setWbsId(Long.parseLong(wtc.getWbsId()));
+            currentNode.setId(wtc.getId()); //数据源
+            currentNode.setRelateId(wtc.getId());
+            List<Long> privateIds = this.jdbcTemplate.queryForList("select p_key_id from m_wbs_tree_private where id=" + currentNode.getRelateId() + " and  project_id=" + wtc.getProjectId() + " and wbs_id=" + wtc.getWbsId(), Long.class);
+            if (Func.isNotEmpty(privateIds)) {
+                currentNode.setPrivateId(privateIds.get(0));
+            }
+            return currentNode;
+        }
+        return null;
+    }
+
     /**
      * 保存日志
      */
@@ -2453,40 +2498,36 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                     continue;
                 }
 
-                try {
-                    //删除SQL
-                    String delSql = "delete from " + wbsTreePrivate.getInitTableName() + " where p_key_id='" + tableInfo.getPkeyId() + "' and group_id = '" + groupId + "'";
-
-                    //新增SQL
-                    String sqlInfo = "";
-                    LinkedHashMap<String, String> dataMap2 = tableInfo.getDataMap();
-                    sqlInfo = "INSERT INTO " + wbsTreePrivate.getInitTableName() + " ( ";
-                    String keyStr = "id,group_id,";
-                    String valStr = SnowFlakeUtil.getId() + "," + groupId + ",";
-                    for (String keys : dataMap2.keySet()) {
-                        keyStr += keys + ",";
-                        valStr += "'" + dataMap2.get(keys) + "',";
-                    }
-                    keyStr = keyStr.substring(0, keyStr.lastIndexOf(","));
-                    valStr = valStr.substring(0, valStr.lastIndexOf(","));
-                    sqlInfo = sqlInfo + keyStr + ") VALUES (" + valStr + ")";
-
-                    TransactionStatus transactionStatus = this.beginTransaction(transactionManager1);
-                    try {
-                        //删除
-                        jdbcTemplate.execute(delSql);
-                        //新增
-                        jdbcTemplate.execute(sqlInfo);
-                        //提交事务
-                        transactionManager1.commit(transactionStatus);
-                    } catch (Exception e) {
-                        //回滚
-                        transactionManager1.rollback(transactionStatus);
+                //删除SQL
+                String delSql = "delete from " + wbsTreePrivate.getInitTableName() + " where p_key_id='" + tableInfo.getPkeyId() + "' and group_id = '" + groupId + "'";
+
+                //新增SQL
+                String sqlInfo = "";
+                LinkedHashMap<String, String> dataMap2 = tableInfo.getDataMap();
+                sqlInfo = "INSERT INTO " + wbsTreePrivate.getInitTableName() + " ( ";
+                String keyStr = "id,group_id,";
+                String valStr = SnowFlakeUtil.getId() + "," + groupId + ",";
+                for (String keys : dataMap2.keySet()) {
+                    keyStr += keys + ",";
+                    valStr += "'" + dataMap2.get(keys) + "',";
+                }
+                keyStr = keyStr.substring(0, keyStr.lastIndexOf(","));
+                valStr = valStr.substring(0, valStr.lastIndexOf(","));
+                sqlInfo = sqlInfo + keyStr + ") VALUES (" + valStr + ")";
 
-                        throw new ServiceException("字段过长,新增失败");
-                    }
+                TransactionStatus transactionStatus = this.beginTransaction(transactionManager1);
+                try {
+                    //删除
+                    jdbcTemplate.execute(delSql);
+                    //新增
+                    jdbcTemplate.execute(sqlInfo);
+                    //提交事务
+                    transactionManager1.commit(transactionStatus);
                 } catch (Exception e) {
-                    e.printStackTrace();
+                    //回滚
+                    transactionManager1.rollback(transactionStatus);
+
+                    throw new RuntimeException("字段过长,新增失败");
                 }
             }
         }