|
@@ -0,0 +1,60 @@
|
|
|
+package cn.com.qmth.examcloud.service.examwork.service;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.service.examwork.dao.ExamOrgTimeRepo;
|
|
|
+import cn.com.qmth.examcloud.service.examwork.entity.ExamOrgTime;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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 javax.persistence.criteria.Predicate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by songyue on 18/3/1.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExamOrgTimeService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExamOrgTimeRepo examOrgTimeRepo;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有学习中心考试时间(分页)
|
|
|
+ * @param examOrgTime
|
|
|
+ * @param pageable
|
|
|
+ * @return
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<ExamOrgTime> getAllOrgTime(ExamOrgTime examOrgTime, Pageable pageable){
|
|
|
+ Specification<ExamOrgTime> specification = getPageSpecification(examOrgTime);
|
|
|
+ Page<ExamOrgTime> examOrgTimes = examOrgTimeRepo.findAll(specification,pageable);
|
|
|
+ return examOrgTimes;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成查询条件
|
|
|
+ * @param examOrgTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Specification<ExamOrgTime> getPageSpecification(ExamOrgTime examOrgTime) {
|
|
|
+ Specification<ExamOrgTime> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ if(!StringUtils.isEmpty(examOrgTime.getExamId())){
|
|
|
+ predicates.add(cb.equal(root.get("examId"),examOrgTime.getExamId()));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(examOrgTime.getOrgCode())){
|
|
|
+ predicates.add(cb.like(root.get("orgCode"),"%"+examOrgTime.getOrgCode()+"%"));
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(examOrgTime.getOrgName())){
|
|
|
+ predicates.add(cb.like(root.get("orgName"),"%"+examOrgTime.getOrgName()+"%"));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+ return specification;
|
|
|
+ }
|
|
|
+}
|