Skip to content

Commit

Permalink
Merge pull request #195 from LearnsMate/feature/voc
Browse files Browse the repository at this point in the history
✨ 기능 수정: VOCService -> countVOCByCategory 수정
  • Loading branch information
YuJeeun authored Nov 16, 2024
2 parents 4fa1837 + 58e2213 commit 0f0815c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,10 +81,12 @@ public ResponseEntity<List<ResponseFindVOCVO>> listAnsweredVOC(@PathVariable("me
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@Operation(summary = "직원 - VOC 카테고리 별 개수 조회")
@Operation(summary = "직원 - 기간 별 VOC 카테고리 별 개수 조회")
@GetMapping("/count-by-category")
public ResponseEntity<List<ResponseCountByCategoryVO>> countVOCByCategory() {
Map<Integer, Long> categoryCountMap = vocService.countVOCByCategory();
public ResponseEntity<List<ResponseCountByCategoryVO>> countVOCByCategory
(@RequestBody RequestCountByCategoryVO requestVO) {
Map<Integer, Long> categoryCountMap = vocService.countVOCByCategory
(requestVO.getStartDate(), requestVO.getEndDate());
List<ResponseCountByCategoryVO> response = categoryCountMap.entrySet().stream()
.map(entry -> ResponseCountByCategoryVO.builder()
.vocCategoryCode(entry.getKey())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,5 +22,10 @@ public interface VOCRepository extends JpaRepository<VOC, Long>, VOCRepositoryCu
"AND v.vocAnswerStatus = true")
List<VOC> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -19,5 +20,5 @@ public interface VOCService {

List<VOCDTO> filterVOC(VOCDTO vocDTO, MemberDTO memberDTO);

Map<Integer, Long> countVOCByCategory();
Map<Integer, Long> countVOCByCategory(LocalDateTime startDate, LocalDateTime endDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,15 +94,20 @@ public List<VOCDTO> filterVOC(VOCDTO vocDTO, MemberDTO memberDTO) {
}

@Override
public Map<Integer, Long> countVOCByCategory(){
public Map<Integer, Long> countVOCByCategory(LocalDateTime startDate, LocalDateTime endDate){
List<VocCategoryDTO> vocCategoryDTOList = vocCategoryService.findAll();

Map<Integer, Long> 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;
Expand Down

0 comments on commit 0f0815c

Please sign in to comment.