|
@@ -2,6 +2,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.bean.admin.ExamListBean;
|
|
|
import com.qmth.themis.business.cache.bean.ExamCacheBean;
|
|
|
import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
@@ -27,6 +28,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CopyOnWriteArraySet;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -648,106 +650,129 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
|
|
|
* 设置考试列表缓存
|
|
|
*/
|
|
|
@Override
|
|
|
- public void setExamListCache() {
|
|
|
+ public void setOrgExamListCache() {
|
|
|
//查询考试场次结束时间大于当前时间的所有考试
|
|
|
List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().gt(TEExamActivity::getFinishTime, System.currentTimeMillis()).eq(TEExamActivity::getEnable, 1));
|
|
|
if (!CollectionUtils.isEmpty(teExamActivityList)) {
|
|
|
- LinkedMultiValueMap<Long, Long> examActivityMap = new LinkedMultiValueMap<>();
|
|
|
+ LinkedMultiValueMap<Long, ExamListBean> examActivityMap = new LinkedMultiValueMap<>();
|
|
|
+ Map<Long, Set<Long>> examMap = new HashMap<>();
|
|
|
+ Map<Long, Set<Long>> orgMap = new HashMap<>();
|
|
|
for (TEExamActivity t : teExamActivityList) {
|
|
|
ExamCacheBean examCacheBean = teExamService.getExamCacheBean(t.getExamId());
|
|
|
if (Objects.nonNull(examCacheBean.getEnable()) && examCacheBean.getEnable().intValue() == 1) {
|
|
|
- examActivityMap.add(t.getExamId(), t.getId());
|
|
|
+ if (orgMap.containsKey(examCacheBean.getOrgId())) {
|
|
|
+ Set<Long> examIdSet = orgMap.get(examCacheBean.getOrgId());
|
|
|
+ examIdSet.add(t.getExamId());
|
|
|
+ orgMap.put(examCacheBean.getOrgId(), examIdSet);
|
|
|
+ } else {
|
|
|
+ orgMap.put(examCacheBean.getOrgId(), new HashSet<>(Arrays.asList(t.getExamId())));
|
|
|
+ }
|
|
|
+ if (examMap.containsKey(t.getExamId())) {
|
|
|
+ Set<Long> examActivityIdSet = examMap.get(examCacheBean.getId());
|
|
|
+ examActivityIdSet.add(t.getId());
|
|
|
+ examMap.put(t.getExamId(), examActivityIdSet);
|
|
|
+ } else {
|
|
|
+ examMap.put(t.getExamId(), new HashSet<>(Arrays.asList(t.getId())));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- examActivityMap.forEach((k, v) -> {
|
|
|
+ orgMap.forEach((k, v) -> {
|
|
|
for (Long l : v) {
|
|
|
- redisUtil.set(SystemConstant.EXAM_LIST_MAP_CACHE + k, l.toString(), l);
|
|
|
- redisUtil.addSet(SystemConstant.EXAM_LIST_ID_CACHE, k);
|
|
|
+ examActivityMap.add(k, new ExamListBean(l, examMap.get(l)));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ examActivityMap.forEach((k, v) -> {
|
|
|
+ for (ExamListBean e : v) {
|
|
|
+ redisUtil.set(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + k, e.getExamId().toString(), e.getExamActivityIdSet());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取考试列表缓存
|
|
|
- *
|
|
|
- * @param examId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public Map<String, List<Long>> getExamListCache(String examId) {
|
|
|
- return redisUtil.getHashEntries(SystemConstant.EXAM_LIST_MAP_CACHE + examId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取考试列表id缓存
|
|
|
+ * 获取机构考试列表缓存
|
|
|
*
|
|
|
+ * @param orgId
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public Set<Long> getExamIdListCache() {
|
|
|
- return redisUtil.getSet(SystemConstant.EXAM_LIST_ID_CACHE);
|
|
|
+ public Map<String, Set<Long>> getOrgExamListCache(String orgId) {
|
|
|
+ return redisUtil.getHashEntries(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新考试列表id缓存
|
|
|
+ * 获取机构考试列表缓存
|
|
|
*
|
|
|
+ * @param orgId
|
|
|
* @param examId
|
|
|
+ * @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public void updateExamListIdCache(Long examId) {
|
|
|
- redisUtil.addSet(SystemConstant.EXAM_LIST_ID_CACHE, examId);
|
|
|
+ public Set<Long> getOrgExamListCache(String orgId, String examId) {
|
|
|
+ Map<String, Set<Long>> map = redisUtil.getHashEntries(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId);
|
|
|
+ if (!CollectionUtils.isEmpty(map)) {
|
|
|
+ return map.get(examId);
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除考试列表id缓存
|
|
|
- *
|
|
|
+ * @param orgId
|
|
|
* @param examId
|
|
|
+ * @param examActivityId
|
|
|
*/
|
|
|
@Override
|
|
|
- public void removeExamListIdCache(Long examId) {
|
|
|
- redisUtil.removeSet(SystemConstant.EXAM_LIST_ID_CACHE, examId);
|
|
|
+ public void updateOrgExamListCache(String orgId, String examId, Long examActivityId) {
|
|
|
+ Map<String, Set<Long>> map = redisUtil.getHashEntries(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId);
|
|
|
+ if (CollectionUtils.isEmpty(map)) {
|
|
|
+ redisUtil.set(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId, examId, new HashSet<>(Arrays.asList(examActivityId)));
|
|
|
+ } else {
|
|
|
+ Set<Long> examActivityIdSet = map.get(examId);
|
|
|
+ examActivityIdSet.add(examActivityId);
|
|
|
+ redisUtil.set(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId, examId, examActivityIdSet);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新考试列表缓存
|
|
|
+ * 删除机构考试列表缓存
|
|
|
*
|
|
|
- * @param examId
|
|
|
- * @param examActivityId
|
|
|
+ * @param orgId
|
|
|
*/
|
|
|
@Override
|
|
|
- public void updateExamListCache(String examId, String examActivityId) {
|
|
|
- this.removeExamListCache(examId, examActivityId);
|
|
|
- redisUtil.set(SystemConstant.EXAM_LIST_MAP_CACHE + examId, examActivityId, examActivityId);
|
|
|
+ public void removeOrgExamListCache(String orgId) {
|
|
|
+ redisUtil.delete(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除考试列表缓存
|
|
|
+ * 删除机构考试列表缓存
|
|
|
*
|
|
|
+ * @param orgId
|
|
|
* @param examId
|
|
|
*/
|
|
|
@Override
|
|
|
- public void removeExamListCache(String examId) {
|
|
|
- redisUtil.delete(SystemConstant.EXAM_LIST_MAP_CACHE + examId);
|
|
|
+ public void removeOrgExamListCache(String orgId, String examId) {
|
|
|
+ redisUtil.delete(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId, examId);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除考试列表缓存
|
|
|
- *
|
|
|
- * @param examId
|
|
|
- * @param examActivityId
|
|
|
- */
|
|
|
@Override
|
|
|
- public void removeExamListCache(String examId, String examActivityId) {
|
|
|
- redisUtil.delete(SystemConstant.EXAM_LIST_MAP_CACHE + examId, examActivityId);
|
|
|
+ public void removeOrgExamListCache(String orgId, String examId, Long examActivityId) {
|
|
|
+ Map<String, Set<Long>> map = redisUtil.getHashEntries(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId);
|
|
|
+ CopyOnWriteArraySet<Long> examActivityIdSet = (CopyOnWriteArraySet<Long>) map.get(examId);
|
|
|
+ for (Long l : examActivityIdSet) {
|
|
|
+ if (l.longValue() == examActivityId.longValue()) {
|
|
|
+ examActivityIdSet.remove(l);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(examActivityIdSet)) {
|
|
|
+ this.removeOrgExamListCache(orgId, examId);
|
|
|
+ this.removeOrgExamListCache(orgId);
|
|
|
+ } else {
|
|
|
+ redisUtil.set(SystemConstant.ORG_EXAM_LIST_MAP_CACHE + orgId, examId, new HashSet<>(examActivityIdSet));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 获取当天考试缓存
|
|
|
- *
|
|
|
- * @param examId
|
|
|
- * @return
|
|
|
- */
|
|
|
@Override
|
|
|
public Map<String, Set<String>> getTodayExamCache(String examId) {
|
|
|
return redisUtil.getHashEntries(SystemConstant.TODAY_EXAM_MAP_CACHE + examId);
|
|
@@ -837,7 +862,14 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
|
|
|
if (Objects.nonNull(roomCode)) {
|
|
|
teExamSummaryQueryWrapper.lambda().eq(TEExamSummary::getRoomCode, roomCode);
|
|
|
}
|
|
|
- return teExamSummaryService.list(teExamSummaryQueryWrapper);
|
|
|
+ List<TEExamSummary> teExamSummaryList = teExamSummaryService.list(teExamSummaryQueryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(teExamSummaryList)) {
|
|
|
+ if (Objects.nonNull(examActivityId) && Objects.nonNull(roomCode)) {
|
|
|
+ teExamSummaryService.examSummary(examId, examActivityId, new HashSet<>(Arrays.asList(roomCode)));
|
|
|
+ }
|
|
|
+ teExamSummaryList = teExamSummaryService.list(teExamSummaryQueryWrapper);
|
|
|
+ }
|
|
|
+ return teExamSummaryList;
|
|
|
}
|
|
|
|
|
|
/**
|