Browse Source

Merge branch 'dev' of http://git.qmth.com.cn/themis/backend-service.git into dev

xiatian 4 years ago
parent
commit
ee47876f83

+ 79 - 72
themis-exam/src/main/java/com/qmth/themis/exam/api/TEMobileController.java

@@ -1,30 +1,18 @@
 package com.qmth.themis.exam.api;
 
-import java.security.NoSuchAlgorithmException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
-
 import com.qmth.themis.business.bean.exam.AnswerReadyParamBean;
 import com.qmth.themis.business.bean.exam.AnswerReadyResponseBean;
 import com.qmth.themis.business.bean.exam.MobileAnswerSubmitParamBean;
 import com.qmth.themis.business.bean.exam.MobileAnswerSubmitReponseBean;
+import com.qmth.themis.business.bean.mobile.MobileAuthorizationBean;
 import com.qmth.themis.business.bean.mobile.MobileAuthorizationParamBean;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.WebsocketDto;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.enums.ExamRecordStatusEnum;
+import com.qmth.themis.business.enums.MobileModeEnum;
 import com.qmth.themis.business.enums.WebsocketTypeEnum;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.TEExamService;
@@ -35,47 +23,52 @@ import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.websocket.WebSocketOeServer;
+import io.swagger.annotations.*;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
+import javax.annotation.Resource;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
 
 @Api(tags = "移动端接口")
 @RestController
 @RequestMapping("/${prefix.url.mobile}")
 public class TEMobileController {
-	
-	@Resource
-	MqDtoService mqDtoService;
-	
-	@Resource
-	TEMobileService mobileService;
-	
-	@Resource
-	TEExamService examService;
 
-	@Resource
-	TEExamStudentService examStudentService;
-	
+    @Resource
+    MqDtoService mqDtoService;
+
+    @Resource
+    TEMobileService mobileService;
 
-	@ApiOperation(value = "获取登录详细信息")
-	@RequestMapping(value = "/authorization", method = RequestMethod.POST)
-	public Result authorization(@RequestBody MobileAuthorizationParamBean param) throws NoSuchAlgorithmException {
-		if (param.getMode() == null) {
-			throw new BusinessException("mode不能为空");
-		}
-		if (param.getCode() == null) {
-			throw new BusinessException("code不能为空");
-		}
-		return ResultUtil.ok(mobileService.authorization(param));
-	}
-	
-	@ApiOperation(value = "拍照/录音答题就绪")
-	@RequestMapping(value = "/answer/ready", method = RequestMethod.POST)
-	public Result answerReady(@RequestBody AnswerReadyParamBean param){
-		if (param.getRecordId() == null) {
+    @Resource
+    TEExamService examService;
+
+    @Resource
+    TEExamStudentService examStudentService;
+
+
+    @ApiOperation(value = "获取登录详细信息")
+    @RequestMapping(value = "/authorization", method = RequestMethod.POST)
+    public Result authorization(@RequestBody MobileAuthorizationParamBean param) throws NoSuchAlgorithmException {
+        if (param.getMode() == null) {
+            throw new BusinessException("mode不能为空");
+        }
+        if (param.getCode() == null) {
+            throw new BusinessException("code不能为空");
+        }
+        return ResultUtil.ok(mobileService.authorization(param));
+    }
+
+    @ApiOperation(value = "拍照/录音答题就绪")
+    @RequestMapping(value = "/answer/ready", method = RequestMethod.POST)
+    public Result answerReady(@RequestBody AnswerReadyParamBean param) {
+        if (param.getRecordId() == null) {
             throw new BusinessException("考试记录id不能为空");
         }
         if (param.getMainNumber() == null) {
@@ -84,38 +77,38 @@ public class TEMobileController {
         if (param.getSubNumber() == null) {
             throw new BusinessException("小题号不能为空");
         }
-        Long esId=ExamRecordCacheUtil.getExamStudentId(param.getRecordId());
-		if(ExamRecordCacheUtil.getId(param.getRecordId())==null) {
-			throw new BusinessException("考试记录不存在");
-		}
-		ExamRecordStatusEnum sta=ExamRecordCacheUtil.getStatus(param.getRecordId());
-		if(ExamRecordStatusEnum.FIRST_PREPARE.equals(sta)) {
-			throw new BusinessException("该考试未开始答题");
-		}
-		if(ExamRecordStatusEnum.FINISHED.equals(sta)||ExamRecordStatusEnum.PERSISTED.equals(sta)) {
-			throw new BusinessException("该考试已结束");
-		}
+        Long esId = ExamRecordCacheUtil.getExamStudentId(param.getRecordId());
+        if (ExamRecordCacheUtil.getId(param.getRecordId()) == null) {
+            throw new BusinessException("考试记录不存在");
+        }
+        ExamRecordStatusEnum sta = ExamRecordCacheUtil.getStatus(param.getRecordId());
+        if (ExamRecordStatusEnum.FIRST_PREPARE.equals(sta)) {
+            throw new BusinessException("该考试未开始答题");
+        }
+        if (ExamRecordStatusEnum.FINISHED.equals(sta) || ExamRecordStatusEnum.PERSISTED.equals(sta)) {
+            throw new BusinessException("该考试已结束");
+        }
         ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
         WebSocketOeServer webSocketOeServer = webSocketMap.get(param.getRecordId());
-        if(webSocketOeServer==null) {
-        	throw new BusinessException("消息连接不存在");
+        if (webSocketOeServer == null) {
+            throw new BusinessException("消息连接不存在");
         }
-        Map<String,Object> map = new HashMap<String,Object>();
+        Map<String, Object> map = new HashMap<String, Object>();
         map.put("recordId", param.getRecordId());
-        map.put("mainNumber",param.getMainNumber());
-        map.put("subNumber",param.getSubNumber());
-        if(param.getSubIndex()!=null) {
-        	map.put("subIndex",param.getSubIndex());
+        map.put("mainNumber", param.getMainNumber());
+        map.put("subNumber", param.getSubNumber());
+        if (param.getSubIndex() != null) {
+            map.put("subIndex", param.getSubIndex());
         }
         WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_ANSWER_READY.name(), map);
         webSocketOeServer.sendMessage(websocketDto);
-        ExamStudentCacheBean  es=examStudentService.getExamStudentCacheBean(esId);
-        AnswerReadyResponseBean ret=new AnswerReadyResponseBean();
+        ExamStudentCacheBean es = examStudentService.getExamStudentCacheBean(esId);
+        AnswerReadyResponseBean ret = new AnswerReadyResponseBean();
         ret.setCourseName(es.getCourseName());
         ret.setExamName(examService.getExamCacheBean(es.getExamId()).getName());
-		return ResultUtil.ok(ret);
-	}
-	
+        return ResultUtil.ok(ret);
+    }
+
     @ApiOperation(value = "文件上传")
     @RequestMapping(value = "/file/upload", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "试卷信息")})
@@ -126,7 +119,7 @@ public class TEMobileController {
         TEStudentCacheDto teStudent = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
         return ResultUtil.ok(examService.fileUpload(teStudent.getId(), recordId, file, suffix, md5));
     }
-    
+
     @ApiOperation(value = "提交作答结果")
     @RequestMapping(value = "/answer/submit", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "试卷信息")})
@@ -146,6 +139,20 @@ public class TEMobileController {
         }
         MobileAnswerSubmitReponseBean ret = mobileService.answerSubmit(teStudent.getId(), param.getRecordId(), param.getMainNumber(),
                 param.getSubNumber(), param.getSubIndex(), param.getUrls());
+        ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
+        if (Objects.nonNull(webSocketMap.get(param.getRecordId()))) {
+            WebSocketOeServer webSocketOeServer = webSocketMap.get(param.getRecordId());
+            Map map = new HashMap<>();
+            map.put(SystemConstant.RECORD_ID, param.getRecordId());
+            map.put("mainNumber", param.getMainNumber());
+            map.put("subNumber", param.getSubNumber());
+            if (param.getSubIndex() != null) {
+                map.put("subIndex", param.getSubIndex());
+            }
+            map.put("urls", param.getUrls());
+            WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_ANSWER_UPLOAD.name(), map);
+            webSocketOeServer.sendMessage(websocketDto);
+        }
         return ResultUtil.ok(ret);
     }
 

+ 21 - 1
themis-exam/src/main/java/com/qmth/themis/exam/api/TIeInvigilateCallMobileController.java

@@ -5,15 +5,16 @@ import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.RedisKeyHelper;
 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.TIeExamInvigilateCallLog;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.MqDtoService;
-import com.qmth.themis.business.service.TIeExamInvigilateCallService;
 import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
+import com.qmth.themis.exam.websocket.WebSocketOeServer;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,8 +26,10 @@ import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * @Description: mobile监考监控通话信息 前端控制器
@@ -173,6 +176,23 @@ public class TIeInvigilateCallMobileController {
         MqDto mqDto = new MqDto(MqTopicEnum.themisTopic.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())) {
+            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())) {
+            WebSocketOeServer webSocketOeServer = webSocketMap.get(recordId);
+            Map map = new HashMap<>();
+            map.put(SystemConstant.RECORD_ID, recordId);
+            map.put("monitorVideoSource", source.name());
+            WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_MONITOR_STOP.name(), map);
+            webSocketOeServer.sendMessage(websocketDto);
+        }
         return ResultUtil.ok(SystemConstant.SUCCESS);
     }
 

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

@@ -287,7 +287,6 @@ public class WebSocketOeServer implements Concurrently {
         } catch (Exception e) {
             e.printStackTrace();
             return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
-
         } finally {
             if (Objects.nonNull(mqDto)) {
                 redisUtil.releaseLock(SystemConstant.REDIS_LOCK_MQ_PREFIX + mqDto.getId());

+ 1 - 1
themis-exam/src/main/resources/application.properties

@@ -150,4 +150,4 @@ wxapp.upload.url=http://wxapp2.qmth.com.cn
 
 #\u65E0\u9700\u9274\u6743\u7684url
 no.auth.urls=/webjars/**,/druid/**,/swagger-ui.html,/doc.html,/swagger-resources/**,/v2/api-docs,/webjars/springfox-swagger-ui/**,/api/oe/student/login,/api/oe/sys/env,/file/**,/upload/**,/client/**,/base_photo/**,/frontend/**,/api/oe/exam/short_code,/api/oe/monitor/live_url,/api/oe/monitor/call/apply,/api/oe/monitor/call/cancel,/api/mobile/monitor/live_url,/api/mobile/monitor/call/apply,/api/mobile/monitor/call/cancel,/api/mobile/authorization
-common.system.urls=/api/oe/student/logout,/api/oe/exam/file/upload
+common.system.urls=/api/oe/student/logout,/api/oe/exam/file/upload,/api/mobile/file/upload