|
@@ -0,0 +1,295 @@
|
|
|
+package cn.com.qmth.examcloud.core.oe.student.api.controller;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.UserType;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.base.utils.Check;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.ExamProcessResultInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.bean.GetFaceVerifyTokenInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.ExamFaceLivenessVerifyRepo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.entity.ExamFaceLivenessVerifyEntity;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.dao.enums.FaceVerifyResult;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.service.ExamFaceLivenessVerifyService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.student.service.ExamRecordDataService;
|
|
|
+import cn.com.qmth.examcloud.support.Constants;
|
|
|
+import cn.com.qmth.examcloud.support.examing.ExamRecordData;
|
|
|
+import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
+import cn.com.qmth.examcloud.web.support.Naked;
|
|
|
+import cn.com.qmth.examcloud.ws.api.WsCloudService;
|
|
|
+import cn.com.qmth.examcloud.ws.api.WsPath;
|
|
|
+import cn.com.qmth.examcloud.ws.api.request.SendMessageReq;
|
|
|
+import cn.com.qmth.examcloud.ws.api.request.SendTextReq;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.json.JSONException;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description 活体检测Controller
|
|
|
+ * @Author lideyin
|
|
|
+ * @Date 2019/12/16 17:38
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+@Api(tags = "活体检测")
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app.api.oe.student}/examFaceLivenessVerify")
|
|
|
+public class ExamFaceLivenessVerifyController extends ControllerSupport {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamFaceLivenessVerifyService examFaceLivenessVerifyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WsCloudService wsCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamFaceLivenessVerifyRepo examFaceLivenessVerifyRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRecordDataService examRecordDataService;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "检测学生底照是否能获取到faceId验证的token")
|
|
|
+ @GetMapping("/checkFaceLiveness")
|
|
|
+ public GetFaceVerifyTokenInfo checkFaceLiveness() {
|
|
|
+ User user = getAccessUser();
|
|
|
+ String bizNo = user.getUserId().toString();
|
|
|
+ return examFaceLivenessVerifyService.getFaceVerifyToken(user.getUserId(), bizNo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得一个faceid用于网页端活体检测的token
|
|
|
+ *
|
|
|
+ * @param examRecordDataId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获得一个faceid用于网页端活体检测的token")
|
|
|
+ @GetMapping("/getFaceLivenessVerifyToken/{examRecordDataId}")
|
|
|
+ @Deprecated
|
|
|
+ public GetFaceVerifyTokenInfo getFaceLivenessVerifyToken(@PathVariable Long examRecordDataId) {
|
|
|
+ Check.isNull(examRecordDataId, "examRecordDataId不能为空");
|
|
|
+ User user = getAccessUser();
|
|
|
+ ExamFaceLivenessVerifyEntity faceVerify = examFaceLivenessVerifyService.saveFaceVerifyByExamRecordDataId(examRecordDataId);
|
|
|
+ GetFaceVerifyTokenInfo getFaceVerifyTokenInfo = examFaceLivenessVerifyService.getFaceVerifyToken(user.getUserId(), faceVerify.getId().toString());
|
|
|
+ if (!getFaceVerifyTokenInfo.getSuccess()) {
|
|
|
+ faceVerify.setIsError(true);
|
|
|
+ faceVerify.setErrorMsg(getFaceVerifyTokenInfo.getErrorMsg());
|
|
|
+ examFaceLivenessVerifyRepo.save(faceVerify);
|
|
|
+ }
|
|
|
+ return getFaceVerifyTokenInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得一个faceid用于网页端活体检测的token
|
|
|
+ *
|
|
|
+ * @param examRecordDataId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获得一个faceid用于网页端活体检测的token")
|
|
|
+ @GetMapping("/startFaceVerify/{examRecordDataId}")
|
|
|
+ public GetFaceVerifyTokenInfo startFaceVerify(@PathVariable Long examRecordDataId) {
|
|
|
+ Check.isNull(examRecordDataId, "examRecordDataId不能为空");
|
|
|
+
|
|
|
+ //活检如果已经进行了两次不允许进行第三次
|
|
|
+ List<ExamFaceLivenessVerifyEntity> faceVerifyList =
|
|
|
+ examFaceLivenessVerifyService.listFaceVerifyByExamRecordId(examRecordDataId);
|
|
|
+ if (faceVerifyList.size() >= 2) {
|
|
|
+ throw new StatusException("100002", "活检次数不能超过2次");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamFaceLivenessVerifyEntity faceVerify = examFaceLivenessVerifyService.saveFaceVerifyByExamRecordDataId(examRecordDataId);
|
|
|
+
|
|
|
+ String bizNo = faceVerify.getId() + "_" + System.currentTimeMillis();
|
|
|
+ GetFaceVerifyTokenInfo getFaceVerifyTokenInfo = examFaceLivenessVerifyService.
|
|
|
+ getFaceVerifyToken(getAccessUser().getUserId(), bizNo);
|
|
|
+ if (!getFaceVerifyTokenInfo.getSuccess()) {
|
|
|
+ faceVerify.setIsError(true);
|
|
|
+ faceVerify.setErrorMsg(getFaceVerifyTokenInfo.getErrorMsg());
|
|
|
+ examFaceLivenessVerifyRepo.save(faceVerify);
|
|
|
+ }
|
|
|
+ getFaceVerifyTokenInfo.setFaceVerifyId(faceVerify.getId());
|
|
|
+ return getFaceVerifyTokenInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获得一个faceid用于网页端活体检测的token
|
|
|
+ *
|
|
|
+ * @param faceVerifyId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获得一个faceid用于网页端活体检测的token")
|
|
|
+ @GetMapping("/getFaceVerifyToken/{faceVerifyId}")
|
|
|
+ public GetFaceVerifyTokenInfo getFaceVerifyToken(@PathVariable Long faceVerifyId) {
|
|
|
+ Check.isNull(faceVerifyId, "faceVerifyId不能为空");
|
|
|
+ User user = getAccessUser();
|
|
|
+
|
|
|
+ String bizNo = faceVerifyId + "_" + System.currentTimeMillis();
|
|
|
+// ExamFaceLivenessVerifyEntity faceVerify = examFaceLivenessVerifyService.saveFaceVerifyByExamRecordDataId(examRecordDataId);
|
|
|
+ GetFaceVerifyTokenInfo getFaceVerifyTokenInfo = examFaceLivenessVerifyService.
|
|
|
+ getFaceVerifyToken(user.getUserId(), bizNo);
|
|
|
+ getFaceVerifyTokenInfo.setFaceVerifyId(faceVerifyId);
|
|
|
+ return getFaceVerifyTokenInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取活体检测的回调结果
|
|
|
+ *
|
|
|
+ * @param faceVerifyId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取活体检测的回调结果")
|
|
|
+ @GetMapping("/getFaceVerifyResult/{faceVerifyId}")
|
|
|
+ public Map<String, Object> getFaceVerifyResult(@PathVariable Long faceVerifyId) {
|
|
|
+ Check.isNull(faceVerifyId, "faceVerifyId不能为空");
|
|
|
+
|
|
|
+ ExamFaceLivenessVerifyEntity faceVerify = examFaceLivenessVerifyService.findFaceVerifyById(faceVerifyId);
|
|
|
+ if (faceVerify == null) {
|
|
|
+ throw new StatusException("100001", "活检结果不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> jsonObject = new HashMap<>();
|
|
|
+ List<ExamFaceLivenessVerifyEntity> faceVerifies = examFaceLivenessVerifyService.listFaceVerifyByExamRecordId(faceVerify.getExamRecordDataId());
|
|
|
+ //验证次数
|
|
|
+ jsonObject.put("verifyCount", faceVerifies.size());
|
|
|
+
|
|
|
+ if (faceVerify.getVerifyResult() == null) {
|
|
|
+ //取最后一次验证结果
|
|
|
+ jsonObject.put("verifyResult", FaceVerifyResult.UNKNOWN.name());
|
|
|
+ } else {
|
|
|
+ //取最后一次验证结果
|
|
|
+ jsonObject.put("verifyResult", faceVerify.getVerifyResult().name());
|
|
|
+ }
|
|
|
+ jsonObject.put("examRecordDataId", faceVerify.getExamRecordDataId());
|
|
|
+
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新活体检测结果")
|
|
|
+ @GetMapping("/updateFaceLivenessVerify/{examRecordDataId}")
|
|
|
+ public void updateFaceVerify(@PathVariable Long examRecordDataId, @RequestParam String errorMsg) {
|
|
|
+ Check.isNull(examRecordDataId, "examRecordDataId不能为空");
|
|
|
+ List<ExamFaceLivenessVerifyEntity> examFaceLivenessVerifyEntities = examFaceLivenessVerifyService.listFaceVerifyByExamRecordId(examRecordDataId);
|
|
|
+ if (examFaceLivenessVerifyEntities != null && examFaceLivenessVerifyEntities.size() > 0) {
|
|
|
+ ExamFaceLivenessVerifyEntity examFaceLivenessVerifyEntity = examFaceLivenessVerifyEntities.get(0);
|
|
|
+ examFaceLivenessVerifyEntity.setIsError(true);
|
|
|
+ examFaceLivenessVerifyEntity.setErrorMsg(errorMsg);
|
|
|
+ examFaceLivenessVerifyRepo.save(examFaceLivenessVerifyEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人脸验证完成后的回调,由faceId调用
|
|
|
+ *
|
|
|
+ * @param data
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Naked
|
|
|
+ @ApiOperation(value = "人脸验证完成后的回调,由faceId调用")
|
|
|
+ @PostMapping("/faceLivenessVerifyCallback")
|
|
|
+ public void faceLivenessVerifyCallback(@RequestParam String data) throws Exception {
|
|
|
+ log.info("faceId回调,data=" + data);
|
|
|
+
|
|
|
+ JSONObject returnJsonObject = new JSONObject(data);
|
|
|
+ String bizNo = returnJsonObject.get("biz_no").toString();
|
|
|
+ Long faceVerifyId;
|
|
|
+ if (bizNo.indexOf("_") == -1) {
|
|
|
+ faceVerifyId = Long.parseLong(bizNo + "");
|
|
|
+ } else {
|
|
|
+ faceVerifyId = Long.parseLong(bizNo.substring(0, bizNo.indexOf("_")));
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamFaceLivenessVerifyEntity currentFaceVerify = examFaceLivenessVerifyService.findFaceVerifyById(faceVerifyId);
|
|
|
+ /*
|
|
|
+ * 如果该检测记录结果已经非空了,直接返回,
|
|
|
+ * 有可能超时程序已经将结果填成TIME_OUT了
|
|
|
+ */
|
|
|
+ if (currentFaceVerify.getVerifyResult() != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamFaceLivenessVerifyEntity faceVerify = examFaceLivenessVerifyService.faceIdNotify(data);
|
|
|
+ List<ExamFaceLivenessVerifyEntity> faceVerifies = examFaceLivenessVerifyService.listFaceVerifyByExamRecordId(faceVerify.getExamRecordDataId());
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ //验证次数
|
|
|
+ jsonObject.put("verifyCount", faceVerifies.size());
|
|
|
+ //取最后一次验证结果
|
|
|
+ jsonObject.put("verifyResult", faceVerifies.get(faceVerifies.size() - 1).getVerifyResult().name());
|
|
|
+ jsonObject.put("examRecordDataId", faceVerify.getExamRecordDataId());
|
|
|
+
|
|
|
+ SendMessageReq sendMessageReq = new SendMessageReq();
|
|
|
+ sendMessageReq.setExamRecordDataId(faceVerify.getExamRecordDataId());
|
|
|
+ sendMessageReq.setReturnMsgJson(jsonObject.toString());
|
|
|
+
|
|
|
+ SendTextReq sendTextReq = new SendTextReq();
|
|
|
+ sendTextReq.setUserType(UserType.STUDENT);
|
|
|
+
|
|
|
+ ExamRecordData examRecordData = examRecordDataService.getExamRecordDataCache(faceVerify.getExamRecordDataId());
|
|
|
+ sendTextReq.setUserId(examRecordData.getStudentId());
|
|
|
+ sendTextReq.setRootOrgId(examRecordData.getRootOrgId());
|
|
|
+ sendTextReq.setPath(WsPath.FACE_BIOPSY);
|
|
|
+ sendTextReq.setContent(JsonUtil.toJson(sendMessageReq));
|
|
|
+ wsCloudService.sendText(sendTextReq);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人脸检测超时处理
|
|
|
+ *
|
|
|
+ * @param examRecordDataId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "人脸检测超时处理")
|
|
|
+ @GetMapping("/faceLivenessVerifyTimeOut/{examRecordDataId}")
|
|
|
+ public String faceTestTimeOut(@PathVariable Long examRecordDataId) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ examFaceLivenessVerifyService.faceTestTimeOut(examRecordDataId);
|
|
|
+ List<ExamFaceLivenessVerifyEntity> faceVerifies = examFaceLivenessVerifyService.listFaceVerifyByExamRecordId(examRecordDataId);
|
|
|
+ //验证次数
|
|
|
+ try {
|
|
|
+ jsonObject.put("verifyCount", faceVerifies.size());
|
|
|
+ //取最后一次验证结果
|
|
|
+ jsonObject.put("verifyResult", faceVerifies.get(faceVerifies.size() - 1).getVerifyResult().name());
|
|
|
+ jsonObject.put("examRecordDataId", examRecordDataId);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return jsonObject.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人脸活体检测结束处理
|
|
|
+ *
|
|
|
+ * @param examRecordDataId 考试记录id
|
|
|
+ * @param result 活体检测结果
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "人脸检测结束处理")
|
|
|
+ @GetMapping(value = "faceLivenessVerifyEnd/{examRecordDataId}")
|
|
|
+ public ExamProcessResultInfo faceTestEndHandle(@PathVariable Long examRecordDataId, @RequestParam String result) throws Exception {
|
|
|
+ ExamProcessResultInfo res = new ExamProcessResultInfo();
|
|
|
+ try {
|
|
|
+ User user = getAccessUser();
|
|
|
+ examFaceLivenessVerifyService.faceTestEndHandle(examRecordDataId, user.getUserId(), result);
|
|
|
+ res.setCode(Constants.COMMON_SUCCESS_CODE);
|
|
|
+ return res;
|
|
|
+ } catch (StatusException e) {
|
|
|
+ if (e.getCode().equals(Constants.EXAM_RECORD_NOT_END_STATUS_CODE)) {
|
|
|
+ res.setCode(Constants.PROCESSING_EXAM_RECORD_CODE);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|