|
@@ -3,13 +3,12 @@ package com.qmth.exam.reserve.cache.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.qmth.exam.reserve.bean.apply.ApplyRecordCacheBean;
|
|
|
import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
|
|
|
+import com.qmth.exam.reserve.bean.examsite.ExamSiteCapacityInfo;
|
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
|
import com.qmth.exam.reserve.cache.RedisClient;
|
|
|
import com.qmth.exam.reserve.entity.StudentApplyEntity;
|
|
|
-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;
|
|
|
+import com.qmth.exam.reserve.entity.TimePeriodEntity;
|
|
|
+import com.qmth.exam.reserve.service.*;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.redisson.api.RAtomicLong;
|
|
@@ -38,6 +37,9 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
@Autowired
|
|
|
private ExamSiteService examSiteService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TimePeriodService timePeriodService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private StudentService studentService;
|
|
|
|
|
@@ -161,6 +163,80 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
return Math.max(availableCount, 0);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取某考点某时段的“剩余可约数量”缓存
|
|
|
+ */
|
|
|
+ public int getApplyAvailableCount2(Long examSiteId, Long timePeriodId) {
|
|
|
+ String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSiteId, timePeriodId);
|
|
|
+ RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
+ return (int) atomic.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 累加 某考点某时段的“剩余可约数量”缓存
|
|
|
+ */
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 累减 某考点某时段的“剩余可约数量”缓存
|
|
|
+ */
|
|
|
+ public void decreaseApplyAvailableCount(Long examSiteId, Long timePeriodId) {
|
|
|
+ String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSiteId, timePeriodId);
|
|
|
+ RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
+ if (atomic.get() > 0) {
|
|
|
+ atomic.decrementAndGet();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化 某考点某时段的“剩余可约数量”缓存
|
|
|
+ */
|
|
|
+ public void initApplyAvailableCountCache(Long examSiteId, int oldCapacity, int newCapacity) {
|
|
|
+ // 获取所有时段ID集合
|
|
|
+ List<TimePeriodEntity> timePeriods = timePeriodService.list(new LambdaQueryWrapper<TimePeriodEntity>().select(TimePeriodEntity::getId));
|
|
|
+ if (CollectionUtils.isEmpty(timePeriods)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新、旧考点容量差额
|
|
|
+ int diffCapacity = newCapacity - oldCapacity;
|
|
|
+
|
|
|
+ for (TimePeriodEntity timePeriod : timePeriods) {
|
|
|
+ String cacheKey = String.format(CACHE_APPLY_AVAILABLE_COUNT, examSiteId, timePeriod.getId());
|
|
|
+ if (redisClient.exist(cacheKey)) {
|
|
|
+ if (diffCapacity == 0) {
|
|
|
+ // 考点总容量未变化,不用更新缓存
|
|
|
+ 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);
|
|
|
+ } else {
|
|
|
+ // 初始考点剩余容量缓存
|
|
|
+ RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
+ atomic.set(newCapacity);
|
|
|
+ log.debug("SET cacheKey:{} value:{}", cacheKey, newCapacity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化 所有考点所有时段的“剩余可约数量”缓存
|
|
|
+ */
|
|
|
+ public void initApplyAvailableCountCacheForAllExamSites() {
|
|
|
+ List<ExamSiteCapacityInfo> examSites = examSiteService.findAllExamSiteCapacityList();
|
|
|
+ for (ExamSiteCapacityInfo examSite : examSites) {
|
|
|
+ this.initApplyAvailableCountCache(examSite.getExamSiteId(), examSite.getCapacity(), examSite.getCapacity());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 累加 某考点某时段的“已预约数量”缓存
|
|
|
*/
|