260626_02_ENH: 발송 축약 결과 조회 구현, admin용 api 보이고 사용 가능하게 수정
This commit is contained in:
@@ -8,6 +8,8 @@ import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||
import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
|
||||
import com.kri.notihub.server.dto.report.SendInfoDto;
|
||||
import com.kri.notihub.server.dto.report.SendResultSummaryRequestDto;
|
||||
import com.kri.notihub.server.dto.report.SendResultSummaryResponseDto;
|
||||
import com.kri.notihub.server.service.ReportService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -56,4 +58,12 @@ public class ReportController {
|
||||
public ReportExcelResponseDto getBulkSendDetailExcel(@PathVariable String bulkSendKey) {
|
||||
return reportService.getBulkSendDetailExcel(bulkSendKey);
|
||||
}
|
||||
|
||||
@Operation(summary = "발송 결과 축약 조회")
|
||||
@PostMapping("/send-result-summary")
|
||||
public List<SendResultSummaryResponseDto> getSendResultSummary(
|
||||
@Valid @RequestBody SendResultSummaryRequestDto req
|
||||
) {
|
||||
return reportService.getSendResultSummary(req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import lombok.Setter;
|
||||
public class ReportExcelResponseDto {
|
||||
|
||||
@Schema(description = "프론트가 저장용으로 쓸 파일명")
|
||||
private String errorFileName;
|
||||
private String fileName;
|
||||
|
||||
@Schema(description = "에러 엑셀 파일 (xlsx)의 Base64 문자열 (hasErrorFile == true일 때만 세팅)")
|
||||
private String errorFileBase64;
|
||||
@Schema(description = "엑셀 파일 (xlsx)의 Base64 문자열 (hasErrorFile == true일 때만 세팅)")
|
||||
private String fileBase64;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.kri.notihub.server.dto.report;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "발송 축약 결과")
|
||||
public class SendResultSummaryDto {
|
||||
|
||||
@Schema(description = "발송 타입 코드")
|
||||
private Short sendTy;
|
||||
|
||||
@Schema(description = "발송 사")
|
||||
private Short sendCorp;
|
||||
|
||||
@Schema(description = "발송 성공 카운트")
|
||||
private Long successCount;
|
||||
|
||||
@Schema(description = "발송 실패 카운트")
|
||||
private Long failCount;
|
||||
|
||||
@Schema(description = "대기중 카운트")
|
||||
private Long standByCount;
|
||||
|
||||
@Schema(description = "전체 카운트")
|
||||
private Long totalCount;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.kri.notihub.server.dto.report;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "발송 축약 결과 요청")
|
||||
public class SendResultSummaryRequestDto {
|
||||
|
||||
@Schema(description = "대량발송 키")
|
||||
private String bulkSendKey;
|
||||
|
||||
@Schema(description = "인트라넷 프로젝트 코드")
|
||||
private String itrntPrjctCd;
|
||||
|
||||
@Schema(description = "요청 서비스")
|
||||
private String reqstSvc;
|
||||
|
||||
@Schema(description = "프로젝트 코드")
|
||||
private String prjctCd;
|
||||
|
||||
@Schema(description = "발송일시 조회 시작")
|
||||
private LocalDateTime sendStartDt;
|
||||
|
||||
@Schema(description = "발송일시 조회 종료")
|
||||
private LocalDateTime sendEndDt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.kri.notihub.server.dto.report;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "발송 축약 결과 응답")
|
||||
public class SendResultSummaryResponseDto extends SendResultSummaryDto {
|
||||
|
||||
@Schema(description = "발송 단가")
|
||||
private BigDecimal price;
|
||||
|
||||
@Schema(description = "발송 비용")
|
||||
private BigDecimal cost;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kri.notihub.server.persistence.repository;
|
||||
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.dto.report.SendResultSummaryDto;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -8,6 +9,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
||||
|
||||
@@ -64,4 +66,34 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
||||
);
|
||||
|
||||
Page<TSendEntity> findByBulkSendKey(String bulkSendKey, Pageable pageable);
|
||||
}
|
||||
|
||||
@Query("""
|
||||
select new com.kri.notihub.server.dto.report.SendResultSummaryDto(
|
||||
s.sendTy,
|
||||
s.sendCorp,
|
||||
sum(case when src.resultCodeType = 1 then 1L else 0L end),
|
||||
sum(case when src.resultCodeType = 0 then 1L else 0L end),
|
||||
sum(case when src.resultCodeType = 9 then 1L else 0L end),
|
||||
count(s)
|
||||
)
|
||||
from TSendEntity s
|
||||
join TSendResultCodeEntity src
|
||||
on s.sendCorp = src.id.sendCorp
|
||||
and s.resultCode = src.id.resultCode
|
||||
where (:bulkSendKey is null or s.bulkSendKey = :bulkSendKey)
|
||||
and (:itrntPrjctCd is null or s.itrntPrjctCd = :itrntPrjctCd)
|
||||
and (:reqstSvc is null or s.reqstSvc = :reqstSvc)
|
||||
and (:prjctCd is null or s.prjctCd = :prjctCd)
|
||||
and (:sendStartDt is null or s.sendDt >= :sendStartDt)
|
||||
and (:sendEndDt is null or s.sendDt <= :sendEndDt)
|
||||
group by s.sendTy, s.sendCorp
|
||||
""")
|
||||
List<SendResultSummaryDto> findSendResultSummary(
|
||||
@Param("bulkSendKey") String bulkSendKey,
|
||||
@Param("itrntPrjctCd") String itrntPrjctCd,
|
||||
@Param("reqstSvc") String reqstSvc,
|
||||
@Param("prjctCd") String prjctCd,
|
||||
@Param("sendStartDt") LocalDateTime sendStartDt,
|
||||
@Param("sendEndDt") LocalDateTime sendEndDt
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.kri.notihub.server.persistence.repository;
|
||||
|
||||
import com.kri.notihub.server.persistence.entity.TUnitPriceEntity;
|
||||
import java.util.List;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UnitPriceRepository extends JpaRepository<TUnitPriceEntity, Integer> {
|
||||
|
||||
List<TUnitPriceEntity> findByUseTrue();
|
||||
}
|
||||
@@ -10,25 +10,37 @@ import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||
import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
|
||||
import com.kri.notihub.server.dto.report.SendInfoDto;
|
||||
import com.kri.notihub.server.dto.report.SendResultSummaryDto;
|
||||
import com.kri.notihub.server.dto.report.SendResultSummaryRequestDto;
|
||||
import com.kri.notihub.server.dto.report.SendResultSummaryResponseDto;
|
||||
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendResultCodeEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TUnitPriceEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendResultCodeRepository;
|
||||
import com.kri.notihub.server.persistence.repository.UnitPriceRepository;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Base64;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@@ -37,6 +49,7 @@ public class ReportService {
|
||||
private final SendResultCodeRepository sendResultCodeRepository;
|
||||
private final BulkSendRepository bulkSendRepository;
|
||||
private final SendRepository sendRepository;
|
||||
private final UnitPriceRepository unitPriceRepository;
|
||||
|
||||
public List<BulkSendInfoDto> getBulkSendList(SendType sendTy, String reqstSvc, String prjctCd,
|
||||
String regCmpn) {
|
||||
@@ -120,8 +133,94 @@ public class ReportService {
|
||||
String base64 = new String(bos.toByteArray(), StandardCharsets.UTF_8);
|
||||
|
||||
return ReportExcelResponseDto.builder()
|
||||
.errorFileName(fileName)
|
||||
.errorFileBase64(base64)
|
||||
.fileName(fileName)
|
||||
.fileBase64(base64)
|
||||
.build();
|
||||
}
|
||||
|
||||
public List<SendResultSummaryResponseDto> getSendResultSummary(
|
||||
SendResultSummaryRequestDto req) {
|
||||
SendResultSummaryRequestDto condition = req != null ? req : new SendResultSummaryRequestDto();
|
||||
|
||||
List<SendResultSummaryDto> summaries = sendRepository.findSendResultSummary(
|
||||
normalize(condition.getBulkSendKey()),
|
||||
normalize(condition.getItrntPrjctCd()),
|
||||
normalize(condition.getReqstSvc()),
|
||||
normalize(condition.getPrjctCd()),
|
||||
condition.getSendStartDt(),
|
||||
condition.getSendEndDt()
|
||||
);
|
||||
|
||||
Map<SendPriceKey, TUnitPriceEntity> unitPriceMap = unitPriceRepository.findByUseTrue()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
price -> new SendPriceKey(price.getSendTy(), price.getSendCorp()),
|
||||
Function.identity(),
|
||||
(left, right) -> left
|
||||
));
|
||||
|
||||
Map<SendPriceKey, SendResultSummaryDto> summaryMap = summaries.stream()
|
||||
.collect(Collectors.toMap(
|
||||
summary -> new SendPriceKey(summary.getSendTy(), summary.getSendCorp()),
|
||||
Function.identity(),
|
||||
this::mergeSummary
|
||||
));
|
||||
|
||||
return Stream.concat(unitPriceMap.keySet().stream(), summaryMap.keySet().stream())
|
||||
.collect(Collectors.toSet())
|
||||
.stream()
|
||||
.sorted(Comparator
|
||||
.comparing(SendPriceKey::sendTy, Comparator.nullsLast(Comparator.naturalOrder()))
|
||||
.thenComparing(SendPriceKey::sendCorp, Comparator.nullsLast(Comparator.naturalOrder())))
|
||||
.map(key -> toSendResultSummaryResponse(key, summaryMap.get(key), unitPriceMap.get(key)))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private SendResultSummaryResponseDto toSendResultSummaryResponse(
|
||||
SendPriceKey key,
|
||||
SendResultSummaryDto summary,
|
||||
TUnitPriceEntity unitPrice
|
||||
) {
|
||||
BigDecimal price = unitPrice != null
|
||||
? BigDecimal.valueOf(unitPrice.getPrice())
|
||||
: BigDecimal.ZERO;
|
||||
Long successCount = summary != null ? summary.getSuccessCount() : 0L;
|
||||
Long failCount = summary != null ? summary.getFailCount() : 0L;
|
||||
Long standByCount = summary != null ? summary.getStandByCount() : 0L;
|
||||
Long totalCount = summary != null ? summary.getTotalCount() : 0L;
|
||||
BigDecimal cost = price.multiply(BigDecimal.valueOf(nullToZero(successCount)));
|
||||
|
||||
return SendResultSummaryResponseDto.builder()
|
||||
.sendTy(key.sendTy())
|
||||
.sendCorp(key.sendCorp())
|
||||
.successCount(successCount)
|
||||
.failCount(failCount)
|
||||
.standByCount(standByCount)
|
||||
.totalCount(totalCount)
|
||||
.price(price)
|
||||
.cost(cost)
|
||||
.build();
|
||||
}
|
||||
|
||||
private SendResultSummaryDto mergeSummary(SendResultSummaryDto left, SendResultSummaryDto right) {
|
||||
return SendResultSummaryDto.builder()
|
||||
.sendTy(left.getSendTy())
|
||||
.sendCorp(left.getSendCorp())
|
||||
.successCount(nullToZero(left.getSuccessCount()) + nullToZero(right.getSuccessCount()))
|
||||
.failCount(nullToZero(left.getFailCount()) + nullToZero(right.getFailCount()))
|
||||
.standByCount(nullToZero(left.getStandByCount()) + nullToZero(right.getStandByCount()))
|
||||
.totalCount(nullToZero(left.getTotalCount()) + nullToZero(right.getTotalCount()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private String normalize(String value) {
|
||||
return StringUtils.hasText(value) ? value : null;
|
||||
}
|
||||
|
||||
private long nullToZero(Long value) {
|
||||
return value != null ? value : 0L;
|
||||
}
|
||||
|
||||
private record SendPriceKey(Short sendTy, Short sendCorp) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user