From dfec00e48c95d7154af594578d1cb954c33e782c Mon Sep 17 00:00:00 2001 From: yeonank Date: Sun, 30 Jul 2023 23:15:29 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[fix]=20=EC=9B=B9=ED=9B=85=20NPE=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/FundingCloseService.java | 21 ++++++++++++------- .../server/service/ScheduleService.java | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/habday/server/service/FundingCloseService.java b/src/main/java/com/habday/server/service/FundingCloseService.java index 2df1616..5046e1f 100644 --- a/src/main/java/com/habday/server/service/FundingCloseService.java +++ b/src/main/java/com/habday/server/service/FundingCloseService.java @@ -3,6 +3,8 @@ import com.google.gson.Gson; import com.habday.server.classes.Common; import com.habday.server.config.email.EmailFormats; +import com.habday.server.constants.CustomException; +import com.habday.server.constants.code.ExceptionCode; import com.habday.server.constants.state.FundingState; import com.habday.server.domain.fundingItem.FundingItem; import com.habday.server.domain.fundingMember.FundingMember; @@ -19,6 +21,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Optional; + import static com.habday.server.constants.state.ScheduledPayState.fail; import static com.habday.server.constants.state.ScheduledPayState.paid; @@ -75,34 +79,35 @@ public void callbackSchedule(CallbackScheduleRequestDto callbackRequestDto, Http String[] ips = {"52.78.100.19", "52.78.48.223", "52.78.5.241"}; List ipLists = new ArrayList<>(Arrays.asList(ips)); - FundingMember fundingMember = fundingMemberRepository.findByMerchantId(callbackRequestDto.getMerchant_uid()); - FundingItem fundingItem = fundingMember.getFundingItem(); - BigDecimal amount = fundingMember.getAmount(); + Optional fundingMember = Optional.ofNullable(fundingMemberRepository.findByMerchantId(callbackRequestDto.getMerchant_uid())); + FundingItem fundingItem = fundingMember.orElseThrow(()-> + new CustomException(ExceptionCode.NO_FUNDING_MEMBER_ID)).getFundingItem(); + BigDecimal amount = fundingMember.get().getAmount(); IamportResponse response = iamportService.paymentByImpUid(callbackRequestDto.getImp_uid()); log.info("response: " + new Gson().toJson(response)); if (!ipLists.contains(clientIp)){ - fundingMember.updateWebhookFail(fail, "ip주소가 맞지 않음"); + fundingMember.get().updateWebhookFail(fail, "ip주소가 맞지 않음"); log.info("callbackSchedule() ip 주소 안맞음"); return;//throw new CustomException(UNAUTHORIZED_IP); //exception 날리면 트랜잭션이 롤백되어버려 영속성컨텍스트 flush 안됨 } if(amount.compareTo(response.getResponse().getAmount()) !=0){ - fundingMember.updateWebhookFail(fail, "결제 금액이 맞지 않음"); + fundingMember.get().updateWebhookFail(fail, "결제 금액이 맞지 않음"); log.info("callbackSchedule(): member-amount : " + amount); log.info("callbackSchedule() 결제 금액 안맞음 " + response.getResponse().getMerchantUid()); return;//throw new CustomException(NO_CORRESPONDING_AMOUNT); } - String[] receiver = {fundingMember.getMember().getEmail()}; + String[] receiver = {fundingMember.get().getMember().getEmail()}; if(callbackRequestDto.getStatus().equals(paid.getMsg())){ - fundingMember.updateWebhookSuccess(paid); + fundingMember.get().updateWebhookSuccess(paid); log.info("callbackSchedule() paid로 update" + response.getResponse().getMerchantUid()); emailFormats.sendPaymentSuccessEmail(fundingItem, receiver, amount); }else{ - fundingMember.updateWebhookFail(fail, response.getResponse().getFailReason()); + fundingMember.get().updateWebhookFail(fail, response.getResponse().getFailReason()); log.info("callbackSchedule() fail로 update" + response.getResponse().getMerchantUid()); emailFormats.sendPaymentFailEmail(fundingItem, receiver); } diff --git a/src/main/java/com/habday/server/service/ScheduleService.java b/src/main/java/com/habday/server/service/ScheduleService.java index 5f049fb..494ce43 100644 --- a/src/main/java/com/habday/server/service/ScheduleService.java +++ b/src/main/java/com/habday/server/service/ScheduleService.java @@ -52,6 +52,7 @@ public void checkFundingState() { @Transactional @Scheduled(cron = memberStateCron)//매일 밤 12시 public void checkMemberState(){ + log.info("member cron 돌아감"); List fundingItems = //now > finishDate + 14 == now - 14 > finishDate fundingItemRepository.findByIsConfirmAndStatusAndFinishDateLessThan(FundingConfirmState.FALSE, FundingState.SUCCESS, LocalDate.now().minusDays(CmnConst.confirmLimitDate));//데이터 많아지면 검색 범위를 지정해도 되지 않을까 너무 옛날꺼는 검색하지 않는다던지 From 4767cf7350e9225f38eccb1cabd5d7ca8ce9e3bd Mon Sep 17 00:00:00 2001 From: yeonank Date: Sun, 30 Jul 2023 23:33:35 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[refactor]=20setter=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/domain/fundingItem/FundingItem.java | 10 ++++++++-- .../server/domain/fundingMember/FundingMember.java | 12 ++++++------ .../habday/server/service/FundingCloseService.java | 12 ++++++------ .../com/habday/server/service/FundingService.java | 2 +- .../java/com/habday/server/service/PayService.java | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/habday/server/domain/fundingItem/FundingItem.java b/src/main/java/com/habday/server/domain/fundingItem/FundingItem.java index 8993961..9125ffe 100644 --- a/src/main/java/com/habday/server/domain/fundingItem/FundingItem.java +++ b/src/main/java/com/habday/server/domain/fundingItem/FundingItem.java @@ -86,8 +86,14 @@ public FundingItem updatePricePercentage(BigDecimal totalPrice, int percentage){ this.percentage = percentage; return this; } - public FundingItem updateFundingState(FundingState status){ - this.status = status; + + public FundingItem updateFundingSuccess(){ + this.status = FundingState.SUCCESS; + return this; + } + + public FundingItem updateFundingFail(){ + this.status = FundingState.FAIL; return this; } diff --git a/src/main/java/com/habday/server/domain/fundingMember/FundingMember.java b/src/main/java/com/habday/server/domain/fundingMember/FundingMember.java index 6565601..ef29d71 100644 --- a/src/main/java/com/habday/server/domain/fundingMember/FundingMember.java +++ b/src/main/java/com/habday/server/domain/fundingMember/FundingMember.java @@ -104,22 +104,22 @@ public static FundingMember of(ParticipateFundingRequest fundingRequestDto, Sche .build(); } - public FundingMember updateCancel(BigDecimal cancelAmount, String reason, ScheduledPayState payment_status, LocalDate cancelDate){ + public FundingMember updateCancel(BigDecimal cancelAmount, String reason, LocalDate cancelDate){ this.cancelAmount = cancelAmount; this.reason = reason; - this.payment_status = payment_status; + this.payment_status = ScheduledPayState.cancel; this.cancelDate = cancelDate; return this; } - public FundingMember updateWebhookFail(ScheduledPayState payment_status, String fail_reason){ - this.payment_status = payment_status; + public FundingMember updateWebhookFail(String fail_reason){ + this.payment_status = ScheduledPayState.fail; this.fail_reason = fail_reason; return this; } - public FundingMember updateWebhookSuccess(ScheduledPayState payment_status){ - this.payment_status = payment_status; + public FundingMember updateWebhookSuccess(){ + this.payment_status = ScheduledPayState.paid; return this; } diff --git a/src/main/java/com/habday/server/service/FundingCloseService.java b/src/main/java/com/habday/server/service/FundingCloseService.java index 5046e1f..fcfc127 100644 --- a/src/main/java/com/habday/server/service/FundingCloseService.java +++ b/src/main/java/com/habday/server/service/FundingCloseService.java @@ -53,12 +53,12 @@ public void checkFundingSuccess(FundingItem fundingItem) { log.info("itemId: " +fundingItem.getId() + " realPercent.compareTo(goalPercent)^^ : " + realPercent.compareTo(goalPercent)); if (realPercent.compareTo(goalPercent) == 0 || realPercent.compareTo(goalPercent) == 1) { // 펀딩 최소 목표 퍼센트에 달성함 - fundingItem.updateFundingState(FundingState.SUCCESS); + fundingItem.updateFundingSuccess(); log.info("최소 목표퍼센트 이상 달성함"); emailFormats.sendFundingSuccessEmail(fundingItem); } else { // 펀딩 최소 목표 퍼센트에 달성 못함 log.info("최소 목표퍼센트 이상 달성 실패"); - fundingItem.updateFundingState(FundingState.FAIL); + fundingItem.updateFundingFail(); payService.unscheduleAll(fundingItem); emailFormats.sendFundingFailEmail(fundingItem);//throw new CustomException(FAIL_FINISH_FUNDING); } @@ -88,14 +88,14 @@ public void callbackSchedule(CallbackScheduleRequestDto callbackRequestDto, Http log.info("response: " + new Gson().toJson(response)); if (!ipLists.contains(clientIp)){ - fundingMember.get().updateWebhookFail(fail, "ip주소가 맞지 않음"); + fundingMember.get().updateWebhookFail("ip주소가 맞지 않음"); log.info("callbackSchedule() ip 주소 안맞음"); return;//throw new CustomException(UNAUTHORIZED_IP); //exception 날리면 트랜잭션이 롤백되어버려 영속성컨텍스트 flush 안됨 } if(amount.compareTo(response.getResponse().getAmount()) !=0){ - fundingMember.get().updateWebhookFail(fail, "결제 금액이 맞지 않음"); + fundingMember.get().updateWebhookFail("결제 금액이 맞지 않음"); log.info("callbackSchedule(): member-amount : " + amount); log.info("callbackSchedule() 결제 금액 안맞음 " + response.getResponse().getMerchantUid()); return;//throw new CustomException(NO_CORRESPONDING_AMOUNT); @@ -103,11 +103,11 @@ public void callbackSchedule(CallbackScheduleRequestDto callbackRequestDto, Http String[] receiver = {fundingMember.get().getMember().getEmail()}; if(callbackRequestDto.getStatus().equals(paid.getMsg())){ - fundingMember.get().updateWebhookSuccess(paid); + fundingMember.get().updateWebhookSuccess(); log.info("callbackSchedule() paid로 update" + response.getResponse().getMerchantUid()); emailFormats.sendPaymentSuccessEmail(fundingItem, receiver, amount); }else{ - fundingMember.get().updateWebhookFail(fail, response.getResponse().getFailReason()); + fundingMember.get().updateWebhookFail(response.getResponse().getFailReason()); log.info("callbackSchedule() fail로 update" + response.getResponse().getMerchantUid()); emailFormats.sendPaymentFailEmail(fundingItem, receiver); } diff --git a/src/main/java/com/habday/server/service/FundingService.java b/src/main/java/com/habday/server/service/FundingService.java index d3be3b5..3ba9f86 100644 --- a/src/main/java/com/habday/server/service/FundingService.java +++ b/src/main/java/com/habday/server/service/FundingService.java @@ -100,7 +100,7 @@ public ParticipateFundingResponseDto participateFunding(ParticipateFundingReques // 펀딩 금액 달성시, SUCCESS로 상태 변경 if(fundingItem.getTotalPrice() == fundingItem.getGoalPrice()) { - fundingItem.updateFundingState(FundingState.SUCCESS); + fundingItem.updateFundingSuccess(); } return ParticipateFundingResponseDto.of(scheduleResult.getCode(), scheduleResult.getMessage()); } diff --git a/src/main/java/com/habday/server/service/PayService.java b/src/main/java/com/habday/server/service/PayService.java index 4364a00..7afd622 100644 --- a/src/main/java/com/habday/server/service/PayService.java +++ b/src/main/java/com/habday/server/service/PayService.java @@ -132,7 +132,7 @@ public UnscheduleResponseDto noneAuthPayUnschedule(NoneAuthPayUnscheduleRequestD throw new CustomExceptionWithMessage(PAY_SCHEDULING_INTERNAL_ERROR, iamportResponse.getMessage()); } LocalDate cancelDate = LocalDate.now(); - fundingMember.updateCancel(fundingMember.getAmount(), unscheduleRequestDto.getReason(), cancel, cancelDate); + fundingMember.updateCancel(fundingMember.getAmount(), unscheduleRequestDto.getReason(), cancelDate); return UnscheduleResponseDto.builder() .merchant_uid(fundingMember.getMerchantId()) From 9357dc8491c1157eb20e358a513930b855d3a485 Mon Sep 17 00:00:00 2001 From: yeonank Date: Mon, 31 Jul 2023 00:09:15 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[refactor]=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/habday/server/classes/Common.java | 3 +++ .../java/com/habday/server/service/FundingService.java | 10 +++------- .../java/com/habday/server/service/MemberService.java | 1 - .../java/com/habday/server/service/PayService.java | 2 -- .../com/habday/server/service/ScheduleService.java | 8 -------- 5 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/habday/server/classes/Common.java b/src/main/java/com/habday/server/classes/Common.java index e65ab46..6dfb284 100644 --- a/src/main/java/com/habday/server/classes/Common.java +++ b/src/main/java/com/habday/server/classes/Common.java @@ -25,6 +25,9 @@ public class Common { @Autowired public FundingMemberRepository fundingMemberRepository; + @Autowired + public MemberRepository memberRepository; + @Autowired public PaymentRepository paymentRepository; diff --git a/src/main/java/com/habday/server/service/FundingService.java b/src/main/java/com/habday/server/service/FundingService.java index 3ba9f86..2d4fa9f 100644 --- a/src/main/java/com/habday/server/service/FundingService.java +++ b/src/main/java/com/habday/server/service/FundingService.java @@ -57,8 +57,6 @@ public class FundingService extends Common { private final S3Uploader s3Uploader; private final EmailFormats emailFormats; private final PayService payService; - private final MemberRepository memberRepository; - private final FundingItemRepository fundingItemRepository; @Transactional//예외 발생 시 롤백해줌 @@ -108,12 +106,10 @@ public ParticipateFundingResponseDto participateFunding(ParticipateFundingReques public ShowFundingContentResponseDto showFundingContent(Long fundingItemId) { FundingItem fundingItem = fundingItemRepository.findById(fundingItemId) .orElseThrow(() -> new CustomException(NO_FUNDING_ITEM_ID)); - Member member = fundingItem.getMember(); - if (member == null) - throw new CustomException(NO_MEMBER_ID_SAVED); - Confirmation confirmation = confirmationRepository.findByFundingItem(fundingItem); + Member member = Optional.ofNullable(fundingItem.getMember()).orElseThrow(()-> new CustomException(NO_MEMBER_ID_SAVED)); + Optional confirmation = Optional.ofNullable(confirmationRepository.findByFundingItem(fundingItem)); return ShowFundingContentResponseDto.of(fundingItem, member, getParticipantList(fundingItem), - confirmation == null ? null : confirmation.getId()); + confirmation.orElseGet(null).getId()); } public List getParticipantList(FundingItem fundingItem) { diff --git a/src/main/java/com/habday/server/service/MemberService.java b/src/main/java/com/habday/server/service/MemberService.java index fa2d5b8..9ef3112 100644 --- a/src/main/java/com/habday/server/service/MemberService.java +++ b/src/main/java/com/habday/server/service/MemberService.java @@ -13,7 +13,6 @@ @Service @RequiredArgsConstructor public class MemberService extends Common { - private final MemberRepository memberRepository; @Transactional public void updateMemberProfile(Long memberId, MemberProfileRequestDto requestDto) { Member member = memberRepository.findById(memberId) diff --git a/src/main/java/com/habday/server/service/PayService.java b/src/main/java/com/habday/server/service/PayService.java index 7afd622..86b3e57 100644 --- a/src/main/java/com/habday/server/service/PayService.java +++ b/src/main/java/com/habday/server/service/PayService.java @@ -44,8 +44,6 @@ public class PayService extends Common { private final IamportService iamportService; private final UIDCreation uidCreation; - private final MemberRepository memberRepository; - private final FundingItemRepository fundingItemRepository; @Transactional public GetBillingKeyResponseDto getBillingKey(NoneAuthPayBillingKeyRequestDto billingKeyRequest, Long memberId){ diff --git a/src/main/java/com/habday/server/service/ScheduleService.java b/src/main/java/com/habday/server/service/ScheduleService.java index 494ce43..6781c82 100644 --- a/src/main/java/com/habday/server/service/ScheduleService.java +++ b/src/main/java/com/habday/server/service/ScheduleService.java @@ -29,8 +29,6 @@ @RequiredArgsConstructor @Service public class ScheduleService extends Common { - private final MemberRepository memberRepository; - private final Calculation calculation; private final FundingCloseService closeService; @Transactional @@ -63,12 +61,6 @@ public void checkMemberState(){ if(member != null && member.getStatus().equals(MemberState.AVAILABLE)) member.updateStatusSuspended(); item.updateIsConfirmDone();//false로 있으면 조건문에 걸릴 수 있으니 -// if (calculation.isAfterTwoWeek(item)){//afterTwoWeek >= LocalDate.now()이면 pass -// Member member = item.getMember(); -// member.updateStatusSuspended(); -// log.info("checkMemberState(): memberId: " + member.getId() + " itemId: " + item.getId() + " 기간 만료"); -// item.updateIsConfirmDone(); -// } })); } } From 583d369e9bc778cbdda94a1c251f3a6dd73a420a Mon Sep 17 00:00:00 2001 From: yeonank Date: Tue, 1 Aug 2023 12:17:11 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[update]=20showConfirmation=20api=20pathvar?= =?UTF-8?q?iable=20=EC=88=98=EC=A0=95,=20response=EC=97=90=20totalPrice=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/habday/server/constants/code/ExceptionCode.java | 2 +- .../com/habday/server/controller/FundingController.java | 8 ++++---- .../server/dto/res/fund/ShowConfirmationResponseDto.java | 5 ++++- .../java/com/habday/server/service/FundingService.java | 7 ++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/habday/server/constants/code/ExceptionCode.java b/src/main/java/com/habday/server/constants/code/ExceptionCode.java index 82f3ad3..c9be3f2 100644 --- a/src/main/java/com/habday/server/constants/code/ExceptionCode.java +++ b/src/main/java/com/habday/server/constants/code/ExceptionCode.java @@ -51,7 +51,7 @@ public enum ExceptionCode { FUNDING_CONFIRM_NOT_NEEDED(INTERNAL_SERVER_ERROR, "펀딩 실패한 경우 인증이 필요하지 않습니다."), FUNDING_CONFIRM_NOT_YET(INTERNAL_SERVER_ERROR, "완료되지 않은 펀딩은 인증을 진행할 수 없습니다."), FUNDING_ALREADY_CONFIRMED(INTERNAL_SERVER_ERROR, "이미 인증된 펀딩입니다."), - NO_CONFIRMATION_EXIST(INTERNAL_SERVER_ERROR,"존재하지 않는 인증 번호 입니다."), + NO_CONFIRMATION_EXIST(INTERNAL_SERVER_ERROR,"펀딩 인증이 존재하지 않습니다."), DELETE_FUNDING_UNAVAILABLE(INTERNAL_SERVER_ERROR, "마감한 펀딩에 대해서는 펀딩 삭제가 불가합니다."), DELETE_PARTICIPATE_UNAVAILABLE(INTERNAL_SERVER_ERROR,"마감한 펀딩에 대해서는 참여 취소가 불가합니다."), PAYMENT_VALIDATION_FAIL(INTERNAL_SERVER_ERROR, "결제 수단이 사용자 정보와 일치하지 않습니다."), diff --git a/src/main/java/com/habday/server/controller/FundingController.java b/src/main/java/com/habday/server/controller/FundingController.java index de7e606..a1c6cda 100644 --- a/src/main/java/com/habday/server/controller/FundingController.java +++ b/src/main/java/com/habday/server/controller/FundingController.java @@ -67,11 +67,11 @@ public ResponseEntity confirm(@RequestHeader("") String accessTo return CommonResponse.toResponse(FUNDING_CONFIRMATION_SUCCESS, null); } - @GetMapping(value = {"/showConfirmation", "/showConfirmation/{confirmationId}"}) - public ResponseEntity showConfirmation(@PathVariable Optional confirmationId){ + @GetMapping(value = {"/showConfirmation", "/showConfirmation/{fundingItemId}"}) + public ResponseEntity showConfirmation(@PathVariable Optional fundingItemId){ - ShowConfirmationResponseDto response = fundingService.showConfirmation(confirmationId.orElseThrow(() -> - new CustomException(NO_CONFIRMATION_EXIST))); + ShowConfirmationResponseDto response = fundingService.showConfirmation(fundingItemId.orElseThrow(() -> + new CustomException(NO_FUNDING_ITEM_ID))); return CommonResponse.toResponse(SHOW_FUNDING_CONFIRM_SUCCESS, response); } diff --git a/src/main/java/com/habday/server/dto/res/fund/ShowConfirmationResponseDto.java b/src/main/java/com/habday/server/dto/res/fund/ShowConfirmationResponseDto.java index 5b5a2aa..af29df4 100644 --- a/src/main/java/com/habday/server/dto/res/fund/ShowConfirmationResponseDto.java +++ b/src/main/java/com/habday/server/dto/res/fund/ShowConfirmationResponseDto.java @@ -4,6 +4,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.math.BigDecimal; import java.time.LocalDateTime; @Getter @@ -12,10 +13,12 @@ public class ShowConfirmationResponseDto { private String confirmationImg; private String message; private LocalDateTime createdDate; - public ShowConfirmationResponseDto(Confirmation confirmation){ + BigDecimal totalPrice; + public ShowConfirmationResponseDto(Confirmation confirmation, BigDecimal totalPrice){ this.title = confirmation.getTitle(); this.confirmationImg = confirmation.getConfirmationImg(); this.message = confirmation.getMessage(); this.createdDate = confirmation.getCreatedDate(); + this.totalPrice = totalPrice; } } diff --git a/src/main/java/com/habday/server/service/FundingService.java b/src/main/java/com/habday/server/service/FundingService.java index 2d4fa9f..d103dbf 100644 --- a/src/main/java/com/habday/server/service/FundingService.java +++ b/src/main/java/com/habday/server/service/FundingService.java @@ -210,9 +210,10 @@ public void confirm(MultipartFile img, ConfirmationRequest request, Long funding fundingItem.updateIsConfirmTrue(); } - public ShowConfirmationResponseDto showConfirmation(Long confirmationId){ - Confirmation confirmation = confirmationRepository.findById(confirmationId).orElseThrow(() -> new CustomException(NO_CONFIRMATION_EXIST)); - return new ShowConfirmationResponseDto(confirmation); + public ShowConfirmationResponseDto showConfirmation(Long fundingItemId){ + FundingItem fundingItem = fundingItemRepository.findById(fundingItemId).orElseThrow(() -> new CustomException(NO_FUNDING_ITEM_ID)); + Confirmation confirmation = Optional.ofNullable(confirmationRepository.findByFundingItem(fundingItem)).orElseThrow(() -> new CustomException(NO_CONFIRMATION_EXIST)); + return new ShowConfirmationResponseDto(confirmation, fundingItem.getTotalPrice()); } @Transactional From 1aecfa6aa3392f83258e8f0f650f2aaa0e8537bb Mon Sep 17 00:00:00 2001 From: yeonank Date: Tue, 1 Aug 2023 17:29:07 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[update]=20=EC=8A=A4=EC=BC=80=EC=A5=B4=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/service/FundingCloseService.java | 16 +++++++++++++++- .../habday/server/service/FundingService.java | 2 +- .../com/habday/server/service/PayService.java | 2 +- .../habday/server/service/ScheduleService.java | 15 +++++++++++---- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/habday/server/service/FundingCloseService.java b/src/main/java/com/habday/server/service/FundingCloseService.java index fcfc127..b3fcd7d 100644 --- a/src/main/java/com/habday/server/service/FundingCloseService.java +++ b/src/main/java/com/habday/server/service/FundingCloseService.java @@ -45,7 +45,7 @@ public class FundingCloseService extends Common { * - 펀딩 성공 메일 보내기 * */ @Transactional - public void checkFundingSuccess(FundingItem fundingItem) { + public void checkFundingSuccess(FundingItem fundingItem) {//성공한 아이템이 들어오게 BigDecimal goalPercent = fundingItem.getGoalPrice().divide(fundingItem.getItemPrice(), BigDecimal.ROUND_DOWN); //최소목표퍼센트 BigDecimal realPercent = fundingItem.getTotalPrice().divide(fundingItem.getItemPrice(), BigDecimal.ROUND_DOWN); // 실제달성퍼센트 @@ -64,6 +64,20 @@ public void checkFundingSuccess(FundingItem fundingItem) { } } + @Transactional + public void fundingSuccess(FundingItem fundingItem){ + log.info("최소 목표퍼센트 이상 달성함"); + emailFormats.sendFundingSuccessEmail(fundingItem); + } + + @Transactional + public void fundingFail(FundingItem fundingItem){ + log.info("최소 목표퍼센트 이상 달성 실패"); + fundingItem.updateFundingFail(); + payService.unscheduleAll(fundingItem); + emailFormats.sendFundingFailEmail(fundingItem);//throw new CustomException(FAIL_FINISH_FUNDING); + } + /* <웹훅> diff --git a/src/main/java/com/habday/server/service/FundingService.java b/src/main/java/com/habday/server/service/FundingService.java index d103dbf..84f161a 100644 --- a/src/main/java/com/habday/server/service/FundingService.java +++ b/src/main/java/com/habday/server/service/FundingService.java @@ -97,7 +97,7 @@ public ParticipateFundingResponseDto participateFunding(ParticipateFundingReques fundingItem.updatePricePercentage(totalPrice, percentage); // 펀딩 금액 달성시, SUCCESS로 상태 변경 - if(fundingItem.getTotalPrice() == fundingItem.getGoalPrice()) { + if(fundingItem.getTotalPrice().compareTo(fundingItem.getGoalPrice()) >=0) { fundingItem.updateFundingSuccess(); } return ParticipateFundingResponseDto.of(scheduleResult.getCode(), scheduleResult.getMessage()); diff --git a/src/main/java/com/habday/server/service/PayService.java b/src/main/java/com/habday/server/service/PayService.java index 86b3e57..7235c83 100644 --- a/src/main/java/com/habday/server/service/PayService.java +++ b/src/main/java/com/habday/server/service/PayService.java @@ -147,7 +147,7 @@ public void unscheduleAll(FundingItem fundingItem){ NoneAuthPayUnscheduleRequestDto request = new NoneAuthPayUnscheduleRequestDto(id, "목표 달성 실패로 인한 결제 취소"); try { UnscheduleResponseDto respone = noneAuthPayUnschedule(request); - log.info("unschedulePayment response: " + new Gson().toJson(respone)); + //log.info("unschedulePayment response: " + new Gson().toJson(respone)); } catch(RuntimeException e){ log.info("unschedule Payment 서비스 내 오류: " + e); } diff --git a/src/main/java/com/habday/server/service/ScheduleService.java b/src/main/java/com/habday/server/service/ScheduleService.java index 6781c82..5a0171e 100644 --- a/src/main/java/com/habday/server/service/ScheduleService.java +++ b/src/main/java/com/habday/server/service/ScheduleService.java @@ -35,10 +35,17 @@ public class ScheduleService extends Common { @Scheduled(cron = scheduleCron) // "0 5 0 * * *" 매일 밤 0시 5분에 실행 public void checkFundingState() { log.info("schedule 시작"); - List overdatedFundings = fundingItemRepository.findByStatusAndFinishDate(FundingState.PROGRESS, LocalDate.now()); - overdatedFundings.forEach(fundingItem -> { - log.info("오늘 마감 fundingItem: " + fundingItem.getId()); - closeService.checkFundingSuccess(fundingItem); + List successFunding = fundingItemRepository.findByStatusAndFinishDate(FundingState.SUCCESS, LocalDate.now()); + List failFunding = fundingItemRepository.findByStatusAndFinishDate(FundingState.PROGRESS, LocalDate.now()); + + successFunding.forEach(fundingItem -> { + log.info("오늘 마감 성공 fundingItem: " + fundingItem.getId()); + closeService.fundingSuccess(fundingItem); + }); + + failFunding.forEach(fundingItem -> { + log.info("오늘 마감 실패 fundingItem: " + fundingItem.getId()); + closeService.fundingFail(fundingItem); }); log.info("schedule 끝"); }