wangwei před 6 roky
rodič
revize
651f82a9ae

+ 1 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamStudentController.java

@@ -208,6 +208,7 @@ public class ExamStudentController extends ControllerSupport {
 			bean.setExamType(exam.getExamType().name());
 			bean.setUpdateTime(cur.getUpdateTime());
 			bean.setEnable(cur.getEnable());
+			bean.setLocked(exam.getExamStudentLocked());
 			ret.add(bean);
 		}
 		return new PageInfo<ExamStudentDomain>(examStudents, ret);

+ 10 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/bean/ExamStudentDomain.java

@@ -79,6 +79,8 @@ public class ExamStudentDomain implements JsonSerializable {
 
 	private Boolean enable;
 
+	private Boolean locked;
+
 	public Long getId() {
 		return id;
 	}
@@ -287,4 +289,12 @@ public class ExamStudentDomain implements JsonSerializable {
 		this.enable = enable;
 	}
 
+	public Boolean getLocked() {
+		return locked;
+	}
+
+	public void setLocked(Boolean locked) {
+		this.locked = locked;
+	}
+
 }

+ 36 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamCloudServiceProvider.java

@@ -42,13 +42,17 @@ import cn.com.qmth.examcloud.examwork.api.bean.ExamBean;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamPropertyReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetOngoingExamListReq;
+import cn.com.qmth.examcloud.examwork.api.request.LockExamStudentsReq;
 import cn.com.qmth.examcloud.examwork.api.request.SaveExamReq;
 import cn.com.qmth.examcloud.examwork.api.request.SetExamPropertyReq;
+import cn.com.qmth.examcloud.examwork.api.request.UnlockExamStudentsReq;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamPropertyResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetOngoingExamListResp;
+import cn.com.qmth.examcloud.examwork.api.response.LockExamStudentsResp;
 import cn.com.qmth.examcloud.examwork.api.response.SaveExamResp;
 import cn.com.qmth.examcloud.examwork.api.response.SetExamPropertyResp;
+import cn.com.qmth.examcloud.examwork.api.response.UnlockExamStudentsResp;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -266,4 +270,36 @@ public class ExamCloudServiceProvider extends ControllerSupport implements ExamC
 		return resp;
 	}
 
+	@Override
+	public LockExamStudentsResp lockExamStudents(@RequestBody LockExamStudentsReq req) {
+		Long examId = req.getExamId();
+		if (null == examId) {
+			throw new StatusException("E-002001", "examId is null");
+		}
+		ExamEntity exam = examRepo.findOne(examId);
+		if (null == exam) {
+			throw new StatusException("E-002002", "ExamEntity is null");
+		}
+		exam.setExamStudentLocked(true);
+		examRepo.save(exam);
+		LockExamStudentsResp resp = new LockExamStudentsResp();
+		return resp;
+	}
+
+	@Override
+	public UnlockExamStudentsResp unlockExamStudents(@RequestBody UnlockExamStudentsReq req) {
+		Long examId = req.getExamId();
+		if (null == examId) {
+			throw new StatusException("E-002001", "examId is null");
+		}
+		ExamEntity exam = examRepo.findOne(examId);
+		if (null == exam) {
+			throw new StatusException("E-002002", "ExamEntity is null");
+		}
+		exam.setExamStudentLocked(false);
+		examRepo.save(exam);
+		UnlockExamStudentsResp resp = new UnlockExamStudentsResp();
+		return resp;
+	}
+
 }

+ 108 - 0
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/provider/ExamStudentCloudServiceProvider.java

@@ -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;
+	}
+
 }

+ 13 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamEntity.java

@@ -79,6 +79,11 @@ public class ExamEntity extends JpaEntity {
 	 */
 	private Long examTimes;
 
+	/**
+	 * 考生锁定(为trues时,不能更新考生)
+	 */
+	private Boolean examStudentLocked;
+
 	public Long getId() {
 		return id;
 	}
@@ -159,4 +164,12 @@ public class ExamEntity extends JpaEntity {
 		this.examTimes = examTimes;
 	}
 
+	public Boolean getExamStudentLocked() {
+		return examStudentLocked;
+	}
+
+	public void setExamStudentLocked(Boolean examStudentLocked) {
+		this.examStudentLocked = examStudentLocked;
+	}
+
 }