Jelajahi Sumber

资料填报响应消息问题

liuyc 1 tahun lalu
induk
melakukan
b22c94e498

+ 49 - 28
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -16,7 +16,6 @@ import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.SneakyThrows;
 import org.apache.commons.codec.Charsets;
-import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.poi.ss.usermodel.WorkbookFactory;
@@ -301,9 +300,9 @@ public class ExcelTabController extends BladeController {
         String filecode = SnowFlakeUtil.getId() + "";
         String thmlUrl = file_path + filecode + ".html";
         String exceUrl = file_path + filecode + "123.xlsx";
-        ExcelInfoUtils.excelInfo(file.getInputStream(),exceUrl,thmlUrl,"1");
+        ExcelInfoUtils.excelInfo(file.getInputStream(), exceUrl, thmlUrl, "1");
         // 上传excel文件
-         BladeFile bladeFile = newIOSSClient.uploadFile(file.getOriginalFilename(),exceUrl);
+        BladeFile bladeFile = newIOSSClient.uploadFile(file.getOriginalFilename(), exceUrl);
         // 解析原始excel
 
         BladeFile bladeFileR = newIOSSClient.uploadFileByInputStream(file);
@@ -1964,7 +1963,7 @@ public class ExcelTabController extends BladeController {
             @ApiImplicitParam(name = "status", value = "状态(1显示 2隐藏)", required = true)
     })
     @Transactional
-    public R showBussTab(Long pkeyId, int status,String nodeId,String classify) throws Exception {
+    public R showBussTab(Long pkeyId, int status, String nodeId, String classify) throws Exception {
         WbsTreeContract wbsTreeContract = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
                 .eq(WbsTreeContract::getPKeyId, pkeyId));
         UpdateWrapper<WbsTreeContract> updateWrapper = new UpdateWrapper<>();
@@ -2083,35 +2082,36 @@ public class ExcelTabController extends BladeController {
     @PostMapping("/save_buss_data")
     @ApiOperationSupport(order = 13)
     @ApiOperation(value = "填报页面数据保存", notes = "填报页面数据保存")
-    public R<String> saveBussData(@Valid @RequestBody JSONObject dataInfo, BladeUser bladeUser) throws Exception {
+    public R saveBussData(@Valid @RequestBody JSONObject dataInfo) throws Exception {
         JSONArray dataArray = new JSONArray();
-        if (dataInfo.containsKey("dataInfo")) { // 节点保存
+        if (dataInfo.containsKey("dataInfo")) { //节点保存
             JSONObject jsonObject = dataInfo.getJSONObject("dataInfo");
             dataArray = jsonObject.getJSONArray("orderList");
-        } else { // 单个保存
+        } else { //单个保存
             dataArray.add(dataInfo);
         }
 
         JSONObject tableInfo1 = dataArray.getJSONObject(0);
-        String nodeid = tableInfo1.getString("nodeId");
+        String nodeId = tableInfo1.getString("nodeId");
         String contractId = tableInfo1.getString("contractId");
         String projectId = tableInfo1.getString("projectId");
         String classify = tableInfo1.getString("classify");
-        String groupId = tableInfo1.getString("tabGroupId");
-        String pkeyId = tableInfo1.getString("pkeyId");
 
-        //
+        /*String groupId = tableInfo1.getString("tabGroupId");
+        String pkeyId = tableInfo1.getString("pkeyId");
         String pkeyIds = pkeyId;
         String groupIds = groupId;
         for (int i = 1; i < dataArray.size(); i++) {
             JSONObject jsonObject = dataArray.getJSONObject(i);
             pkeyIds += "," + jsonObject.getString("pkeyId");
             groupIds += "," + jsonObject.getString("tabGroupId");
-        }
+        }*/
+
         /*全加载,或者可以优化成依赖加载*/
+        List<AppWbsTreeContractVO> tableAll = new ArrayList<>();
         List<TableInfo> tableInfoList = this.excelTabService.getTableInfoList(dataArray);
         if (tableInfoList != null) {
-            List<AppWbsTreeContractVO> tableAll = wbsTreeContractService.searchNodeAllTable(nodeid, "1", contractId, projectId);
+            tableAll = wbsTreeContractService.searchNodeAllTable(nodeId, "1", contractId, projectId);
             List<Long> tableAllIds = tableAll.stream().map(AppWbsTreeContractVO::getPKeyId).collect(Collectors.toList());
             if (tableAll.size() > tableInfoList.size()) {
                 List<Long> exclude = tableInfoList.stream().map(TableInfo::getPkeyId).map(Long::parseLong).collect(Collectors.toList());
@@ -2121,7 +2121,7 @@ public class ExcelTabController extends BladeController {
                         R bussDataInfo = this.excelTabService.getBussDataInfo(pk, 1);
                         @SuppressWarnings("unchecked")
                         Map<String, Object> jo = (Map<String, Object>) bussDataInfo.getData();
-                        if(jo!=null && ObjectUtils.isNotEmpty(jo)){
+                        if (jo != null && ObjectUtils.isNotEmpty(jo)) {
                             jo.put("pkeyId", pk);
                             extra.add(jo);
                         }
@@ -2143,27 +2143,48 @@ public class ExcelTabController extends BladeController {
                 tableInfoList.sort(Comparator.comparingInt(a -> tableAllIds.indexOf(Long.parseLong(a.getPkeyId()))));
             }
         }
+
         //公式填充
-        this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeid), ExecuteType.INSPECTION);
-        // 保存数据到数据库
-        R info = this.excelTabService.saveOrUpdateInfo(tableInfoList);
-        if (!info.isSuccess()) {
-            return info;
+        this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeId), ExecuteType.INSPECTION);
+
+        //保存数据到数据库
+        R<Object> result = this.excelTabService.saveOrUpdateInfo(tableInfoList);
+        if (!result.isSuccess()) {
+            return R.fail("以下的表在保存数据时发生了异常【" + result.getMsg() + "】");
         }
-        try {
-            //单个 pdf加载
-            if (tableInfoList != null) {
-                for (TableInfo tableInfo : tableInfoList) {
-                    excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
+
+        List<String> errorPKeyIds = new ArrayList<>();
+        //单个pdf加载
+        if (tableInfoList != null) {
+            for (TableInfo tableInfo : tableInfoList) {
+                R bussPdfInfo = excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
+                if (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200 || ObjectUtil.isEmpty(bussPdfInfo.getData())) {
+                    //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
+                    errorPKeyIds.add(tableInfo.getPkeyId());
                 }
             }
-            // 合并pdf加载
-            excelTabService.getBussPdfs(nodeid, classify, contractId, projectId);
-        } catch (Exception e) {
-            e.printStackTrace();
         }
+
+        //发生异常后直接返回,不进行合并
+        if (errorPKeyIds.size() > 0) {
+            List<AppWbsTreeContractVO> errorTabs = new LinkedList<>();
+            for (AppWbsTreeContractVO appWbsTreeContractVO : tableAll) {
+                if (errorPKeyIds.contains(appWbsTreeContractVO.getPKeyId().toString())){
+                    errorTabs.add(appWbsTreeContractVO);
+                }
+            }
+            if (errorTabs.size() > 0) {
+                List<String> names = errorTabs.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
+                return R.fail("以下的表在生成pdf文件时发生了异常【" + StringUtils.join(names, "、") + "】");
+            }
+        }
+
+        //合并pdf加载
+        excelTabService.getBussPdfs(nodeId, classify, contractId, projectId);
+
         //更新缓存
         informationQueryClient.delAsyncWbsTree(contractId);
+
         return R.data("操作成功");
     }
 

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

@@ -104,7 +104,7 @@ public interface IExcelTabService extends BaseService<ExcelTab> {
     /**
      * 结果信息持久化
      */
-    R saveOrUpdateInfo(List<TableInfo> tableInfoList) throws SQLException;
+    R<Object> saveOrUpdateInfo(List<TableInfo> tableInfoList) throws SQLException;
 
     Map<String, String> getTablbCols(String pkeyid, String colkey) throws FileNotFoundException;
 

+ 29 - 34
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -335,7 +335,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         if (Func.isNotEmpty(tableInfoList)) {
             try {
                 /*用来保存日志执行情况*/
-                FormulaLog log =new FormulaLog();
+                FormulaLog log = new FormulaLog();
                 /*每次都是部分表单提交,保证跨节点跨表取数正常,其次是反向依赖的被动刷新*/
                 List<NodeTable> tableAll = createNodeTables(nodeId, tableInfoList.get(0).getContractId(), tableInfoList.get(0).getProjectId(), type);
                 StopWatch stopWatch = new StopWatch();
@@ -371,11 +371,11 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                             this.formulaService.execute(tec);
                             tec.after();
                         } else {
-                            tec.getLog().put(FormulaLog.OTHER,"没有执行任何公式");
+                            tec.getLog().put(FormulaLog.OTHER, "没有执行任何公式");
                         }
                         stopWatch.stop();
                         long totalTime = stopWatch.getTotalTimeMillis();
-                        log.put(FormulaLog.PF,"公式执行消耗时间:"+totalTime/1000+"秒");
+                        log.put(FormulaLog.PF, "公式执行消耗时间:" + totalTime / 1000 + "秒");
                         StaticLog.info("公式执行用时:{}", totalTime);
                         updateFormulaLog(log.toJsonString(), pKeyId);
                     }
@@ -955,8 +955,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
     }
 
     @Override
-    public R saveOrUpdateInfo(List<TableInfo> tableInfoList) {
-
+    public R<Object> saveOrUpdateInfo(List<TableInfo> tableInfoList) {
         if (ListUtils.isNotEmpty(tableInfoList)) {
             //施工资料填报
             String pkids = "";
@@ -1359,10 +1358,10 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 .eq(WbsTreeContract::getPKeyId, pkeyId));
 
         if (wbsTreeContract == null) {
-            return R.fail("该数据下无此节点!");
+            return R.fail("未获取到该表单的信息");
         }
         if (wbsTreeContract.getHtmlUrl() == null) {
-            return R.fail("请关联清表!");
+            return R.fail("htmlUrl is null");
         }
 
         String pdfPath = file_path + "/pdf//" + pkeyId + ".pdf";
@@ -1376,7 +1375,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         //获取清表信息
         ExcelTab excelTab = this.getById(wbsTreeContract.getExcelId());
         if (excelTab == null) {
-            return R.fail("失败");
+            return R.fail("未获取到清表信息");
         }
 
         Map<String, Object> DataInfo = (Map<String, Object>) getBussDataInfo(pkeyId, 0).getData();
@@ -1403,8 +1402,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         for (int i = 0; i < 10; i++) {
             CellRangeAddress mergedCell = sheet.getMergedRegion(i);
             int xx = mergedCell.getNumberOfCells();
-            if(xx>=all){
-                all=xx;
+            if (xx >= all) {
+                all = xx;
             }
         }
 
@@ -1444,7 +1443,6 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             }
         }
 
-
         //数据不为空
         if (StringUtils.isNotEmpty(wbsTreeContract.getHtmlUrl())) {
             InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(wbsTreeContract.getHtmlUrl());
@@ -1453,7 +1451,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             Document doc = Jsoup.parse(htmlString);
             Element table = doc.select("table").first();
             Elements trs = table.select("tr");
-            Elements cols = table.select("col");
+            //Elements cols = table.select("col");
 
             if (ObjectUtil.isNotEmpty(DataInfo)) {
                 for (String val : DataInfo.keySet()) {
@@ -1508,9 +1506,9 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                 Object obj = DataInfo.get(val);
                                 if (obj instanceof String[]) {
                                     String[] dataDate = (String[]) obj;
-                                    if((dataDate[0].trim()).equals((dataDate[1].trim()))){
+                                    if ((dataDate[0].trim()).equals((dataDate[1].trim()))) {
                                         myData = dataDate[0];
-                                    }else{
+                                    } else {
                                         myData = dataDate[0] + "-" + dataDate[1].trim();
                                     }
 
@@ -1598,7 +1596,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             queryWrapper.eq("tab_id", wbsTreeContract.getIsTypePrivatePid());
             List<TextdictInfo> textdictInfos = textdictInfoService.getBaseMapper().selectList(queryWrapper);
 
-           // table.getElementsByAttribute("dq")
+            // table.getElementsByAttribute("dq")
 
             if (textdictInfos != null && !textdictInfos.isEmpty()) {
                 for (TextdictInfo e : textdictInfos) {
@@ -1648,8 +1646,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 }
             }
         }
-        //输出流
 
+        //输出流
         FileOutputStream outputStream = new FileOutputStream(excelPath);
         workbook.write(outputStream);
 
@@ -1683,12 +1681,12 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         tableFileList.sort(Comparator.comparing(TableFile::getType));
 
         List<String> dataListPdf = new ArrayList<>();
-        if(wbsTreeContract.getIsBussShow() == 1){
+        if (wbsTreeContract.getIsBussShow() == 1) {
             dataListPdf = tableFileList.stream().filter(tableFile -> tableFile.getDomainPdfUrl() != null && (tableFile.getType() == 1 || tableFile.getType() == 2)).map(TableFile::getDomainPdfUrl).collect(Collectors.toList());
-        }else{
+        } else {
             dataListPdf = tableFileList.stream().filter(tableFile -> tableFile.getDomainPdfUrl() != null && tableFile.getType() == 2).map(TableFile::getDomainPdfUrl).collect(Collectors.toList());
         }
-//        List<String> dataListPdf = tableFileList.stream().filter(tableFile -> tableFile.getDomainPdfUrl() != null && (tableFile.getType() == 1 || tableFile.getType() == 2)).map(TableFile::getDomainPdfUrl).collect(Collectors.toList());
+        //List<String> dataListPdf = tableFileList.stream().filter(tableFile -> tableFile.getDomainPdfUrl() != null && (tableFile.getType() == 1 || tableFile.getType() == 2)).map(TableFile::getDomainPdfUrl).collect(Collectors.toList());
 
         String pdfPath2 = file_path + "/pdf//" + pkeyId + "_2.pdf";
 
@@ -1696,7 +1694,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         if (tabPdf2.exists()) {
             tabPdf2.delete();
         }
-        String fileUrl ="";
+        String fileUrl = "";
         if (dataListPdf.size() > 0) {
             FileUtils.mergePdfPublicMethods(dataListPdf, pdfPath2);
             BladeFile bladeFile2 = newIOSSClient.uploadFile(pkeyId + "2.pdf", pdfPath2);
@@ -1708,14 +1706,11 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         updateWrapper.set("pdf_url", fileUrl);
         wbsTreeContractService.update(updateWrapper);
 
-        if (outputStream != null) {
-            IoUtil.closeQuietly(outputStream);
-        }
-        if (exceInp != null) {
-            IoUtil.closeQuietly(exceInp);
-        }
-        return R.data(fileUrl);
+        //关闭流
+        IoUtil.closeQuietly(outputStream);
+        IoUtil.closeQuietly(exceInp);
 
+        return R.data(fileUrl);
     }
 
     @Override
@@ -1728,14 +1723,14 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             for (WbsTreeContract wbsInfo : wbsTreeContractList) {
                 // 隐藏的不生成pdf
 //                if (wbsInfo.getIsBussShow() == null || wbsInfo.getIsBussShow() != 2) { //
-                    if (StringUtils.isNotEmpty(wbsInfo.getPdfUrl())) {
-                        data.add(wbsInfo.getPdfUrl());
-                    } else {
-                        R bussPdfInfo = this.getBussPdfInfo(wbsInfo.getPKeyId());
-                        if (bussPdfInfo.getCode() == 200) {
-                            data.add(bussPdfInfo.getData() + "");
-                        }
+                if (StringUtils.isNotEmpty(wbsInfo.getPdfUrl())) {
+                    data.add(wbsInfo.getPdfUrl());
+                } else {
+                    R bussPdfInfo = this.getBussPdfInfo(wbsInfo.getPKeyId());
+                    if (bussPdfInfo.getCode() == 200) {
+                        data.add(bussPdfInfo.getData() + "");
                     }
+                }
 //                }
             }
         }

+ 5 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeContractServiceImpl.java

@@ -432,7 +432,7 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
         //当前项目合同段只会存在一个角色roleId
         SaveUserInfoByProject userInfo = baseMapper.selectRoleInfo(userId, contractId, projectId);
         if (userInfo == null) {
-            throw new ServiceException("请先分配当前用户对该合同段的角色信息=" + SecureUtil.getUserId());
+            throw new ServiceException("请先分配当前用户对该合同段的角色信息");
         }
         String roleId = userInfo.getRoleId();
 
@@ -446,8 +446,8 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
 
         List<String> tableOwnerList = null;
         if (StringUtils.isNotEmpty(tableOwner)) {
-            String tableOwners = "";
-            //此处加载字典owner_type 固定写死 施工质检1= 1 2 3 , 监理抽检2= 4 5 6
+            String tableOwners;
+            //字典owner_type
             if (tableOwner.equals("1")) {
                 tableOwners = "1,2,3";
             } else if (tableOwner.equals("2")) {
@@ -457,10 +457,11 @@ public class WbsTreeContractServiceImpl extends BaseServiceImpl<WbsTreeContractM
             }
             tableOwnerList = Func.toStrList(tableOwners);
         }
+
         List<AppWbsTreeContractVO> resultTabs = baseMapper.selectWbsTreeContractList(tableOwnerNumbers, wbsTreeContract.getProjectId(), wbsTreeContract.getWbsId(), wbsTreeContract.getContractId(), wbsTreeContract.getId(), wbsTreeContract.getContractIdRelation(), tableOwnerList);
 
         //表单排序
-        List<AppWbsTreeContractVO> resultTabsToCopy = sortTabs(resultTabs, "__");
+        List<AppWbsTreeContractVO> resultTabsToCopy = this.sortTabs(resultTabs, "__");
         return this.sortTabs(resultTabsToCopy, "_PL_");
     }