Kaynağa Gözat

代码走查优化代码

wangliang 1 yıl önce
ebeveyn
işleme
8df7626916
18 değiştirilmiş dosya ile 194 ekleme ve 95 silme
  1. 14 4
      themis-admin/src/main/java/com/qmth/themis/admin/api/TBUserController.java
  2. 2 1
      themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateController.java
  3. 27 5
      themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateWarnInfoController.java
  4. 12 5
      themis-business/src/main/java/com/qmth/themis/business/dao/TEOrgSummaryMapper.java
  5. 1 1
      themis-business/src/main/java/com/qmth/themis/business/dao/TERegionSummaryMapper.java
  6. 4 1
      themis-business/src/main/java/com/qmth/themis/business/service/TERegionSummaryService.java
  7. 2 1
      themis-business/src/main/java/com/qmth/themis/business/service/TOeExamRecordService.java
  8. 11 11
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java
  9. 5 9
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOrgSummaryServiceImpl.java
  10. 5 2
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TERegionSummaryServiceImpl.java
  11. 9 4
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java
  12. 4 1
      themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java
  13. 11 0
      themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java
  14. 55 25
      themis-business/src/main/resources/mapper/TEOrgSummaryMapper.xml
  15. 6 0
      themis-business/src/main/resources/mapper/TERegionSummaryMapper.xml
  16. 3 3
      themis-business/src/main/resources/mapper/TIeInvigilateWarnInfoMapper.xml
  17. 14 17
      themis-business/src/main/resources/mapper/TOeExamRecordMapper.xml
  18. 9 5
      themis-task/src/main/java/com/qmth/themis/task/quartz/ExamSummaryJob.java

+ 14 - 4
themis-admin/src/main/java/com/qmth/themis/admin/api/TBUserController.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.ExpireTimeDTO;
@@ -14,10 +15,7 @@ import com.qmth.themis.business.entity.TBOrg;
 import com.qmth.themis.business.entity.TBSession;
 import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TBUserRole;
-import com.qmth.themis.business.enums.FieldUniqueEnum;
-import com.qmth.themis.business.enums.MqTagEnum;
-import com.qmth.themis.business.enums.RoleEnum;
-import com.qmth.themis.business.enums.SystemOperationEnum;
+import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.*;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
@@ -571,6 +569,18 @@ public class TBUserController {
                         @ApiParam(value = "机构id", required = false) @RequestParam(required = false) String orgId,
                         @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) int pageNumber,
                         @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) int pageSize) {
+        long timestamp = System.currentTimeMillis();
+        ExamRecordCacheUtil.setWarningCount(1L, 1, timestamp);
+        Integer warningCount = ExamRecordCacheUtil.getWarningCount(id);
+        ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(id);
+        if (Objects.nonNull(status) && status != ExamRecordStatusEnum.PERSISTED) {
+            if (Objects.nonNull(warningCount)) {
+                ExamRecordCacheUtil.setWarningCount(id, warningCount + 1, timestamp);
+            } else {
+                ExamRecordCacheUtil.setWarningCount(id, 1, timestamp);
+            }
+        }
+
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         AuthDto authDto = themisCacheService.addAccountAuthCache(tbUser.getId());
         if (authDto.getRoleCodes().toString().contains(RoleEnum.SUPER_ADMIN.name())) {

+ 2 - 1
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateController.java

@@ -387,7 +387,8 @@ public class TIeInvigilateController {
             tIeExamInvigilateNoticeUpdateWrapper.lambda().set(TIeInvigilateWarnInfo::getApproveStatus, 1)
                     .eq(TIeInvigilateWarnInfo::getExamRecordId, examRecordId);
             tIeInvigilateWarnInfoService.update(tIeExamInvigilateNoticeUpdateWrapper);
-            tOeExamRecordService.updateWarningUnreadCache(examRecordId, 0);
+            tOeExamRecordService.updateWarningUnreadByDb(examRecordId, 0);
+            tOeExamRecordService.updateWarningUnreadCache(examRecordId, 0, false);
         }
         invigilateListDetailBean.setMonitorVideoSource(examCacheBean.getMonitorVideoSource());
         invigilateListDetailBean.setMonitorRecord(examCacheBean.getMonitorRecord());

+ 27 - 5
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateWarnInfoController.java

@@ -3,6 +3,7 @@ package com.qmth.themis.admin.api;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.themis.business.bean.admin.ExamListBean;
 import com.qmth.themis.business.bean.admin.InvigilateListWarningBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
@@ -59,6 +60,9 @@ public class TIeInvigilateWarnInfoController {
     @Resource
     TEExamActivityService teExamActivityService;
 
+    @Resource
+    TEExamService teExamService;
+
     @ApiOperation(value = "预警提醒接口")
     @RequestMapping(value = "/notify", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"count\":1}", response = Result.class)})
@@ -81,14 +85,31 @@ public class TIeInvigilateWarnInfoController {
                 for (TBExamInvigilateUser t : tbExamInvigilateUserList) {
                     List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().eq(TEExamActivity::getExamId, t.getExamId()));
                     for (TEExamActivity teExamActivity : teExamActivityList) {
-                        teExamSummaryService.examSummary(t.getExamId(), teExamActivity.getId(), new HashSet<>(Arrays.asList(t.getRoomCode())));
                         teExamSummaryAllList.addAll(themisCacheService.getExamSummaryCache(t.getExamId(), teExamActivity.getId(), t.getRoomCode()));
                     }
                 }
                 count = teExamSummaryAllList.stream().mapToInt(s -> s.getWarningUnread()).sum();
             }
         } else {
-            count = tIeInvigilateWarnInfoService.warningCount(examId, examActivityId, roomCode, userId, tbUser.getOrgId());
+            //取当前用户机构id所属考试id集合
+            List<TEExam> teExamList = teExamService.list(new QueryWrapper<TEExam>().lambda().eq(TEExam::getOrgId, tbUser.getOrgId()));
+            if (!CollectionUtils.isEmpty(teExamList)) {
+                List<TEExamSummary> teExamSummaryAllList = new ArrayList<>();
+                for (TEExam t : teExamList) {
+                    List<ExamListBean> examListBeanList = themisCacheService.getTodayExamListCache(t.getId().toString());
+                    if (!CollectionUtils.isEmpty(examListBeanList)) {
+                        for (ExamListBean e : examListBeanList) {
+                            Set<String> roomCodeSet = new HashSet<>(Arrays.asList(e.getRoomCode().split(", ")));
+                            for (String s : roomCodeSet) {
+                                teExamSummaryAllList.addAll(themisCacheService.getExamSummaryCache(t.getId(), e.getExamActivityId(), s));
+                            }
+                        }
+                    }
+                }
+                count = teExamSummaryAllList.stream().mapToInt(s -> s.getWarningUnread()).sum();
+            }
+//            Integer count1 = tIeInvigilateWarnInfoService.warningCount(examId, examActivityId, roomCode, userId, tbUser.getOrgId());
+//            System.out.println(111);
         }
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.COUNT, count));
     }
@@ -147,12 +168,12 @@ public class TIeInvigilateWarnInfoController {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         AuthDto authDto = themisCacheService.addAccountAuthCache(tbUser.getId());
         if (!authDto.getRoleCodes().toString().contains(RoleEnum.ADMIN.name())) {
-            if (org.apache.commons.collections.CollectionUtils.isEmpty(warnInfoParams.getWarningIds()) && Objects.isNull(warnInfoParams.getExamRecordId())) {
+            if (CollectionUtils.isEmpty(warnInfoParams.getWarningIds()) && Objects.isNull(warnInfoParams.getExamRecordId())) {
                 throw new BusinessException("预警id数组或考试记录id不能同时为空");
             }
             UpdateWrapper<TIeInvigilateWarnInfo> tIeInvigilateWarnInfoUpdateWrapper = new UpdateWrapper<>();
             tIeInvigilateWarnInfoUpdateWrapper.lambda().set(TIeInvigilateWarnInfo::getApproveStatus, warnInfoParams.getApproveStatus());
-            if (!org.apache.commons.collections.CollectionUtils.isEmpty(warnInfoParams.getWarningIds())) {
+            if (!CollectionUtils.isEmpty(warnInfoParams.getWarningIds())) {
                 List<Long> warningTranIds = warnInfoParams.getWarningIds().stream().map(x -> Long.parseLong(x)).collect(Collectors.toList());
                 tIeInvigilateWarnInfoUpdateWrapper.lambda().in(TIeInvigilateWarnInfo::getId, warningTranIds);
             } else if (Objects.nonNull(warnInfoParams.getExamRecordId())) {
@@ -195,7 +216,8 @@ public class TIeInvigilateWarnInfoController {
             }
             List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.list(tOeExamRecordQueryWrapper);
             for (TOeExamRecord t : tOeExamRecordList) {
-                tOeExamRecordService.updateWarningUnreadCache(t.getId(), 0);
+                tOeExamRecordService.updateWarningUnreadByDb(t.getId(), 0);
+                tOeExamRecordService.updateWarningUnreadCache(t.getId(), 0, false);
             }
             tOeExamRecordService.approveStatusListUpdate(examId, examActivityId, roomCode, approveStatus, name, identity, minMultipleFaceCount, maxMultipleFaceCount, minExceptionCount, maxExceptionCount, minWarningCount, maxWarningCount, userId, tbUser.getOrgId());
         }

+ 12 - 5
themis-business/src/main/java/com/qmth/themis/business/dao/TEOrgSummaryMapper.java

@@ -5,7 +5,6 @@ import com.qmth.themis.business.entity.TEOrgSummary;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
-import java.util.Set;
 
 /**
  * <p>
@@ -23,7 +22,15 @@ public interface TEOrgSummaryMapper extends BaseMapper<TEOrgSummary> {
      * @param examIdSet
      * @return
      */
-    List<Integer> orgSummaryByFinishCountAndFinishStudentCount(@Param("examIdSet") List<Long> examIdSet);
+    List<Integer> orgSummary(@Param("orgId") Long orgId, @Param("examIdSet") List<Long> examIdSet);
+
+    /**
+     * 机构统计考试次数和考试人数信息
+     *
+     * @param examIdSet
+     * @return
+     */
+    List<Integer> orgSummaryByFinishCountAndFinishStudentCount(@Param("orgId") Long orgId, @Param("examIdSet") List<Long> examIdSet);
 
     /**
      * 统计全局考试科次
@@ -31,7 +38,7 @@ public interface TEOrgSummaryMapper extends BaseMapper<TEOrgSummary> {
      * @param examIdSet
      * @return
      */
-    Integer orgSummaryByFinishCount(@Param("examIdSet") List<Long> examIdSet);
+    Integer orgSummaryByFinishCount(@Param("orgId") Long orgId, @Param("examIdSet") List<Long> examIdSet);
 
     /**
      * 统计全局考试科次
@@ -39,7 +46,7 @@ public interface TEOrgSummaryMapper extends BaseMapper<TEOrgSummary> {
      * @param examIdSet
      * @return
      */
-    Integer orgSummaryByOnlineCount(@Param("examIdSet") List<Long> examIdSet);
+    Integer orgSummaryByOnlineCount(@Param("orgId") Long orgId, @Param("examIdSet") List<Long> examIdSet);
 
     /**
      * 统计全局考试科次
@@ -47,7 +54,7 @@ public interface TEOrgSummaryMapper extends BaseMapper<TEOrgSummary> {
      * @param examIdSet
      * @return
      */
-    Integer orgSummaryByExamCount(@Param("examIdSet") List<Long> examIdSet);
+    Integer orgSummaryByExamCount(@Param("orgId") Long orgId, @Param("examIdSet") List<Long> examIdSet);
 
     /**
      * 保存机构统计信息

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/dao/TERegionSummaryMapper.java

@@ -21,7 +21,7 @@ public interface TERegionSummaryMapper extends BaseMapper<TERegionSummary> {
      *
      * @return
      */
-    List<TERegionSummary> regionSummary();
+    List<TERegionSummary> regionSummary(@Param("examId") Long examId,@Param("examActivityId") Long examActivityId);
 
     /**
      * 保存地区统计信息

+ 4 - 1
themis-business/src/main/java/com/qmth/themis/business/service/TERegionSummaryService.java

@@ -15,6 +15,9 @@ public interface TERegionSummaryService extends IService<TERegionSummary> {
 
     /**
      * 保存地区统计信息
+     *
+     * @param examId
+     * @param examActivityId
      */
-    public void regionSummary();
+    public void regionSummary(Long examId, Long examActivityId);
 }

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/service/TOeExamRecordService.java

@@ -655,8 +655,9 @@ public interface TOeExamRecordService extends IService<TOeExamRecord> {
      *
      * @param id
      * @param number
+     * @param updateDb
      */
-    void updateWarningUnreadCache(Long id, Integer number);
+    void updateWarningUnreadCache(Long id, Integer number, Boolean updateDb);
 
     /**
      * 更新陌生人脸预警总数

+ 11 - 11
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -190,17 +190,17 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             teExamActivityWaitList.forEach(i -> {
                 ExamCacheBean examCache = getExamCacheBeanNative(i.getExamId());
                 TEExamWaitDto teExamWaitDto = new TEExamWaitDto(i.getExamId(), i.getExamActivityId(), examCache.getName(), examCache.getCode());
-                if (Objects.nonNull(examCache.getEnable()) && Objects.nonNull(i.getEnable())
-                        && examCache.getEnable().intValue() == 1 && i.getEnable().intValue() == 1
-                        && i.getFinishTime().longValue() > System.currentTimeMillis()) {
-                    setMap.put(i.getExamId(), teExamWaitDto);
-                    Set<TEExamActivityWaitDto> teExamActivityWaitDtos = Objects.nonNull(map.get(i.getExamId())) ? map.get(i.getExamId()) : new LinkedHashSet<>();
-                    teExamActivityWaitDtos.add(i);
-                    map.put(i.getExamId(), teExamActivityWaitDtos);
-                    ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(i.getExamStudentId());
-                    Integer leftExamCount = examCache.getExamCount().intValue() - examStudentCacheBean.getAlreadyExamCount().intValue() < 0 ? 0 : examCache.getExamCount().intValue() - examStudentCacheBean.getAlreadyExamCount().intValue();
-                    i.setLeftExamCount(leftExamCount);
-                }
+//                if (Objects.nonNull(examCache.getEnable()) && Objects.nonNull(i.getEnable())
+//                        && examCache.getEnable().intValue() == 1 && i.getEnable().intValue() == 1
+//                        && i.getFinishTime().longValue() > System.currentTimeMillis()) {
+                setMap.put(i.getExamId(), teExamWaitDto);
+                Set<TEExamActivityWaitDto> teExamActivityWaitDtos = Objects.nonNull(map.get(i.getExamId())) ? map.get(i.getExamId()) : new LinkedHashSet<>();
+                teExamActivityWaitDtos.add(i);
+                map.put(i.getExamId(), teExamActivityWaitDtos);
+                ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(i.getExamStudentId());
+                Integer leftExamCount = examCache.getExamCount().intValue() - examStudentCacheBean.getAlreadyExamCount().intValue() < 0 ? 0 : examCache.getExamCount().intValue() - examStudentCacheBean.getAlreadyExamCount().intValue();
+                i.setLeftExamCount(leftExamCount);
+//                }
             });
             setMap.forEach((k, v) -> {
                 v.setActivities(new ArrayList<>(map.get(k)));

+ 5 - 9
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOrgSummaryServiceImpl.java

@@ -46,10 +46,8 @@ public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEO
     @Override
     public void orgSummary(Long orgId, List<Long> examIdSet) {
         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));
+            List<Integer> list = this.baseMapper.orgSummary(orgId, examIdSet);
+            TEOrgSummary teOrgSummary = new TEOrgSummary(orgId, list.get(0), list.get(1), list.get(2), list.get(3));
             teOrgSummaryService.saveOrUpdate(teOrgSummary);
         } else {
             LinkedMultiValueMap<Long, Long> orgExamIdMap = new LinkedMultiValueMap<>();
@@ -67,10 +65,8 @@ public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEO
                 }
             }
             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));
+                List<Integer> list = this.baseMapper.orgSummary(orgId, examIdSet);
+                TEOrgSummary teOrgSummary = new TEOrgSummary(orgId, list.get(0), list.get(1), list.get(2), list.get(3));
                 teOrgSummaryService.saveOrUpdate(teOrgSummary);
             } else {
                 orgExamIdMap.forEach((k, v) -> {//从考试批次缓存信息里拿取在线人数、考试人数、完成考生数
@@ -83,7 +79,7 @@ public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEO
                             finishStudentCount = finishStudentCount + t.getFinishCount();
                         }
                     }
-                    Integer finishCount = this.baseMapper.orgSummaryByFinishCount(v);
+                    Integer finishCount = this.baseMapper.orgSummaryByFinishCount(orgId, v);
                     TEOrgSummary teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCount, finishStudentCount);
                     teOrgSummaryService.saveOrUpdate(teOrgSummary);
                 });

+ 5 - 2
themis-business/src/main/java/com/qmth/themis/business/service/impl/TERegionSummaryServiceImpl.java

@@ -31,10 +31,13 @@ public class TERegionSummaryServiceImpl extends ServiceImpl<TERegionSummaryMappe
 
     /**
      * 保存地区统计信息
+     *
+     * @param examId
+     * @param examActivityId
      */
     @Override
-    public void regionSummary() {
-        List<TERegionSummary> teRegionSummaryList = this.baseMapper.regionSummary();
+    public void regionSummary(Long examId, Long examActivityId) {
+        List<TERegionSummary> teRegionSummaryList = this.baseMapper.regionSummary(examId, examActivityId);
         if (!CollectionUtils.isEmpty(teRegionSummaryList)) {
             for (TERegionSummary t : teRegionSummaryList) {
                 TERegionSummary teRegionSummaryDb = this.getOne(new QueryWrapper<TERegionSummary>().lambda()

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

@@ -607,9 +607,10 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
      *
      * @param id
      * @param number
+     * @param updateDb
      */
     @Override
-    public void updateWarningUnreadCache(Long id, Integer number) {
+    public void updateWarningUnreadCache(Long id, Integer number, Boolean updateDb) {
         Integer warningUnread = ExamRecordCacheUtil.getWarningUnread(id);
         ExamRecordStatusEnum status = ExamRecordCacheUtil.getStatus(id);
         if (Objects.nonNull(status) && status != ExamRecordStatusEnum.PERSISTED) {
@@ -621,10 +622,14 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
             } else {
                 ExamRecordCacheUtil.setWarningUnread(id, 0, timestamp);
             }
-            this.sendExamRecordDataSaveMq(id, timestamp);
+            if (Objects.nonNull(updateDb) && updateDb) {
+                this.sendExamRecordDataSaveMq(id, timestamp);
+            }
         } else {
-            //已经结束了直接更新数据库
-            this.sendExamRecordDataUpdateWarningUnreadMq(id, number);
+            if (Objects.nonNull(updateDb) && updateDb) {
+                //已经结束了直接更新数据库
+                this.sendExamRecordDataUpdateWarningUnreadMq(id, number);
+            }
         }
     }
 

+ 4 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/ThemisCacheServiceImpl.java

@@ -619,7 +619,10 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
             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).eq(TEExamActivity::getEnable, 1));
+            List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda()
+                    .and(w -> w.ge(TEExamActivity::getStartTime, startTime).le(TEExamActivity::getStartTime, endTime))
+                    .or(w -> w.le(TEExamActivity::getStartTime, startTime).ge(TEExamActivity::getFinishTime, endTime))
+                    .eq(TEExamActivity::getEnable, 1));
             //统计当天00:00:00~23:59:59可以进行的考试批次、场次、考场编码信息
             if (!CollectionUtils.isEmpty(teExamActivityList)) {
                 LinkedMultiValueMap<Long, ExamListBean> todayExamListMap = new LinkedMultiValueMap<>();//考试批次、场次集合/考场编码集合

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

@@ -90,6 +90,17 @@ public class RedisUtil {
         redisTemplate.opsForHash().put(key, hashKey, hashValue);
     }
 
+    /**
+     * 设置hash
+     *
+     * @param key
+     * @param hashKey
+     * @param count
+     */
+    public void setInc(String key, String hashKey, Long count) {
+        redisTemplate.opsForHash().increment(key, hashKey, count);
+    }
+
     /**
      * 获取hash
      *

+ 55 - 25
themis-business/src/main/resources/mapper/TEOrgSummaryMapper.xml

@@ -2,43 +2,69 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.themis.business.dao.TEOrgSummaryMapper">
 
+    <select id="orgSummary" resultType="java.lang.Integer">
+        <include refid="orgSummaryByOnlineCountCommon" />
+            union all
+        <include refid="orgSummaryByExamCountCommon" />
+            union all
+        <include refid="orgSummaryByFinishCountAndFinishStudentCountCommon" />
+    </select>
+
     <select id="orgSummaryByFinishCountAndFinishStudentCount" resultType="java.lang.Integer">
-        select count(1) as finishCount
+        <include refid="orgSummaryByFinishCountAndFinishStudentCountCommon" />
+    </select>
+
+    <sql id="orgSummaryByFinishCountAndFinishStudentCountCommon">
+        select count(1) as c
         from t_oe_exam_record toer
         where toer.STATUS in ('FINISHED', 'PERSISTED')
-        <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
-            and toer.exam_id in
-            <foreach collection="examIdSet" item="examId" index="index" open="(" close=")" separator=",">
-                #{examId}
-            </foreach>
+        <if test="orgId != null and orgId != '' and orgId > 0">
+            <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
+                and toer.exam_id in
+                <foreach collection="examIdSet" item="examId" index="index" open="(" close=")" separator=",">
+                    #{examId}
+                </foreach>
+            </if>
         </if>
         union all
-        select count(distinct tees.id) as finishStudentCount
+        select count(tees.id) as c
         from t_e_exam_student tees
-        left join t_oe_exam_record toer on toer.exam_student_id = tees.id
-        where toer.STATUS in ('FINISHED', 'PERSISTED')
-        <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
-            and toer.exam_id in
-            <foreach collection="examIdSet" item="examId" index="index" open="(" close=")" separator=",">
-                #{examId}
-            </foreach>
+        left join t_oe_exam_record toer on toer.exam_student_id = tees.id and tees.current_record_id = toer.id
+        where toer.STATUS in ('FINISHED', 'PERSISTED') or tees.already_exam_count > 0
+        <if test="orgId != null and orgId != ''">
+            <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
+                and toer.exam_id in
+                <foreach collection="examIdSet" item="examId" index="index" open="(" close=")" separator=",">
+                    #{examId}
+                </foreach>
+            </if>
         </if>
-    </select>
+    </sql>
 
     <select id="orgSummaryByFinishCount" resultType="java.lang.Integer">
+        <include refid="orgSummaryByFinishCountCommon" />
+    </select>
+
+    <sql id="orgSummaryByFinishCountCommon">
         select count(1) as finishCount
         from t_oe_exam_record toer
         where toer.STATUS in ('FINISHED', 'PERSISTED')
-        <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
-            and toer.exam_id in
-            <foreach collection="examIdSet" item="examId" index="index" open="(" close=")" separator=",">
-                #{examId}
-            </foreach>
+        <if test="orgId != null and orgId != '' and orgId > 0">
+            <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
+                and toer.exam_id in
+                <foreach collection="examIdSet" item="examId" index="index" open="(" close=")" separator=",">
+                    #{examId}
+                </foreach>
+            </if>
         </if>
-    </select>
+    </sql>
 
     <select id="orgSummaryByOnlineCount" resultType="java.lang.Integer">
-        select count(1) as onlineCount
+        <include refid="orgSummaryByOnlineCountCommon" />
+    </select>
+
+    <sql id="orgSummaryByOnlineCountCommon">
+        select count(1) as c
         from t_oe_exam_record toer
         where toer.client_websocket_status = 'ON_LINE'
         <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
@@ -47,10 +73,14 @@
                 #{examId}
             </foreach>
         </if>
-    </select>
+    </sql>
 
     <select id="orgSummaryByExamCount" resultType="java.lang.Integer">
-        select count(1) as examCount
+        <include refid="orgSummaryByExamCountCommon" />
+    </select>
+
+    <sql id="orgSummaryByExamCountCommon">
+        select count(1) as c
         from t_oe_exam_record toer
         where (toer.STATUS = 'ANSWERING' and toer.client_websocket_status = 'ON_LINE') or toer.status = 'RESUME_PREPARE' or toer.status = 'BREAK_OFF'
         <if test="examIdSet != null and examIdSet != '' and examIdSet.size > 0">
@@ -59,7 +89,7 @@
                 #{examId}
             </foreach>
         </if>
-    </select>
+    </sql>
 
     <insert id="saveOrgSummary">
         INSERT INTO t_e_org_summary

+ 6 - 0
themis-business/src/main/resources/mapper/TERegionSummaryMapper.xml

@@ -9,6 +9,12 @@
         from t_ip_region tir
         join t_oe_exam_record toer on tir.exam_record_id = toer.id
         WHERE toer.client_websocket_status = 'ON_LINE'
+            <if test="examId != null and examId != ''">
+                and toer.exam_id = #{examId}
+            </if>
+            <if test="examActivityId != null and examActivityId != ''">
+                and toer.exam_activity_id = #{examActivityId}
+            </if>
         group by
         tir.country,
         tir.province

+ 3 - 3
themis-business/src/main/resources/mapper/TIeInvigilateWarnInfoMapper.xml

@@ -72,8 +72,8 @@
         tiiwi.remark,
         tiiwi.exam_id as examId,
         tiiwi.exam_record_id as examRecordId
-        from
-        t_ie_invigilate_warn_info tiiwi
+        from t_e_exam_student tees
+        left join t_ie_invigilate_warn_info tiiwi on tees.id = tiiwi.exam_student_id
         <!--2022/09/03新增 start
         join
         (
@@ -87,7 +87,7 @@
         tiiwi.exam_record_id) temp on
         temp.warningId = tiiwi.id
         2022/09/03新增 end-->
-        left join t_e_exam_student tees on tees.id = tiiwi.exam_student_id
+        left join t_oe_exam_record toer on toer.id = tiiwi.exam_record_id and (toer.id = tees.current_record_id or tees.already_exam_count > 0)
         left join t_b_exam_invigilate_user tbeiu on tbeiu.exam_id = tiiwi.exam_id and tbeiu.room_code = tees.room_code
         join t_e_exam tee on tee.id = tiiwi.exam_id
         <where> 1 = 1

+ 14 - 17
themis-business/src/main/resources/mapper/TOeExamRecordMapper.xml

@@ -4,7 +4,7 @@
         namespace="com.qmth.themis.business.dao.TOeExamRecordMapper">
 
     <sql id="invigilatePageHead">
-        select distinct t.exam_id          examId,
+        select t.exam_id          examId,
                         tee.name  as       examName,
                         t.exam_activity_id examActivityId,
                         teea.code as       examActivityCode,
@@ -30,15 +30,14 @@
 
     <sql id="invigilatePageMiddle">
         from t_oe_exam_record t
-		left join t_e_exam_student s on t.exam_student_id = s.id
+		left join t_e_exam_student s on t.id = s.current_record_id or s.already_exam_count > 0
 		left join t_e_exam tee on tee.id = t.exam_id
 		left join t_e_exam_activity teea on teea.id = t.exam_activity_id
     </sql>
 
     <select id="invigilatePageListVideo" resultType="com.qmth.themis.business.bean.admin.InvigilateListVideoBean">
         select (@i := @i + 1) as seq,t.* from(
-        select
-        distinct s.exam_id as examId,
+        select s.exam_id as examId,
         tee.name as examName,
         s.exam_activity_id as examActivityId,
         teea.code as examActivityCode,
@@ -72,7 +71,7 @@
         <if test="userId != null and userId != ''">
             left join t_b_exam_invigilate_user tbeiu on tbeiu.exam_id = s.exam_id
         </if>
-        left join t_oe_exam_record toer on toer.exam_student_id = s.id
+        left join t_oe_exam_record toer on toer.id = s.current_record_id or s.already_exam_count > 0
         WHERE 1 = 1
         <if test="examId != null and examId != ''">
             and s.exam_id = #{examId}
@@ -141,9 +140,9 @@
         <if test="mobileSecondMonitorStatus != null and mobileSecondMonitorStatus != ''">
             and toer.mobile_second_monitor_status = upper(#{mobileSecondMonitorStatus})
         </if>
+        order by s.identity desc
         ) t,
         (SELECT @i := 0) as i
-        order by t.identity desc
     </select>
 
     <select id="invigilatePageListVideoRandom" resultType="com.qmth.themis.business.bean.admin.InvigilateListVideoBean">
@@ -158,7 +157,7 @@
             <if test="orgId != null and orgId != ''">
                 and tee.org_id = #{orgId}
             </if>
-            and ((toer.status = 'FIRST_PREPARE' and toer.client_websocket_status = 'ON_LINE') or toer.status in ('ANSWERING', 'BREAK_OFF', 'RESUME_PREPARE'))
+            and ((t.status = 'FIRST_PREPARE' and t.client_websocket_status = 'ON_LINE') or t.status in ('ANSWERING', 'BREAK_OFF', 'RESUME_PREPARE'))
         </where>
         ORDER BY RAND() LIMIT #{randomNum}
     </select>
@@ -273,8 +272,7 @@
     </select>
 
     <select id="invigilatePageWarningList" resultType="com.qmth.themis.business.bean.admin.InvigilateListWarningBean">
-        select (@i := @i + 1) as seq,t.* from(select
-        distinct
+        select (@i := @i + 1) as seq,t.* from(select distinct
         tee.id as examId,
         tee.name as examName,
         teea.id as examActivityId,
@@ -294,11 +292,11 @@
         tiiwi.approve_status as approveStatus,
         IFNULL(toer.exception_count,0) as exceptionCount,
         IFNULL(toer.warning_multiple_face_count,0) as multipleFaceCount
-        from t_ie_invigilate_warn_info tiiwi
+        from t_e_exam_student tees
+        left join t_ie_invigilate_warn_info tiiwi on tees.id = tiiwi.exam_student_id
         left join t_e_exam tee on tee.id = tiiwi.exam_id
         left join t_e_exam_activity teea on teea.id = tiiwi.exam_activity_id
-        left join t_oe_exam_record toer on toer.id = tiiwi.exam_record_id
-        left join t_e_exam_student tees on tees.id = tiiwi.exam_student_id
+        left join t_oe_exam_record toer on toer.id = tiiwi.exam_record_id and (toer.id = tees.current_record_id or tees.already_exam_count > 0)
         <if test="userId != null and userId != ''">
             left join t_b_exam_invigilate_user tbeiu on tbeiu.exam_id = tees.exam_id
         </if>
@@ -496,7 +494,7 @@
 
     <select id="invigilatePageProgressListExport"
             resultType="com.qmth.themis.business.bean.admin.InvigilateListProgressExcelBean">
-        select distinct tee.id as examId,
+        select tee.id as examId,
         tee.name as examName,
         teea.id as examActivityId,
         teea.code as examActivityCode,
@@ -519,7 +517,7 @@
         left join t_e_exam_activity teea on
         teea.id = tees.exam_activity_id
         left join t_e_student tes on tees.student_id = tes.id
-        left join t_oe_exam_record t on t.exam_id = tees.exam_id and t.exam_activity_id = tees.exam_activity_id and
+        left join t_oe_exam_record t on t.id = tees.current_record_id or tees.already_exam_count > 0
         t.exam_student_id = tees.id
         <if test="userId != null and userId != ''">
             left join t_b_exam_invigilate_user tbeiu on tbeiu.exam_id = tees.exam_id
@@ -579,8 +577,7 @@
 
     <sql id="invigilatePageListHistorySql">
         select (@i := @i + 1) as seq,t.* from(
-        select
-        distinct s.exam_id as examId,
+        select s.exam_id as examId,
         tee.name as examName,
         s.exam_activity_id as examActivityId,
         teea.code as examActivityCode,
@@ -615,7 +612,7 @@
         teea.id = s.exam_activity_id
         left join t_e_student tes on
         s.student_id = tes.id
-        left join t_oe_exam_record toer on toer.exam_student_id = s.id
+        left join t_oe_exam_record toer on toer.id = s.current_record_id or s.already_exam_count > 0
         <if test="userId != null and userId != ''">
             left join t_b_exam_invigilate_user tbeiu on tbeiu.exam_id = s.exam_id
         </if>

+ 9 - 5
themis-task/src/main/java/com/qmth/themis/task/quartz/ExamSummaryJob.java

@@ -80,7 +80,7 @@ public class ExamSummaryJob extends QuartzJobBean {
                         if (ac.getEnable().intValue() == 1 && startTime <= timestamp && endTime >= timestamp) {
                             log.info("examSummaryJob examId:{},examActivityId:{},roomCodeSet:{} 开始统计", examId, e.getExamActivityId(), roomCodeSet);
                             teExamSummaryService.examSummary(examId, e.getExamActivityId(), roomCodeSet);
-                            teRegionSummaryService.regionSummary();
+                            teRegionSummaryService.regionSummary(examId, e.getExamActivityId());
                         } else if (ac.getEnable().intValue() == 0 || endTime <= timestamp) {//禁用或超过考试结束时间则删除考试场次缓存
                             themisCacheService.removeTodayExamListCache(entry.getKey(), e.getExamActivityId());
                         }
@@ -90,10 +90,14 @@ public class ExamSummaryJob extends QuartzJobBean {
                 }
             }
             //统计机构信息
-            orgExamIdMap.forEach((k, v) -> {
-                teOrgSummaryService.orgSummary(k, v);
-            });
-            teOrgSummaryService.orgSummary(0L, null);
+            if (orgExamIdMap.size() > 0) {
+                List<Long> examIdAll = new ArrayList<>();
+                orgExamIdMap.forEach((k, v) -> {
+                    teOrgSummaryService.orgSummary(k, v);
+                    examIdAll.addAll(v);
+                });
+                teOrgSummaryService.orgSummary(0L, examIdAll);
+            }
         }
     }
 }