diff --git a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java index ac742d45..91a5f8cc 100644 --- a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java @@ -31,6 +31,8 @@ import java.util.Optional; import static com.postgraduate.domain.payment.application.usecase.PaymentParameter.*; +import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseCode.PAYMENT_FAIL; +import static com.postgraduate.domain.payment.presentation.constant.PaymentResponseMessage.FAIL_PAYMENT; import static org.springframework.http.CacheControl.noCache; @Service @@ -61,9 +63,12 @@ public class PaymentManageUseCase { private final SalaryGetService salaryGetService; private final WebClient webClient; - public void savePay(PaymentResultRequest request) { - if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) - throw new PaymentFailException(); + public boolean savePay(PaymentResultRequest request) { + if (!request.PCD_PAY_RST().equals(SUCCESS.getName())) { + log.error("PayPle 결제 진행 취소 및 오류"); + log.error("message : {} code : {}", FAIL_PAYMENT.getMessage(), request.PCD_PAY_CODE()); + return false; + } try { String seniorNickName = request.PCD_PAY_GOODS(); long userId = Long.parseLong(request.PCD_PAYER_NO()); @@ -78,6 +83,7 @@ public void savePay(PaymentResultRequest request) { paymentSaveService.save(payment); refundPay(payment); } + return true; } public void refundPayByUser(User user, String orderId) { diff --git a/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java b/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java index c6fa0bae..b60a6638 100644 --- a/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java +++ b/src/main/java/com/postgraduate/domain/payment/presentation/PaymentController.java @@ -2,6 +2,7 @@ import com.postgraduate.domain.payment.application.dto.req.PaymentResultRequest; import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; +import com.postgraduate.domain.senior.application.usecase.SeniorInfoUseCase; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -18,21 +19,34 @@ @Tag(name = "PAYMENT Controller", description = "") public class PaymentController { private final PaymentManageUseCase paymentManageUseCase; + private final SeniorInfoUseCase seniorInfoUseCase; @Value("${payple.redirect-uri}") private String redirectUri; @Value("${payple.redirect-uri-dev}") private String redirectUriDev; + @Value("${payple.cancel-redirect-uri}") + private String cancelRedirectUri; + @Value("${payple.cancel-redirect-uri-dev}") + private String cancelRedirectUriDev; @PostMapping("/payple/result") public void resultGet(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException { - paymentManageUseCase.savePay(request); - response.sendRedirect(redirectUri + request.PCD_PAY_OID()); + if (paymentManageUseCase.savePay(request)) { + response.sendRedirect(redirectUri + request.PCD_PAY_OID()); + return; + } + Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS()); + response.sendRedirect(cancelRedirectUri + seniorId); } @PostMapping("/payple/dev/result") public void resultGetWithDev(HttpServletResponse response, @ModelAttribute PaymentResultRequest request) throws IOException { - paymentManageUseCase.savePay(request); - response.sendRedirect(redirectUriDev + request.PCD_PAY_OID()); + if (paymentManageUseCase.savePay(request)) { + response.sendRedirect(redirectUriDev + request.PCD_PAY_OID()); + return; + } + Long seniorId = seniorInfoUseCase.getSeniorId(request.PCD_PAY_GOODS()); + response.sendRedirect(cancelRedirectUriDev + seniorId); } @PostMapping("/webhook") diff --git a/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java b/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java index 2855e4f8..2c00e40a 100644 --- a/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java @@ -5,7 +5,6 @@ import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.service.SalaryGetService; import com.postgraduate.domain.salary.domain.service.SalarySaveService; -import com.postgraduate.domain.salary.util.SalaryUtil; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.global.slack.SlackSalaryMessage; import lombok.RequiredArgsConstructor; @@ -25,13 +24,13 @@ public class SalaryManageUseCase { private final SeniorGetService seniorGetService; private final SlackSalaryMessage slackSalaryMessage; - @Scheduled(cron = "0 0 0 10 * *", zone = "Asia/Seoul") + @Scheduled(cron = "0 0 0 * * 4", zone = "Asia/Seoul") public void createSalary() { - List salaries = salaryGetService.findAllLastMonth(); + List salaries = salaryGetService.findAllLast(); slackSalaryMessage.sendSlackSalary(salaries); List seniorAndAccounts = seniorGetService.findAllSeniorAndAccount(); - LocalDate salaryDate = SalaryUtil.getSalaryDate(); + LocalDate salaryDate = LocalDate.now().plusDays(7); seniorAndAccounts.forEach(seniorAndAccount -> { Salary salary = SalaryMapper.mapToSalary(seniorAndAccount.senior(), salaryDate, seniorAndAccount.account()); salarySaveService.save(salary); diff --git a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java index 9eea5e32..23fbecba 100644 --- a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java +++ b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java @@ -33,10 +33,10 @@ public Page findDistinctSeniors(String search, Integer page) { return salaryRepository.findDistinctBySearchSenior(search, pageable); } - public List findAllLastMonth() { + public List findAllLast() { LocalDate salaryDate = SalaryUtil.getSalaryDate() - .minusMonths(1); + .minusDays(7); return salaryRepository.findAllLastSalary(salaryDate); } } diff --git a/src/main/java/com/postgraduate/domain/salary/util/SalaryUtil.java b/src/main/java/com/postgraduate/domain/salary/util/SalaryUtil.java index 5f3225f0..9fdce60b 100644 --- a/src/main/java/com/postgraduate/domain/salary/util/SalaryUtil.java +++ b/src/main/java/com/postgraduate/domain/salary/util/SalaryUtil.java @@ -3,13 +3,14 @@ import com.postgraduate.domain.admin.presentation.constant.SalaryStatus; import com.postgraduate.domain.salary.domain.entity.Salary; +import java.time.DayOfWeek; import java.time.LocalDate; -import java.time.format.DateTimeFormatter; import static com.postgraduate.domain.admin.presentation.constant.SalaryStatus.*; public class SalaryUtil { - private static final int SALARY_DATE = 10; + private static final int SALARY_DATE = 4; // 목요일 + private static final int SALARY_END_DATE = 7; // 일요일 private SalaryUtil() { throw new IllegalArgumentException(); @@ -17,13 +18,10 @@ private SalaryUtil() { public static LocalDate getSalaryDate() { LocalDate now = LocalDate.now(); - return now.getDayOfMonth() < SALARY_DATE - ? now.withDayOfMonth(SALARY_DATE) - : now.plusMonths(1).withDayOfMonth(SALARY_DATE); - } - - public static DateTimeFormatter getMonthFormat() { - return DateTimeFormatter.ofPattern("yyyy-MM"); + DayOfWeek dayOfWeek = now.getDayOfWeek(); + return dayOfWeek.getValue() < SALARY_END_DATE + ? now.plusDays(7 + (dayOfWeek.getValue() - SALARY_DATE)) + : now.plusDays(dayOfWeek.getValue() - SALARY_DATE); } public static SalaryStatus getStatus(Salary salary) { diff --git a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java index f4501c91..adfa9935 100644 --- a/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java +++ b/src/main/java/com/postgraduate/domain/senior/application/usecase/SeniorInfoUseCase.java @@ -99,4 +99,9 @@ public AllSeniorIdResponse getAllSeniorId() { .toList(); return new AllSeniorIdResponse(seniorIds); } + + public Long getSeniorId(String nickName) { + Senior senior = seniorGetService.bySeniorNickName(nickName); + return senior.getSeniorId(); + } }