deason 8 ヶ月 前
コミット
5b9a6ecb47

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

@@ -167,7 +167,8 @@ public class ApplyTaskCacheService implements CacheConstants {
     public void increaseApplyAvailableCount(Long examSiteId, Long timePeriodId) {
         String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSiteId, timePeriodId);
         RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
-        atomic.incrementAndGet();
+        long value = atomic.incrementAndGet();
+        log.warn("累加成功,最新考点剩余可约数量:{} cacheKey:{}", value, cacheKey);
     }
 
     /**
@@ -188,11 +189,11 @@ public class ApplyTaskCacheService implements CacheConstants {
         luaScript.append("end;");
         luaScript.append("return -2;");
         List<String> keys = Collections.singletonList(cacheKey);
-        List<Object> args = Collections.singletonList(1);
+        Object[] args = new Object[]{1};
 
         // 执行Lua脚本,传入键列表和参数列表
         DefaultRedisScript<Long> redisScript = new DefaultRedisScript<>(luaScript.toString(), Long.class);
-        Long result = redisClient.getRedisTemplate().execute(redisScript, keys, args.toArray(new Object[0]));
+        Long result = redisClient.getRedisTemplate().execute(redisScript, keys, args);
         Objects.requireNonNull(result, "缓存操作异常,返回结果为空!");
 
         if (-2 == result) {
@@ -413,13 +414,4 @@ public class ApplyTaskCacheService implements CacheConstants {
         }
     }
 
-    /**
-     * 获取考生预约记录队列数量
-     */
-    public int getStudentApplyRecordQueueSize() {
-        RQueue<ApplyRecordCacheBean> queue = redisClient.getRedissonClient()
-                .getQueue(QUEUE_STUDENT_APPLY_RECORD);
-        return queue.size();
-    }
-
 }

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

@@ -120,6 +120,12 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("当前预约时段已禁止预约");
         }
 
+        if (concurrentService.isLocked(CacheConstants.LOCK_AUTO_APPLY)) {
+            // 系统自动预约“任务执行期间”不允许预约
+            log.warn("系统自动预约中,不允许考生操作预约!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
+            throw new StatusException(Constants.SYSTEM_BUSY);
+        }
+
         // 考生预约操作锁
         String studentApplyLockKey = String.format(CacheConstants.LOCK_STUDENT_APPLY, student.getId());
         RLock studentApplyLock = (RLock) concurrentService.getLock(studentApplyLockKey);
@@ -128,13 +134,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 log.warn("获取锁失败,同一个考生不允许同时操作预约!lockKey:{}", studentApplyLockKey);
                 throw new StatusException(Constants.SYSTEM_BUSY);
             }
-
             log.info("获取锁成功!lockKey:{}", studentApplyLockKey);
-            if (concurrentService.isLocked(CacheConstants.LOCK_AUTO_APPLY)) {
-                // 系统自动预约“任务执行期间”不允许预约
-                log.warn("系统自动预约中,不允许考生操作预约!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
-                throw new StatusException(Constants.SYSTEM_BUSY);
-            }
 
             // 考生剩余预约次数 = 允许预约次数 - 已完成预约次数
             int studentApplyNumber = applyTaskCacheService.getStudentApplyNumber(student.getId());
@@ -251,6 +251,12 @@ public class ExamReserveServiceImpl implements ExamReserveService {
             throw new StatusException("当前预约记录已禁止取消预约");
         }
 
+        if (concurrentService.isLocked(CacheConstants.LOCK_AUTO_APPLY)) {
+            // 系统自动预约“任务执行期间”不允许取消预约
+            log.warn("系统自动预约中,不允许考生操作预约!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
+            throw new StatusException(Constants.SYSTEM_BUSY);
+        }
+
         // 考生预约操作锁
         String studentApplyLockKey = String.format(CacheConstants.LOCK_STUDENT_APPLY, student.getId());
         RLock studentApplyLock = (RLock) concurrentService.getLock(studentApplyLockKey);
@@ -259,13 +265,7 @@ public class ExamReserveServiceImpl implements ExamReserveService {
                 log.warn("获取锁失败,同一个考生不允许同时操作预约!lockKey:{}", studentApplyLockKey);
                 throw new StatusException(Constants.SYSTEM_BUSY);
             }
-
             log.info("获取锁成功!lockKey:{}", studentApplyLockKey);
-            if (concurrentService.isLocked(CacheConstants.LOCK_AUTO_APPLY)) {
-                // 系统自动预约“任务执行期间”不允许取消预约
-                log.warn("系统自动预约中,不允许考生操作预约!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
-                throw new StatusException(Constants.SYSTEM_BUSY);
-            }
 
             // StudentApplyEntity existApply = applyTaskCacheService.getStudentApplyRecordFormDB(student.getId(), examSiteId, timePeriodId);
             ApplyRecordCacheBean existApply = applyTaskCacheService.getStudentApplyRecord(student.getId(), examSiteId, timePeriodId);