Browse Source

完善代码

lideyin 5 years ago
parent
commit
bf1cdbe1e7

+ 66 - 6
examcloud-core-oe-student-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/student/controller/FaceBiopsyController.java

@@ -4,15 +4,13 @@ import cn.com.qmth.examcloud.api.commons.security.bean.User;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.core.oe.common.base.Constants;
 import cn.com.qmth.examcloud.core.oe.common.base.Constants;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
+import cn.com.qmth.examcloud.core.oe.common.entity.FaceBiopsyItemStepEntity;
 import cn.com.qmth.examcloud.core.oe.common.enums.ExamProperties;
 import cn.com.qmth.examcloud.core.oe.common.enums.ExamProperties;
 import cn.com.qmth.examcloud.core.oe.common.enums.FaceBiopsyType;
 import cn.com.qmth.examcloud.core.oe.common.enums.FaceBiopsyType;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemStepRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemStepRepo;
-import cn.com.qmth.examcloud.core.oe.student.bean.ExamSessionInfo;
-import cn.com.qmth.examcloud.core.oe.student.bean.FaceBiopsyInfo;
-import cn.com.qmth.examcloud.core.oe.student.bean.SaveFaceBiopsyResultReq;
-import cn.com.qmth.examcloud.core.oe.student.bean.SaveFaceBiopsyResultResp;
+import cn.com.qmth.examcloud.core.oe.student.bean.*;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamSessionInfoService;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamSessionInfoService;
 import cn.com.qmth.examcloud.core.oe.student.service.FaceBiopsyService;
 import cn.com.qmth.examcloud.core.oe.student.service.FaceBiopsyService;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
@@ -24,6 +22,8 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
+import java.util.List;
+
 /**
 /**
  * @Description 人脸活体检测接口
  * @Description 人脸活体检测接口
  * @Author lideyin
  * @Author lideyin
@@ -81,7 +81,67 @@ public class FaceBiopsyController extends ControllerSupport {
     @ApiOperation(value = "保存活体检测结果")
     @ApiOperation(value = "保存活体检测结果")
     @PostMapping("/saveFaceBiopsyResult")
     @PostMapping("/saveFaceBiopsyResult")
     public SaveFaceBiopsyResultResp saveFaceBiopsyResult(@RequestBody SaveFaceBiopsyResultReq req) {
     public SaveFaceBiopsyResultResp saveFaceBiopsyResult(@RequestBody SaveFaceBiopsyResultReq req) {
-        SaveFaceBiopsyResultResp result = new SaveFaceBiopsyResultResp();
-        return result;
+        User user = getAccessUser();
+        Long studentId = user.getUserId();
+        String sequenceLockKey = Constants.GET_FACE_BIOPSY_INFO_PREFIX + studentId;
+        //系统在请求结束后会,自动释放锁,无需手动解锁
+        SequenceLockHelper.getLock(sequenceLockKey);
+
+        if (req.getExamRecordDataId() == null) {
+            throw new StatusException("200104", "考试记录id不允许为空");
+        }
+        //判断考试记录id是否有效
+        ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, req.getExamRecordDataId(),
+                ExamRecordDataEntity.class);
+        if (examRecordData == null) {
+            throw new StatusException("200101", "无效的考试记录");
+        }
+        if (req.getFaceBiopsyItemId() == null) {
+            throw new StatusException("200105", "人脸活体检测明细id不允许为空");
+        }
+        if (req.getVerifySteps() == null || req.getVerifySteps().isEmpty()) {
+            throw new StatusException("200106", "活体检测步骤不允许为空");
+        }
+
+        if (req.getVerifySteps().stream().anyMatch(p -> p.getStepId() == null)) {
+            throw new StatusException("200107", "活体检测步骤id不允许为空");
+        }
+
+        if (req.getVerifySteps().stream().anyMatch(p -> p.getAction() == null)) {
+            throw new StatusException("200107", "活体检测执行动作不允许为空");
+        }
+
+        if (verifyStepsAllMatch(req.getFaceBiopsyItemId(), req.getVerifySteps())) {
+            throw new StatusException("200108", "活体检测步骤与原始定义不匹配");
+        }
+
+        return faceBiopsyService.saveFaceBiopsyResult(req);
+    }
+
+    /**
+     * 校验活检步骤和原始步骤是否匹配
+     *
+     * @param faceBiopsyItemId
+     * @param verifySteps
+     * @return
+     */
+    private boolean verifyStepsAllMatch(Long faceBiopsyItemId, List<FaceBiopsyStepInfo> verifySteps) {
+        List<FaceBiopsyItemStepEntity> originalVerifySteps = faceBiopsyItemStepRepo.findByFaceBiopsyItemId(faceBiopsyItemId);
+
+        if (originalVerifySteps == null || originalVerifySteps.isEmpty() ||
+                originalVerifySteps.size() != verifySteps.size()) {
+            return false;
+        }
+
+        for (int i=0;i<originalVerifySteps.size();i++){
+            FaceBiopsyItemStepEntity originalStep = originalVerifySteps.get(i);
+            FaceBiopsyStepInfo newStep = verifySteps.get(i);
+            //如果步骤id和动作不同时匹配,则认为不匹配
+            if (!(originalStep.getId().equals(newStep.getStepId()) &&
+                    originalStep.getAction().equals(newStep.getAction()))){
+                return false;
+            }
+        }
+        return true;
     }
     }
 }
 }

+ 58 - 1
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/FaceBiopsyStepInfo.java

@@ -2,6 +2,7 @@ package cn.com.qmth.examcloud.core.oe.student.bean;
 
 
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
 import cn.com.qmth.examcloud.core.oe.common.enums.FaceBiopsyAction;
 import cn.com.qmth.examcloud.core.oe.common.enums.FaceBiopsyAction;
+import cn.com.qmth.examcloud.core.oe.common.enums.ResourceType;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModelProperty;
 
 
 import javax.persistence.EnumType;
 import javax.persistence.EnumType;
@@ -24,9 +25,25 @@ public class FaceBiopsyStepInfo implements JsonSerializable {
 	@Enumerated(EnumType.STRING)
 	@Enumerated(EnumType.STRING)
 	private FaceBiopsyAction action;
 	private FaceBiopsyAction action;
 
 
-	@ApiModelProperty(value = "动作时长",required = false)
+	@ApiModelProperty(value = "动作时长")
 	private Integer stay;
 	private Integer stay;
 
 
+	@ApiModelProperty(value = "资源文件路径")
+	private String resourceUrl;
+
+	@ApiModelProperty(value = "资源文件类型")
+	@Enumerated(EnumType.STRING)
+	private ResourceType resourceType;
+
+	@ApiModelProperty(value = "执行结果")
+	private Boolean result;
+
+	@ApiModelProperty(value = "指令执行结果json串")
+	private String resultJson;
+
+	@ApiModelProperty(value = "错误描述")
+	private String errorMsg;
+
 	public Long getStepId() {
 	public Long getStepId() {
 		return stepId;
 		return stepId;
 	}
 	}
@@ -50,4 +67,44 @@ public class FaceBiopsyStepInfo implements JsonSerializable {
 	public void setStay(Integer stay) {
 	public void setStay(Integer stay) {
 		this.stay = stay;
 		this.stay = stay;
 	}
 	}
+
+	public String getResourceUrl() {
+		return resourceUrl;
+	}
+
+	public void setResourceUrl(String resourceUrl) {
+		this.resourceUrl = resourceUrl;
+	}
+
+	public ResourceType getResourceType() {
+		return resourceType;
+	}
+
+	public void setResourceType(ResourceType resourceType) {
+		this.resourceType = resourceType;
+	}
+
+	public Boolean getResult() {
+		return result;
+	}
+
+	public void setResult(Boolean result) {
+		this.result = result;
+	}
+
+	public String getResultJson() {
+		return resultJson;
+	}
+
+	public void setResultJson(String resultJson) {
+		this.resultJson = resultJson;
+	}
+
+	public String getErrorMsg() {
+		return errorMsg;
+	}
+
+	public void setErrorMsg(String errorMsg) {
+		this.errorMsg = errorMsg;
+	}
 }
 }

+ 2 - 2
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/bean/SaveFaceBiopsyResultReq.java

@@ -1,7 +1,7 @@
 package cn.com.qmth.examcloud.core.oe.student.bean;
 package cn.com.qmth.examcloud.core.oe.student.bean;
 
 
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-import com.sun.tools.javac.util.List;
+import java.util.List;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiModelProperty;
 
 
 /**
 /**
@@ -16,7 +16,7 @@ public class SaveFaceBiopsyResultReq implements JsonSerializable {
 	@ApiModelProperty(value = "考试记录id",required = true)
 	@ApiModelProperty(value = "考试记录id",required = true)
 	private Long examRecordDataId;
 	private Long examRecordDataId;
 
 
-	@ApiModelProperty(value = "人脸活体检测明细id",required = false)
+	@ApiModelProperty(value = "人脸活体检测明细id",required = true)
 	private Long faceBiopsyItemId;
 	private Long faceBiopsyItemId;
 
 
 	@ApiModelProperty(value = "实际活体检测步骤",required = true)
 	@ApiModelProperty(value = "实际活体检测步骤",required = true)

+ 8 - 0
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/FaceBiopsyService.java

@@ -2,6 +2,8 @@ package cn.com.qmth.examcloud.core.oe.student.service;
 
 
 import cn.com.qmth.examcloud.core.oe.common.enums.FaceBiopsyType;
 import cn.com.qmth.examcloud.core.oe.common.enums.FaceBiopsyType;
 import cn.com.qmth.examcloud.core.oe.student.bean.FaceBiopsyInfo;
 import cn.com.qmth.examcloud.core.oe.student.bean.FaceBiopsyInfo;
+import cn.com.qmth.examcloud.core.oe.student.bean.SaveFaceBiopsyResultReq;
+import cn.com.qmth.examcloud.core.oe.student.bean.SaveFaceBiopsyResultResp;
 
 
 import java.util.Date;
 import java.util.Date;
 
 
@@ -21,4 +23,10 @@ public interface FaceBiopsyService {
      */
      */
     FaceBiopsyInfo getFaceBiopsyInfo(Long rootOrgId, Long examRecordDataId,FaceBiopsyType faceBiopsyType);
     FaceBiopsyInfo getFaceBiopsyInfo(Long rootOrgId, Long examRecordDataId,FaceBiopsyType faceBiopsyType);
 
 
+    /**
+     * 保存活体检测结果
+     * @param req
+     * @return
+     */
+    SaveFaceBiopsyResultResp saveFaceBiopsyResult(SaveFaceBiopsyResultReq req);
 }
 }

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

@@ -14,9 +14,7 @@ import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemStepRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyItemStepRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.FaceBiopsyRepo;
-import cn.com.qmth.examcloud.core.oe.student.bean.ExamSessionInfo;
-import cn.com.qmth.examcloud.core.oe.student.bean.FaceBiopsyInfo;
-import cn.com.qmth.examcloud.core.oe.student.bean.FaceBiopsyStepInfo;
+import cn.com.qmth.examcloud.core.oe.student.bean.*;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamSessionInfoService;
 import cn.com.qmth.examcloud.core.oe.student.service.ExamSessionInfoService;
 import cn.com.qmth.examcloud.core.oe.student.service.FaceBiopsyService;
 import cn.com.qmth.examcloud.core.oe.student.service.FaceBiopsyService;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
@@ -91,6 +89,15 @@ public class FaceBiopsyServiceImpl implements FaceBiopsyService {
         return appendFaceBiopsy(faceBiopsyEntity.getId(), verifiedTimes, examRecordDataId, faceBiopsyType);
         return appendFaceBiopsy(faceBiopsyEntity.getId(), verifiedTimes, examRecordDataId, faceBiopsyType);
     }
     }
 
 
+    @Override
+    public SaveFaceBiopsyResultResp saveFaceBiopsyResult(SaveFaceBiopsyResultReq req) {
+        List<FaceBiopsyStepInfo> verifySteps = req.getVerifySteps();
+        for (int i=0;i<verifySteps.size();i++){
+
+        }
+        return null;
+    }
+
     /**
     /**
      * 第一次添加人脸活体检测结果
      * 第一次添加人脸活体检测结果
      *
      *

+ 77 - 1
examcloud-core-oe-student-service/src/main/java/cn/com/qmth/examcloud/core/oe/student/service/impl/OfflineExamServiceImpl.java

@@ -1,15 +1,18 @@
 package cn.com.qmth.examcloud.core.oe.student.service.impl;
 package cn.com.qmth.examcloud.core.oe.student.service.impl;
 
 
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
+import cn.com.qmth.examcloud.commons.util.HttpClientUtil;
 import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
 import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordDataEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordForMarkingEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamRecordForMarkingEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.oe.common.entity.ExamStudentEntity;
+import cn.com.qmth.examcloud.core.oe.common.entity.OfflineFileEntity;
 import cn.com.qmth.examcloud.core.oe.common.enums.ExamRecordStatus;
 import cn.com.qmth.examcloud.core.oe.common.enums.ExamRecordStatus;
 import cn.com.qmth.examcloud.core.oe.common.enums.ExamType;
 import cn.com.qmth.examcloud.core.oe.common.enums.ExamType;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordForMarkingRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamRecordForMarkingRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamStudentRepo;
 import cn.com.qmth.examcloud.core.oe.common.repository.ExamStudentRepo;
+import cn.com.qmth.examcloud.core.oe.common.repository.OfflineFileRepo;
 import cn.com.qmth.examcloud.core.oe.common.service.GainBaseDataService;
 import cn.com.qmth.examcloud.core.oe.common.service.GainBaseDataService;
 import cn.com.qmth.examcloud.core.oe.student.bean.OfflineExamCourseInfo;
 import cn.com.qmth.examcloud.core.oe.student.bean.OfflineExamCourseInfo;
 import cn.com.qmth.examcloud.core.oe.student.service.*;
 import cn.com.qmth.examcloud.core.oe.student.service.*;
@@ -20,17 +23,35 @@ import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.OrgCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
 import cn.com.qmth.examcloud.support.cache.bean.SysPropertyCacheBean;
+import cn.com.qmth.examcloud.web.facepp.FaceppClient;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import main.java.com.UpYun;
 import main.java.com.UpYun;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.io.FileUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.CookieSpecs;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
-import java.io.File;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 
 /**
 /**
  * @author chenken
  * @author chenken
@@ -65,6 +86,9 @@ public class OfflineExamServiceImpl implements OfflineExamService {
     @Autowired
     @Autowired
     private ExamRecordForMarkingRepo examRecordForMarkingRepo;
     private ExamRecordForMarkingRepo examRecordForMarkingRepo;
 
 
+    @Autowired
+    private OfflineFileRepo offlineFileRepo;
+
     @Value("${$upyun.site.1.bucketName}")
     @Value("${$upyun.site.1.bucketName}")
     private String bucketName;
     private String bucketName;
 
 
@@ -237,6 +261,56 @@ public class OfflineExamServiceImpl implements OfflineExamService {
         examRecordDataRepo.save(examRecordDataEntity);
         examRecordDataRepo.save(examRecordDataEntity);
     }
     }
 
 
+    @Override
+    public void downOfflineExam() {
+        List<OfflineFileEntity> list = offlineFileRepo.findAll();
+        for (int i = 0; i < list.size(); i++) {
+            OfflineFileEntity fileEntity = list.get(i);
+            String fileUrl = fileEntity.getFileUrl();
+            System.out.println((i + 1) + "开始下载文件:" + fileEntity.getFileUrl());
+
+            //对fileUrl中的中文进行编码
+            fileUrl = encode(fileUrl, "utf-8");
+
+            byte[] bs;
+            try {
+                bs = HttpClientUtil.get(fileUrl);
+            }catch (Exception e){
+                System.err.println((i + 1) + "文件:" + fileEntity.getFileUrl() + "下载失败,继续下一个文件...");
+                e.printStackTrace();
+                continue;
+            }
+
+            String suffix = fileUrl.substring(fileUrl.lastIndexOf("."));
+            String filePath = "d:/data/" + fileEntity.getStudentCode() + "_" + fileEntity.getCourseCode() + suffix;
+            File file = new File(filePath);
+            try {
+                FileUtils.writeByteArrayToFile(file, bs);
+                System.out.println((i + 1) + "文件:" + fileEntity.getFileUrl() + "下载完毕...");
+                System.out.println("剩余" + (list.size() - i - 1) + "个文件待下载...");
+            } catch (IOException e) {
+                throw new StatusException("100003", "文件读写失败");
+            }
+        }
+    }
+
+    private static String encode(String url, String chartSet) {
+        try {
+            Matcher matcher = Pattern.compile("[^\\x00-\\xff]").matcher(url);//双字节,包括中文和中文符号[^\x00-\xff]  中文[\u4e00-\u9fa5]
+            while (matcher.find()) {
+                String tmp = matcher.group();
+                url = url.replaceAll(tmp, java.net.URLEncoder.encode(tmp, chartSet));
+            }
+        } catch (UnsupportedEncodingException e) {
+            try {
+                throw e;
+            } catch (UnsupportedEncodingException e1) {
+                e1.printStackTrace();
+            }
+        }
+        return url;
+    }
+
     private String createOfflineFileName(ExamRecordDataEntity examRecordDataEntity) {
     private String createOfflineFileName(ExamRecordDataEntity examRecordDataEntity) {
         long currentTime = System.currentTimeMillis();
         long currentTime = System.currentTimeMillis();
 
 
@@ -249,4 +323,6 @@ public class OfflineExamServiceImpl implements OfflineExamService {
                 examRecordDataEntity.getStudentName() + "_" +
                 examRecordDataEntity.getStudentName() + "_" +
                 courseBean.getCode() + "_" + currentTime;
                 courseBean.getCode() + "_" + currentTime;
     }
     }
+
+
 }
 }