wangliang 4 năm trước cách đây
mục cha
commit
0f21e42a7b

+ 4 - 13
distributed-print-business/src/main/java/com/qmth/distributed/print/business/cache/CreatePdfCacheUtil.java

@@ -2,10 +2,6 @@ package com.qmth.distributed.print.business.cache;
 
 import com.qmth.distributed.print.business.util.RedisUtil;
 import com.qmth.distributed.print.common.contant.SpringContextHolder;
-import com.qmth.distributed.print.common.contant.SystemConstant;
-
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 /**
  * @Description: 生成pdf cache
@@ -17,16 +13,11 @@ import java.util.concurrent.TimeUnit;
 public class CreatePdfCacheUtil {
     private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
 
-    public static void setCurrentPaperType(Long printPlanId, Map<String, Object> map) {
-        redisUtil.setForHash(RedisKeyHelper.printPlanIdCurrentPaperTypeKey(printPlanId), map);
-        redisUtil.expire(RedisKeyHelper.printPlanIdCurrentPaperTypeKey(printPlanId), SystemConstant.REDIS_CREATE_PDF_EXPIRE_TIME, TimeUnit.SECONDS);
-    }
-
-    public static Map getCurrentPaperType(Long printPlanId) {
-        return redisUtil.getHashEntries(RedisKeyHelper.printPlanIdCurrentPaperTypeKey(printPlanId));
+    public static void setPaperType(String key, String paperType) {
+        redisUtil.set(RedisKeyHelper.paperTypeKey(key), paperType);
     }
 
-    public static void deleteCurrentPaperType(Long printPlanId) {
-        redisUtil.delete(RedisKeyHelper.printPlanIdCurrentPaperTypeKey(printPlanId));
+    public static String getPaperType(String key) {
+        return (String) redisUtil.get(RedisKeyHelper.paperTypeKey(key));
     }
 }

+ 3 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/cache/RedisKeyHelper.java

@@ -9,9 +9,9 @@ package com.qmth.distributed.print.business.cache;
  */
 public class RedisKeyHelper {
 
-    private static String printPlanIdCurrentPaperTypePrefix = "print_planId_current_paper_type:";
+    private static String paperTypePrefix = "paper_type:";
 
-    public static String printPlanIdCurrentPaperTypeKey(Long id) {
-        return printPlanIdCurrentPaperTypePrefix + id;
+    public static String paperTypeKey(String key) {
+        return paperTypePrefix + key;
     }
 }

+ 0 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java

@@ -683,8 +683,6 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
         }
         // 删除exam_student 表数据
         examStudentService.remove(new QueryWrapper<ExamStudent>().lambda().in(ExamStudent::getId, examStudentIds));
-
-        CreatePdfCacheUtil.deleteCurrentPaperType(printPlanId);
     }
 
     private List<ExtendFieldsDto> getExtendFieldsByFields(List<FieldsDto> fieldsDtoList) {

+ 8 - 12
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -384,22 +384,20 @@ public class CreatePdfUtil {
      * @return
      */
     public String getPaperType(ExamPrintPlan examPrintPlan, ExamTaskDetail examTaskDetail, ExamDetail examDetail, ExamDetailCourse examDetailCourse) {
-        Map<String, Object> paperTypeMap = CreatePdfCacheUtil.getCurrentPaperType(examPrintPlan.getId());
-        paperTypeMap = Objects.isNull(paperTypeMap) ? paperTypeMap = new HashMap<>() : paperTypeMap;
         String key = examDetail.getSchoolId()
-                + Math.abs(examDetail.getExamStartTime() + examDetail.getExamEndTime())
-                + examDetail.getExamPlace()
-                + examDetailCourse.getCourseCode()
-                + examDetailCourse.getPaperNumber();
+                + "_" + examDetail.getExamStartTime()
+                + "_" + examDetail.getExamEndTime()
+                + "_" + examDetail.getExamPlace()
+                + "_" + examDetailCourse.getCourseCode()
+                + "_" + examDetailCourse.getPaperNumber();
         String paperType = null;
         boolean lock = true;
         for (int i = 0; i < SystemConstant.MAX_RETRY_COUNT; i++) {
             lock = redisUtil.lock(key, SystemConstant.REDIS_CACHE_TIME_OUT);
             if (lock) {
                 try {
-                    if (paperTypeMap.containsKey(key)) {
-                        paperType = (String) paperTypeMap.get(key);
-                    } else {
+                    paperType = CreatePdfCacheUtil.getPaperType(key);
+                    if (Objects.isNull(paperType)) {
                         //抽取卷型
                         DrawRuleEnum drawRule = Objects.nonNull(examPrintPlan.getDrawRule()) ? examPrintPlan.getDrawRule() : DrawRuleEnum.ONE;
                         //未曝光卷型
@@ -425,9 +423,7 @@ public class CreatePdfUtil {
                         }
                         int paperRandom = new Random().nextInt(paperTypes.length);
                         paperType = paperTypes[paperRandom];
-                        String finalPaperType = paperType;
-                        paperTypeMap.computeIfAbsent(key, v -> finalPaperType);
-                        CreatePdfCacheUtil.setCurrentPaperType(examPrintPlan.getId(), paperTypeMap);
+                        CreatePdfCacheUtil.setPaperType(key, paperType);
                     }
                     break;
                 } catch (Exception e) {