deason 1 year ago
parent
commit
8d86a85636

+ 9 - 3
src/main/java/com/qmth/exam/reserve/cache/CacheConstants.java

@@ -6,10 +6,16 @@ package com.qmth.exam.reserve.cache;
 public interface CacheConstants {
 
     /**
-     * 预约任务 - 某考点某时段的“可预约总量”的缓存
-     * $cache:apply_total:{examSiteId}_{timePeriodId}
+     * 当前启用的预约任务缓存
+     * $cache:current_apply_task:{orgId}
      */
-    String CACHE_APPLY_TOTAL = "$cache:apply_total:%s_%s";
+    String CACHE_CURRENT_APPLY_TASK = "$cache:current_apply_task:%s";
+
+    /**
+     * 预约任务 - 某考点的“可预约总量”的缓存
+     * $cache:apply_total:{examSiteId}
+     */
+    String CACHE_APPLY_TOTAL = "$cache:apply_total:%s";
 
     /**
      * 预约任务 - 某考点某时段的“已预约数量”的缓存

+ 29 - 4
src/main/java/com/qmth/exam/reserve/cache/impl/ApplyTaskCacheService.java

@@ -1,7 +1,9 @@
 package com.qmth.exam.reserve.cache.impl;
 
+import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
 import com.qmth.exam.reserve.cache.CacheConstants;
 import com.qmth.exam.reserve.cache.RedisClient;
+import com.qmth.exam.reserve.service.ApplyTaskService;
 import com.qmth.exam.reserve.service.ExamSiteService;
 import com.qmth.exam.reserve.service.StudentApplyService;
 import com.qmth.exam.reserve.service.StudentService;
@@ -21,6 +23,9 @@ public class ApplyTaskCacheService implements CacheConstants {
     @Autowired
     private RedisClient redisClient;
 
+    @Autowired
+    private ApplyTaskService applyTaskService;
+
     @Autowired
     private ExamSiteService examSiteService;
 
@@ -30,6 +35,27 @@ public class ApplyTaskCacheService implements CacheConstants {
     @Autowired
     private StudentApplyService studentApplyService;
 
+    /**
+     * 获取当前启用的预约任务缓存
+     */
+    public CurrentApplyTaskVO currentApplyTask(Long orgId) {
+        String cacheKey = String.format(CACHE_CURRENT_APPLY_TASK, orgId);
+        CurrentApplyTaskVO value = redisClient.get(cacheKey, CurrentApplyTaskVO.class);
+        if (value != null) {
+            return value;
+        }
+
+        value = applyTaskService.currentApplyTask(orgId);
+        if (value == null) {
+            return null;
+        }
+
+        redisClient.set(cacheKey, value, 3, TimeUnit.HOURS);
+        log.info("{} = id:{} name:{}", cacheKey, value.getTaskId(), value.getTaskName());
+
+        return value;
+    }
+
     /**
      * 获取某考生的“允许预约时段次数”
      */
@@ -48,16 +74,15 @@ public class ApplyTaskCacheService implements CacheConstants {
     }
 
     /**
-     * 获取某考点某时段的“可预约总量”
+     * 获取某考点的“可预约总量”
      */
-    public int getApplyTotalCount(Long examSiteId, Long timePeriodId) {
-        String cacheKey = String.format(CACHE_APPLY_TOTAL, examSiteId, timePeriodId);
+    public int getApplyTotalCount(Long examSiteId) {
+        String cacheKey = String.format(CACHE_APPLY_TOTAL, examSiteId);
         Integer value = redisClient.get(cacheKey, Integer.class);
         if (value != null) {
             return value;
         }
 
-        // 当前考点当前时段容量 = 当前考点总容量
         value = examSiteService.countExamSiteCapacityById(examSiteId);
         redisClient.set(cacheKey, value, 3, TimeUnit.HOURS);
         log.info("{} = {}", cacheKey, value);

+ 1 - 1
src/main/java/com/qmth/exam/reserve/service/impl/ExamReserveServiceImpl.java

@@ -258,7 +258,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
 
     private int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
         // 当前预约时段剩余可约数量
-        int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId, timePeriodId);
+        int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId);
         int finishCount = applyTaskCacheService.getApplyFinishCount(examSiteId, timePeriodId);
         int availableCount = totalCount - finishCount;
         return Math.max(availableCount, 0);