deason 8 hónapja
szülő
commit
fa6f0ddda4

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

@@ -112,7 +112,7 @@ public class ApplyTaskCacheService implements CacheConstants {
     public int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
         String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSiteId, timePeriodId);
         RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
-        return (int) atomic.get();
+        return (int) atomic.get();//若缓存不存在时,会返回0
     }
 
     /**
@@ -122,7 +122,7 @@ public class ApplyTaskCacheService implements CacheConstants {
         String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSiteId, timePeriodId);
         RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
         long value = atomic.incrementAndGet();
-        log.warn("累加成功,最新考点剩余可约数量:{} cacheKey:{}", value, cacheKey);
+        log.warn("累加成功,最新考点时段剩余可约数量:{} cacheKey:{}", value, cacheKey);
     }
 
     /**
@@ -151,13 +151,13 @@ public class ApplyTaskCacheService implements CacheConstants {
         Objects.requireNonNull(result, "缓存操作异常,返回结果为空!");
 
         if (-2 == result) {
-            log.warn("扣减失败,考点剩余可约数量缓存不存在!cacheKey:{}", cacheKey);
+            log.warn("扣减失败,考点时段剩余可约数量缓存不存在!cacheKey:{}", cacheKey);
             return false;
         } else if (-1 == result) {
-            log.warn("扣减失败,考点剩余可约数量为0不足!cacheKey:{}", cacheKey);
+            log.warn("扣减失败,考点时段剩余可约数量为0不足!cacheKey:{}", cacheKey);
             return false;
         }
-        log.info("扣减成功,最新考点剩余可约数量:{} cacheKey:{}", result, cacheKey);
+        log.info("扣减成功,最新考点时段剩余可约数量:{} cacheKey:{}", result, cacheKey);
         return true;
     }
 
@@ -189,16 +189,15 @@ public class ApplyTaskCacheService implements CacheConstants {
                         continue;
                     }
 
-                    // 总容量变化时,则更新考点剩余可约数量缓存
+                    // 总容量变化时,则更新
                     RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
                     long availableCount = Math.max(atomic.get() + diffCapacity, 0);
                     atomic.set(availableCount);
-                    log.warn("SET cacheKey:{} value:{}", cacheKey, availableCount);
+                    log.warn("更新考点时段剩余可约数量:{} cacheKey:{}", availableCount, cacheKey);
                 } else {
-                    // 初始考点剩余可约数量缓存
                     RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
                     atomic.set(newCapacity);
-                    log.info("SET cacheKey:{} value:{}", cacheKey, newCapacity);
+                    log.warn("初始考点时段剩余可约数量:{} cacheKey:{}", newCapacity, cacheKey);
                 }
             }
         } finally {
@@ -238,18 +237,19 @@ public class ApplyTaskCacheService implements CacheConstants {
 
                 for (TimePeriodEntity timePeriod : timePeriods) {
                     String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSite.getExamSiteId(), timePeriod.getId());
-                    if (redisClient.exist(cacheKey) && skipExisted) {
+                    boolean existCache = redisClient.exist(cacheKey);
+                    if (existCache && skipExisted) {
                         // 跳过存在的缓存
                         continue;
                     }
 
-                    // 获取某考点某时段的“已预约数量”(仅查数据库会有误差,需等预约队列中全部完成数据库持久化后再执行!)
+                    // 获取某考点某时段的“已预约数量”(仅查数据库会有误差,需等预约队列中全部完成数据库持久化后再执行!!!
                     int finishCount = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSite.getExamSiteId(), timePeriod.getId());
                     // 剩余可约数量
                     int availableCount = Math.max(examSite.getCapacity() - finishCount, 0);
                     RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
                     atomic.set(availableCount);
-                    log.warn("SET cacheKey:{} value:{}", cacheKey, availableCount);
+                    log.warn("{}考点时段剩余可约数量:{} cacheKey:{}", existCache ? "更新" : "初始", availableCount, cacheKey);
                 }
             } finally {
                 try {