Explorar o código

预警通知修改

wangliang hai 1 ano
pai
achega
b206000aa0

+ 60 - 7
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateWarnInfoController.java

@@ -1,19 +1,16 @@
 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.annotation.RedisLimitAnnotation;
 import com.qmth.themis.business.bean.admin.InvigilateListWarningBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.params.WarnInfoParams;
 import com.qmth.themis.business.dto.response.TIeWarningNotifyDto;
-import com.qmth.themis.business.entity.TBUser;
-import com.qmth.themis.business.entity.TIeInvigilateWarnInfo;
+import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.RoleEnum;
-import com.qmth.themis.business.service.TIeInvigilateWarnInfoService;
-import com.qmth.themis.business.service.TOeExamRecordService;
-import com.qmth.themis.business.service.ThemisCacheService;
+import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
@@ -53,6 +50,15 @@ public class TIeInvigilateWarnInfoController {
     @Resource
     ThemisCacheService themisCacheService;
 
+    @Resource
+    TBExamInvigilateUserService tbExamInvigilateUserService;
+
+    @Resource
+    TEExamSummaryService teExamSummaryService;
+
+    @Resource
+    TEExamActivityService teExamActivityService;
+
     @ApiOperation(value = "预警提醒接口")
     @RequestMapping(value = "/notify", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"count\":1}", response = Result.class)})
@@ -63,11 +69,27 @@ public class TIeInvigilateWarnInfoController {
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         AuthDto authDto = themisCacheService.addAccountAuthCache(tbUser.getId());
         //如果有监考员角色,只能查看自己所监考的考场,巡考员和管理员则可以查看全部考场
+        Integer count = null;
         Long userId = null;
         if (authDto.getRoleCodes().toString().contains(RoleEnum.INVIGILATE.name())) {
             userId = tbUser.getId();
+            List<TBExamInvigilateUser> tbExamInvigilateUserList = tbExamInvigilateUserService.list(new QueryWrapper<TBExamInvigilateUser>().lambda()
+                    .eq(TBExamInvigilateUser::getOrgId, tbUser.getOrgId())
+                    .eq(TBExamInvigilateUser::getUserId, userId));
+            if (!CollectionUtils.isEmpty(tbExamInvigilateUserList)) {
+                List<TEExamSummary> teExamSummaryAllList = new ArrayList<>();
+                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.addExamSummaryCache(t.getExamId(), teExamActivity.getId(), t.getRoomCode()));
+                    }
+                }
+                count = teExamSummaryAllList.stream().mapToInt(s -> s.getWarningUnread()).sum();
+            }
+        } else {
+            count = tIeInvigilateWarnInfoService.warningCount(examId, examActivityId, roomCode, userId, tbUser.getOrgId());
         }
-        Integer count = tIeInvigilateWarnInfoService.warningCount(examId, examActivityId, roomCode, userId, tbUser.getOrgId());
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.COUNT, count));
     }
 
@@ -185,4 +207,35 @@ public class TIeInvigilateWarnInfoController {
         }
         return ResultUtil.ok(true);
     }
+
+    /**
+     * 预警通知公用
+     *
+     * @param admin
+     * @return
+     */
+    protected Integer warnNotifyCommon(boolean admin) {
+        Integer count = null;
+        TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
+        QueryWrapper<TBExamInvigilateUser> tbExamInvigilateUserQueryWrapper = new QueryWrapper<>();
+        tbExamInvigilateUserQueryWrapper.lambda().eq(TBExamInvigilateUser::getOrgId, tbUser.getOrgId());
+        if (!admin) {
+            tbExamInvigilateUserQueryWrapper.lambda().eq(TBExamInvigilateUser::getUserId, tbUser.getId());
+        }
+        List<TBExamInvigilateUser> tbExamInvigilateUserList = tbExamInvigilateUserService.list(tbExamInvigilateUserQueryWrapper);
+        if (!CollectionUtils.isEmpty(tbExamInvigilateUserList)) {
+            List<TEExamSummary> teExamSummaryAllList = new ArrayList<>();
+            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.addExamSummaryCache(t.getExamId(), teExamActivity.getId(), t.getRoomCode()));
+                }
+            }
+            if (!CollectionUtils.isEmpty(teExamSummaryAllList)) {
+                count = teExamSummaryAllList.stream().mapToInt(s -> s.getWarningUnread()).sum();
+            }
+        }
+        return count;
+    }
 }

+ 2 - 2
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -197,8 +197,8 @@ public class SystemConstant {
     public static final String FORM_USER_ID = "formUserId";
     public static final String OPER = "oper";
     public static final String EXAM = "exam";
-//    public static final String WARNING_COUNT_UPDATE = "warning_count_update";
-//    public static final String WARNING_UNREAD_UPDATE = "warning_unread_update";
+    public static final String WARNING_COUNT_UPDATE = "warning_count_update";
+    public static final String WARNING_UNREAD_UPDATE = "warning_unread_update";
     //    public static final String EXEC_TIME = "execTime";
 //    public static final String REAL_EXEC_TIME = "realExecTime";
     public static final String INSERT = "insert";

+ 14 - 14
themis-business/src/main/java/com/qmth/themis/business/dao/TOeExamRecordMapper.java

@@ -587,18 +587,18 @@ public interface TOeExamRecordMapper extends BaseMapper<TOeExamRecord> {
 //     */
 //    List<MapDataCountBean> mapDataCount();
 
-//    /**
-//     * 根据id更新预警数量
-//     *
-//     * @param id
-//     */
-//    void updateWarningCount(@Param("id") Long id);
-//
-//    /**
-//     * 更新预警未读数
-//     *
-//     * @param id
-//     * @param number
-//     */
-//    void updateWarningUnread(@Param("id") Long id, @Param("number") Integer number);
+    /**
+     * 根据id更新预警数量
+     *
+     * @param id
+     */
+    void updateWarningCount(@Param("id") Long id);
+
+    /**
+     * 更新预警未读数
+     *
+     * @param id
+     * @param number
+     */
+    void updateWarningUnread(@Param("id") Long id, @Param("number") Integer number);
 }

+ 28 - 30
themis-business/src/main/java/com/qmth/themis/business/service/TOeExamRecordService.java

@@ -61,22 +61,20 @@ public interface TOeExamRecordService extends IService<TOeExamRecord> {
      */
     void sendExamRecordDataSaveMq(Long recordId, Long timestamp);
 
-//    /**
-//     * 发送mq更新考试预警数量记录
-//     *
-//     * @param recordId
-//     * @param timestamp
-//     */
-//    void sendExamRecordDataUpdateWarningCountMq(Long recordId, Long timestamp);
-//
-//    /**
-//     * 发送mq更新考试预警未读数量
-//     *
-//     * @param recordId
-//     * @param timestamp
-//     * @param number
-//     */
-//    void sendExamRecordDataUpdateWarningUnreadMq(Long recordId, Long timestamp, Integer number);
+    /**
+     * 发送mq更新考试预警数量记录
+     *
+     * @param recordId
+     */
+    void sendExamRecordDataUpdateWarningCountMq(Long recordId);
+
+    /**
+     * 发送mq更新考试预警未读数量
+     *
+     * @param recordId
+     * @param number
+     */
+    void sendExamRecordDataUpdateWarningUnreadMq(Long recordId, Integer number);
 
     /**
      * 发送mq更新考试记录
@@ -629,20 +627,20 @@ public interface TOeExamRecordService extends IService<TOeExamRecord> {
      */
     TOeExamRecord getExamRecordForDb(Long examId, Long activityId, Long examStudentId, ExamRecordStatusEnum examRecordStatusEnum);
 
-//    /**
-//     * 根据id更新预警数量
-//     *
-//     * @param id
-//     */
-//    void updateWarningCount(Long id);
-//
-//    /**
-//     * 根据id更新预警未读数量
-//     *
-//     * @param id
-//     * @param number
-//     */
-//    void updateWarningUnread(Long id, Integer number);
+    /**
+     * 根据id更新预警数量
+     *
+     * @param id
+     */
+    void updateWarningCountByDb(Long id);
+
+    /**
+     * 根据id更新预警未读数量
+     *
+     * @param id
+     * @param number
+     */
+    void updateWarningUnreadByDb(Long id, Integer number);
 
     /**
      * 更新预警总数

+ 60 - 58
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -544,26 +544,26 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
         return this.getOne(tOeExamRecordQueryWrapper);
     }
 
-//    /**
-//     * 根据id更新预警数量
-//     *
-//     * @param id
-//     */
-//    @Override
-//    public void updateWarningCount(Long id) {
-//        this.baseMapper.updateWarningCount(id);
-//    }
-//
-//    /**
-//     * 根据id更新预警未读数量
-//     *
-//     * @param id
-//     * @param number
-//     */
-//    @Override
-//    public void updateWarningUnread(Long id, Integer number) {
-//        this.baseMapper.updateWarningUnread(id, number);
-//    }
+    /**
+     * 根据id更新预警数量
+     *
+     * @param id
+     */
+    @Override
+    public void updateWarningCountByDb(Long id) {
+        this.baseMapper.updateWarningCount(id);
+    }
+
+    /**
+     * 根据id更新预警未读数量
+     *
+     * @param id
+     * @param number
+     */
+    @Override
+    public void updateWarningUnreadByDb(Long id, Integer number) {
+        this.baseMapper.updateWarningUnread(id, number);
+    }
 
     /**
      * 更新预警总数
@@ -593,6 +593,9 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
                 this.updateWarningMultipleFaceCountCache(id);
             }
             this.sendExamRecordDataSaveMq(id, timestamp);
+        } else {
+            //已经结束了直接更新数据库
+            this.sendExamRecordDataUpdateWarningCountMq(id);
         }
     }
 
@@ -616,6 +619,9 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
                 ExamRecordCacheUtil.setWarningUnread(id, 0, timestamp);
             }
             this.sendExamRecordDataSaveMq(id, timestamp);
+        } else {
+            //已经结束了直接更新数据库
+            this.sendExamRecordDataUpdateWarningUnreadMq(id, number);
         }
     }
 
@@ -715,43 +721,39 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
         }
     }
 
-//    /**
-//     * 发送mq更新考试预警数量记录
-//     *
-//     * @param recordId
-//     * @param timestamp
-//     */
-//    @Override
-//    public void sendExamRecordDataUpdateWarningCountMq(Long recordId, Long timestamp) {
-//        try {
-//            ExamRecordCacheUtil.setUpdateTime(recordId, timestamp);
-//            MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), SystemConstant.WARNING_COUNT_UPDATE, timestamp);
-//            mqDtoService.assembleSendAsyncMsg(mqDto);
-//        } catch (Exception e) {
-//            log.error(SystemConstant.LOG_ERROR, e);
-//        }
-//    }
-//
-//    /**
-//     * 发送mq更新考试预警未读数量
-//     *
-//     * @param recordId
-//     * @param timestamp
-//     * @param number
-//     */
-//    @Override
-//    public void sendExamRecordDataUpdateWarningUnreadMq(Long recordId, Long timestamp, Integer number) {
-//        try {
-//            ExamRecordCacheUtil.setUpdateTime(recordId, timestamp);
-//            Map<String, Object> properties = new HashMap<>();
-//            properties.put(SystemConstant.NUMBER, number);
-//            MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), SystemConstant.WARNING_UNREAD_UPDATE, timestamp);
-//            mqDto.setProperties(properties);
-//            mqDtoService.assembleSendAsyncMsg(mqDto);
-//        } catch (Exception e) {
-//            log.error(SystemConstant.LOG_ERROR, e);
-//        }
-//    }
+    /**
+     * 发送mq更新考试预警数量记录
+     *
+     * @param recordId
+     */
+    @Override
+    public void sendExamRecordDataUpdateWarningCountMq(Long recordId) {
+        try {
+            MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), SystemConstant.WARNING_COUNT_UPDATE, System.currentTimeMillis());
+            mqDtoService.assembleSendAsyncMsg(mqDto);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        }
+    }
+
+    /**
+     * 发送mq更新考试预警未读数量
+     *
+     * @param recordId
+     * @param number
+     */
+    @Override
+    public void sendExamRecordDataUpdateWarningUnreadMq(Long recordId, Integer number) {
+        try {
+            Map<String, Object> properties = new HashMap<>();
+            properties.put(SystemConstant.NUMBER, number);
+            MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), SystemConstant.WARNING_UNREAD_UPDATE, System.currentTimeMillis());
+            mqDto.setProperties(properties);
+            mqDtoService.assembleSendAsyncMsg(mqDto);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        }
+    }
 
     /**
      * 发送mq更新考试记录
@@ -1749,7 +1751,7 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
     public List<Long> dataCount() {
         TEOrgSummary teOrgSummary = themisCacheService.addOrgSummaryCache(0L);
         if (Objects.isNull(teOrgSummary)) {
-            teOrgSummaryService.orgSummary(0L, null);
+            teOrgSummaryService.orgSummary(0L, null);//第一次进来没数据,强制统计一次
             teOrgSummary = themisCacheService.addOrgSummaryCache(0L);
         }
         List<Long> list = new ArrayList<>();

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

@@ -622,7 +622,7 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
             List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().ge(TEExamActivity::getStartTime, startTime).le(TEExamActivity::getStartTime, endTime).eq(TEExamActivity::getEnable, 1));
             //统计当天00:00:00~23:59:59可以进行的考试批次、场次、考场编码信息
             if (!CollectionUtils.isEmpty(teExamActivityList)) {
-                LinkedMultiValueMap<Long, ExamListBean> examActivityMap = new LinkedMultiValueMap<>();
+                LinkedMultiValueMap<Long, ExamListBean> todayExamListMap = new LinkedMultiValueMap<>();//考试批次、场次集合/考场编码集合
                 Map<Long, Set<Long>> examActivityIdMap = new HashMap<>();//考试批次id,场次id集合
                 Map<Long, Set<String>> roomCodeMap = new HashMap<>();//考试场次id,考场编码集合
                 for (TEExamActivity t : teExamActivityList) {
@@ -645,15 +645,13 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
                 examActivityIdMap.forEach((k, v) -> {
                     for (Long l : v) {
                         String s = StringUtils.join(roomCodeMap.get(l)).replaceAll("\\[", "").replaceAll("\\]", "");
-                        examActivityMap.add(k, new ExamListBean(l, s));
+                        todayExamListMap.add(k, new ExamListBean(l, s));
                     }
                 });
-                examActivityMap.forEach((k, v) -> {
+                todayExamListMap.forEach((k, v) -> {
                     redisUtil.set(SystemConstant.TODAY_EXAM_LIST_MAP_CACHE, k.toString(), v);
                 });
             }
-            teOrgSummaryService.orgSummary(0L, null);//统计全局机构信息
-            teRegionSummaryService.regionSummary();
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
         }
@@ -667,8 +665,8 @@ public class ThemisCacheServiceImpl implements ThemisCacheService {
         //查询考试场次结束时间大于当前时间的所有考试
         List<TEExamActivity> teExamActivityList = teExamActivityService.list(new QueryWrapper<TEExamActivity>().lambda().gt(TEExamActivity::getFinishTime, System.currentTimeMillis()).eq(TEExamActivity::getEnable, 1));
         if (!CollectionUtils.isEmpty(teExamActivityList)) {
-            Map<Long, Set<Long>> examMap = new HashMap<>();//考试批次id,场次id集合
             Map<Long, Set<Long>> orgMap = new HashMap<>();//机构id,考试批次id集合
+            Map<Long, Set<Long>> examMap = new HashMap<>();//考试批次id,场次id集合
             for (TEExamActivity t : teExamActivityList) {
                 ExamCacheBean examCacheBean = teExamService.getExamCacheBean(t.getExamId());
                 if (Objects.nonNull(examCacheBean.getEnable()) && examCacheBean.getEnable().intValue() == 1) {

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

@@ -1729,20 +1729,20 @@
 <!--            tir.province-->
 <!--    </select>-->
 
-<!--    <update id="updateWarningCount">-->
-<!--        update t_oe_exam_record set warning_count = warning_count + 1, warning_unread = warning_unread + 1 where id = #{id}-->
-<!--    </update>-->
+    <update id="updateWarningCount">
+        update t_oe_exam_record set warning_count = warning_count + 1, warning_unread = warning_unread + 1 where id = #{id}
+    </update>
 
-<!--    <update id="updateWarningUnread">-->
-<!--        update t_oe_exam_record set-->
-<!--        <choose>-->
-<!--            <when test="number != null and number != '' or number == 0">-->
-<!--                warning_unread = #{number}-->
-<!--            </when>-->
-<!--            <otherwise>-->
-<!--                warning_unread = warning_unread - #{number}-->
-<!--            </otherwise>-->
-<!--        </choose>-->
-<!--            where id = #{id}-->
-<!--    </update>-->
+    <update id="updateWarningUnread">
+        update t_oe_exam_record set
+        <choose>
+            <when test="number != null and number != '' or number == 0">
+                warning_unread = #{number}
+            </when>
+            <otherwise>
+                warning_unread = warning_unread - #{number}
+            </otherwise>
+        </choose>
+            where id = #{id}
+    </update>
 </mapper>

+ 10 - 10
themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

@@ -701,16 +701,16 @@ public class MqLogicServiceImpl implements MqLogicService {
         Long updateTime = ExamRecordCacheUtil.getUpdateTime(recordId);
         if (Objects.isNull(updateTime) || (Objects.nonNull(updateTime) &&
                 mqDto.getTimestamp().longValue() >= updateTime.longValue())) {
-//            if (Objects.nonNull(mqDto.getObjName()) && Objects.equals(mqDto.getObjName(), SystemConstant.WARNING_COUNT_UPDATE)) {
-//                examRecordService.updateWarningCount(recordId);
-//            } else if (Objects.nonNull(mqDto.getObjName()) && Objects.equals(mqDto.getObjName(), SystemConstant.WARNING_UNREAD_UPDATE)) {
-//                Map<String, Object> tranMap = mqDto.getProperties();
-//                Integer number = (Integer) tranMap.get(SystemConstant.NUMBER);
-//                number = Objects.isNull(number) || number < 0 ? 0 : number;
-//                examRecordService.updateWarningUnread(recordId, number);
-//            } else {
-            examRecordService.examRecordDataSave(recordId);
-//            }
+            if (Objects.nonNull(mqDto.getObjName()) && Objects.equals(mqDto.getObjName(), SystemConstant.WARNING_COUNT_UPDATE)) {
+                examRecordService.updateWarningCountByDb(recordId);
+            } else if (Objects.nonNull(mqDto.getObjName()) && Objects.equals(mqDto.getObjName(), SystemConstant.WARNING_UNREAD_UPDATE)) {
+                Map<String, Object> tranMap = mqDto.getProperties();
+                Integer number = (Integer) tranMap.get(SystemConstant.NUMBER);
+                number = Objects.isNull(number) || number < 0 ? 0 : number;
+                examRecordService.updateWarningUnreadByDb(recordId, number);
+            } else {
+                examRecordService.examRecordDataSave(recordId);
+            }
             tIpRegionService.saveIpRegion(recordId);
         }
         tmRocketMessageService.saveMqMessageSuccess(mqDto, key);