260219_01_ENH: 공용라이브러리 버전업, 알림톡 발송 구현 완료
This commit is contained in:
@@ -38,7 +38,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.kri.common:starter:beta.1.0.63"
|
implementation "com.kri.common:starter:beta.1.0.66"
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class NotihubConst {
|
public final class NotihubConst {
|
||||||
|
|
||||||
|
public static final String NATION_CODE = "82";
|
||||||
public static final int OUTSOURCE_USER_ROLE = 4000;
|
public static final int OUTSOURCE_USER_ROLE = 4000;
|
||||||
public static final int CHUNK_SIZE = 5_000;
|
public static final int CHUNK_SIZE = 5_000;
|
||||||
public static final int INSERT_CHUNK_SIZE = 1_000;
|
public static final int INSERT_CHUNK_SIZE = 1_000;
|
||||||
@@ -12,9 +13,8 @@ public final class NotihubConst {
|
|||||||
public static final short EMAIL_RESULT_SEARCH_DELAY = 500;
|
public static final short EMAIL_RESULT_SEARCH_DELAY = 500;
|
||||||
public static final short EMAIL_DELAY = 500;
|
public static final short EMAIL_DELAY = 500;
|
||||||
public static final short DELAY_MAX_MS = (short) 5_000; // 필요시 조정
|
public static final short DELAY_MAX_MS = (short) 5_000; // 필요시 조정
|
||||||
public static final List<SendType> MOBILE_TYPE_LIST = List.of(SendType.SMS, SendType.LMS_MMS);
|
public static final List<Short> SMS_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
||||||
public static final List<Short> MOBILE_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(),
|
public static final List<Short> KKO_TYPE_CODE_LIST = List.of(SendType.KKO_AT.getCode());
|
||||||
SendType.LMS_MMS.getCode());
|
|
||||||
public static final List<Short> EMAIL_TYPE_CODE_LIST = List.of(SendType.EMAIL.getCode());
|
public static final List<Short> EMAIL_TYPE_CODE_LIST = List.of(SendType.EMAIL.getCode());
|
||||||
public static final String EMAIL_RESERVATION_PREFIX = "RESERVATION_";
|
public static final String EMAIL_RESERVATION_PREFIX = "RESERVATION_";
|
||||||
public static final short EMAIL_STANDBY = 100;
|
public static final short EMAIL_STANDBY = 100;
|
||||||
@@ -27,6 +27,10 @@ public final class NotihubConst {
|
|||||||
public static final short SMS_NOT_RESULT = 9999;
|
public static final short SMS_NOT_RESULT = 9999;
|
||||||
public static final short LMS_MMS_STANDBY = 6000;
|
public static final short LMS_MMS_STANDBY = 6000;
|
||||||
public static final short LMS_MMS_SUCCESS = 6600;
|
public static final short LMS_MMS_SUCCESS = 6600;
|
||||||
|
public static final short KKO_AT_STANDBY = 7900;
|
||||||
|
public static final short KKO_AT_SUCCESS = 7000;
|
||||||
|
public static final short KKO_AT_NOT_RESULT = 7999;
|
||||||
|
|
||||||
private NotihubConst() {
|
private NotihubConst() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
public enum ChannelType implements CodeEnum<Short> {
|
public enum ChannelType implements CodeEnum<Short> {
|
||||||
|
|
||||||
EMAIL((short) 1),
|
EMAIL((short) 1),
|
||||||
SMS((short) 2);
|
SMS((short) 2),
|
||||||
|
KKO_AT((short) 3);
|
||||||
|
|
||||||
private final Short code;
|
private final Short code;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.kri.notihub.server.common.enums;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import com.kri.common.enums.CodeEnum;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Getter(onMethod_ = @JsonValue)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public enum SendKkoAtType implements CodeEnum<Short> {
|
||||||
|
KKO_AT((short) 31);
|
||||||
|
|
||||||
|
private final Short code;
|
||||||
|
|
||||||
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
|
public static SendKkoAtType fromCode(Short code) {
|
||||||
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (SendKkoAtType s : values()) {
|
||||||
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown SendKkoAtType code: " + code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,8 @@ import lombok.RequiredArgsConstructor;
|
|||||||
public enum SendType implements CodeEnum<Short> {
|
public enum SendType implements CodeEnum<Short> {
|
||||||
EMAIL(SendEmailType.EMAIL),
|
EMAIL(SendEmailType.EMAIL),
|
||||||
SMS(SendSmsType.SMS),
|
SMS(SendSmsType.SMS),
|
||||||
LMS_MMS(SendSmsType.LMS_MMS);
|
LMS_MMS(SendSmsType.LMS_MMS),
|
||||||
|
KKO_AT(SendKkoAtType.KKO_AT);
|
||||||
|
|
||||||
private final Short code;
|
private final Short code;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.kri.notihub.server.common.external.pringo.dto;
|
package com.kri.notihub.server.common.external.pringo.dto;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import com.kri.common.util.StringUtil;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -27,7 +28,7 @@ public class PringoJsonReturnRequestDto {
|
|||||||
if (this.apiKey == null || this.apiKey.isBlank()) {
|
if (this.apiKey == null || this.apiKey.isBlank()) {
|
||||||
this.apiKey = defaultApiKey;
|
this.apiKey = defaultApiKey;
|
||||||
}
|
}
|
||||||
if (this.templateId == null || this.templateId.isBlank()) {
|
if (StringUtil.isNullOrBlank(this.templateId)) {
|
||||||
this.templateId = defaultTemplateId;
|
this.templateId = defaultTemplateId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.kri.notihub.server.common.util;
|
package com.kri.notihub.server.common.util;
|
||||||
|
|
||||||
|
import com.kri.common.util.StringUtil;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -23,10 +24,6 @@ public final class TemplateContentSanitizer {
|
|||||||
return s.getBytes(StandardCharsets.UTF_8).length;
|
return s.getBytes(StandardCharsets.UTF_8).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBlank(String s) {
|
|
||||||
return s == null || s.isBlank();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* title은 최대 128자(코드포인트 기준)로 절단
|
* title은 최대 128자(코드포인트 기준)로 절단
|
||||||
*/
|
*/
|
||||||
@@ -100,8 +97,8 @@ public final class TemplateContentSanitizer {
|
|||||||
String text = doc.body() != null ? doc.body().wholeText() : doc.wholeText();
|
String text = doc.body() != null ? doc.body().wholeText() : doc.wholeText();
|
||||||
|
|
||||||
text = normalizeControls(text, true);
|
text = normalizeControls(text, true);
|
||||||
text = text.replaceAll("[ \\t\\f\\v]+", " ");
|
text = text.replaceAll("[ \\t\\f]+", " ");
|
||||||
text = text.replaceAll("\\n{3,}", "\n\n");
|
//text = text.replaceAll("\\n{3,}", "\n\n");
|
||||||
|
|
||||||
return text.trim();
|
return text.trim();
|
||||||
}
|
}
|
||||||
@@ -126,7 +123,7 @@ public final class TemplateContentSanitizer {
|
|||||||
|
|
||||||
outBody = sanitizeEmailHtml(outBody);
|
outBody = sanitizeEmailHtml(outBody);
|
||||||
}
|
}
|
||||||
case SMS, LMS_MMS -> {
|
case SMS, LMS_MMS, KKO_AT -> {
|
||||||
// 평문화
|
// 평문화
|
||||||
outTitle = htmlToPlainTextPreserveNewlines(outTitle);
|
outTitle = htmlToPlainTextPreserveNewlines(outTitle);
|
||||||
outTitle = truncateTo128CodePoints(outTitle);
|
outTitle = truncateTo128CodePoints(outTitle);
|
||||||
@@ -135,17 +132,19 @@ public final class TemplateContentSanitizer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) 타입 재결정(요청사항)
|
if (type == SendType.KKO_AT) {
|
||||||
if (type == SendType.SMS) {
|
outTitle = null;
|
||||||
|
} else if (type == SendType.SMS) {
|
||||||
// SMS는 제목 저장 안 함
|
// SMS는 제목 저장 안 함
|
||||||
outTitle = null;
|
outTitle = null;
|
||||||
|
|
||||||
|
// 2) 타입 재결정
|
||||||
// 본문이 SMS 한도 초과면 LMS_MMS로 승격
|
// 본문이 SMS 한도 초과면 LMS_MMS로 승격
|
||||||
if (utf8ByteLength(outBody) > SMS_MAX_BYTES_UTF8) {
|
if (utf8ByteLength(outBody) > SMS_MAX_BYTES_UTF8) {
|
||||||
type = SendType.LMS_MMS;
|
type = SendType.LMS_MMS;
|
||||||
}
|
}
|
||||||
} else if (type == SendType.LMS_MMS) {
|
} else if (type == SendType.LMS_MMS) {
|
||||||
boolean hasTitle = !isBlank(outTitle);
|
boolean hasTitle = StringUtil.hasText(outTitle);
|
||||||
|
|
||||||
// "LMS_MMS인데 본문이 짧으면 SMS로 강등"이 기본인데,
|
// "LMS_MMS인데 본문이 짧으면 SMS로 강등"이 기본인데,
|
||||||
// 단, 제목이 있으면 본문이 짧아도 LMS_MMS 유지
|
// 단, 제목이 있으면 본문이 짧아도 LMS_MMS 유지
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.kri.notihub.server.controller;
|
||||||
|
|
||||||
|
import com.kri.common.webmvc.RequestUserContext;
|
||||||
|
import com.kri.notihub.server.dto.send.BizppurioCursorResponseDto;
|
||||||
|
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
||||||
|
import com.kri.notihub.server.dto.send.BulkSendResponseDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendRequestBulkDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
||||||
|
import com.kri.notihub.server.service.BizppurioSendCursorStore;
|
||||||
|
import com.kri.notihub.server.service.SendKkoAtService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/send-kko")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Tag(name = "Send Kakao", description = "카카오 알림톡 발송 API")
|
||||||
|
public class SendKkoAtController {
|
||||||
|
private final SendKkoAtService sendKKoAtService;
|
||||||
|
private final BizppurioSendCursorStore cursorStore;
|
||||||
|
|
||||||
|
@Operation(summary = "발송 결과 반영 커서(send_idx) 조회")
|
||||||
|
@GetMapping("/cursor")
|
||||||
|
public BizppurioCursorResponseDto getCursor() {
|
||||||
|
return BizppurioCursorResponseDto.of(cursorStore.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "벌크 발송키 생성")
|
||||||
|
@PutMapping("/create/bulk")
|
||||||
|
public String createBulkSendKey(@Valid @RequestBody BulkSendCreateRequestDto req) {
|
||||||
|
return sendKKoAtService.issueBulkKey(req);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "알림톡 단건 발송")
|
||||||
|
@PostMapping("/single")
|
||||||
|
public void sendSingle(
|
||||||
|
@Valid @RequestBody SendRequestSingleDto req,
|
||||||
|
RequestUserContext ctx
|
||||||
|
) {
|
||||||
|
sendKKoAtService.doSendSingle(req, ctx.getUserCmpn(), ctx.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "bulkSendKey 기반 알림톡 벌크 발송")
|
||||||
|
@PostMapping("/bulk")
|
||||||
|
public BulkSendResponseDto sendBulk(
|
||||||
|
@Valid @RequestBody SendRequestBulkDto req
|
||||||
|
) {
|
||||||
|
return sendKKoAtService.doSendBulk(req);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,9 @@ import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
|||||||
import com.kri.notihub.server.dto.send.BulkSendResponseDto;
|
import com.kri.notihub.server.dto.send.BulkSendResponseDto;
|
||||||
import com.kri.notihub.server.dto.send.SendRequestBulkDto;
|
import com.kri.notihub.server.dto.send.SendRequestBulkDto;
|
||||||
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
||||||
import com.kri.notihub.server.dto.send.SmsCursorResponseDto;
|
import com.kri.notihub.server.dto.send.BizppurioCursorResponseDto;
|
||||||
import com.kri.notihub.server.service.SendSmsService;
|
import com.kri.notihub.server.service.SendSmsService;
|
||||||
import com.kri.notihub.server.service.SmsSendCursorStore;
|
import com.kri.notihub.server.service.BizppurioSendCursorStore;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
@@ -26,12 +26,12 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
public class SendSmsController {
|
public class SendSmsController {
|
||||||
|
|
||||||
private final SendSmsService sendSmsService;
|
private final SendSmsService sendSmsService;
|
||||||
private final SmsSendCursorStore cursorStore;
|
private final BizppurioSendCursorStore cursorStore;
|
||||||
|
|
||||||
@Operation(summary = "SMS 결과 반영 커서(send_idx) 조회")
|
@Operation(summary = "발송 결과 반영 커서(send_idx) 조회")
|
||||||
@GetMapping("/cursor")
|
@GetMapping("/cursor")
|
||||||
public SmsCursorResponseDto getCursor() {
|
public BizppurioCursorResponseDto getCursor() {
|
||||||
return SmsCursorResponseDto.of(cursorStore.get());
|
return BizppurioCursorResponseDto.of(cursorStore.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "벌크 발송키 생성")
|
@Operation(summary = "벌크 발송키 생성")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.kri.notihub.server.controller;
|
|||||||
|
|
||||||
import com.kri.common.webmvc.RequestUserContext;
|
import com.kri.common.webmvc.RequestUserContext;
|
||||||
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.dto.template.TemplateBasicDto;
|
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||||
import com.kri.notihub.server.dto.template.TemplateDto;
|
import com.kri.notihub.server.dto.template.TemplateDto;
|
||||||
import com.kri.notihub.server.dto.template.TemplateSummaryDto;
|
import com.kri.notihub.server.dto.template.TemplateSummaryDto;
|
||||||
@@ -56,14 +57,16 @@ public class TemplateController {
|
|||||||
TemplateDto newTmplat = templateService.createTemplate(template.getItrntPrjctCd(), template,
|
TemplateDto newTmplat = templateService.createTemplate(template.getItrntPrjctCd(), template,
|
||||||
ctx.getUserId());
|
ctx.getUserId());
|
||||||
|
|
||||||
String newHtml = fileService.syncOnSave(
|
if (template.getTmplatTy() == SendType.EMAIL) {
|
||||||
newTmplat.getItrntPrjctCd(),
|
String newHtml = fileService.syncOnSave(
|
||||||
newTmplat.getTmplatIdx(),
|
newTmplat.getItrntPrjctCd(),
|
||||||
newTmplat.getTmplatBody()
|
newTmplat.getTmplatIdx(),
|
||||||
);
|
newTmplat.getTmplatBody()
|
||||||
newTmplat.setTmplatBody(newHtml);
|
);
|
||||||
|
newTmplat.setTmplatBody(newHtml);
|
||||||
|
|
||||||
templateService.updateTemplateBodyWithCreate(newTmplat);
|
templateService.updateTemplateBodyWithCreate(newTmplat);
|
||||||
|
}
|
||||||
|
|
||||||
return newTmplat;
|
return newTmplat;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import lombok.NoArgsConstructor;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SmsCursorResponseDto {
|
public class BizppurioCursorResponseDto {
|
||||||
|
|
||||||
@Schema(description = "SMS 결과 반영 스케줄러 커서(send_idx)")
|
@Schema(description = "SMS 결과 반영 스케줄러 커서(send_idx)")
|
||||||
private Long cursor;
|
private Long cursor;
|
||||||
|
|
||||||
public static SmsCursorResponseDto of(long cursor) {
|
public static BizppurioCursorResponseDto of(long cursor) {
|
||||||
return SmsCursorResponseDto.builder()
|
return BizppurioCursorResponseDto.builder()
|
||||||
.cursor(cursor)
|
.cursor(cursor)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -23,25 +23,32 @@ public class BulkSendCreateRequestDto {
|
|||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송 요청 회사")
|
@Schema(description = "발송 요청 회사")
|
||||||
String reqstCmpn;
|
String reqstCmpn;
|
||||||
|
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송 요청자")
|
@Schema(description = "발송 요청자")
|
||||||
String reqstUser;
|
String reqstUser;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송 요청 서비스 (로그용)")
|
@Schema(description = "발송 요청 서비스 (로그용)")
|
||||||
private String reqstSvc;
|
private String reqstSvc;
|
||||||
|
|
||||||
@Schema(description = "발송 요청 서비스의 프로젝트 코드 (로그용)")
|
@Schema(description = "발송 요청 서비스의 프로젝트 코드 (로그용)")
|
||||||
private String prjctCd;
|
private String prjctCd;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "템플릿 idx")
|
@Schema(description = "템플릿 idx")
|
||||||
private Long tmplatIdx;
|
private Long tmplatIdx;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
@Schema(description = "예약 여부")
|
@Schema(description = "예약 여부")
|
||||||
private Boolean resve = false;
|
private Boolean resve = false;
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@Schema(description = "발송일시(미입력 시 현재 시간)")
|
@Schema(description = "발송일시(미입력 시 현재 시간)")
|
||||||
private LocalDateTime sendDt;
|
private LocalDateTime sendDt;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "대상자 수")
|
@Schema(description = "대상자 수")
|
||||||
private Integer trgtCnt;
|
private Integer trgtCnt;
|
||||||
|
|||||||
@@ -17,17 +17,22 @@ public class SendRequestSingleDto extends SendRequestBasicDto {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "수신자 정보")
|
@Schema(description = "수신자 정보")
|
||||||
DestInfoDto destInfo;
|
DestInfoDto destInfo;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "발송 템플릿")
|
@Schema(description = "발송 템플릿")
|
||||||
private long tmplatIdx;
|
private long tmplatIdx;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송 요청 서비스 (로그용)")
|
@Schema(description = "발송 요청 서비스 (로그용)")
|
||||||
private String reqstSvc;
|
private String reqstSvc;
|
||||||
|
|
||||||
@Schema(description = "발송 요청 서비스의 프로젝트 코드 (로그용)")
|
@Schema(description = "발송 요청 서비스의 프로젝트 코드 (로그용)")
|
||||||
private String prjctCd;
|
private String prjctCd;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "예약 여부")
|
@Schema(description = "예약 여부")
|
||||||
private Boolean resve = false;
|
private Boolean resve = false;
|
||||||
|
|
||||||
@Schema(description = "발송 희망 시간 (비어있는 경우 즉시)")
|
@Schema(description = "발송 희망 시간 (비어있는 경우 즉시)")
|
||||||
@LenientLocalDateTime
|
@LenientLocalDateTime
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.kri.notihub.server.dto.template;
|
|||||||
|
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
import jakarta.validation.constraints.Email;
|
import jakarta.validation.constraints.Email;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
@@ -22,39 +23,51 @@ public class TemplateBasicDto {
|
|||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "인트라넷 프로젝트 코드")
|
@Schema(description = "인트라넷 프로젝트 코드")
|
||||||
public String itrntPrjctCd;
|
private String itrntPrjctCd;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "템플릿 타입")
|
@Schema(description = "템플릿 타입")
|
||||||
public SendType tmplatTy;
|
private SendType tmplatTy;
|
||||||
|
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "템플릿 명")
|
@Schema(description = "템플릿 명")
|
||||||
public String tmplatNm;
|
private String tmplatNm;
|
||||||
|
|
||||||
@Size(max = 128)
|
@Size(max = 128)
|
||||||
@Schema(description = "발송시 제목")
|
@Schema(description = "발송시 제목")
|
||||||
public String tmplatTitle;
|
private String tmplatTitle;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송 내용")
|
@Schema(description = "발송 내용")
|
||||||
public String tmplatBody;
|
private String tmplatBody;
|
||||||
|
|
||||||
|
@Schema(description = "비즈뿌리오 알림톡 프로필의 sender key")
|
||||||
|
private String senderKey;
|
||||||
|
|
||||||
|
@Schema(description = "카카오 알림톡 템플릿 코드")
|
||||||
|
private String kkoTmplatCd;
|
||||||
|
|
||||||
|
@Schema(description = "국가 코드 (알림톡에서 사용)")
|
||||||
|
private String nationCd;
|
||||||
|
|
||||||
|
@Schema(description = "첨부 파일 (여러 개일 경우, ‘I’문자로 구분)")
|
||||||
|
private String atchFl;
|
||||||
|
|
||||||
@Schema(description = "이메일 건당 발송 딜레이(단위 ms, 기본: 500ms)")
|
@Schema(description = "이메일 건당 발송 딜레이(단위 ms, 기본: 500ms)")
|
||||||
public Short delayTime;
|
private Short delayTime;
|
||||||
|
|
||||||
@Size(max = 16)
|
@Size(max = 16)
|
||||||
@Schema(description = "발송 전화번호(문자 발송에서 사용)")
|
@Schema(description = "발송 전화번호(문자 발송에서 사용)")
|
||||||
public String sendTel;
|
private String sendTel;
|
||||||
|
|
||||||
@Size(max = 64)
|
@Size(max = 64)
|
||||||
@Email
|
@Email
|
||||||
@Schema(description = "발송 이메일(이메일 발송에서 사용)")
|
@Schema(description = "발송 이메일(이메일 발송에서 사용)")
|
||||||
public String sendEml;
|
private String sendEml;
|
||||||
|
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송자 이름")
|
@Schema(description = "발송자 이름")
|
||||||
public String sendNm;
|
private String sendNm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public class TemplateDto extends TemplateBasicDto {
|
|||||||
.tmplatNm(entity.getTmplatNm())
|
.tmplatNm(entity.getTmplatNm())
|
||||||
.tmplatTitle(entity.getTmplatTitle())
|
.tmplatTitle(entity.getTmplatTitle())
|
||||||
.tmplatBody(entity.getTmplatBody())
|
.tmplatBody(entity.getTmplatBody())
|
||||||
|
.senderKey(entity.getSenderKey())
|
||||||
|
.kkoTmplatCd(entity.getKkoTmplatCd())
|
||||||
|
.nationCd(entity.getNationCd())
|
||||||
|
.atchFl(entity.getAtchFl())
|
||||||
.delayTime(entity.getDelayTime())
|
.delayTime(entity.getDelayTime())
|
||||||
.sendTel(entity.getSendTel())
|
.sendTel(entity.getSendTel())
|
||||||
.sendEml(entity.getSendEml())
|
.sendEml(entity.getSendEml())
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ import lombok.Setter;
|
|||||||
public class TemplateSummaryDto {
|
public class TemplateSummaryDto {
|
||||||
|
|
||||||
@Schema(description = "템플릿 고유 키")
|
@Schema(description = "템플릿 고유 키")
|
||||||
public Long tmplatIdx;
|
private Long tmplatIdx;
|
||||||
|
|
||||||
@Schema(description = "템플릿 명")
|
@Schema(description = "템플릿 명")
|
||||||
public String tmplatNm;
|
private String tmplatNm;
|
||||||
|
|
||||||
public static TemplateSummaryDto from(TTmplatEntity entity) {
|
public static TemplateSummaryDto from(TTmplatEntity entity) {
|
||||||
return TemplateSummaryDto.builder()
|
return TemplateSummaryDto.builder()
|
||||||
|
|||||||
@@ -89,15 +89,15 @@ public class BizMsgEntity {
|
|||||||
|
|
||||||
@Size(max = 5)
|
@Size(max = 5)
|
||||||
@Column(name = "`NATION_CODE`", length = 5)
|
@Column(name = "`NATION_CODE`", length = 5)
|
||||||
private String nationCode;
|
private String nationCode; //알림톡에서만 사용
|
||||||
|
|
||||||
@Size(max = 40)
|
@Size(max = 40)
|
||||||
@Column(name = "`SENDER_KEY`", length = 40)
|
@Column(name = "`SENDER_KEY`", length = 40)
|
||||||
private String senderKey;
|
private String senderKey; //알림톡에서만 사용(발송 프로필 키)
|
||||||
|
|
||||||
@Size(max = 64)
|
@Size(max = 64)
|
||||||
@Column(name = "`TEMPLATE_CODE`", length = 64)
|
@Column(name = "`TEMPLATE_CODE`", length = 64)
|
||||||
private String templateCode;
|
private String templateCode; //알림톡에서만 사용
|
||||||
|
|
||||||
@Size(max = 8)
|
@Size(max = 8)
|
||||||
@Column(name = "`RESPONSE_METHOD`", length = 8)
|
@Column(name = "`RESPONSE_METHOD`", length = 8)
|
||||||
@@ -136,7 +136,7 @@ public class BizMsgEntity {
|
|||||||
|
|
||||||
@Size(max = 1000)
|
@Size(max = 1000)
|
||||||
@Column(name = "`ATTACHED_FILE`", length = 1000)
|
@Column(name = "`ATTACHED_FILE`", length = 1000)
|
||||||
private String attachedFile;
|
private String attachedFile;//알림톡에서 버튼 구현등을 위해 사용
|
||||||
|
|
||||||
@Size(max = 64)
|
@Size(max = 64)
|
||||||
@Column(name = "`VXML_FILE`", length = 64)
|
@Column(name = "`VXML_FILE`", length = 64)
|
||||||
@@ -176,9 +176,7 @@ public class BizMsgEntity {
|
|||||||
private String rcsRefkey;
|
private String rcsRefkey;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static BizMsgEntity fromSend(TSendEntity s) {
|
public static BizMsgEntity fromSend(TSendEntity s, int msgType, String subject) {
|
||||||
int msgType = s.getSendTy().equals(SendType.SMS.getCode()) ? 0 : 5;
|
|
||||||
String subject = s.getSendTy().equals(SendType.SMS.getCode()) ? null : s.getMsgTitle();
|
|
||||||
|
|
||||||
return BizMsgEntity.builder()
|
return BizMsgEntity.builder()
|
||||||
.cmid(s.getCmid())
|
.cmid(s.getCmid())
|
||||||
@@ -192,7 +190,11 @@ public class BizMsgEntity {
|
|||||||
.sendName(s.getSendNm())
|
.sendName(s.getSendNm())
|
||||||
.subject(subject)
|
.subject(subject)
|
||||||
.msgBody(s.getMsgBody())
|
.msgBody(s.getMsgBody())
|
||||||
|
.attachedFile(s.getAtchFl())//varchar(1000)
|
||||||
.cinfo(s.getReqstSvc())
|
.cinfo(s.getReqstSvc())
|
||||||
|
.nationCode(s.getNationCd())//varchar(5)
|
||||||
|
.senderKey(s.getSenderKey())
|
||||||
|
.templateCode(s.getKkoTmplatCd())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.kri.notihub.server.dto.send.DestInfoDto;
|
|||||||
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
||||||
import com.kri.notihub.server.dto.send.SendRequestBasicDto;
|
import com.kri.notihub.server.dto.send.SendRequestBasicDto;
|
||||||
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
||||||
|
import com.kri.notihub.server.dto.template.TemplateDto;
|
||||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
@@ -87,6 +88,22 @@ public class TSendEntity {
|
|||||||
@Column(name = "tmplat_idx", columnDefinition = "int UNSIGNED")
|
@Column(name = "tmplat_idx", columnDefinition = "int UNSIGNED")
|
||||||
private Long tmplatIdx;
|
private Long tmplatIdx;
|
||||||
|
|
||||||
|
@Size(max = 40)
|
||||||
|
@Column(name = "sender_key", length = 40)
|
||||||
|
private String senderKey;
|
||||||
|
|
||||||
|
@Size(max = 64)
|
||||||
|
@Column(name = "kko_tmplat_cd", length = 64)
|
||||||
|
private String kkoTmplatCd;
|
||||||
|
|
||||||
|
@Size(max = 5)
|
||||||
|
@Column(name = "nation_cd", length = 5)
|
||||||
|
private String nationCd;
|
||||||
|
|
||||||
|
@Size(max = 1000)
|
||||||
|
@Column(name = "atch_fl", length = 1000)
|
||||||
|
private String atchFl;
|
||||||
|
|
||||||
@Size(max = 64)
|
@Size(max = 64)
|
||||||
@Column(name = "send_eml", length = 64)
|
@Column(name = "send_eml", length = 64)
|
||||||
private String sendEml;
|
private String sendEml;
|
||||||
@@ -154,9 +171,8 @@ public class TSendEntity {
|
|||||||
|
|
||||||
public static TSendEntity from(
|
public static TSendEntity from(
|
||||||
SendRequestSingleDto req,
|
SendRequestSingleDto req,
|
||||||
SendType sendTy,
|
TemplateDto tmplat,
|
||||||
SendInternalResultDto sendResult,
|
SendInternalResultDto sendResult,
|
||||||
String itrntPrjctCd,
|
|
||||||
String msgTitle,
|
String msgTitle,
|
||||||
String msgBody,
|
String msgBody,
|
||||||
String regCmpn,
|
String regCmpn,
|
||||||
@@ -171,12 +187,10 @@ public class TSendEntity {
|
|||||||
return from(
|
return from(
|
||||||
req,
|
req,
|
||||||
req.getDestInfo(),
|
req.getDestInfo(),
|
||||||
sendTy,
|
tmplat,
|
||||||
sendResult,
|
sendResult,
|
||||||
itrntPrjctCd,
|
|
||||||
req.getReqstSvc(),
|
req.getReqstSvc(),
|
||||||
req.getPrjctCd(),
|
req.getPrjctCd(),
|
||||||
req.getTmplatIdx(),
|
|
||||||
msgTitle,
|
msgTitle,
|
||||||
msgBody,
|
msgBody,
|
||||||
regCmpn,
|
regCmpn,
|
||||||
@@ -191,12 +205,10 @@ public class TSendEntity {
|
|||||||
public static TSendEntity from(
|
public static TSendEntity from(
|
||||||
SendRequestBasicDto basic,
|
SendRequestBasicDto basic,
|
||||||
DestInfoDto dest,
|
DestInfoDto dest,
|
||||||
SendType sendTy,
|
TemplateDto tmplat,
|
||||||
SendInternalResultDto sendResult,
|
SendInternalResultDto sendResult,
|
||||||
String itrntPrjctCd,
|
|
||||||
String reqstSvc,
|
String reqstSvc,
|
||||||
String prjctCd,
|
String prjctCd,
|
||||||
Long tmplatIdx,
|
|
||||||
String msgTitle,
|
String msgTitle,
|
||||||
String msgBody,
|
String msgBody,
|
||||||
String regCmpn,
|
String regCmpn,
|
||||||
@@ -214,21 +226,25 @@ public class TSendEntity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Short sendCorp = sendTy == SendType.EMAIL ? SendCorpType.PRINGO.getCode()
|
Short sendCorp = tmplat.getTmplatTy() == SendType.EMAIL ? SendCorpType.PRINGO.getCode()
|
||||||
: SendCorpType.BIZ_PPURIO.getCode();
|
: SendCorpType.BIZ_PPURIO.getCode();
|
||||||
|
|
||||||
return TSendEntity.builder()
|
return TSendEntity.builder()
|
||||||
.cmid(sendResult.getCmid())
|
.cmid(sendResult.getCmid())
|
||||||
.bulkSendKey(bulkSendKey)
|
.bulkSendKey(bulkSendKey)
|
||||||
.sendTy(sendTy.getCode())
|
.sendTy(tmplat.getTmplatTy().getCode())
|
||||||
.resve(resve)
|
.resve(resve)
|
||||||
.sendCorp(sendCorp)
|
.sendCorp(sendCorp)
|
||||||
.sendStatus(sendResult.getStatus().getCode())
|
.sendStatus(sendResult.getStatus().getCode())
|
||||||
.resultCode(sendResult.getResultCode())
|
.resultCode(sendResult.getResultCode())
|
||||||
.itrntPrjctCd(itrntPrjctCd)
|
.itrntPrjctCd(tmplat.getItrntPrjctCd())
|
||||||
.reqstSvc(reqstSvc)
|
.reqstSvc(reqstSvc)
|
||||||
.prjctCd(prjctCd)
|
.prjctCd(prjctCd)
|
||||||
.tmplatIdx(tmplatIdx)
|
.tmplatIdx(tmplat.getTmplatIdx())
|
||||||
|
.senderKey(tmplat.getSenderKey())
|
||||||
|
.kkoTmplatCd(tmplat.getKkoTmplatCd())
|
||||||
|
.nationCd(tmplat.getNationCd())
|
||||||
|
.atchFl(tmplat.getAtchFl())
|
||||||
.sendEml(basic.getSendEml())
|
.sendEml(basic.getSendEml())
|
||||||
.sendTel(basic.getSendTel())
|
.sendTel(basic.getSendTel())
|
||||||
.sendNm(basic.getSendNm())
|
.sendNm(basic.getSendNm())
|
||||||
|
|||||||
@@ -52,9 +52,25 @@ public class TTmplatEntity {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Lob
|
@Lob
|
||||||
@Column(name = "tmplat_body", nullable = false)
|
@Column(name = "tmplat_body", nullable = false, columnDefinition = "TEXT")
|
||||||
private String tmplatBody;
|
private String tmplatBody;
|
||||||
|
|
||||||
|
@Size(max = 40)
|
||||||
|
@Column(name = "sender_key", length = 40)
|
||||||
|
private String senderKey;
|
||||||
|
|
||||||
|
@Size(max = 64)
|
||||||
|
@Column(name = "kko_tmplat_cd", length = 64)
|
||||||
|
private String kkoTmplatCd;
|
||||||
|
|
||||||
|
@Size(max = 5)
|
||||||
|
@Column(name = "nation_cd", length = 5)
|
||||||
|
private String nationCd;
|
||||||
|
|
||||||
|
@Size(max = 1000)
|
||||||
|
@Column(name = "atch_fl", length = 1000)
|
||||||
|
private String atchFl;
|
||||||
|
|
||||||
@Column(name = "delay_time")
|
@Column(name = "delay_time")
|
||||||
private Short delayTime;
|
private Short delayTime;
|
||||||
|
|
||||||
@@ -103,14 +119,18 @@ public class TTmplatEntity {
|
|||||||
LocalDateTime regDt) {
|
LocalDateTime regDt) {
|
||||||
return TTmplatEntity.builder()
|
return TTmplatEntity.builder()
|
||||||
.itrntPrjctCd(itrntPrjctCd)
|
.itrntPrjctCd(itrntPrjctCd)
|
||||||
.tmplatTy(template.tmplatTy.getCode())
|
.tmplatTy(template.getTmplatTy().getCode())
|
||||||
.tmplatNm(template.tmplatNm)
|
.tmplatNm(template.getTmplatNm())
|
||||||
.tmplatTitle(template.tmplatTitle)
|
.tmplatTitle(template.getTmplatTitle())
|
||||||
.tmplatBody(template.tmplatBody)
|
.tmplatBody(template.getTmplatBody())
|
||||||
.delayTime(template.delayTime)
|
.senderKey(template.getSenderKey())
|
||||||
.sendTel(template.sendTel)
|
.kkoTmplatCd(template.getKkoTmplatCd())
|
||||||
.sendEml(template.sendEml)
|
.nationCd(template.getNationCd())
|
||||||
.sendNm(template.sendNm)
|
.atchFl(template.getAtchFl())
|
||||||
|
.delayTime(template.getDelayTime())
|
||||||
|
.sendTel(template.getSendTel())
|
||||||
|
.sendEml(template.getSendEml())
|
||||||
|
.sendNm(template.getSendNm())
|
||||||
.regUser(regUser)
|
.regUser(regUser)
|
||||||
.regDt(regDt)
|
.regDt(regDt)
|
||||||
.del(false)
|
.del(false)
|
||||||
@@ -119,14 +139,18 @@ public class TTmplatEntity {
|
|||||||
|
|
||||||
public void updateFrom(TemplateBasicDto template, String modUser, LocalDateTime modDt) {
|
public void updateFrom(TemplateBasicDto template, String modUser, LocalDateTime modDt) {
|
||||||
// 기본 정보 갱신
|
// 기본 정보 갱신
|
||||||
this.tmplatTy = template.tmplatTy.getCode();
|
this.tmplatTy = template.getTmplatTy().getCode();
|
||||||
this.tmplatNm = template.tmplatNm;
|
this.tmplatNm = template.getTmplatNm();
|
||||||
this.tmplatTitle = template.tmplatTitle;
|
this.tmplatTitle = template.getTmplatTitle();
|
||||||
this.tmplatBody = template.tmplatBody;
|
this.tmplatBody = template.getTmplatBody();
|
||||||
this.delayTime = template.delayTime;
|
this.senderKey = template.getSenderKey();
|
||||||
this.sendTel = template.sendTel;
|
this.kkoTmplatCd = template.getKkoTmplatCd();
|
||||||
this.sendEml = template.sendEml;
|
this.nationCd = template.getNationCd();
|
||||||
this.sendNm = template.sendNm;
|
this.atchFl = template.getAtchFl();
|
||||||
|
this.delayTime = template.getDelayTime();
|
||||||
|
this.sendTel = template.getSendTel();
|
||||||
|
this.sendEml = template.getSendEml();
|
||||||
|
this.sendNm = template.getSendNm();
|
||||||
|
|
||||||
// 수정 메타 갱신
|
// 수정 메타 갱신
|
||||||
this.modUser = modUser;
|
this.modUser = modUser;
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
|||||||
@Query("""
|
@Query("""
|
||||||
select coalesce(min(s.sendIdx), 0)
|
select coalesce(min(s.sendIdx), 0)
|
||||||
from TSendEntity s
|
from TSendEntity s
|
||||||
where s.sendTy = :sendTy and s.sendStatus = 0
|
where s.sendTy in :sendTyList and s.sendStatus = 0
|
||||||
""")
|
""")
|
||||||
long findMinSendIdxBySendTy(short sendTy);
|
long findMinSendIdxBySendTyList(List<Short> sendTyList);
|
||||||
|
|
||||||
|
|
||||||
@Query("""
|
@Query("""
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.kri.notihub.server.scheduler;
|
package com.kri.notihub.server.scheduler;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.common.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.util.StringUtil;
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
@@ -10,7 +11,7 @@ import com.kri.notihub.server.persistence.entity.TSendEntity;
|
|||||||
import com.kri.notihub.server.persistence.repository.BizLogRepository;
|
import com.kri.notihub.server.persistence.repository.BizLogRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
import com.kri.notihub.server.service.SmsSendCursorStore;
|
import com.kri.notihub.server.service.BizppurioSendCursorStore;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -31,7 +32,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class BizLogResultScheduler {
|
public class BizLogResultScheduler {
|
||||||
|
|
||||||
private final SmsSendCursorStore cursorStore;
|
private final BizppurioSendCursorStore cursorStore;
|
||||||
private final SendRepository sendRepository;
|
private final SendRepository sendRepository;
|
||||||
private final BizLogRepository bizLogRepository;
|
private final BizLogRepository bizLogRepository;
|
||||||
private final BulkSendRepository bulkSendRepository;
|
private final BulkSendRepository bulkSendRepository;
|
||||||
@@ -151,7 +152,7 @@ public class BizLogResultScheduler {
|
|||||||
Map<String, Integer> failDelta
|
Map<String, Integer> failDelta
|
||||||
) {
|
) {
|
||||||
String key = s.getBulkSendKey();
|
String key = s.getBulkSendKey();
|
||||||
if (key == null || key.isBlank()) {
|
if (StringUtil.isNullOrBlank(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!bulkMap.containsKey(key)) {
|
if (!bulkMap.containsKey(key)) {
|
||||||
|
|||||||
@@ -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;
|
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 com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SmsSendCursorStore {
|
public class BizppurioSendCursorStore {
|
||||||
|
|
||||||
// 프로세스 전역 커서(스레드 세이프)
|
// 프로세스 전역 커서(스레드 세이프)
|
||||||
private static final java.util.concurrent.atomic.AtomicLong CURSOR = new java.util.concurrent.atomic.AtomicLong(
|
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)로 초기화
|
// 서비스 기동 시: t_send에서 sendTy=SMS의 max(send_idx)로 초기화
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
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);
|
CURSOR.set(maxSendIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.kri.notihub.server.service;
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
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.consts.NotihubConst;
|
||||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||||
import com.kri.notihub.server.common.external.pringo.PringoApiClient;
|
import com.kri.notihub.server.common.external.pringo.PringoApiClient;
|
||||||
@@ -56,7 +56,7 @@ class EmailResultUpdater {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
short resultCode = CommonUtil.safeParseShort(item.getStatus(), NotihubConst.EMAIL_NOT_RESULT);
|
short resultCode = NumericUtil.safeParseShort(item.getStatus(), NotihubConst.EMAIL_NOT_RESULT);
|
||||||
|
|
||||||
//resultCode를 대상으로 Success인지 아닌지 판별 필요
|
//resultCode를 대상으로 Success인지 아닌지 판별 필요
|
||||||
SendStatusType sendStatus =
|
SendStatusType sendStatus =
|
||||||
|
|||||||
@@ -1,35 +1,19 @@
|
|||||||
package com.kri.notihub.server.service;
|
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.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.enums.SendType;
|
||||||
import com.kri.notihub.server.common.external.pringo.PringoApiClient;
|
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.BulkSendRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class SendEmailService extends SendService {
|
public class SendEmailService extends AbstractPringoSendService {
|
||||||
|
|
||||||
private final PringoApiClient pringoApiClient;
|
|
||||||
private final EmailResultPoller emailResultPoller;
|
|
||||||
private final EmailResultUpdater emailResultUpdater;
|
|
||||||
|
|
||||||
public SendEmailService(
|
public SendEmailService(
|
||||||
TemplateRepository templateRepository,
|
TemplateRepository templateRepository,
|
||||||
@@ -37,132 +21,13 @@ public class SendEmailService extends SendService {
|
|||||||
SendRepository sendRepository,
|
SendRepository sendRepository,
|
||||||
TemplateService templateService,
|
TemplateService templateService,
|
||||||
PringoApiClient pringoApiClient,
|
PringoApiClient pringoApiClient,
|
||||||
EmailResultPoller emailResultPoller,
|
EmailResultPoller emailResultPoller
|
||||||
EmailResultUpdater emailResultUpdater
|
|
||||||
) {
|
) {
|
||||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
super(templateRepository, bulkSendRepository, sendRepository, templateService, pringoApiClient, emailResultPoller);
|
||||||
this.pringoApiClient = pringoApiClient;
|
|
||||||
this.emailResultPoller = emailResultPoller;
|
|
||||||
this.emailResultUpdater = emailResultUpdater;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SendType getSendType() {
|
protected ChannelType defaultChannelType() {
|
||||||
return SendType.EMAIL;
|
return ChannelType.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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 static org.apache.commons.lang3.StringUtils.firstNonBlank;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.common.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.util.StringUtil;
|
||||||
import com.kri.common.web.BusinessException;
|
import com.kri.common.web.BusinessException;
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
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.SendStatusType;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
||||||
@@ -69,7 +71,7 @@ public abstract class SendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
||||||
validateTemplateType(tmplat, getSendType());
|
validateTemplateType(tmplat);
|
||||||
|
|
||||||
TBulkSendEntity bulk = TBulkSendEntity.from(req, now);
|
TBulkSendEntity bulk = TBulkSendEntity.from(req, now);
|
||||||
TBulkSendEntity saved = bulkSendRepository.save(bulk);
|
TBulkSendEntity saved = bulkSendRepository.save(bulk);
|
||||||
@@ -77,13 +79,15 @@ public abstract class SendService {
|
|||||||
return saved.getBulkSendKey();
|
return saved.getBulkSendKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateTemplateType(TemplateDto tmplat, SendType requiredType) {
|
protected void validateTemplateType(TemplateDto tmplat) {
|
||||||
|
ChannelType requiredType = getChannelType();
|
||||||
|
|
||||||
if (tmplat == null || requiredType == null) {
|
if (tmplat == null || requiredType == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tmplatTy = tmplat.getTmplatTy().getCode() / 10;
|
int tmplatTy = tmplat.getTmplatTy().getCode() / 10;
|
||||||
int required = requiredType.getCode() / 10;
|
int required = requiredType.getCode();
|
||||||
|
|
||||||
if (tmplat.getTmplatTy() == null || tmplatTy != required) {
|
if (tmplat.getTmplatTy() == null || tmplatTy != required) {
|
||||||
throw BusinessException.badRequest("WRONG_TEMPLATE_TYPE", "템플릿 타입이 잘 못 됐습니다.")
|
throw BusinessException.badRequest("WRONG_TEMPLATE_TYPE", "템플릿 타입이 잘 못 됐습니다.")
|
||||||
@@ -112,16 +116,16 @@ public abstract class SendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
||||||
validateTemplateType(tmplat, getSendType());
|
validateTemplateType(tmplat);
|
||||||
|
|
||||||
LocalDateTime sendDt = req.getSendDt() != null ? req.getSendDt() : now;
|
LocalDateTime sendDt = req.getSendDt() != null ? req.getSendDt() : now;
|
||||||
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
||||||
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
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());
|
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
||||||
|
|
||||||
if (sendFrom == null || sendFrom.isBlank()) {
|
if (sendFrom == null || sendFrom.isBlank()) {
|
||||||
if (getSendType() == SendType.EMAIL) {
|
if (isEmailChannel()) {
|
||||||
throw BusinessException.badRequest("SEND_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
throw BusinessException.badRequest("SEND_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
||||||
} else {
|
} else {
|
||||||
throw BusinessException.badRequest("SEND_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
throw BusinessException.badRequest("SEND_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
||||||
@@ -129,9 +133,9 @@ public abstract class SendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DestInfoDto dest = req.getDestInfo();
|
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 (sendTo == null || sendTo.isBlank()) {
|
||||||
if (getSendType() == SendType.EMAIL) {
|
if (isEmailChannel()) {
|
||||||
throw BusinessException.badRequest("DEST_EMAIL_REQUIRED", "destEml은 필수 입니다.");
|
throw BusinessException.badRequest("DEST_EMAIL_REQUIRED", "destEml은 필수 입니다.");
|
||||||
} else {
|
} else {
|
||||||
throw BusinessException.badRequest("DEST_TEL_REQUIRED", "destTel은 필수 입니다.");
|
throw BusinessException.badRequest("DEST_TEL_REQUIRED", "destTel은 필수 입니다.");
|
||||||
@@ -159,9 +163,8 @@ public abstract class SendService {
|
|||||||
List<TSendEntity> sendInfo = new ArrayList<>(List.of(
|
List<TSendEntity> sendInfo = new ArrayList<>(List.of(
|
||||||
TSendEntity.from(
|
TSendEntity.from(
|
||||||
req,
|
req,
|
||||||
tmplat.getTmplatTy(),
|
tmplat,
|
||||||
sendResult,
|
sendResult,
|
||||||
tmplat.getItrntPrjctCd(),
|
|
||||||
msgTitle,
|
msgTitle,
|
||||||
msgBody,
|
msgBody,
|
||||||
regCmpn,
|
regCmpn,
|
||||||
@@ -203,18 +206,18 @@ public abstract class SendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TemplateDto tmplat = templateService.getTemplate(bulk.getTmplatIdx());
|
TemplateDto tmplat = templateService.getTemplate(bulk.getTmplatIdx());
|
||||||
validateTemplateType(tmplat, getSendType());
|
validateTemplateType(tmplat);
|
||||||
|
|
||||||
Boolean isResve = bulk.getResve();
|
Boolean isResve = bulk.getResve();
|
||||||
LocalDateTime sendDt = bulk.getSendDt() != null ? bulk.getSendDt() : now;
|
LocalDateTime sendDt = bulk.getSendDt() != null ? bulk.getSendDt() : now;
|
||||||
|
|
||||||
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
||||||
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
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());
|
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
||||||
|
|
||||||
if (sendFrom == null || sendFrom.isBlank()) {
|
if (sendFrom == null || sendFrom.isBlank()) {
|
||||||
if (getSendType() == SendType.EMAIL) {
|
if (isEmailChannel()) {
|
||||||
throw BusinessException.badRequest("SENDER_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
throw BusinessException.badRequest("SENDER_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
||||||
} else {
|
} else {
|
||||||
throw BusinessException.badRequest("SENDER_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
throw BusinessException.badRequest("SENDER_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
||||||
@@ -237,7 +240,7 @@ public abstract class SendService {
|
|||||||
List<DestInfoDto> chunk = req.getDestInfoList().subList(offset, end);
|
List<DestInfoDto> chunk = req.getDestInfoList().subList(offset, end);
|
||||||
|
|
||||||
for (DestInfoDto dest : chunk) {
|
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()) {
|
if (dest == null || sendTo.isBlank()) {
|
||||||
failCnt++;
|
failCnt++;
|
||||||
continue;
|
continue;
|
||||||
@@ -267,12 +270,10 @@ public abstract class SendService {
|
|||||||
TSendEntity.from(
|
TSendEntity.from(
|
||||||
req,
|
req,
|
||||||
dest,
|
dest,
|
||||||
tmplat.getTmplatTy(),
|
tmplat,
|
||||||
sendResult,
|
sendResult,
|
||||||
tmplat.getItrntPrjctCd(),
|
|
||||||
bulk.getReqstSvc(),
|
bulk.getReqstSvc(),
|
||||||
bulk.getPrjctCd(),
|
bulk.getPrjctCd(),
|
||||||
bulk.getTmplatIdx(),
|
|
||||||
msgTitle,
|
msgTitle,
|
||||||
msgBody,
|
msgBody,
|
||||||
bulk.getRegCmpn(),
|
bulk.getRegCmpn(),
|
||||||
@@ -284,7 +285,7 @@ public abstract class SendService {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (getSendType() == SendType.EMAIL) {
|
if (isEmailChannel()) {
|
||||||
// 발송 간 딜레이(Pringo rate-limit 대응)
|
// 발송 간 딜레이(Pringo rate-limit 대응)
|
||||||
long delay = Math.max(tmplat.getDelayTime(), NotihubConst.EMAIL_DELAY);
|
long delay = Math.max(tmplat.getDelayTime(), NotihubConst.EMAIL_DELAY);
|
||||||
sleepSilently(delay);
|
sleepSilently(delay);
|
||||||
@@ -311,7 +312,7 @@ public abstract class SendService {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("\\[\\$([^\\]]+)]");
|
Pattern pattern = Pattern.compile("(?:\\[\\$|#\\{)([^\\]}]+)(?:]|})"); // [$A] 또는 #{A}
|
||||||
Matcher matcher = pattern.matcher(text);
|
Matcher matcher = pattern.matcher(text);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
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;
|
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.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.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.entity.TSendEntity;
|
||||||
import com.kri.notihub.server.persistence.repository.BizMsgRepository;
|
import com.kri.notihub.server.persistence.repository.BizMsgRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
import com.kri.notihub.server.persistence.repository.BulkSendRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
import com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SendSmsService extends SendService {
|
public class SendSmsService extends AbstractBizppurioSendService {
|
||||||
|
|
||||||
private final BizMsgRepository bizMsgRepository;
|
|
||||||
|
|
||||||
public SendSmsService(
|
public SendSmsService(
|
||||||
BizMsgRepository bizMsgRepository,
|
|
||||||
TemplateRepository templateRepository,
|
TemplateRepository templateRepository,
|
||||||
BulkSendRepository bulkSendRepository,
|
BulkSendRepository bulkSendRepository,
|
||||||
|
BizMsgRepository bizMsgRepository,
|
||||||
SendRepository sendRepository,
|
SendRepository sendRepository,
|
||||||
TemplateService templateService
|
TemplateService templateService
|
||||||
) {
|
) {
|
||||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
super(templateRepository, bulkSendRepository, bizMsgRepository, sendRepository, templateService);
|
||||||
this.bizMsgRepository = bizMsgRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SendType getSendType() {
|
protected ChannelType defaultChannelType() {
|
||||||
//일단 SMS로 내보내고 발송시에 Template의 SendType 또는 MessageBody, 제목여부로 강화 필요
|
return ChannelType.SMS;
|
||||||
return SendType.SMS; // 프로젝트 enum 기준
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SendInternalResultDto doSendInternal(
|
protected short standbyResultCode(SendType sendType) {
|
||||||
Boolean isResve,
|
return sendType == SendType.LMS_MMS
|
||||||
String bulkSendKey,
|
? NotihubConst.LMS_MMS_STANDBY
|
||||||
SendType sendType,
|
: NotihubConst.SMS_STANDBY;
|
||||||
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
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPersistSendEntities(List<TSendEntity> persisted) {
|
protected List<Short> sendTypeList() {
|
||||||
if (persisted == null || persisted.isEmpty()) {
|
return NotihubConst.SMS_TYPE_CODE_LIST;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
@Override
|
||||||
if (s == null) {
|
protected String subject(TSendEntity sendEntity) {
|
||||||
continue;
|
return sendEntity.getSendTy().equals(SendType.SMS.getCode()) ? null : sendEntity.getMsgTitle();
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.kri.notihub.server.service;
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.common.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.util.StringUtil;
|
||||||
import com.kri.common.web.BusinessException;
|
import com.kri.common.web.BusinessException;
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
import com.kri.notihub.server.common.enums.ChannelType;
|
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 com.kri.notihub.server.persistence.repository.TemplateRepository;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Log4j2
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TemplateService {
|
public class TemplateService {
|
||||||
@@ -28,8 +32,11 @@ public class TemplateService {
|
|||||||
private final TemplateEventLogRepository templateEventLogRepository;
|
private final TemplateEventLogRepository templateEventLogRepository;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public TemplateDto createTemplate(String itrntPrjctCd, TemplateBasicDto template,
|
public TemplateDto createTemplate(
|
||||||
String regUser) {
|
String itrntPrjctCd,
|
||||||
|
TemplateBasicDto template,
|
||||||
|
String regUser
|
||||||
|
) {
|
||||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
validateBySendType(template);
|
validateBySendType(template);
|
||||||
@@ -47,12 +54,13 @@ public class TemplateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<TemplateSummaryDto> getTemplateList(ChannelType chnnlTy, String itrntPrjctCd) {
|
public List<TemplateSummaryDto> getTemplateList(ChannelType chnnlTy, String itrntPrjctCd) {
|
||||||
List<Short> tmplatTyList = chnnlTy == ChannelType.SMS
|
List<Short> tmplatTyList = getSendTypeCodeList(chnnlTy);
|
||||||
? NotihubConst.MOBILE_TYPE_CODE_LIST
|
|
||||||
: NotihubConst.EMAIL_TYPE_CODE_LIST;
|
|
||||||
|
|
||||||
return templateRepository.findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(tmplatTyList,
|
return templateRepository.findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(
|
||||||
itrntPrjctCd).stream()
|
tmplatTyList,
|
||||||
|
itrntPrjctCd
|
||||||
|
)
|
||||||
|
.stream()
|
||||||
.map(TemplateSummaryDto::from)
|
.map(TemplateSummaryDto::from)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
@@ -133,21 +141,30 @@ public class TemplateService {
|
|||||||
templateEventLogRepository.save(log);
|
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) {
|
private void validateBySendType(TemplateBasicDto template) {
|
||||||
//공통 검증
|
//공통 검증
|
||||||
if (template.getTmplatTy() == null) {
|
if (template.getTmplatTy() == null) {
|
||||||
throw BusinessException.badRequest("NULL TYPE", "템플릿 타입은 필수입니다.");
|
throw BusinessException.badRequest("NULL TYPE", "템플릿 타입은 필수입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.getTmplatNm() == null || template.getTmplatNm().isBlank()) {
|
if (StringUtil.isNullOrBlank(template.getTmplatNm())) {
|
||||||
throw BusinessException.badRequest("EMPTY_NAME", "템플릿 명은 필수입니다.");
|
throw BusinessException.badRequest("EMPTY_NAME", "템플릿 명은 필수입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.getTmplatBody() == null || template.getTmplatBody().isBlank()) {
|
if (StringUtil.isNullOrBlank(template.getTmplatBody())) {
|
||||||
throw BusinessException.badRequest("EMPTY_BODY", "내용은 필수입니다.");
|
throw BusinessException.badRequest("EMPTY_BODY", "내용은 필수입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (template.getSendNm() == null || template.getSendNm().isBlank()) {
|
if (StringUtil.isNullOrBlank(template.getSendNm())) {
|
||||||
throw BusinessException.badRequest("EMPTY_SEND_NAME", "발신자 명은 필수입니다.");
|
throw BusinessException.badRequest("EMPTY_SEND_NAME", "발신자 명은 필수입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,22 +177,36 @@ public class TemplateService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SendType ty = template.getTmplatTy();
|
Short ty = template.getTmplatTy().getCode();
|
||||||
if (ty == SendType.EMAIL) {
|
if (NotihubConst.EMAIL_TYPE_CODE_LIST.contains(ty)) {
|
||||||
if (template.getSendEml() == null || template.getSendEml().isBlank()) {
|
if (StringUtil.isNullOrBlank(template.getSendEml())) {
|
||||||
throw BusinessException.badRequest("EMPTY_EMAIL", "이메일은 필수입니다.");
|
throw BusinessException.badRequest("EMPTY_EMAIL", "이메일은 필수입니다.");
|
||||||
}
|
}
|
||||||
if (template.getTmplatTitle() == null || template.getTmplatTitle().isBlank()) {
|
if (StringUtil.isNullOrBlank(template.getTmplatTitle())) {
|
||||||
throw BusinessException.badRequest("EMPTY_TITLE", "제목은 필수입니다.");
|
throw BusinessException.badRequest("EMPTY_TITLE", "제목은 필수입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
template.setSendTel(null);
|
template.setSendTel(null);
|
||||||
} else if (NotihubConst.MOBILE_TYPE_LIST.contains(ty)) {
|
} else if (NotihubConst.SMS_TYPE_CODE_LIST.contains(ty) || NotihubConst.KKO_TYPE_CODE_LIST.contains(ty)) {
|
||||||
if (template.getSendTel() == null || template.getSendTel().isBlank()) {
|
if (StringUtil.isNullOrBlank(template.getSendTel())) {
|
||||||
throw BusinessException.badRequest("EMPTY_TEL", "발송번호는 필수입니다.");
|
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.setTmplatTitle(null);
|
||||||
}
|
}
|
||||||
template.setSendEml(null);
|
template.setSendEml(null);
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ spring:
|
|||||||
hibernate:
|
hibernate:
|
||||||
dialect: org.hibernate.dialect.MySQL8Dialect
|
dialect: org.hibernate.dialect.MySQL8Dialect
|
||||||
format_sql: true
|
format_sql: true
|
||||||
show_sql: true
|
show_sql: false
|
||||||
open-in-view: false
|
open-in-view: false
|
||||||
|
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org.hibernate.SQL: debug
|
org.hibernate.SQL: DEBUG
|
||||||
org.hibernate.type.descriptor.sql.BasicBinder: trace
|
org.hibernate.orm.jdbc.bind: TRACE
|
||||||
|
org.hibernate.orm.jdbc.extract: TRACE
|
||||||
Reference in New Issue
Block a user