Skip to content

Commit

Permalink
Merge pull request #165 from WE-ARE-RACCOONS/RAC-322
Browse files Browse the repository at this point in the history
RAC-322 fix : ์ •์‚ฐ ๋‹จ์œ„ ์ฃผ๋‹จ์œ„๋กœ ๋ณ€๊ฒฝ
  • Loading branch information
ywj9811 authored Mar 10, 2024
2 parents 56f96a1 + a652d48 commit 64f65e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
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

0 comments on commit 64f65e5

Please sign in to comment.