|
@@ -1,6 +1,7 @@
|
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.qmth.themis.business.bean.admin.ExamActivityTodayBean;
|
|
|
import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.dto.AuthDto;
|
|
@@ -8,6 +9,7 @@ import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
|
|
|
import com.qmth.themis.business.entity.*;
|
|
|
import com.qmth.themis.business.enums.RoleEnum;
|
|
|
import com.qmth.themis.business.service.*;
|
|
|
+import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.themis.common.exception.BusinessException;
|
|
|
import com.qmth.themis.common.util.GsonUtil;
|
|
@@ -18,8 +20,11 @@ import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.CachePut;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -73,6 +78,15 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
|
|
|
@Resource
|
|
|
TBProblemService tbProblemService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamActivityService teExamActivityService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamStudentService teExamStudentService;
|
|
|
+
|
|
|
/**
|
|
|
* 添加机构缓存
|
|
|
*
|
|
@@ -576,4 +590,116 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
|
|
|
public void removeProblemCache() {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置当天考试缓存
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void setTodayExamCache() {
|
|
|
+ try {
|
|
|
+ Date now = new Date();
|
|
|
+ SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String today = sdf1.format(now);
|
|
|
+ SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ Long startTime = sdf2.parse(today + " 00:00:00").getTime();
|
|
|
+ Long endTime = sdf2.parse(today + " 23:59:59").getTime();
|
|
|
+ List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().ge(TEExamActivity::getStartTime, startTime).le(TEExamActivity::getStartTime, endTime));
|
|
|
+ if (!CollectionUtils.isEmpty(teExamActivityList)) {
|
|
|
+ LinkedMultiValueMap<Long, ExamActivityTodayBean> examActivityMap = new LinkedMultiValueMap<>();
|
|
|
+ for (TEExamActivity t : teExamActivityList) {
|
|
|
+ List<TEExamStudent> teExamStudentList = teExamStudentService.list(new QueryWrapper<TEExamStudent>().lambda().eq(TEExamStudent::getExamId, t.getExamId()).eq(TEExamStudent::getExamActivityId, t.getId()));
|
|
|
+ if (!CollectionUtils.isEmpty(teExamStudentList)) {
|
|
|
+ Set<String> roomCodeSet = teExamStudentList.stream().map(s -> s.getRoomCode()).collect(Collectors.toSet());
|
|
|
+ examActivityMap.add(t.getExamId(), new ExamActivityTodayBean(t.getId(), roomCodeSet));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ examActivityMap.forEach((k, v) -> {
|
|
|
+ for (ExamActivityTodayBean e : v) {
|
|
|
+ redisUtil.set(SystemConstant.TODAY_EXAM_MAP_CACHE + k, e.getExamActivityId().toString(), e.getRoomCodeList());
|
|
|
+ redisUtil.addSet(SystemConstant.TODAY_EXAM_ID_LIST_CACHE, k);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当天考试缓存
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Set<String>> getTodayExamCache(String examId) {
|
|
|
+ return redisUtil.getHashEntries(SystemConstant.TODAY_EXAM_MAP_CACHE + examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新当天考试缓存
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateTodayExamCache(String examId, String examActivityId) {
|
|
|
+ List<TEExamStudent> teExamStudentList = teExamStudentService.list(new QueryWrapper<TEExamStudent>().lambda().eq(TEExamStudent::getExamId, Long.parseLong(examId)).eq(TEExamStudent::getExamActivityId, Long.parseLong(examActivityId)));
|
|
|
+ if (!CollectionUtils.isEmpty(teExamStudentList)) {
|
|
|
+ Set<String> roomCodeSet = teExamStudentList.stream().map(s -> s.getRoomCode()).collect(Collectors.toSet());
|
|
|
+ this.removeTodayExamCache(examId, examActivityId);
|
|
|
+ redisUtil.set(SystemConstant.TODAY_EXAM_MAP_CACHE + examId, examActivityId, roomCodeSet);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除当天考试缓存
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void removeTodayExamCache(String examId) {
|
|
|
+ redisUtil.delete(SystemConstant.TODAY_EXAM_MAP_CACHE + examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除当天考试缓存
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ * @param examActivityId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void removeTodayExamCache(String examId, String examActivityId) {
|
|
|
+ redisUtil.delete(SystemConstant.TODAY_EXAM_MAP_CACHE + examId, examActivityId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当天考试列表缓存
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Set<Long> getTodayExamListCache() {
|
|
|
+ return redisUtil.getSet(SystemConstant.TODAY_EXAM_ID_LIST_CACHE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新当天考试列表缓存
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void updateTodayExamListCache(Long examId) {
|
|
|
+ redisUtil.addSet(SystemConstant.TODAY_EXAM_ID_LIST_CACHE, examId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除当天考试列表缓存
|
|
|
+ *
|
|
|
+ * @param examId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void removeTodayExamListCache(Long examId) {
|
|
|
+ redisUtil.removeSet(SystemConstant.TODAY_EXAM_ID_LIST_CACHE, examId);
|
|
|
+ }
|
|
|
}
|