Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.data.jpa.domain.Specification;

import java.time.LocalDateTime;
import java.util.List;

public class SearchSpecification {

Expand Down Expand Up @@ -53,25 +52,24 @@ public static Specification<CaseEntity> hasPolice(String police) {
// police == null ? criteriaBuilder.conjunction() : criteriaBuilder.equal(root.get("police"), police);
}


// cctv_id ํ•„ํ„ฐ ์ถ”๊ฐ€ (cctv_info ํ…Œ์ด๋ธ”์—์„œ ๊ฐ€์ ธ์˜จ id ๊ฐ’)
public static Specification<CaseEntity> hasCctvIds(List<Integer> cctvIds) {
// ์ฃผ์†Œ ํฌํ•จ ํ•„ํ„ฐ
public static Specification<CaseEntity> hasAddress(String address) {
return (root, query, criteriaBuilder) -> {
if (cctvIds == null || cctvIds.isEmpty()) {
return criteriaBuilder.conjunction(); // ์กฐ๊ฑด ์—†์œผ๋ฉด ์ „์ฒด ์กฐํšŒ
if (address == null || address.trim().isEmpty()) {
return criteriaBuilder.conjunction();
}
return root.get("cctv").get("id").in(cctvIds);
return criteriaBuilder.like(root.get("cctv").get("address"), "%" + address + "%");
};
}

// ์—ฌ๋Ÿฌ ์กฐ๊ฑด์„ ์กฐํ•ฉํ•˜๋Š” ๋ฉ”์„œ๋“œ
public static Specification<CaseEntity> filterCases(String category, LocalDateTime startDate, LocalDateTime endDate, String police, List<Integer> cctvIds, Integer officeId) {
public static Specification<CaseEntity> filterCases(String category, LocalDateTime startDate, LocalDateTime endDate, String police, String address, Integer officeId) {
return Specification
.where(hasOffice(officeId))
.and(hasState("์™„๋ฃŒ"))
.and(hasDateRange(startDate, endDate)) // ๋‚ ์งœ ๋ฒ”์œ„ ์กฐ๊ฑด์„ ์ถ”๊ฐ€
.and(hasCctvIds(cctvIds))
.and(hasPolice(police)) // police ํ•„ํ„ฐ ์ถ”๊ฐ€
.and(hasDateRange(startDate, endDate))
.and(hasAddress(address))
.and(hasPolice(police))
.and(hasCategory(category));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.backend.common.domain.CaseEntity;
import com.example.backend.search.domain.SearchSpecification;
import com.example.backend.search.dto.*;
import com.example.backend.search.repository.CctvRepository;
import com.example.backend.search.repository.SearchRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.*;
Expand All @@ -20,18 +19,12 @@
@RequiredArgsConstructor
public class SearchService {
private final SearchRepository searchRepository;
private final CctvRepository cctvRepository;
private static final int PAGE_SIZE = 8; // ํ•œ ํŽ˜์ด์ง€๋‹น 8๊ฐœ์”ฉ

public SearchResult getCheckLog(String category, LocalDateTime startDate, LocalDateTime endDate, String address, String police, String order, Integer page, Integer officeId) {
// address๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ, cctv_info์—์„œ ํ•ด๋‹น ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง„ cctv_id ๋ฆฌ์ŠคํŠธ ์กฐํšŒ
List<Integer> cctvIds = null;
if (address != null) {
cctvIds = cctvRepository.findCctvIdsByAddress(address);
}

// ๋™์  ๊ฒ€์ƒ‰ ์กฐ๊ฑด ์ƒ์„ฑ
Specification<CaseEntity> spec = SearchSpecification.filterCases(category, startDate, endDate, police, cctvIds, officeId);
Specification<CaseEntity> spec = SearchSpecification.filterCases(category, startDate, endDate, police, address, officeId);

// ์ •๋ ฌ ์„ค์ •
Sort sort = Sort.unsorted();
Expand Down
Loading