Bladeren bron

新加入考试语音消息修改

wangliang 2 jaren geleden
bovenliggende
commit
5710d2d4b2

+ 25 - 115
themis-exam/src/main/java/com/qmth/themis/exam/listener/service/impl/MqOeLogicServiceImpl.java

@@ -1,20 +1,22 @@
 package com.qmth.themis.exam.listener.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.qmth.themis.business.bean.status.MonitorStatusBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
-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.MqDto;
 import com.qmth.themis.business.dto.WebsocketDto;
-import com.qmth.themis.business.entity.*;
+import com.qmth.themis.business.entity.TEExamStudent;
+import com.qmth.themis.business.entity.TEExamStudentLog;
+import com.qmth.themis.business.entity.TIeExamInvigilateNotice;
+import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.*;
-import com.qmth.themis.business.service.*;
+import com.qmth.themis.business.service.TEExamStudentLogService;
+import com.qmth.themis.business.service.TEExamStudentService;
+import com.qmth.themis.business.service.TIeExamInvigilateNoticeService;
+import com.qmth.themis.business.service.TMRocketMessageService;
 import com.qmth.themis.business.util.JacksonUtil;
-import com.qmth.themis.business.util.OssUtil;
 import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.exam.listener.service.MqOeLogicService;
@@ -24,10 +26,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
-import java.io.File;
 import java.io.IOException;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
@@ -56,21 +56,6 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
     @Resource
     TIeExamInvigilateNoticeService tIeExamInvigilateNoticeService;
 
-    @Resource
-    TEExamActivityService teExamActivityService;
-
-    @Resource
-    TEExamService teExamService;
-
-    @Resource
-    CacheService cacheService;
-
-    @Resource
-    TOeExamRecordService tOeExamRecordService;
-
-    @Resource
-    OssUtil ossUtil;
-
     /**
      * 强制离线交卷持久化逻辑
      *
@@ -404,108 +389,19 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
         if (Objects.equals(MqTagEnum.EXAM_STOP.name(), tag)//考试退出
                 || Objects.equals(MqTagEnum.EXAM_START.name(), tag)//考试开始
                 || Objects.equals(MqTagEnum.EXAM_AUDIO_MOBILE.name(), tag)) {//考试语音
-            if (Objects.equals(MqTagEnum.EXAM_STOP.name(), tag) || Objects.equals(MqTagEnum.EXAM_START.name(), tag)) {
-                examStartAndStopLogic(mqDto, key);
-            } else if (Objects.equals(MqTagEnum.EXAM_AUDIO_MOBILE.name(), tag)) {
-                Map<String, Object> properties = mqDto.getProperties();
-                if (!CollectionUtils.isEmpty(properties) && Objects.nonNull(properties.get(SystemConstant.CONTENT))) {
-                    List<String> list = (List<String>) properties.get(SystemConstant.CONTENT);
-                    Long teAudioId = Long.parseLong(list.get(0));
-                    Long examActivityId = Long.parseLong(list.get(1));
-                    Long examId = Long.parseLong(list.get(2));
-                    Long execTime = Long.parseLong(list.get(3));
-                    if (Objects.nonNull(teAudioId)) {
-                        List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.findExamRecordByExamIdAndExamActivityId(examId, examActivityId);
-                        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
-                            ConcurrentHashMap<String, WebSocketMobileServer> webSocketMap = WebSocketMobileServer.getWebSocketMap();
-                            for (TOeExamRecord t : tOeExamRecordList) {
-                                ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
-                                ExamActivityCacheBean examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(examActivityId);
-                                TEAudio teAudio = cacheService.examAudioCache(teAudioId);
-                                if (Objects.nonNull(examCacheBean) && Objects.nonNull(examActivityCacheBean) && Objects.nonNull(teAudio)
-                                        && Objects.nonNull(examCacheBean.getForceFinish()) && examCacheBean.getForceFinish().intValue() == 1
-                                        && Objects.nonNull(examCacheBean.getEnable()) && examCacheBean.getEnable() == 1
-                                        && Objects.nonNull(examActivityCacheBean.getEnable()) && examActivityCacheBean.getEnable() == 1
-                                        && Objects.nonNull(teAudio.getEnable()) && teAudio.getEnable()
-                                        && Objects.nonNull(t.getMonitorRecord())
-                                        && (t.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_FIRST.name())
-                                        || t.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
-                                    ExamRecordStatusEnum examRecordStatusEnum = ExamRecordCacheUtil.getStatus(t.getId());
-                                    examRecordStatusEnum = Objects.isNull(examRecordStatusEnum) ? t.getStatus() : examRecordStatusEnum;
-
-                                    if (Objects.nonNull(t.getMonitorRecord()) && t.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_FIRST.name())) {
-                                        //第一机位
-                                        String mobileFirstWebsocketId = ExamRecordCacheUtil.getMobileFirstWebsocketId(t.getId());
-                                        mobileFirstWebsocketId = Objects.isNull(mobileFirstWebsocketId) ? t.getMobileFirstWebsocketId() : mobileFirstWebsocketId;
-                                        if (Objects.nonNull(mobileFirstWebsocketId) && Objects.nonNull(webSocketMap.get(mobileFirstWebsocketId))) {
-                                            WebSocketMobileServer webSocketFirstMobileServer = webSocketMap.get(mobileFirstWebsocketId);
-                                            if (Objects.nonNull(examRecordStatusEnum)
-                                                    && Objects.nonNull(webSocketFirstMobileServer.getRecordId())
-                                                    && webSocketFirstMobileServer.getRecordId().longValue() == t.getId().longValue()) {
-                                                if (!Objects.equals(ExamRecordStatusEnum.PERSISTED, examRecordStatusEnum)
-                                                        && !Objects.equals(ExamRecordStatusEnum.FINISHED, examRecordStatusEnum)) {
-                                                    Map<String, Object> map = new HashMap<>();
-                                                    map.put(SystemConstant.RECORD_ID, t.getId());
-                                                    map.put(SystemConstant.EXEC_TIME, execTime);
-                                                    TBAttachment tbAttachment = cacheService.attachmentCache(teAudio.getAttachmentId());
-                                                    if (Objects.nonNull(tbAttachment) && Objects.nonNull(tbAttachment.getRemark())) {
-                                                        JSONObject jsonObject = JSONObject.parseObject(tbAttachment.getRemark());
-                                                        map.put(SystemConstant.PATH, ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + jsonObject.getString(SystemConstant.PATH));
-                                                        map.put(SystemConstant.NAME, tbAttachment.getName() + tbAttachment.getType());
-                                                    }
-                                                    WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_AUDIO.name(), map);
-                                                    webSocketFirstMobileServer.sendMessage(websocketDto);
-                                                }
-                                            }
-                                        }
-                                    }
-
-                                    if (Objects.nonNull(t.getMonitorRecord()) && t.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_SECOND.name())) {
-                                        //第二机位
-                                        String mobileSecondWebsocketId = ExamRecordCacheUtil.getMobileSecondWebsocketId(t.getId());
-                                        mobileSecondWebsocketId = Objects.isNull(mobileSecondWebsocketId) ? t.getMobileSecondWebsocketId() : mobileSecondWebsocketId;
-                                        if (Objects.nonNull(mobileSecondWebsocketId) && Objects.nonNull(webSocketMap.get(mobileSecondWebsocketId))) {
-                                            WebSocketMobileServer webSocketSecondMobileServer = webSocketMap.get(mobileSecondWebsocketId);
-                                            if (Objects.nonNull(examRecordStatusEnum)
-                                                    && Objects.nonNull(webSocketSecondMobileServer.getRecordId())
-                                                    && webSocketSecondMobileServer.getRecordId().longValue() == t.getId().longValue()) {
-                                                if (!Objects.equals(ExamRecordStatusEnum.PERSISTED, examRecordStatusEnum)
-                                                        && !Objects.equals(ExamRecordStatusEnum.FINISHED, examRecordStatusEnum)) {
-                                                    Map<String, Object> map = new HashMap<>();
-                                                    map.put(SystemConstant.RECORD_ID, t.getId());
-                                                    map.put(SystemConstant.EXEC_TIME, execTime);
-                                                    TBAttachment tbAttachment = cacheService.attachmentCache(teAudio.getAttachmentId());
-                                                    if (Objects.nonNull(tbAttachment) && Objects.nonNull(tbAttachment.getRemark())) {
-                                                        JSONObject jsonObject = JSONObject.parseObject(tbAttachment.getRemark());
-                                                        map.put(SystemConstant.PATH, ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + jsonObject.getString(SystemConstant.PATH));
-                                                        map.put(SystemConstant.NAME, tbAttachment.getName() + tbAttachment.getType());
-                                                    }
-                                                    WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_AUDIO.name(), map);
-                                                    webSocketSecondMobileServer.sendMessage(websocketDto);
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-                tmRocketMessageService.saveMqMessageSuccess(mqDto, key);
-            }
+            examStartAndStopAndAudioLogic(mqDto, key);
         }
     }
 
-
     /**
-     * 考试开始和停止逻辑
+     * 考试开始和停止和语音逻辑
      *
      * @param mqDto
      * @param key
      * @throws NoSuchAlgorithmException
      * @throws IOException
      */
-    public void examStartAndStopLogic(MqDto mqDto, String key) throws NoSuchAlgorithmException, IOException {
+    public void examStartAndStopAndAudioLogic(MqDto mqDto, String key) throws NoSuchAlgorithmException, IOException {
         ConcurrentHashMap<String, WebSocketMobileServer> webSocketMap = WebSocketMobileServer.getWebSocketMap();
         String tag = mqDto.getTag();
         Long recordId = Long.parseLong(String.valueOf(mqDto.getBody()));
@@ -560,6 +456,13 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                             webSocketFirstMobileServer.sendMessage(websocketDto);
                         }
                         break;
+                    case "EXAM_AUDIO_MOBILE":
+                        if (!Objects.equals(ExamRecordStatusEnum.PERSISTED, examRecordStatusEnum)
+                                && !Objects.equals(ExamRecordStatusEnum.FINISHED, examRecordStatusEnum)) {
+                            websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_AUDIO.name(), mqDto.getProperties());
+                            webSocketFirstMobileServer.sendMessage(websocketDto);
+                        }
+                        break;
                     default:
                         break;
                 }
@@ -599,6 +502,13 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                             webSocketSecondMobileServer.sendMessage(websocketDto);
                         }
                         break;
+                    case "EXAM_AUDIO_MOBILE":
+                        if (!Objects.equals(ExamRecordStatusEnum.PERSISTED, examRecordStatusEnum)
+                                && !Objects.equals(ExamRecordStatusEnum.FINISHED, examRecordStatusEnum)) {
+                            websocketDto = new WebsocketDto(WebsocketTypeEnum.EXAM_AUDIO.name(), mqDto.getProperties());
+                            webSocketSecondMobileServer.sendMessage(websocketDto);
+                        }
+                        break;
                     default:
                         break;
                 }

+ 50 - 5
themis-task/src/main/java/com/qmth/themis/task/quartz/service/impl/QuartzLogicServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.themis.task.quartz.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.bean.ExamActivityCacheBean;
@@ -7,12 +8,16 @@ 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.MqDto;
+import com.qmth.themis.business.entity.TBAttachment;
+import com.qmth.themis.business.entity.TEAudio;
 import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.ExamRecordStatusEnum;
 import com.qmth.themis.business.enums.FinishTypeEnum;
+import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
 import com.qmth.themis.business.enums.MqTagEnum;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.MqUtil;
+import com.qmth.themis.business.util.OssUtil;
 import com.qmth.themis.task.quartz.service.QuartzLogicService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -21,7 +26,11 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
-import java.util.*;
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 /**
  * @Description: quartz逻辑 impl
@@ -55,6 +64,12 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
     @Resource
     MqDtoService mqDtoService;
 
+    @Resource
+    CacheService cacheService;
+
+    @Resource
+    OssUtil ossUtil;
+
     /**
      * 考试场次quartz逻辑
      *
@@ -173,9 +188,39 @@ public class QuartzLogicServiceImpl implements QuartzLogicService {
         log.info("execExamAudioJobLogic key:{}", key);
         String[] strings = key.split("\\.");
         String[] exams = strings[1].split("-");
-        Map<String, Object> mapParameter = new HashMap<>();
-        mapParameter.put(SystemConstant.CONTENT, Arrays.asList(exams));
-        MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.EXAM_AUDIO_MOBILE.name(), Long.parseLong(exams[2]), MqTagEnum.EXAM_AUDIO_MOBILE, exams[2], mapParameter, exams[2]);
-        mqDtoService.assembleSendOneOrderMsg(mqDto);
+        Long teAudioId = Long.parseLong(exams[0]);
+        Long examActivityId = Long.parseLong(exams[1]);
+        Long examId = Long.parseLong(exams[2]);
+        Long execTime = Long.parseLong(exams[3]);
+        if (Objects.nonNull(teAudioId)) {
+            List<TOeExamRecord> tOeExamRecordList = tOeExamRecordService.findExamRecordByExamIdAndExamActivityId(examId, examActivityId);
+            if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
+                for (TOeExamRecord t : tOeExamRecordList) {
+                    ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examId);
+                    ExamActivityCacheBean examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(examActivityId);
+                    TEAudio teAudio = cacheService.examAudioCache(teAudioId);
+                    if (Objects.nonNull(examCacheBean) && Objects.nonNull(examActivityCacheBean) && Objects.nonNull(teAudio)
+                            && Objects.nonNull(examCacheBean.getForceFinish()) && examCacheBean.getForceFinish().intValue() == 1
+                            && Objects.nonNull(examCacheBean.getEnable()) && examCacheBean.getEnable() == 1
+                            && Objects.nonNull(examActivityCacheBean.getEnable()) && examActivityCacheBean.getEnable() == 1
+                            && Objects.nonNull(teAudio.getEnable()) && teAudio.getEnable()
+                            && Objects.nonNull(t.getMonitorRecord())
+                            && (t.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_FIRST.name())
+                            || t.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
+                        Map<String, Object> mapParameter = new HashMap<>();
+                        mapParameter.put(SystemConstant.RECORD_ID, t.getId());
+                        mapParameter.put(SystemConstant.EXEC_TIME, execTime);
+                        TBAttachment tbAttachment = cacheService.attachmentCache(teAudio.getAttachmentId());
+                        if (Objects.nonNull(tbAttachment) && Objects.nonNull(tbAttachment.getRemark())) {
+                            JSONObject jsonObject = JSONObject.parseObject(tbAttachment.getRemark());
+                            mapParameter.put(SystemConstant.PATH, ossUtil.getAliYunOssPublicDomain().getPublicUrl() + File.separator + jsonObject.getString(SystemConstant.PATH));
+                            mapParameter.put(SystemConstant.NAME, tbAttachment.getName() + tbAttachment.getType());
+                        }
+                        MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.EXAM_AUDIO_MOBILE.name(), t.getId(), MqTagEnum.EXAM_AUDIO_MOBILE, exams[2], mapParameter, exams[2]);
+                        mqDtoService.assembleSendOneOrderMsg(mqDto);
+                    }
+                }
+            }
+        }
     }
 }