|
@@ -1,168 +1,168 @@
|
|
|
-package cn.com.qmth.examcloud.core.basic.service.impl;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import javax.persistence.criteria.Predicate;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.domain.Sort.Direction;
|
|
|
-import org.springframework.data.jpa.domain.Specification;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-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.FaceService;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.bean.StudentFaceInfo;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.cache.StudentCache;
|
|
|
-import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
-
|
|
|
-/**
|
|
|
- * 类注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @date 2018年9月3日
|
|
|
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class FaceServiceImpl implements FaceService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StudentFaceRepo studentFaceRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- FacesetRepo facesetRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StudentRepo studentRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StudentCache studentCache;
|
|
|
-
|
|
|
- @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();
|
|
|
- Long faceCount = info.getFaceCount();
|
|
|
-
|
|
|
- if (null == studentId) {
|
|
|
- throw new StatusException("680001", "studentId is null");
|
|
|
- }
|
|
|
- if (null == rootOrgId) {
|
|
|
- throw new StatusException("680002", "rootOrgId is null");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(facesetToken)) {
|
|
|
- throw new StatusException("680003", "facesetToken is null");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(faceToken)) {
|
|
|
- throw new StatusException("680004", "faceToken is null");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(operator)) {
|
|
|
- throw new StatusException("680005", "operator is null");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(photoName)) {
|
|
|
- throw new StatusException("680006", "photoName is null");
|
|
|
- }
|
|
|
- if (!photoName.matches("\\w+\\.\\w+")) {
|
|
|
- throw new StatusException("680006", "photoName is wrong");
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isBlank(photoName)) {
|
|
|
- throw new StatusException("680015", "photoTreatyPath is null");
|
|
|
- }
|
|
|
-
|
|
|
- if (null == faceCount) {
|
|
|
- throw new StatusException("680008", "faceCount is null");
|
|
|
- }
|
|
|
- if (1 > faceCount) {
|
|
|
- throw new StatusException("680013", "faceCount is less than 1");
|
|
|
- }
|
|
|
-
|
|
|
- StudentEntity studentEntity = GlobalHelper.getEntity(studentRepo, studentId,
|
|
|
- StudentEntity.class);
|
|
|
-
|
|
|
- if (null == studentEntity) {
|
|
|
- throw new StatusException("680009", "studentEntity is null");
|
|
|
- }
|
|
|
-
|
|
|
- if (!studentEntity.getRootOrgId().equals(rootOrgId)) {
|
|
|
- throw new StatusException("680010", "studentId,rootOrgId is not matched");
|
|
|
- }
|
|
|
-
|
|
|
- FacesetEntity facesetEntity = facesetRepo.findByFacesetToken(facesetToken);
|
|
|
- if (null == facesetEntity) {
|
|
|
- throw new StatusException("680011", "facesetEntity is null");
|
|
|
- }
|
|
|
-
|
|
|
-// String photoPath = rootOrgId + "/" + studentId + "/" + photoName;
|
|
|
- String photoPath =info.getPhotoTreatyPath();
|
|
|
- studentEntity.setPhotoPath(photoPath);
|
|
|
-
|
|
|
- StudentFaceEntity studentFaceEntity = GlobalHelper.getEntity(studentFaceRepo, studentId,
|
|
|
- StudentFaceEntity.class);
|
|
|
- if (null == studentFaceEntity) {
|
|
|
- studentFaceEntity = new StudentFaceEntity();
|
|
|
- studentFaceEntity.setStudentId(studentId);
|
|
|
- studentFaceEntity.setCreator(operator);
|
|
|
- }
|
|
|
-
|
|
|
- studentFaceEntity.setFacesetId(facesetEntity.getId());
|
|
|
- studentFaceEntity.setFaceToken(faceToken);
|
|
|
- studentFaceEntity.setModifiedBy(operator);
|
|
|
-
|
|
|
- if (null == facesetEntity.getFaceCount() || facesetEntity.getFaceCount() < faceCount) {
|
|
|
- facesetEntity.setFaceCount(faceCount);
|
|
|
- }
|
|
|
-
|
|
|
- facesetRepo.save(facesetEntity);
|
|
|
- studentRepo.save(studentEntity);
|
|
|
- StudentFaceEntity saved = studentFaceRepo.save(studentFaceEntity);
|
|
|
-
|
|
|
- studentCache.remove(studentId);
|
|
|
-
|
|
|
- return saved;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<FacesetEntity> getUsableFacesetList() {
|
|
|
-
|
|
|
- Specification<FacesetEntity> specification = (root, query, cb) -> {
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
- predicates.add(cb.lessThan(root.get("faceCount"), 8000));
|
|
|
- predicates.add(cb.equal(root.get("enable"), true));
|
|
|
-
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
- };
|
|
|
-
|
|
|
- PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Direction.DESC, "updateTime"));
|
|
|
-
|
|
|
- Page<FacesetEntity> studentList = facesetRepo.findAll(specification, pageRequest);
|
|
|
-
|
|
|
- Iterator<FacesetEntity> iterator = studentList.iterator();
|
|
|
-
|
|
|
- List<FacesetEntity> list = Lists.newArrayList();
|
|
|
-
|
|
|
- while (iterator.hasNext()) {
|
|
|
- list.add(iterator.next());
|
|
|
- }
|
|
|
-
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+// package cn.com.qmth.examcloud.core.basic.service.impl;
|
|
|
+//
|
|
|
+// import java.util.ArrayList;
|
|
|
+// import java.util.Iterator;
|
|
|
+// import java.util.List;
|
|
|
+//
|
|
|
+// import javax.persistence.criteria.Predicate;
|
|
|
+//
|
|
|
+// import org.apache.commons.lang3.StringUtils;
|
|
|
+// import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+// import org.springframework.data.domain.Page;
|
|
|
+// import org.springframework.data.domain.PageRequest;
|
|
|
+// import org.springframework.data.domain.Sort;
|
|
|
+// import org.springframework.data.domain.Sort.Direction;
|
|
|
+// import org.springframework.data.jpa.domain.Specification;
|
|
|
+// import org.springframework.stereotype.Service;
|
|
|
+//
|
|
|
+// import com.google.common.collect.Lists;
|
|
|
+//
|
|
|
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+// 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.FaceService;
|
|
|
+// import cn.com.qmth.examcloud.core.basic.service.bean.StudentFaceInfo;
|
|
|
+// import cn.com.qmth.examcloud.core.basic.service.cache.StudentCache;
|
|
|
+// import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 类注释
|
|
|
+// *
|
|
|
+// * @author WANGWEI
|
|
|
+// * @date 2018年9月3日
|
|
|
+// * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+// */
|
|
|
+// @Service
|
|
|
+// public class FaceServiceImpl implements FaceService {
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// StudentFaceRepo studentFaceRepo;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// FacesetRepo facesetRepo;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// StudentRepo studentRepo;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// StudentCache studentCache;
|
|
|
+//
|
|
|
+// @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();
|
|
|
+// Long faceCount = info.getFaceCount();
|
|
|
+//
|
|
|
+// if (null == studentId) {
|
|
|
+// throw new StatusException("680001", "studentId is null");
|
|
|
+// }
|
|
|
+// if (null == rootOrgId) {
|
|
|
+// throw new StatusException("680002", "rootOrgId is null");
|
|
|
+// }
|
|
|
+// if (StringUtils.isBlank(facesetToken)) {
|
|
|
+// throw new StatusException("680003", "facesetToken is null");
|
|
|
+// }
|
|
|
+// if (StringUtils.isBlank(faceToken)) {
|
|
|
+// throw new StatusException("680004", "faceToken is null");
|
|
|
+// }
|
|
|
+// if (StringUtils.isBlank(operator)) {
|
|
|
+// throw new StatusException("680005", "operator is null");
|
|
|
+// }
|
|
|
+// if (StringUtils.isBlank(photoName)) {
|
|
|
+// throw new StatusException("680006", "photoName is null");
|
|
|
+// }
|
|
|
+// if (!photoName.matches("\\w+\\.\\w+")) {
|
|
|
+// throw new StatusException("680006", "photoName is wrong");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (StringUtils.isBlank(photoName)) {
|
|
|
+// throw new StatusException("680015", "photoTreatyPath is null");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (null == faceCount) {
|
|
|
+// throw new StatusException("680008", "faceCount is null");
|
|
|
+// }
|
|
|
+// if (1 > faceCount) {
|
|
|
+// throw new StatusException("680013", "faceCount is less than 1");
|
|
|
+// }
|
|
|
+//
|
|
|
+// StudentEntity studentEntity = GlobalHelper.getEntity(studentRepo, studentId,
|
|
|
+// StudentEntity.class);
|
|
|
+//
|
|
|
+// if (null == studentEntity) {
|
|
|
+// throw new StatusException("680009", "studentEntity is null");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!studentEntity.getRootOrgId().equals(rootOrgId)) {
|
|
|
+// throw new StatusException("680010", "studentId,rootOrgId is not matched");
|
|
|
+// }
|
|
|
+//
|
|
|
+// FacesetEntity facesetEntity = facesetRepo.findByFacesetToken(facesetToken);
|
|
|
+// if (null == facesetEntity) {
|
|
|
+// throw new StatusException("680011", "facesetEntity is null");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // String photoPath = rootOrgId + "/" + studentId + "/" + photoName;
|
|
|
+// String photoPath =info.getPhotoTreatyPath();
|
|
|
+// studentEntity.setPhotoPath(photoPath);
|
|
|
+//
|
|
|
+// StudentFaceEntity studentFaceEntity = GlobalHelper.getEntity(studentFaceRepo, studentId,
|
|
|
+// StudentFaceEntity.class);
|
|
|
+// if (null == studentFaceEntity) {
|
|
|
+// studentFaceEntity = new StudentFaceEntity();
|
|
|
+// studentFaceEntity.setStudentId(studentId);
|
|
|
+// studentFaceEntity.setCreator(operator);
|
|
|
+// }
|
|
|
+//
|
|
|
+// studentFaceEntity.setFacesetId(facesetEntity.getId());
|
|
|
+// studentFaceEntity.setFaceToken(faceToken);
|
|
|
+// studentFaceEntity.setModifiedBy(operator);
|
|
|
+//
|
|
|
+// if (null == facesetEntity.getFaceCount() || facesetEntity.getFaceCount() < faceCount) {
|
|
|
+// facesetEntity.setFaceCount(faceCount);
|
|
|
+// }
|
|
|
+//
|
|
|
+// facesetRepo.save(facesetEntity);
|
|
|
+// studentRepo.save(studentEntity);
|
|
|
+// StudentFaceEntity saved = studentFaceRepo.save(studentFaceEntity);
|
|
|
+//
|
|
|
+// studentCache.remove(studentId);
|
|
|
+//
|
|
|
+// return saved;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<FacesetEntity> getUsableFacesetList() {
|
|
|
+//
|
|
|
+// Specification<FacesetEntity> specification = (root, query, cb) -> {
|
|
|
+// List<Predicate> predicates = new ArrayList<>();
|
|
|
+// predicates.add(cb.lessThan(root.get("faceCount"), 8000));
|
|
|
+// predicates.add(cb.equal(root.get("enable"), true));
|
|
|
+//
|
|
|
+// return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+// };
|
|
|
+//
|
|
|
+// PageRequest pageRequest = PageRequest.of(0, 10, Sort.by(Direction.DESC, "updateTime"));
|
|
|
+//
|
|
|
+// Page<FacesetEntity> studentList = facesetRepo.findAll(specification, pageRequest);
|
|
|
+//
|
|
|
+// Iterator<FacesetEntity> iterator = studentList.iterator();
|
|
|
+//
|
|
|
+// List<FacesetEntity> list = Lists.newArrayList();
|
|
|
+//
|
|
|
+// while (iterator.hasNext()) {
|
|
|
+// list.add(iterator.next());
|
|
|
+// }
|
|
|
+//
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+// }
|