배치이력 생성 작업
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
package app.module.admin.config.application.batch;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.batchLog.ports.BatchLogPortIn;
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
public class BatchLogRunner {
|
||||||
|
private final BatchLogPortIn batchLogPortIn;
|
||||||
|
|
||||||
|
public void run(BatchLogType batchType, Runnable action) {
|
||||||
|
// 이미 실행 중인지 확인
|
||||||
|
if (batchLogPortIn.exists(batchType)) {
|
||||||
|
log.warn("[{}] 배치가 이미 실행 중 입니다.", batchType.name());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 실행 로그 insert (RUNNING)
|
||||||
|
Long logId = batchLogPortIn.create(batchType);
|
||||||
|
|
||||||
|
try {
|
||||||
|
action.run();
|
||||||
|
// 성공 처리
|
||||||
|
batchLogPortIn.update(logId, "SUCCESS", null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 실패 처리
|
||||||
|
batchLogPortIn.update(logId, "FAIL", e.getMessage());
|
||||||
|
log.error("[{}] 배치 실패: {}", batchType.name(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.adapters.persistence;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.batchLog.ports.BatchLogPortOut;
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogCmd;
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
class BatchLogDao implements BatchLogPortOut {
|
||||||
|
private final BatchLogMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exists(BatchLogType type) {
|
||||||
|
return mapper.exists(type.name());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long create(BatchLogType type) {
|
||||||
|
BatchLogCmd cmd = new BatchLogCmd(null, type.name(), "RUNNING", LocalDateTime.now());
|
||||||
|
mapper.create(cmd);
|
||||||
|
return cmd.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Long id, String status, String errorMessage) {
|
||||||
|
mapper.update(id, status, errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.adapters.persistence;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogCmd;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface BatchLogMapper {
|
||||||
|
boolean exists(String type);
|
||||||
|
Long create(BatchLogCmd cmd);
|
||||||
|
void update(Long id, String status, String errorMessage);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.ports;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
|
||||||
|
|
||||||
|
public interface BatchLogPortIn {
|
||||||
|
boolean exists(BatchLogType type);
|
||||||
|
Long create(BatchLogType type);
|
||||||
|
void update(Long id, String status, String errorMessage);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.ports;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
|
||||||
|
|
||||||
|
public interface BatchLogPortOut {
|
||||||
|
boolean exists(BatchLogType type);
|
||||||
|
Long create(BatchLogType type);
|
||||||
|
void update(Long id, String status, String errorMessage);
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.ports.application;
|
||||||
|
|
||||||
|
import app.module.admin.usecase.batchLog.ports.BatchLogPortIn;
|
||||||
|
import app.module.admin.usecase.batchLog.ports.BatchLogPortOut;
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
class BatchLogService implements BatchLogPortIn {
|
||||||
|
private final BatchLogPortOut portOut;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean exists(BatchLogType type) {
|
||||||
|
return portOut.exists(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long create(BatchLogType type) {
|
||||||
|
return portOut.create(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Long id, String status, String errorMessage) {
|
||||||
|
portOut.update(id, status, errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.ports.application.domain;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class BatchLog {
|
||||||
|
private Long id;
|
||||||
|
private String type;
|
||||||
|
private String status;
|
||||||
|
private LocalDateTime startAt;
|
||||||
|
private LocalDateTime endAt;
|
||||||
|
private String errorMessage;
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.ports.application.domain;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode
|
||||||
|
public class BatchLogCmd {
|
||||||
|
private Long id;
|
||||||
|
private String type;
|
||||||
|
private String status;
|
||||||
|
private LocalDateTime startAt;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package app.module.admin.usecase.batchLog.ports.application.domain;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum BatchLogType {
|
||||||
|
AUTO_SMS,
|
||||||
|
MONTHLY_STATUS,
|
||||||
|
CARRYOVER;
|
||||||
|
}
|
||||||
@@ -1,14 +1,12 @@
|
|||||||
package app.module.admin.usecase.schedule.autoSchedules.adapters.persistence;
|
package app.module.admin.usecase.schedule.autoSchedules.adapters.persistence;
|
||||||
|
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortOut;
|
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortOut;
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.application.domain.CreateSmsAutoSendCmd;
|
import java.util.Optional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Repository
|
@Repository
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -24,24 +22,9 @@ class AutoSchedulesDao implements AutoSchedulesPortOut {
|
|||||||
|
|
||||||
return Optional.of(true);
|
return Optional.of(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// 예외 발생 시 false 반환
|
log.error("[AutoSchedule][createMonthlyInputStatus] message: {}", e.getMessage(), e);
|
||||||
return Optional.of(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
throw new RuntimeException("월별 입력 항목 관리 생성 중 오류: " + e.getMessage(), e);
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd) {
|
|
||||||
try {
|
|
||||||
mapper.createSmsAutoSend(cmd);
|
|
||||||
|
|
||||||
return Optional.of(true);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.info(e.getMessage());
|
|
||||||
|
|
||||||
// 예외 발생 시 false 반환
|
|
||||||
return Optional.of(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,8 +38,7 @@ class AutoSchedulesDao implements AutoSchedulesPortOut {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("[AutoSchedule][monthlyCarryOver] message: {}", e.getMessage(), e);
|
log.error("[AutoSchedule][monthlyCarryOver] message: {}", e.getMessage(), e);
|
||||||
|
|
||||||
// 예외 발생 시 false 반환
|
throw new RuntimeException("일계부 월초이월금 생성 중 오류: " + e.getMessage(), e);
|
||||||
return Optional.of(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package app.module.admin.usecase.schedule.autoSchedules.adapters.persistence;
|
package app.module.admin.usecase.schedule.autoSchedules.adapters.persistence;
|
||||||
|
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.application.domain.CreateSmsAutoSendCmd;
|
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface AutoSchedulesMapper {
|
public interface AutoSchedulesMapper {
|
||||||
void createMonthlyInputStatus();
|
String createMonthlyInputStatus();
|
||||||
void createSmsAutoSend(CreateSmsAutoSendCmd cmd);
|
|
||||||
String createMonthlyCarryOver();
|
String createMonthlyCarryOver();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package app.module.admin.usecase.schedule.autoSchedules.adapters.web;
|
package app.module.admin.usecase.schedule.autoSchedules.adapters.web;
|
||||||
|
|
||||||
import app.module.admin.config.application.util.DateUiUtil;
|
|
||||||
import app.module.admin.config.application.util.model.DayRange;
|
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortIn;
|
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortIn;
|
||||||
import java.time.LocalDate;
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -17,13 +14,19 @@ public class AutoSchedulesController {
|
|||||||
this.portIn = portIn;
|
this.portIn = portIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 매 월 1일 1초 마다 실행되는 스케줄러
|
/**
|
||||||
|
* 월별입력상태 등록
|
||||||
|
* 매 월 1일 1초 마다 실행되는 스케줄러
|
||||||
|
*/
|
||||||
@Scheduled(cron = "1 0 0 1 * *")
|
@Scheduled(cron = "1 0 0 1 * *")
|
||||||
public void fetchArticlesPeriodically() {
|
public void fetchArticlesPeriodically() {
|
||||||
portIn.operate();
|
portIn.operate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 매일 오후 5시 마다 실행되는 스케줄러
|
/**
|
||||||
|
* 문자자동발송 등록
|
||||||
|
* 매일 오후 5시 마다 실행되는 스케줄러
|
||||||
|
*/
|
||||||
@Scheduled(cron = "0 0 17 * * ?")
|
@Scheduled(cron = "0 0 17 * * ?")
|
||||||
public void fetchSmsAutoSend() {
|
public void fetchSmsAutoSend() {
|
||||||
portIn.sendAutoSms();
|
portIn.sendAutoSms();
|
||||||
@@ -37,14 +40,4 @@ public class AutoSchedulesController {
|
|||||||
public void fetchMonthlyCarryOver() {
|
public void fetchMonthlyCarryOver() {
|
||||||
portIn.monthlyCarryOver();
|
portIn.monthlyCarryOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO 스케쥴 있다면.. 추가.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 매일 오후 5시 마다 실행되는 스케줄러
|
|
||||||
@Scheduled(cron = "0 1 * * * ?")
|
|
||||||
public void fetchSmsAutoSenTest() {
|
|
||||||
portIn.sendAutoSmsTest();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ public interface AutoSchedulesPortIn {
|
|||||||
Optional<Boolean> operate();
|
Optional<Boolean> operate();
|
||||||
Optional<Boolean> sendAutoSms();
|
Optional<Boolean> sendAutoSms();
|
||||||
Optional<Boolean> monthlyCarryOver();
|
Optional<Boolean> monthlyCarryOver();
|
||||||
Optional<Boolean> sendAutoSmsTest();
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package app.module.admin.usecase.schedule.autoSchedules.ports;
|
package app.module.admin.usecase.schedule.autoSchedules.ports;
|
||||||
|
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.application.domain.CreateSmsAutoSendCmd;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface AutoSchedulesPortOut {
|
public interface AutoSchedulesPortOut {
|
||||||
|
|
||||||
Optional<Boolean> operate();
|
Optional<Boolean> operate();
|
||||||
Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd);
|
|
||||||
Optional<Boolean> monthlyCarryOver();
|
Optional<Boolean> monthlyCarryOver();
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,42 @@
|
|||||||
package app.module.admin.usecase.schedule.autoSchedules.ports.application;
|
package app.module.admin.usecase.schedule.autoSchedules.ports.application;
|
||||||
|
|
||||||
|
import app.module.admin.config.application.batch.BatchLogRunner;
|
||||||
import app.module.admin.config.application.util.DateUiUtil;
|
import app.module.admin.config.application.util.DateUiUtil;
|
||||||
import app.module.admin.config.application.util.model.DayRange;
|
import app.module.admin.config.application.util.model.DayRange;
|
||||||
|
import app.module.admin.usecase.batchLog.ports.application.domain.BatchLogType;
|
||||||
import app.module.admin.usecase.dashboard.getSmsAutoStatus.ports.GetSmsAutoStatusPortIn;
|
import app.module.admin.usecase.dashboard.getSmsAutoStatus.ports.GetSmsAutoStatusPortIn;
|
||||||
import app.module.admin.usecase.dashboard.getSmsAutoStatus.ports.application.domain.GetSmsAutoStatus;
|
import app.module.admin.usecase.dashboard.getSmsAutoStatus.ports.application.domain.GetSmsAutoStatus;
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortIn;
|
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortIn;
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortOut;
|
import app.module.admin.usecase.schedule.autoSchedules.ports.AutoSchedulesPortOut;
|
||||||
import app.module.admin.usecase.schedule.autoSchedules.ports.application.domain.CreateSmsAutoSendCmd;
|
|
||||||
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.GetIncompleteHouseholdsPortIn;
|
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.GetIncompleteHouseholdsPortIn;
|
||||||
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholds;
|
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholds;
|
||||||
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholdsCmd;
|
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholdsCmd;
|
||||||
|
import app.module.mms.ports.MMSPortIn;
|
||||||
|
import app.module.mms.ports.application.domain.CreateSmsAutoSendCmd;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import app.module.mms.ports.MMSPortIn;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
class AutoSchedulesService implements AutoSchedulesPortIn {
|
class AutoSchedulesService implements AutoSchedulesPortIn {
|
||||||
|
|
||||||
private final AutoSchedulesPortOut portOut;
|
private final AutoSchedulesPortOut portOut;
|
||||||
private final MMSPortIn mmsPortIn;
|
private final MMSPortIn mmsPortIn;
|
||||||
private final GetSmsAutoStatusPortIn getSmsAutoStatusPortIn;
|
private final GetSmsAutoStatusPortIn getSmsAutoStatusPortIn;
|
||||||
private final GetIncompleteHouseholdsPortIn getIncompleteHouseholdsPortIn;
|
private final GetIncompleteHouseholdsPortIn getIncompleteHouseholdsPortIn;
|
||||||
|
private final BatchLogRunner batchLogRunner;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Boolean> operate() {
|
public Optional<Boolean> operate() {
|
||||||
return portOut.operate();
|
batchLogRunner.run(BatchLogType.MONTHLY_STATUS, portOut::operate);
|
||||||
|
return Optional.of(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,63 +44,40 @@ class AutoSchedulesService implements AutoSchedulesPortIn {
|
|||||||
public Optional<Boolean> sendAutoSms() {
|
public Optional<Boolean> sendAutoSms() {
|
||||||
GetSmsAutoStatus getSmsAutoStatus = getSmsAutoStatusPortIn.operate().orElse(null);
|
GetSmsAutoStatus getSmsAutoStatus = getSmsAutoStatusPortIn.operate().orElse(null);
|
||||||
|
|
||||||
// 문자 자동 발송 활성화 상태 체크
|
|
||||||
if (getSmsAutoStatus == null || Boolean.FALSE.equals(getSmsAutoStatus.getActive())) {
|
if (getSmsAutoStatus == null || Boolean.FALSE.equals(getSmsAutoStatus.getActive())) {
|
||||||
System.out.println("문자 발송 비활성화 상태");
|
log.info("문자 발송 비활성화 상태");
|
||||||
return Optional.of(false);
|
return Optional.of(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalDate today = LocalDate.now();
|
LocalDate today = LocalDate.now();
|
||||||
int day = today.getDayOfMonth();
|
int day = today.getDayOfMonth();
|
||||||
|
|
||||||
// 발송일 조건: 8일, 15일, 22일, 1일(다음 달 대상자)
|
|
||||||
if (day == 8 || day == 15 || day == 22 || day == 1) {
|
if (day == 8 || day == 15 || day == 22 || day == 1) {
|
||||||
// 발송 대상 날짜 범위 구하기
|
|
||||||
DayRange dayRange = DateUiUtil.getDayRange(today).orElse(null);
|
DayRange dayRange = DateUiUtil.getDayRange(today).orElse(null);
|
||||||
if (dayRange == null) return Optional.of(false);
|
if (dayRange == null) {
|
||||||
|
log.error("잘못된 날짜({})에 문자 자동 발송 로직이 실행됨 - 발송 대상일이 아님", today);
|
||||||
|
return Optional.of(false);
|
||||||
|
}
|
||||||
|
|
||||||
// 대상 월 계산 (1일 이면 이전 달 / 1일이 아니면 현재 달 yyyyMM 을 가져온다.)
|
|
||||||
LocalDate baseDate = (day == 1) ? today.minusMonths(1) : today;
|
LocalDate baseDate = (day == 1) ? today.minusMonths(1) : today;
|
||||||
String targetMonth = DateUiUtil.getMonthValue(baseDate);
|
String targetMonth = DateUiUtil.getMonthValue(baseDate);
|
||||||
|
|
||||||
// dayRange 날짜 범위의 일계부 미등록한 임가 목록 조회
|
|
||||||
List<GetIncompleteHouseholds> incompleteHouseholds = getIncompleteHouseholdsPortIn.operate(
|
List<GetIncompleteHouseholds> incompleteHouseholds = getIncompleteHouseholdsPortIn.operate(
|
||||||
new GetIncompleteHouseholdsCmd(targetMonth, dayRange.getFromDay(), dayRange.getToDay())
|
new GetIncompleteHouseholdsCmd(targetMonth, dayRange.getFromDay(), dayRange.getToDay())
|
||||||
);
|
);
|
||||||
|
|
||||||
// 미등록 임가가 있을 경우에만 실행
|
if (!CollectionUtils.isEmpty(incompleteHouseholds)) {
|
||||||
if(!CollectionUtils.isEmpty(incompleteHouseholds)) {
|
batchLogRunner.run(BatchLogType.AUTO_SMS, () -> {
|
||||||
portOut.sendAutoSms(new CreateSmsAutoSendCmd(
|
mmsPortIn.sendAutoSms(new CreateSmsAutoSendCmd(
|
||||||
incompleteHouseholds,
|
incompleteHouseholds,
|
||||||
getSmsAutoStatus.getSendPhone(),
|
getSmsAutoStatus.getSendPhone(),
|
||||||
getSmsAutoStatus.getMessage()
|
getSmsAutoStatus.getMessage()
|
||||||
));
|
));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
log.info("문자 발송 날짜 아님.");
|
||||||
return Optional.of(true);
|
return Optional.of(false);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<Boolean> sendAutoSmsTest() {
|
|
||||||
String targetMonth = "202507";
|
|
||||||
DayRange dayRange = new DayRange(1, 7);
|
|
||||||
GetSmsAutoStatus getSmsAutoStatus = new GetSmsAutoStatus(true, "테스트", "01012345678", null, null);
|
|
||||||
|
|
||||||
// dayRange 날짜 범위의 일계부 미등록한 임가 목록 조회
|
|
||||||
List<GetIncompleteHouseholds> incompleteHouseholds = getIncompleteHouseholdsPortIn.operate(
|
|
||||||
new GetIncompleteHouseholdsCmd(targetMonth, dayRange.getFromDay(), dayRange.getToDay())
|
|
||||||
);
|
|
||||||
|
|
||||||
System.out.println(incompleteHouseholds);
|
|
||||||
|
|
||||||
// 미등록 임가가 있을 경우에만 실행
|
|
||||||
if(!CollectionUtils.isEmpty(incompleteHouseholds)) {
|
|
||||||
mmsPortIn.sendAutoSms(new app.module.mms.ports.application.domain.CreateSmsAutoSendCmd(
|
|
||||||
incompleteHouseholds,
|
|
||||||
getSmsAutoStatus.getSendPhone(),
|
|
||||||
getSmsAutoStatus.getMessage()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(true);
|
return Optional.of(true);
|
||||||
@@ -104,6 +85,7 @@ class AutoSchedulesService implements AutoSchedulesPortIn {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Boolean> monthlyCarryOver() {
|
public Optional<Boolean> monthlyCarryOver() {
|
||||||
return portOut.monthlyCarryOver();
|
batchLogRunner.run(BatchLogType.CARRYOVER, portOut::monthlyCarryOver);
|
||||||
|
return Optional.of(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package app.module.admin.usecase.schedule.autoSchedules.ports.application.domain;
|
|
||||||
|
|
||||||
import app.module.admin.usecase.schedule.getIncompleteHouseholds.ports.application.domain.GetIncompleteHouseholds;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@AllArgsConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
public class CreateSmsAutoSendCmd {
|
|
||||||
private List<GetIncompleteHouseholds> sendHouseholds;
|
|
||||||
private String sendPhone;
|
|
||||||
private String message;
|
|
||||||
}
|
|
||||||
@@ -19,16 +19,13 @@ public class MMSDao implements MMSPortOut {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd) {
|
public Optional<Boolean> sendAutoSms(CreateSmsAutoSendCmd cmd) {
|
||||||
try {
|
try {
|
||||||
log.debug("@@@ sendAutoSmsTest");
|
|
||||||
|
|
||||||
mapper.createSmsAutoSend(cmd);
|
mapper.createSmsAutoSend(cmd);
|
||||||
|
|
||||||
return Optional.of(true);
|
return Optional.of(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info(e.getMessage());
|
log.error(e.getMessage());
|
||||||
|
|
||||||
// 예외 발생 시 false 반환
|
throw new RuntimeException("문자 자동 발송 생성 중 오류: " + e.getMessage(), e);
|
||||||
return Optional.of(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
admin/src/main/resources/mappers/batchLog/BatchLogMapper.xml
Normal file
34
admin/src/main/resources/mappers/batchLog/BatchLogMapper.xml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="app.module.admin.usecase.batchLog.adapters.persistence.BatchLogMapper">
|
||||||
|
<!-- 실행 중인지 확인 -->
|
||||||
|
<select id="exists" resultType="boolean">
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM batch_log
|
||||||
|
WHERE type = #{type}
|
||||||
|
AND status = 'RUNNING'
|
||||||
|
AND start_at::date = CURRENT_DATE
|
||||||
|
)
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 실행 로그 insert -->
|
||||||
|
<insert id="create">
|
||||||
|
<selectKey keyProperty="id" resultType="long" order="BEFORE">
|
||||||
|
SELECT nextval('batch_log_id_seq')
|
||||||
|
</selectKey>
|
||||||
|
|
||||||
|
INSERT INTO batch_log (id, type, status, start_at, created_at)
|
||||||
|
VALUES (#{id}, #{type}, #{status}, #{startAt}, now())
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 상태 업데이트 -->
|
||||||
|
<update id="update">
|
||||||
|
UPDATE batch_log
|
||||||
|
SET status = #{status},
|
||||||
|
error_message = #{errorMessage},
|
||||||
|
end_at = now()
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
</mapper>
|
||||||
@@ -3,38 +3,11 @@
|
|||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper
|
<mapper
|
||||||
namespace="app.module.admin.usecase.schedule.autoSchedules.adapters.persistence.AutoSchedulesMapper">
|
namespace="app.module.admin.usecase.schedule.autoSchedules.adapters.persistence.AutoSchedulesMapper">
|
||||||
<select id="createMonthlyInputStatus">
|
<select id="createMonthlyInputStatus" resultType="java.lang.String">
|
||||||
select fn_monthly_input_status()
|
select fn_monthly_input_status()
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="createSmsAutoSend">
|
<select id="createMonthlyCarryOver" resultType="java.lang.String">
|
||||||
/* createSmsAutoSend : 문자 발송 insert */
|
|
||||||
INSERT INTO biz_msg
|
|
||||||
(
|
|
||||||
MSG_TYPE,
|
|
||||||
CMID,
|
|
||||||
REQUEST_TIME,
|
|
||||||
SEND_TIME,
|
|
||||||
DEST_PHONE,
|
|
||||||
SEND_PHONE,
|
|
||||||
MSG_BODY
|
|
||||||
)
|
|
||||||
VALUES
|
|
||||||
<foreach collection="sendHouseholds" item="item" separator=",">
|
|
||||||
(
|
|
||||||
5,
|
|
||||||
TO_CHAR(NOW(), 'YYYYMMDDHH24MISS') || '_' || #{item.householdNum},
|
|
||||||
NOW(),
|
|
||||||
NOW(),
|
|
||||||
#{item.phone},
|
|
||||||
#{sendPhone},
|
|
||||||
#{message}
|
|
||||||
)
|
|
||||||
</foreach>
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<select id="createMonthlyCarryOver">
|
|
||||||
select fn_monthly_carry_over(null)
|
select fn_monthly_carry_over(null)
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user