Browse Source

Merge remote-tracking branch 'origin/master'

wangliang 4 years ago
parent
commit
956824c8ab

+ 51 - 34
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallMobileController.java

@@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
 @RestController
 @RequestMapping("/${prefix.url.mobile}/monitor")
 public class TIeInvigilateCallMobileController {
+
     private final static Logger log = LoggerFactory.getLogger(TIeInvigilateCallMobileController.class);
 
     @Resource
@@ -50,13 +51,12 @@ public class TIeInvigilateCallMobileController {
 
     @ApiOperation(value = "监控观看地址更新接口")
     @RequestMapping(value = "/live_url", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
+    @ApiResponses({ @ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class) })
     @Transactional
     public Result liveUrl(@ApiJsonObject(name = "liveUrlMobile", value = {
             @ApiJsonProperty(key = "recordId", type = "long", example = "1", description = "考试记录id", required = true),
             @ApiJsonProperty(key = "source", description = "监考视频源", required = true),
-            @ApiJsonProperty(key = "liveUrl", description = "观看地址", required = true)
-    }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
+            @ApiJsonProperty(key = "liveUrl", description = "观看地址", required = true) }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
         if (Objects.isNull(mapParameter.get("recordId")) || Objects.equals(mapParameter.get("recordId"), "")) {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
@@ -66,7 +66,8 @@ public class TIeInvigilateCallMobileController {
             if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
                 throw new BusinessException("监考视频源不能为空");
             }
-            MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")).toUpperCase());
+            MonitorVideoSourceEnum source = MonitorVideoSourceEnum
+                    .valueOf(String.valueOf(mapParameter.get("source")).toUpperCase());
             if (Objects.isNull(mapParameter.get("liveUrl")) || Objects.equals(mapParameter.get("liveUrl"), "")) {
                 throw new BusinessException("观看地址不能为空");
             }
@@ -76,20 +77,25 @@ public class TIeInvigilateCallMobileController {
             }
             String liveUrl = String.valueOf(mapParameter.get("liveUrl"));
             String monitorKey = ExamRecordCacheUtil.getMonitorKey(recordId);
-            TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl, MonitorStatusSourceEnum.INIT, monitorKey);
+            TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl,
+                    MonitorStatusSourceEnum.INIT, monitorKey);
             //获取考试记录缓存
             ExamRecordCacheUtil.setMonitorLiveUrl(recordId, source, liveUrl, true);
 
             //监考监控通话信息 发送mq start
-            MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(), tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()), source.name());
+            MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(),
+                    tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()),
+                    source.name());
             mqDtoService.assembleSendOneWayMsg(mqDto);
             //监考监控通话信息 发送mq end
         } catch (Exception e) {
             log.error("请求出错", e);
             if (e instanceof DuplicateKeyException) {
                 String errorColumn = e.getCause().toString();
-                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
-                throw new BusinessException("考试记录id[" + recordId + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
+                String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length())
+                        .replaceAll("'", "");
+                throw new BusinessException(
+                        "考试记录id[" + recordId + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
             } else if (e instanceof BusinessException) {
                 throw new BusinessException(e.getMessage());
             } else {
@@ -101,12 +107,11 @@ public class TIeInvigilateCallMobileController {
 
     @ApiOperation(value = "发送通话申请接口")
     @RequestMapping(value = "/call/apply", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
+    @ApiResponses({ @ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class) })
     @Transactional
     public Result callApply(@ApiJsonObject(name = "callApplyMobile", value = {
             @ApiJsonProperty(key = "recordId", type = "long", example = "1", description = "考试记录id", required = true),
-            @ApiJsonProperty(key = "source", description = "监考视频源", required = true)
-    }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
+            @ApiJsonProperty(key = "source", description = "监考视频源", required = true) }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
         if (Objects.isNull(mapParameter.get("recordId")) || Objects.equals(mapParameter.get("recordId"), "")) {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
@@ -126,10 +131,13 @@ public class TIeInvigilateCallMobileController {
         }
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.START);
         String monitorKey = ExamRecordCacheUtil.getMonitorKey(recordId);
-        TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl, status, monitorKey, MonitorCallStatusSourceEnum.START);
+        TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl,
+                status, monitorKey, MonitorCallStatusSourceEnum.START);
         tIeExamInvigilateCallLog.setStartTime(System.currentTimeMillis());
         //监考监控通话信息 发送mq start
-        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(), tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()), source.name());
+        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(),
+                tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()),
+                source.name());
         mqDtoService.assembleSendOneWayMsg(mqDto);
         //监考监控通话信息 发送mq end
         return ResultUtil.ok(Collections.singletonMap("updateTime", System.currentTimeMillis()));
@@ -137,14 +145,13 @@ public class TIeInvigilateCallMobileController {
 
     @ApiOperation(value = "监控状态更新接口")
     @RequestMapping(value = "/status", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
+    @ApiResponses({ @ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class) })
     @Transactional
     public Result status(@ApiJsonObject(name = "statusMobile", value = {
             @ApiJsonProperty(key = "recordId", type = "long", example = "1", description = "考试记录id", required = true),
             @ApiJsonProperty(key = "source", description = "监考视频源", required = true),
             @ApiJsonProperty(key = "status", description = "当前状态", required = true),
-            @ApiJsonProperty(key = "type", description = "异常类型,status=stop时需要传递")
-    }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
+            @ApiJsonProperty(key = "type", description = "异常类型,status=stop时需要传递") }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
         if (Objects.isNull(mapParameter.get("recordId")) || Objects.equals(mapParameter.get("recordId"), "")) {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
@@ -152,46 +159,53 @@ public class TIeInvigilateCallMobileController {
         if (Objects.isNull(mapParameter.get("source")) || Objects.equals(mapParameter.get("source"), "")) {
             throw new BusinessException("监考视频源不能为空");
         }
-        MonitorVideoSourceEnum source = MonitorVideoSourceEnum.valueOf(String.valueOf(mapParameter.get("source")).toUpperCase());
+        MonitorVideoSourceEnum source = MonitorVideoSourceEnum
+                .valueOf(String.valueOf(mapParameter.get("source")).toUpperCase());
         if (Objects.isNull(mapParameter.get("status")) || Objects.equals(mapParameter.get("status"), "")) {
             throw new BusinessException("监考视频状态不能为空");
         }
-        MonitorStatusSourceEnum status = MonitorStatusSourceEnum.valueOf(String.valueOf(mapParameter.get("status")).toUpperCase());
-        if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get("type")) || Objects.equals(mapParameter.get("type"), ""))) {
+        MonitorStatusSourceEnum status = MonitorStatusSourceEnum
+                .valueOf(String.valueOf(mapParameter.get("status")).toUpperCase());
+        if (Objects.equals(status, MonitorStatusSourceEnum.STOP.name()) && (Objects.isNull(mapParameter.get("type"))
+                || Objects.equals(mapParameter.get("type"), ""))) {
             throw new BusinessException("异常类型不能为空");
         }
-        ConcurrentHashMap<String, WebSocketMobileServer> mobileWebSocketMap = WebSocketMobileServer.getWebSocketMap();
-        if (Objects.isNull(mobileWebSocketMap.get(recordId + "-" + source.name()))) {
-            throw new BusinessException("网络连接失败");
-        }
         //获取考试记录缓存
         String liveUrl = null;
         if (Objects.nonNull(ExamRecordCacheUtil.getMonitorLiveUrl(recordId, source))) {
             liveUrl = ExamRecordCacheUtil.getMonitorLiveUrl(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;
         ExamRecordCacheUtil.setMonitorStatus(recordId, source, status, true);
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, callStatus);
         String monitorKey = ExamRecordCacheUtil.getMonitorKey(recordId);
-        TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl, MonitorStatusSourceEnum.START, monitorKey, callStatus);
+        TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl,
+                MonitorStatusSourceEnum.START, monitorKey, callStatus);
         if (Objects.nonNull(mapParameter.get("type")) && !Objects.equals(mapParameter.get("type"), "")) {
             tIeExamInvigilateCallLog.setType(ExceptionEnum.valueOf(String.valueOf(mapParameter.get("type"))));
         }
 
         //监考监控通话信息 发送mq start
-        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(), tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()), source.name());
+        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(),
+                tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()),
+                source.name());
         mqDtoService.assembleSendOneWayMsg(mqDto);
         //监考监控通话信息 发送mq end
 
         ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
-        if (Objects.nonNull(webSocketMap.get(recordId)) && Objects.equals(status.name(), MonitorStatusSourceEnum.START.name())) {
+        if (Objects.nonNull(webSocketMap.get(recordId)) && Objects
+                .equals(status.name(), MonitorStatusSourceEnum.START.name())) {
             WebSocketOeServer webSocketOeServer = webSocketMap.get(recordId);
             Map map = new HashMap<>();
             map.put(SystemConstant.RECORD_ID, recordId);
             map.put("source", source.name());
             WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_MONITOR_START.name(), map);
             webSocketOeServer.sendMessage(websocketDto);
-        } else if (Objects.nonNull(webSocketMap.get(recordId)) && Objects.equals(status.name(), MonitorStatusSourceEnum.STOP.name())) {
+        } else if (Objects.nonNull(webSocketMap.get(recordId)) && Objects
+                .equals(status.name(), MonitorStatusSourceEnum.STOP.name())) {
             WebSocketOeServer webSocketOeServer = webSocketMap.get(recordId);
             Map map = new HashMap<>();
             map.put(SystemConstant.RECORD_ID, recordId);
@@ -207,12 +221,11 @@ public class TIeInvigilateCallMobileController {
 
     @ApiOperation(value = "撤销通话申请接口")
     @RequestMapping(value = "/call/cancel", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
+    @ApiResponses({ @ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class) })
     @Transactional
     public Result callCancel(@ApiJsonObject(name = "callCancelExamMobile", value = {
             @ApiJsonProperty(key = "recordId", type = "long", example = "1", description = "考试记录id", required = true),
-            @ApiJsonProperty(key = "source", description = "监考视频源", required = true)
-    }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
+            @ApiJsonProperty(key = "source", description = "监考视频源", required = true) }) @ApiParam(value = "监控信息", required = true) @RequestBody Map<String, Object> mapParameter) {
         if (Objects.isNull(mapParameter.get("recordId")) || Objects.equals(mapParameter.get("recordId"), "")) {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
@@ -224,7 +237,8 @@ public class TIeInvigilateCallMobileController {
         //获取考试记录缓存
         String liveUrl = null;
         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)) {
             return ResultUtil.ok(Collections.singletonMap("updateTime", System.currentTimeMillis()));
         } else if (Objects.isNull(ExamRecordCacheUtil.getMonitorStatus(recordId, source))) {
             throw new BusinessException("推流状态为空");
@@ -232,10 +246,13 @@ public class TIeInvigilateCallMobileController {
         ExamRecordCacheUtil.setMonitorCallStatus(recordId, source, MonitorCallStatusSourceEnum.STOP);
         String monitorKey = ExamRecordCacheUtil.getMonitorKey(recordId);
         MonitorStatusSourceEnum status = ExamRecordCacheUtil.getMonitorStatus(recordId, source);
-        TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl, status, monitorKey, MonitorCallStatusSourceEnum.STOP);
+        TIeExamInvigilateCallLog tIeExamInvigilateCallLog = new TIeExamInvigilateCallLog(recordId, source, liveUrl,
+                status, monitorKey, MonitorCallStatusSourceEnum.STOP);
         tIeExamInvigilateCallLog.setEndTime(System.currentTimeMillis());
         //监考监控通话信息 发送mq start
-        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(), tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()), source.name());
+        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.MONITOR_LOG.name(),
+                tIeExamInvigilateCallLog, MqTagEnum.MONITOR_LOG, String.valueOf(tIeExamInvigilateCallLog.getId()),
+                source.name());
         mqDtoService.assembleSendOneWayMsg(mqDto);
         //监考监控通话信息 发送mq end
         return ResultUtil.ok(Collections.singletonMap("updateTime", System.currentTimeMillis()));