|
@@ -22,6 +22,7 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
@@ -36,11 +37,14 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.common.dto.core.Course;
|
|
|
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.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;
|
|
|
import cn.com.qmth.examcloud.core.examwork.dao.ExamRepo;
|
|
@@ -91,26 +95,86 @@ public class ExamStudentController extends ControllerSupport {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 重构
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param examCriteria
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "查询考试学生带条件和分页", notes = "带条件带分页")
|
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
|
- public ResponseEntity getAllExamStudent(HttpServletRequest request,
|
|
|
- @ModelAttribute ExamStudentDTO examStudent, @PathVariable Integer curPage,
|
|
|
+ public List<ExamStudentDomain> getExamStudentList(
|
|
|
+ @ModelAttribute ExamStudentDomain examCriteria, @PathVariable Integer curPage,
|
|
|
@PathVariable Integer pageSize) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- if (accessUser != null) {
|
|
|
- if (accessUser.getRootOrgId().longValue() == accessUser.getOrgId().longValue()
|
|
|
- || examStudent.getStudentId() != null) {
|
|
|
- examStudent.setRootOrgId(accessUser.getRootOrgId());
|
|
|
- } else {
|
|
|
- examStudent.setOrgId(accessUser.getOrgId());
|
|
|
+ Specification<ExamStudent> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), examCriteria.getRootOrgId()));
|
|
|
+
|
|
|
+ if (null != examCriteria.getOrgId()) {
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), examCriteria.getOrgId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != examCriteria.getExamId()) {
|
|
|
+ predicates.add(cb.equal(root.get("exam").get("id"), examCriteria.getExamId()));
|
|
|
}
|
|
|
- } else {
|
|
|
- return new ResponseEntity(new ErrorMsg("无访问权限"), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ if (StringUtils.isNotEmpty(examCriteria.getName())) {
|
|
|
+ predicates
|
|
|
+ .add(cb.like(root.get("name"), toSqlSearchPattern(examCriteria.getName())));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(examCriteria.getStudentCode())) {
|
|
|
+ predicates.add(cb.like(root.get("studentCode"),
|
|
|
+ toSqlSearchPattern(examCriteria.getStudentCode())));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(examCriteria.getCourseCode())) {
|
|
|
+ predicates.add(cb.equal(root.get("courseCode"), examCriteria.getCourseCode()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(examCriteria.getCourseLevel())) {
|
|
|
+ predicates.add(cb.equal(root.get("courseLevel"), examCriteria.getCourseLevel()));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(examCriteria.getCourseName())) {
|
|
|
+ predicates.add(cb.like(root.get("courseName"),
|
|
|
+ toSqlSearchPattern(examCriteria.getCourseName())));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtils.isEmpty(examCriteria.getExamSite())) {
|
|
|
+ predicates.add(cb.like(root.get("examSite"),
|
|
|
+ toSqlSearchPattern(examCriteria.getExamSite())));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(examCriteria.getIdentityNumber())) {
|
|
|
+ predicates.add(cb.like(root.get("identityNumber"),
|
|
|
+ toSqlSearchPattern(examCriteria.getIdentityNumber())));
|
|
|
+ }
|
|
|
+ if (!StringUtils.isEmpty(examCriteria.getSpecialtyName())) {
|
|
|
+ predicates.add(cb.like(root.get("specialtyName"),
|
|
|
+ "%" + examCriteria.getSpecialtyName() + "%"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = new PageRequest(curPage, pageSize,
|
|
|
+ new Sort(Direction.DESC, "id"));
|
|
|
+
|
|
|
+ Page<ExamStudent> examStudents = examStudentRepo.findAll(specification, pageRequest);
|
|
|
+
|
|
|
+ List<ExamStudentDomain> ret = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (ExamStudent cur : examStudents) {
|
|
|
+ ExamStudentDomain bean = new ExamStudentDomain();
|
|
|
+ bean.setId(cur.getId());
|
|
|
+ bean.setName(cur.getName());
|
|
|
+ bean.setStudentCode(cur.getStudentCode());
|
|
|
+ bean.setIdentityNumber(cur.getIdentityNumber());
|
|
|
+ bean.setCourseCode(cur.getCourseCode());
|
|
|
+ bean.setCourseName(cur.getCourseName());
|
|
|
+ bean.setInfoCollector(cur.getInfoCollector());
|
|
|
+
|
|
|
+ ret.add(bean);
|
|
|
}
|
|
|
- return new ResponseEntity(
|
|
|
- examStudentService.getAllExamStudent(examStudent,
|
|
|
- new PageRequest(curPage, pageSize, new Sort(Direction.DESC, "id"))),
|
|
|
- HttpStatus.OK);
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
/**
|