Skip to content

Commit

Permalink
Merge pull request #88 from Hanaro-trip-together-bank/feature/exchange
Browse files Browse the repository at this point in the history
feat: 개인별 총 입금액 조회 및 월별 입금액 api 구현
  • Loading branch information
ny2060 authored May 31, 2024
2 parents 6dc9d4d + b17c5be commit 1bfa165
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.hanaro.triptogether.account.domain;

import com.hanaro.triptogether.accountTransactionDetails.AccountTransactionDetails;
import com.hanaro.triptogether.dues.dto.response.DuesDetailTotalAmountResponseDto;
import com.hanaro.triptogether.dues.dto.response.DuesDetailYearTotalAmountResponseDto;
import com.hanaro.triptogether.dues.dto.response.DuesListMemberResponseDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -11,8 +13,29 @@

public interface AccountTransactionDetailsRepository extends JpaRepository<AccountTransactionDetails,Long> {

@Query("SELECT NEW com.hanaro.triptogether.dues.dto.response.DuesDetailTotalAmountResponseDto( SUM(atd.transAmount) )" +
"FROM AccountTransactionDetails atd " +
"WHERE atd.account.accIdx = :accIdx AND atd.member.memberIdx = :memberIdx " +
"GROUP BY atd.member")
DuesDetailTotalAmountResponseDto findSumOfTransAmountByMemberIdx(@Param("accIdx") Long accIdx, @Param("memberIdx") Long memberIdx);

@Query("SELECT new com.hanaro.triptogether.dues.dto.response.DuesDetailYearTotalAmountResponseDto(" +
"FUNCTION('MONTH', atd.transDate), SUM(atd.transAmount)) " +
"FROM AccountTransactionDetails atd " +
"WHERE atd.account.accIdx = :accIdx " +
"AND atd.member.memberIdx = :memberIdx " +
"AND FUNCTION('YEAR', atd.transDate) = :year " +
"GROUP BY FUNCTION('MONTH', atd.transDate)")
List<DuesDetailYearTotalAmountResponseDto> findMonthlySumOfTransAmountByAccIdxAndMemberIdxAndYear(
@Param("accIdx") Long accIdx,
@Param("memberIdx") Long memberIdx,
@Param("year") int year);





@Query(value = "select NEW com.hanaro.triptogether.dues.dto.response.DuesListMemberResponseDto(atd.account.member.memberName,sum(atd.transAmount)) " +
@Query(value = "select NEW com.hanaro.triptogether.dues.dto.response.DuesListMemberResponseDto(atd.account.member.memberIdx,atd.account.member.memberName,sum(atd.transAmount)) " +
"from AccountTransactionDetails atd where atd.account.accIdx = :accIdx" +
" AND FUNCTION('YEAR', atd.transDate) = :year " +
"AND FUNCTION('MONTH', atd.transDate) = :month " +
Expand All @@ -24,7 +47,7 @@ List<DuesListMemberResponseDto> findUsersWithTransAmountGreaterThanOrEqual(
@Param("month") int month,
@Param("duesAmount") BigDecimal duesAmount);

@Query("SELECT NEW com.hanaro.triptogether.dues.dto.response.DuesListMemberResponseDto(atd.account.member.memberName, SUM(atd.transAmount)) " +
@Query("SELECT NEW com.hanaro.triptogether.dues.dto.response.DuesListMemberResponseDto(atd.account.member.memberIdx,atd.account.member.memberName, SUM(atd.transAmount)) " +
"FROM AccountTransactionDetails atd " +
"WHERE atd.account.accIdx = :accIdx " +
"AND FUNCTION('YEAR', atd.transDate) = :year " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.hanaro.triptogether.account.domain.Account;
import com.hanaro.triptogether.dues.domain.entity.BaseEntity;
import com.hanaro.triptogether.enumeration.TransType;
import com.hanaro.triptogether.member.domain.Member;
import jakarta.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDateTime;
Expand All @@ -28,7 +29,9 @@ public class AccountTransactionDetails extends BaseEntity {
@Column(nullable = false)
private LocalDateTime transDate;

private String transName;
@ManyToOne
@JoinColumn(name = "member_idx", nullable = false)
private Member member;

@Column(nullable = false, length = 255)
private String transFrom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.hanaro.triptogether.common.response.BaseResponse;
import com.hanaro.triptogether.common.response.ResponseStatus;
import com.hanaro.triptogether.dues.dto.request.DuesAlarmRequestDto;
import com.hanaro.triptogether.dues.dto.request.DuesDetailOfMonthAmountRequestDto;
import com.hanaro.triptogether.dues.dto.request.DuesDetailRequestDto;
import com.hanaro.triptogether.dues.dto.request.DuesRuleRequestDto;
import com.hanaro.triptogether.dues.dto.response.DuesListResponseDto;
import com.hanaro.triptogether.dues.service.DuesService;
Expand All @@ -30,9 +32,20 @@ public BaseResponse setDuesRule(@RequestBody DuesRuleRequestDto duesRuleRequestD
return BaseResponse.res(ResponseStatus.SUCCESS, ResponseStatus.SUCCESS.getMessage());
}

@GetMapping("/rule")
public BaseResponse getDuesRule(@RequestBody Map<String, Long> teamIdx) {
return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage(),duesService.getDuesRule(teamIdx.get("teamIdx")));
@GetMapping("/rule/{teamIdx}")
public BaseResponse getDuesRule(@PathVariable(value ="teamIdx" ) Long teamIdx) {
return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage(),duesService.getDuesRule(teamIdx));
}

@GetMapping("/details/amount")
public BaseResponse getDuesAllAmount(@RequestBody DuesDetailRequestDto duesDetailRequestDto){
return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage(),duesService.getDuesDetailTotalAmount(duesDetailRequestDto));

}

@GetMapping("/details/month")
public BaseResponse getDuesOfMonthAmount(@RequestBody DuesDetailOfMonthAmountRequestDto duesDetailOfMonthAmountRequestDto) {
return BaseResponse.res(ResponseStatus.SUCCESS,ResponseStatus.SUCCESS.getMessage(),duesService.getDuesDetailByMonthAmount(duesDetailOfMonthAmountRequestDto));
}

@GetMapping("")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hanaro.triptogether.dues.dto.request;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Builder
public class DuesDetailOfMonthAmountRequestDto {
private Long accIdx;
private Long memberIdx;
private String duesYear;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hanaro.triptogether.dues.dto.request;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class DuesDetailRequestDto {
private Long accIdx;
private Long memberIdx;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.hanaro.triptogether.dues.dto.response;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

@Getter
@Setter
@Builder
public class DuesDetailTotalAmountResponseDto {
private BigDecimal duesTotalAmount;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hanaro.triptogether.dues.dto.response;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;

@Getter
@Setter
@Builder
public class DuesDetailYearTotalAmountResponseDto {
private String duesOfMonth;
private BigDecimal duesAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@NoArgsConstructor
public class DuesListMemberResponseDto {

private Long memberIdx;
private String memberName;
private BigDecimal memberAmount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.hanaro.triptogether.account.domain.AccountTransactionDetailsRepository;
import com.hanaro.triptogether.dues.domain.entity.Dues;
import com.hanaro.triptogether.dues.domain.repository.DuesRepository;
import com.hanaro.triptogether.dues.dto.request.DuesDetailOfMonthAmountRequestDto;
import com.hanaro.triptogether.dues.dto.request.DuesDetailRequestDto;
import com.hanaro.triptogether.dues.dto.request.DuesRuleRequestDto;
import com.hanaro.triptogether.dues.dto.response.DuesListMemberResponseDto;
import com.hanaro.triptogether.dues.dto.response.DuesListResponseDto;
import com.hanaro.triptogether.dues.dto.response.DuesRuleResponseDto;
import com.hanaro.triptogether.dues.dto.response.*;
import com.hanaro.triptogether.teamMember.domain.TeamMember;
import com.hanaro.triptogether.teamMember.domain.TeamMemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -20,6 +22,16 @@ public class DuesService {

private final DuesRepository duesRepository;
private final AccountTransactionDetailsRepository accountTransactionDetailsRepository;
private final TeamMemberRepository teamMemberRepository;


public DuesDetailTotalAmountResponseDto getDuesDetailTotalAmount(DuesDetailRequestDto duesDetailRequestDto) {
return accountTransactionDetailsRepository.findSumOfTransAmountByMemberIdx(duesDetailRequestDto.getAccIdx(),duesDetailRequestDto.getMemberIdx());
}

public List<DuesDetailYearTotalAmountResponseDto> getDuesDetailByMonthAmount(DuesDetailOfMonthAmountRequestDto dto){
return accountTransactionDetailsRepository.findMonthlySumOfTransAmountByAccIdxAndMemberIdxAndYear(dto.getAccIdx(),dto.getMemberIdx(), Integer.parseInt(dto.getDuesYear()));
}

public void setDuesRule(DuesRuleRequestDto duesRuleRequestDto){
duesRepository.save(duesRuleRequestDto.toEntity());
Expand All @@ -37,6 +49,10 @@ public DuesRuleResponseDto getDuesRule(Long teamIdx){
public DuesListResponseDto getDuesList(Long teamIdx,Long accIdx, YearMonth date,Boolean paid){
List<DuesListMemberResponseDto> duesListMemberResponseDtos;
BigDecimal duesTotalAmount;

List<TeamMember> teamMembers = teamMemberRepository.findAllByTeamIdx(teamIdx);


if(paid) {
duesListMemberResponseDtos = accountTransactionDetailsRepository.findUsersWithTransAmountGreaterThanOrEqual(accIdx, date.getYear(), date.getMonthValue(), getTeamDuesAmount(teamIdx));
}
Expand Down

0 comments on commit 1bfa165

Please sign in to comment.