260721_01_ENH: 프링고 parameter 방식의 send요청 추가, 발송시 sendTy 다시 계산하도록 수정, sid 별 조회 추가

This commit is contained in:
2026-07-21 09:58:34 +09:00
parent fb213035f3
commit 9c722e78d0
12 changed files with 197 additions and 56 deletions

View File

@@ -15,7 +15,7 @@ public final class NotihubConst {
public static final short EMAIL_RESULT_SEARCH_DELAY = 500;
public static final short EMAIL_DELAY = 500;
public static final short DELAY_MAX_MS = (short) 5_000; // 필요시 조정
public static final List<Short> SMS_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
public static final List<Short> SMS_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
public static final List<Short> KKO_TYPE_CODE_LIST = List.of(SendType.KKO_AT.getCode());
public static final List<Short> EMAIL_TYPE_CODE_LIST = List.of(SendType.EMAIL.getCode());
public static final String EMAIL_RESERVATION_PREFIX = "RESERVATION_";

View File

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kri.common.feature.http.ExternalApiClient;
import com.kri.common.feature.http.ExternalApiMultipartPart;
import com.kri.common.feature.http.ExternalApiResponse;
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnErrorDto;
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnItemDto;
@@ -12,7 +13,9 @@ import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnRequest
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnResponseDto;
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendRequestDto;
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendResponseDto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
@@ -25,23 +28,23 @@ public class PringoApiClient {
private final ExternalApiClient externalApiClient = new ExternalApiClient();
private final ObjectMapper objectMapper = new ObjectMapper();
@Value("${kri.api.pringo.url}")
private String pringoBaseUrl;
@Value("${kri.api.pringo.apiKey}")
private String apiKey;
@Value("${kri.api.pringo.template-id}")
private String templateId;
/**
* Pringo 자동메일 Json 발송 POST {pringoBaseUrl}/json-send
* Pringo automatic email JSON send POST {pringoBaseUrl}/json-send.
*/
public PringoJsonSendResponseDto jsonSend(PringoJsonSendRequestDto request) {
String url = String.format("%s/json-send", pringoBaseUrl);
// defaults 주입
request.applyDefaults(apiKey, templateId);
// 필수값 검증(Pringo 실패 케이스 사전 차단)
request.validateRequired();
Map<String, String> headers = new HashMap<>();
@@ -54,14 +57,40 @@ public class PringoApiClient {
return objectMapper.readValue(response.getBody(), PringoJsonSendResponseDto.class);
} catch (JsonProcessingException e) {
// 프로젝트 스타일에 맞게 BusinessException으로 바꿔도 됨
throw new IllegalStateException("Failed to call Pringo json-send API.", e);
}
}
/**
* 편의 메서드: vars 포함해서 바로 발송
* Pringo automatic email parameter send POST {pringoBaseUrl}/parameter-send.
*/
public PringoJsonSendResponseDto parameterSend(PringoJsonSendRequestDto request) {
String url = String.format("%s/parameter-send", pringoBaseUrl);
request.applyDefaults(apiKey, templateId);
request.validateRequired();
Map<String, String> headers = new HashMap<>();
headers.put("Accept", "application/json");
try {
List<ExternalApiMultipartPart> parts = new ArrayList<>();
addFormField(parts, "api_key", request.getApiKey());
addFormField(parts, "template_id", request.getTemplateId());
addFormField(parts, "sender", request.getSender());
addFormField(parts, "sender_name", request.getSenderName());
addFormField(parts, "recipient_name", request.getRecipientName());
addFormField(parts, "subject", request.getSubject());
addFormField(parts, "body", request.getBody());
addFormField(parts, "user_info", objectMapper.writeValueAsString(buildUserInfo(request)));
ExternalApiResponse response = externalApiClient.postMultipart(url, headers, parts);
return objectMapper.readValue(response.getBody(), PringoJsonSendResponseDto.class);
} catch (JsonProcessingException e) {
throw new IllegalStateException("Failed to call Pringo parameter-send API.", e);
}
}
public PringoJsonSendResponseDto jsonSend(
String sender,
String senderName,
@@ -88,7 +117,7 @@ public class PringoApiClient {
}
/**
* Pringo 자동메일 Json 조회 POST {pringoBaseUrl}/json-return
* Pringo automatic email JSON return POST {pringoBaseUrl}/json-return.
*/
public PringoJsonReturnResponseDto jsonReturn(PringoJsonReturnRequestDto request) {
String url = String.format("%s/json-return", pringoBaseUrl);
@@ -104,10 +133,8 @@ public class PringoApiClient {
String body = objectMapper.writeValueAsString(request);
ExternalApiResponse response = externalApiClient.post(url, headers, body);
// 응답은 항상 배열 형태
JsonNode root = objectMapper.readTree(response.getBody());
if (root == null || !root.isArray() || root.size() == 0) {
// 비정상/빈 응답 방어
return PringoJsonReturnResponseDto.builder()
.itemList(List.of())
.error(PringoJsonReturnErrorDtoBuilder.noResultFallback())
@@ -116,7 +143,6 @@ public class PringoApiClient {
JsonNode first = root.get(0);
// 실패 형태 판별: result/msg가 있으면 오류 DTO로 본다
if (first.has("result") && first.has("msg")) {
PringoJsonReturnErrorDto err = objectMapper.convertValue(first,
PringoJsonReturnErrorDto.class);
@@ -126,7 +152,6 @@ public class PringoApiClient {
.build();
}
// 성공 형태: row 리스트
List<PringoJsonReturnItemDto> items = objectMapper.convertValue(
root, new TypeReference<List<PringoJsonReturnItemDto>>() {
}
@@ -142,9 +167,6 @@ public class PringoApiClient {
}
}
/**
* 편의 메서드: returnKey만으로 조회
*/
public PringoJsonReturnResponseDto jsonReturn(String returnKey) {
PringoJsonReturnRequestDto req = PringoJsonReturnRequestDto.builder()
.returnKey(returnKey)
@@ -152,20 +174,32 @@ public class PringoApiClient {
return jsonReturn(req);
}
/**
* 편의 메서드: long도 지원
*/
public PringoJsonReturnResponseDto jsonReturn(long returnKey) {
return jsonReturn(Long.toString(returnKey));
}
// 내부 fallback builder (원하시면 별도 클래스로 분리)
private void addFormField(List<ExternalApiMultipartPart> parts, String name, String value) {
if (value == null) {
return;
}
parts.add(ExternalApiMultipartPart.formField(name, value));
}
private Map<String, Object> buildUserInfo(PringoJsonSendRequestDto request) {
Map<String, Object> recipientInfo = new LinkedHashMap<>();
recipientInfo.put("alternates", request.getVars() == null ? Map.of() : request.getVars());
Map<String, Object> userInfo = new LinkedHashMap<>();
userInfo.put(request.getRecipient(), recipientInfo);
return userInfo;
}
private static final class PringoJsonReturnErrorDtoBuilder {
static PringoJsonReturnErrorDto noResultFallback() {
PringoJsonReturnErrorDto e = new PringoJsonReturnErrorDto();
e.setResult("0");
e.setMsg("응답이 비어 있습니다.");
e.setMsg("\uC751\uB2F5\uC774 \uBE44\uC5B4 \uC788\uC2B5\uB2C8\uB2E4.");
return e;
}
}

View File

@@ -1,5 +1,7 @@
package com.kri.notihub.server.common.util;
import static com.kri.notihub.server.common.consts.NotihubConst.SMS_TYPE_CODE_LIST;
import com.kri.common.feature.util.StringUtil;
import com.kri.notihub.server.common.enums.SendType;
import com.kri.notihub.server.dto.template.TemplateBasicDto;
@@ -103,6 +105,13 @@ public final class TemplateContentSanitizer {
return text.trim();
}
public static SendType determineSms(String outTitle, String outBody){
boolean hasTitle = StringUtil.hasText(outTitle);
boolean isLargeBody = utf8ByteLength(outBody) <= SMS_MAX_BYTES_UTF8;
return hasTitle || isLargeBody ? SendType.LMS_MMS : SendType.SMS;
}
/**
* 1) tmplatTy별 치환/정리 2) (SMS/LMS_MMS) 치환 후 길이 기반으로 타입 재결정 - SMS는 제목 저장 안 함 - LMS_MMS는 본문 짧아도 제목
* 있으면 그대로 유지
@@ -134,24 +143,8 @@ public final class TemplateContentSanitizer {
if (type == SendType.KKO_AT) {
outTitle = null;
} else if (type == SendType.SMS) {
// SMS는 제목 저장 안 함
outTitle = null;
// 2) 타입 재결정
// 본문이 SMS 한도 초과면 LMS_MMS로 승격
if (utf8ByteLength(outBody) > SMS_MAX_BYTES_UTF8) {
type = SendType.LMS_MMS;
}
} else if (type == SendType.LMS_MMS) {
boolean hasTitle = StringUtil.hasText(outTitle);
// "LMS_MMS인데 본문이 짧으면 SMS로 강등"이 기본인데,
// 단, 제목이 있으면 본문이 짧아도 LMS_MMS 유지
if (!hasTitle && utf8ByteLength(outBody) <= SMS_MAX_BYTES_UTF8) {
type = SendType.SMS;
outTitle = null; // SMS는 제목 저장 안 함
}
} else if (SMS_TYPE_CODE_LIST.contains(type)) {
type = determineSms(outTitle, outBody);
}
return new SanitizedTemplate(type, outTitle, outBody);

View File

@@ -8,6 +8,7 @@ import com.kri.notihub.server.common.enums.ChannelType;
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.SendResultLastWithSidDto;
import com.kri.notihub.server.dto.report.SendResultCodeDto;
import com.kri.notihub.server.dto.report.SendResultInfoDto;
import com.kri.notihub.server.dto.report.SendResultSummaryRequestDto;
@@ -86,4 +87,15 @@ public class ReportController {
) {
return reportService.getSendResultSummary(req);
}
@Operation(summary = "리스트 별 최종 발송 결과 조회")
@PostMapping("/last/send/{channelTy}/{reqstSvc}/{prjctCd}")
public List<SendResultLastWithSidDto> getSendResultLastWithSid(
@PathVariable ChannelType channelTy,
@PathVariable String reqstSvc,
@PathVariable String prjctCd,
@RequestBody List<String> sids
) {
return reportService.getSendResultLastWithSid(channelTy, reqstSvc, prjctCd, sids);
}
}

View File

@@ -23,15 +23,24 @@ import lombok.Setter;
@Schema(description = "발송 결과 정보")
public class SendResultInfoDto {
@Size(max = 32)
@NotBlank
@Schema(description = "CMID")
private String cmid;
@Size(max = 32)
@Schema(description = "대량 발송 키")
private String bulkSendKey;
@Schema(description = "인트라넷 프로젝트 코드")
private String itrntPrjctCd;
@Schema(description = "요청 서비스")
private String reqstSvc;
@Schema(description = "프로젝트 코드")
private String prjctCd;
@Schema(description = "리스트 아이디")
private String sid;
@NotNull
@Schema(description = "발송 타입")
private Short sendTy;
@@ -116,6 +125,10 @@ public class SendResultInfoDto {
return SendResultInfoDto.builder()
.cmid(entity.getCmid())
.bulkSendKey(entity.getBulkSendKey())
.itrntPrjctCd(entity.getItrntPrjctCd())
.reqstSvc(entity.getReqstSvc())
.prjctCd(entity.getPrjctCd())
.sid(entity.getSid())
.sendTy(entity.getSendTy())
.resve(entity.isResve())
.resultCode(entity.getResultCode())

View File

@@ -0,0 +1,37 @@
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;
import lombok.experimental.SuperBuilder;
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "발송 결과 정보")
public class SendResultLastWithSidDto {
@Schema(description = "리스트 아이디")
private String sid;
@Schema(description = "마지막 결과 코드")
private Short lastResultCode;
@Schema(description = "마지막 결과 라벨")
private String lastResultLabel;
@Schema(description = "마지막 결과 표시 라벨")
private String lastResultViewLabel;
@Schema(description = "마지막 발송 일시")
private LocalDateTime lastSendDt;
@Schema(description = "총 발송 Count")
private Integer totalSendCount;
}

View File

@@ -1,5 +1,8 @@
package com.kri.notihub.server.persistence.entity;
import static com.kri.notihub.server.common.consts.NotihubConst.SMS_TYPE_CODE_LIST;
import static com.kri.notihub.server.common.util.TemplateContentSanitizer.determineSms;
import com.kri.notihub.server.common.enums.SendCorpType;
import com.kri.notihub.server.common.enums.SendType;
import com.kri.notihub.server.dto.send.DestInfoDto;
@@ -230,10 +233,15 @@ public class TSendEntity {
Short sendCorp = tmplat.getTmplatTy() == SendType.EMAIL ? SendCorpType.PRINGO.getCode()
: SendCorpType.BIZ_PPURIO.getCode();
Short sendTy = tmplat.getTmplatTy().getCode();
if(SMS_TYPE_CODE_LIST.contains(sendTy)){
sendTy = determineSms(msgTitle, msgBody).getCode();
}
return TSendEntity.builder()
.cmid(sendResult.getCmid())
.bulkSendKey(bulkSendKey)
.sendTy(tmplat.getTmplatTy().getCode())
.sendTy(sendTy)
.resve(resve)
.sendCorp(sendCorp)
.sendStatus(sendResult.getStatus().getCode())

View File

@@ -1,5 +1,8 @@
package com.kri.notihub.server.persistence.repository;
import com.kri.notihub.server.common.enums.ChannelType;
import com.kri.notihub.server.common.enums.SendType;
import com.kri.notihub.server.dto.report.SendResultLastWithSidDto;
import com.kri.notihub.server.dto.report.SendResultSummaryDto;
import com.kri.notihub.server.persistence.entity.TSendEntity;
import java.time.LocalDateTime;
@@ -131,6 +134,49 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
List<Short> sendTyList
);
@Query("""
select new com.kri.notihub.server.dto.report.SendResultLastWithSidDto(
s.sid,
s.resultCode,
src.resultLabel,
src.resultViewLabel,
s.sendDt,
cast((
select count(sc)
from TSendEntity sc
where sc.sid = s.sid
and sc.prjctCd = :prjctCd
and sc.reqstSvc = :reqstSvc
and sc.sendTy in :sendTys
) as integer)
)
from TSendEntity s
join TSendResultCodeEntity src
on s.sendCorp = src.id.sendCorp
and s.resultCode = src.id.resultCode
where s.sid in :sids
and s.prjctCd = :prjctCd
and s.reqstSvc = :reqstSvc
and s.sendTy in :sendTys
and not exists (
select 1
from TSendEntity last
where last.sid = s.sid
and last.prjctCd = :prjctCd
and last.reqstSvc = :reqstSvc
and last.sendTy in :sendTys
and last.sendIdx > s.sendIdx
)
order by s.sid desc
""")
List<SendResultLastWithSidDto> findSendResultLastWithSidBySid(
@Param("sendTys") List<Short> sendTys,
@Param("reqstSvc") String reqstSvc,
@Param("prjctCd") String prjctCd,
@Param("sids") List<String> sids
);
@Query("""
select new com.kri.notihub.server.dto.report.SendResultSummaryDto(
s.sendTy,

View File

@@ -83,8 +83,6 @@ public abstract class AbstractBizppurioSendService extends AbstractSendService {
}
if (!msgList.isEmpty()) {
//bizMsgRepository.saveAll(msgList);
//bizMsgRepository.flush();
bizMsgBulkJdbcWriter.bulkInsert(msgList);
}
}

View File

@@ -39,17 +39,6 @@ public abstract class AbstractSendService {
protected final SendRepository sendRepository;
protected final TemplateService templateService;
protected static void sleepSilently(long ms) {
if (ms <= 0) {
return;
}
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public String issueBulkKey(BulkSendCreateRequestDto req) {
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();

View File

@@ -13,6 +13,7 @@ import com.kri.notihub.server.dto.report.ReportExcelResponseDto;
import com.kri.notihub.server.dto.report.SendInfoDto;
import com.kri.notihub.server.dto.report.SendResultCodeDto;
import com.kri.notihub.server.dto.report.SendResultInfoDto;
import com.kri.notihub.server.dto.report.SendResultLastWithSidDto;
import com.kri.notihub.server.dto.report.SendResultSummaryDto;
import com.kri.notihub.server.dto.report.SendResultSummaryRequestDto;
import com.kri.notihub.server.dto.report.SendResultSummaryResponseDto;
@@ -202,6 +203,16 @@ public class ReportService {
.toList();
}
public List<SendResultLastWithSidDto> getSendResultLastWithSid(
ChannelType channelTy,
String reqstSvc,
String prjctCd,
List<String> sids
) {
List<Short> sendTys = getSendTypeCodeList(channelTy);
return sendRepository.findSendResultLastWithSidBySid(sendTys, reqstSvc, prjctCd, sids);
}
private SendResultSummaryResponseDto toSendResultSummaryResponse(
SendPriceKey key,
SendResultSummaryDto summary,