Quellcode durchsuchen

feat: 优化子查询;超时设到30min

dengjia vor 3 Tagen
Ursprung
Commit
fd4d280551

+ 20 - 8
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/controller/init/InitController.java

@@ -1466,11 +1466,8 @@ public class InitController {
     return R.ok(r);
   }
 
-  /* @ResponseExcel(
-      name = "taskCheckHistoryExcel",
-      sheets = {@Sheet(sheetName = "审核信息")}) */
   @GetMapping(value = "/cnbg/init/task/check/his/export")
-  public List<TaskCheckHistoryExcelModel> exportTaskCheckHistoryExcel(
+  public R<List<TaskCheckHistoryExcelModel>> exportTaskCheckHistoryExcel(
     @RequestParam(value = "taskPeriod", required = true) LocalDate[] taskPeriod) {
     
     if(taskPeriod == null || taskPeriod.length < 2 || taskPeriod[1].minus(31, ChronoUnit.DAYS).isAfter(taskPeriod[0])) {
@@ -1481,12 +1478,27 @@ public class InitController {
       throw new RuntimeException("没有导出审核监督明细的权限");
     }
 
-    // sync
-    // return wmTaskSupervisionService.selectTaskSupProcess(SecurityUtils.getUser(), taskPeriod);
-
     // async
     wmTaskSupervisionService.asyncExportTaskCheckSup(SecurityUtils.getUser(), taskPeriod);
-    return List.of();
+    return R.ok(List.of());
+  }
+
+  @ResponseExcel(
+      name = "taskCheckHistoryExcel",
+      sheets = {@Sheet(sheetName = "审核信息")})
+  @GetMapping(value = "/cnbg/init/task/check/his/export-sync")
+  public List<TaskCheckHistoryExcelModel> exportTaskCheckHistoryExcelSync(
+    @RequestParam(value = "taskPeriod", required = true) LocalDate[] taskPeriod) {
+    
+    if(taskPeriod == null || taskPeriod.length < 2 || taskPeriod[1].minus(31, ChronoUnit.DAYS).isAfter(taskPeriod[0])) {
+      throw new RuntimeException("合法的任务导出区间是一个月");
+    }
+
+    if(!CollUtil.contains(SecurityUtils.getRoles(),53)) {
+      throw new RuntimeException("没有导出审核监督明细的权限");
+    }
+
+    return wmTaskSupervisionService.selectTaskSupProcess(SecurityUtils.getUser(), taskPeriod);
   }
 
   private Map<String, String> getInfo(

+ 1 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/service/impl/WmTaskSupervisionServiceImpl.java

@@ -153,7 +153,7 @@ public class WmTaskSupervisionServiceImpl extends ServiceImpl<WmTaskSupervisionM
         List<TaskCheckHistoryExcelModel> t = List.of();
         try {
             t = retryTemplate.execute(retryContext -> {
-                log.info("人员异步导出第{}次重试", retryContext.getRetryCount());
+                log.info("任务审核监督异步导出第{}次重试", retryContext.getRetryCount());
                 redisUtils.checkExportGlobalAllows(upmsConfig.getAsyncExportLimit());
 
                 List<TaskCheckHistoryExcelModel> data = 

+ 1 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/util/ExportUtils.java

@@ -48,7 +48,7 @@ public final class ExportUtils {
 		String ret = ERROR_MSG_UNKNOWN;
 		try {
 			// 写入excel文件
-			EasyExcel.write(fullPath, head).sheet(exportType.getDescription())
+			EasyExcel.write(fullPath).sheet(exportType.getDescription())
 					.doWrite(data);
 			log.info("{}导出生成缓存文件:{}", exportType.getDescription(), fullPath);
 

+ 1 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/util/OsEnvUtils.java

@@ -82,7 +82,7 @@ public final class OsEnvUtils {
       pathMap.put(TargetFile.FONT.getName(), "~/");
       pathMap.put(TargetFile.CONTRACT.getName(), "~/");
       pathMap.put(TargetFile.TEMPLATE.getName(), "~/");
-      pathMap.put(TargetFile.TEMP.getName(), "~/");
+      pathMap.put(TargetFile.TEMP.getName(), "/tmp/");
     }
     if (osName.contains("windows")) {
       pathMap.put(TargetFile.EXCEL.getName(), "D:\\");

+ 1 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/util/RedisUtils.java

@@ -73,7 +73,7 @@ public final class RedisUtils {
 
 			// 设置key的过期时间,避免计数器无限增长
 			if (increment != null && increment.equals(1L)) {
-				redisTemplate.expire(key, 1, TimeUnit.MINUTES);
+				redisTemplate.expire(key, 30, TimeUnit.MINUTES);
 			}
 
 			// 检查是否超过限流阈值

+ 91 - 130
hnqz-upms/hnqz-upms-biz/src/main/resources/mapper/WmTaskSupervisionMapper.xml

@@ -172,7 +172,52 @@
     <result property="financeSubmgrRemarks" column="finance_submgr_remarks"/>
   </resultMap>
 
-<select id="selectTaskSupProcess" resultMap="wmTaskSupProcessMap">
+<select id="selectTaskSupProcess" resultMap="wmTaskSupProcessMap" timeout="1800">
+  WITH base_check_his AS (
+      SELECT
+          target_id,
+          node_id,
+          check_result,
+          check_msg,
+          update_time1,
+          create_by1
+      FROM sys_chain_node_check_his
+      WHERE create_time1 &gt;= #{taskBeginTime}
+  ),
+  check_users AS (
+      SELECT DISTINCT username, realname FROM sys_user
+  ),
+  check_data AS (
+      SELECT
+          b.target_id,
+          b.node_id,
+          b.check_result,
+          b.check_msg,
+          b.update_time1,
+          u.realname
+      FROM base_check_his b
+      JOIN check_users u ON b.create_by1 = u.username
+  ),
+  sup_data AS (
+    select sup."task_id", u.realname, sup.create_time, sup.sup_res, sup."remarks", ur.role_id from wm_task_sup sup 
+
+    join sys_user u on u."username" = sup."create_by"
+
+    join "sys_user_role" ur on u.user_id = ur."user_id"
+
+    where sup."create_time" &gt;= #{taskBeginTime} 
+  ),
+  adv_data AS (
+    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks, ur.role_id from wm_task_sup sup 
+
+    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
+
+    join sys_user u on u."username" = adv."create_by"
+
+    join "sys_user_role" ur on u.user_id = ur."user_id"
+
+    where sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0' 
+  )
   select
 
     t.id,
@@ -393,15 +438,11 @@
 
   (
 
-    select "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
-
-    from "sys_chain_node_check_his" his
-
-    join (select distinct username, realname from sys_user) u
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    on u."username" = his."create_by1"
+    from check_data
 
-    where "node_id" = 1 and create_time1 &gt;= #{taskBeginTime} <!-- 服务商 -->
+    where "node_id" = 1 <!-- 服务商 -->
 
   ) t1
 
@@ -411,15 +452,11 @@
 
   (
 
-    select "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    from "sys_chain_node_check_his" his
+    from check_data
 
-    join (select distinct username, realname from sys_user) u
-
-    on u."username" = his."create_by1"
-
-    where "node_id" = 2 and create_time1 &gt;= #{taskBeginTime} <!-- 地市 -->
+    where "node_id" = 2  <!-- 地市 -->
 
   ) t2
 
@@ -429,13 +466,11 @@
 
   (
 
-    select "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
-
-    from "sys_chain_node_check_his" his join (select distinct username, realname from sys_user) u
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    on u."username" = his."create_by1"
+    from check_data
 
-    where "node_id" = 3 and create_time1 &gt;= #{taskBeginTime} <!-- 区域 -->
+    where "node_id" = 3  <!-- 区域 -->
 
   ) t3
 
@@ -445,13 +480,11 @@
 
   (
 
-    select "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    from "sys_chain_node_check_his" his join (select distinct username, realname from sys_user) u
+    from check_data
 
-    on u."username" = his."create_by1"
-
-    where "node_id" = 8 and create_time1 &gt;= #{taskBeginTime} <!-- 市场 -->
+    where "node_id" = 8 <!-- 市场 -->
 
   ) t8
 
@@ -461,13 +494,11 @@
 
     (
 
-    select "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
-
-    from "sys_chain_node_check_his" his join (select distinct username, realname from sys_user) u
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    on u."username" = his."create_by1"
+    from check_data
 
-    where "node_id" = 9 and create_time1 &gt;= #{taskBeginTime} <!-- 商务 -->
+    where "node_id" = 9 <!-- 商务 -->
 
     ) t9
 
@@ -477,13 +508,11 @@
 
     (
 
-    select "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
-
-    from "sys_chain_node_check_his" his join (select distinct username, realname from sys_user) u
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    on u."username" = his."create_by1"
+    from check_data
 
-    where "node_id" = 5 and create_time1 &gt;= #{taskBeginTime} <!-- 分管领导 -->
+    where "node_id" = 5 <!-- 分管领导 -->
 
     ) t5
 
@@ -493,13 +522,11 @@
 
     (
 
-    select distinct "target_id", "check_result", "check_msg", his."update_time1" update_time, u."realname"
+    select "target_id", "check_result", "check_msg", "update_time1" update_time, "realname"
 
-    from "sys_chain_node_check_his" his join (select distinct username, realname from sys_user) u
+    from check_data
 
-    on u."username" = his."create_by1"
-
-    where "node_id" = 6 and create_time1 &gt;= #{taskBeginTime} <!-- 总经理 -->
+    where "node_id" = 6 <!-- 总经理 -->
 
     ) t6
 
@@ -509,15 +536,9 @@
 
     (
 
-    select sup."task_id", u.realname, sup.create_time, sup.sup_res, sup."remarks" from wm_task_sup sup 
-
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = sup."create_by"
+    select "task_id", realname, create_time, sup_res, "remarks" from sup_data
 
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 49 and sup."create_time" &gt;= #{taskBeginTime}  <!-- 厂家财务 -->
+    where "role_id" = 49 <!-- 厂家财务 -->
 
     ) sup1
 
@@ -527,15 +548,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
-
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    where ur."role_id" = 57 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'   <!-- 厂家财务负责人 -->
+    where "role_id" = 57 <!-- 厂家财务负责人 -->
 
     ) sup11
 
@@ -545,15 +560,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 51 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 厂家财务分管领导 -->
+    where "role_id" = 51 <!-- 厂家财务分管领导 -->
 
     ) sup12
 
@@ -563,13 +572,9 @@
 
     (
 
-    select sup."task_id", u.realname, sup.create_time, sup.sup_res, sup."remarks" from wm_task_sup sup 
+    select "task_id", realname, create_time, sup_res, "remarks" from sup_data
 
-    join sys_user u on u."username" = sup."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 52 and sup."create_time" &gt;= #{taskBeginTime}  <!-- 厂家销售 -->
+    where "role_id" = 52 <!-- 厂家销售 -->
 
     ) sup2
 
@@ -579,15 +584,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 58 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 厂家销售负责人 -->
+    where "role_id" = 58 <!-- 厂家销售负责人 -->
 
     ) sup21
 
@@ -597,15 +596,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
-
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    where ur."role_id" = 61 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 厂家销售分管领导 -->
+    where "role_id" = 61 <!-- 厂家销售分管领导 -->
 
     ) sup22
 
@@ -615,13 +608,9 @@
 
     (
 
-    select sup."task_id", u.realname, sup.create_time, sup.sup_res, sup."remarks" from wm_task_sup sup 
+    select "task_id", realname, create_time, sup_res, "remarks" from sup_data
 
-    join sys_user u on u."username" = sup."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 53 and sup."create_time" &gt;= #{taskBeginTime}  <!-- 营销合规 -->
+    where "role_id" = 53 <!-- 营销合规 -->
 
     ) sup3
 
@@ -631,15 +620,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 60 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 营销合规负责人 -->
+    where "role_id" = 60 <!-- 营销合规负责人 -->
 
     ) sup31
 
@@ -649,15 +632,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 54 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 营销合规分管领导 -->
+    where "role_id" = 54 <!-- 营销合规分管领导 -->
 
     ) sup32
 
@@ -667,13 +644,9 @@
 
     (
 
-    select sup."task_id", u.realname, sup.create_time, sup.sup_res, sup."remarks" from wm_task_sup sup 
+    select "task_id", realname, create_time, sup_res, "remarks" from sup_data
 
-    join sys_user u on u."username" = sup."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 56 and sup."create_time" &gt;= #{taskBeginTime}  <!-- 营销财务 -->
+    where "role_id" = 56 <!-- 营销财务 -->
 
     ) sup4
 
@@ -683,15 +656,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
+    select "task_id", realname, create_time, advice_result, remarks from adv_data
 
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
-
-    where ur."role_id" = 59 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 营销财务负责人 -->
+    where "role_id" = 59 <!-- 营销财务负责人 -->
 
     ) sup41
 
@@ -701,15 +668,9 @@
 
     (
 
-    select sup."task_id", u.realname, adv.create_time, adv.advice_result, adv.remarks  from wm_task_sup sup 
-
-    join wm_task_sup_adv adv on adv.task_supervision_id = sup.sup_id
-
-    join sys_user u on u."username" = adv."create_by"
-
-    join "sys_user_role" ur on u.user_id = ur."user_id"
+    select "task_id", realname, create_time, advice_result, remarks  from adv_data
 
-    where ur."role_id" = 55 and sup."create_time" &gt;= #{taskBeginTime} and adv.del_flag = '0'  <!-- 营销财务分管领导 -->
+    where "role_id" = 55 <!-- 营销财务分管领导 -->
 
     ) sup42