wangwei 6 years ago
parent
commit
4dc1dfa353

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

@@ -6,11 +6,13 @@ import java.util.List;
 
 import javax.persistence.criteria.Predicate;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
+import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -21,10 +23,14 @@ import org.springframework.web.bind.annotation.RestController;
 import com.google.common.collect.Lists;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.web.helpers.page.PageInfo;
 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.OrgBean;
+import cn.com.qmth.examcloud.core.basic.api.request.GetOrgReq;
+import cn.com.qmth.examcloud.core.basic.api.response.GetOrgResp;
 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.ExamEntity;
@@ -34,9 +40,11 @@ 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.CopyExamStudentsReq;
+import cn.com.qmth.examcloud.examwork.api.request.GetExamStudentPageReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamStudentReq;
 import cn.com.qmth.examcloud.examwork.api.request.SaveExamStudentReq;
 import cn.com.qmth.examcloud.examwork.api.response.CopyExamStudentsResp;
+import cn.com.qmth.examcloud.examwork.api.response.GetExamStudentPageResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamStudentResp;
 import cn.com.qmth.examcloud.examwork.api.response.SaveExamStudentResp;
 import io.swagger.annotations.ApiOperation;
@@ -249,4 +257,116 @@ public class ExamStudentCloudServiceProvider extends ControllerSupport
 		return resp;
 	}
 
+	@ApiOperation(value = " 分页查询考生")
+	@PostMapping("getExamStudentPage")
+	@Override
+	public GetExamStudentPageResp getExamStudentPage(@RequestBody GetExamStudentPageReq req) {
+		Long rootOrgId = req.getRootOrgId();
+		String courseCode = req.getCourseCode();
+		String courseLevel = req.getCourseLevel();
+		String courseName = req.getCourseName();
+		Integer curPage = req.getCurPage();
+		Long examId = req.getExamId();
+		String examSite = req.getExamSite();
+		String identityNumber = req.getIdentityNumber();
+		String infoCollector = req.getInfoCollector();
+		Long orgId = req.getOrgId();
+		String specialtyName = req.getSpecialtyName();
+		String studentCode = req.getStudentCode();
+		String studentName = req.getStudentName();
+		Integer pageSize = req.getPageSize();
+
+		if (null == rootOrgId) {
+			throw new StatusException("E-210005", "rootOrgId is null");
+		}
+
+		Specification<ExamStudentEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
+
+			if (null != orgId) {
+				predicates.add(cb.equal(root.get("orgId"), orgId));
+			}
+
+			if (null != examId) {
+				predicates.add(cb.equal(root.get("examId"), examId));
+			}
+			if (StringUtils.isNotEmpty(studentName)) {
+				predicates.add(cb.like(root.get("name"), toSqlSearchPattern(studentName)));
+			}
+			if (StringUtils.isNotEmpty(studentCode)) {
+				predicates.add(cb.like(root.get("studentCode"), toSqlSearchPattern(studentCode)));
+			}
+			if (StringUtils.isNotEmpty(courseCode)) {
+				predicates.add(cb.equal(root.get("courseCode"), courseCode));
+			}
+			if (StringUtils.isNotEmpty(courseLevel)) {
+				predicates.add(cb.equal(root.get("courseLevel"), courseLevel));
+			}
+			if (StringUtils.isNotEmpty(courseName)) {
+				predicates.add(cb.like(root.get("courseName"), toSqlSearchPattern(courseName)));
+			}
+			if (!StringUtils.isEmpty(examSite)) {
+				predicates.add(cb.like(root.get("examSite"), toSqlSearchPattern(examSite)));
+			}
+			if (StringUtils.isNotEmpty(identityNumber)) {
+				predicates.add(
+						cb.like(root.get("identityNumber"), toSqlSearchPattern(identityNumber)));
+			}
+			if (StringUtils.isNotEmpty(specialtyName)) {
+				predicates
+						.add(cb.like(root.get("specialtyName"), toSqlSearchPattern(specialtyName)));
+			}
+			if (StringUtils.isNotEmpty(infoCollector)) {
+				predicates
+						.add(cb.like(root.get("infoCollector"), toSqlSearchPattern(infoCollector)));
+			}
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		PageRequest pageRequest = new PageRequest(curPage, pageSize,
+				new Sort(Direction.DESC, "updateTime"));
+
+		Page<ExamStudentEntity> examStudents = examStudentRepo.findAll(specification, pageRequest);
+
+		List<ExamStudentBean> ret = Lists.newArrayList();
+
+		for (ExamStudentEntity cur : examStudents) {
+			ExamEntity exam = examRepo.findOne(cur.getExamId());
+
+			GetOrgReq getOrgReq = new GetOrgReq();
+			getOrgReq.setOrgId(cur.getOrgId());
+			GetOrgResp getOrgResp = orgCloudService.getOrg(getOrgReq);
+			OrgBean org = getOrgResp.getOrg();
+
+			ExamStudentBean bean = new ExamStudentBean();
+			bean.setId(cur.getId());
+			bean.setExamId(exam.getId());
+			bean.setExamName(exam.getName());
+			bean.setStudentId(cur.getStudentId());
+			bean.setStudentName(cur.getName());
+			bean.setStudentCode(cur.getStudentCode());
+			bean.setIdentityNumber(cur.getIdentityNumber());
+			bean.setCourseCode(cur.getCourseCode());
+			bean.setCourseName(cur.getCourseName());
+			bean.setInfoCollector(cur.getInfoCollector());
+			bean.setOrgId(cur.getOrgId());
+			bean.setOrgCode(org.getCode());
+			bean.setOrgName(org.getName());
+			bean.setPaperType(cur.getPaperType());
+			bean.setGrade(cur.getGrade());
+			bean.setSpecialtyName(cur.getSpecialtyName());
+			bean.setExamSite(cur.getExamSite());
+
+			ret.add(bean);
+		}
+		PageInfo<ExamStudentBean> pageInfo = new PageInfo<ExamStudentBean>(examStudents, ret);
+
+		GetExamStudentPageResp resp = new GetExamStudentPageResp();
+		resp.setPageInfo(pageInfo);
+
+		return resp;
+	}
+
 }