Browse Source

加入监考源判断

wangliang 3 năm trước cách đây
mục cha
commit
7d91e673ce

+ 49 - 4
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateCallMobileController.java

@@ -13,11 +13,13 @@ import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.AuthDto;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.MqDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.dto.response.TIeExamInvigilateCallDto;
 import com.qmth.themis.business.dto.response.TIeExamInvigilateCallDto;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.entity.*;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.*;
 import com.qmth.themis.business.util.*;
+import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.Source;
 import com.qmth.themis.common.enums.Source;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.exception.BusinessException;
@@ -158,15 +160,36 @@ public class TIeInvigilateCallMobileController {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
         }
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
-        if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
+        if (Objects.isNull(mapParameter.get(Constants.HEADER_SOURCE)) || Objects.equals(mapParameter.get(Constants.HEADER_SOURCE), "")) {
             throw new BusinessException("来源不能为空!");
             throw new BusinessException("来源不能为空!");
         }
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")));
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get(Constants.HEADER_SOURCE)));
         //获取考试记录缓存
         //获取考试记录缓存
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
         if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
             throw new BusinessException("推流状态为空");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
         Long timestamp = System.currentTimeMillis();
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.CALLING, timestamp);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.CALLING, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
@@ -194,10 +217,10 @@ public class TIeInvigilateCallMobileController {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
         }
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
-        if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
+        if (Objects.isNull(mapParameter.get(Constants.HEADER_SOURCE)) || Objects.equals(mapParameter.get(Constants.HEADER_SOURCE), "")) {
             throw new BusinessException("来源不能为空!");
             throw new BusinessException("来源不能为空!");
         }
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")));
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get(Constants.HEADER_SOURCE)));
         //获取考试记录缓存
         //获取考试记录缓存
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         ExamRecordStatusEnum statusEnum = ExamRecordCacheUtil.getStatus(recordId);
         ExamRecordStatusEnum statusEnum = ExamRecordCacheUtil.getStatus(recordId);
@@ -207,6 +230,28 @@ public class TIeInvigilateCallMobileController {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
             throw new BusinessException("推流状态为空");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
+
         Long timestamp = System.currentTimeMillis();
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);

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

@@ -19,6 +19,8 @@ import com.qmth.themis.common.exception.BusinessException;
 import java.io.File;
 import java.io.File;
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchAlgorithmException;
 import java.util.*;
 import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * @Description: 系统常量
  * @Description: 系统常量
@@ -414,24 +416,24 @@ public class SystemConstant {
         calendar.setTime(now);
         calendar.setTime(now);
         long redisExpire = REDIS_EXPIRE_TIME;
         long redisExpire = REDIS_EXPIRE_TIME;
         switch (source) {
         switch (source) {
-        case ADMIN_WEB:
-            calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.ADMIN_WEB_SESSION_EXPIRE);
-            break;
-        case ADMIN_CLIENT:
-            calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.ADMIN_CLIENT_SESSION_EXPIRE);
-            break;
-        case OE_CLIENT:
-            calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.OE_CLIENT_SESSION_EXPIRE);
-            redisExpire = REDIS_CLIENT_EXPIRE_TIME;
-            break;
-        case OE_ANSWER:
-        case MOBILE_MONITOR_FIRST:
-        case MOBILE_MONITOR_SECOND:
-            calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.MOBILE_SESSION_EXPIRE);
-            redisExpire = REDIS_PHONE_EXPIRE_TIME;
-            break;
-        default:
-            break;
+            case ADMIN_WEB:
+                calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.ADMIN_WEB_SESSION_EXPIRE);
+                break;
+            case ADMIN_CLIENT:
+                calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.ADMIN_CLIENT_SESSION_EXPIRE);
+                break;
+            case OE_CLIENT:
+                calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.OE_CLIENT_SESSION_EXPIRE);
+                redisExpire = REDIS_CLIENT_EXPIRE_TIME;
+                break;
+            case OE_ANSWER:
+            case MOBILE_MONITOR_FIRST:
+            case MOBILE_MONITOR_SECOND:
+                calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.MOBILE_SESSION_EXPIRE);
+                redisExpire = REDIS_PHONE_EXPIRE_TIME;
+                break;
+            default:
+                break;
         }
         }
         dto.setDate(calendar.getTime());
         dto.setDate(calendar.getTime());
         dto.setExpireSeconds(redisExpire);
         dto.setExpireSeconds(redisExpire);
@@ -670,4 +672,23 @@ public class SystemConstant {
         }
         }
         return tOeExamRecord;
         return tOeExamRecord;
     }
     }
+
+    /**
+     * 获取monitorRecordMap
+     *
+     * @param monitorRecord
+     * @return
+     */
+    public static Map<String, String> getMonitorRecordMap(String monitorRecord) {
+        if (Objects.nonNull(monitorRecord) && !Objects.equals(monitorRecord.trim().replaceAll(" ", ""), "")) {
+            List<String> monitorRecordList = Arrays.asList(monitorRecord.trim().toUpperCase().split(","));
+            Map<String, String> monitorRecordMap = monitorRecordList.stream()
+                    .collect(Collectors.toMap(Function.identity(), s -> s));
+            return Objects.nonNull(monitorRecordMap) && monitorRecordMap.size() > 0 ? monitorRecordMap : null;
+        } else {
+            return null;
+        }
+    }
+
+
 }
 }

+ 75 - 7
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallMobileController.java

@@ -5,11 +5,15 @@ import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.MqDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.TIeExamInvigilateCallLog;
 import com.qmth.themis.business.entity.TIeExamInvigilateCallLog;
+import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.util.MqUtil;
 import com.qmth.themis.business.util.MqUtil;
+import com.qmth.themis.business.util.ServletUtil;
+import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.Result;
@@ -120,10 +124,10 @@ public class TIeInvigilateCallMobileController {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
         }
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
-        if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
+        if (Objects.isNull(mapParameter.get(Constants.HEADER_SOURCE)) || Objects.equals(mapParameter.get(Constants.HEADER_SOURCE), "")) {
             throw new BusinessException("来源不能为空!");
             throw new BusinessException("来源不能为空!");
         }
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")));
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get(Constants.HEADER_SOURCE)));
         //获取考试记录缓存
         //获取考试记录缓存
         if (Objects.isNull(source) || Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
         if (Objects.isNull(source) || Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
             throw new BusinessException("推流状态为空");
@@ -132,6 +136,28 @@ public class TIeInvigilateCallMobileController {
         if (!Objects.equals(status, MonitorStatusSourceEnum.START)) {
         if (!Objects.equals(status, MonitorStatusSourceEnum.START)) {
             throw new BusinessException("推流状态不正常");
             throw new BusinessException("推流状态不正常");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
+
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         Long timestamp = System.currentTimeMillis();
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.START, timestamp);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.START, timestamp);
@@ -160,10 +186,10 @@ public class TIeInvigilateCallMobileController {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
         }
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
-        if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
+        if (Objects.isNull(mapParameter.get(Constants.HEADER_SOURCE)) || Objects.equals(mapParameter.get(Constants.HEADER_SOURCE), "")) {
             throw new BusinessException("监考视频源不能为空");
             throw new BusinessException("监考视频源不能为空");
         }
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")).toUpperCase());
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get(Constants.HEADER_SOURCE)).toUpperCase());
         if (Objects.isNull(mapParameter.get(SystemConstant.STATUS)) || Objects.equals(mapParameter.get(SystemConstant.STATUS), "")) {
         if (Objects.isNull(mapParameter.get(SystemConstant.STATUS)) || Objects.equals(mapParameter.get(SystemConstant.STATUS), "")) {
             throw new BusinessException("监考视频状态不能为空");
             throw new BusinessException("监考视频状态不能为空");
         }
         }
@@ -171,6 +197,27 @@ public class TIeInvigilateCallMobileController {
         if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get(SystemConstant.TYPE)) || Objects.equals(mapParameter.get(SystemConstant.TYPE), ""))) {
         if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get(SystemConstant.TYPE)) || Objects.equals(mapParameter.get(SystemConstant.TYPE), ""))) {
             throw new BusinessException("异常类型不能为空");
             throw new BusinessException("异常类型不能为空");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
         //获取考试记录缓存
         //获取考试记录缓存
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         MonitorCallStatusSourceEnum callStatus = Objects.nonNull(ExamRecordCacheUtil.getMonitorCallStatus(recordId, source)) ? ExamRecordCacheUtil.getMonitorCallStatus(recordId, source) : null;
         MonitorCallStatusSourceEnum callStatus = Objects.nonNull(ExamRecordCacheUtil.getMonitorCallStatus(recordId, source)) ? ExamRecordCacheUtil.getMonitorCallStatus(recordId, source) : null;
@@ -191,7 +238,7 @@ public class TIeInvigilateCallMobileController {
 
 
         Map mqMap = new HashMap<>();
         Map mqMap = new HashMap<>();
         mqMap.put(SystemConstant.RECORD_ID, recordId);
         mqMap.put(SystemConstant.RECORD_ID, recordId);
-        mqMap.put("source", source.name());
+        mqMap.put(Constants.HEADER_SOURCE, source.name());
         if (Objects.equals(status.name(), MonitorStatusSourceEnum.START.name())) {
         if (Objects.equals(status.name(), MonitorStatusSourceEnum.START.name())) {
             //监控开始
             //监控开始
             MqDto mqDtoStart = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.MONITOR_START.name(), recordId, MqTagEnum.MONITOR_START, String.valueOf(recordId), mqMap, String.valueOf(recordId));
             MqDto mqDtoStart = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.MONITOR_START.name(), recordId, MqTagEnum.MONITOR_START, String.valueOf(recordId), mqMap, String.valueOf(recordId));
@@ -219,10 +266,10 @@ public class TIeInvigilateCallMobileController {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
         }
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
-        if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
+        if (Objects.isNull(mapParameter.get(Constants.HEADER_SOURCE)) || Objects.equals(mapParameter.get(Constants.HEADER_SOURCE), "")) {
             throw new BusinessException("来源不能为空!");
             throw new BusinessException("来源不能为空!");
         }
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")));
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get(Constants.HEADER_SOURCE)));
         //获取考试记录缓存
         //获取考试记录缓存
         ExamRecordStatusEnum statusEnum = ExamRecordCacheUtil.getStatus(recordId);
         ExamRecordStatusEnum statusEnum = ExamRecordCacheUtil.getStatus(recordId);
         if (Objects.isNull(statusEnum) || Objects.equals(statusEnum, ExamRecordStatusEnum.FINISHED) || Objects.equals(statusEnum, ExamRecordStatusEnum.PERSISTED)) {
         if (Objects.isNull(statusEnum) || Objects.equals(statusEnum, ExamRecordStatusEnum.FINISHED) || Objects.equals(statusEnum, ExamRecordStatusEnum.PERSISTED)) {
@@ -230,6 +277,27 @@ public class TIeInvigilateCallMobileController {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
             throw new BusinessException("推流状态为空");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         Long timestamp = System.currentTimeMillis();
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);

+ 75 - 6
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallOeController.java

@@ -5,11 +5,15 @@ import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.MqDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.TIeExamInvigilateCallLog;
 import com.qmth.themis.business.entity.TIeExamInvigilateCallLog;
+import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.util.MqUtil;
 import com.qmth.themis.business.util.MqUtil;
+import com.qmth.themis.business.util.ServletUtil;
+import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.Result;
@@ -25,10 +29,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * @Description: mobile监考监控通话信息 前端控制器
  * @Description: mobile监考监控通话信息 前端控制器
@@ -121,10 +124,10 @@ public class TIeInvigilateCallOeController {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
         }
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
         Long recordId = Long.parseLong(String.valueOf(mapParameter.get(SystemConstant.RECORD_ID)));
-        if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
+        if (Objects.isNull(mapParameter.get(Constants.HEADER_SOURCE)) || Objects.equals(mapParameter.get(Constants.HEADER_SOURCE), "")) {
             throw new BusinessException("监考视频源不能为空");
             throw new BusinessException("监考视频源不能为空");
         }
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")).toUpperCase());
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get(Constants.HEADER_SOURCE)).toUpperCase());
         if (Objects.isNull(mapParameter.get(SystemConstant.STATUS)) || Objects.equals(mapParameter.get(SystemConstant.STATUS), "")) {
         if (Objects.isNull(mapParameter.get(SystemConstant.STATUS)) || Objects.equals(mapParameter.get(SystemConstant.STATUS), "")) {
             throw new BusinessException("监考视频状态不能为空");
             throw new BusinessException("监考视频状态不能为空");
         }
         }
@@ -132,6 +135,28 @@ public class TIeInvigilateCallOeController {
         if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get(SystemConstant.TYPE)) || Objects.equals(mapParameter.get(SystemConstant.TYPE), ""))) {
         if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get(SystemConstant.TYPE)) || Objects.equals(mapParameter.get(SystemConstant.TYPE), ""))) {
             throw new BusinessException("异常类型不能为空");
             throw new BusinessException("异常类型不能为空");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
+
         //获取考试记录缓存
         //获取考试记录缓存
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         String liveUrl = SystemConstant.setStreamId(dictionaryConfig.monitorDomain().getPrefix(), recordId, source);
         MonitorCallStatusSourceEnum callStatus = Objects.nonNull(ExamRecordCacheUtil.getMonitorCallStatus(recordId, source)) ? ExamRecordCacheUtil.getMonitorCallStatus(recordId, source) : null;
         MonitorCallStatusSourceEnum callStatus = Objects.nonNull(ExamRecordCacheUtil.getMonitorCallStatus(recordId, source)) ? ExamRecordCacheUtil.getMonitorCallStatus(recordId, source) : null;
@@ -176,6 +201,28 @@ public class TIeInvigilateCallOeController {
         if (!Objects.equals(status, MonitorStatusSourceEnum.START)) {
         if (!Objects.equals(status, MonitorStatusSourceEnum.START)) {
             throw new BusinessException("推流状态不正常");
             throw new BusinessException("推流状态不正常");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
+
         Long timestamp = System.currentTimeMillis();
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.START, timestamp);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.START, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
         tOeExamRecordService.sendExamRecordDataSaveMq(recordId, timestamp);
@@ -209,6 +256,28 @@ public class TIeInvigilateCallOeController {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
             throw new BusinessException("推流状态为空");
         }
         }
+        //2022/04/21加入校验
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        if (Objects.nonNull(teStudentCacheDto) && Objects.nonNull(teStudentCacheDto.getExamingRecordId())
+                && teStudentCacheDto.getExamingRecordId().longValue() == recordId.longValue()) {
+            String monitorRecord = ExamRecordCacheUtil.getMonitorRecord(recordId);
+            if (Objects.isNull(monitorRecord)) {
+                TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
+                monitorRecord = tOeExamRecord.getMonitorRecord();
+            }
+            Map<String, String> monitorRecordMap = SystemConstant.getMonitorRecordMap(monitorRecord);
+            if (Objects.isNull(monitorRecordMap)) {
+                return ResultUtil.ok();
+            } else {
+                String monitorRecordStr = monitorRecordMap.get(source.name());
+                if (Objects.isNull(monitorRecordStr)) {
+                    return ResultUtil.ok();
+                }
+            }
+        } else {
+            return ResultUtil.ok();
+        }
+
         MonitorStatusSourceEnum status = ExamRecordCacheUtil.getMonitorStatus(recordId, source);
         MonitorStatusSourceEnum status = ExamRecordCacheUtil.getMonitorStatus(recordId, source);
         Long timestamp = System.currentTimeMillis();
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP, timestamp);

+ 3 - 2
themis-exam/src/main/java/com/qmth/themis/exam/listener/service/impl/MqOeLogicServiceImpl.java

@@ -14,6 +14,7 @@ import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.business.util.JacksonUtil;
+import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.exam.listener.service.MqOeLogicService;
 import com.qmth.themis.exam.listener.service.MqOeLogicService;
 import com.qmth.themis.exam.websocket.WebSocketMobileServer;
 import com.qmth.themis.exam.websocket.WebSocketMobileServer;
@@ -312,7 +313,7 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                             }
                             }
                             break;
                             break;
                         case "MONITOR_START":
                         case "MONITOR_START":
-                            MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf((String) prop.get("source"));
+                            MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf((String) prop.get(Constants.HEADER_SOURCE));
                             MonitorStatusBean monitorStatusBean = ExamRecordCacheUtil.getMonitorStatusBean(recordId, source);
                             MonitorStatusBean monitorStatusBean = ExamRecordCacheUtil.getMonitorStatusBean(recordId, source);
                             if (Objects.nonNull(monitorStatusBean)
                             if (Objects.nonNull(monitorStatusBean)
                                     && Objects.nonNull(monitorStatusBean.getTimestamp())
                                     && Objects.nonNull(monitorStatusBean.getTimestamp())
@@ -322,7 +323,7 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                             }
                             }
                             break;
                             break;
                         case "MONITOR_STOP":
                         case "MONITOR_STOP":
-                            source = MonitorVideoSourceEnum.valueOf((String) prop.get("source"));
+                            source = MonitorVideoSourceEnum.valueOf((String) prop.get(Constants.HEADER_SOURCE));
                             monitorStatusBean = ExamRecordCacheUtil.getMonitorStatusBean(recordId, source);
                             monitorStatusBean = ExamRecordCacheUtil.getMonitorStatusBean(recordId, source);
                             if (Objects.nonNull(monitorStatusBean)
                             if (Objects.nonNull(monitorStatusBean)
                                     && Objects.nonNull(monitorStatusBean.getTimestamp())
                                     && Objects.nonNull(monitorStatusBean.getTimestamp())

+ 1 - 1
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketMobileServer.java

@@ -141,7 +141,7 @@ public class WebSocketMobileServer implements Concurrently {
                     MqDtoService mqDtoService = SpringContextHolder.getBean(MqDtoService.class);
                     MqDtoService mqDtoService = SpringContextHolder.getBean(MqDtoService.class);
                     Map mqMap = new HashMap<>();
                     Map mqMap = new HashMap<>();
                     mqMap.put(SystemConstant.RECORD_ID, this.recordId);
                     mqMap.put(SystemConstant.RECORD_ID, this.recordId);
-                    mqMap.put("source", this.source.name());
+                    mqMap.put(Constants.HEADER_SOURCE, this.source.name());
                     //监控结束
                     //监控结束
                     MqDto mqDtoStop = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.MONITOR_STOP.name(),
                     MqDto mqDtoStop = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.MONITOR_STOP.name(),
                             recordId, MqTagEnum.MONITOR_STOP, String.valueOf(recordId), mqMap,
                             recordId, MqTagEnum.MONITOR_STOP, String.valueOf(recordId), mqMap,

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

@@ -712,11 +712,12 @@ public class MqLogicServiceImpl implements MqLogicService {
                     .readJson(JacksonUtil.parseJson(mqDto.getBody()), TIeExamInvigilateCallLog.class);
                     .readJson(JacksonUtil.parseJson(mqDto.getBody()), TIeExamInvigilateCallLog.class);
             Long recordId = tIeExamInvigilateCallLog.getExamRecordId();
             Long recordId = tIeExamInvigilateCallLog.getExamRecordId();
             Long examId = null, examActivityId = null, examStudentId = null;
             Long examId = null, examActivityId = null, examStudentId = null;
+            //有缓存则从缓存取
             if (Objects.nonNull(ExamRecordCacheUtil.getExamActivityId(recordId))) {
             if (Objects.nonNull(ExamRecordCacheUtil.getExamActivityId(recordId))) {
                 examActivityId = ExamRecordCacheUtil.getExamActivityId(recordId);
                 examActivityId = ExamRecordCacheUtil.getExamActivityId(recordId);
                 examId = ExamRecordCacheUtil.getExamId(recordId);
                 examId = ExamRecordCacheUtil.getExamId(recordId);
                 examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
                 examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
-            } else {
+            } else {//否则数据库取
                 TOeExamRecord tOeExamRecord = examRecordService.getById(tIeExamInvigilateCallLog.getExamRecordId());
                 TOeExamRecord tOeExamRecord = examRecordService.getById(tIeExamInvigilateCallLog.getExamRecordId());
                 examActivityId = tOeExamRecord.getExamActivityId();
                 examActivityId = tOeExamRecord.getExamActivityId();
                 examId = tOeExamRecord.getExamId();
                 examId = tOeExamRecord.getExamId();
@@ -732,11 +733,12 @@ public class MqLogicServiceImpl implements MqLogicService {
                     .eq(TIeExamInvigilateCall::getSource, tIeExamInvigilateCallLog.getSource());
                     .eq(TIeExamInvigilateCall::getSource, tIeExamInvigilateCallLog.getSource());
             TIeExamInvigilateCall tIeExamInvigilateCall = tIeExamInvigilateCallService
             TIeExamInvigilateCall tIeExamInvigilateCall = tIeExamInvigilateCallService
                     .getOne(tIeExamInvigilateCallQueryWrapper);
                     .getOne(tIeExamInvigilateCallQueryWrapper);
-            if (Objects.isNull(tIeExamInvigilateCall)) {
+            //根据examRecordId和source取TIeExamInvigilateCall记录
+            if (Objects.isNull(tIeExamInvigilateCall)) {//没有新增
                 tIeExamInvigilateCall = gson
                 tIeExamInvigilateCall = gson
                         .fromJson(gson.toJson(tIeExamInvigilateCallLog), TIeExamInvigilateCall.class);
                         .fromJson(gson.toJson(tIeExamInvigilateCallLog), TIeExamInvigilateCall.class);
                 tIeExamInvigilateCall.setId(uidUtil.getId());
                 tIeExamInvigilateCall.setId(uidUtil.getId());
-            } else {
+            } else {//否则更新
                 tIeExamInvigilateCall.setLiveUrl(tIeExamInvigilateCallLog.getLiveUrl());
                 tIeExamInvigilateCall.setLiveUrl(tIeExamInvigilateCallLog.getLiveUrl());
                 tIeExamInvigilateCall.setStatus(tIeExamInvigilateCallLog.getStatus());
                 tIeExamInvigilateCall.setStatus(tIeExamInvigilateCallLog.getStatus());
                 tIeExamInvigilateCall.setCallStatus(tIeExamInvigilateCallLog.getCallStatus());
                 tIeExamInvigilateCall.setCallStatus(tIeExamInvigilateCallLog.getCallStatus());
@@ -752,10 +754,11 @@ public class MqLogicServiceImpl implements MqLogicService {
                 Long dbtimestamp = Objects.nonNull(tIeExamInvigilateCall.getUpdateTime()) ?
                 Long dbtimestamp = Objects.nonNull(tIeExamInvigilateCall.getUpdateTime()) ?
                         tIeExamInvigilateCall.getUpdateTime() :
                         tIeExamInvigilateCall.getUpdateTime() :
                         0L;
                         0L;
+                //如果mq时间大于则更新
                 if (mqDto.getTimestamp() > dbtimestamp) {
                 if (mqDto.getTimestamp() > dbtimestamp) {
                     tIeExamInvigilateCallService.updateById(tIeExamInvigilateCall);
                     tIeExamInvigilateCallService.updateById(tIeExamInvigilateCall);
                 }
                 }
-            } else {
+            } else {//否则新增
                 tIeExamInvigilateCallService.saveOrUpdate(tIeExamInvigilateCall);
                 tIeExamInvigilateCallService.saveOrUpdate(tIeExamInvigilateCall);
             }
             }
             tIeExamInvigilateCallLogService.saveOrUpdate(tIeExamInvigilateCallLog);
             tIeExamInvigilateCallLogService.saveOrUpdate(tIeExamInvigilateCallLog);