|
@@ -4,6 +4,7 @@ import com.qmth.exam.reserve.cache.CacheConstants;
|
|
import com.qmth.exam.reserve.cache.RedisClient;
|
|
import com.qmth.exam.reserve.cache.RedisClient;
|
|
import com.qmth.exam.reserve.service.ExamSiteService;
|
|
import com.qmth.exam.reserve.service.ExamSiteService;
|
|
import com.qmth.exam.reserve.service.StudentApplyService;
|
|
import com.qmth.exam.reserve.service.StudentApplyService;
|
|
|
|
+import org.redisson.api.RAtomicLong;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -38,6 +39,7 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
// 当前考点当前时段容量 = 当前考点总容量
|
|
// 当前考点当前时段容量 = 当前考点总容量
|
|
value = examSiteService.countExamSiteCapacityById(examSiteId);
|
|
value = examSiteService.countExamSiteCapacityById(examSiteId);
|
|
redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
|
|
redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
|
|
|
|
+ log.info("{} = {}", cacheKey, value);
|
|
|
|
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
@@ -47,13 +49,16 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
*/
|
|
*/
|
|
public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
|
|
String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
|
|
- Integer value = redisClient.get(cacheKey, Integer.class);
|
|
|
|
- if (value != null) {
|
|
|
|
- return value;
|
|
|
|
|
|
+ if (redisClient.exist(cacheKey)) {
|
|
|
|
+ return (int) redisClient.getRedissonClient().getAtomicLong(cacheKey).get();
|
|
}
|
|
}
|
|
|
|
|
|
- value = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
|
|
|
|
- redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
|
|
|
|
|
|
+ RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
|
+
|
|
|
|
+ int value = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
|
|
|
|
+ atomic.set(value);
|
|
|
|
+ atomic.expire(30, TimeUnit.DAYS);
|
|
|
|
+ log.info("{} = {}", cacheKey, value);
|
|
|
|
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
@@ -62,14 +67,18 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
* 累加 某考点某时段的“已预约数量”
|
|
* 累加 某考点某时段的“已预约数量”
|
|
*/
|
|
*/
|
|
public void increaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
public void increaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
- // redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
|
|
|
+ String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
|
|
|
|
+ RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
|
+ atomic.incrementAndGet();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 累减 某考点某时段的“已预约数量”
|
|
* 累减 某考点某时段的“已预约数量”
|
|
*/
|
|
*/
|
|
public void decreaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
public void decreaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
-
|
|
|
|
|
|
+ String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
|
|
|
|
+ RAtomicLong atomic = redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
|
+ atomic.decrementAndGet();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|