Explorar el Código

拍照/录音答题就绪

xiatian hace 4 años
padre
commit
75d47a78d8

+ 54 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/exam/AnswerReadyParamBean.java

@@ -0,0 +1,54 @@
+package com.qmth.themis.business.bean.exam;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("拍照/录音答题就绪参数")
+public class AnswerReadyParamBean {
+	
+	@ApiModelProperty("考试记录id")
+	private Long recordId;
+	
+	@ApiModelProperty("大题号")
+	private Integer mainNumber;
+
+	@ApiModelProperty("小题号")
+	private Integer subNumber;
+	
+	@ApiModelProperty("套题子题序号")
+	private Integer subIndex;
+
+	public Long getRecordId() {
+		return recordId;
+	}
+
+	public void setRecordId(Long recordId) {
+		this.recordId = recordId;
+	}
+
+	public Integer getMainNumber() {
+		return mainNumber;
+	}
+
+	public void setMainNumber(Integer mainNumber) {
+		this.mainNumber = mainNumber;
+	}
+
+	public Integer getSubNumber() {
+		return subNumber;
+	}
+
+	public void setSubNumber(Integer subNumber) {
+		this.subNumber = subNumber;
+	}
+
+	public Integer getSubIndex() {
+		return subIndex;
+	}
+
+	public void setSubIndex(Integer subIndex) {
+		this.subIndex = subIndex;
+	}
+	
+	
+}

+ 32 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/exam/AnswerReadyResponseBean.java

@@ -0,0 +1,32 @@
+package com.qmth.themis.business.bean.exam;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("拍照/录音答题就绪返回信息")
+public class AnswerReadyResponseBean {
+	
+	@ApiModelProperty("考试名称")
+	private String examName;
+	
+	@ApiModelProperty("科目名称")
+	private String courseName;
+
+	public String getExamName() {
+		return examName;
+	}
+
+	public void setExamName(String examName) {
+		this.examName = examName;
+	}
+
+	public String getCourseName() {
+		return courseName;
+	}
+
+	public void setCourseName(String courseName) {
+		this.courseName = courseName;
+	}
+
+	
+}

+ 32 - 24
themis-business/src/main/java/com/qmth/themis/business/enums/WebsocketTypeEnum.java

@@ -31,7 +31,9 @@ public enum WebsocketTypeEnum {
 
     EXAM_START("考试开始", "examStart"),
 
-    EXAM_STOP("考试结束", "examStop");
+    EXAM_STOP("考试结束", "examStop"),
+    		
+	MOBILE_ANSWER_READY("移动端拍照/录音扫描完成", "mobileAnswerReady");
 
     private String code;
     private String desc;
@@ -56,28 +58,34 @@ public enum WebsocketTypeEnum {
      * @return
      */
     public static String convertToName(String value) {
-        if (Objects.equals(value.trim(), CLIENT_PAPER_DOWNLOAD.getDesc())) {
-            return CLIENT_PAPER_DOWNLOAD.name();
-        } else if (Objects.equals(value.trim(), SYNC_STATUS.getDesc())) {
-            return SYNC_STATUS.name();
-        } else if (Objects.equals(value.trim(), SYNC_ACK.getDesc())) {
-            return SYNC_ACK.name();
-        } else if (Objects.equals(value.trim(), INVIGILATE_LIVENESS_VERIFY.getDesc())) {
-            return INVIGILATE_LIVENESS_VERIFY.name();
-        } else if (Objects.equals(value.trim(), INVIGILATE_NOTICE.getDesc())) {
-            return INVIGILATE_NOTICE.name();
-        } else if (Objects.equals(value.trim(), INVIGILATE_NOTICE_ACK.getDesc())) {
-            return INVIGILATE_NOTICE_ACK.name();
-        } else if (Objects.equals(value.trim(), INVIGILATE_STOP_EXAM.getDesc())) {
-            return INVIGILATE_STOP_EXAM.name();
-        } else if (Objects.equals(value.trim(), BREACH_STOP_EXAM.getDesc())) {
-            return BREACH_STOP_EXAM.name();
-        } else if (Objects.equals(value.trim(), EXAM_START.getDesc())) {
-            return EXAM_START.name();
-        } else if (Objects.equals(value.trim(), EXAM_STOP.getDesc())) {
-            return EXAM_STOP.name();
-        } else {
-            return HAND_STOP_EXAM.name();
-        }
+//        if (Objects.equals(value.trim(), CLIENT_PAPER_DOWNLOAD.getDesc())) {
+//            return CLIENT_PAPER_DOWNLOAD.name();
+//        } else if (Objects.equals(value.trim(), SYNC_STATUS.getDesc())) {
+//            return SYNC_STATUS.name();
+//        } else if (Objects.equals(value.trim(), SYNC_ACK.getDesc())) {
+//            return SYNC_ACK.name();
+//        } else if (Objects.equals(value.trim(), INVIGILATE_LIVENESS_VERIFY.getDesc())) {
+//            return INVIGILATE_LIVENESS_VERIFY.name();
+//        } else if (Objects.equals(value.trim(), INVIGILATE_NOTICE.getDesc())) {
+//            return INVIGILATE_NOTICE.name();
+//        } else if (Objects.equals(value.trim(), INVIGILATE_NOTICE_ACK.getDesc())) {
+//            return INVIGILATE_NOTICE_ACK.name();
+//        } else if (Objects.equals(value.trim(), INVIGILATE_STOP_EXAM.getDesc())) {
+//            return INVIGILATE_STOP_EXAM.name();
+//        } else if (Objects.equals(value.trim(), BREACH_STOP_EXAM.getDesc())) {
+//            return BREACH_STOP_EXAM.name();
+//        } else if (Objects.equals(value.trim(), EXAM_START.getDesc())) {
+//            return EXAM_START.name();
+//        } else if (Objects.equals(value.trim(), EXAM_STOP.getDesc())) {
+//            return EXAM_STOP.name();
+//        } else {
+//            return HAND_STOP_EXAM.name();
+//        }
+    	for(WebsocketTypeEnum e:WebsocketTypeEnum.values()) {
+    		if (Objects.equals(value.trim(), e.getDesc())) {
+    			return e.name();
+    		}
+    	}
+    	return HAND_STOP_EXAM.name();
     }
 }

+ 63 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEMobileController.java

@@ -1,6 +1,9 @@
 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;
 
@@ -9,12 +12,22 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.qmth.themis.business.bean.exam.AnswerReadyParamBean;
+import com.qmth.themis.business.bean.exam.AnswerReadyResponseBean;
 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.dto.WebsocketDto;
+import com.qmth.themis.business.enums.ExamRecordStatusEnum;
+import com.qmth.themis.business.enums.WebsocketTypeEnum;
 import com.qmth.themis.business.service.MqDtoService;
+import com.qmth.themis.business.service.TEExamService;
+import com.qmth.themis.business.service.TEExamStudentService;
 import com.qmth.themis.business.service.TEMobileService;
 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.Api;
 import io.swagger.annotations.ApiOperation;
@@ -29,6 +42,12 @@ public class TEMobileController {
 	
 	@Resource
 	TEMobileService mobileService;
+	
+	@Resource
+	TEExamService examService;
+
+	@Resource
+	TEExamStudentService examStudentService;
 
 	@ApiOperation(value = "获取登录详细信息")
 	@RequestMapping(value = "/authorization", method = RequestMethod.POST)
@@ -41,5 +60,49 @@ public class TEMobileController {
 		}
 		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) {
+            throw new BusinessException("大题号不能为空");
+        }
+        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("该考试已结束");
+		}
+        ConcurrentHashMap<Long, WebSocketOeServer> webSocketMap = WebSocketOeServer.getWebSocketMap();
+        WebSocketOeServer webSocketOeServer = webSocketMap.get(param.getRecordId());
+        if(webSocketOeServer==null) {
+        	throw new BusinessException("消息连接不存在");
+        }
+        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());
+        }
+        WebsocketDto websocketDto = new WebsocketDto(WebsocketTypeEnum.MOBILE_ANSWER_READY.name(), map);
+        webSocketOeServer.sendMessage(websocketDto);
+        ExamStudentCacheBean  es=examStudentService.getExamStudentCacheBean(esId);
+        AnswerReadyResponseBean ret=new AnswerReadyResponseBean();
+        ret.setCourseName(es.getCourseName());
+        ret.setExamName(examService.getExamCacheBean(es.getExamId()).getName());
+		return ResultUtil.ok(ret);
+	}
 
 }