wangwei 7 年之前
父節點
當前提交
b17ea11faa

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

@@ -44,6 +44,9 @@ import cn.com.qmth.examcloud.common.dto.examwork.CommonExamStudent;
 import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
+import cn.com.qmth.examcloud.core.basic.api.request.InsertOrUpdateStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.response.InsertOrUpdateStudentResp;
 import cn.com.qmth.examcloud.core.examwork.api.controller.bean.ExamStudentDomain;
 import cn.com.qmth.examcloud.core.examwork.base.util.ExportUtils;
 import cn.com.qmth.examcloud.core.examwork.base.util.ImportUtils;
@@ -52,9 +55,12 @@ import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.bean.ExamStudentAssembler;
 import cn.com.qmth.examcloud.core.examwork.dao.bean.ExamStudentDTO;
 import cn.com.qmth.examcloud.core.examwork.dao.bean.OrgExamInfoDTO;
-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;
+import cn.com.qmth.examcloud.examwork.api.bean.ExamStudentBean;
+import cn.com.qmth.examcloud.examwork.api.request.SaveExamStudentReq;
+import cn.com.qmth.examcloud.examwork.api.response.SaveExamStudentResp;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -78,6 +84,12 @@ public class ExamStudentController extends ControllerSupport {
 	@Autowired
 	ExamRepo examRepo;
 
+	@Autowired
+	StudentCloudService studentCloudService;
+
+	@Autowired
+	ExamStudentCloudService examStudentCloudService;
+
 	@GetMapping("/query")
 	public List<ExamStudent> find(
 			@RequestParam(value = "student_id", required = false) Long studentId) {
@@ -120,9 +132,9 @@ public class ExamStudentController extends ControllerSupport {
 			if (null != examCriteria.getExamId()) {
 				predicates.add(cb.equal(root.get("exam").get("id"), examCriteria.getExamId()));
 			}
-			if (StringUtils.isNotEmpty(examCriteria.getName())) {
-				predicates
-						.add(cb.like(root.get("name"), toSqlSearchPattern(examCriteria.getName())));
+			if (StringUtils.isNotEmpty(examCriteria.getStudentName())) {
+				predicates.add(cb.like(root.get("name"),
+						toSqlSearchPattern(examCriteria.getStudentName())));
 			}
 			if (StringUtils.isNotEmpty(examCriteria.getStudentCode())) {
 				predicates.add(cb.like(root.get("studentCode"),
@@ -165,7 +177,7 @@ public class ExamStudentController extends ControllerSupport {
 		for (ExamStudent cur : examStudents) {
 			ExamStudentDomain bean = new ExamStudentDomain();
 			bean.setId(cur.getId());
-			bean.setName(cur.getName());
+			bean.setStudentName(cur.getName());
 			bean.setStudentCode(cur.getStudentCode());
 			bean.setIdentityNumber(cur.getIdentityNumber());
 			bean.setCourseCode(cur.getCourseCode());
@@ -232,41 +244,81 @@ public class ExamStudentController extends ControllerSupport {
 		return new ResponseEntity(examStudentService.findById(id), HttpStatus.OK);
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param request
+	 * @param examStudent
+	 * @return
+	 */
 	@ApiOperation(value = "新增考试学生", notes = "新增")
 	@PostMapping()
-	public ExamStudent addExamStudent(HttpServletRequest request,
-			@RequestBody ExamStudent examStudent) {
-
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (accessUser != null) {
-			examStudent.setRootOrgId(accessUser.getRootOrgId());
-		}
-		Exam exam = examRepo.findOne(examStudent.getExam().getId());
-		examStudent.setExam(exam);
-		if (StringUtils.isEmpty(examStudent.getPaperType())) {
-			examStudent.setPaperType("O");
-		}
-		if (null == examStudent.getFinished()) {
-			examStudent.setFinished(false);
-		}
-		ExamStudent saveExamStu = examStudentService.saveExamStudent(accessUser.getUserToken(),
-				examStudent);
-		return saveExamStu;
+	public ExamStudentDomain addExamStudent(HttpServletRequest request,
+			@RequestBody ExamStudentDomain examStudent) {
+		return saveExamStudent(examStudent);
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param examStudent
+	 * @return
+	 */
 	@ApiOperation(value = "更新考试学生", notes = "更新")
 	@PutMapping()
-	public ExamStudent updateExamStudent(@RequestBody ExamStudent examStudent) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+	public ExamStudentDomain updateExamStudent(@RequestBody ExamStudentDomain examStudent) {
+		return saveExamStudent(examStudent);
+	}
 
-		Exam exam = examRepo.findOne(examStudent.getExam().getId());
-		examStudent.setExam(exam);
-		if (StringUtils.isEmpty(examStudent.getPaperType())) {
-			examStudent.setPaperType("O");
-		}
-		ExamStudent saveExamStu = examStudentService.saveExamStudent(accessUser.getUserToken(),
-				examStudent);
-		return saveExamStu;
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param examStudent
+	 * @return
+	 */
+	private ExamStudentDomain saveExamStudent(ExamStudentDomain examStudent) {
+		InsertOrUpdateStudentReq saveStudentReq = new InsertOrUpdateStudentReq();
+		saveStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
+		saveStudentReq.setName(examStudent.getStudentName());
+		saveStudentReq.setPhoneNumber(examStudent.getPhone());
+		saveStudentReq.setOrgCode(examStudent.getOrgCode());
+		saveStudentReq.setOrgId(examStudent.getOrgId());
+		saveStudentReq.setOrgName(examStudent.getOrgName());
+		saveStudentReq.setRemark(examStudent.getRemark());
+		saveStudentReq.setRootOrgId(examStudent.getRootOrgId());
+		saveStudentReq.setStudentCode(examStudent.getStudentCode());
+
+		InsertOrUpdateStudentResp insertOrUpdateStudentResp = studentCloudService
+				.insertOrUpdateStudent(saveStudentReq);
+
+		Long studentId = insertOrUpdateStudentResp.getStudentId();
+
+		SaveExamStudentReq saveExamStudentReq = new SaveExamStudentReq();
+		saveExamStudentReq.setCourseCode(examStudent.getCourseCode());
+		saveExamStudentReq.setCourseLevel(examStudent.getCourseLevel());
+		saveExamStudentReq.setCourseName(examStudent.getCourseName());
+		saveExamStudentReq.setExamId(examStudent.getExamId());
+		saveExamStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
+		saveExamStudentReq.setPaperType(examStudent.getPaperType());
+		saveExamStudentReq.setRootOrgId(examStudent.getRootOrgId());
+		saveExamStudentReq.setStudentCode(examStudent.getStudentCode());
+		saveExamStudentReq.setStudentName(examStudent.getStudentName());
+		saveExamStudentReq.setStudentId(studentId);
+
+		SaveExamStudentResp saveExamStudentResp = examStudentCloudService
+				.saveExamStudent(saveExamStudentReq);
+		ExamStudentBean examStudentBean = saveExamStudentResp.getExamStudentBean();
+
+		ExamStudentDomain ret = new ExamStudentDomain();
+		ret.setStudentId(studentId);
+		ret.setStudentCode(examStudentBean.getStudentCode());
+		ret.setStudentName(examStudentBean.getStudentName());
+		ret.setCourseCode(examStudentBean.getCourseCode());
+		ret.setCourseName(examStudentBean.getCourseName());
+		return ret;
 	}
 
 	@ApiOperation(value = "更新考试学生缺考状态", notes = "更新缺考")

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

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.core.examwork.api.controller.bean;
 
 import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
-import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
 
 /**
  * 类注释
@@ -16,9 +15,11 @@ public class ExamStudentDomain implements JsonSerializable {
 
 	private Long id;
 
-	private String name;
+	private Long studentId;
 
-	private Exam exam;
+	private String studentName;
+
+	private String studentCode;
 
 	private Long examId;
 
@@ -26,8 +27,6 @@ public class ExamStudentDomain implements JsonSerializable {
 
 	private Long orgId;
 
-	private String studentCode;
-
 	private String identityNumber;
 
 	private String orgCode;
@@ -58,6 +57,13 @@ public class ExamStudentDomain implements JsonSerializable {
 	 */
 	private String infoCollector;
 
+	/**
+	 * 学生电话
+	 */
+	private String phone;
+
+	private String remark;
+
 	public Long getId() {
 		return id;
 	}
@@ -66,20 +72,28 @@ public class ExamStudentDomain implements JsonSerializable {
 		this.id = id;
 	}
 
-	public String getName() {
-		return name;
+	public Long getStudentId() {
+		return studentId;
 	}
 
-	public void setName(String name) {
-		this.name = name;
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
 	}
 
-	public Exam getExam() {
-		return exam;
+	public String getStudentName() {
+		return studentName;
 	}
 
-	public void setExam(Exam exam) {
-		this.exam = exam;
+	public void setStudentName(String studentName) {
+		this.studentName = studentName;
+	}
+
+	public String getStudentCode() {
+		return studentCode;
+	}
+
+	public void setStudentCode(String studentCode) {
+		this.studentCode = studentCode;
 	}
 
 	public Long getExamId() {
@@ -106,14 +120,6 @@ public class ExamStudentDomain implements JsonSerializable {
 		this.orgId = orgId;
 	}
 
-	public String getStudentCode() {
-		return studentCode;
-	}
-
-	public void setStudentCode(String studentCode) {
-		this.studentCode = studentCode;
-	}
-
 	public String getIdentityNumber() {
 		return identityNumber;
 	}
@@ -210,4 +216,20 @@ public class ExamStudentDomain implements JsonSerializable {
 		this.infoCollector = infoCollector;
 	}
 
+	public String getPhone() {
+		return phone;
+	}
+
+	public void setPhone(String phone) {
+		this.phone = phone;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+
 }

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

@@ -132,14 +132,18 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 		SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
 		CourseBean courseBean = saveCourseResp.getCourseBean();
 
-		List<ExamStudent> examStudentList = examStudentRepo.findByExamAndStudentIdAndCourseCode(
-				exam, studentInfo.getId(), courseBean.getCode());
+		List<ExamStudent> examStudentList = examStudentRepo
+				.findByExamAndStudentIdAndCourseCodeOrderByUpdateTimeDesc(exam, studentInfo.getId(),
+						courseBean.getCode());
 
+		ExamStudent examStudent = new ExamStudent();
+
+		// 数据悲观修正 by wangwei
 		if (CollectionUtils.isNotEmpty(examStudentList)) {
+			examStudent = examStudentList.get(0);
 			examStudentRepo.deleteInBatch(examStudentList);
 		}
 
-		ExamStudent examStudent = new ExamStudent();
 		examStudent.setName(studentInfo.getName());
 		examStudent.setRootOrgId(rootOrgId);
 		examStudent.setCourseCode(courseCode);

+ 10 - 0
examcloud-core-examwork-api/src/main/java/cn/com/qmth/examcloud/examwork/api/request/SaveExamStudentReq.java

@@ -21,6 +21,8 @@ public class SaveExamStudentReq extends BaseRequest {
 	 */
 	private String examName;
 
+	private Long studentId;
+
 	/**
 	 * 学生姓名
 	 */
@@ -136,4 +138,12 @@ public class SaveExamStudentReq extends BaseRequest {
 		this.paperType = paperType;
 	}
 
+	public Long getStudentId() {
+		return studentId;
+	}
+
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
+	}
+
 }

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

@@ -79,6 +79,6 @@ public interface ExamStudentRepo
 	@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);
 
-	List<ExamStudent> findByExamAndStudentIdAndCourseCode(Exam exam, Long studentId,
+	List<ExamStudent> findByExamAndStudentIdAndCourseCodeOrderByUpdateTimeDesc(Exam exam, Long studentId,
 			String courseCode);
 }

+ 2 - 1
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamStudent.java

@@ -10,13 +10,14 @@ import javax.persistence.Transient;
 import javax.validation.constraints.NotNull;
 
 import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
 
 /**
  * Created by songyue on 17/1/13.
  */
 @Entity
 @Table(name = "ecs_exam_student")
-public class ExamStudent implements JsonSerializable {
+public class ExamStudent extends JpaEntity {
 
 	private static final long serialVersionUID = 757531976286006550L;