|
@@ -153,20 +153,10 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
return value;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取当前预约时段剩余可约数量缓存
|
|
|
- */
|
|
|
- public int getApplyAvailableCount(Long examSiteId, Long timePeriodId) {
|
|
|
- int totalCount = this.getApplyTotalCount(examSiteId);
|
|
|
- int finishCount = this.getApplyFinishCount(examSiteId, timePeriodId);
|
|
|
- int availableCount = totalCount - finishCount;
|
|
|
- return Math.max(availableCount, 0);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 获取某考点某时段的“剩余可约数量”缓存
|
|
|
*/
|
|
|
- public int getApplyAvailableCount2(Long examSiteId, Long timePeriodId) {
|
|
|
+ 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();
|
|
@@ -184,12 +174,15 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
/**
|
|
|
* 累减 某考点某时段的“剩余可约数量”缓存
|
|
|
*/
|
|
|
- public void decreaseApplyAvailableCount(Long examSiteId, Long timePeriodId) {
|
|
|
+ public boolean 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();
|
|
|
+ if (atomic.decrementAndGet() >= 0) {
|
|
|
+ return true;
|
|
|
}
|
|
|
+ // 允许最小减到0,否则减操作失败,退回一个数量
|
|
|
+ atomic.incrementAndGet();
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -338,7 +331,25 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
|
public ApplyRecordCacheBean getStudentApplyRecord(Long studentId, Long examSiteId, Long timePeriodId) {
|
|
|
String cacheKey = String.format(CACHE_STUDENT_APPLY_RECORD, studentId);
|
|
|
String hashKey = String.format("%s_%s", examSiteId, timePeriodId);
|
|
|
- return redisClient.getForHash(cacheKey, hashKey, ApplyRecordCacheBean.class);
|
|
|
+ ApplyRecordCacheBean cacheBean = redisClient.getForHash(cacheKey, hashKey, ApplyRecordCacheBean.class);
|
|
|
+ if (cacheBean != null) {
|
|
|
+ return cacheBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 缓存不存在时,从数据库再查一次
|
|
|
+ StudentApplyEntity entity = this.getStudentApplyRecordFormDB(studentId, examSiteId, timePeriodId);
|
|
|
+ if (entity != null) {
|
|
|
+ cacheBean = new ApplyRecordCacheBean();
|
|
|
+ cacheBean.setStudentId(entity.getStudentId());
|
|
|
+ cacheBean.setExamSiteId(entity.getExamSiteId());
|
|
|
+ cacheBean.setTimePeriodId(entity.getTimePeriodId());
|
|
|
+ cacheBean.setCancel(entity.getCancel());
|
|
|
+ cacheBean.setOperateId(entity.getOperateId());
|
|
|
+ cacheBean.setOperateTime(entity.getUpdateTime());
|
|
|
+ return cacheBean;
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|