|
4 | 4 | import org.springframework.data.jpa.domain.Specification; |
5 | 5 |
|
6 | 6 | import java.time.LocalDateTime; |
7 | | -import java.util.List; |
8 | 7 |
|
9 | 8 | public class SearchSpecification { |
10 | 9 |
|
@@ -53,25 +52,24 @@ public static Specification<CaseEntity> hasPolice(String police) { |
53 | 52 | // police == null ? criteriaBuilder.conjunction() : criteriaBuilder.equal(root.get("police"), police); |
54 | 53 | } |
55 | 54 |
|
56 | | - |
57 | | - // cctv_id 필터 추가 (cctv_info 테이블에서 가져온 id 값) |
58 | | - public static Specification<CaseEntity> hasCctvIds(List<Integer> cctvIds) { |
| 55 | + // 주소 포함 필터 |
| 56 | + public static Specification<CaseEntity> hasAddress(String address) { |
59 | 57 | return (root, query, criteriaBuilder) -> { |
60 | | - if (cctvIds == null || cctvIds.isEmpty()) { |
61 | | - return criteriaBuilder.conjunction(); // 조건 없으면 전체 조회 |
| 58 | + if (address == null || address.trim().isEmpty()) { |
| 59 | + return criteriaBuilder.conjunction(); |
62 | 60 | } |
63 | | - return root.get("cctv").get("id").in(cctvIds); |
| 61 | + return criteriaBuilder.like(root.get("cctv").get("address"), "%" + address + "%"); |
64 | 62 | }; |
65 | 63 | } |
66 | 64 |
|
67 | 65 | // 여러 조건을 조합하는 메서드 |
68 | | - public static Specification<CaseEntity> filterCases(String category, LocalDateTime startDate, LocalDateTime endDate, String police, List<Integer> cctvIds, Integer officeId) { |
| 66 | + public static Specification<CaseEntity> filterCases(String category, LocalDateTime startDate, LocalDateTime endDate, String police, String address, Integer officeId) { |
69 | 67 | return Specification |
70 | 68 | .where(hasOffice(officeId)) |
71 | 69 | .and(hasState("완료")) |
72 | | - .and(hasDateRange(startDate, endDate)) // 날짜 범위 조건을 추가 |
73 | | - .and(hasCctvIds(cctvIds)) |
74 | | - .and(hasPolice(police)) // police 필터 추가 |
| 70 | + .and(hasDateRange(startDate, endDate)) |
| 71 | + .and(hasAddress(address)) |
| 72 | + .and(hasPolice(police)) |
75 | 73 | .and(hasCategory(category)); |
76 | 74 | } |
77 | 75 |
|
|
0 commit comments