Skip to content

Commit

Permalink
[ADD] 가계부 분석 - 카테고리 조회 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-Dong-Jun99 committed May 2, 2023
1 parent 9940684 commit 9b3dc76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public ResponseEntity<MonthlyCompare> getAccountBookMonthlyCompare(@PathVariable

@Operation(summary = "가계부 분석용 한달 지출 조회 API")
@GetMapping(value = "/{id}/analyze/month/{year}/{month}")
public ResponseEntity<Page<AccountBookDataQ>> getAccountBookMonthlyRecord(@PathVariable("id") Long id, @PathVariable("year") Long year, @PathVariable("month") Long month, @RequestParam(value = "category", required = false) String category, Pageable pageable) {
public ResponseEntity<Page<AccountBookDataQ>> getAccountBookMonthlyRecord(@PathVariable("id") Long id, @PathVariable("year") Long year, @PathVariable("month") Long month, @RequestParam(value = "category", required = false, defaultValue = "") String category, Pageable pageable) {

log.info("가계부 분석 - 월별 지출 조회 API 호출");
return ResponseEntity.ok(accountBookService.getAccountBookMonthlyRecord(id, year, month, pageable, category));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,25 @@ public AccountBookDailyRecord getAccountBookDailyRecord(Long id, Long year, Long
@Transactional
public AccountBookCategoryAnalyze getAccountBookCategoryAnalyze(Long id, Long year, Long month) {
List<AccountBookCategoryAnalyzeQ> categoryAnalyze = accountBookRepository.findAccountBookCategoryAnalyze(id, year, month);
MonthlySumQ monthlySumQ = recordRepository.getMonthlySumByAccountBookId(id, year, month).get();
Long compare = 0L;
for (AccountBookCategoryAnalyzeQ analyzeQ : categoryAnalyze) {
compare += analyzeQ.getValue();
}
if (compare.equals(monthlySumQ.getValue())) {
return AccountBookCategoryAnalyze.builder().categories(categoryAnalyze).sum(monthlySumQ.getValue()).build();
Optional<MonthlySumQ> monthlySum = recordRepository.getMonthlySumByAccountBookId(id, year, month);
if (monthlySum.isPresent()) {
MonthlySumQ monthlySumQ = monthlySum.get();
Long compare = 0L;
for (AccountBookCategoryAnalyzeQ analyzeQ : categoryAnalyze) {
compare += analyzeQ.getValue();
}
if (compare.equals(monthlySumQ.getValue())) {
return AccountBookCategoryAnalyze.builder().categories(categoryAnalyze).sum(monthlySumQ.getValue()).build();
} else {
AccountBookCategoryAnalyzeQ built = AccountBookCategoryAnalyzeQ.builder().name("그 외").value(monthlySumQ.getValue() - compare).build();
categoryAnalyze.add(built);
return AccountBookCategoryAnalyze.builder().categories(categoryAnalyze).sum(monthlySumQ.getValue()).build();
}
} else {
AccountBookCategoryAnalyzeQ built = AccountBookCategoryAnalyzeQ.builder().name("그 외").value(monthlySumQ.getValue() - compare).build();
categoryAnalyze.add(built);
return AccountBookCategoryAnalyze.builder().categories(categoryAnalyze).sum(monthlySumQ.getValue()).build();
return AccountBookCategoryAnalyze.builder().categories(categoryAnalyze).sum(0L).build();
}


}

@Transactional
Expand Down

0 comments on commit 9b3dc76

Please sign in to comment.