parent
cbfb56ac52
commit
10602de6c9
@ -0,0 +1,51 @@
|
|||||||
|
package kr.re.etri.security.jwt.specification;
|
||||||
|
|
||||||
|
import jakarta.persistence.criteria.Path;
|
||||||
|
import jakarta.persistence.criteria.Predicate;
|
||||||
|
import kr.re.etri.security.jwt.entity.ProjectEntity;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class ProjectSpecification {
|
||||||
|
|
||||||
|
public static Specification<ProjectEntity> searchByConditions(
|
||||||
|
String searchType, String keyword,
|
||||||
|
LocalDate startDate, LocalDate endDate) {
|
||||||
|
|
||||||
|
return (root, query, cb) -> {
|
||||||
|
Predicate predicate = cb.conjunction();
|
||||||
|
|
||||||
|
// 문자열 필드만 지정 (날짜 필드 제외)
|
||||||
|
Set<String> stringFields = Set.of("prjNm", "prjDesc", "delYn");
|
||||||
|
|
||||||
|
if (keyword != null && !keyword.isEmpty()) {
|
||||||
|
if ("전체".equalsIgnoreCase(searchType) || "all".equalsIgnoreCase(searchType)) {
|
||||||
|
predicate = cb.and(predicate, cb.or(
|
||||||
|
cb.like(cb.lower(root.get("prjNm")), "%" + keyword.toLowerCase() + "%"),
|
||||||
|
cb.like(cb.lower(root.get("prjDesc")), "%" + keyword.toLowerCase() + "%"),
|
||||||
|
cb.like(cb.lower(root.get("delYn")), "%" + keyword.toLowerCase() + "%")
|
||||||
|
));
|
||||||
|
} else if (stringFields.contains(searchType)) {
|
||||||
|
predicate = cb.and(predicate,
|
||||||
|
cb.like(cb.lower(root.get(searchType)), "%" + keyword.toLowerCase() + "%"));
|
||||||
|
}
|
||||||
|
// searchType이 날짜 컬럼이면 keyword 검색 안함
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startDate != null) {
|
||||||
|
predicate = cb.and(predicate,
|
||||||
|
cb.greaterThanOrEqualTo(root.get("prjStartDt"), startDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endDate != null) {
|
||||||
|
predicate = cb.and(predicate,
|
||||||
|
cb.lessThanOrEqualTo(root.get("prjEndDt"), endDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
return predicate;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,5 @@
|
|||||||
-- src/main/resources/data.sql
|
-- src/main/resources/data.sql
|
||||||
|
|
||||||
INSERT INTO tb_role (id, name) VALUES (1, 'ROLE_USER');
|
# INSERT INTO tb_role (id, name) VALUES (1, 'ROLE_USER');
|
||||||
INSERT INTO tb_role (id, name) VALUES (2, 'ROLE_MODERATOR');
|
# INSERT INTO tb_role (id, name) VALUES (2, 'ROLE_MODERATOR');
|
||||||
INSERT INTO tb_role (id, name) VALUES (3, 'ROLE_ADMIN');
|
# INSERT INTO tb_role (id, name) VALUES (3, 'ROLE_ADMIN');
|
||||||
|
|||||||
Loading…
Reference in new issue