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()) 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; +} 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..26df506c 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,10 @@ public interface VOCRepository extends JpaRepository, VOCRepositoryCu "AND v.vocAnswerStatus = true") List findAnsweredVOCByMember(@Param("memberCode") Long memberCode); + @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); + long countByVocCategory_VocCategoryCode(Integer vocCategoryCode); } 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..004a3150 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,20 @@ 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; + if(startDate != null && endDate != null) { + count = vocRepository.countByVocCategoryCodeAndDateRange(vocCategoryCode, startDate, endDate); + } else { + count = vocRepository.countByVocCategory_VocCategoryCode(vocCategoryCode); + } + categoryCountMap.put(vocCategoryCode, count); }); return categoryCountMap;