wangwei 7 年 前
コミット
164c552b02

+ 2 - 2
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamController.java

@@ -52,7 +52,7 @@ import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgEntity;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudent;
 import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
 import cn.com.qmth.examcloud.core.examwork.service.impl.ExamService;
-import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentService;
+import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -73,7 +73,7 @@ public class ExamController extends ControllerSupport {
 	ExamStudentRepo examStudentRepo;
 
 	@Autowired
-	ExamStudentService examStudentService;
+	ExamStudentServiceImpl examStudentService;
 
 	@Autowired
 	CourseGroupRepo courseGroupRepo;

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

@@ -57,11 +57,8 @@ 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.ExamStudent;
 import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
-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 cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
+import cn.com.qmth.examcloud.core.examwork.service.impl.ExamStudentServiceImpl;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -77,7 +74,7 @@ public class ExamStudentController extends ControllerSupport {
 	ExamStudentRepo examStudentRepo;
 
 	@Autowired
-	ExamStudentService examStudentService;
+	ExamStudentServiceImpl examStudentService;
 
 	@Autowired
 	ExamStudentAssembler examStudentAssembler;
@@ -88,9 +85,6 @@ public class ExamStudentController extends ControllerSupport {
 	@Autowired
 	StudentCloudService studentCloudService;
 
-	@Autowired
-	ExamStudentCloudService examStudentCloudService;
-
 	@Autowired
 	ExamStudentImportService examStudentImportService;
 
@@ -326,33 +320,31 @@ public class ExamStudentController extends ControllerSupport {
 
 		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);
-		saveExamStudentReq.setInfoCollector(examStudent.getInfoCollector());
-		saveExamStudentReq.setGrade(examStudent.getGrade());
-		saveExamStudentReq.setExamSite(examStudent.getExamSite());
-		saveExamStudentReq.setSpecialtyName(examStudent.getSpecialtyName());
-
-		SaveExamStudentResp saveExamStudentResp = examStudentCloudService
-				.saveExamStudent(saveExamStudentReq);
-		ExamStudentBean examStudentBean = saveExamStudentResp.getExamStudentBean();
+		ExamStudentInfo info = new ExamStudentInfo();
+		info.setCourseCode(examStudent.getCourseCode());
+		info.setCourseLevel(examStudent.getCourseLevel());
+		info.setCourseName(examStudent.getCourseName());
+		info.setExamId(examStudent.getExamId());
+		info.setIdentityNumber(examStudent.getIdentityNumber());
+		info.setPaperType(examStudent.getPaperType());
+		info.setRootOrgId(examStudent.getRootOrgId());
+		info.setStudentCode(examStudent.getStudentCode());
+		info.setStudentName(examStudent.getStudentName());
+		info.setStudentId(studentId);
+		info.setInfoCollector(examStudent.getInfoCollector());
+		info.setGrade(examStudent.getGrade());
+		info.setExamSite(examStudent.getExamSite());
+		info.setSpecialtyName(examStudent.getSpecialtyName());
+
+		ExamStudentInfo savedExamStudent = examStudentService.saveExamStudent(info);
 
 		ExamStudentDomain ret = new ExamStudentDomain();
-		ret.setId(examStudentBean.getId());
+		ret.setId(savedExamStudent.getId());
 		ret.setStudentId(studentId);
-		ret.setStudentCode(examStudentBean.getStudentCode());
-		ret.setStudentName(examStudentBean.getStudentName());
-		ret.setCourseCode(examStudentBean.getCourseCode());
-		ret.setCourseName(examStudentBean.getCourseName());
+		ret.setStudentCode(savedExamStudent.getStudentCode());
+		ret.setStudentName(savedExamStudent.getStudentName());
+		ret.setCourseCode(savedExamStudent.getCourseCode());
+		ret.setCourseName(savedExamStudent.getCourseName());
 		return ret;
 	}
 

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

@@ -1,36 +1,21 @@
 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.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 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.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.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.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.SaveExamStudentReq;
@@ -58,7 +43,7 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 	OrgCloudService orgCloudService;
 
 	@Autowired
-	ExamStudentService examStudentService;
+	ExamStudentServiceImpl examStudentService;
 
 	@Autowired
 	StudentCloudService studentCloudService;
@@ -74,111 +59,12 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 	@Override
 	public SaveExamStudentResp saveExamStudent(@RequestBody SaveExamStudentReq req) {
 		trim(req);
-		String paperType = req.getPaperType();
-		if (StringUtils.isBlank(paperType)) {
-			paperType = "A";
-		} else if (!paperType.matches("[A-Z]")) {
-			throw new StatusException("E-100020", "paperType must be one of A-Z");
-		}
-
-		Long rootOrgId = req.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");
-		}
-
-		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();
-
-		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);
-
-		StudentBean studentInfo = getStudentResp.getStudentInfo();
-
-		String courseCode = req.getCourseCode();
-		String courseName = req.getCourseName();
-		String courseLevel = req.getCourseLevel();
-
-		SaveCourseReq saveCourseReq = new SaveCourseReq();
-		saveCourseReq.setCourseId(req.getCourseId());
-		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
-				.findByExamAndStudentIdAndCourseCodeOrderByUpdateTimeDesc(exam, studentInfo.getId(),
-						courseBean.getCode());
-
-		ExamStudent examStudent = null;
-
-		if (1 < examStudentList.size()) {
-			// 数据需要修正
-			throw new StatusException("E-100008", "考生数据重复. studentId: " + studentInfo.getId());
-		} else if (1 == examStudentList.size()) {
-			examStudent = examStudentList.get(0);
-		} else {
-			examStudent = new ExamStudent();
-			examStudent.setNormalExamTimes(0);
-			examStudent.setFinished(false);
-			examStudent.setIsReexamine(false);
-			examStudent.setCanUpload(false);
-		}
-		examStudent.setInfoCollector(req.getInfoCollector());
-		examStudent.setName(studentInfo.getName());
-		examStudent.setRootOrgId(rootOrgId);
-
-		examStudent.setCourseId(courseBean.getId());
-		examStudent.setCourseCode(courseBean.getCode());
-		examStudent.setCourseName(courseBean.getName());
-		examStudent.setCourseLevel(courseBean.getLevel());
-
-		examStudent.setExam(exam);
-		examStudent.setIdentityNumber(studentInfo.getIdentityNumber());
-		examStudent.setStudentCode(studentInfo.getStudentCode());
-		examStudent.setPaperType(paperType);
-		examStudent.setStudentId(studentInfo.getId());
-		examStudent.setOrgId(studentInfo.getOrgId());
-		examStudent.setOrgName(studentInfo.getOrgName());
-		examStudent.setOrgCode(studentInfo.getOrgCode());
-		examStudent.setPhone(studentInfo.getPhoneNumber());
-		examStudent.setGrade(req.getGrade());
-		examStudent.setSpecialtyName(req.getSpecialtyName());
-		examStudent.setExamSite(req.getExamSite());
-
-		System.out.println(examStudent.getCourseLevel());
-		ExamStudent saved = examStudentRepo.save(examStudent);
+		ExamStudentInfo info = new ExamStudentInfo();
+
+		info.setCourseCode(req.getCourseCode());
+		info.setCourseId(req.getCourseId());
+
+		ExamStudentInfo saved = examStudentService.saveExamStudent(info);
 
 		SaveExamStudentResp resp = new SaveExamStudentResp();
 
@@ -187,13 +73,13 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 		examStudentBean.setCourseCode(saved.getCourseCode());
 		examStudentBean.setCourseLevel(saved.getCourseLevel());
 		examStudentBean.setCourseName(saved.getCourseName());
-		examStudentBean.setExamId(saved.getExam().getId());
-		examStudentBean.setExamName(saved.getExam().getName());
+		examStudentBean.setExamId(saved.getExamId());
+		examStudentBean.setExamName(saved.getExamName());
 		examStudentBean.setIdentityNumber(saved.getIdentityNumber());
 		examStudentBean.setStudentCode(saved.getStudentCode());
 		examStudentBean.setPaperType(saved.getPaperType());
 		examStudentBean.setRootOrgId(saved.getRootOrgId());
-		examStudentBean.setStudentName(studentInfo.getName());
+		examStudentBean.setStudentName(saved.getStudentName());
 
 		resp.setExamStudentBean(examStudentBean);
 

+ 0 - 6
examcloud-core-examwork-service/pom.xml

@@ -32,12 +32,6 @@
 			<version>${examcloud.version}</version>
 		</dependency>
 
-		<dependency>
-			<groupId>cn.com.qmth.examcloud.core.examwork</groupId>
-			<artifactId>examcloud-core-examwork-api</artifactId>
-			<version>${examcloud.version}</version>
-		</dependency>
-
 	</dependencies>
 
 </project>

+ 9 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/ExamStudentService.java

@@ -0,0 +1,9 @@
+package cn.com.qmth.examcloud.core.examwork.service;
+
+import cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
+
+public interface ExamStudentService {
+
+	public ExamStudentInfo saveExamStudent(ExamStudentInfo examStudentInfo);
+
+}

+ 227 - 0
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/bean/ExamStudentInfo.java

@@ -0,0 +1,227 @@
+package cn.com.qmth.examcloud.core.examwork.service.bean;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年7月18日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class ExamStudentInfo {
+
+	private Long id;
+
+	/**
+	 * 顶级机构ID
+	 */
+	private Long rootOrgId;
+
+	/**
+	 * 考试ID
+	 */
+	private Long examId;
+
+	/**
+	 * 考试名称
+	 */
+	private String examName;
+
+	private Long studentId;
+
+	/**
+	 * 学生姓名
+	 */
+	private String studentName;
+
+	/**
+	 * 学生学号
+	 */
+	private String studentCode;
+
+	/**
+	 * 学生身份证号
+	 */
+	private String identityNumber;
+
+	/**
+	 * 考试课程名称
+	 */
+	private String courseName;
+
+	/**
+	 * 考试课程ID
+	 */
+	private Long courseId;
+
+	/**
+	 * 考试课程code
+	 */
+	private String courseCode;
+
+	/**
+	 * 考试课程level
+	 */
+	private String courseLevel;
+
+	/**
+	 * 试卷类型
+	 */
+	private String paperType;
+
+	/**
+	 * 信息采集人
+	 */
+	private String infoCollector;
+
+	/**
+	 * 考点
+	 */
+	private String examSite;
+
+	/**
+	 * 专业名称
+	 */
+	private String specialtyName;
+
+	/**
+	 * 年级
+	 */
+	private String grade;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Long getExamId() {
+		return examId;
+	}
+
+	public void setExamId(Long examId) {
+		this.examId = examId;
+	}
+
+	public String getExamName() {
+		return examName;
+	}
+
+	public void setExamName(String examName) {
+		this.examName = examName;
+	}
+
+	public Long getStudentId() {
+		return studentId;
+	}
+
+	public void setStudentId(Long studentId) {
+		this.studentId = studentId;
+	}
+
+	public String getStudentName() {
+		return studentName;
+	}
+
+	public void setStudentName(String studentName) {
+		this.studentName = studentName;
+	}
+
+	public String getStudentCode() {
+		return studentCode;
+	}
+
+	public void setStudentCode(String studentCode) {
+		this.studentCode = studentCode;
+	}
+
+	public String getIdentityNumber() {
+		return identityNumber;
+	}
+
+	public void setIdentityNumber(String identityNumber) {
+		this.identityNumber = identityNumber;
+	}
+
+	public String getCourseName() {
+		return courseName;
+	}
+
+	public void setCourseName(String courseName) {
+		this.courseName = courseName;
+	}
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+	public String getCourseCode() {
+		return courseCode;
+	}
+
+	public void setCourseCode(String courseCode) {
+		this.courseCode = courseCode;
+	}
+
+	public String getCourseLevel() {
+		return courseLevel;
+	}
+
+	public void setCourseLevel(String courseLevel) {
+		this.courseLevel = courseLevel;
+	}
+
+	public String getPaperType() {
+		return paperType;
+	}
+
+	public void setPaperType(String paperType) {
+		this.paperType = paperType;
+	}
+
+	public String getInfoCollector() {
+		return infoCollector;
+	}
+
+	public void setInfoCollector(String infoCollector) {
+		this.infoCollector = infoCollector;
+	}
+
+	public String getExamSite() {
+		return examSite;
+	}
+
+	public void setExamSite(String examSite) {
+		this.examSite = examSite;
+	}
+
+	public String getSpecialtyName() {
+		return specialtyName;
+	}
+
+	public void setSpecialtyName(String specialtyName) {
+		this.specialtyName = specialtyName;
+	}
+
+	public String getGrade() {
+		return grade;
+	}
+
+	public void setGrade(String grade) {
+		this.grade = grade;
+	}
+
+}

+ 1 - 1
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamService.java

@@ -36,7 +36,7 @@ public class ExamService {
 	ExamRepo examRepo;
 
 	@Autowired
-	ExamStudentService examStudentService;
+	ExamStudentServiceImpl examStudentService;
 
 	@Autowired
 	ExamOrgTimeRepo examOrgTimeRepo;

+ 21 - 25
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentImportServiceImpl.java

@@ -32,10 +32,7 @@ import cn.com.qmth.examcloud.core.basic.api.response.InsertOrUpdateStudentResp;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentTempRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentTempEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
-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 cn.com.qmth.examcloud.core.examwork.service.bean.ExamStudentInfo;
 
 /**
  * 类注释
@@ -53,13 +50,13 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
 			"学习中心名称", "课程代码", "课程名称", "试卷类型", "专业", "考点", "信息采集人", "学生电话", "年级"};
 
 	@Autowired
-	ExamStudentTempRepo examStudentTempRepo;
+	ExamStudentServiceImpl examStudentService;
 
 	@Autowired
-	StudentCloudService studentCloudService;
+	ExamStudentTempRepo examStudentTempRepo;
 
 	@Autowired
-	ExamStudentCloudService examStudentCloudService;
+	StudentCloudService studentCloudService;
 
 	@PersistenceUnit
 	private EntityManagerFactory entityManagerFactory;
@@ -172,24 +169,23 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
 
 		Long studentId = insertOrUpdateStudentResp.getStudentId();
 
-		SaveExamStudentReq saveExamStudentReq = new SaveExamStudentReq();
-		saveExamStudentReq.setCourseId(Long.parseLong(examStudent.getCourseId()));
-		saveExamStudentReq.setExamId(examStudent.getExamId());
-		saveExamStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
-		saveExamStudentReq.setPaperType(examStudent.getPaperType());
-		saveExamStudentReq.setRootOrgId(examStudent.getRootOrgId());
-		saveExamStudentReq.setStudentCode(examStudent.getStudentCode());
-		saveExamStudentReq.setStudentName(examStudent.getName());
-		saveExamStudentReq.setStudentId(studentId);
-		saveExamStudentReq.setInfoCollector(examStudent.getInfoCollector());
-		saveExamStudentReq.setGrade(examStudent.getGrade());
-		saveExamStudentReq.setExamSite(examStudent.getExamSite());
-		saveExamStudentReq.setSpecialtyName(examStudent.getSpecialtyName());
-
-		SaveExamStudentResp saveExamStudentResp = examStudentCloudService
-				.saveExamStudent(saveExamStudentReq);
-		ExamStudentBean examStudentBean = saveExamStudentResp.getExamStudentBean();
-		log.debug("examStudentId=" + examStudentBean.getId());
+		ExamStudentInfo info = new ExamStudentInfo();
+		info.setCourseId(Long.parseLong(examStudent.getCourseId()));
+		info.setExamId(examStudent.getExamId());
+		info.setIdentityNumber(examStudent.getIdentityNumber());
+		info.setPaperType(examStudent.getPaperType());
+		info.setRootOrgId(examStudent.getRootOrgId());
+		info.setStudentCode(examStudent.getStudentCode());
+		info.setStudentName(examStudent.getName());
+		info.setStudentId(studentId);
+		info.setInfoCollector(examStudent.getInfoCollector());
+		info.setGrade(examStudent.getGrade());
+		info.setExamSite(examStudent.getExamSite());
+		info.setSpecialtyName(examStudent.getSpecialtyName());
+
+		ExamStudentInfo savedExamStudent = examStudentService.saveExamStudent(info);
+
+		log.debug("examStudentId=" + savedExamStudent.getId());
 	}
 
 	/**

+ 182 - 22
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentService.java → examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentServiceImpl.java

@@ -10,6 +10,8 @@ import java.util.List;
 
 import javax.persistence.criteria.Predicate;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +24,6 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
 
 import cn.com.qmth.examcloud.common.dto.core.Course;
 import cn.com.qmth.examcloud.common.dto.core.Org;
@@ -36,6 +37,18 @@ 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.base.util.excel.ExcelReader;
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReaderHandle;
+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.ExamOrgTimeRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.ExamStudentRepo;
@@ -46,6 +59,8 @@ import cn.com.qmth.examcloud.core.examwork.dao.entity.Exam;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamOrgTime;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudent;
 import cn.com.qmth.examcloud.core.examwork.dao.enums.ExamType;
+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.examwork.service.rpc.CourseService;
 import cn.com.qmth.examcloud.core.examwork.service.rpc.OrgService;
 import cn.com.qmth.examcloud.core.examwork.service.rpc.SpecialtyService;
@@ -55,9 +70,9 @@ import cn.com.qmth.examcloud.core.examwork.service.rpc.StudentService;
  * 考试学生服务类 Created by songyue on 17/1/14.
  */
 @Service
-public class ExamStudentService {
+public class ExamStudentServiceImpl implements ExamStudentService {
 
-	protected static final Logger log = LoggerFactory.getLogger(ExamStudentService.class);
+	protected static final Logger log = LoggerFactory.getLogger(ExamStudentServiceImpl.class);
 
 	@Autowired
 	ExamStudentRepo examStudentRepo;
@@ -86,6 +101,18 @@ public class ExamStudentService {
 	@Autowired
 	ExamOrgTimeRepo examOrgTimeRepo;
 
+	@Autowired
+	OrgCloudService orgCloudService;
+
+	@Autowired
+	ExamStudentServiceImpl examStudentService;
+
+	@Autowired
+	StudentCloudService studentCloudService;
+
+	@Autowired
+	CourseCloudService courseCloudService;
+
 	/**
 	 * 获取所有考试学生(分页)
 	 * 
@@ -457,7 +484,7 @@ public class ExamStudentService {
 
 	private String getSqlSpecification(CommonExamStudent examCriteria) {
 		StringBuffer sql = new StringBuffer("");
-		if (!StringUtils.isEmpty(examCriteria.getOrgId())) {
+		if (null != examCriteria.getOrgId()) {
 			sql.append(" and t1.org_id = " + examCriteria.getOrgId());
 		}
 		if (!StringUtils.isEmpty(examCriteria.getName())) {
@@ -488,19 +515,19 @@ public class ExamStudentService {
 	private Specification<ExamStudent> getSpecification(ExamStudentDTO examCriteria) {
 		Specification<ExamStudent> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
-			if (!StringUtils.isEmpty(examCriteria.getStudentId())) {
+			if (null != examCriteria.getStudentId()) {
 				predicates.add(cb.equal(root.get("studentId"), examCriteria.getStudentId()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getRootOrgId())) {
+			if (null != examCriteria.getRootOrgId()) {
 				predicates.add(cb.equal(root.get("rootOrgId"), examCriteria.getRootOrgId()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getOrgId())) {
+			if (null != examCriteria.getOrgId()) {
 				predicates.add(cb.equal(root.get("orgId"), examCriteria.getOrgId()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getOrgName())) {
 				predicates.add(cb.like(root.get("orgName"), "%" + examCriteria.getOrgName() + "%"));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getExamId())) {
+			if (null != examCriteria.getExamId()) {
 				predicates.add(cb.equal(root.get("exam").get("id"), examCriteria.getExamId()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getName())) {
@@ -520,7 +547,7 @@ public class ExamStudentService {
 				predicates.add(
 						cb.like(root.get("courseName"), "%" + examCriteria.getCourseName() + "%"));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getFinished())) {
+			if (null != examCriteria.getFinished()) {
 				predicates.add(cb.equal(root.get("finished"), examCriteria.getFinished()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getExamSite())) {
@@ -538,13 +565,13 @@ public class ExamStudentService {
 			if (!StringUtils.isEmpty(examCriteria.getPaperType())) {
 				predicates.add(cb.equal(root.get("paperType"), examCriteria.getPaperType()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getDegree())) {
+			if (null != examCriteria.getDegree()) {
 				predicates.add(cb.equal(root.get("degree"), examCriteria.getDegree()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getRepair())) {
+			if (null != examCriteria.getRepair()) {
 				predicates.add(cb.equal(root.get("repair"), examCriteria.getRepair()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getGraduated())) {
+			if (null != examCriteria.getGraduated()) {
 				predicates.add(cb.equal(root.get("graduated"), examCriteria.getGraduated()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getGrade())) {
@@ -572,19 +599,19 @@ public class ExamStudentService {
 	private Specification<ExamStudent> getPageSpecification(ExamStudentDTO examCriteria) {
 		Specification<ExamStudent> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
-			if (!StringUtils.isEmpty(examCriteria.getStudentId())) {
+			if (null != examCriteria.getStudentId()) {
 				predicates.add(cb.equal(root.get("studentId"), examCriteria.getStudentId()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getRootOrgId())) {
+			if (null != examCriteria.getRootOrgId()) {
 				predicates.add(cb.equal(root.get("rootOrgId"), examCriteria.getRootOrgId()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getOrgId())) {
+			if (null != examCriteria.getOrgId()) {
 				predicates.add(cb.equal(root.get("orgId"), examCriteria.getOrgId()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getOrgName())) {
 				predicates.add(cb.like(root.get("orgName"), "%" + examCriteria.getOrgName() + "%"));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getExamId())) {
+			if (null != examCriteria.getExamId()) {
 				predicates.add(cb.equal(root.get("exam").get("id"), examCriteria.getExamId()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getName())) {
@@ -604,7 +631,7 @@ public class ExamStudentService {
 				predicates.add(
 						cb.like(root.get("courseName"), "%" + examCriteria.getCourseName() + "%"));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getFinished())) {
+			if (null != examCriteria.getFinished()) {
 				predicates.add(cb.equal(root.get("finished"), examCriteria.getFinished()));
 			}
 
@@ -623,13 +650,13 @@ public class ExamStudentService {
 			if (!StringUtils.isEmpty(examCriteria.getPaperType())) {
 				predicates.add(cb.equal(root.get("paperType"), examCriteria.getPaperType()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getDegree())) {
+			if (null != examCriteria.getDegree()) {
 				predicates.add(cb.equal(root.get("degree"), examCriteria.getDegree()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getRepair())) {
+			if (null != examCriteria.getRepair()) {
 				predicates.add(cb.equal(root.get("repair"), examCriteria.getRepair()));
 			}
-			if (!StringUtils.isEmpty(examCriteria.getGraduated())) {
+			if (null != examCriteria.getGraduated()) {
 				predicates.add(cb.equal(root.get("graduated"), examCriteria.getGraduated()));
 			}
 			if (!StringUtils.isEmpty(examCriteria.getGrade())) {
@@ -724,7 +751,7 @@ public class ExamStudentService {
 	 * @return
 	 */
 	public List<OrgExamInfoDTO> findOrgExamInfos(String examId, String orgCode) {
-		if (!StringUtils.hasLength(examId)) {
+		if (StringUtils.isBlank(examId)) {
 			return null;
 		}
 		StringBuilder sql = new StringBuilder();
@@ -732,7 +759,7 @@ public class ExamStudentService {
 				+ " count(t.id) allNum,"
 				+ " sum(case when t.finished = 1 then 1 else  0 end) completedNum "
 				+ " from ecs_exam_student  t" + " where t.exam_id = ?");
-		if (StringUtils.hasLength(orgCode)) {
+		if (StringUtils.isNotBlank(orgCode)) {
 			sql.append(" and t.org_code = '" + orgCode + "'");
 		}
 		sql.append(" group by t.org_id, t.org_name order by t.org_id");
@@ -859,4 +886,137 @@ public class ExamStudentService {
 		}
 		return examStudentRepo.findByLimit(examId, startLimit - 1, (endLimit - startLimit + 1));
 	}
+
+	/*
+	 * 实现
+	 *
+	 * @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 = "A";
+		} else if (!paperType.matches("[A-Z]")) {
+			throw new StatusException("E-100020", "paperType must be one of A-Z");
+		}
+
+		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");
+		}
+
+		Exam exam = null;
+		Long examId = examStudentInfo.getExamId();
+		if (null == examId) {
+			String examName = examStudentInfo.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 = examStudentInfo.getStudentCode();
+		String identityNumber = examStudentInfo.getIdentityNumber();
+
+		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);
+
+		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();
+
+		List<ExamStudent> examStudentList = examStudentRepo
+				.findByExamAndStudentIdAndCourseCodeOrderByUpdateTimeDesc(exam, studentInfo.getId(),
+						courseBean.getCode());
+
+		ExamStudent examStudent = null;
+
+		if (1 < examStudentList.size()) {
+			// 数据需要修正
+			throw new StatusException("E-100008", "考生数据重复. studentId: " + studentInfo.getId());
+		} else if (1 == examStudentList.size()) {
+			examStudent = examStudentList.get(0);
+		} else {
+			examStudent = new ExamStudent();
+			examStudent.setNormalExamTimes(0);
+			examStudent.setFinished(false);
+			examStudent.setIsReexamine(false);
+			examStudent.setCanUpload(false);
+		}
+		examStudent.setInfoCollector(examStudentInfo.getInfoCollector());
+		examStudent.setName(studentInfo.getName());
+		examStudent.setRootOrgId(rootOrgId);
+
+		examStudent.setCourseId(courseBean.getId());
+		examStudent.setCourseCode(courseBean.getCode());
+		examStudent.setCourseName(courseBean.getName());
+		examStudent.setCourseLevel(courseBean.getLevel());
+
+		examStudent.setExam(exam);
+		examStudent.setIdentityNumber(studentInfo.getIdentityNumber());
+		examStudent.setStudentCode(studentInfo.getStudentCode());
+		examStudent.setPaperType(paperType);
+		examStudent.setStudentId(studentInfo.getId());
+		examStudent.setOrgId(studentInfo.getOrgId());
+		examStudent.setOrgName(studentInfo.getOrgName());
+		examStudent.setOrgCode(studentInfo.getOrgCode());
+		examStudent.setPhone(studentInfo.getPhoneNumber());
+		examStudent.setGrade(examStudentInfo.getGrade());
+		examStudent.setSpecialtyName(examStudentInfo.getSpecialtyName());
+		examStudent.setExamSite(examStudentInfo.getExamSite());
+
+		System.out.println(examStudent.getCourseLevel());
+		ExamStudent saved = examStudentRepo.save(examStudent);
+
+		ExamStudentInfo ret = new ExamStudentInfo();
+		ret.setId(saved.getId());
+		ret.setCourseCode(saved.getCourseCode());
+		ret.setCourseLevel(saved.getCourseLevel());
+		ret.setCourseName(saved.getCourseName());
+		ret.setExamId(saved.getExam().getId());
+		ret.setExamName(saved.getExam().getName());
+		ret.setIdentityNumber(saved.getIdentityNumber());
+		ret.setStudentCode(saved.getStudentCode());
+		ret.setPaperType(saved.getPaperType());
+		ret.setRootOrgId(saved.getRootOrgId());
+		ret.setStudentName(studentInfo.getName());
+
+		return ret;
+	}
 }