|
@@ -6,7 +6,10 @@ import java.util.List;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.service.examwork.util.BeanCopierUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.data.domain.ExampleMatcher;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
@@ -31,6 +34,8 @@ import cn.com.qmth.examcloud.service.examwork.service.rpc.CourseService;
|
|
|
import cn.com.qmth.examcloud.service.examwork.service.rpc.OrgService;
|
|
|
import cn.com.qmth.examcloud.service.examwork.service.rpc.StudentService;
|
|
|
|
|
|
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
|
|
|
+
|
|
|
/**
|
|
|
* 考试学生服务类
|
|
|
* Created by songyue on 17/1/14.
|
|
@@ -65,12 +70,17 @@ public class ExamStudentService {
|
|
|
* @return
|
|
|
*/
|
|
|
public Page<ExamStudent> getAllExamStudent(ExamStudentDTO examCriteria, Pageable pageable){
|
|
|
+// ExamStudent examStudentSearch = BeanCopierUtil.copyProperties(examCriteria,ExamStudent.class);
|
|
|
// ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
-// .withMatcher("name",startsWith());
|
|
|
-// Example<ExamStudent> examExamStudentple = Example.of(examCriteria, exampleMatcher);
|
|
|
-// return examStudentRepo.findAll(examExamStudentple,pageable);
|
|
|
+// .withMatcher("name",contains())
|
|
|
+// .withMatcher("studentCode",contains())
|
|
|
+// .withMatcher("specialtyName",contains()).withIgnoreNullValues();
|
|
|
+// Example<ExamStudent> examExamStudentple = Example.of(examStudentSearch, exampleMatcher);
|
|
|
+// Page<ExamStudent> examStudents = examStudentRepo.findAll(examExamStudentple,pageable);
|
|
|
+// return examStudents;
|
|
|
Specification<ExamStudent> specification = getSpecification(examCriteria);
|
|
|
- return examStudentRepo.findAll(specification,pageable);
|
|
|
+ Page<ExamStudent> examStudents = examStudentRepo.findAll(specification,pageable);
|
|
|
+ return examStudents;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -185,7 +195,7 @@ public class ExamStudentService {
|
|
|
|
|
|
/**
|
|
|
* 考生导入验证
|
|
|
- * @param stu
|
|
|
+ * @param dto
|
|
|
* @return
|
|
|
*/
|
|
|
public ExcelError importCheck(ExamStudentDTO dto){
|
|
@@ -247,27 +257,33 @@ public class ExamStudentService {
|
|
|
private Specification<ExamStudent> getSpecification(ExamStudentDTO examCriteria) {
|
|
|
Specification<ExamStudent> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
- if(null!=examCriteria.getRootOrgId()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getRootOrgId())){
|
|
|
predicates.add(cb.equal(root.get("rootOrgId"),examCriteria.getRootOrgId()));
|
|
|
}
|
|
|
- if(null!=examCriteria.getOrgId()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getOrgId())){
|
|
|
predicates.add(cb.equal(root.get("orgId"),examCriteria.getOrgId()));
|
|
|
}
|
|
|
- if(null!=examCriteria.getExam()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getExam())){
|
|
|
predicates.add(cb.equal(root.get("exam").get("id"),examCriteria.getExam().getId()));
|
|
|
}
|
|
|
- if(null!=examCriteria.getName()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getName())){
|
|
|
predicates.add(cb.like(root.get("name"),"%"+examCriteria.getName()+"%"));
|
|
|
}
|
|
|
- if(null!=examCriteria.getStudentCode()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getStudentCode())){
|
|
|
predicates.add(cb.like(root.get("studentCode"),"%"+examCriteria.getStudentCode()+"%"));
|
|
|
}
|
|
|
- if(null!=examCriteria.getFinished()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getCourseCode())){
|
|
|
+ predicates.add(cb.equal(root.get("courseCode"),examCriteria.getCourseCode()));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getFinished())){
|
|
|
predicates.add(cb.equal(root.get("finished"),examCriteria.getFinished()));
|
|
|
}
|
|
|
- if(null!=examCriteria.getStudentId()){
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getStudentId())){
|
|
|
predicates.add(cb.equal(root.get("studentId"),examCriteria.getStudentId()));
|
|
|
}
|
|
|
+ if(!StringUtils.isEmpty(examCriteria.getExamSite())){
|
|
|
+ predicates.add(cb.like(root.get("examSite"),"%"+examCriteria.getExamSite()+"%"));
|
|
|
+ }
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
return specification;
|