261022_02_ENH: 발송 결과·벌크 상세·벌크 목록 응답에 예약 취소 가능 여부(cancelable) 추가
This commit is contained in:
@@ -44,6 +44,9 @@ public class BulkSendInfoDto {
|
|||||||
@Schema(description = "예약 여부")
|
@Schema(description = "예약 여부")
|
||||||
private Boolean resve;
|
private Boolean resve;
|
||||||
|
|
||||||
|
@Schema(description = "조회 시점에 취소 가능한 예약 상세 건이 하나 이상인지 여부. 최종 판단은 취소 API 응답 기준")
|
||||||
|
private boolean cancelable;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "발송일시")
|
@Schema(description = "발송일시")
|
||||||
private LocalDateTime sendDt;
|
private LocalDateTime sendDt;
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ public record SendResultInfoDto(
|
|||||||
@Schema(description = "예약 여부")
|
@Schema(description = "예약 여부")
|
||||||
Boolean resve,
|
Boolean resve,
|
||||||
|
|
||||||
|
@Schema(description = "조회 시점의 상태 기준 예약 취소 가능 여부. 최종 판단은 취소 API 응답 기준")
|
||||||
|
boolean cancelable,
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "결과 코드")
|
@Schema(description = "결과 코드")
|
||||||
Short resultCode,
|
Short resultCode,
|
||||||
@@ -118,6 +121,11 @@ public record SendResultInfoDto(
|
|||||||
|
|
||||||
public static SendResultInfoDto from(TSendEntity entity,
|
public static SendResultInfoDto from(TSendEntity entity,
|
||||||
List<TSendResultCodeEntity> resultCodeEntity) {
|
List<TSendResultCodeEntity> resultCodeEntity) {
|
||||||
|
return from(entity, resultCodeEntity, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SendResultInfoDto from(TSendEntity entity,
|
||||||
|
List<TSendResultCodeEntity> resultCodeEntity, boolean cancelable) {
|
||||||
if (entity == null) {
|
if (entity == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -137,6 +145,7 @@ public record SendResultInfoDto(
|
|||||||
.sid(entity.getSid())
|
.sid(entity.getSid())
|
||||||
.sendTy(entity.getSendTy())
|
.sendTy(entity.getSendTy())
|
||||||
.resve(entity.isResve())
|
.resve(entity.isResve())
|
||||||
|
.cancelable(cancelable)
|
||||||
.resultCode(entity.getResultCode())
|
.resultCode(entity.getResultCode())
|
||||||
.resultLabel(canceled ? NotihubConst.CANCELED_LABEL
|
.resultLabel(canceled ? NotihubConst.CANCELED_LABEL
|
||||||
: resultCode != null ? resultCode.getResultLabel() : null)
|
: resultCode != null ? resultCode.getResultLabel() : null)
|
||||||
|
|||||||
@@ -21,6 +21,22 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
||||||
|
|
||||||
|
// 목록과 벌크 집계에서 동일한 상태 기준을 사용한다. 취소 API의 잠금 후 판단이 최종이다.
|
||||||
|
String CANCELABLE_CONDITION = """
|
||||||
|
s.resve = true and s.sendStatus = 0 and s.cancelDt is null
|
||||||
|
and (
|
||||||
|
(s.sendTy = :emailSendType and s.resultCode = :emailStandbyCode)
|
||||||
|
or (s.sendTy in :bizSendTypes and exists (
|
||||||
|
select 1 from BizMsgEntity m where m.cmid = s.cmid and m.status = 0
|
||||||
|
))
|
||||||
|
)
|
||||||
|
""";
|
||||||
|
|
||||||
|
@Query("select s.sendIdx from TSendEntity s where s.sendIdx in :sendIds and ("
|
||||||
|
+ CANCELABLE_CONDITION + ")")
|
||||||
|
List<Long> findCancelableSendIds(List<Long> sendIds, short emailSendType,
|
||||||
|
short emailStandbyCode, List<Short> bizSendTypes);
|
||||||
|
|
||||||
@Lock(LockModeType.PESSIMISTIC_WRITE)
|
@Lock(LockModeType.PESSIMISTIC_WRITE)
|
||||||
@Query("select s from TSendEntity s where s.sendIdx = :sendIdx")
|
@Query("select s from TSendEntity s where s.sendIdx = :sendIdx")
|
||||||
Optional<TSendEntity> findForUpdate(Long sendIdx);
|
Optional<TSendEntity> findForUpdate(Long sendIdx);
|
||||||
@@ -35,14 +51,17 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
|||||||
String getBulkSendKey();
|
String getBulkSendKey();
|
||||||
Long getCanceledCount();
|
Long getCanceledCount();
|
||||||
Long getTargetCount();
|
Long getTargetCount();
|
||||||
|
Long getCancelableCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query("select s.bulkSendKey as bulkSendKey, "
|
@Query("select s.bulkSendKey as bulkSendKey, "
|
||||||
+ "sum(case when s.sendStatus = 8 then 1L else 0L end) as canceledCount, "
|
+ "sum(case when s.sendStatus = 8 then 1L else 0L end) as canceledCount, "
|
||||||
+ "count(s) as targetCount "
|
+ "count(s) as targetCount, "
|
||||||
|
+ "sum(case when " + CANCELABLE_CONDITION + " then 1L else 0L end) as cancelableCount "
|
||||||
+ "from TSendEntity s where s.bulkSendKey in :bulkSendKeys "
|
+ "from TSendEntity s where s.bulkSendKey in :bulkSendKeys "
|
||||||
+ "group by s.bulkSendKey")
|
+ "group by s.bulkSendKey")
|
||||||
List<CancellationCount> countCanceledByBulkSendKeys(List<String> bulkSendKeys);
|
List<CancellationCount> countCanceledByBulkSendKeys(List<String> bulkSendKeys,
|
||||||
|
short emailSendType, short emailStandbyCode, List<Short> bizSendTypes);
|
||||||
|
|
||||||
Optional<TSendEntity> findByCmid(String cmid);
|
Optional<TSendEntity> findByCmid(String cmid);
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import java.util.Base64;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -69,6 +70,7 @@ public class ReportService {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public List<SendResultInfoDto> getSendResultList(String sid, String prjctCd, String reqstSvc,
|
public List<SendResultInfoDto> getSendResultList(String sid, String prjctCd, String reqstSvc,
|
||||||
ChannelType channelTy) {
|
ChannelType channelTy) {
|
||||||
List<Short> sendTyList = getSendTypeCodeList(channelTy);
|
List<Short> sendTyList = getSendTypeCodeList(channelTy);
|
||||||
@@ -80,9 +82,11 @@ public class ReportService {
|
|||||||
: sendRepository.findBySidAndPrjctCdAndReqstSvcAndSendTyInOrderBySendDtDescSendIdxDesc(
|
: sendRepository.findBySidAndPrjctCdAndReqstSvcAndSendTyInOrderBySendDtDescSendIdxDesc(
|
||||||
sid, prjctCd, reqstSvc, sendTyList);
|
sid, prjctCd, reqstSvc, sendTyList);
|
||||||
|
|
||||||
|
Set<Long> cancelableIds = findCancelableSendIds(sendList);
|
||||||
return sendList
|
return sendList
|
||||||
.stream()
|
.stream()
|
||||||
.map(entity -> SendResultInfoDto.from(entity, resultCodeList))
|
.map(entity -> SendResultInfoDto.from(entity, resultCodeList,
|
||||||
|
cancelableIds.contains(entity.getSendIdx())))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,7 +107,8 @@ public class ReportService {
|
|||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
Map<String, SendRepository.CancellationCount> counts = sendRepository.countCanceledByBulkSendKeys(
|
Map<String, SendRepository.CancellationCount> counts = sendRepository.countCanceledByBulkSendKeys(
|
||||||
bulks.stream().map(TBulkSendEntity::getBulkSendKey).toList()).stream()
|
bulks.stream().map(TBulkSendEntity::getBulkSendKey).toList(),
|
||||||
|
SendType.EMAIL.getCode(), NotihubConst.EMAIL_STANDBY, bizSendTypes()).stream()
|
||||||
.collect(Collectors.toMap(SendRepository.CancellationCount::getBulkSendKey,
|
.collect(Collectors.toMap(SendRepository.CancellationCount::getBulkSendKey,
|
||||||
Function.identity()));
|
Function.identity()));
|
||||||
return bulks.stream().map(bulk -> {
|
return bulks.stream().map(bulk -> {
|
||||||
@@ -111,21 +116,40 @@ public class ReportService {
|
|||||||
SendRepository.CancellationCount count = counts.get(bulk.getBulkSendKey());
|
SendRepository.CancellationCount count = counts.get(bulk.getBulkSendKey());
|
||||||
dto.applyCanceledCount(count == null ? 0 : count.getCanceledCount(),
|
dto.applyCanceledCount(count == null ? 0 : count.getCanceledCount(),
|
||||||
count == null ? 0 : count.getTargetCount());
|
count == null ? 0 : count.getTargetCount());
|
||||||
|
dto.setCancelable(Boolean.TRUE.equals(bulk.getResve())
|
||||||
|
&& count != null && count.getCancelableCount() > 0);
|
||||||
return dto;
|
return dto;
|
||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public PageResponseDto<SendResultInfoDto> getBulkSendDetail(String bulkSendKey,
|
public PageResponseDto<SendResultInfoDto> getBulkSendDetail(String bulkSendKey,
|
||||||
PageRequestDto pageReq) {
|
PageRequestDto pageReq) {
|
||||||
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
||||||
|
|
||||||
Pageable pageable = Pageables.of(pageReq, TSendEntity.class);
|
Pageable pageable = Pageables.of(pageReq, TSendEntity.class);
|
||||||
Page<SendResultInfoDto> page = sendRepository.findByBulkSendKey(bulkSendKey, pageable)
|
Page<TSendEntity> sends = sendRepository.findByBulkSendKey(bulkSendKey, pageable);
|
||||||
.map(entity -> SendResultInfoDto.from(entity, resultCodeList));
|
Set<Long> cancelableIds = findCancelableSendIds(sends.getContent());
|
||||||
|
Page<SendResultInfoDto> page = sends.map(entity -> SendResultInfoDto.from(
|
||||||
|
entity, resultCodeList, cancelableIds.contains(entity.getSendIdx())));
|
||||||
|
|
||||||
return PageResponseDto.from(page);
|
return PageResponseDto.from(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<Long> findCancelableSendIds(List<TSendEntity> sends) {
|
||||||
|
if (sends.isEmpty()) {
|
||||||
|
return Set.of();
|
||||||
|
}
|
||||||
|
return Set.copyOf(sendRepository.findCancelableSendIds(
|
||||||
|
sends.stream().map(TSendEntity::getSendIdx).toList(), SendType.EMAIL.getCode(),
|
||||||
|
NotihubConst.EMAIL_STANDBY, bizSendTypes()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Short> bizSendTypes() {
|
||||||
|
return Stream.concat(NotihubConst.SMS_TYPE_CODE_LIST.stream(),
|
||||||
|
NotihubConst.KKO_TYPE_CODE_LIST.stream()).toList();
|
||||||
|
}
|
||||||
|
|
||||||
public ReportExcelResponseDto getBulkSendDetailExcel(String bulkSendKey) {
|
public ReportExcelResponseDto getBulkSendDetailExcel(String bulkSendKey) {
|
||||||
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user