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 @@ -36,10 +36,12 @@ public ResponseEntity<ApiResponse<ProcessResponseDTO>> create(@Valid @RequestBod
public ResponseEntity<ApiResponse<PageResponseDto<ProcessResponseDTO>>> 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<ProcessResponseDTO> response = processService.search(q, status, page, size);
PageResponseDto<ProcessResponseDTO> response = processService.search(q, status, categoryId, groupId, page, size);
return ApiResponse.success(SuccessStatus.OK, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProcessStepResponseDTO> steps;

public ProcessResponseDTO(Process p) {
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,38 @@ public interface ProcessRepository extends JpaRepository<Process, Long> {

// 검색 메서드 추가 (공정코드, 부품명으로 검색, 상태 필터)
@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<Process> search(
@Param("q") String q,
@Param("status") ProcessStatus status,
@Param("categoryId") Long categoryId,
@Param("groupId") Long groupId,
Pageable pageable
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public ProcessResponseDTO create(ProcessCreateRequestDTO req) {
}

@Transactional(readOnly = true)
public PageResponseDto<ProcessResponseDTO> search(String q, ProcessStatus status, int page, int size) {
public PageResponseDto<ProcessResponseDTO> 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<Process> result = processRepository.search(keyword, status, pageable);
Page<Process> result = processRepository.search(keyword, status, categoryId, groupId, pageable);

return PageResponseDto.<ProcessResponseDTO>builder()
.content(result.map(ProcessResponseDTO::new).toList())
Expand Down