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