From 7d208abbd5bcda726abfbb04343ad4d5379bbd2c Mon Sep 17 00:00:00 2001 From: ayoung-kim Date: Sat, 31 Aug 2024 15:13:08 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EC=9E=85=EC=B6=9C=EA=B8=88=20?= =?UTF-8?q?=EA=B3=84=EC=A2=8C=20memo=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/service/AccountService.java | 1 - .../domain/target/service/TargetService.java | 2 ++ .../target/service/TargetTransferService.java | 32 +++++++++++-------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/fav/daengnyang/domain/account/service/AccountService.java b/src/main/java/com/fav/daengnyang/domain/account/service/AccountService.java index 925579d..cd2402b 100644 --- a/src/main/java/com/fav/daengnyang/domain/account/service/AccountService.java +++ b/src/main/java/com/fav/daengnyang/domain/account/service/AccountService.java @@ -49,7 +49,6 @@ public class AccountService { private final AccountRepository accountRepository; private final MemberRepository memberRepository; - private final PetRepository petRepository; private final AccountCodeRepository accountCodeRepository; private final RestTemplate restTemplate; private final ObjectMapper objectMapper; diff --git a/src/main/java/com/fav/daengnyang/domain/target/service/TargetService.java b/src/main/java/com/fav/daengnyang/domain/target/service/TargetService.java index aa915a1..26bf8ec 100644 --- a/src/main/java/com/fav/daengnyang/domain/target/service/TargetService.java +++ b/src/main/java/com/fav/daengnyang/domain/target/service/TargetService.java @@ -13,6 +13,7 @@ import com.fav.daengnyang.domain.targetDetail.repository.TargetDetailRepository; import com.fav.daengnyang.global.exception.CustomException; import com.fav.daengnyang.global.exception.ErrorCode; +import com.fav.daengnyang.global.transaction.service.TransactionService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -36,6 +37,7 @@ public class TargetService { private final TargetDetailRepository targetDetailRepository; private final AccountRepository accountRepository; private final PetRepository petRepository; + private final TransactionService transactionService; private final Random random = new Random(); // 타겟 추천 메소드 diff --git a/src/main/java/com/fav/daengnyang/domain/target/service/TargetTransferService.java b/src/main/java/com/fav/daengnyang/domain/target/service/TargetTransferService.java index 29b4920..856d1bd 100644 --- a/src/main/java/com/fav/daengnyang/domain/target/service/TargetTransferService.java +++ b/src/main/java/com/fav/daengnyang/domain/target/service/TargetTransferService.java @@ -11,7 +11,9 @@ import com.fav.daengnyang.domain.target.service.dto.request.TransferHeaderRequest; import com.fav.daengnyang.domain.targetDetail.entity.TargetDetail; import com.fav.daengnyang.domain.targetDetail.repository.TargetDetailRepository; +import com.fav.daengnyang.global.transaction.service.TransactionService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -24,6 +26,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -31,6 +34,7 @@ @Service @RequiredArgsConstructor @Transactional +@Slf4j public class TargetTransferService { private final TargetRepository targetRepository; @@ -38,6 +42,7 @@ public class TargetTransferService { private final MemberRepository memberRepository; private final RestTemplate restTemplate; private final ObjectMapper objectMapper; + private final TransactionService transactionService; @Value("${api.key}") private String apiKey; @@ -58,6 +63,7 @@ public void transferToTarget(Long memberId, String userKey, Long targetId, Targe // 금융 API 호출하여 이체 수행 callTransferApi(depositAccountNo, withdrawalAccountNo, amount, userKey); + // 타겟의 current_amount 업데이트 및 목표 달성 여부 확인 int updatedAmount = target.getCurrentAmount() + amount; target.setCurrentAmount(updatedAmount); @@ -101,7 +107,7 @@ public void updateTarget(Long memberId, String userKey, Long targetId) throws Js // 총 합계금액을 Member의 depositAccount로 이체 if (totalAmount > 0) { - callTransferApi(depositAccountNo, withdrawalAccountNo, totalAmount, userKey); // 재사용 + callTransferApi(depositAccountNo, withdrawalAccountNo, totalAmount, userKey); } // 출금 처리 @@ -158,8 +164,8 @@ void callTransferApi(String depositAccountNo, String withdrawalAccountNo, int am body.put("depositAccountNo", depositAccountNo); body.put("withdrawalAccountNo", withdrawalAccountNo); body.put("transactionBalance", amount); - body.put("depositTransactionSummary", "(수시입출금) : 입금(이체)"); - body.put("withdrawalTransactionSummary", "(수시입출금) : 출금(이체)"); + body.put("depositTransactionSummary", "입금"); + body.put("withdrawalTransactionSummary", "출금"); // HttpHeaders 설정 HttpHeaders headers = new HttpHeaders(); @@ -172,15 +178,15 @@ void callTransferApi(String depositAccountNo, String withdrawalAccountNo, int am String url = "https://finopenapi.ssafy.io/ssafy/api/v1/edu/demandDeposit/updateDemandDepositAccountTransfer"; ResponseEntity response = restTemplate.postForEntity(url, requestEntity, String.class); - if (response.getStatusCode().is2xxSuccessful()) { - // 성공적으로 이체된 경우 처리 - JsonNode responseBody = objectMapper.readTree(response.getBody()); - String responseCode = responseBody.path("Header").path("responseCode").asText(); - if (!"H0000".equals(responseCode)) { - throw new RuntimeException("이체 오류: " + responseBody.path("Header").path("responseMessage").asText()); - } - } else { - throw new RuntimeException("API 호출 오류: " + response.getBody()); - } + // 5. 거래 번호 추출 + List transactionUniqueNos = new ArrayList<>(); + + JsonNode rootNode = objectMapper.readTree((response.getBody())); + JsonNode recNode = rootNode.path("REC"); + + String memo = "투자계좌"; + transactionService.makeMemo(withdrawalAccountNo, recNode.get(0).path("transactionUniqueNo").asText(), memo, userKey); + transactionService.makeMemo(depositAccountNo, recNode.get(1).path("transactionUniqueNo").asText(), memo, userKey); + } }