261102_01_ENH: 알림톡 발신 프로필 목록 조회 추가 및 템플릿 API senderKey 필수 검증 적용
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
package com.kri.notihub.server.dto.report;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 요청 서비스 · 인트라넷 프로젝트 · 발송 타입별 발송 비용 집계 (조회 전용 projection)
|
||||||
|
*/
|
||||||
|
public record SendCostByTypeDto(
|
||||||
|
String reqstSvc,
|
||||||
|
String itrntPrjctCd,
|
||||||
|
Short sendTy,
|
||||||
|
Long sendCnt,
|
||||||
|
BigDecimal totalPrice
|
||||||
|
) {
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.kri.notihub.server.dto.report;
|
package com.kri.notihub.server.dto.report;
|
||||||
|
|
||||||
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.common.external.intranet.dto.IntranetProjectBaseInfoDto;
|
import com.kri.notihub.server.common.external.intranet.dto.IntranetProjectBaseInfoDto;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -14,7 +15,7 @@ import lombok.Setter;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Schema(description = "인트라넷 프로젝트 정보 포함 발송 비용 요약")
|
@Schema(description = "인트라넷 프로젝트 정보 포함 발송 비용 요약 (발송 타입별 컬럼)")
|
||||||
public class SendCostSummaryWithItrntPrjctDto {
|
public class SendCostSummaryWithItrntPrjctDto {
|
||||||
|
|
||||||
@Schema(description = "요청 서비스")
|
@Schema(description = "요청 서비스")
|
||||||
@@ -23,38 +24,100 @@ public class SendCostSummaryWithItrntPrjctDto {
|
|||||||
@Schema(description = "인트라넷 프로젝트 코드")
|
@Schema(description = "인트라넷 프로젝트 코드")
|
||||||
private String itrntPrjctCd;
|
private String itrntPrjctCd;
|
||||||
|
|
||||||
@Schema(description = "발송 타입")
|
@Schema(description = "EMAIL 발송 건수")
|
||||||
private Short sendTy;
|
@Builder.Default
|
||||||
|
private Long emailCnt = 0L;
|
||||||
|
|
||||||
@Schema(description = "발송 업체")
|
@Schema(description = "SMS 발송 건수")
|
||||||
private Short sendCorp;
|
@Builder.Default
|
||||||
|
private Long smsCnt = 0L;
|
||||||
|
|
||||||
@Schema(description = "발송 건수")
|
@Schema(description = "LMS 발송 건수")
|
||||||
private Long sendCnt;
|
@Builder.Default
|
||||||
|
private Long lmsCnt = 0L;
|
||||||
|
|
||||||
@Schema(description = "단가")
|
@Schema(description = "MMS 발송 건수")
|
||||||
private BigDecimal unitPrice;
|
@Builder.Default
|
||||||
|
private Long mmsCnt = 0L;
|
||||||
|
|
||||||
@Schema(description = "총 비용")
|
@Schema(description = "알림톡 발송 건수")
|
||||||
private BigDecimal totalPrice;
|
@Builder.Default
|
||||||
|
private Long kkoAtCnt = 0L;
|
||||||
|
|
||||||
|
@Schema(description = "EMAIL 단가")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal emailUnitPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "SMS 단가")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal smsUnitPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "LMS 단가")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal lmsUnitPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "MMS 단가")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal mmsUnitPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "알림톡 단가")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal kkoAtUnitPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "EMAIL 비용")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal emailTotalPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "SMS 비용")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal smsTotalPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "LMS 비용")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal lmsTotalPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "MMS 비용")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal mmsTotalPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
@Schema(description = "알림톡 비용")
|
||||||
|
@Builder.Default
|
||||||
|
private BigDecimal kkoAtTotalPrice = BigDecimal.ZERO;
|
||||||
|
|
||||||
@Schema(description = "인트라넷 프로젝트 정보")
|
@Schema(description = "인트라넷 프로젝트 정보")
|
||||||
private IntranetProjectBaseInfoDto itrntPrjctInfo;
|
private IntranetProjectBaseInfoDto itrntPrjctInfo;
|
||||||
|
|
||||||
public SendCostSummaryWithItrntPrjctDto(
|
/**
|
||||||
String reqstSvc,
|
* 발송 타입에 해당하는 건수 · 단가 · 비용 컬럼을 설정한다.
|
||||||
String itrntPrjctCd,
|
*/
|
||||||
Short sendTy,
|
public void applySendType(SendType sendType, long sendCnt, BigDecimal unitPrice,
|
||||||
Short sendCorp,
|
BigDecimal totalPrice) {
|
||||||
Long sendCnt,
|
switch (sendType) {
|
||||||
BigDecimal unitPrice
|
case EMAIL -> {
|
||||||
) {
|
this.emailCnt = sendCnt;
|
||||||
this.reqstSvc = reqstSvc;
|
this.emailUnitPrice = unitPrice;
|
||||||
this.itrntPrjctCd = itrntPrjctCd;
|
this.emailTotalPrice = totalPrice;
|
||||||
this.sendTy = sendTy;
|
}
|
||||||
this.sendCorp = sendCorp;
|
case SMS -> {
|
||||||
this.sendCnt = sendCnt;
|
this.smsCnt = sendCnt;
|
||||||
this.unitPrice = unitPrice != null ? unitPrice : BigDecimal.ZERO;
|
this.smsUnitPrice = unitPrice;
|
||||||
this.totalPrice = this.unitPrice.multiply(BigDecimal.valueOf(sendCnt != null ? sendCnt : 0L));
|
this.smsTotalPrice = totalPrice;
|
||||||
|
}
|
||||||
|
case LMS -> {
|
||||||
|
this.lmsCnt = sendCnt;
|
||||||
|
this.lmsUnitPrice = unitPrice;
|
||||||
|
this.lmsTotalPrice = totalPrice;
|
||||||
|
}
|
||||||
|
case MMS -> {
|
||||||
|
this.mmsCnt = sendCnt;
|
||||||
|
this.mmsUnitPrice = unitPrice;
|
||||||
|
this.mmsTotalPrice = totalPrice;
|
||||||
|
}
|
||||||
|
case KKO_AT -> {
|
||||||
|
this.kkoAtCnt = sendCnt;
|
||||||
|
this.kkoAtUnitPrice = unitPrice;
|
||||||
|
this.kkoAtTotalPrice = totalPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.kri.notihub.server.dto.report;
|
package com.kri.notihub.server.dto.report;
|
||||||
|
|
||||||
import com.kri.common.feature.excel.ExcelColumn;
|
import com.kri.common.feature.excel.ExcelColumn;
|
||||||
import com.kri.notihub.server.common.enums.SendCorpType;
|
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
|
||||||
import com.kri.notihub.server.common.external.intranet.dto.IntranetProjectBaseInfoDto;
|
import com.kri.notihub.server.common.external.intranet.dto.IntranetProjectBaseInfoDto;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -21,20 +19,50 @@ public record SendCostSummaryWithItrntPrjctExcelDto(
|
|||||||
@ExcelColumn(header = "연구팀 명", order = 3)
|
@ExcelColumn(header = "연구팀 명", order = 3)
|
||||||
String researchTeamName,
|
String researchTeamName,
|
||||||
|
|
||||||
@ExcelColumn(header = "발송 타입", order = 4)
|
@ExcelColumn(header = "EMAIL 건수", order = 4)
|
||||||
String sendTy,
|
Long emailCnt,
|
||||||
|
|
||||||
@ExcelColumn(header = "발송 업체", order = 5)
|
@ExcelColumn(header = "SMS 건수", order = 5)
|
||||||
String sendCorp,
|
Long smsCnt,
|
||||||
|
|
||||||
@ExcelColumn(header = "발송 건수", order = 6)
|
@ExcelColumn(header = "LMS 건수", order = 6)
|
||||||
Long sendCnt,
|
Long lmsCnt,
|
||||||
|
|
||||||
@ExcelColumn(header = "단가", order = 7)
|
@ExcelColumn(header = "MMS 건수", order = 7)
|
||||||
BigDecimal unitPrice,
|
Long mmsCnt,
|
||||||
|
|
||||||
@ExcelColumn(header = "총 비용", order = 8)
|
@ExcelColumn(header = "알림톡 건수", order = 8)
|
||||||
BigDecimal totalPrice
|
Long kkoAtCnt,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "EMAIL 단가", order = 9)
|
||||||
|
BigDecimal emailUnitPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "SMS 단가", order = 10)
|
||||||
|
BigDecimal smsUnitPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "LMS 단가", order = 11)
|
||||||
|
BigDecimal lmsUnitPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "MMS 단가", order = 12)
|
||||||
|
BigDecimal mmsUnitPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "알림톡 단가", order = 13)
|
||||||
|
BigDecimal kkoAtUnitPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "EMAIL 비용", order = 14)
|
||||||
|
BigDecimal emailTotalPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "SMS 비용", order = 15)
|
||||||
|
BigDecimal smsTotalPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "LMS 비용", order = 16)
|
||||||
|
BigDecimal lmsTotalPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "MMS 비용", order = 17)
|
||||||
|
BigDecimal mmsTotalPrice,
|
||||||
|
|
||||||
|
@ExcelColumn(header = "알림톡 비용", order = 18)
|
||||||
|
BigDecimal kkoAtTotalPrice
|
||||||
) {
|
) {
|
||||||
public static SendCostSummaryWithItrntPrjctExcelDto from(
|
public static SendCostSummaryWithItrntPrjctExcelDto from(
|
||||||
SendCostSummaryWithItrntPrjctDto source) {
|
SendCostSummaryWithItrntPrjctDto source) {
|
||||||
@@ -49,33 +77,21 @@ public record SendCostSummaryWithItrntPrjctExcelDto(
|
|||||||
.itrntPrjctCd(source.getItrntPrjctCd())
|
.itrntPrjctCd(source.getItrntPrjctCd())
|
||||||
.title(projectInfo != null ? projectInfo.title() : null)
|
.title(projectInfo != null ? projectInfo.title() : null)
|
||||||
.researchTeamName(projectInfo != null ? projectInfo.researchTeamName() : null)
|
.researchTeamName(projectInfo != null ? projectInfo.researchTeamName() : null)
|
||||||
.sendTy(getSendTypeLabel(source.getSendTy()))
|
.emailCnt(source.getEmailCnt())
|
||||||
.sendCorp(getSendCorpLabel(source.getSendCorp()))
|
.smsCnt(source.getSmsCnt())
|
||||||
.sendCnt(source.getSendCnt())
|
.lmsCnt(source.getLmsCnt())
|
||||||
.unitPrice(source.getUnitPrice())
|
.mmsCnt(source.getMmsCnt())
|
||||||
.totalPrice(source.getTotalPrice())
|
.kkoAtCnt(source.getKkoAtCnt())
|
||||||
|
.emailUnitPrice(source.getEmailUnitPrice())
|
||||||
|
.smsUnitPrice(source.getSmsUnitPrice())
|
||||||
|
.lmsUnitPrice(source.getLmsUnitPrice())
|
||||||
|
.mmsUnitPrice(source.getMmsUnitPrice())
|
||||||
|
.kkoAtUnitPrice(source.getKkoAtUnitPrice())
|
||||||
|
.emailTotalPrice(source.getEmailTotalPrice())
|
||||||
|
.smsTotalPrice(source.getSmsTotalPrice())
|
||||||
|
.lmsTotalPrice(source.getLmsTotalPrice())
|
||||||
|
.mmsTotalPrice(source.getMmsTotalPrice())
|
||||||
|
.kkoAtTotalPrice(source.getKkoAtTotalPrice())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSendTypeLabel(Short code) {
|
|
||||||
if (code == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return SendType.fromCode(code).name();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return code.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getSendCorpLabel(Short code) {
|
|
||||||
if (code == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return SendCorpType.fromCode(code).name();
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return code.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.persistence.repository;
|
|||||||
|
|
||||||
import com.kri.notihub.server.common.enums.ChannelType;
|
import com.kri.notihub.server.common.enums.ChannelType;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.dto.report.SendCostSummaryWithItrntPrjctDto;
|
import com.kri.notihub.server.dto.report.SendCostByTypeDto;
|
||||||
import com.kri.notihub.server.dto.report.SendResultLastWithSidDto;
|
import com.kri.notihub.server.dto.report.SendResultLastWithSidDto;
|
||||||
import com.kri.notihub.server.dto.report.SendResultSummaryDto;
|
import com.kri.notihub.server.dto.report.SendResultSummaryDto;
|
||||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
@@ -270,13 +270,12 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
select new com.kri.notihub.server.dto.report.SendCostSummaryWithItrntPrjctDto(
|
select new com.kri.notihub.server.dto.report.SendCostByTypeDto(
|
||||||
s.reqstSvc,
|
s.reqstSvc,
|
||||||
s.itrntPrjctCd,
|
s.itrntPrjctCd,
|
||||||
s.sendTy,
|
s.sendTy,
|
||||||
s.sendCorp,
|
|
||||||
count(s),
|
count(s),
|
||||||
up.price
|
sum(up.price)
|
||||||
)
|
)
|
||||||
from TSendEntity s
|
from TSendEntity s
|
||||||
left join TUnitPriceEntity up
|
left join TUnitPriceEntity up
|
||||||
@@ -286,10 +285,10 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
|||||||
where s.sendStatus = 1
|
where s.sendStatus = 1
|
||||||
and s.sendDt >= :startDt
|
and s.sendDt >= :startDt
|
||||||
and s.sendDt < :endDt
|
and s.sendDt < :endDt
|
||||||
group by s.reqstSvc, s.itrntPrjctCd, s.sendTy, s.sendCorp, up.price
|
group by s.reqstSvc, s.itrntPrjctCd, s.sendTy
|
||||||
order by s.reqstSvc, s.itrntPrjctCd, s.sendTy, s.sendCorp
|
order by s.reqstSvc, s.itrntPrjctCd, s.sendTy
|
||||||
""")
|
""")
|
||||||
List<SendCostSummaryWithItrntPrjctDto> findSendCostSummaryWithItrntPrjct(
|
List<SendCostByTypeDto> findSendCostSummaryWithItrntPrjct(
|
||||||
@Param("startDt") LocalDateTime startDt,
|
@Param("startDt") LocalDateTime startDt,
|
||||||
@Param("endDt") LocalDateTime endDt
|
@Param("endDt") LocalDateTime endDt
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ public class EmailResultPoller {
|
|||||||
private volatile boolean running = true;
|
private volatile boolean running = true;
|
||||||
private Thread worker;
|
private Thread worker;
|
||||||
|
|
||||||
|
// false면 워커 스레드 · 기동 시 복구 · 큐 등록을 모두 하지 않는다 (local 등에서 Pringo 조회/DB 갱신 방지)
|
||||||
|
@Value("${kri.email.result-poll.enabled:true}")
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
@Value("${kri.email.result-poll.initial-delay-ms:10000}")
|
@Value("${kri.email.result-poll.initial-delay-ms:10000}")
|
||||||
private long initialDelayMs;
|
private long initialDelayMs;
|
||||||
|
|
||||||
@@ -62,7 +66,7 @@ public class EmailResultPoller {
|
|||||||
private int recoverPageSize;
|
private int recoverPageSize;
|
||||||
|
|
||||||
public void enqueue(String returnKey) {
|
public void enqueue(String returnKey) {
|
||||||
if (returnKey == null || returnKey.isBlank()) {
|
if (!enabled || returnKey == null || returnKey.isBlank()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
enqueueInternal(returnKey.trim(), initialDelayMs, 0);
|
enqueueInternal(returnKey.trim(), initialDelayMs, 0);
|
||||||
@@ -104,6 +108,9 @@ public class EmailResultPoller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enqueueRecoverableEmailResults(long delayMs) {
|
private void enqueueRecoverableEmailResults(long delayMs) {
|
||||||
|
if (!enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
LocalDateTime from = LocalDateTime.now().minusDays(Math.max(1, recoverDays));
|
LocalDateTime from = LocalDateTime.now().minusDays(Math.max(1, recoverDays));
|
||||||
Pageable pageable = PageRequest.of(0, Math.max(100, recoverPageSize));
|
Pageable pageable = PageRequest.of(0, Math.max(100, recoverPageSize));
|
||||||
@@ -136,6 +143,10 @@ public class EmailResultPoller {
|
|||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void start() {
|
public void start() {
|
||||||
|
if (!enabled) {
|
||||||
|
log.info("EmailResultPoller disabled (kri.email.result-poll.enabled=false)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
worker = new Thread(() -> {
|
worker = new Thread(() -> {
|
||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.kri.notihub.server.common.external.intranet.IntranetApiClient;
|
|||||||
import com.kri.notihub.server.common.external.intranet.dto.IntranetProjectBaseInfoDto;
|
import com.kri.notihub.server.common.external.intranet.dto.IntranetProjectBaseInfoDto;
|
||||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||||
import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
|
import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
|
||||||
|
import com.kri.notihub.server.dto.report.SendCostByTypeDto;
|
||||||
import com.kri.notihub.server.dto.report.SendCostSummaryRequestDto;
|
import com.kri.notihub.server.dto.report.SendCostSummaryRequestDto;
|
||||||
import com.kri.notihub.server.dto.report.SendCostSummaryWithItrntPrjctDto;
|
import com.kri.notihub.server.dto.report.SendCostSummaryWithItrntPrjctDto;
|
||||||
import com.kri.notihub.server.dto.report.SendCostSummaryWithItrntPrjctExcelDto;
|
import com.kri.notihub.server.dto.report.SendCostSummaryWithItrntPrjctExcelDto;
|
||||||
@@ -33,14 +34,20 @@ import com.kri.notihub.server.persistence.repository.UnitPriceRepository;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
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;
|
||||||
@@ -256,12 +263,14 @@ public class ReportService {
|
|||||||
LocalDateTime startDt = condition.startDt().atStartOfDay();
|
LocalDateTime startDt = condition.startDt().atStartOfDay();
|
||||||
LocalDateTime endDt = condition.endDt().plusDays(1).atStartOfDay();
|
LocalDateTime endDt = condition.endDt().plusDays(1).atStartOfDay();
|
||||||
|
|
||||||
List<SendCostSummaryWithItrntPrjctDto> summaries =
|
List<SendCostByTypeDto> costsByType =
|
||||||
sendRepository.findSendCostSummaryWithItrntPrjct(
|
sendRepository.findSendCostSummaryWithItrntPrjct(
|
||||||
startDt,
|
startDt,
|
||||||
endDt
|
endDt
|
||||||
);
|
);
|
||||||
|
|
||||||
|
List<SendCostSummaryWithItrntPrjctDto> summaries = pivotSendCostBySendType(costsByType);
|
||||||
|
|
||||||
List<String> itrntPrjctCds = summaries.stream()
|
List<String> itrntPrjctCds = summaries.stream()
|
||||||
.map(SendCostSummaryWithItrntPrjctDto::getItrntPrjctCd)
|
.map(SendCostSummaryWithItrntPrjctDto::getItrntPrjctCd)
|
||||||
.filter(StringUtils::hasText)
|
.filter(StringUtils::hasText)
|
||||||
@@ -283,6 +292,95 @@ public class ReportService {
|
|||||||
return summaries;
|
return summaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 발송 타입별 row를 (요청 서비스, 인트라넷 프로젝트) 1 row로 합치고 발송 타입을 컬럼으로 펼친다.
|
||||||
|
* 발송 업체는 구분하지 않으며, 단가는 발송 건이 있으면 비용 ÷ 건수(가중 평균),
|
||||||
|
* 없으면 사용 중 단가가 하나뿐일 때 그 단가를 사용한다.
|
||||||
|
*/
|
||||||
|
private List<SendCostSummaryWithItrntPrjctDto> pivotSendCostBySendType(
|
||||||
|
List<SendCostByTypeDto> costsByType
|
||||||
|
) {
|
||||||
|
Map<SendType, BigDecimal> configuredUnitPriceMap = getConfiguredUnitPriceBySendType();
|
||||||
|
Map<List<String>, SendCostSummaryWithItrntPrjctDto> summaryMap = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
for (SendCostByTypeDto cost : costsByType) {
|
||||||
|
SendCostSummaryWithItrntPrjctDto summary = summaryMap.computeIfAbsent(
|
||||||
|
Arrays.asList(cost.reqstSvc(), cost.itrntPrjctCd()),
|
||||||
|
key -> SendCostSummaryWithItrntPrjctDto.builder()
|
||||||
|
.reqstSvc(cost.reqstSvc())
|
||||||
|
.itrntPrjctCd(cost.itrntPrjctCd())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
SendType sendType = toSendTypeOrNull(cost.sendTy());
|
||||||
|
if (sendType == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
long sendCnt = cost.sendCnt() != null ? cost.sendCnt() : 0L;
|
||||||
|
BigDecimal totalPrice = cost.totalPrice() != null ? cost.totalPrice() : BigDecimal.ZERO;
|
||||||
|
BigDecimal unitPrice = sendCnt > 0
|
||||||
|
? totalPrice.divide(BigDecimal.valueOf(sendCnt), totalPrice.scale(), RoundingMode.HALF_UP)
|
||||||
|
: BigDecimal.ZERO;
|
||||||
|
|
||||||
|
summary.applySendType(sendType, sendCnt, unitPrice, totalPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 발송 건이 없는 타입은 사용 중 단가로 단가 컬럼을 채운다.
|
||||||
|
summaryMap.values().forEach(summary -> configuredUnitPriceMap.forEach((sendType, price) -> {
|
||||||
|
if (getSendCnt(summary, sendType) == 0L) {
|
||||||
|
summary.applySendType(sendType, 0L, price, BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
return new ArrayList<>(summaryMap.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 발송 타입별 사용 중 단가. 업체별 단가가 서로 다르면 하나로 정할 수 없으므로 제외한다.
|
||||||
|
*/
|
||||||
|
private Map<SendType, BigDecimal> getConfiguredUnitPriceBySendType() {
|
||||||
|
Map<SendType, Set<BigDecimal>> pricesByType = new EnumMap<>(SendType.class);
|
||||||
|
for (TUnitPriceEntity price : unitPriceRepository.findByUseTrue()) {
|
||||||
|
SendType sendType = toSendTypeOrNull(price.getSendTy());
|
||||||
|
if (sendType == null || price.getPrice() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pricesByType.computeIfAbsent(sendType, key -> new TreeSet<>())
|
||||||
|
.add(price.getPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<SendType, BigDecimal> result = new EnumMap<>(SendType.class);
|
||||||
|
pricesByType.forEach((sendType, prices) -> {
|
||||||
|
if (prices.size() == 1) {
|
||||||
|
result.put(sendType, prices.iterator().next());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getSendCnt(SendCostSummaryWithItrntPrjctDto summary, SendType sendType) {
|
||||||
|
Long sendCnt = switch (sendType) {
|
||||||
|
case EMAIL -> summary.getEmailCnt();
|
||||||
|
case SMS -> summary.getSmsCnt();
|
||||||
|
case LMS -> summary.getLmsCnt();
|
||||||
|
case MMS -> summary.getMmsCnt();
|
||||||
|
case KKO_AT -> summary.getKkoAtCnt();
|
||||||
|
};
|
||||||
|
return sendCnt != null ? sendCnt : 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SendType toSendTypeOrNull(Short code) {
|
||||||
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return SendType.fromCode(code);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ReportExcelResponseDto getSendCostSummaryWithItrntPrjctExcel(
|
public ReportExcelResponseDto getSendCostSummaryWithItrntPrjctExcel(
|
||||||
SendCostSummaryRequestDto req
|
SendCostSummaryRequestDto req
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ kri:
|
|||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
scheduling:
|
scheduling:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
email:
|
||||||
|
result-poll:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ kri:
|
|||||||
batch-size: 500
|
batch-size: 500
|
||||||
sending-stale-minutes: 30
|
sending-stale-minutes: 30
|
||||||
result-poll:
|
result-poll:
|
||||||
|
enabled: true # false면 이메일 결과 조회(워커 · 기동 시 복구 · 큐 등록) 미동작
|
||||||
initial-delay-ms: 10000
|
initial-delay-ms: 10000
|
||||||
max-attempts: 0
|
max-attempts: 0
|
||||||
max-delay-ms: 30000
|
max-delay-ms: 30000
|
||||||
|
|||||||
Reference in New Issue
Block a user