From d2231e7a62f05ac25aabd43f55348c4de7ccf615 Mon Sep 17 00:00:00 2001 From: meli Date: Thu, 28 Nov 2024 02:06:15 +0900 Subject: [PATCH] [Feat] Diecast Graph --- .../diecast/controller/DiecastController.java | 8 +++++ .../diecast/converter/DiecastConverter.java | 9 ++++++ .../dto/response/DiecastResponseDTO.java | 11 +++++++ .../diecast/repository/DiecastRepository.java | 6 ++++ .../diecast/service/DiecastQueryService.java | 15 +++++++++ .../photo/controller/PhotoController.java | 23 +++++++++++++ .../photo/converter/PhotoConverter.java | 9 ++++++ .../photo/dto/response/PhotoResponseDTO.java | 22 +++++++++++++ .../photo/repository/PhotoRepository.java | 2 ++ .../photo/service/PhotoQueryService.java | 32 +++++++++++++++++++ 10 files changed, 137 insertions(+) diff --git a/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java b/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java index 92cc291..a312b72 100644 --- a/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java +++ b/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java @@ -57,6 +57,14 @@ public DiecastResponseDTO.DiecastListDTO getDiecastList() { } + @GetMapping(value = "/graph/okng") + @Operation(summary = "전체 양불판정 그래프 조회", description = "좌측 양불판정 통계 그래프에 NG OK 개수 보여주기") + public DiecastResponseDTO.DiecastGraphDTO getDiecastGraphOkng() { + DiecastResponseDTO.DiecastGraphDTO diecastGraphDTO = diecastQueryService.getDiecastGraphOkng(); + + return diecastGraphDTO; + + } } diff --git a/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java b/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java index 42d847d..709327d 100644 --- a/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java +++ b/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java @@ -79,4 +79,13 @@ public static DiecastResponseDTO.DiecastListDTO diecastListDTO(List die .build(); } + + + public static DiecastResponseDTO.DiecastGraphDTO diecastGraphDTO(int diecastOk, int diecastNg) { + return DiecastResponseDTO.DiecastGraphDTO.builder() + .diecastOk(diecastOk) + .diecastNg(diecastNg) + .build(); + } + } diff --git a/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java b/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java index 01c7f3e..6fe3f6e 100644 --- a/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java +++ b/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java @@ -70,4 +70,15 @@ public static class DiecastDTO { Long diecastvideoUuid; } + + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class DiecastGraphDTO { + int diecastOk; + int diecastNg; + } + } diff --git a/src/main/java/aws/teamthreefive/diecast/repository/DiecastRepository.java b/src/main/java/aws/teamthreefive/diecast/repository/DiecastRepository.java index 3e39a6a..d43183c 100644 --- a/src/main/java/aws/teamthreefive/diecast/repository/DiecastRepository.java +++ b/src/main/java/aws/teamthreefive/diecast/repository/DiecastRepository.java @@ -2,7 +2,13 @@ import aws.teamthreefive.diecast.entity.Diecast; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface DiecastRepository extends JpaRepository { +// @Query("SELECT d.diecastOkng, COUNT(d) FROM Diecast d GROUP BY d.diecastOkng") +// List countByDiecastOkng(); + } diff --git a/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java b/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java index f3c48b9..5826579 100644 --- a/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java +++ b/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java @@ -1,5 +1,7 @@ package aws.teamthreefive.diecast.service; +import aws.teamthreefive.diecast.converter.DiecastConverter; +import aws.teamthreefive.diecast.dto.response.DiecastResponseDTO; import aws.teamthreefive.diecast.entity.Diecast; import aws.teamthreefive.diecast.repository.DiecastRepository; import aws.teamthreefive.photo.entity.Photo; @@ -36,4 +38,17 @@ public List getDiecastList() { } + public DiecastResponseDTO.DiecastGraphDTO getDiecastGraphOkng() { + + List diecastList = diecastRepository.findAll(); + + int diecastOk = (int) diecastList.stream().filter(d -> d.getDiecastOkng() == 0).count(); + int diecastNg = (int) diecastList.stream().filter(d -> d.getDiecastOkng() == 1).count(); + + DiecastResponseDTO.DiecastGraphDTO diecastGraphDTO = DiecastConverter.diecastGraphDTO(diecastOk, diecastNg); + + return diecastGraphDTO; + + } + } diff --git a/src/main/java/aws/teamthreefive/photo/controller/PhotoController.java b/src/main/java/aws/teamthreefive/photo/controller/PhotoController.java index ee1d506..1c3bcea 100644 --- a/src/main/java/aws/teamthreefive/photo/controller/PhotoController.java +++ b/src/main/java/aws/teamthreefive/photo/controller/PhotoController.java @@ -1,5 +1,6 @@ package aws.teamthreefive.photo.controller; +import aws.teamthreefive.diecast.dto.response.DiecastResponseDTO; import aws.teamthreefive.photo.converter.PhotoConverter; import aws.teamthreefive.photo.dto.response.PhotoResponseDTO; import aws.teamthreefive.photo.entity.Photo; @@ -40,4 +41,26 @@ public PhotoResponseDTO.PhotoListDTO getPhotoListNgCamera( } + @GetMapping(value = "/graph/ng/type") + @Operation(summary = "전체 불량 유형 그래프 조회", description = "좌측 불량 유형 통계 그래프에 불량 유형 개수 보여주기") + public PhotoResponseDTO.PhotoGraphDTO getPhotoGraphNgType() { + + PhotoResponseDTO.PhotoGraphDTO photoGraphDTO = photoQueryService.getPhotoGraphNgType(); + + return photoGraphDTO; + + } + + @GetMapping(value = "/graph/ng/type/{photoPosition}") + @Operation(summary = "카메라별 불량 유형 그래프 조회", description = "카메라별로 통계 그래프에 불량 유형 개수 보여주기") + public PhotoResponseDTO.PhotoGraphDTO getPhotoGraphNgTypePhotoPosition( + @PathVariable(name = "photoPosition") int photoPosition + ) { + + PhotoResponseDTO.PhotoGraphDTO photoGraphDTO = photoQueryService.getPhotoGraphNgTypePhotoPosition(photoPosition); + + return photoGraphDTO; + + } + } diff --git a/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java b/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java index e2a8ae1..3b57d9d 100644 --- a/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java +++ b/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java @@ -33,4 +33,13 @@ public static PhotoResponseDTO.PhotoListDTO photoListDTO(List photoList) } + public static PhotoResponseDTO.PhotoGraphDTO photoGraphDTO(int photoNgtypeOne, int photoNgtypeTwo, int photoNgtypeTree, int photoNgtypeFour) { + return PhotoResponseDTO.PhotoGraphDTO.builder() + .photoNgtypeOne(photoNgtypeOne) + .photoNgtypeTwo(photoNgtypeTwo) + .photoNgtypeThree(photoNgtypeTree) + .photoNgtypeFour(photoNgtypeFour) + .build(); + } + } diff --git a/src/main/java/aws/teamthreefive/photo/dto/response/PhotoResponseDTO.java b/src/main/java/aws/teamthreefive/photo/dto/response/PhotoResponseDTO.java index 1ab4906..dcfd471 100644 --- a/src/main/java/aws/teamthreefive/photo/dto/response/PhotoResponseDTO.java +++ b/src/main/java/aws/teamthreefive/photo/dto/response/PhotoResponseDTO.java @@ -33,4 +33,26 @@ public static class PhotoDTO { Long diecastUuid; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PhotoGraphDTO { + int photoNgtypeOne; + int photoNgtypeTwo; + int photoNgtypeThree; + int photoNgtypeFour; + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PhotoGraphPositionDTO { + int photoNgtypeOne; + int photoNgtypeTwo; + int photoNgtypeThree; + int photoNgtypeFour; + } + } diff --git a/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java b/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java index c5c6b79..3b18d8b 100644 --- a/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java +++ b/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java @@ -14,4 +14,6 @@ public interface PhotoRepository extends JpaRepository { List findAllByPhotoPositionAndPhotoNgtypeNot(int photoPosition, int photoNgtype); + List findAllByPhotoPosition(int photoPosition); + } diff --git a/src/main/java/aws/teamthreefive/photo/service/PhotoQueryService.java b/src/main/java/aws/teamthreefive/photo/service/PhotoQueryService.java index cbdcc3d..6259279 100644 --- a/src/main/java/aws/teamthreefive/photo/service/PhotoQueryService.java +++ b/src/main/java/aws/teamthreefive/photo/service/PhotoQueryService.java @@ -1,5 +1,7 @@ package aws.teamthreefive.photo.service; +import aws.teamthreefive.photo.converter.PhotoConverter; +import aws.teamthreefive.photo.dto.response.PhotoResponseDTO; import aws.teamthreefive.photo.entity.Photo; import aws.teamthreefive.photo.repository.PhotoRepository; import jakarta.transaction.Transactional; @@ -31,4 +33,34 @@ public List getPhotoListNgCamera(int photoPosition) { } + public PhotoResponseDTO.PhotoGraphDTO getPhotoGraphNgType() { + + List photoList = photoRepository.findAll(); + + int photoNgtypeOne = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 1).count(); + int photoNgtypeTwo = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 2).count(); + int photoNgtypeThree = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 3).count(); + int photoNgtypeFour = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 4).count(); + + PhotoResponseDTO.PhotoGraphDTO photoGraphDTO = PhotoConverter.photoGraphDTO(photoNgtypeOne, photoNgtypeTwo, photoNgtypeThree, photoNgtypeFour); + + return photoGraphDTO; + + } + + public PhotoResponseDTO.PhotoGraphDTO getPhotoGraphNgTypePhotoPosition(int photoPosition) { + + List photoList = photoRepository.findAllByPhotoPosition(photoPosition); + + int photoNgtypeOne = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 1).count(); + int photoNgtypeTwo = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 2).count(); + int photoNgtypeThree = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 3).count(); + int photoNgtypeFour = (int) photoList.stream().filter(p -> p.getPhotoNgtype() == 4).count(); + + PhotoResponseDTO.PhotoGraphDTO photoGraphDTO = PhotoConverter.photoGraphDTO(photoNgtypeOne, photoNgtypeTwo, photoNgtypeThree, photoNgtypeFour); + + return photoGraphDTO; + + } + }