|
@@ -1,23 +1,41 @@
|
|
|
package cn.com.qmth.examcloud.core.examwork.api.provider;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
+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.CourseCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
|
|
|
import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
|
|
|
import cn.com.qmth.examcloud.examwork.api.ExamStudentCloudService;
|
|
|
import cn.com.qmth.examcloud.examwork.api.bean.ExamStudentBean;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.CopyExamStudentsReq;
|
|
|
import cn.com.qmth.examcloud.examwork.api.request.SaveExamStudentReq;
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.CopyExamStudentsResp;
|
|
|
import cn.com.qmth.examcloud.examwork.api.response.SaveExamStudentResp;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
@@ -98,4 +116,94 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CopyExamStudentsResp copyExamStudents(@RequestBody CopyExamStudentsReq req) {
|
|
|
+
|
|
|
+ Long examId1 = req.getExamId1();
|
|
|
+ Long examId2 = req.getExamId2();
|
|
|
+
|
|
|
+ if (null == examId1) {
|
|
|
+ throw new StatusException("E-210001", "examId1 is null");
|
|
|
+ }
|
|
|
+ if (null == examId2) {
|
|
|
+ throw new StatusException("E-210002", "examId2 is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamEntity exam1 = examRepo.findOne(examId1);
|
|
|
+ ExamEntity exam2 = examRepo.findOne(examId2);
|
|
|
+ if (null == exam1) {
|
|
|
+ throw new StatusException("E-210003", "ExamEntity is null");
|
|
|
+ }
|
|
|
+ if (null == exam2) {
|
|
|
+ throw new StatusException("E-210004", "ExamEntity is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!exam1.getRootOrgId().equals(exam2.getRootOrgId())) {
|
|
|
+ throw new StatusException("E-210005", "examId1 and examId2 is not matched");
|
|
|
+ }
|
|
|
+
|
|
|
+ final Long rootOrgId = exam1.getRootOrgId();
|
|
|
+
|
|
|
+ final long start = null == req.getStart() ? 1 : req.getStart();
|
|
|
+
|
|
|
+ Pageable pageable = new PageRequest(0, 10, Sort.Direction.ASC, "id");
|
|
|
+
|
|
|
+ Specification<ExamStudentEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
+ predicates.add(cb.greaterThanOrEqualTo(root.get("id"), start));
|
|
|
+ predicates.add(cb.equal(root.get("examId"), examId1));
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ Page<ExamStudentEntity> page = examStudentRepo.findAll(specification, pageable);
|
|
|
+
|
|
|
+ Iterator<ExamStudentEntity> iterator = page.iterator();
|
|
|
+
|
|
|
+ List<Long> examStudentIds = Lists.newArrayList();
|
|
|
+
|
|
|
+ long next = start;
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ ExamStudentEntity es = iterator.next();
|
|
|
+
|
|
|
+ ExamStudentEntity finded = examStudentRepo.findByExamIdAndStudentIdAndCourseId(examId2,
|
|
|
+ es.getStudentId(), es.getCourseId());
|
|
|
+
|
|
|
+ if (null == finded) {
|
|
|
+ ExamStudentEntity one = new ExamStudentEntity();
|
|
|
+ one.setCourseId(es.getCourseId());
|
|
|
+ one.setEnable(es.getEnable());
|
|
|
+ one.setExamId(examId2);
|
|
|
+ one.setExamSite(es.getExamSite());
|
|
|
+ one.setGrade(es.getGrade());
|
|
|
+ one.setIdentityNumber(es.getIdentityNumber());
|
|
|
+ one.setInfoCollector(es.getInfoCollector());
|
|
|
+ one.setName(es.getName());
|
|
|
+ one.setOrgId(es.getOrgId());
|
|
|
+ one.setPaperType(es.getPaperType());
|
|
|
+ one.setRemark(es.getRemark());
|
|
|
+ one.setRootOrgId(es.getRootOrgId());
|
|
|
+ one.setSpecialtyName(es.getSpecialtyName());
|
|
|
+ one.setStudentCode(es.getStudentCode());
|
|
|
+ one.setStudentId(es.getStudentId());
|
|
|
+
|
|
|
+ ExamStudentEntity saved = examStudentRepo.save(one);
|
|
|
+ examStudentIds.add(saved.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ next = es.getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (next != start) {
|
|
|
+ next++;
|
|
|
+ }
|
|
|
+
|
|
|
+ CopyExamStudentsResp resp = new CopyExamStudentsResp();
|
|
|
+ resp.setNext(next);
|
|
|
+ resp.setExamStudentIds(examStudentIds);
|
|
|
+
|
|
|
+ return resp;
|
|
|
+ }
|
|
|
+
|
|
|
}
|