| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.data.jpa.domain.Specification; |
| | | |
| | | import javax.persistence.criteria.CriteriaBuilder; |
| | | import javax.persistence.criteria.CriteriaQuery; |
| | | import javax.persistence.criteria.Predicate; |
| | | import javax.persistence.criteria.Root; |
| | | import javax.persistence.criteria.*; |
| | | import java.util.*; |
| | | |
| | | import static com.pollex.pam.consts.SeniorityQueryConst.*; |
| | | |
| | | public class ConsultantQuerySpec { |
| | | private ConsultantQuerySpec() { |
| | |
| | | } |
| | | |
| | | if(Objects.nonNull(param.getAvgScore()) && param.getAvgScore().intValue() != 0) { |
| | | set.add(criteriaBuilder.between(root.get("avgScore"), param.getAvgScore().intValue() - 1, param.getAvgScore().intValue() + 1)); |
| | | set.add(criteriaBuilder.greaterThanOrEqualTo(root.get("avgScore"), param.getAvgScore().intValue())); |
| | | } |
| | | |
| | | Predicate[] predicates = new Predicate[set.size()]; |
| | | predicates = set.toArray(predicates); |
| | | return criteriaBuilder.or(predicates); |
| | | return criteriaBuilder.and(predicates); |
| | | } |
| | | }; |
| | | } |
| | |
| | | } |
| | | |
| | | if(Objects.nonNull(param.getAvgScore()) && param.getAvgScore().intValue() != 0) { |
| | | set.add(criteriaBuilder.between(root.get("avgScore"), param.getAvgScore().intValue() - 1, param.getAvgScore().intValue() + 1)); |
| | | set.add(criteriaBuilder.greaterThanOrEqualTo(root.get("avgScore"), param.getAvgScore().intValue())); |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(param.getSeniority()) && !StringUtils.equals(UNLIMITED, param.getSeniority())) { |
| | | if(YOUNG.equals(param.getSeniority())) { |
| | | set.add(criteriaBuilder.lessThanOrEqualTo(root.get("seniorityYear"), 5)); |
| | | } |
| | | else if(SENIOR.equals(param.getSeniority())) { |
| | | set.add(criteriaBuilder.greaterThan(root.get("seniorityYear"), 5)); |
| | | } |
| | | } |
| | | |
| | | if(StringUtils.isNotEmpty(param.getArea())) { |
| | | set.add(criteriaBuilder.like(root.get("serveArea"), "%" + param.getArea() + "%")); |
| | | Predicate predicate1 = criteriaBuilder.like(root.get("serveArea"), "%" + param.getArea() + "%"); |
| | | Predicate predicate2 = criteriaBuilder.like(root.get("serveArea"), "%全台%"); |
| | | |
| | | Predicate finalPredicate = criteriaBuilder.or(predicate1, predicate2); |
| | | set.add(finalPredicate); |
| | | } |
| | | |
| | | List<String> allRequirements = Objects.nonNull(param.getRequirements()) ? param.getRequirements() : new ArrayList<>(); |