|
@@ -1,374 +1,370 @@
|
|
|
-package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
|
|
|
-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.basic.api.bean.CourseBean;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamOrgSettingsRepo;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
|
|
|
-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.ExamCourseRelationEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
|
|
|
-import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
|
|
|
-import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
|
|
|
-import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
|
-import cn.com.qmth.examcloud.task.api.request.SyncExamStudentReq;
|
|
|
-
|
|
|
-/**
|
|
|
- * 考试学生服务类 Created by songyue on 17/1/14.
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class ExamStudentServiceImpl implements ExamStudentService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentRepo examStudentRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamRepo examRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamOrgSettingsRepo examOrgRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- OrgCloudService orgCloudService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamStudentServiceImpl examStudentService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- StudentCloudService studentCloudService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- CourseCloudService courseCloudService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamCourseRelationRepo examCourseRelationRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- DataSyncCloudService dataSyncCloudService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamRecordCloudService examRecordCloudService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
|
|
|
-
|
|
|
- /**
|
|
|
- * 是否强制删除考生
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean forceDeleteExamStudent() {
|
|
|
- boolean b = PropertiesUtil.getBoolean("$deleteExamStudent.force", false);
|
|
|
- return b;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 是否开考
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param examId
|
|
|
- * @param StudentId
|
|
|
- * @param courseId
|
|
|
- * @return
|
|
|
- */
|
|
|
- private boolean isStarted(Long examId, Long StudentId, Long courseId) {
|
|
|
- CheckExamIsStartedReq checkExamIsStartedReq = new CheckExamIsStartedReq();
|
|
|
- checkExamIsStartedReq.setExamId(examId);
|
|
|
- checkExamIsStartedReq.setCourseId(courseId);
|
|
|
- checkExamIsStartedReq.setStudentId(StudentId);
|
|
|
- CheckExamIsStartedResp checkExamIsStartedResp = examRecordCloudService
|
|
|
- .checkExamIsStarted(checkExamIsStartedReq);
|
|
|
- return checkExamIsStartedResp.getIsStarted();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param ids
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void deleteExamStudentsByStudentIds(List<Long> ids) {
|
|
|
- List<ExamStudentEntity> examStudents = examStudentRepo.findByIdIn(ids);
|
|
|
-
|
|
|
- for (ExamStudentEntity examStudent : examStudents) {
|
|
|
- // 网考判断
|
|
|
- if ((!forceDeleteExamStudent()) && isStarted(examStudent.getExamId(), null, null)) {
|
|
|
- throw new StatusException("E-150112", examStudent.getName() + "已开始考试,不能删除");
|
|
|
- }
|
|
|
- examStudentRepo.delete(examStudent);
|
|
|
-
|
|
|
- List<ExamStudentEntity> top2 = examStudentRepo.findTop2ByExamIdAndCourseId(
|
|
|
- examStudent.getExamId(), examStudent.getCourseId());
|
|
|
- if (1 > top2.size()) {
|
|
|
- examCourseRelationRepo.deleteByExamIdAndCourseId(examStudent.getExamId(),
|
|
|
- examStudent.getCourseId());
|
|
|
- }
|
|
|
-
|
|
|
- top2 = examStudentRepo.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
|
|
|
- examStudent.getCourseId(), examStudent.getPaperType());
|
|
|
- if (1 > top2.size()) {
|
|
|
- examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
|
|
|
- examStudent.getExamId(), examStudent.getCourseId(),
|
|
|
- examStudent.getPaperType());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (ExamStudentEntity cur : examStudents) {
|
|
|
- // 同步操作
|
|
|
- SyncExamStudentReq req = new SyncExamStudentReq();
|
|
|
- req.setSyncType("delete");
|
|
|
- req.setId(cur.getId());
|
|
|
- req.setCourseId(cur.getId());
|
|
|
- req.setCourseCode(cur.getCourseCode());
|
|
|
- req.setCourseName(cur.getCourseName());
|
|
|
- req.setExamId(cur.getId());
|
|
|
- req.setStudentId(cur.getStudentId());
|
|
|
- req.setStudentName(cur.getName());
|
|
|
- req.setIdentityNumber(cur.getIdentityNumber());
|
|
|
- req.setStudentCode(cur.getStudentCode());
|
|
|
- dataSyncCloudService.syncExamStudent(req);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param examId
|
|
|
- */
|
|
|
- @Override
|
|
|
- public void deleteExamStudentsByExamId(Long examId) {
|
|
|
- ExamEntity exam = examRepo.findOne(examId);
|
|
|
- // 已经开考
|
|
|
- if ((!forceDeleteExamStudent()) && isStarted(exam.getId(), null, null)) {
|
|
|
- throw new StatusException("E-150113", "该考试已开始,不能删除");
|
|
|
- }
|
|
|
- examStudentRepo.deleteByExamId(examId);
|
|
|
- examCourseRelationRepo.deleteByExamId(examId);
|
|
|
- examPaperTypeRelationRepo.deleteByExamId(examId);
|
|
|
-
|
|
|
- // 同步操作
|
|
|
- SyncExamStudentReq req = new SyncExamStudentReq();
|
|
|
- req.setSyncType("deleteByExamId");
|
|
|
- req.setExamId(examId);
|
|
|
- dataSyncCloudService.syncExamStudent(req);
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- * 实现
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- *
|
|
|
- * @see cn.com.qmth.examcloud.core.examwork.service.ExamStudentService#
|
|
|
- * saveExamStudent(cn.com.qmth.examcloud.core.examwork.service.bean.
|
|
|
- * ExamStudentInfo)
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ExamStudentInfo saveExamStudent(ExamStudentInfo examStudentInfo) {
|
|
|
- String paperType = examStudentInfo.getPaperType();
|
|
|
- if (StringUtils.isBlank(paperType)) {
|
|
|
- paperType = "X";
|
|
|
- } else if (!paperType.matches("[A-Z]")) {
|
|
|
- throw new StatusException("E-100020", "试卷类型必须为一个大写的英文字母");
|
|
|
- }
|
|
|
-
|
|
|
- Long rootOrgId = examStudentInfo.getRootOrgId();
|
|
|
- GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
- getOrgReq.setOrgId(rootOrgId);
|
|
|
- GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
- OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
- if (null != rootOrg.getParentId()) {
|
|
|
- throw new StatusException("E-100001", "rootOrgId is wrong");
|
|
|
- }
|
|
|
-
|
|
|
- ExamEntity exam = null;
|
|
|
- Long examId = examStudentInfo.getExamId();
|
|
|
- String examName = examStudentInfo.getExamName();
|
|
|
-
|
|
|
- if (null != examId) {
|
|
|
- exam = examRepo.findOne(examId);
|
|
|
- if (null == exam) {
|
|
|
- throw new StatusException("E-100020", "examId is wrong");
|
|
|
- }
|
|
|
- } else if (StringUtils.isBlank(examName)) {
|
|
|
- exam = examRepo.findByNameAndRootOrgId(examName, rootOrgId);
|
|
|
- if (null == exam) {
|
|
|
- throw new StatusException("E-100005", "考试不存在");
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new StatusException("E-100002", "examId & examName are both blank");
|
|
|
- }
|
|
|
-
|
|
|
- String identityNumber = examStudentInfo.getIdentityNumber();
|
|
|
-
|
|
|
- if (StringUtils.isBlank(identityNumber)) {
|
|
|
- throw new StatusException("E-100003", "identityNumber is null");
|
|
|
- }
|
|
|
- GetStudentReq getStudentReq = new GetStudentReq();
|
|
|
- getStudentReq.setRootOrgId(rootOrgId);
|
|
|
- getStudentReq.setIdentityNumber(identityNumber);
|
|
|
- GetStudentResp getStudentResp = studentCloudService.getStudent(getStudentReq);
|
|
|
-
|
|
|
- StudentBean studentInfo = getStudentResp.getStudentInfo();
|
|
|
-
|
|
|
- String courseCode = examStudentInfo.getCourseCode();
|
|
|
- String courseName = examStudentInfo.getCourseName();
|
|
|
- String courseLevel = examStudentInfo.getCourseLevel();
|
|
|
-
|
|
|
- SaveCourseReq saveCourseReq = new SaveCourseReq();
|
|
|
- saveCourseReq.setCourseId(examStudentInfo.getCourseId());
|
|
|
- saveCourseReq.setCourseCode(courseCode);
|
|
|
- saveCourseReq.setCourseName(courseName);
|
|
|
- saveCourseReq.setCourseLevel(courseLevel);
|
|
|
- saveCourseReq.setRootOrgId(rootOrgId);
|
|
|
-
|
|
|
- SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
|
|
|
- CourseBean courseBean = saveCourseResp.getCourseBean();
|
|
|
-
|
|
|
- ExamStudentEntity examStudent = examStudentRepo.findByExamIdAndStudentIdAndCourseId(
|
|
|
- exam.getId(), studentInfo.getId(), courseBean.getId());
|
|
|
-
|
|
|
- if (null == examStudent) {
|
|
|
- examStudent = new ExamStudentEntity();
|
|
|
- examStudent.setEnable(true);
|
|
|
- } else {
|
|
|
- if (!paperType.equals(examStudent.getPaperType())) {
|
|
|
- List<ExamStudentEntity> top2 = examStudentRepo
|
|
|
- .findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
|
|
|
- examStudent.getCourseId(), examStudent.getPaperType());
|
|
|
- if (2 > top2.size()) {
|
|
|
- examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
|
|
|
- examStudent.getExamId(), examStudent.getCourseId(),
|
|
|
- examStudent.getPaperType());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- examStudent.setInfoCollector(examStudentInfo.getInfoCollector());
|
|
|
- examStudent.setName(studentInfo.getName());
|
|
|
- examStudent.setRootOrgId(rootOrgId);
|
|
|
-
|
|
|
- examStudent.setCourseId(courseBean.getId());
|
|
|
- examStudent.setCourseName(courseBean.getName());
|
|
|
- examStudent.setCourseCode(courseBean.getCode());
|
|
|
- examStudent.setCourseLevel(courseBean.getLevel());
|
|
|
-
|
|
|
- examStudent.setExamId(exam.getId());
|
|
|
- examStudent.setIdentityNumber(studentInfo.getIdentityNumber());
|
|
|
- examStudent.setStudentCode(studentInfo.getStudentCode());
|
|
|
- examStudent.setPaperType(paperType);
|
|
|
- examStudent.setStudentId(studentInfo.getId());
|
|
|
- examStudent.setOrgId(studentInfo.getOrgId());
|
|
|
- examStudent.setOrgCode(studentInfo.getOrgCode());
|
|
|
- examStudent.setGrade(examStudentInfo.getGrade());
|
|
|
- examStudent.setSpecialtyName(examStudentInfo.getSpecialtyName());
|
|
|
- examStudent.setExamSite(examStudentInfo.getExamSite());
|
|
|
- examStudent.setRemark(examStudentInfo.getRemark());
|
|
|
-
|
|
|
- examStudent.setExt1(examStudentInfo.getExt1());
|
|
|
- examStudent.setExt2(examStudentInfo.getExt2());
|
|
|
- examStudent.setExt3(examStudentInfo.getExt3());
|
|
|
- examStudent.setExt4(examStudentInfo.getExt4());
|
|
|
- examStudent.setExt5(examStudentInfo.getExt5());
|
|
|
-
|
|
|
- ExamStudentEntity saved = examStudentRepo.save(examStudent);
|
|
|
-
|
|
|
- ExamCourseRelationEntity relation = new ExamCourseRelationEntity();
|
|
|
- relation.setExamId(saved.getExamId());
|
|
|
- relation.setCourseId(saved.getCourseId());
|
|
|
- relation.setCourseLevel(saved.getCourseLevel());
|
|
|
- relation.setCourseCode(courseBean.getCode());
|
|
|
- relation.setCourseName(saved.getCourseName());
|
|
|
- relation.setCourseEnable(courseBean.getEnable());
|
|
|
- examCourseRelationRepo.save(relation);
|
|
|
-
|
|
|
- ExamPaperTypeRelationEntity pt = new ExamPaperTypeRelationEntity();
|
|
|
- pt.setCourseId(saved.getCourseId());
|
|
|
- pt.setExamId(saved.getExamId());
|
|
|
- pt.setPaperType(saved.getPaperType());
|
|
|
- examPaperTypeRelationRepo.save(pt);
|
|
|
-
|
|
|
- // 同步操作
|
|
|
- SyncExamStudentReq req = new SyncExamStudentReq();
|
|
|
- req.setSyncType("update");
|
|
|
- req.setId(saved.getId());
|
|
|
-
|
|
|
- req.setCourseId(courseBean.getId());
|
|
|
- req.setCourseCode(courseBean.getCode());
|
|
|
- req.setCourseLevel(courseBean.getLevel());
|
|
|
- req.setCourseName(courseBean.getName());
|
|
|
-
|
|
|
- req.setExamId(exam.getId());
|
|
|
- req.setExamName(exam.getName());
|
|
|
-
|
|
|
- req.setRootOrgId(saved.getRootOrgId());
|
|
|
- req.setStudentId(studentInfo.getId());
|
|
|
- req.setStudentName(studentInfo.getName());
|
|
|
- req.setIdentityNumber(saved.getIdentityNumber());
|
|
|
- req.setStudentCode(saved.getStudentCode());
|
|
|
- req.setOrgId(studentInfo.getOrgId());
|
|
|
- req.setOrgName(studentInfo.getOrgName());
|
|
|
- req.setOrgCode(studentInfo.getOrgCode());
|
|
|
-
|
|
|
- req.setGrade(saved.getGrade());
|
|
|
- req.setSpecialtyName(saved.getSpecialtyName());
|
|
|
- req.setPaperType(saved.getPaperType());
|
|
|
- req.setRemark(saved.getRemark());
|
|
|
- req.setInfoCollector(saved.getInfoCollector());
|
|
|
- req.setExamSite(saved.getExamSite());
|
|
|
- dataSyncCloudService.syncExamStudent(req);
|
|
|
-
|
|
|
- ExamStudentInfo ret = new ExamStudentInfo();
|
|
|
- ret.setId(saved.getId());
|
|
|
-
|
|
|
- ret.setCourseId(courseBean.getId());
|
|
|
- ret.setCourseCode(courseBean.getCode());
|
|
|
- ret.setCourseLevel(courseBean.getLevel());
|
|
|
- ret.setCourseName(courseBean.getName());
|
|
|
-
|
|
|
- ret.setExamId(exam.getId());
|
|
|
- ret.setExamName(exam.getName());
|
|
|
-
|
|
|
- ret.setRootOrgId(saved.getRootOrgId());
|
|
|
- ret.setStudentName(studentInfo.getName());
|
|
|
- ret.setIdentityNumber(saved.getIdentityNumber());
|
|
|
- ret.setStudentCode(saved.getStudentCode());
|
|
|
- ret.setOrgId(studentInfo.getOrgId());
|
|
|
- ret.setOrgName(studentInfo.getOrgName());
|
|
|
- ret.setOrgCode(studentInfo.getOrgCode());
|
|
|
-
|
|
|
- ret.setPaperType(saved.getPaperType());
|
|
|
- ret.setRemark(saved.getRemark());
|
|
|
- ret.setInfoCollector(saved.getInfoCollector());
|
|
|
- ret.setExamSite(saved.getExamSite());
|
|
|
-
|
|
|
- return ret;
|
|
|
- }
|
|
|
-}
|
|
|
+package cn.com.qmth.examcloud.core.examwork.service.impl;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
|
|
|
+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.basic.api.bean.CourseBean;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.bean.StudentBean;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamCourseRelationRepo;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.ExamPaperTypeRelationRepo;
|
|
|
+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.ExamCourseRelationEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamPaperTypeRelationEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentEntity;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.ExamStudentService;
|
|
|
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.ExamRecordCloudService;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.request.CheckExamIsStartedReq;
|
|
|
+import cn.com.qmth.examcloud.core.oe.admin.api.response.CheckExamIsStartedResp;
|
|
|
+import cn.com.qmth.examcloud.task.api.DataSyncCloudService;
|
|
|
+import cn.com.qmth.examcloud.task.api.request.SyncExamStudentReq;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 考试学生服务类 Created by songyue on 17/1/14.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExamStudentServiceImpl implements ExamStudentService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentRepo examStudentRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRepo examRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrgCloudService orgCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamStudentServiceImpl examStudentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StudentCloudService studentCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CourseCloudService courseCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamCourseRelationRepo examCourseRelationRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DataSyncCloudService dataSyncCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamRecordCloudService examRecordCloudService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExamPaperTypeRelationRepo examPaperTypeRelationRepo;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否强制删除考生
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean forceDeleteExamStudent() {
|
|
|
+ boolean b = PropertiesUtil.getBoolean("$deleteExamStudent.force", false);
|
|
|
+ return b;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否开考
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ * @param StudentId
|
|
|
+ * @param courseId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private boolean isStarted(Long examId, Long StudentId, Long courseId) {
|
|
|
+ CheckExamIsStartedReq checkExamIsStartedReq = new CheckExamIsStartedReq();
|
|
|
+ checkExamIsStartedReq.setExamId(examId);
|
|
|
+ checkExamIsStartedReq.setCourseId(courseId);
|
|
|
+ checkExamIsStartedReq.setStudentId(StudentId);
|
|
|
+ CheckExamIsStartedResp checkExamIsStartedResp = examRecordCloudService
|
|
|
+ .checkExamIsStarted(checkExamIsStartedReq);
|
|
|
+ return checkExamIsStartedResp.getIsStarted();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteExamStudentsByStudentIds(List<Long> ids) {
|
|
|
+ List<ExamStudentEntity> examStudents = examStudentRepo.findByIdIn(ids);
|
|
|
+
|
|
|
+ for (ExamStudentEntity examStudent : examStudents) {
|
|
|
+ // 网考判断
|
|
|
+ if ((!forceDeleteExamStudent()) && isStarted(examStudent.getExamId(), null, null)) {
|
|
|
+ throw new StatusException("E-150112", examStudent.getName() + "已开始考试,不能删除");
|
|
|
+ }
|
|
|
+ examStudentRepo.delete(examStudent);
|
|
|
+
|
|
|
+ List<ExamStudentEntity> top2 = examStudentRepo.findTop2ByExamIdAndCourseId(
|
|
|
+ examStudent.getExamId(), examStudent.getCourseId());
|
|
|
+ if (1 > top2.size()) {
|
|
|
+ examCourseRelationRepo.deleteByExamIdAndCourseId(examStudent.getExamId(),
|
|
|
+ examStudent.getCourseId());
|
|
|
+ }
|
|
|
+
|
|
|
+ top2 = examStudentRepo.findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
|
|
|
+ examStudent.getCourseId(), examStudent.getPaperType());
|
|
|
+ if (1 > top2.size()) {
|
|
|
+ examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
|
|
|
+ examStudent.getExamId(), examStudent.getCourseId(),
|
|
|
+ examStudent.getPaperType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (ExamStudentEntity cur : examStudents) {
|
|
|
+ // 同步操作
|
|
|
+ SyncExamStudentReq req = new SyncExamStudentReq();
|
|
|
+ req.setSyncType("delete");
|
|
|
+ req.setId(cur.getId());
|
|
|
+ req.setCourseId(cur.getId());
|
|
|
+ req.setCourseCode(cur.getCourseCode());
|
|
|
+ req.setCourseName(cur.getCourseName());
|
|
|
+ req.setExamId(cur.getId());
|
|
|
+ req.setStudentId(cur.getStudentId());
|
|
|
+ req.setStudentName(cur.getName());
|
|
|
+ req.setIdentityNumber(cur.getIdentityNumber());
|
|
|
+ req.setStudentCode(cur.getStudentCode());
|
|
|
+ dataSyncCloudService.syncExamStudent(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void deleteExamStudentsByExamId(Long examId) {
|
|
|
+ ExamEntity exam = examRepo.findOne(examId);
|
|
|
+ // 已经开考
|
|
|
+ if ((!forceDeleteExamStudent()) && isStarted(exam.getId(), null, null)) {
|
|
|
+ throw new StatusException("E-150113", "该考试已开始,不能删除");
|
|
|
+ }
|
|
|
+ examStudentRepo.deleteByExamId(examId);
|
|
|
+ examCourseRelationRepo.deleteByExamId(examId);
|
|
|
+ examPaperTypeRelationRepo.deleteByExamId(examId);
|
|
|
+
|
|
|
+ // 同步操作
|
|
|
+ SyncExamStudentReq req = new SyncExamStudentReq();
|
|
|
+ req.setSyncType("deleteByExamId");
|
|
|
+ req.setExamId(examId);
|
|
|
+ dataSyncCloudService.syncExamStudent(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 实现
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ *
|
|
|
+ * @see cn.com.qmth.examcloud.core.examwork.service.ExamStudentService#
|
|
|
+ * saveExamStudent(cn.com.qmth.examcloud.core.examwork.service.bean.
|
|
|
+ * ExamStudentInfo)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ExamStudentInfo saveExamStudent(ExamStudentInfo examStudentInfo) {
|
|
|
+ String paperType = examStudentInfo.getPaperType();
|
|
|
+ if (StringUtils.isBlank(paperType)) {
|
|
|
+ paperType = "X";
|
|
|
+ } else if (!paperType.matches("[A-Z]")) {
|
|
|
+ throw new StatusException("E-100020", "试卷类型必须为一个大写的英文字母");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long rootOrgId = examStudentInfo.getRootOrgId();
|
|
|
+ GetOrgReq getOrgReq = new GetOrgReq();
|
|
|
+ getOrgReq.setOrgId(rootOrgId);
|
|
|
+ GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
|
|
|
+ OrgBean rootOrg = getOrgResp.getOrg();
|
|
|
+ if (null != rootOrg.getParentId()) {
|
|
|
+ throw new StatusException("E-100001", "rootOrgId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ ExamEntity exam = null;
|
|
|
+ Long examId = examStudentInfo.getExamId();
|
|
|
+ String examName = examStudentInfo.getExamName();
|
|
|
+
|
|
|
+ if (null != examId) {
|
|
|
+ exam = examRepo.findOne(examId);
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("E-100020", "examId is wrong");
|
|
|
+ }
|
|
|
+ } else if (StringUtils.isBlank(examName)) {
|
|
|
+ exam = examRepo.findByNameAndRootOrgId(examName, rootOrgId);
|
|
|
+ if (null == exam) {
|
|
|
+ throw new StatusException("E-100005", "考试不存在");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new StatusException("E-100002", "examId & examName are both blank");
|
|
|
+ }
|
|
|
+
|
|
|
+ String identityNumber = examStudentInfo.getIdentityNumber();
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(identityNumber)) {
|
|
|
+ throw new StatusException("E-100003", "identityNumber is null");
|
|
|
+ }
|
|
|
+ GetStudentReq getStudentReq = new GetStudentReq();
|
|
|
+ getStudentReq.setRootOrgId(rootOrgId);
|
|
|
+ getStudentReq.setIdentityNumber(identityNumber);
|
|
|
+ GetStudentResp getStudentResp = studentCloudService.getStudent(getStudentReq);
|
|
|
+
|
|
|
+ StudentBean studentInfo = getStudentResp.getStudentInfo();
|
|
|
+
|
|
|
+ String courseCode = examStudentInfo.getCourseCode();
|
|
|
+ String courseName = examStudentInfo.getCourseName();
|
|
|
+ String courseLevel = examStudentInfo.getCourseLevel();
|
|
|
+
|
|
|
+ SaveCourseReq saveCourseReq = new SaveCourseReq();
|
|
|
+ saveCourseReq.setCourseId(examStudentInfo.getCourseId());
|
|
|
+ saveCourseReq.setCourseCode(courseCode);
|
|
|
+ saveCourseReq.setCourseName(courseName);
|
|
|
+ saveCourseReq.setCourseLevel(courseLevel);
|
|
|
+ saveCourseReq.setRootOrgId(rootOrgId);
|
|
|
+
|
|
|
+ SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
|
|
|
+ CourseBean courseBean = saveCourseResp.getCourseBean();
|
|
|
+
|
|
|
+ ExamStudentEntity examStudent = examStudentRepo.findByExamIdAndStudentIdAndCourseId(
|
|
|
+ exam.getId(), studentInfo.getId(), courseBean.getId());
|
|
|
+
|
|
|
+ if (null == examStudent) {
|
|
|
+ examStudent = new ExamStudentEntity();
|
|
|
+ examStudent.setEnable(true);
|
|
|
+ } else {
|
|
|
+ if (!paperType.equals(examStudent.getPaperType())) {
|
|
|
+ List<ExamStudentEntity> top2 = examStudentRepo
|
|
|
+ .findTop2ByExamIdAndCourseIdAndPaperType(examStudent.getExamId(),
|
|
|
+ examStudent.getCourseId(), examStudent.getPaperType());
|
|
|
+ if (2 > top2.size()) {
|
|
|
+ examPaperTypeRelationRepo.deleteByExamIdAndCourseIdAndPaperType(
|
|
|
+ examStudent.getExamId(), examStudent.getCourseId(),
|
|
|
+ examStudent.getPaperType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ examStudent.setInfoCollector(examStudentInfo.getInfoCollector());
|
|
|
+ examStudent.setName(studentInfo.getName());
|
|
|
+ examStudent.setRootOrgId(rootOrgId);
|
|
|
+
|
|
|
+ examStudent.setCourseId(courseBean.getId());
|
|
|
+ examStudent.setCourseName(courseBean.getName());
|
|
|
+ examStudent.setCourseCode(courseBean.getCode());
|
|
|
+ examStudent.setCourseLevel(courseBean.getLevel());
|
|
|
+
|
|
|
+ examStudent.setExamId(exam.getId());
|
|
|
+ examStudent.setIdentityNumber(studentInfo.getIdentityNumber());
|
|
|
+ examStudent.setStudentCode(studentInfo.getStudentCode());
|
|
|
+ examStudent.setPaperType(paperType);
|
|
|
+ examStudent.setStudentId(studentInfo.getId());
|
|
|
+ examStudent.setOrgId(studentInfo.getOrgId());
|
|
|
+ examStudent.setOrgCode(studentInfo.getOrgCode());
|
|
|
+ examStudent.setGrade(examStudentInfo.getGrade());
|
|
|
+ examStudent.setSpecialtyName(examStudentInfo.getSpecialtyName());
|
|
|
+ examStudent.setExamSite(examStudentInfo.getExamSite());
|
|
|
+ examStudent.setRemark(examStudentInfo.getRemark());
|
|
|
+
|
|
|
+ examStudent.setExt1(examStudentInfo.getExt1());
|
|
|
+ examStudent.setExt2(examStudentInfo.getExt2());
|
|
|
+ examStudent.setExt3(examStudentInfo.getExt3());
|
|
|
+ examStudent.setExt4(examStudentInfo.getExt4());
|
|
|
+ examStudent.setExt5(examStudentInfo.getExt5());
|
|
|
+
|
|
|
+ ExamStudentEntity saved = examStudentRepo.save(examStudent);
|
|
|
+
|
|
|
+ ExamCourseRelationEntity relation = new ExamCourseRelationEntity();
|
|
|
+ relation.setExamId(saved.getExamId());
|
|
|
+ relation.setCourseId(saved.getCourseId());
|
|
|
+ relation.setCourseLevel(saved.getCourseLevel());
|
|
|
+ relation.setCourseCode(courseBean.getCode());
|
|
|
+ relation.setCourseName(saved.getCourseName());
|
|
|
+ relation.setCourseEnable(courseBean.getEnable());
|
|
|
+ examCourseRelationRepo.save(relation);
|
|
|
+
|
|
|
+ ExamPaperTypeRelationEntity pt = new ExamPaperTypeRelationEntity();
|
|
|
+ pt.setCourseId(saved.getCourseId());
|
|
|
+ pt.setExamId(saved.getExamId());
|
|
|
+ pt.setPaperType(saved.getPaperType());
|
|
|
+ examPaperTypeRelationRepo.save(pt);
|
|
|
+
|
|
|
+ // 同步操作
|
|
|
+ SyncExamStudentReq req = new SyncExamStudentReq();
|
|
|
+ req.setSyncType("update");
|
|
|
+ req.setId(saved.getId());
|
|
|
+
|
|
|
+ req.setCourseId(courseBean.getId());
|
|
|
+ req.setCourseCode(courseBean.getCode());
|
|
|
+ req.setCourseLevel(courseBean.getLevel());
|
|
|
+ req.setCourseName(courseBean.getName());
|
|
|
+
|
|
|
+ req.setExamId(exam.getId());
|
|
|
+ req.setExamName(exam.getName());
|
|
|
+
|
|
|
+ req.setRootOrgId(saved.getRootOrgId());
|
|
|
+ req.setStudentId(studentInfo.getId());
|
|
|
+ req.setStudentName(studentInfo.getName());
|
|
|
+ req.setIdentityNumber(saved.getIdentityNumber());
|
|
|
+ req.setStudentCode(saved.getStudentCode());
|
|
|
+ req.setOrgId(studentInfo.getOrgId());
|
|
|
+ req.setOrgName(studentInfo.getOrgName());
|
|
|
+ req.setOrgCode(studentInfo.getOrgCode());
|
|
|
+
|
|
|
+ req.setGrade(saved.getGrade());
|
|
|
+ req.setSpecialtyName(saved.getSpecialtyName());
|
|
|
+ req.setPaperType(saved.getPaperType());
|
|
|
+ req.setRemark(saved.getRemark());
|
|
|
+ req.setInfoCollector(saved.getInfoCollector());
|
|
|
+ req.setExamSite(saved.getExamSite());
|
|
|
+ dataSyncCloudService.syncExamStudent(req);
|
|
|
+
|
|
|
+ ExamStudentInfo ret = new ExamStudentInfo();
|
|
|
+ ret.setId(saved.getId());
|
|
|
+
|
|
|
+ ret.setCourseId(courseBean.getId());
|
|
|
+ ret.setCourseCode(courseBean.getCode());
|
|
|
+ ret.setCourseLevel(courseBean.getLevel());
|
|
|
+ ret.setCourseName(courseBean.getName());
|
|
|
+
|
|
|
+ ret.setExamId(exam.getId());
|
|
|
+ ret.setExamName(exam.getName());
|
|
|
+
|
|
|
+ ret.setRootOrgId(saved.getRootOrgId());
|
|
|
+ ret.setStudentName(studentInfo.getName());
|
|
|
+ ret.setIdentityNumber(saved.getIdentityNumber());
|
|
|
+ ret.setStudentCode(saved.getStudentCode());
|
|
|
+ ret.setOrgId(studentInfo.getOrgId());
|
|
|
+ ret.setOrgName(studentInfo.getOrgName());
|
|
|
+ ret.setOrgCode(studentInfo.getOrgCode());
|
|
|
+
|
|
|
+ ret.setPaperType(saved.getPaperType());
|
|
|
+ ret.setRemark(saved.getRemark());
|
|
|
+ ret.setInfoCollector(saved.getInfoCollector());
|
|
|
+ ret.setExamSite(saved.getExamSite());
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+}
|