浏览代码

待考列表优化

wangliang 1 年之前
父节点
当前提交
59c713e3e5

+ 5 - 1
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamController.java

@@ -485,10 +485,14 @@ public class TEExamController {
         }
 
         List<TEExamSummary> teExamSummaryAllList = new ArrayList<>();
-        if (Objects.nonNull(examActivityId)) {
+        if (Objects.nonNull(examId) && Objects.nonNull(examActivityId) && !CollectionUtils.isEmpty(roomCodeSet)) {
             for (String s : roomCodeSet) {
                 teExamSummaryAllList.addAll(themisCacheService.addExamSummaryCache(examId, examActivityId, s));
             }
+        } else if (Objects.nonNull(examId) && Objects.nonNull(examActivityId)) {
+            teExamSummaryAllList.addAll(themisCacheService.addExamSummaryCache(examId, examActivityId));
+        } else {
+            teExamSummaryAllList.addAll(themisCacheService.addExamSummaryCache(examId));
         }
         ExamPropCountDto examPropCountDto = new ExamPropCountDto(examId, 0, 0, 0, 0, 0, new BigDecimal(0));
         if (!CollectionUtils.isEmpty(teExamSummaryAllList)) {

+ 8 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEOrgSummaryService.java

@@ -30,6 +30,14 @@ public interface TEOrgSummaryService extends IService<TEOrgSummary> {
      */
     public void saveOrgSummaryCommon(TEOrgSummary teOrgSummary);
 
+    /**
+     * 更新机构统计信息
+     *
+     * @param orgId
+     * @param teOrgSummary
+     */
+    public void updateOrgSummaryCommon(Long orgId, TEOrgSummary teOrgSummary);
+
     /**
      * 更新全局机构考试完成数量和考生完成数量
      *

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/service/ThemisCacheService.java

@@ -539,4 +539,13 @@ public interface ThemisCacheService {
      * 删除地区统计缓存
      */
     public void removeOrgSummaryCache();
+
+    /**
+     * 删除全部考试统计缓存
+     *
+     * @param examId
+     * @param examActivityId
+     * @param roomCode
+     */
+    public void removeExamSummaryAllCache(Long examId, Long examActivityId, String roomCode);
 }

+ 2 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamSummaryServiceImpl.java

@@ -156,6 +156,8 @@ public class TEExamSummaryServiceImpl extends ServiceImpl<TEExamSummaryMapper, T
                     this.baseMapper.updateExamSummary(examId, examActivityId, s, stringJoinerFieldValue.toString());
                 }
             }
+            themisCacheService.updateExamSummaryCache(examId);
+            themisCacheService.updateExamSummaryCache(examId, examActivityId);
             themisCacheService.updateExamSummaryCache(examId, examActivityId, s);
         }
     }

+ 80 - 40
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOrgSummaryServiceImpl.java

@@ -17,7 +17,6 @@ import org.springframework.util.LinkedMultiValueMap;
 
 import javax.annotation.Resource;
 import java.util.List;
-import java.util.Objects;
 import java.util.StringJoiner;
 
 /**
@@ -49,51 +48,61 @@ public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEO
     @Override
     @Transactional
     public void orgSummary(Long orgId, List<Long> examIdSet) {
-        TEOrgSummary teOrgSummary = themisCacheService.addOrgSummaryCache(orgId);
-        if (Objects.isNull(teOrgSummary)) {//说明没有缓存
-            if (orgId.longValue() == 0) {//全局机构
-                Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);
-                Integer examCount = this.baseMapper.orgSummaryByExamCount(examIdSet);
-                List<Integer> finishCountList = this.baseMapper.orgSummaryByFinishCountAndFinishStudentCount(examIdSet);
-                teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCountList.get(0), finishCountList.get(1));
+        int count = this.baseMapper.selectOrgSummaryCount(orgId);
+        if (orgId.longValue() == 0) {//全局机构
+            Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);
+            Integer examCount = this.baseMapper.orgSummaryByExamCount(examIdSet);
+            List<Integer> finishCountList = this.baseMapper.orgSummaryByFinishCountAndFinishStudentCount(examIdSet);
+            TEOrgSummary teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCountList.get(0), finishCountList.get(1));
+            if (count == 0) {
                 teOrgSummaryService.saveOrgSummaryCommon(teOrgSummary);
             } else {
-                LinkedMultiValueMap<Long, Long> orgExamIdMap = new LinkedMultiValueMap<>();
-                boolean reloadDb = false;
-                //先查询考试批次统计缓存
-                for (Long l : examIdSet) {
-                    List<TEExamSummary> teExamSummaryList = themisCacheService.addExamSummaryCache(l);
-                    if (!CollectionUtils.isEmpty(teExamSummaryList)) {//如果没有该批次的考试统计缓存信息,则自己从数据库取
-                        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(l);
-                        TBOrg tbOrg = themisCacheService.addOrgCache(examCacheBean.getOrgId());
-                        orgExamIdMap.add(tbOrg.getId(), l);
-                    } else {
-                        reloadDb = true;
-                        break;
-                    }
+                teOrgSummaryService.updateOrgSummaryCommon(orgId, teOrgSummary);
+            }
+        } else {
+            LinkedMultiValueMap<Long, Long> orgExamIdMap = new LinkedMultiValueMap<>();
+            boolean reloadDb = false;
+            //先查询考试批次统计缓存
+            for (Long l : examIdSet) {
+                List<TEExamSummary> teExamSummaryList = themisCacheService.addExamSummaryCache(l);
+                if (!CollectionUtils.isEmpty(teExamSummaryList)) {//如果没有该批次的考试统计缓存信息,则自己从数据库取
+                    ExamCacheBean examCacheBean = teExamService.getExamCacheBean(l);
+                    TBOrg tbOrg = themisCacheService.addOrgCache(examCacheBean.getOrgId());
+                    orgExamIdMap.add(tbOrg.getId(), l);
+                } else {
+                    reloadDb = true;
+                    break;
                 }
-                if (reloadDb) {//没有该批次的考试统计缓存信息,则从数据库取数据
-                    Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);
-                    Integer examCount = this.baseMapper.orgSummaryByExamCount(examIdSet);
-                    List<Integer> finishCountList = this.baseMapper.orgSummaryByFinishCountAndFinishStudentCount(examIdSet);
-                    teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCountList.get(0), finishCountList.get(1));
+            }
+            if (reloadDb) {//没有该批次的考试统计缓存信息,则从数据库取数据
+                Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);
+                Integer examCount = this.baseMapper.orgSummaryByExamCount(examIdSet);
+                List<Integer> finishCountList = this.baseMapper.orgSummaryByFinishCountAndFinishStudentCount(examIdSet);
+                TEOrgSummary teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCountList.get(0), finishCountList.get(1));
+                if (count == 0) {
                     teOrgSummaryService.saveOrgSummaryCommon(teOrgSummary);
                 } else {
-                    orgExamIdMap.forEach((k, v) -> {//从考试批次缓存信息里拿取在线人数、考试人数、完成考生数
-                        Integer onlineCount = 0, examCount = 0, finishStudentCount = 0;
-                        for (Long l : v) {
-                            List<TEExamSummary> teExamSummaryList = themisCacheService.addExamSummaryCache(l);
-                            for (TEExamSummary t : teExamSummaryList) {
-                                onlineCount = onlineCount + t.getOnlineCount();
-                                examCount = examCount + t.getExamCount();
-                                finishStudentCount = finishStudentCount + t.getFinishCount();
-                            }
-                        }
-                        Integer finishCount = this.baseMapper.orgSummaryByFinishCount(v);
-                        TEOrgSummary teOrgSummaryNotZero = new TEOrgSummary(orgId, onlineCount, examCount, finishCount, finishStudentCount);
-                        teOrgSummaryService.saveOrgSummaryCommon(teOrgSummaryNotZero);
-                    });
+                    teOrgSummaryService.updateOrgSummaryCommon(orgId, teOrgSummary);
                 }
+            } else {
+                orgExamIdMap.forEach((k, v) -> {//从考试批次缓存信息里拿取在线人数、考试人数、完成考生数
+                    Integer onlineCount = 0, examCount = 0, finishStudentCount = 0;
+                    for (Long l : v) {
+                        List<TEExamSummary> teExamSummaryList = themisCacheService.addExamSummaryCache(l);
+                        for (TEExamSummary t : teExamSummaryList) {
+                            onlineCount = onlineCount + t.getOnlineCount();
+                            examCount = examCount + t.getExamCount();
+                            finishStudentCount = finishStudentCount + t.getFinishCount();
+                        }
+                    }
+                    Integer finishCount = this.baseMapper.orgSummaryByFinishCount(v);
+                    TEOrgSummary teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCount, finishStudentCount);
+                    if (count == 0) {
+                        teOrgSummaryService.saveOrgSummaryCommon(teOrgSummary);
+                    } else {
+                        teOrgSummaryService.updateOrgSummaryCommon(orgId, teOrgSummary);
+                    }
+                });
             }
         }
     }
@@ -120,6 +129,37 @@ public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEO
         this.baseMapper.saveOrgSummary(stringJoinerFieldName.toString(), stringJoinerFieldValue.toString());
     }
 
+    /**
+     * 更新机构统计信息
+     *
+     * @param teOrgSummary
+     */
+    @Override
+    @Transactional
+    public void updateOrgSummaryCommon(Long orgId, TEOrgSummary teOrgSummary) {
+        StringJoiner stringJoinerFieldValue = new StringJoiner(",");
+        OrgSummaryEnum[] orgSummaryEnums = OrgSummaryEnum.values();
+        for (int i = 0; i < orgSummaryEnums.length; i++) {
+            switch (orgSummaryEnums[i]) {
+                case onlineCount:
+                    stringJoinerFieldValue.add(orgSummaryEnums[i].getCode() + "=" + teOrgSummary.getOnlineCount());
+                    break;
+                case examCount:
+                    stringJoinerFieldValue.add(orgSummaryEnums[i].getCode() + "=" + teOrgSummary.getExamCount());
+                    break;
+                case finishCount:
+                    stringJoinerFieldValue.add(orgSummaryEnums[i].getCode() + "=" + teOrgSummary.getFinishCount());
+                    break;
+                case finishStudentCount:
+                    stringJoinerFieldValue.add(orgSummaryEnums[i].getCode() + "=" + teOrgSummary.getFinishStudentCount());
+                    break;
+                default:
+                    break;
+            }
+        }
+        this.baseMapper.updateOrgSummary(orgId, stringJoinerFieldValue.toString());
+    }
+
     /**
      * 更新全局机构考试完成数量和考生完成数量
      *

+ 4 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -1747,6 +1747,10 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
     @Override
     public List<Long> dataCount() {
         TEOrgSummary teOrgSummary = themisCacheService.addOrgSummaryCache(0L);
+        if (Objects.isNull(teOrgSummary)) {
+            teOrgSummaryService.orgSummary(0L, null);
+            teOrgSummary = themisCacheService.addOrgSummaryCache(0L);
+        }
         List<Long> list = new ArrayList<>();
         list.add(Objects.nonNull(teOrgSummary) && Objects.nonNull(teOrgSummary.getOnlineCount()) ? Long.parseLong(teOrgSummary.getOnlineCount().toString()) : 0L);
         list.add(Objects.nonNull(teOrgSummary) && Objects.nonNull(teOrgSummary.getExamCount()) ? Long.parseLong(teOrgSummary.getExamCount().toString()) : 0L);

+ 17 - 3
themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java

@@ -761,7 +761,7 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
      */
     @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)));
+        List<TEExamStudent> teExamStudentList = teExamStudentService.list(new QueryWrapper<TEExamStudent>().lambda().eq(TEExamStudent::getExamId, Long.parseLong(examId)).eq(TEExamStudent::getExamActivityId, examActivityId));
         if (!CollectionUtils.isEmpty(teExamStudentList)) {
             Set<String> roomCodeSet = teExamStudentList.stream().map(s -> s.getRoomCode()).collect(Collectors.toSet());
             this.removeTodayExamCache(examId, examActivityId);
@@ -995,7 +995,7 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
      * @return
      */
     @Override
-    @Cacheable(value = SystemConstant.regionSummaryCache, unless = "#result == null")
+    @Cacheable(value = SystemConstant.regionSummaryCache, unless = "#result?.size() == 0")
     public List<TERegionSummary> addRegionSummaryCache() {
         return teRegionSummaryService.list();
     }
@@ -1006,7 +1006,7 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
      * @return
      */
     @Override
-    @CachePut(value = SystemConstant.regionSummaryCache, condition = "#result != null")
+    @CachePut(value = SystemConstant.regionSummaryCache, condition = "#result?.size() > 0")
     public List<TERegionSummary> updateRegionSummaryCache() {
         return teRegionSummaryService.list();
     }
@@ -1019,4 +1019,18 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
     public void removeOrgSummaryCache() {
 
     }
+
+    /**
+     * 删除全部考试统计缓存
+     *
+     * @param examId
+     * @param examActivityId
+     * @param roomCode
+     */
+    @Override
+    public void removeExamSummaryAllCache(Long examId, Long examActivityId, String roomCode) {
+        this.removeExamSummaryCache(examId);
+        this.removeExamSummaryCache(examId, examActivityId);
+        this.removeExamSummaryCache(examId, examActivityId, roomCode);
+    }
 }

+ 0 - 1
themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java

@@ -9,7 +9,6 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 

+ 4 - 2
themis-task/src/main/java/com/qmth/themis/task/quartz/MqActivityJob.java

@@ -5,7 +5,6 @@ import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
 import com.qmth.themis.business.cache.bean.ExamCacheBean;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
-import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.TEExam;
 import com.qmth.themis.business.entity.TEExamActivity;
 import com.qmth.themis.business.entity.TOeExamRecord;
@@ -78,6 +77,7 @@ public class MqActivityJob extends QuartzJobBean {
                 });
             } else {
                 themisCacheService.removeTodayExamCache(l.toString());
+                themisCacheService.removeTodayExamListCache(l);
             }
         }
         Long finishTime = System.currentTimeMillis();
@@ -124,8 +124,9 @@ public class MqActivityJob extends QuartzJobBean {
                                             updateExamRecordList.add(s);
                                             commonService.dismissRoomByStrRoomId(s.getId());
                                         } else {//交卷
-                                            teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
+                                           teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
                                         }
+                                        themisCacheService.removeExamSummaryAllCache(s.getExamId(), s.getExamActivityId(), examStudentCacheBean.getRoomCode());
                                     } catch (Exception e) {
                                         log.error(SystemConstant.LOG_ERROR, e);
                                     }
@@ -163,6 +164,7 @@ public class MqActivityJob extends QuartzJobBean {
                                         } else {//交卷
                                             teExamService.finish(examStudentCacheBean.getStudentId(), s.getId(), FinishTypeEnum.AUTO.name(), durationSeconds);
                                         }
+                                        themisCacheService.removeExamSummaryAllCache(s.getExamId(), s.getExamActivityId(), examStudentCacheBean.getRoomCode());
                                     } catch (Exception e) {
                                         log.error(SystemConstant.LOG_ERROR, e);
                                     }

+ 0 - 1
themis-task/src/main/java/com/qmth/themis/task/start/StartRunning.java

@@ -8,7 +8,6 @@ import com.qmth.themis.business.service.ThemisCacheService;
 import com.qmth.themis.business.util.MqUtil;
 import com.qmth.themis.mq.listener.RocketMessageConsumer;
 import com.qmth.themis.mq.templete.impl.*;
-import com.qmth.themis.task.config.DictionaryConfig;
 import com.qmth.themis.task.enums.QuartzTaskEnum;
 import com.qmth.themis.task.listener.QuartzOrderlyImpl;
 import com.qmth.themis.task.quartz.*;