浏览代码

增加faceSet查询

chenken 7 年之前
父节点
当前提交
6d02d67228

+ 41 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/FaceSetTokenApi.java

@@ -0,0 +1,41 @@
+package cn.com.qmth.examcloud.service.core.api;
+
+import io.swagger.annotations.ApiOperation;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
+import cn.com.qmth.examcloud.service.core.service.FaceSetTokenService;
+
+/**
+ * @author  	chenken
+ * @date    	2018年1月23日 上午11:21:39
+ * @company 	QMTH
+ * @description FaceSetTokenApi.java
+ */
+@RestController
+@RequestMapping("${app.api.root}/faceSet")
+public class FaceSetTokenApi {
+	
+	@Autowired
+	private FaceSetTokenService faceSetTokenService;
+	
+	@ApiOperation(value="查询可用的faceSet",notes="查询可用的faceSet")
+    @GetMapping("/enableFaceSet")
+	public ResponseEntity<Object> getEnableFaceSet(){
+		try{
+			String faceSet = faceSetTokenService.getEnableFaceSet();
+			return new ResponseEntity<Object>(faceSet, HttpStatus.OK);
+		}catch(Exception e){
+			e.printStackTrace();
+			return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
+		}
+	}
+	
+}
+

+ 42 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/FaceSetTokenService.java

@@ -0,0 +1,42 @@
+package cn.com.qmth.examcloud.service.core.service;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.service.core.entity.FaceSetToken;
+import cn.com.qmth.examcloud.service.core.repo.FaceSetTokenRepo;
+
+/**
+ * @author  	chenken
+ * @date    	2018年1月23日 上午11:05:49
+ * @company 	QMTH
+ * @description FaceSetTokenService.java
+ */
+@Service("faceSetTokenService")
+public class FaceSetTokenService {
+	
+	@Autowired
+	private FaceSetTokenRepo faceSetTokenRepo;
+	
+	@Autowired
+	private StudentFaceInfoService studentFaceInfoService;
+	
+	/**
+	 * 获取可用的faceSet
+	 * @return
+	 */
+	public String getEnableFaceSet(){
+		List<FaceSetToken> faceSetList = faceSetTokenRepo.findAll();
+		for(FaceSetToken faceSetToken:faceSetList){
+			String faceSet = faceSetToken.getFaceSetToken();
+			if(studentFaceInfoService.judgeFaceSetIsAvailable(faceSet)){
+				return faceSet;
+			}
+		}
+		return null;
+	}
+	
+}
+

+ 19 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentFaceInfoService.java

@@ -1,12 +1,14 @@
 package cn.com.qmth.examcloud.service.core.service;
 
 import java.util.Date;
+import java.util.List;
 
 import javax.transaction.Transactional;
 
 import cn.com.qmth.examcloud.service.core.entity.Student;
 import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -45,5 +47,22 @@ public class StudentFaceInfoService {
     	old.setCreateType(studentFaceInfo.getCreateType());
         return studentFaceInfoRepo.save(old);
     }
+    
+    /**
+     * 判断faceSet是否可用
+     * faceSet在ecs_core_student_face_info表中的记录数不允许超过8000
+     * @param faceSet
+     * @return
+     */
+    public boolean judgeFaceSetIsAvailable(String faceSet){
+    	if(StringUtils.isBlank(faceSet)){
+    		return false;
+    	}
+    	List<StudentFaceInfo> studentFaceInfos = studentFaceInfoRepo.findByFaceSetToken(faceSet);
+    	if(studentFaceInfos==null||studentFaceInfos.size()<=8000){
+    		return true;
+    	}
+    	return false;
+    }
 
 }

+ 30 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/FaceSetToken.java

@@ -0,0 +1,30 @@
+package cn.com.qmth.examcloud.service.core.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author  	chenken
+ * @date    	2018年1月18日 下午3:43:53
+ * @company 	QMTH
+ * @description 1个faceSetToken中最多能存放10000个face_token,
+ * 这里的faceset_token是在ecs_faceset_token表中是预先存好的
+ */
+@Entity
+@Table(name = "ecs_faceset_token")
+public class FaceSetToken {
+	
+	@Id
+	private String faceSetToken;
+
+	public String getFaceSetToken() {
+		return faceSetToken;
+	}
+
+	public void setFaceSetToken(String faceSetToken) {
+		this.faceSetToken = faceSetToken;
+	}
+	
+}
+

+ 7 - 3
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Student.java

@@ -53,6 +53,13 @@ public class Student implements Serializable {
 	public static long getSerialVersionUID() {
 		return serialVersionUID;
 	}
+	
+	public Student() {
+	}
+
+	public Student(Long studentId) {
+		this.id = studentId;
+	}
 
 	public Long getId() {
 		return id;
@@ -149,7 +156,4 @@ public class Student implements Serializable {
 	public void setRootOrgId(Long rootOrgId) {
 		this.rootOrgId = rootOrgId;
 	}
-
-	public Student() {
-	}
 }

+ 1 - 2
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/StudentFaceInfo.java

@@ -115,8 +115,7 @@ public class StudentFaceInfo implements Serializable {
 		this.updateTime = updateTime;
 	}
 
-	public StudentFaceInfo() {
-	}
+	public StudentFaceInfo() {}
 
 	public String getCreateUser() {
 		return createUser;

+ 18 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/FaceSetTokenRepo.java

@@ -0,0 +1,18 @@
+package cn.com.qmth.examcloud.service.core.repo;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.service.core.entity.FaceSetToken;
+
+/**
+ * @author  	chenken
+ * @date    	2018年1月23日 上午11:01:58
+ * @company 	QMTH
+ * @description FaceSetTokenRepo.java
+ */
+public interface FaceSetTokenRepo  extends JpaRepository<FaceSetToken, Long>,QueryByExampleExecutor<FaceSetToken>, JpaSpecificationExecutor<FaceSetToken> {
+	
+}
+

+ 4 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/StudentFaceInfoRepo.java

@@ -1,5 +1,7 @@
 package cn.com.qmth.examcloud.service.core.repo;
 
+import java.util.List;
+
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
@@ -9,4 +11,6 @@ public interface StudentFaceInfoRepo extends JpaRepository<StudentFaceInfo,Long>
 
 	StudentFaceInfo findByStudentId(Long studentId);
 
+	
+	List<StudentFaceInfo> findByFaceSetToken(String faceSetToken);
 }