|
@@ -1,15 +1,21 @@
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.PageRequest;
|
|
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.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -26,6 +32,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
@@ -51,19 +58,41 @@ public class StudentController extends ControllerSupport {
|
|
@Autowired
|
|
@Autowired
|
|
UserRepo userRepo;
|
|
UserRepo userRepo;
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 方法注释
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param name
|
|
|
|
+ * @param studentCode
|
|
|
|
+ * @param identityNumber
|
|
|
|
+ * @param curPage
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@ApiOperation(value = "查询所有学生", notes = "分页")
|
|
@ApiOperation(value = "查询所有学生", notes = "分页")
|
|
@GetMapping("/{curPage}/{pageSize}")
|
|
@GetMapping("/{curPage}/{pageSize}")
|
|
- public Page<Student> getAllStudent(HttpServletRequest request,
|
|
|
|
- @ModelAttribute Student studentCriteria, @PathVariable Integer curPage,
|
|
|
|
|
|
+ public Page<Student> getAllStudent(@RequestParam String name, @RequestParam String studentCode,
|
|
|
|
+ @RequestParam String identityNumber, @PathVariable Integer curPage,
|
|
@PathVariable Integer pageSize) {
|
|
@PathVariable Integer pageSize) {
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
|
|
- if (!isSuperAdmin()) {
|
|
|
|
- studentCriteria.setRootOrgId(accessUser.getRootOrgId());
|
|
|
|
- }
|
|
|
|
|
|
+ Specification<Student> specification = (root, query, cb) -> {
|
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isNotEmpty(name)) {
|
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isNotEmpty(studentCode)) {
|
|
|
|
+ predicates.add(cb.like(root.get("studentCode"), toSqlSearchPattern(studentCode)));
|
|
|
|
+ }
|
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ PageRequest pageRequest = new PageRequest(curPage, pageSize,
|
|
|
|
+ new Sort(Direction.DESC, "updateTime"));
|
|
|
|
|
|
- Page<Student> studentList = studentService.getAllStudent(studentCriteria,
|
|
|
|
- new PageRequest(curPage, pageSize));
|
|
|
|
|
|
+ Page<Student> studentList = studentRepo.findAll(specification, pageRequest);
|
|
return studentList;
|
|
return studentList;
|
|
}
|
|
}
|
|
|
|
|