Przeglądaj źródła

clean up generating status in finally

dengjia 4 dni temu
rodzic
commit
8be502708f

+ 2 - 1
hnqz-upms/hnqz-upms-biz/src/main/java/com/qunzhixinxi/hnqz/admin/aspect/ExportGuardAspect.java

@@ -2,6 +2,7 @@
 package com.qunzhixinxi.hnqz.admin.aspect;
 
 import com.qunzhixinxi.hnqz.admin.api.constant.enums.ExportType;
+import com.qunzhixinxi.hnqz.admin.api.entity.WmReportOpt;
 import com.qunzhixinxi.hnqz.common.security.service.HnqzUser;
 
 import org.springframework.data.redis.core.RedisTemplate;
@@ -40,7 +41,7 @@ public class ExportGuardAspect {
 		@SuppressWarnings("unchecked")
 		RedisTemplate<String, Object> redisTemplate = (RedisTemplate<String, Object>) SpringUtil.getBean("redisTemplate");
 		String status = (String) redisTemplate.opsForValue().get(key);
-		if ("GENERATING".equals(status)) {
+		if (WmReportOpt.WmReportOptStatus.GENERATING.name().equals(status)) {
 			throw new RuntimeException("导出正在生成中,请稍后再试");
 		}
 		

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

@@ -154,8 +154,8 @@ public class WmTaskSupervisionServiceImpl extends ServiceImpl<WmTaskSupervisionM
         try {
             t = retryTemplate.execute(retryContext -> {
                 log.info("人员异步导出第{}次重试", retryContext.getRetryCount());
-
                 redisUtils.checkExportGlobalAllows(upmsConfig.getAsyncExportLimit());
+
                 List<TaskCheckHistoryExcelModel> data = 
                     wmTaskSupervisionMapper.selectTaskSupProcess(LocalDateTime.of(taskPeriod[0], LocalTime.MIN), LocalDateTime.of(taskPeriod[1], LocalTime.MAX));
                 // 导出
@@ -165,6 +165,7 @@ public class WmTaskSupervisionServiceImpl extends ServiceImpl<WmTaskSupervisionM
             });
 		} finally {
             redisUtils.releaseExportGlobalAllows();
+            redisUtils.cleanupGenerating(ExportType.CHECK_SUP, user.getId());
 		}
 
         return t;

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

@@ -30,10 +30,10 @@ import org.springframework.stereotype.Component;
 @Component
 public final class ExportUtils {
 
-  @Resource private RedisTemplate<String, Object> redisTemplate;
-  @Resource private SysFileService fileService;
+	@Resource private RedisTemplate<String, Object> redisTemplate;
+	@Resource private SysFileService fileService;
 
-  public static final String ERROR_MSG_UNKNOWN = "ERROR_未知错误,请联系管理员";
+	public static final String ERROR_MSG_UNKNOWN = "ERROR_未知错误,请联系管理员";
 	public static final String ERROR_MSG_NO_DATA = "ERROR_没有数据";
 	public static final String ERROR_MSG_UPLOAD_FAIL = "ERROR_上传OSS失败";
 

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

@@ -96,6 +96,16 @@ public final class RedisUtils {
 		  redisTemplate.opsForValue().decrement(CacheConstants.ASYNC_EXPORT_LIMIT_KEY);
   }
 
+  public void cleanupGenerating(ExportType exportType, Integer userId) {
+      // 缓存key
+			String cacheKey = ExportType.getAsyncExportCache(exportType, userId);
+			// 更新状态为生成中
+      String status = (String) redisTemplate.opsForValue().get(cacheKey);
+      if (WmReportOpt.WmReportOptStatus.GENERATING.name().equals(status)) {
+			  redisTemplate.opsForValue().set(cacheKey, ExportUtils.ERROR_MSG_UNKNOWN, CommonConstants.DEF_REPORT_TTL, TimeUnit.MILLISECONDS);
+      }
+  }
+
   @Data
   @AllArgsConstructor
   public static class Token{