From ccbbaacc44c4226319ef54d3028c7cfdd2d71d3d Mon Sep 17 00:00:00 2001 From: YuJeeun Date: Sat, 16 Nov 2024 20:19:35 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80:=20RequestCountByCategoryVO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/reqeust/RequestCountByCategoryVO.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LearnsMate/src/main/java/intbyte4/learnsmate/voc/domain/vo/reqeust/RequestCountByCategoryVO.java diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/domain/vo/reqeust/RequestCountByCategoryVO.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/domain/vo/reqeust/RequestCountByCategoryVO.java new file mode 100644 index 00000000..cf2ed547 --- /dev/null +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/domain/vo/reqeust/RequestCountByCategoryVO.java @@ -0,0 +1,20 @@ +package intbyte4.learnsmate.voc.domain.vo.reqeust; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class RequestCountByCategoryVO { + private LocalDateTime startDate; + private LocalDateTime endDate; +} From 1514a47d01b922d79f7aa10a14ed89641eded34d Mon Sep 17 00:00:00 2001 From: YuJeeun Date: Sat, 16 Nov 2024 20:20:58 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95:=20VOCController=20->=20countVOCByCategory=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../learnsmate/voc/controller/VOCController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/controller/VOCController.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/controller/VOCController.java index 035c82f0..50c0842b 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/controller/VOCController.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/controller/VOCController.java @@ -3,6 +3,7 @@ import intbyte4.learnsmate.common.exception.CommonException; import intbyte4.learnsmate.member.domain.dto.MemberDTO; import intbyte4.learnsmate.voc.domain.dto.VOCDTO; +import intbyte4.learnsmate.voc.domain.vo.reqeust.RequestCountByCategoryVO; import intbyte4.learnsmate.voc.domain.vo.response.ResponseCountByCategoryVO; import intbyte4.learnsmate.voc.domain.vo.response.ResponseFindVOCVO; import intbyte4.learnsmate.voc.mapper.VOCMapper; @@ -80,10 +81,12 @@ public ResponseEntity> listAnsweredVOC(@PathVariable("me return ResponseEntity.status(HttpStatus.OK).body(response); } - @Operation(summary = "직원 - VOC 카테고리 별 개수 조회") + @Operation(summary = "직원 - 기간 별 VOC 카테고리 별 개수 조회") @GetMapping("/count-by-category") - public ResponseEntity> countVOCByCategory() { - Map categoryCountMap = vocService.countVOCByCategory(); + public ResponseEntity> countVOCByCategory + (@RequestBody RequestCountByCategoryVO requestVO) { + Map categoryCountMap = vocService.countVOCByCategory + (requestVO.getStartDate(), requestVO.getEndDate()); List response = categoryCountMap.entrySet().stream() .map(entry -> ResponseCountByCategoryVO.builder() .vocCategoryCode(entry.getKey()) From 15821581378e030dd04866efd30bf8c4e8446b4d Mon Sep 17 00:00:00 2001 From: YuJeeun Date: Sat, 16 Nov 2024 20:21:23 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95:=20VOCRepository=20->=20countByVocCategory=5FVocCateg?= =?UTF-8?q?oryCode=EC=82=AD=EC=A0=9C,countByVocCategoryCodeAndDateRange=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intbyte4/learnsmate/voc/repository/VOCRepository.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java index 057cf03a..14ac1229 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.time.LocalDateTime; import java.util.List; @Repository @@ -21,5 +22,8 @@ public interface VOCRepository extends JpaRepository, VOCRepositoryCu "AND v.vocAnswerStatus = true") List findAnsweredVOCByMember(@Param("memberCode") Long memberCode); - long countByVocCategory_VocCategoryCode(Integer vocCategoryCode); + @Query("SELECT COUNT(v) FROM Voc v WHERE v.vocCategory.vocCategoryCode = :vocCategoryCode AND v.createdAt BETWEEN :startDate AND :endDate") + long countByVocCategoryCodeAndDateRange(@Param("vocCategoryCode") Integer vocCategoryCode, + @Param("startDate") LocalDateTime startDate, + @Param("endDate") LocalDateTime endDate); } From fd6c3a138d5a48b9ce1029d61da0a455feec8de7 Mon Sep 17 00:00:00 2001 From: YuJeeun Date: Sat, 16 Nov 2024 20:21:42 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95:=20VOCService=20->=20countVOCByCategory=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/intbyte4/learnsmate/voc/service/VOCService.java | 3 ++- .../intbyte4/learnsmate/voc/service/VOCServiceImpl.java | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCService.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCService.java index 84512462..067989a1 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCService.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCService.java @@ -3,6 +3,7 @@ import intbyte4.learnsmate.member.domain.dto.MemberDTO; import intbyte4.learnsmate.voc.domain.dto.VOCDTO; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -19,5 +20,5 @@ public interface VOCService { List filterVOC(VOCDTO vocDTO, MemberDTO memberDTO); - Map countVOCByCategory(); + Map countVOCByCategory(LocalDateTime startDate, LocalDateTime endDate); } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java index 051e636f..35fb8165 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -93,15 +94,15 @@ public List filterVOC(VOCDTO vocDTO, MemberDTO memberDTO) { } @Override - public Map countVOCByCategory(){ + public Map countVOCByCategory(LocalDateTime startDate, LocalDateTime endDate){ List vocCategoryDTOList = vocCategoryService.findAll(); Map categoryCountMap = new HashMap<>(); vocCategoryDTOList.forEach(category -> { - int categoryCode = category.getVocCategoryCode(); - long count = vocRepository.countByVocCategory_VocCategoryCode(categoryCode); - categoryCountMap.put(categoryCode, count); + int vocCategoryCode = category.getVocCategoryCode(); + long count = vocRepository.countByVocCategoryCodeAndDateRange(vocCategoryCode, startDate, endDate); + categoryCountMap.put(vocCategoryCode, count); }); return categoryCountMap; From 8d9a7176c4e2987c663c4c52c21eeb0c3e287bb1 Mon Sep 17 00:00:00 2001 From: YuJeeun Date: Sat, 16 Nov 2024 20:37:13 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80:=20VOCRepository=20->=20countByVocCategory=5FVocCateg?= =?UTF-8?q?oryCode=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/intbyte4/learnsmate/voc/repository/VOCRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java index 14ac1229..26df506c 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/repository/VOCRepository.java @@ -26,4 +26,6 @@ public interface VOCRepository extends JpaRepository, VOCRepositoryCu long countByVocCategoryCodeAndDateRange(@Param("vocCategoryCode") Integer vocCategoryCode, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); + + long countByVocCategory_VocCategoryCode(Integer vocCategoryCode); } From 58e2213087b79f7e63160de99d4dab202765f061 Mon Sep 17 00:00:00 2001 From: YuJeeun Date: Sat, 16 Nov 2024 20:37:35 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95:=20VOCService=20->=20countVOCByCategory=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intbyte4/learnsmate/voc/service/VOCServiceImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java index 35fb8165..004a3150 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/voc/service/VOCServiceImpl.java @@ -101,7 +101,12 @@ public Map countVOCByCategory(LocalDateTime startDate, LocalDateT vocCategoryDTOList.forEach(category -> { int vocCategoryCode = category.getVocCategoryCode(); - long count = vocRepository.countByVocCategoryCodeAndDateRange(vocCategoryCode, startDate, endDate); + long count; + if(startDate != null && endDate != null) { + count = vocRepository.countByVocCategoryCodeAndDateRange(vocCategoryCode, startDate, endDate); + } else { + count = vocRepository.countByVocCategory_VocCategoryCode(vocCategoryCode); + } categoryCountMap.put(vocCategoryCode, count); });