|
@@ -1,18 +1,24 @@
|
|
package com.qmth.exam.reserve.cache.impl;
|
|
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.applytask.CurrentApplyTaskVO;
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
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.entity.StudentApplyEntity;
|
|
import com.qmth.exam.reserve.service.ApplyTaskService;
|
|
import com.qmth.exam.reserve.service.ApplyTaskService;
|
|
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 com.qmth.exam.reserve.service.StudentService;
|
|
import com.qmth.exam.reserve.service.StudentService;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.redisson.api.RAtomicLong;
|
|
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;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -145,4 +151,48 @@ public class ApplyTaskCacheService implements CacheConstants {
|
|
atomic.decrementAndGet();
|
|
atomic.decrementAndGet();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取某考生的 所有的“预约记录”缓存
|
|
|
|
+ */
|
|
|
|
+ public Map<String, ApplyRecordCacheBean> getStudentApplyRecords(Long studentId) {
|
|
|
|
+ String cacheKey = String.format(CACHE_STUDENT_APPLY_RECORD, studentId);
|
|
|
|
+ if (!redisClient.exist(cacheKey)) {
|
|
|
|
+ LambdaQueryWrapper<StudentApplyEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(StudentApplyEntity::getStudentId, studentId);
|
|
|
|
+ List<StudentApplyEntity> list = studentApplyService.list(wrapper);
|
|
|
|
+
|
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
+ for (StudentApplyEntity entity : list) {
|
|
|
|
+ ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
|
|
|
|
+ bean.setTimePeriodId(entity.getTimePeriodId());
|
|
|
|
+ bean.setExamSiteId(entity.getExamSiteId());
|
|
|
|
+ bean.setCancel(entity.getCancel());
|
|
|
|
+ this.saveStudentApplyRecord(studentId, bean);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ redisClient.expire(cacheKey, 30, TimeUnit.DAYS);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return redisClient.getEntriesForHash(cacheKey, ApplyRecordCacheBean.class);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取某考生的 某考点某时段的“预约记录”缓存
|
|
|
|
+ */
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存某考生的 某考点某时段的“预约记录”缓存
|
|
|
|
+ */
|
|
|
|
+ public void saveStudentApplyRecord(Long studentId, ApplyRecordCacheBean value) {
|
|
|
|
+ String cacheKey = String.format(CACHE_STUDENT_APPLY_RECORD, studentId);
|
|
|
|
+ String hashKey = String.format("%s_%s", value.getExamSiteId(), value.getTimePeriodId());
|
|
|
|
+ redisClient.setForHash(cacheKey, hashKey, value);
|
|
|
|
+ log.info("SET cacheKey:{} hashKey:{}", cacheKey, hashKey);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|