wangwei 6 years ago
parent
commit
b0ca57d773

+ 3 - 32
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/StudentFaceCloudServiceProvider.java

@@ -1,6 +1,5 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -8,15 +7,12 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.basic.api.StudentFaceCloudService;
-import cn.com.qmth.examcloud.core.basic.api.request.SaveStudentFaceInfoReq;
-import cn.com.qmth.examcloud.core.basic.api.response.SaveStudentFaceInfoResp;
+import cn.com.qmth.examcloud.core.basic.api.request.SaveStudentFaceReq;
+import cn.com.qmth.examcloud.core.basic.api.response.SaveStudentFaceResp;
 import cn.com.qmth.examcloud.core.basic.dao.StudentFaceRepo;
 import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
-import cn.com.qmth.examcloud.core.basic.dao.entity.StudentFaceEntity;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -44,33 +40,8 @@ public class StudentFaceCloudServiceProvider extends ControllerSupport
 	@ApiOperation(value = "保存学生人脸数据")
 	@PostMapping("saveStudentFaceInfo")
 	@Override
-	public SaveStudentFaceInfoResp saveStudentFaceInfo(@RequestBody SaveStudentFaceInfoReq req) {
+	public SaveStudentFaceResp saveStudentFace(@RequestBody SaveStudentFaceReq req) {
 
-//		String photoPath = req.getPhotoPath();
-//
-//		if (StringUtils.isBlank(photoPath)) {
-//			throw new StatusException("B-412001", "photoPath is blank");
-//		}
-//
-//		Long studentId = req.getStudentId();
-//		StudentEntity student = studentRepo.findOne(studentId);
-//		student.setPhotoPath(req.getPhotoPath());
-//		String operator = req.getOperator();
-//
-//		StudentFaceInfo studentFaceInfo = studentFaceInfoRepo.findByStudentId(student.getId());
-//		if (studentFaceInfo == null) {
-//			studentFaceInfo = new StudentFaceInfo();
-//			studentFaceInfo.setStudent(student);
-//			studentFaceInfo.setCreateUser(operator);
-//		}
-//
-//		studentFaceInfo.setUpdateUser(operator);
-//		studentFaceInfo.setFaceSetToken(req.getFaceSetToken());
-//		studentFaceInfo.setFaceToken(req.getFaceToken());
-//		StudentFaceInfo studentFaceInfoSave = studentFaceInfoRepo.save(studentFaceInfo);
-//
-//		SaveStudentFaceInfoResp resp = new SaveStudentFaceInfoResp();
-//		resp.setId(studentFaceInfoSave.getId());
 		return null;
 	}
 

+ 5 - 3
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/FacesetRepo.java

@@ -3,11 +3,13 @@ package cn.com.qmth.examcloud.core.basic.dao;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
-import cn.com.qmth.examcloud.core.basic.dao.entity.StudentFaceEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.FacesetEntity;
 
 public interface FacesetRepo
 		extends
-			JpaRepository<StudentFaceEntity, Long>,
-			QueryByExampleExecutor<StudentFaceEntity> {
+			JpaRepository<FacesetEntity, Long>,
+			QueryByExampleExecutor<FacesetEntity> {
+
+	FacesetEntity findByFacesetToken(String facesetToken);
 
 }

+ 3 - 3
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/StudentFaceRepo.java

@@ -3,11 +3,11 @@ package cn.com.qmth.examcloud.core.basic.dao;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
-import cn.com.qmth.examcloud.core.basic.dao.entity.FacesetEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentFaceEntity;
 
 public interface StudentFaceRepo
 		extends
-			JpaRepository<FacesetEntity, Long>,
-			QueryByExampleExecutor<FacesetEntity> {
+			JpaRepository<StudentFaceEntity, Long>,
+			QueryByExampleExecutor<StudentFaceEntity> {
 
 }

+ 24 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/StudentFaceService.java

@@ -0,0 +1,24 @@
+package cn.com.qmth.examcloud.core.basic.service;
+
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentFaceEntity;
+import cn.com.qmth.examcloud.core.basic.service.bean.StudentFaceInfo;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月3日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface StudentFaceService {
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param info
+	 * @return
+	 */
+	StudentFaceEntity saveStudentFace(StudentFaceInfo info);
+
+}

+ 76 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/StudentFaceInfo.java

@@ -0,0 +1,76 @@
+package cn.com.qmth.examcloud.core.basic.service.bean;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月3日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class StudentFaceInfo implements JsonSerializable {
+
+	private static final long serialVersionUID = -4210571202590959124L;
+
+	private Long rootOrgId;
+
+	private Long studentId;
+
+	private String faceToken;
+
+	private String facesetToken;
+
+	private String photoName;
+
+	private String operator;
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Long getStudentId() {
+		return studentId;
+	}
+
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
+	}
+
+	public String getFaceToken() {
+		return faceToken;
+	}
+
+	public void setFaceToken(String faceToken) {
+		this.faceToken = faceToken;
+	}
+
+	public String getFacesetToken() {
+		return facesetToken;
+	}
+
+	public void setFacesetToken(String facesetToken) {
+		this.facesetToken = facesetToken;
+	}
+
+	public String getPhotoName() {
+		return photoName;
+	}
+
+	public void setPhotoName(String photoName) {
+		this.photoName = photoName;
+	}
+
+	public String getOperator() {
+		return operator;
+	}
+
+	public void setOperator(String operator) {
+		this.operator = operator;
+	}
+
+}

+ 100 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentFaceServiceImpl.java

@@ -0,0 +1,100 @@
+package cn.com.qmth.examcloud.core.basic.service.impl;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.base.util.UrlUtil;
+import cn.com.qmth.examcloud.core.basic.dao.FacesetRepo;
+import cn.com.qmth.examcloud.core.basic.dao.StudentFaceRepo;
+import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.FacesetEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.StudentFaceEntity;
+import cn.com.qmth.examcloud.core.basic.service.StudentFaceService;
+import cn.com.qmth.examcloud.core.basic.service.bean.StudentFaceInfo;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月3日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class StudentFaceServiceImpl implements StudentFaceService {
+
+	@Autowired
+	StudentFaceRepo studentFaceRepo;
+
+	@Autowired
+	FacesetRepo facesetRepo;
+
+	@Autowired
+	StudentRepo studentRepo;
+
+	@Override
+	public StudentFaceEntity saveStudentFace(StudentFaceInfo info) {
+		String facesetToken = info.getFacesetToken();
+		String faceToken = info.getFaceToken();
+		String operator = info.getOperator();
+		String photoName = info.getPhotoName();
+		Long rootOrgId = info.getRootOrgId();
+		Long studentId = info.getStudentId();
+
+		if (null == studentId) {
+			throw new StatusException("B-680001", "studentId is null");
+		}
+		if (null == rootOrgId) {
+			throw new StatusException("B-680002", "rootOrgId is null");
+		}
+		if (StringUtils.isBlank(facesetToken)) {
+			throw new StatusException("B-680003", "facesetToken is null");
+		}
+		if (StringUtils.isBlank(faceToken)) {
+			throw new StatusException("B-680004", "faceToken is null");
+		}
+		if (StringUtils.isBlank(operator)) {
+			throw new StatusException("B-680005", "operator is null");
+		}
+		if (StringUtils.isBlank(photoName)) {
+			throw new StatusException("B-680006", "photoName is null");
+		}
+
+		StudentEntity studentEntity = studentRepo.findOne(studentId);
+
+		if (null == studentEntity) {
+			throw new StatusException("B-680007", "studentEntity is null");
+		}
+
+		if (!studentEntity.getRootOrgId().equals(rootOrgId)) {
+			throw new StatusException("B-680008", "studentId,rootOrgId is not matched");
+		}
+
+		String identityNumber = studentEntity.getIdentityNumber();
+
+		FacesetEntity facesetEntity = facesetRepo.findByFacesetToken(facesetToken);
+		if (null == facesetEntity) {
+			throw new StatusException("B-680003", "facesetEntity is null");
+		}
+
+		String photoPath = rootOrgId + "/" + UrlUtil.encode(identityNumber) + "/" + photoName;
+		studentEntity.setPhotoPath(photoPath);
+
+		StudentFaceEntity studentFaceEntity = studentFaceRepo.findOne(studentId);
+		if (null == studentFaceEntity) {
+			studentFaceEntity = new StudentFaceEntity();
+			studentFaceEntity.setStudentId(studentId);
+			studentFaceEntity.setCreator(operator);
+		}
+
+		studentFaceEntity.setFacesetId(facesetEntity.getId());
+		studentFaceEntity.setFaceToken(faceToken);
+		studentFaceEntity.setModifiedBy(operator);
+
+		studentRepo.save(studentEntity);
+		StudentFaceEntity saved = studentFaceRepo.save(studentFaceEntity);
+
+		return saved;
+	}
+
+}