|
@@ -2,11 +2,15 @@ package com.qmth.exam.reserve.cache.impl;
|
|
|
|
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
|
import com.qmth.exam.reserve.cache.RedisClient;
|
|
|
+import com.qmth.exam.reserve.service.ExamSiteService;
|
|
|
+import com.qmth.exam.reserve.service.StudentApplyService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
@Component
|
|
|
public class ApplyTaskCacheService implements CacheConstants {
|
|
|
|
|
@@ -15,6 +19,12 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
@Autowired
|
|
|
private RedisClient redisClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamSiteService examSiteService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentApplyService studentApplyService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取某考点某时段的“可预约总量”
|
|
|
*/
|
|
@@ -24,22 +34,35 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
if (value != null) {
|
|
|
return value;
|
|
|
}
|
|
|
- // todo
|
|
|
- return 1;
|
|
|
+
|
|
|
+ // 当前考点当前时段容量 = 当前考点总容量
|
|
|
+ value = examSiteService.countExamSiteCapacityById(examSiteId);
|
|
|
+ redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ return value;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取某考点某时段的“已预约数量”
|
|
|
*/
|
|
|
public int getApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
|
- return 0;
|
|
|
+ String cacheKey = String.format(CACHE_APPLY_FINISH, examSiteId, timePeriodId);
|
|
|
+ Integer value = redisClient.get(cacheKey, Integer.class);
|
|
|
+ if (value != null) {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ value = studentApplyService.countApplyFinishForExamSiteAndTimePeriod(examSiteId, timePeriodId);
|
|
|
+ redisClient.set(cacheKey, value, 1, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ return value;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 累加 某考点某时段的“已预约数量”
|
|
|
*/
|
|
|
public void increaseApplyFinishCount(Long examSiteId, Long timePeriodId) {
|
|
|
-
|
|
|
+ // redisClient.getRedissonClient().getAtomicLong(cacheKey);
|
|
|
}
|
|
|
|
|
|
/**
|