260723_01_ENH: 문자발송 갱신 조건 변경 (1시간 이내 -> 현재 시간보다 작은 모든 것)

This commit is contained in:
2026-07-23 10:54:55 +09:00
parent 8043fc457c
commit 86f9d1b634
3 changed files with 25 additions and 24 deletions

View File

@@ -33,14 +33,20 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
from TSendEntity s
where s.sendStatus = :sendStatus
and s.sendTy in :sendTyList
and s.sendDt between :fromDt and :toDt
and s.resultCode in :resultCodes
and s.sendDt <= :now
and exists (
select 1
from BizLogEntity b
where b.cmid = s.cmid
)
order by s.sendIdx asc
""")
List<TSendEntity> findSendListToRefreshWithinHours(
List<TSendEntity> findSendListToRefresh(
List<Short> sendTyList,
short sendStatus,
LocalDateTime fromDt,
LocalDateTime toDt,
List<Short> resultCodes,
LocalDateTime now,
Pageable pageable
);

View File

@@ -38,22 +38,22 @@ public class BizLogResultScheduler {
private final BizLogRepository bizLogRepository;
private final BulkSendRepository bulkSendRepository;
@Value("${kri.sms.result-sync.window-hours:1}")
private long resultSyncWindowHours;
@Value("${kri.sms.result-sync.batch-size:1000}")
private int resultSyncBatchSize;
@Scheduled(fixedDelayString = "${kri.sms.result-sync.fixed-delay-ms:60000}") // 나중에 증가시킬 것
@Scheduled(fixedDelayString = "${kri.sms.result-sync.fixed-delay-ms:60000}")
@Transactional(transactionManager = "transactionManager")
public void syncSmsResults() {
TimeWindow window = buildWindow(resultSyncWindowHours);
List<Short> sendTyList = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode(), SendType.KKO_AT.getCode());
List<Short> resultCodes = List.of(
NotihubConst.SMS_STANDBY,
NotihubConst.LMS_MMS_STANDBY,
NotihubConst.KKO_AT_STANDBY
);
while (true) {
List<TSendEntity> batch = fetchRefreshTargets(sendTyList, window, resultSyncBatchSize);
List<TSendEntity> batch = fetchRefreshTargets(sendTyList, resultCodes, resultSyncBatchSize);
if (batch.isEmpty()) {
return;
}
@@ -63,21 +63,20 @@ public class BizLogResultScheduler {
BatchResult result = applyResultsAndCollectDeltas(batch, bulkCtx);
persistChanges(result, bulkCtx);
if (result.updatedSends().isEmpty()) {
return;
}
}
}
private TimeWindow buildWindow(long hours) {
LocalDateTime toDt = LocalDateTime.now();
return new TimeWindow(toDt.minusHours(hours), toDt);
}
private List<TSendEntity> fetchRefreshTargets(List<Short> sendTyList, TimeWindow window,
private List<TSendEntity> fetchRefreshTargets(List<Short> sendTyList, List<Short> resultCodes,
int size) {
return sendRepository.findSendListToRefreshWithinHours(
return sendRepository.findSendListToRefresh(
sendTyList,
SendStatusType.STANDBY.getCode(),
window.from(),
window.to(),
resultCodes,
LocalDateTime.now(),
PageRequest.of(0, size)
);
}
@@ -275,9 +274,6 @@ public class BizLogResultScheduler {
}
}
private record TimeWindow(LocalDateTime from, LocalDateTime to) {
}
private record BulkContext(Set<String> bulkKeys, Map<String, TBulkSendEntity> bulkMap) {