- DjbApistatusIncidentPrenotice Entity/Repository 추가 - 사전 발송 시각 및 결과 관리 로직 PortalNoticeManService에 추가 - UI에 사전 발송 관련 Feature 추가 및 Validation 포함
This commit is contained in:
@@ -3,10 +3,13 @@ package com.eactive.eai.rms.onl.apim.portalnotice;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.DjbApistatusIncident;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.DjbApistatusIncidentApi;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.DjbApistatusIncidentApiId;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.DjbApistatusIncidentPrenotice;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.DjbApistatusIncidentTimeline;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.IncidentKind;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.IncidentState;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.entity.PrenoticeResult;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.repository.DjbApistatusIncidentApiRepository;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.repository.DjbApistatusIncidentPrenoticeRepository;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.repository.DjbApistatusIncidentRepository;
|
||||
import com.eactive.apim.portal.djb.apistatus.incident.repository.DjbApistatusIncidentTimelineRepository;
|
||||
import com.eactive.apim.portal.file.entity.FileDetail;
|
||||
@@ -53,6 +56,7 @@ public class PortalNoticeManService extends BaseService {
|
||||
private final DjbApistatusIncidentRepository incidentRepository;
|
||||
private final DjbApistatusIncidentApiRepository incidentApiRepository;
|
||||
private final DjbApistatusIncidentTimelineRepository incidentTimelineRepository;
|
||||
private final DjbApistatusIncidentPrenoticeRepository incidentPrenoticeRepository;
|
||||
private final ApiStatusDraftTemplate draftTemplate;
|
||||
private final ApiStatusNoticeComposer noticeComposer;
|
||||
|
||||
@@ -81,6 +85,7 @@ public class PortalNoticeManService extends BaseService {
|
||||
DjbApistatusIncidentRepository incidentRepository,
|
||||
DjbApistatusIncidentApiRepository incidentApiRepository,
|
||||
DjbApistatusIncidentTimelineRepository incidentTimelineRepository,
|
||||
DjbApistatusIncidentPrenoticeRepository incidentPrenoticeRepository,
|
||||
ApiStatusDraftTemplate draftTemplate,
|
||||
ApiStatusNoticeComposer noticeComposer){
|
||||
this.portalNoticeService = portalNoticeService;
|
||||
@@ -89,6 +94,7 @@ public class PortalNoticeManService extends BaseService {
|
||||
this.incidentRepository = incidentRepository;
|
||||
this.incidentApiRepository = incidentApiRepository;
|
||||
this.incidentTimelineRepository = incidentTimelineRepository;
|
||||
this.incidentPrenoticeRepository = incidentPrenoticeRepository;
|
||||
this.draftTemplate = draftTemplate;
|
||||
this.noticeComposer = noticeComposer;
|
||||
}
|
||||
@@ -221,6 +227,21 @@ public class PortalNoticeManService extends BaseService {
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
ui.setAffectedApis(apis);
|
||||
|
||||
populatePrenotice(incident, ui);
|
||||
}
|
||||
|
||||
/** 사전 발송 예약/결과를 화면에 실어준다. 예약이 없으면 값은 모두 비워둔다. */
|
||||
private void populatePrenotice(DjbApistatusIncident incident, PortalNoticeUI ui) {
|
||||
incidentPrenoticeRepository.findById(incident.getIncidentId()).ifPresent(prenotice -> {
|
||||
ui.setPrenotiAt(prenotice.getPrenotiAt());
|
||||
ui.setPrenotiRunAt(prenotice.getRunAt());
|
||||
ui.setPrenotiResult(prenotice.getResult() == null ? null : prenotice.getResult().name());
|
||||
ui.setPrenotiTargetCnt(prenotice.getTargetCnt());
|
||||
ui.setPrenotiSentCnt(prenotice.getSentCnt());
|
||||
ui.setPrenotiFailMsg(prenotice.getFailMsg());
|
||||
ui.setPrenotiSent(isPrenoticeSent(prenotice));
|
||||
});
|
||||
}
|
||||
|
||||
public void insert(PortalNoticeUI portalNoticeUI) throws IOException {
|
||||
@@ -326,9 +347,79 @@ public class PortalNoticeManService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
persistPrenotice(portalNoticeUI, saved);
|
||||
|
||||
return saved;
|
||||
}
|
||||
|
||||
// ───────────────────── 점검 사전발송 ─────────────────────
|
||||
|
||||
/**
|
||||
* 사전 발송 예약을 저장한다. 행이 있다 = 예약이 있다.
|
||||
*
|
||||
* <p>사전 발송은 점검(MAINTENANCE)에만 있다 - 장애는 언제 터질지 모르니 미리 알릴 수 없다.
|
||||
* 지정 시각을 비우고 저장하면 예약 취소로 보고 행을 지우되, <b>이미 발송된 건은 남긴다</b>
|
||||
* (발송 이력을 관리자가 지울 수 있으면 안 된다).</p>
|
||||
*
|
||||
* <p>실제 발송은 이 코드가 하지 않는다. RUN_AT/RESULT/건수/실패사유는 향후 스케줄러가 채운다.</p>
|
||||
*/
|
||||
/** 발송 작업이 이미 돌았는지. RESULT 가 비어 있는 행(구 데이터)은 미발송으로 본다. */
|
||||
private static boolean isPrenoticeSent(DjbApistatusIncidentPrenotice prenotice) {
|
||||
return prenotice != null && prenotice.getResult() != null && prenotice.getResult().isSent();
|
||||
}
|
||||
|
||||
private void persistPrenotice(PortalNoticeUI portalNoticeUI, DjbApistatusIncident incident) {
|
||||
DjbApistatusIncidentPrenotice prenotice =
|
||||
incidentPrenoticeRepository.findById(incident.getIncidentId()).orElse(null);
|
||||
|
||||
if (incident.getKind() != IncidentKind.MAINTENANCE) {
|
||||
// 점검 → 장애로 유형이 바뀐 경우. 미발송 예약만 정리한다.
|
||||
if (prenotice != null && !isPrenoticeSent(prenotice)) {
|
||||
incidentPrenoticeRepository.delete(prenotice);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
LocalDateTime prenotiAt = portalNoticeUI.getPrenotiAt();
|
||||
|
||||
if (prenotiAt == null) {
|
||||
if (prenotice != null && !isPrenoticeSent(prenotice)) {
|
||||
incidentPrenoticeRepository.delete(prenotice);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 이미 발송된 건은 지정 시각을 못 바꾼다. 다만 값이 그대로면 제목만 고치는 저장까지 막지는 않는다.
|
||||
if (isPrenoticeSent(prenotice)) {
|
||||
if (!prenotiAt.equals(prenotice.getPrenotiAt())) {
|
||||
throw new IllegalArgumentException("이미 발송된 사전 발송은 지정 시각을 변경할 수 없습니다.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// "사전"이므로 점검 시작보다 빨라야 한다 - 시작 이후면 예고가 아니라 사후 통보가 된다.
|
||||
if (incident.getStartedAt() != null && !prenotiAt.isBefore(incident.getStartedAt())) {
|
||||
throw new IllegalArgumentException("사전 발송 시각은 점검 시작 시각보다 빨라야 합니다.");
|
||||
}
|
||||
|
||||
// 지난 시각으로는 새로 예약할 수 없다. 스케줄러는 'PENDING 이고 지정 시각이 지난' 건을 집어가므로,
|
||||
// 이미 끝난 점검 공지를 수정하면서 과거 시각을 넣으면 곧바로 발송돼 버린다.
|
||||
// 단, 값이 그대로면 통과시킨다 - 스케줄러가 아직 집어가지 못한 기존 예약 때문에
|
||||
// 제목만 고치는 평범한 수정까지 막히면 안 된다.
|
||||
boolean prenotiAtChanged = prenotice == null || !prenotiAt.equals(prenotice.getPrenotiAt());
|
||||
if (prenotiAtChanged && !prenotiAt.isAfter(LocalDateTime.now())) {
|
||||
throw new IllegalArgumentException("사전 발송 시각은 현재 시각 이후여야 합니다. 이미 지난 시각으로는 예약할 수 없습니다.");
|
||||
}
|
||||
|
||||
if (prenotice == null) {
|
||||
prenotice = new DjbApistatusIncidentPrenotice();
|
||||
prenotice.setIncidentId(incident.getIncidentId());
|
||||
prenotice.setResult(PrenoticeResult.PENDING);
|
||||
}
|
||||
prenotice.setPrenotiAt(prenotiAt);
|
||||
incidentPrenoticeRepository.save(prenotice);
|
||||
}
|
||||
|
||||
// ───────────────────── 장애 처리 타임라인 ─────────────────────
|
||||
|
||||
private static final String AUTHOR_OPERATOR = "OPERATOR";
|
||||
@@ -478,6 +569,7 @@ public class PortalNoticeManService extends BaseService {
|
||||
incidentRepository.findByNoticeId(noticeId).ifPresent(incident -> {
|
||||
incidentApiRepository.deleteByIncidentId(incident.getIncidentId());
|
||||
incidentTimelineRepository.deleteByIncidentId(incident.getIncidentId());
|
||||
incidentPrenoticeRepository.deleteByIncidentId(incident.getIncidentId());
|
||||
incidentRepository.delete(incident);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,4 +78,24 @@ public class PortalNoticeUI {
|
||||
private String previousState; // 직전 상태
|
||||
|
||||
private List<IncidentAffectedApiUI> affectedApis;
|
||||
|
||||
// ───── 사전 발송 (점검 공지 한정, djb_apistatus_incident_prenotice) ─────
|
||||
// 관리자가 입력하는 값은 prenotiAt 하나다. 나머지는 발송 스케줄러가 채우는 읽기 전용 결과.
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
|
||||
private LocalDateTime prenotiAt;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm")
|
||||
private LocalDateTime prenotiRunAt;
|
||||
|
||||
private String prenotiResult; // PENDING / SUCCESS / FAIL
|
||||
|
||||
private Integer prenotiTargetCnt;
|
||||
|
||||
private Integer prenotiSentCnt;
|
||||
|
||||
private String prenotiFailMsg;
|
||||
|
||||
/** 발송 작업이 이미 돌았는지 - 화면에서 지정 시각을 잠그는 판단에 쓴다. */
|
||||
private boolean prenotiSent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user