260219_01_ENH: 공용라이브러리 버전업, 알림톡 발송 구현 완료
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.util.CommonUtil;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.send.DestInfoDto;
|
||||
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
||||
import com.kri.notihub.server.persistence.entity.BizMsgEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BizMsgRepository;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractBizppurioSendService extends SendService {
|
||||
|
||||
private final BizMsgRepository bizMsgRepository;
|
||||
|
||||
protected AbstractBizppurioSendService(
|
||||
TemplateRepository templateRepository,
|
||||
BulkSendRepository bulkSendRepository,
|
||||
BizMsgRepository bizMsgRepository,
|
||||
SendRepository sendRepository,
|
||||
TemplateService templateService
|
||||
) {
|
||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
||||
this.bizMsgRepository = bizMsgRepository;
|
||||
}
|
||||
|
||||
protected abstract ChannelType defaultChannelType();
|
||||
protected abstract short standbyResultCode(SendType sendType);
|
||||
protected abstract List<Short> sendTypeList();
|
||||
protected abstract int msgType(TSendEntity sendEntity);
|
||||
protected abstract String subject(TSendEntity sendEntity);
|
||||
|
||||
@Override
|
||||
protected final ChannelType getChannelType() {
|
||||
return defaultChannelType();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final SendInternalResultDto doSendInternal(
|
||||
Boolean isResve,
|
||||
String bulkSendKey,
|
||||
SendType sendType,
|
||||
String sendTel,
|
||||
String sendNm,
|
||||
String msgTitle,
|
||||
String msgBody,
|
||||
DestInfoDto dest
|
||||
) {
|
||||
String cmid = CommonUtil.uuid32();
|
||||
SendStatusType sendStatus = SendStatusType.STANDBY;
|
||||
short resultCode = standbyResultCode(sendType);
|
||||
|
||||
return SendInternalResultDto.of(cmid, sendStatus, resultCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPersistSendEntities(List<TSendEntity> persisted) {
|
||||
if (persisted == null || persisted.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<BizMsgEntity> msgList = new ArrayList<>(persisted.size());
|
||||
|
||||
for (TSendEntity s : persisted) {
|
||||
if (s == null || !sendTypeList().contains(s.getSendTy())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BizMsgEntity m = BizMsgEntity.fromSend(s, msgType(s), subject(s));
|
||||
msgList.add(m);
|
||||
}
|
||||
|
||||
if (!msgList.isEmpty()) {
|
||||
bizMsgRepository.saveAll(msgList);
|
||||
bizMsgRepository.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.util.CommonUtil;
|
||||
import com.kri.common.util.NumericUtil;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.common.external.pringo.PringoApiClient;
|
||||
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendRequestDto;
|
||||
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendResponseDto;
|
||||
import com.kri.notihub.server.dto.send.DestInfoDto;
|
||||
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public abstract class AbstractPringoSendService extends SendService {
|
||||
|
||||
private final PringoApiClient pringoApiClient;
|
||||
private final EmailResultPoller emailResultPoller;
|
||||
|
||||
protected AbstractPringoSendService(
|
||||
TemplateRepository templateRepository,
|
||||
BulkSendRepository bulkSendRepository,
|
||||
SendRepository sendRepository,
|
||||
TemplateService templateService,
|
||||
PringoApiClient pringoApiClient,
|
||||
EmailResultPoller emailResultPoller
|
||||
) {
|
||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
||||
this.pringoApiClient = pringoApiClient;
|
||||
this.emailResultPoller = emailResultPoller;
|
||||
}
|
||||
|
||||
protected abstract ChannelType defaultChannelType();
|
||||
|
||||
@Override
|
||||
protected final ChannelType getChannelType() {
|
||||
return defaultChannelType();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SendInternalResultDto doSendInternal(
|
||||
Boolean isResve,
|
||||
String bulkSendKey,
|
||||
SendType sendType, //Sms에서 사용 Email에서는 의미 없음
|
||||
String sendEml,
|
||||
String sendNm,
|
||||
String msgTitle,
|
||||
String msgBody,
|
||||
DestInfoDto dest
|
||||
) {
|
||||
if (Boolean.TRUE.equals(isResve)) {
|
||||
//예약 용 cmid 생성 추후 실제 발송 후 갱신
|
||||
String ts = DateTimeUtil.nowKstLocalDateTime()
|
||||
.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
|
||||
|
||||
int r = ThreadLocalRandom.current().nextInt(36 * 36 * 36);
|
||||
String suffix = String.format("%3s", Integer.toString(r, 36)).replace(' ', '0');
|
||||
|
||||
String cmid = NotihubConst.EMAIL_RESERVATION_PREFIX + ts + suffix;
|
||||
|
||||
return SendInternalResultDto.of(cmid, SendStatusType.STANDBY, NotihubConst.EMAIL_STANDBY);
|
||||
} else {
|
||||
PringoJsonSendRequestDto pringoReq = buildPringoSendRequest(sendEml, sendNm, msgTitle,
|
||||
msgBody, dest);
|
||||
return sendPringoEmail(pringoReq);
|
||||
}
|
||||
}
|
||||
|
||||
public SendInternalResultDto sendPringoEmail(PringoJsonSendRequestDto pringoReq) {
|
||||
PringoJsonSendResponseDto pringoRes = null;
|
||||
try {
|
||||
pringoRes = pringoApiClient.jsonSend(pringoReq);
|
||||
} catch (Exception e) {
|
||||
log.warn("Pringo json-send failed (pringoReq={})", pringoReq, e);
|
||||
}
|
||||
|
||||
String cmid = resolveEmailCmid(pringoRes);
|
||||
SendStatusType sendStatus;
|
||||
short resultCode;
|
||||
|
||||
if (pringoRes != null && pringoRes.isSuccess() && pringoRes.getReturnKey() != null) {
|
||||
//발송 요청에 성공한 것이지 발송이 성공이 아니므로 STANDBY 유지
|
||||
sendStatus = SendStatusType.STANDBY;
|
||||
resultCode = NotihubConst.EMAIL_PENDING;
|
||||
} else {
|
||||
sendStatus = SendStatusType.FAIL;
|
||||
resultCode = NotihubConst.EMAIL_SEND_FAIL;
|
||||
}
|
||||
|
||||
return SendInternalResultDto.of(cmid, sendStatus, resultCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPersistSendEntities(List<TSendEntity> persisted) {
|
||||
if (persisted == null || persisted.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (TSendEntity e : persisted) {
|
||||
if (validateSendEntity(e)) {
|
||||
emailResultPoller.enqueue(e.getCmid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PringoJsonSendRequestDto buildPringoSendRequest(
|
||||
String sendEml,
|
||||
String sendNm,
|
||||
String msgTitle,
|
||||
String msgBody,
|
||||
DestInfoDto dest
|
||||
) {
|
||||
Map<String, Object> vars = new HashMap<>();
|
||||
if (dest.getMsgParam() != null) {
|
||||
vars.putAll(dest.getMsgParam());
|
||||
}
|
||||
|
||||
return PringoJsonSendRequestDto.builder()
|
||||
.sender(sendEml)
|
||||
.senderName(Optional.ofNullable(sendNm).orElse(""))
|
||||
.recipient(dest.getDestEml())
|
||||
.recipientName(Optional.ofNullable(dest.getDestNm()).orElse(""))
|
||||
.subject(Optional.ofNullable(msgTitle).orElse(""))
|
||||
.body(Optional.ofNullable(msgBody).orElse(""))
|
||||
.vars(vars)
|
||||
.build();
|
||||
}
|
||||
|
||||
private String resolveEmailCmid(PringoJsonSendResponseDto pringoRes) {
|
||||
if (pringoRes != null && pringoRes.isSuccess() && pringoRes.getReturnKey() != null) {
|
||||
return String.valueOf(pringoRes.getReturnKey());
|
||||
}
|
||||
// return_key 미수신 케이스는 SendFau
|
||||
return CommonUtil.uuid32();
|
||||
}
|
||||
|
||||
private boolean validateSendEntity(TSendEntity e) {
|
||||
if (e == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pringo return polling이 필요한 상태만
|
||||
if (e.getResultCode() == null || e.getResultCode() != NotihubConst.EMAIL_PENDING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//예약은 갱신용 큐에 넣지 않음
|
||||
if (e.getCmid().startsWith(NotihubConst.EMAIL_RESERVATION_PREFIX)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// return_key(숫자)인 경우만
|
||||
return NumericUtil.isNumeric(e.getCmid());
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class SmsSendCursorStore {
|
||||
public class BizppurioSendCursorStore {
|
||||
|
||||
// 프로세스 전역 커서(스레드 세이프)
|
||||
private static final java.util.concurrent.atomic.AtomicLong CURSOR = new java.util.concurrent.atomic.AtomicLong(
|
||||
@@ -18,7 +20,14 @@ public class SmsSendCursorStore {
|
||||
// 서비스 기동 시: t_send에서 sendTy=SMS의 max(send_idx)로 초기화
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
long maxSendIdx = sendRepository.findMinSendIdxBySendTy(SendType.SMS.getCode());
|
||||
List<Short> bizppurioTypeList = Stream.concat(
|
||||
NotihubConst.SMS_TYPE_CODE_LIST.stream(),
|
||||
NotihubConst.KKO_TYPE_CODE_LIST.stream()
|
||||
)
|
||||
.distinct()
|
||||
.toList();
|
||||
|
||||
long maxSendIdx = sendRepository.findMinSendIdxBySendTyList(bizppurioTypeList);
|
||||
CURSOR.set(maxSendIdx);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.util.CommonUtil;
|
||||
import com.kri.common.util.NumericUtil;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.external.pringo.PringoApiClient;
|
||||
@@ -56,7 +56,7 @@ class EmailResultUpdater {
|
||||
return true;
|
||||
}
|
||||
|
||||
short resultCode = CommonUtil.safeParseShort(item.getStatus(), NotihubConst.EMAIL_NOT_RESULT);
|
||||
short resultCode = NumericUtil.safeParseShort(item.getStatus(), NotihubConst.EMAIL_NOT_RESULT);
|
||||
|
||||
//resultCode를 대상으로 Success인지 아닌지 판별 필요
|
||||
SendStatusType sendStatus =
|
||||
|
||||
@@ -1,35 +1,19 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.util.CommonUtil;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.common.external.pringo.PringoApiClient;
|
||||
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendRequestDto;
|
||||
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendResponseDto;
|
||||
import com.kri.notihub.server.dto.send.DestInfoDto;
|
||||
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class SendEmailService extends SendService {
|
||||
|
||||
private final PringoApiClient pringoApiClient;
|
||||
private final EmailResultPoller emailResultPoller;
|
||||
private final EmailResultUpdater emailResultUpdater;
|
||||
public class SendEmailService extends AbstractPringoSendService {
|
||||
|
||||
public SendEmailService(
|
||||
TemplateRepository templateRepository,
|
||||
@@ -37,132 +21,13 @@ public class SendEmailService extends SendService {
|
||||
SendRepository sendRepository,
|
||||
TemplateService templateService,
|
||||
PringoApiClient pringoApiClient,
|
||||
EmailResultPoller emailResultPoller,
|
||||
EmailResultUpdater emailResultUpdater
|
||||
EmailResultPoller emailResultPoller
|
||||
) {
|
||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
||||
this.pringoApiClient = pringoApiClient;
|
||||
this.emailResultPoller = emailResultPoller;
|
||||
this.emailResultUpdater = emailResultUpdater;
|
||||
super(templateRepository, bulkSendRepository, sendRepository, templateService, pringoApiClient, emailResultPoller);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SendType getSendType() {
|
||||
return SendType.EMAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SendInternalResultDto doSendInternal(
|
||||
Boolean isResve,
|
||||
String bulkSendKey,
|
||||
SendType sendType, //Sms에서 사용 Email에서는 의미 없음
|
||||
String sendEml,
|
||||
String sendNm,
|
||||
String msgTitle,
|
||||
String msgBody,
|
||||
DestInfoDto dest
|
||||
) {
|
||||
if (Boolean.TRUE.equals(isResve)) {
|
||||
//예약 용 cmid 생성 추후 실제 발송 후 갱신
|
||||
String ts = DateTimeUtil.nowKstLocalDateTime()
|
||||
.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
|
||||
|
||||
int r = ThreadLocalRandom.current().nextInt(36 * 36 * 36);
|
||||
String suffix = String.format("%3s", Integer.toString(r, 36)).replace(' ', '0');
|
||||
|
||||
String cmid = NotihubConst.EMAIL_RESERVATION_PREFIX + ts + suffix;
|
||||
|
||||
return SendInternalResultDto.of(cmid, SendStatusType.STANDBY, NotihubConst.EMAIL_STANDBY);
|
||||
} else {
|
||||
PringoJsonSendRequestDto pringoReq = buildPringoSendRequest(sendEml, sendNm, msgTitle,
|
||||
msgBody, dest);
|
||||
return sendPringoEmail(pringoReq);
|
||||
}
|
||||
}
|
||||
|
||||
public SendInternalResultDto sendPringoEmail(PringoJsonSendRequestDto pringoReq) {
|
||||
PringoJsonSendResponseDto pringoRes = null;
|
||||
try {
|
||||
pringoRes = pringoApiClient.jsonSend(pringoReq);
|
||||
} catch (Exception e) {
|
||||
log.warn("Pringo json-send failed (pringoReq={})", pringoReq, e);
|
||||
}
|
||||
|
||||
String cmid = resolveEmailCmid(pringoRes);
|
||||
SendStatusType sendStatus;
|
||||
short resultCode;
|
||||
|
||||
if (pringoRes != null && pringoRes.isSuccess() && pringoRes.getReturnKey() != null) {
|
||||
//발송 요청에 성공한 것이지 발송이 성공이 아니므로 STANDBY 유지
|
||||
//sendStatus = SendStatusType.SUCCESS;
|
||||
sendStatus = SendStatusType.STANDBY;
|
||||
resultCode = NotihubConst.EMAIL_PENDING;
|
||||
} else {
|
||||
sendStatus = SendStatusType.FAIL;
|
||||
resultCode = NotihubConst.EMAIL_SEND_FAIL;
|
||||
}
|
||||
|
||||
return SendInternalResultDto.of(cmid, sendStatus, resultCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPersistSendEntities(List<TSendEntity> persisted) {
|
||||
if (persisted == null || persisted.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (TSendEntity e : persisted) {
|
||||
if (e == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Pringo return polling이 필요한 상태만
|
||||
if (e.getResultCode() == null || e.getResultCode() != NotihubConst.EMAIL_PENDING) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//예약은 갱신용 큐에 넣지 않음
|
||||
if (e.getCmid().startsWith(NotihubConst.EMAIL_RESERVATION_PREFIX)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// return_key(숫자)인 경우만
|
||||
if (!CommonUtil.isNumeric(e.getCmid())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
emailResultPoller.enqueue(e.getCmid());
|
||||
}
|
||||
}
|
||||
|
||||
public PringoJsonSendRequestDto buildPringoSendRequest(
|
||||
String sendEml,
|
||||
String sendNm,
|
||||
String msgTitle,
|
||||
String msgBody,
|
||||
DestInfoDto dest
|
||||
) {
|
||||
Map<String, Object> vars = new HashMap<>();
|
||||
if (dest.getMsgParam() != null) {
|
||||
vars.putAll(dest.getMsgParam());
|
||||
}
|
||||
|
||||
return PringoJsonSendRequestDto.builder()
|
||||
.sender(sendEml)
|
||||
.senderName(Optional.ofNullable(sendNm).orElse(""))
|
||||
.recipient(dest.getDestEml())
|
||||
.recipientName(Optional.ofNullable(dest.getDestNm()).orElse(""))
|
||||
.subject(Optional.ofNullable(msgTitle).orElse(""))
|
||||
.body(Optional.ofNullable(msgBody).orElse(""))
|
||||
.vars(vars)
|
||||
.build();
|
||||
}
|
||||
|
||||
private String resolveEmailCmid(PringoJsonSendResponseDto pringoRes) {
|
||||
if (pringoRes != null && pringoRes.isSuccess() && pringoRes.getReturnKey() != null) {
|
||||
return String.valueOf(pringoRes.getReturnKey());
|
||||
}
|
||||
// return_key 미수신 케이스는 SendFau
|
||||
return CommonUtil.uuid32();
|
||||
protected ChannelType defaultChannelType() {
|
||||
return ChannelType.EMAIL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BizMsgRepository;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SendKkoAtService extends AbstractBizppurioSendService {
|
||||
|
||||
public SendKkoAtService(
|
||||
TemplateRepository templateRepository,
|
||||
BulkSendRepository bulkSendRepository,
|
||||
BizMsgRepository bizMsgRepository,
|
||||
SendRepository sendRepository,
|
||||
TemplateService templateService
|
||||
) {
|
||||
super(templateRepository, bulkSendRepository, bizMsgRepository, sendRepository,
|
||||
templateService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChannelType defaultChannelType() {
|
||||
return ChannelType.KKO_AT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected short standbyResultCode(SendType sendType) {
|
||||
return NotihubConst.KKO_AT_STANDBY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Short> sendTypeList() {
|
||||
return NotihubConst.KKO_TYPE_CODE_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int msgType(TSendEntity sendEntity) { return 6;}
|
||||
|
||||
@Override
|
||||
protected String subject(TSendEntity sendEntity) { return null; }
|
||||
|
||||
}
|
||||
@@ -3,8 +3,10 @@ package com.kri.notihub.server.service;
|
||||
import static org.apache.commons.lang3.StringUtils.firstNonBlank;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.util.StringUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
||||
@@ -69,7 +71,7 @@ public abstract class SendService {
|
||||
}
|
||||
|
||||
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
||||
validateTemplateType(tmplat, getSendType());
|
||||
validateTemplateType(tmplat);
|
||||
|
||||
TBulkSendEntity bulk = TBulkSendEntity.from(req, now);
|
||||
TBulkSendEntity saved = bulkSendRepository.save(bulk);
|
||||
@@ -77,13 +79,15 @@ public abstract class SendService {
|
||||
return saved.getBulkSendKey();
|
||||
}
|
||||
|
||||
protected void validateTemplateType(TemplateDto tmplat, SendType requiredType) {
|
||||
protected void validateTemplateType(TemplateDto tmplat) {
|
||||
ChannelType requiredType = getChannelType();
|
||||
|
||||
if (tmplat == null || requiredType == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int tmplatTy = tmplat.getTmplatTy().getCode() / 10;
|
||||
int required = requiredType.getCode() / 10;
|
||||
int required = requiredType.getCode();
|
||||
|
||||
if (tmplat.getTmplatTy() == null || tmplatTy != required) {
|
||||
throw BusinessException.badRequest("WRONG_TEMPLATE_TYPE", "템플릿 타입이 잘 못 됐습니다.")
|
||||
@@ -112,16 +116,16 @@ public abstract class SendService {
|
||||
}
|
||||
|
||||
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
||||
validateTemplateType(tmplat, getSendType());
|
||||
validateTemplateType(tmplat);
|
||||
|
||||
LocalDateTime sendDt = req.getSendDt() != null ? req.getSendDt() : now;
|
||||
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
||||
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
||||
String sendFrom = getSendType() == SendType.EMAIL ? sendEml : sendTel;
|
||||
String sendFrom = isEmailChannel() ? sendEml : sendTel;
|
||||
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
||||
|
||||
if (sendFrom == null || sendFrom.isBlank()) {
|
||||
if (getSendType() == SendType.EMAIL) {
|
||||
if (isEmailChannel()) {
|
||||
throw BusinessException.badRequest("SEND_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
||||
} else {
|
||||
throw BusinessException.badRequest("SEND_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
||||
@@ -129,9 +133,9 @@ public abstract class SendService {
|
||||
}
|
||||
|
||||
DestInfoDto dest = req.getDestInfo();
|
||||
String sendTo = getSendType() == SendType.EMAIL ? dest.getDestEml() : dest.getDestTel();
|
||||
String sendTo = isEmailChannel() ? dest.getDestEml() : dest.getDestTel();
|
||||
if (sendTo == null || sendTo.isBlank()) {
|
||||
if (getSendType() == SendType.EMAIL) {
|
||||
if (isEmailChannel()) {
|
||||
throw BusinessException.badRequest("DEST_EMAIL_REQUIRED", "destEml은 필수 입니다.");
|
||||
} else {
|
||||
throw BusinessException.badRequest("DEST_TEL_REQUIRED", "destTel은 필수 입니다.");
|
||||
@@ -159,9 +163,8 @@ public abstract class SendService {
|
||||
List<TSendEntity> sendInfo = new ArrayList<>(List.of(
|
||||
TSendEntity.from(
|
||||
req,
|
||||
tmplat.getTmplatTy(),
|
||||
tmplat,
|
||||
sendResult,
|
||||
tmplat.getItrntPrjctCd(),
|
||||
msgTitle,
|
||||
msgBody,
|
||||
regCmpn,
|
||||
@@ -203,18 +206,18 @@ public abstract class SendService {
|
||||
}
|
||||
|
||||
TemplateDto tmplat = templateService.getTemplate(bulk.getTmplatIdx());
|
||||
validateTemplateType(tmplat, getSendType());
|
||||
validateTemplateType(tmplat);
|
||||
|
||||
Boolean isResve = bulk.getResve();
|
||||
LocalDateTime sendDt = bulk.getSendDt() != null ? bulk.getSendDt() : now;
|
||||
|
||||
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
||||
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
||||
String sendFrom = getSendType() == SendType.EMAIL ? sendEml : sendTel;
|
||||
String sendFrom = isEmailChannel() ? sendEml : sendTel;
|
||||
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
||||
|
||||
if (sendFrom == null || sendFrom.isBlank()) {
|
||||
if (getSendType() == SendType.EMAIL) {
|
||||
if (isEmailChannel()) {
|
||||
throw BusinessException.badRequest("SENDER_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
||||
} else {
|
||||
throw BusinessException.badRequest("SENDER_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
||||
@@ -237,7 +240,7 @@ public abstract class SendService {
|
||||
List<DestInfoDto> chunk = req.getDestInfoList().subList(offset, end);
|
||||
|
||||
for (DestInfoDto dest : chunk) {
|
||||
String sendTo = getSendType() == SendType.EMAIL ? dest.getDestEml() : dest.getDestTel();
|
||||
String sendTo = isEmailChannel() ? dest.getDestEml() : dest.getDestTel();
|
||||
if (dest == null || sendTo.isBlank()) {
|
||||
failCnt++;
|
||||
continue;
|
||||
@@ -267,12 +270,10 @@ public abstract class SendService {
|
||||
TSendEntity.from(
|
||||
req,
|
||||
dest,
|
||||
tmplat.getTmplatTy(),
|
||||
tmplat,
|
||||
sendResult,
|
||||
tmplat.getItrntPrjctCd(),
|
||||
bulk.getReqstSvc(),
|
||||
bulk.getPrjctCd(),
|
||||
bulk.getTmplatIdx(),
|
||||
msgTitle,
|
||||
msgBody,
|
||||
bulk.getRegCmpn(),
|
||||
@@ -284,7 +285,7 @@ public abstract class SendService {
|
||||
)
|
||||
);
|
||||
|
||||
if (getSendType() == SendType.EMAIL) {
|
||||
if (isEmailChannel()) {
|
||||
// 발송 간 딜레이(Pringo rate-limit 대응)
|
||||
long delay = Math.max(tmplat.getDelayTime(), NotihubConst.EMAIL_DELAY);
|
||||
sleepSilently(delay);
|
||||
@@ -311,7 +312,7 @@ public abstract class SendService {
|
||||
return text;
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("\\[\\$([^\\]]+)]");
|
||||
Pattern pattern = Pattern.compile("(?:\\[\\$|#\\{)([^\\]}]+)(?:]|})"); // [$A] 또는 #{A}
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -364,5 +365,9 @@ public abstract class SendService {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract SendType getSendType();
|
||||
protected boolean isEmailChannel() {
|
||||
return getChannelType() == ChannelType.EMAIL;
|
||||
}
|
||||
|
||||
protected abstract ChannelType getChannelType();
|
||||
}
|
||||
|
||||
@@ -1,92 +1,53 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.util.CommonUtil;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.dto.send.DestInfoDto;
|
||||
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
||||
import com.kri.notihub.server.persistence.entity.BizMsgEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
import com.kri.notihub.server.persistence.repository.BizMsgRepository;
|
||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class SendSmsService extends SendService {
|
||||
|
||||
private final BizMsgRepository bizMsgRepository;
|
||||
public class SendSmsService extends AbstractBizppurioSendService {
|
||||
|
||||
public SendSmsService(
|
||||
BizMsgRepository bizMsgRepository,
|
||||
TemplateRepository templateRepository,
|
||||
BulkSendRepository bulkSendRepository,
|
||||
BizMsgRepository bizMsgRepository,
|
||||
SendRepository sendRepository,
|
||||
TemplateService templateService
|
||||
) {
|
||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
||||
this.bizMsgRepository = bizMsgRepository;
|
||||
super(templateRepository, bulkSendRepository, bizMsgRepository, sendRepository, templateService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SendType getSendType() {
|
||||
//일단 SMS로 내보내고 발송시에 Template의 SendType 또는 MessageBody, 제목여부로 강화 필요
|
||||
return SendType.SMS; // 프로젝트 enum 기준
|
||||
protected ChannelType defaultChannelType() {
|
||||
return ChannelType.SMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SendInternalResultDto doSendInternal(
|
||||
Boolean isResve,
|
||||
String bulkSendKey,
|
||||
SendType sendType,
|
||||
String sendTel,
|
||||
String sendNm,
|
||||
String msgTitle,
|
||||
String msgBody,
|
||||
DestInfoDto dest
|
||||
) {
|
||||
//문자는 비즈 뿌리오가 발송을 해주기 때문에 예약도 따로 처리할 필요 없음
|
||||
|
||||
String cmid = CommonUtil.uuid32();
|
||||
SendStatusType sendStatus = SendStatusType.STANDBY;
|
||||
short resultCode =
|
||||
sendType == SendType.LMS_MMS ? NotihubConst.LMS_MMS_STANDBY : NotihubConst.SMS_STANDBY;
|
||||
|
||||
return SendInternalResultDto.of(
|
||||
cmid,
|
||||
sendStatus,
|
||||
resultCode
|
||||
);
|
||||
protected short standbyResultCode(SendType sendType) {
|
||||
return sendType == SendType.LMS_MMS
|
||||
? NotihubConst.LMS_MMS_STANDBY
|
||||
: NotihubConst.SMS_STANDBY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPersistSendEntities(List<TSendEntity> persisted) {
|
||||
if (persisted == null || persisted.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
protected List<Short> sendTypeList() {
|
||||
return NotihubConst.SMS_TYPE_CODE_LIST;
|
||||
}
|
||||
|
||||
List<BizMsgEntity> msgList = new ArrayList<>(persisted.size());
|
||||
@Override
|
||||
protected int msgType(TSendEntity sendEntity) {
|
||||
return sendEntity.getSendTy().equals(SendType.SMS.getCode()) ? 0 : 5;
|
||||
}
|
||||
|
||||
for (TSendEntity s : persisted) {
|
||||
if (s == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NotihubConst.MOBILE_TYPE_LIST.contains(s.getSendTy())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BizMsgEntity m = BizMsgEntity.fromSend(s);
|
||||
msgList.add(m);
|
||||
}
|
||||
|
||||
if (!msgList.isEmpty()) {
|
||||
bizMsgRepository.saveAll(msgList);
|
||||
bizMsgRepository.flush();
|
||||
}
|
||||
@Override
|
||||
protected String subject(TSendEntity sendEntity) {
|
||||
return sendEntity.getSendTy().equals(SendType.SMS.getCode()) ? null : sendEntity.getMsgTitle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.kri.common.datetime.DateTimeUtil;
|
||||
import com.kri.common.util.StringUtil;
|
||||
import com.kri.common.web.BusinessException;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
@@ -16,10 +17,13 @@ import com.kri.notihub.server.persistence.repository.TemplateEventLogRepository;
|
||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Log4j2
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TemplateService {
|
||||
@@ -28,8 +32,11 @@ public class TemplateService {
|
||||
private final TemplateEventLogRepository templateEventLogRepository;
|
||||
|
||||
@Transactional
|
||||
public TemplateDto createTemplate(String itrntPrjctCd, TemplateBasicDto template,
|
||||
String regUser) {
|
||||
public TemplateDto createTemplate(
|
||||
String itrntPrjctCd,
|
||||
TemplateBasicDto template,
|
||||
String regUser
|
||||
) {
|
||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||
|
||||
validateBySendType(template);
|
||||
@@ -47,12 +54,13 @@ public class TemplateService {
|
||||
}
|
||||
|
||||
public List<TemplateSummaryDto> getTemplateList(ChannelType chnnlTy, String itrntPrjctCd) {
|
||||
List<Short> tmplatTyList = chnnlTy == ChannelType.SMS
|
||||
? NotihubConst.MOBILE_TYPE_CODE_LIST
|
||||
: NotihubConst.EMAIL_TYPE_CODE_LIST;
|
||||
List<Short> tmplatTyList = getSendTypeCodeList(chnnlTy);
|
||||
|
||||
return templateRepository.findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(tmplatTyList,
|
||||
itrntPrjctCd).stream()
|
||||
return templateRepository.findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(
|
||||
tmplatTyList,
|
||||
itrntPrjctCd
|
||||
)
|
||||
.stream()
|
||||
.map(TemplateSummaryDto::from)
|
||||
.toList();
|
||||
}
|
||||
@@ -133,21 +141,30 @@ public class TemplateService {
|
||||
templateEventLogRepository.save(log);
|
||||
}
|
||||
|
||||
private List<Short> getSendTypeCodeList(ChannelType chnnlTy) {
|
||||
return switch (chnnlTy) {
|
||||
case EMAIL -> NotihubConst.EMAIL_TYPE_CODE_LIST;
|
||||
case SMS -> NotihubConst.SMS_TYPE_CODE_LIST;
|
||||
case KKO_AT -> NotihubConst.KKO_TYPE_CODE_LIST;
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
|
||||
private void validateBySendType(TemplateBasicDto template) {
|
||||
//공통 검증
|
||||
if (template.getTmplatTy() == null) {
|
||||
throw BusinessException.badRequest("NULL TYPE", "템플릿 타입은 필수입니다.");
|
||||
}
|
||||
|
||||
if (template.getTmplatNm() == null || template.getTmplatNm().isBlank()) {
|
||||
if (StringUtil.isNullOrBlank(template.getTmplatNm())) {
|
||||
throw BusinessException.badRequest("EMPTY_NAME", "템플릿 명은 필수입니다.");
|
||||
}
|
||||
|
||||
if (template.getTmplatBody() == null || template.getTmplatBody().isBlank()) {
|
||||
if (StringUtil.isNullOrBlank(template.getTmplatBody())) {
|
||||
throw BusinessException.badRequest("EMPTY_BODY", "내용은 필수입니다.");
|
||||
}
|
||||
|
||||
if (template.getSendNm() == null || template.getSendNm().isBlank()) {
|
||||
if (StringUtil.isNullOrBlank(template.getSendNm())) {
|
||||
throw BusinessException.badRequest("EMPTY_SEND_NAME", "발신자 명은 필수입니다.");
|
||||
}
|
||||
|
||||
@@ -160,22 +177,36 @@ public class TemplateService {
|
||||
}
|
||||
}
|
||||
|
||||
SendType ty = template.getTmplatTy();
|
||||
if (ty == SendType.EMAIL) {
|
||||
if (template.getSendEml() == null || template.getSendEml().isBlank()) {
|
||||
Short ty = template.getTmplatTy().getCode();
|
||||
if (NotihubConst.EMAIL_TYPE_CODE_LIST.contains(ty)) {
|
||||
if (StringUtil.isNullOrBlank(template.getSendEml())) {
|
||||
throw BusinessException.badRequest("EMPTY_EMAIL", "이메일은 필수입니다.");
|
||||
}
|
||||
if (template.getTmplatTitle() == null || template.getTmplatTitle().isBlank()) {
|
||||
if (StringUtil.isNullOrBlank(template.getTmplatTitle())) {
|
||||
throw BusinessException.badRequest("EMPTY_TITLE", "제목은 필수입니다.");
|
||||
}
|
||||
|
||||
template.setSendTel(null);
|
||||
} else if (NotihubConst.MOBILE_TYPE_LIST.contains(ty)) {
|
||||
if (template.getSendTel() == null || template.getSendTel().isBlank()) {
|
||||
} else if (NotihubConst.SMS_TYPE_CODE_LIST.contains(ty) || NotihubConst.KKO_TYPE_CODE_LIST.contains(ty)) {
|
||||
if (StringUtil.isNullOrBlank(template.getSendTel())) {
|
||||
throw BusinessException.badRequest("EMPTY_TEL", "발송번호는 필수입니다.");
|
||||
}
|
||||
|
||||
if (ty == SendType.SMS) {
|
||||
if(NotihubConst.KKO_TYPE_CODE_LIST.contains(ty)) {
|
||||
if(StringUtil.isNullOrBlank(template.getNationCd())){
|
||||
template.setNationCd(NotihubConst.NATION_CODE);
|
||||
}
|
||||
|
||||
if(StringUtil.isNullOrBlank(template.getSenderKey())){
|
||||
throw BusinessException.badRequest("EMPTY_SENDER_KEY", "Sender Key는 필수입니다.");
|
||||
}
|
||||
|
||||
if(StringUtil.isNullOrBlank(template.getKkoTmplatCd())){
|
||||
throw BusinessException.badRequest("EMPTY_KKO_TMPLAT_CD", "Kakao Talk Template Code는 필수입니다.");
|
||||
}
|
||||
}
|
||||
|
||||
if (Objects.equals(ty, SendType.SMS.getCode()) || NotihubConst.KKO_TYPE_CODE_LIST.contains(ty)) {
|
||||
template.setTmplatTitle(null);
|
||||
}
|
||||
template.setSendEml(null);
|
||||
|
||||
Reference in New Issue
Block a user