You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.3 KiB
30 lines
1.3 KiB
package com.mydreamjob.job;
|
|
|
|
import jakarta.persistence.criteria.Predicate;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
/** 企业私有岗位列表查询;租户条件始终是必选条件。 */
|
|
public final class CompanyJobManagementSpecification {
|
|
private CompanyJobManagementSpecification() {}
|
|
|
|
public static Specification<Job> forCompany(long companyId, String status, String keyword, String city) {
|
|
return (root, query, cb) -> {
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
predicates.add(cb.equal(root.get("companyId"), companyId));
|
|
if (status != null) predicates.add(cb.equal(root.get("status"), status));
|
|
if (keyword != null) {
|
|
// LOCATE treats % and _ literally and is supported by both H2 and MySQL.
|
|
predicates.add(cb.greaterThan(cb.locate(
|
|
cb.lower(root.get("title")), keyword.toLowerCase(Locale.ROOT)), 0));
|
|
}
|
|
if (city != null) {
|
|
predicates.add(cb.equal(cb.lower(root.get("city")), city.toLowerCase(Locale.ROOT)));
|
|
}
|
|
return cb.and(predicates.toArray(Predicate[]::new));
|
|
};
|
|
}
|
|
|
|
}
|
|
|