wangwei 7 роки тому
батько
коміт
668b689119

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

@@ -2,20 +2,31 @@ package cn.com.qmth.examcloud.core.examwork.api.provider;
 
 import java.util.List;
 
+import javax.transaction.Transactional;
+
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-import cn.com.qmth.examcloud.commons.base.util.BeanCopierUtil;
 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.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.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
-import cn.com.qmth.examcloud.core.examwork.dao.bean.ExamStudentDTO;
+import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudent;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentService;
 import cn.com.qmth.examcloud.examwork.api.ExamStudentCloudService;
@@ -28,21 +39,31 @@ import cn.com.qmth.examcloud.examwork.api.request.SaveExamStudentReq;
  * @company QMTH
  * @description ExamStudentProvider.java
  */
+@Transactional
 @RestController
 @RequestMapping("${$rmp.cloud.examwork}" + "examStudent")
 public class ExamStudentCloudServiceProvider extends ControllerSupport
 		implements
 			ExamStudentCloudService {
 
+	@Autowired
+	ExamRepo examRepo;
+
 	@Autowired
 	OrgCloudService orgCloudService;
 
 	@Autowired
 	ExamStudentService examStudentService;
 
+	@Autowired
+	StudentCloudService studentCloudService;
+
 	@Autowired
 	ExamStudentRepo examStudentRepo;
 
+	@Autowired
+	CourseCloudService courseCloudService;
+
 	@Override
 	public void saveExamStudent(SaveExamStudentReq req) {
 
@@ -55,6 +76,25 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 			throw new StatusException("E-100001", "rootOrgId is wrong");
 		}
 
+		Exam exam = null;
+		Long examId = req.getExamId();
+		if (null == examId) {
+			String examName = req.getExamName();
+			if (StringUtils.isBlank(examName)) {
+				throw new StatusException("E-100002", "examId & examName are both blank");
+			}
+			List<Exam> examList = examRepo.findByNameAndRootOrgId(examName, rootOrgId);
+			if (CollectionUtils.isEmpty(examList)) {
+				throw new StatusException("E-100005", "考试不存在");
+			}
+			if (1 < examList.size()) {
+				throw new StatusException("E-100005", "考试名称对应多个考试");
+			}
+			exam = examList.get(0);
+		} else {
+			exam = examRepo.findOne(examId);
+		}
+
 		String studentCode = req.getStudentCode();
 		String identityNumber = req.getIdentityNumber();
 
@@ -65,27 +105,45 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 		if (StringUtils.isBlank(identityNumber)) {
 			throw new StatusException("E-100003", "identityNumber is null");
 		}
+		GetStudentReq getStudentReq = new GetStudentReq();
+		getStudentReq.setRootOrgId(rootOrgId);
+		getStudentReq.setStudentCode(studentCode);
+		getStudentReq.setIdentityNumber(identityNumber);
+		GetStudentResp getStudentResp = studentCloudService.getStudent(getStudentReq);
 
-		ExamStudentDTO examStudentDto = new ExamStudentDTO();
-		examStudentDto.setExamId(req.getExamId());
-		examStudentDto.setCourseCode(req.getCourseCode());
-		examStudentDto.setIdentityNumber(req.getIdentityNumber());
-		List<ExamStudent> examStudents = examStudentService.getAllExamStudent(examStudentDto);
-		if (examStudents != null && examStudents.size() > 0) {
-			ExamStudent examStudentOld = examStudents.get(0);
-			// 更新相关的姓名、学习中心、专业
-			// examStudentOld.setName(examStudentReq.getStudentName());
-			// examStudentOld.setOrgId(examStudentReq.getOrgId());
-			// examStudentOld.setOrgCode(examStudentReq.getOrgCode());
-			// examStudentOld.setOrgName(examStudentReq.getOrgName());
-			// examStudentOld.setRootOrgId(examStudentReq.getRootOrgId());
-			// examStudentOld.setSpecialtyName(examStudentReq.getSpecialtyName());
-			examStudentRepo.save(examStudentOld);
-		} else {
-			ExamStudent examStudent = BeanCopierUtil.copyProperties(req, ExamStudent.class);
-			examStudent.setFinished(false);
-			examStudentRepo.save(examStudent);
+		StudentBean studentInfo = getStudentResp.getStudentInfo();
+
+		String courseCode = req.getCourseCode();
+		String courseName = req.getCourseName();
+		String courseLevel = req.getCourseLevel();
+
+		SaveCourseReq saveCourseReq = new SaveCourseReq();
+		saveCourseReq.setCourseCode(courseCode);
+		saveCourseReq.setCourseName(courseName);
+		saveCourseReq.setCourseLevel(courseLevel);
+		saveCourseReq.setRootOrgId(rootOrgId);
+
+		SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
+		CourseBean courseBean = saveCourseResp.getCourseBean();
+
+		List<ExamStudent> examStudentList = examStudentRepo.findByExamIdAndStudentIdAndCourseCode(
+				exam.getId(), studentInfo.getId(), courseBean.getCode());
+
+		if (CollectionUtils.isNotEmpty(examStudentList)) {
+			examStudentRepo.deleteInBatch(examStudentList);
 		}
+
+		ExamStudent examStudent = new ExamStudent();
+		examStudent.setName(studentInfo.getName());
+		examStudent.setRootOrgId(rootOrgId);
+		examStudent.setCourseCode(courseCode);
+		examStudent.setCourseName(courseName);
+		examStudent.setCourseLevel(courseBean.getLevel());
+		examStudent.setExam(exam);
+		examStudent.setPaperType(req.getPaperType());
+
+		examStudentRepo.save(examStudent);
+
 	}
 
 }

+ 3 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamStudentRepo.java

@@ -73,4 +73,7 @@ public interface ExamStudentRepo extends JpaRepository<ExamStudent, Long>, Query
     
     @Query(value = "SELECT * FROM ecs_exam_student t WHERE t.exam_id = ?1 order by id desc limit ?2,?3 ",nativeQuery = true)
     public List<ExamStudent> findByLimit(Long examId,Integer startLimit,Integer endLimit);
+    
+    @Query("select s from ExamStudent s where s.examId=?1 and s.studentId=?2 and s.courseCode=?3")
+    List<ExamStudent> findByExamIdAndStudentIdAndCourseCode(Long examId,Long studentId, String courseCode);
 }