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) {