diff --git a/src/main/java/com/kri/notihub/server/common/consts/NotihubConst.java b/src/main/java/com/kri/notihub/server/common/consts/NotihubConst.java index d11ac2f..de5d462 100644 --- a/src/main/java/com/kri/notihub/server/common/consts/NotihubConst.java +++ b/src/main/java/com/kri/notihub/server/common/consts/NotihubConst.java @@ -21,7 +21,15 @@ 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 SMS_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode()); + public static final List SMS_TYPE_CODE_LIST = List.of( + SendType.SMS.getCode(), + SendType.LMS.getCode(), + SendType.MMS.getCode() + ); + public static final List LMS_MMS_TYPE_CODE_LIST = List.of( + SendType.LMS.getCode(), + SendType.MMS.getCode() + ); public static final List KKO_TYPE_CODE_LIST = List.of(SendType.KKO_AT.getCode()); public static final List EMAIL_TYPE_CODE_LIST = List.of(SendType.EMAIL.getCode()); public static final String EMAIL_RESERVATION_PREFIX = "RESERVATION_"; diff --git a/src/main/java/com/kri/notihub/server/common/enums/SendSmsType.java b/src/main/java/com/kri/notihub/server/common/enums/SendSmsType.java index bec67ae..748385b 100644 --- a/src/main/java/com/kri/notihub/server/common/enums/SendSmsType.java +++ b/src/main/java/com/kri/notihub/server/common/enums/SendSmsType.java @@ -10,7 +10,8 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public enum SendSmsType implements CodeEnum { SMS((short) 21), - LMS_MMS((short) 22); + LMS((short) 22), + MMS((short) 23); private final Short code; diff --git a/src/main/java/com/kri/notihub/server/common/enums/SendType.java b/src/main/java/com/kri/notihub/server/common/enums/SendType.java index e901296..5fbd562 100644 --- a/src/main/java/com/kri/notihub/server/common/enums/SendType.java +++ b/src/main/java/com/kri/notihub/server/common/enums/SendType.java @@ -11,7 +11,8 @@ import lombok.RequiredArgsConstructor; public enum SendType implements CodeEnum { EMAIL(SendEmailType.EMAIL), SMS(SendSmsType.SMS), - LMS_MMS(SendSmsType.LMS_MMS), + LMS(SendSmsType.LMS), + MMS(SendSmsType.MMS), KKO_AT(SendKkoAtType.KKO_AT); private final Short code; diff --git a/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java b/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java index 61e6618..fb532bc 100644 --- a/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java +++ b/src/main/java/com/kri/notihub/server/common/util/TemplateContentSanitizer.java @@ -167,11 +167,22 @@ public final class TemplateContentSanitizer { return text.trim(); } + public static SendType resolveSendType(SendType originalType, String title, String body, + String attachments) { + if (!SMS_TYPE_CODE_LIST.contains(originalType.getCode())) { + return originalType; + } + if (attachments != null && !attachments.isBlank()) { + return SendType.MMS; + } + return determineSms(title, body); + } + 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; + return hasTitle || isLargeBody ? SendType.LMS : SendType.SMS; } /** @@ -197,7 +208,7 @@ public final class TemplateContentSanitizer { case KKO_AT -> { // 카카오 등록 원문과 일치하도록 미리보기 제목과 본문을 변형하지 않는다. } - case SMS, LMS_MMS -> { + case SMS, LMS, MMS -> { // 평문화 outTitle = htmlToPlainTextPreserveNewlines(outTitle); outTitle = truncateTo128CodePoints(outTitle); diff --git a/src/main/java/com/kri/notihub/server/persistence/entity/TSendEntity.java b/src/main/java/com/kri/notihub/server/persistence/entity/TSendEntity.java index ad2bea4..e28ba72 100644 --- a/src/main/java/com/kri/notihub/server/persistence/entity/TSendEntity.java +++ b/src/main/java/com/kri/notihub/server/persistence/entity/TSendEntity.java @@ -1,7 +1,7 @@ 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 static com.kri.notihub.server.common.util.TemplateContentSanitizer.resolveSendType; import com.kri.notihub.server.common.enums.SendCorpType; import com.kri.notihub.server.common.enums.SendType; @@ -239,11 +239,8 @@ 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 = tmplat.getAtchFl() != null && !tmplat.getAtchFl().isBlank() - ? SendType.LMS_MMS.getCode() : determineSms(msgTitle, msgBody).getCode(); - } + Short sendTy = resolveSendType(tmplat.getTmplatTy(), msgTitle, msgBody, + tmplat.getAtchFl()).getCode(); return TSendEntity.builder() .cmid(sendResult.cmid()) diff --git a/src/main/java/com/kri/notihub/server/service/AbstractSendService.java b/src/main/java/com/kri/notihub/server/service/AbstractSendService.java index 7ac4718..b50b224 100644 --- a/src/main/java/com/kri/notihub/server/service/AbstractSendService.java +++ b/src/main/java/com/kri/notihub/server/service/AbstractSendService.java @@ -1,6 +1,5 @@ package com.kri.notihub.server.service; -import static com.kri.notihub.server.common.util.TemplateContentSanitizer.determineSms; import static org.apache.commons.lang3.StringUtils.firstNonBlank; import com.kri.common.feature.datetime.DateTimeUtil; @@ -11,6 +10,7 @@ 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.enums.TemplatePurpose; +import com.kri.notihub.server.common.util.TemplateContentSanitizer; import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto; import com.kri.notihub.server.dto.send.BulkSendResponseDto; import com.kri.notihub.server.dto.send.DestInfoDto; @@ -304,7 +304,7 @@ public abstract class AbstractSendService { SendInternalResultDto sendResult = doSendInternal( isResve, bulkSendKey, - tmplat.getTmplatTy(), + resolveSendType(tmplat, msgTitle, msgBody), tmplat.getTmplatIdx(), tmplat.getAtchFl(), sendFrom, @@ -413,13 +413,8 @@ public abstract class AbstractSendService { } private SendType resolveSendType(TemplateDto tmplat, String msgTitle, String msgBody) { - if (NotihubConst.SMS_TYPE_CODE_LIST.contains(tmplat.getTmplatTy().getCode())) { - if (tmplat.getAtchFl() != null && !tmplat.getAtchFl().isBlank()) { - return SendType.LMS_MMS; - } - return determineSms(msgTitle, msgBody); - } - return tmplat.getTmplatTy(); + return TemplateContentSanitizer.resolveSendType( + tmplat.getTmplatTy(), msgTitle, msgBody, tmplat.getAtchFl()); } private void validateBulkTemplatePurpose(TemplateDto tmplat) { diff --git a/src/main/java/com/kri/notihub/server/service/ReportService.java b/src/main/java/com/kri/notihub/server/service/ReportService.java index 7ae2370..600b39a 100644 --- a/src/main/java/com/kri/notihub/server/service/ReportService.java +++ b/src/main/java/com/kri/notihub/server/service/ReportService.java @@ -95,7 +95,7 @@ public class ReportService { String regCmpn) { List sendTyList = switch (sendTy) { case EMAIL -> NotihubConst.EMAIL_TYPE_CODE_LIST; - case SMS, LMS_MMS -> NotihubConst.SMS_TYPE_CODE_LIST; + case SMS, LMS, MMS -> NotihubConst.SMS_TYPE_CODE_LIST; case KKO_AT -> NotihubConst.KKO_TYPE_CODE_LIST; }; diff --git a/src/main/java/com/kri/notihub/server/service/SendSmsService.java b/src/main/java/com/kri/notihub/server/service/SendSmsService.java index 244ea37..db9d565 100644 --- a/src/main/java/com/kri/notihub/server/service/SendSmsService.java +++ b/src/main/java/com/kri/notihub/server/service/SendSmsService.java @@ -50,7 +50,7 @@ public class SendSmsService extends AbstractBizppurioSendService { @Override protected short standbyResultCode(SendType sendType) { - return sendType == SendType.LMS_MMS + return NotihubConst.LMS_MMS_TYPE_CODE_LIST.contains(sendType.getCode()) ? NotihubConst.LMS_MMS_STANDBY : NotihubConst.SMS_STANDBY; } diff --git a/src/main/java/com/kri/notihub/server/service/TemplateService.java b/src/main/java/com/kri/notihub/server/service/TemplateService.java index 59474e5..36f1495 100644 --- a/src/main/java/com/kri/notihub/server/service/TemplateService.java +++ b/src/main/java/com/kri/notihub/server/service/TemplateService.java @@ -91,9 +91,6 @@ public class TemplateService { final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime(); validateBySendType(template); TemplateContentSanitizer.sanitizeAndNormalizeInPlace(template); - if (hasAttachments(files) && template.getTmplatTy() == SendType.SMS) { - template.setTmplatTy(SendType.LMS_MMS); - } TTmplatEntity entity = TTmplatEntity.create(itrntPrjctCd, template, regUser, now); entity.setAtchFl(null); @@ -110,6 +107,7 @@ public class TemplateService { entity.setAtchFl(attachmentService(template.getTmplatTy()) .create(entity.getTmplatIdx(), files)); } + normalizeSmsType(entity); templateRepository.save(entity); TemplateDto created = TemplateDto.from(entity); @@ -199,11 +197,6 @@ public class TemplateService { //제목, 본문 정규화 TemplateContentSanitizer.sanitizeAndNormalizeInPlace(template); - if (template.getTmplatTy() == SendType.SMS - && (hasAttachments(files) || (previousType != SendType.EMAIL - && entity.getAtchFl() != null && !entity.getAtchFl().isBlank()))) { - template.setTmplatTy(SendType.LMS_MMS); - } TemplateBasicDto before = TemplateDto.from(entity); @@ -217,11 +210,7 @@ public class TemplateService { )); } - if (template.getTmplatTy() == SendType.LMS_MMS - && (entity.getAtchFl() == null || entity.getAtchFl().isBlank())) { - entity.setTmplatTy(TemplateContentSanitizer.determineSms( - entity.getTmplatTitle(), entity.getTmplatBody()).getCode()); - } + normalizeSmsType(entity); templateRepository.save(entity); @@ -276,8 +265,16 @@ public class TemplateService { return deleteFileNames != null && !deleteFileNames.isEmpty(); } + private void normalizeSmsType(TTmplatEntity entity) { + SendType type = SendType.fromCode(entity.getTmplatTy()); + if (NotihubConst.SMS_TYPE_CODE_LIST.contains(type.getCode())) { + entity.setTmplatTy(TemplateContentSanitizer.resolveSendType(type, + entity.getTmplatTitle(), entity.getTmplatBody(), entity.getAtchFl()).getCode()); + } + } + private boolean supportsAttachments(SendType type) { - return type == SendType.EMAIL || type == SendType.SMS || type == SendType.LMS_MMS; + return type == SendType.EMAIL || NotihubConst.SMS_TYPE_CODE_LIST.contains(type.getCode()); } private AbstractTemplateAttachmentService attachmentService(SendType type) {