|
@@ -1,21 +1,20 @@
|
|
|
package cn.com.qmth.examcloud.service.core.service;
|
|
|
|
|
|
-import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
|
|
|
-
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
import javax.transaction.Transactional;
|
|
|
|
|
|
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;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import cn.com.qmth.examcloud.common.util.excel.ExcelError;
|
|
|
import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
|
|
@@ -69,22 +68,44 @@ public class CourseService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public Page<Course> findAll(Course orgCriteria, Pageable pageable) {
|
|
|
- ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("name", startsWith())
|
|
|
- .withMatcher("code", startsWith()).withIgnoreNullValues();
|
|
|
- Example<Course> examExamStudentple = Example.of(orgCriteria,
|
|
|
- exampleMatcher);
|
|
|
- return courseRepo.findAll(examExamStudentple, pageable);
|
|
|
+ public Page<Course> findAll(Course courseCriteria, Pageable pageable) {
|
|
|
+// ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
+// .withMatcher("name", startsWith())
|
|
|
+// .withMatcher("code", startsWith()).withIgnoreNullValues();
|
|
|
+// Example<Course> examExamStudentple = Example.of(orgCriteria,
|
|
|
+// exampleMatcher);
|
|
|
+// return courseRepo.findAll(examExamStudentple, pageable);
|
|
|
+ Specification<Course> specification = getSpecification(courseCriteria);
|
|
|
+ Page<Course> examStudents = courseRepo.findAll(specification,pageable);
|
|
|
+ return examStudents;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Specification<Course> getSpecification(Course courseCriteria) {
|
|
|
+ Specification<Course> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if(!StringUtils.isEmpty(courseCriteria.getOrgId())){
|
|
|
+ predicates.add(cb.equal(root.get("orgId"),courseCriteria.getOrgId()));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(courseCriteria.getName())){
|
|
|
+ predicates.add(cb.like(root.get("name"),"%"+courseCriteria.getName()+"%"));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(courseCriteria.getCode())){
|
|
|
+ predicates.add(cb.like(root.get("code"),"%"+courseCriteria.getCode()+"%"));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+ return specification;
|
|
|
}
|
|
|
|
|
|
- public List<Course> findAll(Course orgCriteria) {
|
|
|
- ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
- .withMatcher("name", startsWith())
|
|
|
- .withMatcher("code", startsWith()).withIgnoreNullValues();
|
|
|
- Example<Course> examExample = Example.of(orgCriteria,exampleMatcher);
|
|
|
- List<Course> courseList = courseRepo.findAll(examExample);
|
|
|
- return courseList;
|
|
|
+ public List<Course> findAll(Course courseCriteria) {
|
|
|
+// ExampleMatcher exampleMatcher = ExampleMatcher.matching()
|
|
|
+// .withMatcher("name", startsWith())
|
|
|
+// .withMatcher("code", startsWith()).withIgnoreNullValues();
|
|
|
+// Example<Course> examExample = Example.of(orgCriteria,exampleMatcher);
|
|
|
+// List<Course> courseList = courseRepo.findAll(examExample);
|
|
|
+// return courseList;
|
|
|
+ Specification<Course> specification = getSpecification(courseCriteria);
|
|
|
+ return courseRepo.findAll(specification);
|
|
|
}
|
|
|
|
|
|
public Course save(Course course) throws Exception{
|