|
@@ -179,6 +179,7 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
/**
|
|
/**
|
|
* 刷新 某考点下所有时段的“剩余可约数量”缓存
|
|
* 刷新 某考点下所有时段的“剩余可约数量”缓存
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public void refreshApplyAvailableCountCache(Long examSiteId, int oldCapacity, int newCapacity) {
|
|
public void refreshApplyAvailableCountCache(Long examSiteId, int oldCapacity, int newCapacity) {
|
|
String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examSiteId);
|
|
String lockKey = String.format(CacheConstants.LOCK_EXAM_SITE_CAPACITY, examSiteId);
|
|
Lock lock = concurrentService.getLock(lockKey);
|
|
Lock lock = concurrentService.getLock(lockKey);
|
|
@@ -206,13 +207,27 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
|
|
|
// 总容量变化时,则更新
|
|
// 总容量变化时,则更新
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
- long availableCount = Math.max(atomic.get() + diffCapacity, 0);
|
|
|
|
- atomic.set(availableCount);
|
|
|
|
- log.warn("更新考点时段剩余可约数量:{} {}", availableCount, cacheKey);
|
|
|
|
|
|
+ long curAvailableCount = atomic.get();
|
|
|
|
+ if (diffCapacity > 0 && curAvailableCount == 0) {
|
|
|
|
+ // 容量变大 且 剩余可约数量为0 时,可能存在已约记录,需计算去掉。
|
|
|
|
+ int finishCount = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriod.getId());
|
|
|
|
+ long newAvailableCount = Math.max(diffCapacity - finishCount, 0);
|
|
|
|
+ atomic.set(newAvailableCount);
|
|
|
|
+ log.warn("考点时段剩余可约数量从{}更新为{} oldCapacity:{} newCapacity:{} finishCount:{} {}",
|
|
|
|
+ curAvailableCount, newAvailableCount, oldCapacity, newCapacity, finishCount, cacheKey);
|
|
|
|
+ } else {
|
|
|
|
+ // 容量变小时,不允许超减,最小减到0
|
|
|
|
+ long newAvailableCount = Math.max(curAvailableCount + diffCapacity, 0);
|
|
|
|
+ atomic.set(newAvailableCount);
|
|
|
|
+ log.warn("考点时段剩余可约数量从{}更新为{} oldCapacity:{} newCapacity:{} {}",
|
|
|
|
+ curAvailableCount, newAvailableCount, oldCapacity, newCapacity, cacheKey);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
- atomic.set(newCapacity);
|
|
|
|
- log.warn("初始考点时段剩余可约数量:{} {}", newCapacity, cacheKey);
|
|
|
|
|
|
+ int finishCount = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriod.getId());
|
|
|
|
+ long newAvailableCount = Math.max(newCapacity - finishCount, 0);
|
|
|
|
+ atomic.set(newAvailableCount);
|
|
|
|
+ log.warn("初始考点时段剩余可约数量:{} {}", newAvailableCount, cacheKey);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
@@ -247,13 +262,27 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
|
|
|
// 总容量变化时,则更新
|
|
// 总容量变化时,则更新
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
- long availableCount = Math.max(atomic.get() + diffCapacity, 0);
|
|
|
|
- atomic.set(availableCount);
|
|
|
|
- log.warn("更新考点时段剩余可约数量:{} {}", availableCount, cacheKey);
|
|
|
|
|
|
+ long curAvailableCount = atomic.get();
|
|
|
|
+ if (diffCapacity > 0 && curAvailableCount == 0) {
|
|
|
|
+ // 容量变大 且 剩余可约数量为0 时,可能存在已约记录,需计算去掉。
|
|
|
|
+ int finishCount = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
|
|
|
|
+ long newAvailableCount = Math.max(diffCapacity - finishCount, 0);
|
|
|
|
+ atomic.set(newAvailableCount);
|
|
|
|
+ log.warn("考点时段剩余可约数量从{}更新为{} oldCapacity:{} newCapacity:{} finishCount:{} {}",
|
|
|
|
+ curAvailableCount, newAvailableCount, oldCapacity, newCapacity, finishCount, cacheKey);
|
|
|
|
+ } else {
|
|
|
|
+ // 容量变小时,不允许超减,最小减到0
|
|
|
|
+ long newAvailableCount = Math.max(curAvailableCount + diffCapacity, 0);
|
|
|
|
+ atomic.set(newAvailableCount);
|
|
|
|
+ log.warn("考点时段剩余可约数量从{}更新为{} oldCapacity:{} newCapacity:{} {}",
|
|
|
|
+ curAvailableCount, newAvailableCount, oldCapacity, newCapacity, cacheKey);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
- atomic.set(newCapacity);
|
|
|
|
- log.warn("初始考点时段剩余可约数量:{} {}", newCapacity, cacheKey);
|
|
|
|
|
|
+ int finishCount = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
|
|
|
|
+ long newAvailableCount = Math.max(newCapacity - finishCount, 0);
|
|
|
|
+ atomic.set(newAvailableCount);
|
|
|
|
+ log.warn("初始考点时段剩余可约数量:{} {}", newAvailableCount, cacheKey);
|
|
}
|
|
}
|
|
} finally {
|
|
} finally {
|
|
try {
|
|
try {
|