Skip to content

Commit

Permalink
Merge pull request #166 from WE-ARE-RACCOONS/develop
Browse files Browse the repository at this point in the history
Develop 운영 반영
  • Loading branch information
ywj9811 authored Mar 10, 2024
2 parents 108805d + 64f65e5 commit 0246469
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -78,6 +83,7 @@ public void savePay(PaymentResultRequest request) {
paymentSaveService.save(payment);
refundPay(payment);
}
return true;
}

public void refundPayByUser(User user, String orderId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Salary> salaries = salaryGetService.findAllLastMonth();
List<Salary> salaries = salaryGetService.findAllLast();
slackSalaryMessage.sendSlackSalary(salaries);

List<SeniorAndAccount> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public Page<SeniorSalary> findDistinctSeniors(String search, Integer page) {
return salaryRepository.findDistinctBySearchSenior(search, pageable);
}

public List<Salary> findAllLastMonth() {
public List<Salary> findAllLast() {
LocalDate salaryDate =
SalaryUtil.getSalaryDate()
.minusMonths(1);
.minusDays(7);
return salaryRepository.findAllLastSalary(salaryDate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,25 @@
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();
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit 0246469

Please sign in to comment.