Przeglądaj źródła

新活体调试bug修复

lideyin 5 lat temu
rodzic
commit
59d4618279

+ 45 - 1
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/controller/ExamControlController.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.core.oe.student.controller;
 
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.util.Util;
 import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
 import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
 import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
@@ -18,6 +19,8 @@ import cn.com.qmth.examcloud.core.oe.student.api.request.GetStudentOnlineExamInf
 import cn.com.qmth.examcloud.core.oe.student.api.response.GetStudentOnlineExamInfoResp;
 import cn.com.qmth.examcloud.core.oe.student.bean.*;
 import cn.com.qmth.examcloud.core.oe.student.bean.ExamProcessResultInfo;
+import cn.com.qmth.examcloud.core.oe.student.controller.bean.BatchGetUpyunSignDomain;
+import cn.com.qmth.examcloud.core.oe.student.controller.bean.BatchGetUpyunSignDomainQuery;
 import cn.com.qmth.examcloud.core.oe.student.controller.bean.GetUpyunSignDomain;
 import cn.com.qmth.examcloud.core.oe.student.controller.bean.GetUpyunSignDomainQuery;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamControlService;
@@ -41,8 +44,10 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author chenken
@@ -337,7 +342,7 @@ public class ExamControlController extends ControllerSupport {
     public GetUpyunSignDomain getCapturePhotoUpYunSign(GetUpyunSignDomainQuery query) {
         String fileSuffix = query.getFileSuffix();
         if (StringUtils.isNullOrEmpty(fileSuffix)) {
-            throw new StatusException("", "文件后缀名不允许为空");
+            throw new StatusException("200001", "文件后缀名不允许为空");
         }
         fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
 
@@ -360,4 +365,43 @@ public class ExamControlController extends ControllerSupport {
         return result;
     }
 
+    @ApiOperation(value = "批量获取抓拍照片的又拍云签名")
+    @GetMapping("/batchGetCapturePhotoUpYunSign")
+    public BatchGetUpyunSignDomain batchGetCapturePhotoUpYunSign(BatchGetUpyunSignDomainQuery batchQuery) {
+        if (batchQuery.getQueryList() == null || batchQuery.getQueryList().isEmpty()) {
+            throw new StatusException("200001", "查询条件不允许为空");
+        }
+
+        List<GetUpyunSignDomain> signDomainList = new ArrayList<>();
+        for (GetUpyunSignDomainQuery query : batchQuery.getQueryList()) {
+            String fileSuffix = query.getFileSuffix();
+            if (StringUtils.isNullOrEmpty(fileSuffix)) {
+                throw new StatusException("", "文件后缀名不允许为空");
+            }
+            fileSuffix = fileSuffix.indexOf(".") == -1 ? "." + fileSuffix : fileSuffix;
+
+            GetUpyunSignDomain upyunSignDomain = new GetUpyunSignDomain();
+            User accessUser = this.getAccessUser();
+            String signIdentifier = String.valueOf(System.currentTimeMillis());
+            String upyunSignRedisKey = Constants.EXAM_CAPTURE_PHOTO_UPYUN_SIGN_PREFIX
+                    + accessUser.getUserId() + "_" + signIdentifier;
+
+            UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
+            env.setRootOrgId(accessUser.getRootOrgId().toString());
+            env.setUserId(accessUser.getUserId().toString());
+            env.setFileSuffix(fileSuffix);
+            UpYunHttpRequest upYunHttpRequest = upyunService.buildUpYunHttpRequest(CAPTURE_PHOTO_UPYUN_SITEID, env, query.getFileMd5());
+            redisClient.set(upyunSignRedisKey, upYunHttpRequest, 60);
+            upyunSignDomain.setAccessUrl(upYunHttpRequest.getAccessUrl());
+            upyunSignDomain.setFormUrl(upYunHttpRequest.getFormUrl());
+            upyunSignDomain.setFormParams(upYunHttpRequest.getFormParams());
+            upyunSignDomain.setSignIdentifier(signIdentifier);
+
+            signDomainList.add(upyunSignDomain);
+            Util.sleep(TimeUnit.MILLISECONDS,1);
+        }
+        BatchGetUpyunSignDomain result = new BatchGetUpyunSignDomain();
+        result.setList(signDomainList);
+        return result;
+    }
 }

+ 29 - 0
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/controller/bean/BatchGetUpyunSignDomain.java

@@ -0,0 +1,29 @@
+package cn.com.qmth.examcloud.core.oe.student.controller.bean;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ * @Description 获取又拍云签名实体
+ * @Author lideyin
+ * @Date 2019/7/29 13:51
+ * @Version 1.0
+ */
+public class BatchGetUpyunSignDomain implements JsonSerializable {
+
+	private static final long serialVersionUID = -1590654532824096979L;
+
+	@ApiModelProperty("又拍云签名集合")
+	private List<GetUpyunSignDomain> list;
+
+	public List<GetUpyunSignDomain> getList() {
+		return list;
+	}
+
+	public void setList(List<GetUpyunSignDomain> list) {
+		this.list = list;
+	}
+}

+ 28 - 0
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/controller/bean/BatchGetUpyunSignDomainQuery.java

@@ -0,0 +1,28 @@
+package cn.com.qmth.examcloud.core.oe.student.controller.bean;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description 获取又拍云签名查询实体
+ * @Author lideyin
+ * @Date 2019/7/29 13:52
+ * @Version 1.0
+ */
+public class BatchGetUpyunSignDomainQuery implements Serializable {
+
+    private static final long serialVersionUID = 9042153672752879732L;
+
+    @ApiModelProperty("又拍云签名查询参数集合")
+    private List<GetUpyunSignDomainQuery> queryList;
+
+    public List<GetUpyunSignDomainQuery> getQueryList() {
+        return queryList;
+    }
+
+    public void setQueryList(List<GetUpyunSignDomainQuery> queryList) {
+        this.queryList = queryList;
+    }
+}

+ 46 - 4
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/FaceBiopsyServiceImpl.java

@@ -21,6 +21,7 @@ import cn.com.qmth.examcloud.core.oe.student.service.FaceBiopsyService;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
+import com.mysql.cj.util.StringUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -52,7 +53,15 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
     private ExamControlService examControlService;
 
     @Override
+    @Transactional
     public FaceBiopsyInfo getFaceBiopsyInfo(Long rootOrgId, Long examRecordDataId, FaceBiopsyType faceBiopsyType) {
+        //如果在冻结时间外,需要判断是否开启冻结时间外添加人脸活体检测
+        boolean isInFreezeTime = calculateIsInFreezeTime(examRecordDataId);
+        if (!isInFreezeTime) {
+            if (!addFaceVerifyOutFreezeTime(examRecordDataId)) {
+                throw new StatusException("201004", "非冻结时间内不允许人脸活体检测");
+            }
+        }
 
         //如果是第一次进行人脸活体检测,则初始化相关信息保存并返回
         FaceBiopsyEntity faceBiopsyEntity = faceBiopsyRepo.findByExamRecordDataId(examRecordDataId);
@@ -93,6 +102,7 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
     }
 
     @Override
+    @Transactional
     public SaveFaceBiopsyResultResp saveFaceBiopsyResult(SaveFaceBiopsyResultReq req) {
         //构建业务实体
         SaveFaceBiopsyResultResp resp = buildSaveFaceBiopsyResultResp(req.getExamRecordDataId(), req.getVerifySteps());
@@ -105,6 +115,7 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
 
     /**
      * 获取人脸活体检测开始分钟数
+     *
      * @param examRecordDataId 考试记录id
      * @return Integer
      */
@@ -142,6 +153,10 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
         boolean isInFreezeTime = calculateIsInFreezeTime(examRecordDataId);
 
         for (FaceBiopsyStepInfo stepInfo : verifySteps) {
+            if (stepInfo.getResult() == null) {
+                throw new StatusException("201005", "检测结果不允许为空");
+            }
+
             if (!stepInfo.getResult()) {
                 errorMsg = stepInfo.getErrorMsg();
             }
@@ -196,7 +211,6 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
      * @param finalIsSuccess
      * @param errorMsg
      */
-    @Transactional
     public void updateFaceBiopsyResult(Long examRecordDataId, Long faceBiopsyItemId, List<FaceBiopsyStepInfo> verifySteps,
                                        boolean finalIsSuccess, String errorMsg) {
         List<FaceBiopsyItemStepEntity> faceBiopsyItemStepEntityList =
@@ -276,7 +290,16 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
      * @return
      */
     private String getRelativePath(String resourceUrl) {
-        //TODO 待完善代码
+        if (!StringUtils.isNullOrEmpty(resourceUrl)) {
+            String domain = PropertyHolder.getString("$upyun.site.1.domain");
+            String backupDomain = PropertyHolder.getString("$upyun.site.1.domain.backup");
+            if (!StringUtils.isNullOrEmpty(domain)){
+                resourceUrl = resourceUrl.replace(domain, "");
+            }
+            if (!StringUtils.isNullOrEmpty(backupDomain)){
+                resourceUrl = resourceUrl.replace(backupDomain, "");
+            }
+        }
         return resourceUrl;
     }
 
@@ -288,7 +311,6 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
      * @param faceBiopsyType
      * @return
      */
-    @Transactional
     public FaceBiopsyInfo addFirstFaceBiopsy(Long rootOrgId, Long examRecordDataId, FaceBiopsyType faceBiopsyType) {
         //保存人脸活体检测相关信息
         Long faceBiopsyId = addFaceBiopsyEntity(rootOrgId, examRecordDataId);
@@ -405,6 +427,7 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
         faceBiopsyItemEntity.setExamRecordDataId(examRecordDataId);
         faceBiopsyItemEntity.setFaceBiopsyId(faceBiopsyId);
         faceBiopsyItemEntity.setFaceBiopsyType(faceBiopsyType);
+        faceBiopsyItemEntity.setCompleted(false);
         faceBiopsyItemRepo.save(faceBiopsyItemEntity);
         return faceBiopsyItemEntity.getId();
     }
@@ -542,12 +565,31 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
         }
     }
 
+    /**
+     * 是否允许冻结时间外添加人脸活体检测
+     *
+     * @param examId
+     * @param orgId
+     * @return
+     */
     private boolean addFaceVerifyOutFreezeTime(Long examId, Long orgId) {
         String addFaceVerifyOutFreezeTime = CacheHelper.getExamOrgProperty(examId, orgId,
                 ExamProperties.ADD_FACE_VERIFY_OUT_FREEZE_TIME.name()).getValue();
         return Constants.isTrue.equals(addFaceVerifyOutFreezeTime);
     }
 
+    /**
+     * 是否允许冻结时间外添加人脸活体检测
+     *
+     * @param examRecordDataId
+     * @return
+     */
+    private boolean addFaceVerifyOutFreezeTime(Long examRecordDataId) {
+        ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId,
+                ExamRecordDataEntity.class);
+        return addFaceVerifyOutFreezeTime(examRecordData.getExamId(), examRecordData.getOrgId());
+    }
+
     /**
      * 当前考试是否在冻结时间内
      *
@@ -560,7 +602,7 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
 
         ExamSessionInfo examSessionInfo = examSessionInfoService.getExamSessionInfo(examRecordData.getStudentId());
         if (examSessionInfo == null) {
-            throw new StatusException("201002", "考试会话已过期");
+            throw new StatusException("201003", "考试会话已过期");
         }
         Long usedMilliseconds = examControlService.calculateExamUsedMilliseconds(examSessionInfo);