From 5479865b9cee5ae0677528cb8443f3b83a157ab5 Mon Sep 17 00:00:00 2001 From: yangjiseonn Date: Fri, 7 Nov 2025 00:42:55 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EA=B3=B5=EC=A0=95=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EA=B2=80=EC=83=89/=EC=83=81=EC=84=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=ED=99=95=EC=9E=A5=20(=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC/=EA=B7=B8=EB=A3=B9=20=ED=91=9C=EC=8B=9C,=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=ED=95=84=ED=84=B0=20=EC=B6=94=EA=B0=80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../process/controller/ProcessController.java | 4 +- .../api/process/dto/ProcessResponseDTO.java | 18 ++++++++ .../process/repository/ProcessRepository.java | 42 ++++++++++++------- .../api/process/service/ProcessService.java | 4 +- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/sampoom/backend/api/process/controller/ProcessController.java b/src/main/java/com/sampoom/backend/api/process/controller/ProcessController.java index 6f78e2a..1733548 100644 --- a/src/main/java/com/sampoom/backend/api/process/controller/ProcessController.java +++ b/src/main/java/com/sampoom/backend/api/process/controller/ProcessController.java @@ -36,10 +36,12 @@ public ResponseEntity> create(@Valid @RequestBod public ResponseEntity>> search( @RequestParam(value = "query", required = false) String q, @RequestParam(value = "status", required = false) ProcessStatus status, + @RequestParam(value = "categoryId", required = false) Long categoryId, + @RequestParam(value = "groupId", required = false) Long groupId, @RequestParam(value = "page", defaultValue = "0") int page, @RequestParam(value = "size", defaultValue = "10") int size ) { - PageResponseDto response = processService.search(q, status, page, size); + PageResponseDto response = processService.search(q, status, categoryId, groupId, page, size); return ApiResponse.success(SuccessStatus.OK, response); } diff --git a/src/main/java/com/sampoom/backend/api/process/dto/ProcessResponseDTO.java b/src/main/java/com/sampoom/backend/api/process/dto/ProcessResponseDTO.java index 3e146c6..1ce5934 100644 --- a/src/main/java/com/sampoom/backend/api/process/dto/ProcessResponseDTO.java +++ b/src/main/java/com/sampoom/backend/api/process/dto/ProcessResponseDTO.java @@ -23,6 +23,12 @@ public class ProcessResponseDTO { private final Integer totalWaitMinutes; // 모든 스텝의 대기시간 합계 private final Integer totalStepMinutes; // 모든 스텝의 총 시간 합계 private final Long totalProcessCost; // 총 공정비용 (원) + + private final Long categoryId; + private final String categoryName; + private final Long groupId; + private final String groupName; + private final List steps; public ProcessResponseDTO(Process p) { @@ -40,6 +46,18 @@ public ProcessResponseDTO(Process p) { this.totalWaitMinutes = p.getTotalWaitMinutes(); this.totalStepMinutes = p.getTotalStepMinutes(); this.totalProcessCost = p.getTotalProcessCost(); + + this.categoryId = (p.getPart().getPartGroup() != null && p.getPart().getPartGroup().getCategory() != null) + ? p.getPart().getPartGroup().getCategory().getId() + : null; + + this.categoryName = (p.getPart().getPartGroup() != null && p.getPart().getPartGroup().getCategory() != null) + ? p.getPart().getPartGroup().getCategory().getName() + : null; + + this.groupId = p.getPart().getPartGroup() != null ? p.getPart().getPartGroup().getId() : null; + this.groupName = p.getPart().getPartGroup() != null ? p.getPart().getPartGroup().getName() : null; + this.steps = p.getSteps().stream().map(ProcessStepResponseDTO::new).collect(Collectors.toList()); } } diff --git a/src/main/java/com/sampoom/backend/api/process/repository/ProcessRepository.java b/src/main/java/com/sampoom/backend/api/process/repository/ProcessRepository.java index dad5606..7ab77fe 100644 --- a/src/main/java/com/sampoom/backend/api/process/repository/ProcessRepository.java +++ b/src/main/java/com/sampoom/backend/api/process/repository/ProcessRepository.java @@ -19,26 +19,38 @@ public interface ProcessRepository extends JpaRepository { // 검색 메서드 추가 (공정코드, 부품명으로 검색, 상태 필터) @Query( - value = """ - SELECT DISTINCT p FROM Process p - JOIN FETCH p.part part - WHERE (:q IS NULL OR :q = '' - OR LOWER(p.code) LIKE CONCAT('%', LOWER(:q), '%') - OR LOWER(part.name) LIKE CONCAT('%', LOWER(:q), '%')) - AND (:status IS NULL OR p.status = :status) + value = """ + SELECT DISTINCT p FROM Process p + JOIN FETCH p.part part + LEFT JOIN FETCH part.partGroup g + LEFT JOIN FETCH g.category c + WHERE (:q IS NULL OR :q = '' + OR LOWER(p.code) LIKE CONCAT('%', LOWER(:q), '%') + OR LOWER(part.code) LIKE CONCAT('%', LOWER(:q), '%') + OR LOWER(part.name) LIKE CONCAT('%', LOWER(:q), '%')) + AND (:status IS NULL OR p.status = :status) + AND (:categoryId IS NULL OR c.id = :categoryId) + AND (:groupId IS NULL OR g.id = :groupId) """, - countQuery = """ - SELECT COUNT(p) FROM Process p - JOIN p.part part - WHERE (:q IS NULL OR :q = '' - OR LOWER(p.code) LIKE CONCAT('%', LOWER(:q), '%') - OR LOWER(part.name) LIKE CONCAT('%', LOWER(:q), '%')) - AND (:status IS NULL OR p.status = :status) + countQuery = """ + SELECT COUNT(p) FROM Process p + JOIN p.part part + LEFT JOIN part.partGroup g + LEFT JOIN g.category c + WHERE (:q IS NULL OR :q = '' + OR LOWER(p.code) LIKE CONCAT('%', LOWER(:q), '%') + OR LOWER(part.code) LIKE CONCAT('%', LOWER(:q), '%') + OR LOWER(part.name) LIKE CONCAT('%', LOWER(:q), '%')) + AND (:status IS NULL OR p.status = :status) + AND (:categoryId IS NULL OR c.id = :categoryId) + AND (:groupId IS NULL OR g.id = :groupId) """ - ) + ) Page search( @Param("q") String q, @Param("status") ProcessStatus status, + @Param("categoryId") Long categoryId, + @Param("groupId") Long groupId, Pageable pageable ); diff --git a/src/main/java/com/sampoom/backend/api/process/service/ProcessService.java b/src/main/java/com/sampoom/backend/api/process/service/ProcessService.java index 6bdd384..171490a 100644 --- a/src/main/java/com/sampoom/backend/api/process/service/ProcessService.java +++ b/src/main/java/com/sampoom/backend/api/process/service/ProcessService.java @@ -98,14 +98,14 @@ public ProcessResponseDTO create(ProcessCreateRequestDTO req) { } @Transactional(readOnly = true) - public PageResponseDto search(String q, ProcessStatus status, int page, int size) { + public PageResponseDto search(String q, ProcessStatus status, Long categoryId, Long groupId, int page, int size) { int safePage = Math.max(page, 0); int safeSize = Math.min(Math.max(size, 1), 100); Pageable pageable = PageRequest.of(safePage, safeSize, Sort.by(Sort.Direction.DESC, "id")); String keyword = (q == null || q.isBlank()) ? null : q.trim(); - Page result = processRepository.search(keyword, status, pageable); + Page result = processRepository.search(keyword, status, categoryId, groupId, pageable); return PageResponseDto.builder() .content(result.map(ProcessResponseDTO::new).toList())