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 @@ -118,4 +118,34 @@ public ResponseEntity<ApiResponse<List<PartOrderResponseDto>>> confirmMps(

return ApiResponse.success(SuccessStatus.CREATED, partOrders);
}

@Operation(summary = "MPS 부품 목록 조회", description = "해당 공장에 저장된 MPS의 모든 부품 ID 목록을 조회합니다.")
@GetMapping("/parts")
public ResponseEntity<ApiResponse<List<Long>>> getMpsPartList(
@Parameter(description = "공장 ID", required = true) @PathVariable Long factoryId) {

log.info("MPS 부품 목록 조회 요청 - factoryId: {}", factoryId);

List<Long> partIds = mpsService.getMpsPartListByFactory(factoryId);

log.info("MPS 부품 목록 조회 성공 - factoryId: {}, 부품 수: {}", factoryId, partIds.size());

return ApiResponse.success(SuccessStatus.OK, partIds);
}

@Operation(summary = "특정 부품의 예측 달 조회", description = "특정 부품 ID에 대한 모든 예측 달(targetDate) 목록을 조회합니다.")
@GetMapping("/parts/{partId}/forecast-months")
public ResponseEntity<ApiResponse<List<LocalDate>>> getPartForecastMonths(
@Parameter(description = "공장 ID", required = true) @PathVariable Long factoryId,
@Parameter(description = "부품 ID", required = true) @PathVariable Long partId) {

log.info("부품 예측 달 조회 요청 - factoryId: {}, partId: {}", factoryId, partId);

List<LocalDate> forecastMonths = mpsService.getForecastMonthsByFactoryAndPart(factoryId, partId);

log.info("부품 예측 달 조회 성공 - factoryId: {}, partId: {}, 예측 달 수: {}",
factoryId, partId, forecastMonths.size());

return ApiResponse.success(SuccessStatus.OK, forecastMonths);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,12 @@ Optional<Mps> findByFactoryIdAndPartIdAndWarehouseIdAndForecastMonth(@Param("fac
// 시작일이 특정 날짜 이전인 MPS 조회 (긴급 생산 필요)
@Query("SELECT m FROM Mps m WHERE m.startDate <= :date AND m.status = :status")
List<Mps> findUrgentMps(@Param("date") LocalDate date, @Param("status") MpsStatus status);
}

// 공장에 저장된 MPS의 모든 부품 ID 목록 조회 (중복 제거)
@Query("SELECT DISTINCT m.partId FROM Mps m WHERE m.factoryId = :factoryId ORDER BY m.partId")
List<Long> findDistinctPartIdsByFactoryId(@Param("factoryId") Long factoryId);

// 특정 부품 ID에 대한 모든 예측 달(targetDate) 목록 조회 (중복 제거, 정렬)
@Query("SELECT DISTINCT m.targetDate FROM Mps m WHERE m.factoryId = :factoryId AND m.partId = :partId ORDER BY m.targetDate")
List<LocalDate> findDistinctTargetDatesByFactoryIdAndPartId(@Param("factoryId") Long factoryId, @Param("partId") Long partId);
}
26 changes: 26 additions & 0 deletions src/main/java/com/sampoom/factory/api/mps/service/MpsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,31 @@ public List<PartOrderResponseDto> confirmMps(Long factoryId, Long mpsId) {
return partOrderResponses;
}

/**
* 공장에 저장된 MPS의 모든 부품 ID 목록 조회
*/
public List<Long> getMpsPartListByFactory(Long factoryId) {
log.info("MPS 부품 목록 조회 시작 - factoryId: {}", factoryId);

List<Long> partIds = mpsRepository.findDistinctPartIdsByFactoryId(factoryId);

log.info("MPS 부품 목록 조회 완료 - factoryId: {}, 부품 수: {}", factoryId, partIds.size());

return partIds;
}

/**
* 특정 부품 ID에 대한 모든 예측 달(targetDate) 목록 조회
*/
public List<LocalDate> getForecastMonthsByFactoryAndPart(Long factoryId, Long partId) {
log.info("부품 예측 달 조회 시작 - factoryId: {}, partId: {}", factoryId, partId);

List<LocalDate> forecastMonths = mpsRepository.findDistinctTargetDatesByFactoryIdAndPartId(factoryId, partId);

log.info("부품 예측 달 조회 완료 - factoryId: {}, partId: {}, 예측 달 수: {}",
factoryId, partId, forecastMonths.size());

return forecastMonths;
}

}