Browse Source

质检-保存表单,把生成pdf改为异步执行,更新redis环境去掉

LHB 1 tháng trước cách đây
mục cha
commit
374898d7d2

+ 3 - 33
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -2003,40 +2003,10 @@ public class ExcelTabController extends BladeController {
             return R.fail(result.getMsg());
         }
         executionTime.info("----数据合并前----");
-        List<String> errorPKeyIds = new ArrayList<>();
-        //单个pdf加载
-        if (tableInfoList != null) {
-            tableInfoList.parallelStream().forEach(tableInfo -> {
-                R bussPdfInfo = null;
-                try {
-                    bussPdfInfo = excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                if (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200) {
-                    //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
-                    errorPKeyIds.add(tableInfo.getPkeyId());
-                }
-            });
-        }
 
-        executionTime.info("----数据保存完毕 ----");
-        //发生异常后直接返回,不进行合并
-        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, "、") + "】");
-            }
-        }
-        executionTime.info("----数据合并前 ----");
-        //合并pdf加载
-        excelTabService.getBussPdfs(nodeId, classify, contractId, projectId);
+        //异步生成pdf 和 合并pdf
+        excelTabService.synchronizedPdf(tableInfoList,nodeId, classify, contractId, projectId);
+
         executionTime.info("---PDF合并耗时---");
         //更新缓存
         informationQueryClient.delAsyncWbsTree(contractId);

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

@@ -211,4 +211,6 @@ public interface IExcelTabService extends BaseService<ExcelTab> {
      * @return
      */
     List<Map<String, Object>> getBussDataInfoTrialentrust(Long id, Long pkeyId, Long contractId, Long sampleId, JSONObject jsonObject,Boolean isremove,Boolean isCaneal);
+
+    void synchronizedPdf(List<TableInfo> tableInfoList, String nodeId, String classify, String contractId, String projectId) throws Exception;
 }

+ 44 - 1
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -78,6 +78,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
@@ -1318,7 +1319,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                 //保存操作记录
                 this.operationLogClient.saveUserOperationLog(1, "资料填报", "工序填报页面", json);
                 // 更新redis
-                informationQueryClient.AsyncWbsTree(wbsTreeContractByP.getParentId() + "", wbsTreeContractByP.getParentId() + "", wbsTreeContractByP.getContractId(), "", "1");
+//                informationQueryClient.AsyncWbsTree(wbsTreeContractByP.getParentId() + "", wbsTreeContractByP.getParentId() + "", wbsTreeContractByP.getContractId(), "", "1");
             } catch (Exception e) {
                 e.printStackTrace();
                 return R.fail("操作失败");
@@ -5004,4 +5005,46 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         }
     }
 
+    @Override
+    @Async("taskExecutor1")
+    public void synchronizedPdf(List<TableInfo> tableInfoList, String nodeId, String classify, String contractId, String projectId) {
+        try {
+            List<String> errorPKeyIds = new ArrayList<>();
+            //单个pdf加载
+            if (tableInfoList != null) {
+                tableInfoList.parallelStream().forEach(tableInfo -> {
+                    R bussPdfInfo = null;
+                    try {
+                        bussPdfInfo = this.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    if (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200) {
+                        //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
+                        errorPKeyIds.add(tableInfo.getPkeyId());
+                    }
+                });
+            }
+
+            //发生异常后直接返回,不进行合并
+//        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加载
+            this.getBussPdfs(nodeId, classify, contractId, projectId);
+        } catch (Exception e) {
+            e.printStackTrace();
+            throw new ServiceException("问题");
+        }
+    }
 }