[BO] 문자 발송 작업 중 (2)

This commit is contained in:
kangsunlee
2025-07-08 11:38:13 +09:00
parent bbebedf1da
commit 68f99ca8fb
4 changed files with 31 additions and 33 deletions

View File

@@ -6,6 +6,7 @@ import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.springframework.stereotype.Component;
@Component
@@ -49,26 +50,21 @@ public class DateUiUtil {
* @param day 오늘 날짜의 일(day of month)
* @return DayRange 객체 또는 발송일이 아니면 null
*/
public static DayRange getDayRange(int day) {
public static Optional<DayRange> getDayRange(int day) {
LocalDate today = LocalDate.now();
int lastDay = today.lengthOfMonth();
int fromDay;
int toDay;
// 주간 범위 계산
if (day == 7) {
fromDay = day - 6;
toDay = day - 1;
} else if (day == 14 || day == 21) {
fromDay = day - 7;
toDay = day - 1;
return Optional.of(new DayRange(1, 6));
} else if (day == 14) {
return Optional.of(new DayRange(7, 13));
} else if (day == 21) {
return Optional.of(new DayRange(14, 20));
} else if (day == lastDay) {
fromDay = 21;
toDay = lastDay;
return Optional.of(new DayRange(21, lastDay));
} else {
return null;
return Optional.empty(); // 발송일 아님
}
return new DayRange(fromDay, toDay);
}
}

View File

@@ -24,7 +24,7 @@ public class AutoSchedulesController {
}
// 매일 오후 5시 마다 실행되는 스케줄러
// @Scheduled(cron = "0 0 17 * * ?")
@Scheduled(cron = "0 0 17 * * ?")
public void fetchSmsAutoSend() {
portIn.sendAutoSms();
}

View File

@@ -20,6 +20,7 @@ import org.springframework.stereotype.Service;
import java.util.Optional;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@Service
@RequiredArgsConstructor
@@ -41,24 +42,24 @@ class AutoSchedulesService implements AutoSchedulesPortIn {
// 문자 자동 발송 활성화 상태 체크
if (getSmsAutoStatus == null || Boolean.FALSE.equals(getSmsAutoStatus.getActive())) {
System.out.println("문자 발송 비활성화 상태입니다.");
System.out.println("문자 발송 비활성화 상태");
return Optional.of(false);
}
String currentMonth = DateUiUtil.getCurrentMonthValue(); // 현재 월
LocalDate today = LocalDate.now();
int day = today.getDayOfMonth();
int lastDay = today.lengthOfMonth();
// 현재 월
String currentMonth = DateUiUtil.getCurrentMonthValue();
// 매월 7일, 24일, 21일, 말일 에만 발송
if (day == 7 || day == 14 || day == 21 || day == lastDay) {
DayRange dayRange = DateUiUtil.getDayRange(day);
DayRange dayRange = DateUiUtil.getDayRange(day).orElse(null);
if (dayRange == null) {
return Optional.of(false);
}
// 해당 날짜에 일계부 미등록한 임가 목록 조회
// dayRange 날짜 범위의 일계부 미등록한 임가 목록 조회
List<GetIncompleteHouseholds> incompleteHouseholds =
getIncompleteHouseholdsPortIn.operate(
new GetIncompleteHouseholdsCmd(
@@ -66,13 +67,14 @@ class AutoSchedulesService implements AutoSchedulesPortIn {
dayRange.getFromDay(),
dayRange.getToDay()));
portOut.sendAutoSms(new CreateSmsAutoSendCmd(
incompleteHouseholds,
getSmsAutoStatus.getSendPhone(),
getSmsAutoStatus.getMessage()
));
} else {
System.out.println("문자 발송일 아님: " + today);
// 미등록 임가가 있을 경우에만 실행
if(!CollectionUtils.isEmpty(incompleteHouseholds)) {
portOut.sendAutoSms(new CreateSmsAutoSendCmd(
incompleteHouseholds,
getSmsAutoStatus.getSendPhone(),
getSmsAutoStatus.getMessage()
));
}
}
return Optional.of(true);

View File

@@ -20,15 +20,15 @@
MSG_BODY
)
VALUES
<foreach collection="cmd.sendHouseholds" item="item" separator=",">
<foreach collection="sendHouseholds" item="item" separator=",">
(
0,
5,
TO_CHAR(NOW(), 'YYYYMMDDHH24MISS') || '_' || #{item.householdNum},
NOW(),
NOW(),
#{item.phone},
#{item.sendPhone},
#{item.message}
#{sendPhone},
#{message}
)
</foreach>
</insert>