deason 1 年之前
父节点
当前提交
01edf6397d

+ 13 - 11
src/main/java/com/qmth/exam/reserve/cache/impl/ApplyTaskCacheService.java

@@ -59,7 +59,7 @@ public class ApplyTaskCacheService implements CacheConstants {
             return null;
         }
 
-        redisClient.set(cacheKey, value, 10, TimeUnit.MINUTES);
+        redisClient.set(cacheKey, value, 6, TimeUnit.HOURS);
         log.info("SET cacheKey:{} curApplyTaskId:{}", cacheKey, value.getTaskId());
 
         return value;
@@ -136,6 +136,16 @@ public class ApplyTaskCacheService implements CacheConstants {
         return value;
     }
 
+    /**
+     * 获取当前预约时段剩余可约数量
+     */
+    public int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
+        int totalCount = this.getApplyTotalCount(examSiteId);
+        int finishCount = this.getApplyFinishCount(examSiteId, timePeriodId);
+        int availableCount = totalCount - finishCount;
+        return Math.max(availableCount, 0);
+    }
+
     /**
      * 累加 某考点某时段的“已预约数量”
      */
@@ -160,14 +170,6 @@ public class ApplyTaskCacheService implements CacheConstants {
      * 获取某考生的 已完成预约次数
      */
     public int getStudentApplyFinishCount(Long studentId) {
-        /*String cacheKey = String.format(CACHE_STUDENT_APPLY_RECORD, studentId);
-        if (!redisClient.exist(cacheKey)) {
-            LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
-            wrapper.eq(StudentApplyEntity::getStudentId, studentId);
-            wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
-            return studentApplyService.count(wrapper);
-        }*/
-
         // Map<String, ApplyRecordCacheBean> maps = this.getStudentApplyRecords(studentId);
         // int studentApplyFinishCount = 0;
         // for (ApplyRecordCacheBean bean : maps.values()) {
@@ -189,7 +191,7 @@ public class ApplyTaskCacheService implements CacheConstants {
     public Map<String, ApplyRecordCacheBean> getStudentApplyRecords(Long studentId) {
         String cacheKey = String.format(CACHE_STUDENT_APPLY_RECORD, studentId);
         if (!redisClient.exist(cacheKey)) {
-            Map<String, ApplyRecordCacheBean> maps = this.getStudentApplyRecordsFormDB(studentId);
+            Map<String, ApplyRecordCacheBean> maps = this.getStudentApplyRecordsFromDB(studentId);
             if (MapUtils.isEmpty(maps)) {
                 return new HashMap<>();
             }
@@ -208,7 +210,7 @@ public class ApplyTaskCacheService implements CacheConstants {
     /**
      * 获取某考生的 所有的“预约记录”
      */
-    public Map<String, ApplyRecordCacheBean> getStudentApplyRecordsFormDB(Long studentId) {
+    public Map<String, ApplyRecordCacheBean> getStudentApplyRecordsFromDB(Long studentId) {
         LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(StudentApplyEntity::getStudentId, studentId);
         List<StudentApplyEntity> list = studentApplyService.list(wrapper);

+ 1 - 1
src/main/java/com/qmth/exam/reserve/cache/impl/OrgCacheService.java

@@ -63,7 +63,7 @@ public class OrgCacheService implements CacheConstants {
             return null;
         }
 
-        redisClient.set(CACHE_CURRENT_ORG, value, 12, TimeUnit.HOURS);
+        redisClient.set(CACHE_CURRENT_ORG, value, 6, TimeUnit.HOURS);
         log.info("SET cacheKey:{} curOrgId:{}", CACHE_CURRENT_ORG, value.getOrgId());
 
         return value;

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

@@ -106,8 +106,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 throw new StatusException(Constants.SYSTEM_BUSY);
             }
 
-            log.warn("获取锁成功!lockKey:{}", studentApplyLockKey);
-
+            log.info("获取锁成功!lockKey:{}", studentApplyLockKey);
             if (concurrentService.isLocked(CacheConstants.LOCK_AUTO_APPLY)) {
                 // 系统自动预约“任务执行期间”不允许预约
                 log.warn("系统自动预约中,不允许考生操作预约!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
@@ -125,7 +124,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             }
 
             // 当前预约时段剩余可约数量
-            int availableCount = this.getApplyAvailableCount(examSiteId, timePeriodId);
+            int availableCount = applyTaskCacheService.getApplyAvailableCount(examSiteId, timePeriodId);
             if (availableCount < 1) {
                 log.warn("预约失败,当前预约时段已约满!examSiteId:{} timePeriodId:{}", examSiteId, timePeriodId);
                 throw new StatusException("当前预约时段已约满");
@@ -259,8 +258,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 throw new StatusException(Constants.SYSTEM_BUSY);
             }
 
-            log.warn("获取锁成功!lockKey:{}", studentApplyLockKey);
-
+            log.info("获取锁成功!lockKey:{}", studentApplyLockKey);
             if (concurrentService.isLocked(CacheConstants.LOCK_AUTO_APPLY)) {
                 // 系统自动预约“任务执行期间”不允许取消预约
                 log.warn("系统自动预约中,不允许考生操作预约!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
@@ -294,14 +292,6 @@ public class ExamReserveServiceImpl implements ExamReserveService {
         }
     }
 
-    private int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
-        // 当前预约时段剩余可约数量
-        int totalCount = applyTaskCacheService.getApplyTotalCount(examSiteId);
-        int finishCount = applyTaskCacheService.getApplyFinishCount(examSiteId, timePeriodId);
-        int availableCount = totalCount - finishCount;
-        return Math.max(availableCount, 0);
-    }
-
     private StudentApplyEntity getStudentApply(Long studentId, Long examSiteId, Long timePeriodId) {
         LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(StudentApplyEntity::getExamSiteId, examSiteId);
@@ -551,7 +541,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
         List<TimePeriodEntity> timePeriods = timePeriodService.list(wrapper);
 
         // 获取某考生的 所有的“预约记录”
-        Map<String, ApplyRecordCacheBean> maps = applyTaskCacheService.getStudentApplyRecordsFormDB(student.getId());
+        Map<String, ApplyRecordCacheBean> maps = applyTaskCacheService.getStudentApplyRecordsFromDB(student.getId());
         int studentApplyFinishCount = 0;
         for (ApplyRecordCacheBean bean : maps.values()) {
             if (!bean.getCancel()) {
@@ -571,7 +561,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 info.setTimePeriodStart(timePeriod.getStartTime());
                 info.setTimePeriodEnd(timePeriod.getEndTime());
 
-                int availableCount = this.getApplyAvailableCount(examSiteId, timePeriod.getId());
+                int availableCount = applyTaskCacheService.getApplyAvailableCount(examSiteId, timePeriod.getId());
                 info.setAvailableCount(availableCount);
                 if (availableCount < 1) {
                     info.setStatus(ApplyStatus.FULL);