Compare commits
10 Commits
8c9ae42650
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| cab3eb4ba1 | |||
| e6f2603a29 | |||
| 9ace29400f | |||
| 00dbcec1dc | |||
| efc49bea23 | |||
| 674e8f20f0 | |||
| 774188088b | |||
| 6bd9b0902b | |||
| 925b6744c0 | |||
| 6daa84ac95 |
@@ -38,7 +38,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "com.kri.common:starter:beta.1.0.61"
|
implementation "com.kri.common:starter:beta.1.1.02"
|
||||||
|
|
||||||
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'
|
||||||
|
|||||||
@@ -1,38 +1,35 @@
|
|||||||
package com.kri.notihub.server.common.consts;
|
package com.kri.notihub.server.common.consts;
|
||||||
|
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class NotihubConst {
|
public final class NotihubConst {
|
||||||
private 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;
|
||||||
public static final int ROW_WINDOW = 500;
|
public static final int ROW_WINDOW = 500;
|
||||||
|
|
||||||
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<Short> SMS_TYPE_CODE_LIST = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
||||||
public static final List<SendType> MOBILE_TYPE_LIST = List.of(SendType.SMS, SendType.LMS_MMS);
|
public static final List<Short> KKO_TYPE_CODE_LIST = List.of(SendType.KKO_AT.getCode());
|
||||||
|
|
||||||
public static final List<Short> MOBILE_TYPE_CODE_LIST = List.of(SendType.SMS.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;
|
||||||
public static final short EMAIL_PENDING = (short) 111; // 발송요청은 성공했으나 json_return 미조회
|
public static final short EMAIL_PENDING = (short) 111; // 발송요청은 성공했으나 json_return 미조회
|
||||||
public static final short EMAIL_SEND_FAIL = (short) 109; // 발송요청 실패(또는 return_key 미수신)
|
public static final short EMAIL_SEND_FAIL = (short) 109; // 발송요청 실패(또는 return_key 미수신)
|
||||||
public static final short EMAIL_NOT_RESULT = (short) 119; // json_return 조회 실패/결과없음(최종상태 확보 실패)
|
public static final short EMAIL_NOT_RESULT = (short) 119; // json_return 조회 실패/결과없음(최종상태 확보 실패)
|
||||||
public static final short EMAIL_SUCCESS = 250;
|
public static final short EMAIL_SUCCESS = 250;
|
||||||
|
|
||||||
public static final short SMS_STANDBY = 4000;
|
public static final short SMS_STANDBY = 4000;
|
||||||
public static final short SMS_SUCCESS = 4100;
|
public static final short SMS_SUCCESS = 4100;
|
||||||
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;
|
||||||
|
|
||||||
|
private NotihubConst() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.common.enums;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -21,9 +22,13 @@ public enum ChannelType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
public static ChannelType fromCode(Short code) {
|
public static ChannelType fromCode(Short code) {
|
||||||
if (code == null) return null;
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (ChannelType s : values()) {
|
for (ChannelType s : values()) {
|
||||||
if (s.code == code) return s;
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown ChannelType code: " + code);
|
throw new IllegalArgumentException("Unknown ChannelType code: " + code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.common.enums;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -16,9 +16,13 @@ public enum SendCorpType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
public static SendCorpType fromCode(Short code) {
|
public static SendCorpType fromCode(Short code) {
|
||||||
if (code == null) return null;
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (SendCorpType s : values()) {
|
for (SendCorpType s : values()) {
|
||||||
if (s.code == code) return s;
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown SendCorpType code: " + code);
|
throw new IllegalArgumentException("Unknown SendCorpType code: " + code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.common.enums;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -15,9 +15,13 @@ public enum SendEmailType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
public static SendEmailType fromCode(Short code) {
|
public static SendEmailType fromCode(Short code) {
|
||||||
if (code == null) return null;
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (SendEmailType s : values()) {
|
for (SendEmailType s : values()) {
|
||||||
if (s.code == code) return s;
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown SendEmailType code: " + code);
|
throw new IllegalArgumentException("Unknown SendEmailType code: " + 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.feature.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.common.enums;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -16,9 +16,13 @@ public enum SendSmsType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
public static SendSmsType fromCode(Short code) {
|
public static SendSmsType fromCode(Short code) {
|
||||||
if (code == null) return null;
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (SendSmsType s : values()) {
|
for (SendSmsType s : values()) {
|
||||||
if (s.code == code) return s;
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown SendSmsType code: " + code);
|
throw new IllegalArgumentException("Unknown SendSmsType code: " + code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.common.enums;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -22,9 +22,13 @@ public enum SendStatusType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
public static SendStatusType fromCode(Short code) {
|
public static SendStatusType fromCode(Short code) {
|
||||||
if (code == null) return null;
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (SendStatusType s : values()) {
|
for (SendStatusType s : values()) {
|
||||||
if (s.code == code) return s;
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown SendStatusType code: " + code);
|
throw new IllegalArgumentException("Unknown SendStatusType code: " + code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.kri.notihub.server.common.enums;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
@@ -21,9 +22,13 @@ public enum SendType implements CodeEnum<Short> {
|
|||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||||
public static SendType fromCode(Short code) {
|
public static SendType fromCode(Short code) {
|
||||||
if (code == null) return null;
|
if (code == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (SendType s : values()) {
|
for (SendType s : values()) {
|
||||||
if (s.code == code) return s;
|
if (s.code == code) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unknown SendType code: " + code);
|
throw new IllegalArgumentException("Unknown SendType code: " + code);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.kri.notihub.server.common.enums;
|
package com.kri.notihub.server.common.enums;
|
||||||
|
|
||||||
import com.kri.common.enums.CodeEnum;
|
import com.kri.common.feature.enums.CodeEnum;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
|||||||
@@ -4,35 +4,36 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.kri.common.http.ExternalApiClient;
|
import com.kri.common.feature.http.ExternalApiClient;
|
||||||
import com.kri.common.http.ExternalApiResponse;
|
import com.kri.common.feature.http.ExternalApiResponse;
|
||||||
import com.kri.notihub.server.common.external.pringo.dto.*;
|
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnErrorDto;
|
||||||
|
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnItemDto;
|
||||||
|
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnRequestDto;
|
||||||
|
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnResponseDto;
|
||||||
|
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendRequestDto;
|
||||||
|
import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendResponseDto;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PringoApiClient {
|
public class PringoApiClient {
|
||||||
@Value("${kri.api.pringo.url}")
|
|
||||||
private String pringoBaseUrl;
|
|
||||||
|
|
||||||
@Value("${kri.api.pringo.apiKey}")
|
|
||||||
private String apiKey;
|
|
||||||
|
|
||||||
@Value("${kri.api.pringo.template-id}")
|
|
||||||
private String templateId;
|
|
||||||
|
|
||||||
private final ExternalApiClient externalApiClient = new ExternalApiClient();
|
private final ExternalApiClient externalApiClient = new ExternalApiClient();
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
@Value("${kri.api.pringo.url}")
|
||||||
|
private String pringoBaseUrl;
|
||||||
|
@Value("${kri.api.pringo.apiKey}")
|
||||||
|
private String apiKey;
|
||||||
|
@Value("${kri.api.pringo.template-id}")
|
||||||
|
private String templateId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pringo 자동메일 Json 발송
|
* Pringo 자동메일 Json 발송 POST {pringoBaseUrl}/json-send
|
||||||
* POST {pringoBaseUrl}/json-send
|
|
||||||
*/
|
*/
|
||||||
public PringoJsonSendResponseDto jsonSend(PringoJsonSendRequestDto request) {
|
public PringoJsonSendResponseDto jsonSend(PringoJsonSendRequestDto request) {
|
||||||
String url = String.format("%s/json-send", pringoBaseUrl);
|
String url = String.format("%s/json-send", pringoBaseUrl);
|
||||||
@@ -87,8 +88,7 @@ public class PringoApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pringo 자동메일 Json 조회
|
* Pringo 자동메일 Json 조회 POST {pringoBaseUrl}/json-return
|
||||||
* POST {pringoBaseUrl}/json-return
|
|
||||||
*/
|
*/
|
||||||
public PringoJsonReturnResponseDto jsonReturn(PringoJsonReturnRequestDto request) {
|
public PringoJsonReturnResponseDto jsonReturn(PringoJsonReturnRequestDto request) {
|
||||||
String url = String.format("%s/json-return", pringoBaseUrl);
|
String url = String.format("%s/json-return", pringoBaseUrl);
|
||||||
@@ -118,7 +118,8 @@ public class PringoApiClient {
|
|||||||
|
|
||||||
// 실패 형태 판별: result/msg가 있으면 오류 DTO로 본다
|
// 실패 형태 판별: result/msg가 있으면 오류 DTO로 본다
|
||||||
if (first.has("result") && first.has("msg")) {
|
if (first.has("result") && first.has("msg")) {
|
||||||
PringoJsonReturnErrorDto err = objectMapper.convertValue(first, PringoJsonReturnErrorDto.class);
|
PringoJsonReturnErrorDto err = objectMapper.convertValue(first,
|
||||||
|
PringoJsonReturnErrorDto.class);
|
||||||
return PringoJsonReturnResponseDto.builder()
|
return PringoJsonReturnResponseDto.builder()
|
||||||
.itemList(List.of())
|
.itemList(List.of())
|
||||||
.error(err)
|
.error(err)
|
||||||
@@ -127,7 +128,8 @@ public class PringoApiClient {
|
|||||||
|
|
||||||
// 성공 형태: row 리스트
|
// 성공 형태: row 리스트
|
||||||
List<PringoJsonReturnItemDto> items = objectMapper.convertValue(
|
List<PringoJsonReturnItemDto> items = objectMapper.convertValue(
|
||||||
root, new TypeReference<List<PringoJsonReturnItemDto>>() {}
|
root, new TypeReference<List<PringoJsonReturnItemDto>>() {
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return PringoJsonReturnResponseDto.builder()
|
return PringoJsonReturnResponseDto.builder()
|
||||||
@@ -140,7 +142,9 @@ public class PringoApiClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 편의 메서드: returnKey만으로 조회 */
|
/**
|
||||||
|
* 편의 메서드: returnKey만으로 조회
|
||||||
|
*/
|
||||||
public PringoJsonReturnResponseDto jsonReturn(String returnKey) {
|
public PringoJsonReturnResponseDto jsonReturn(String returnKey) {
|
||||||
PringoJsonReturnRequestDto req = PringoJsonReturnRequestDto.builder()
|
PringoJsonReturnRequestDto req = PringoJsonReturnRequestDto.builder()
|
||||||
.returnKey(returnKey)
|
.returnKey(returnKey)
|
||||||
@@ -148,13 +152,16 @@ public class PringoApiClient {
|
|||||||
return jsonReturn(req);
|
return jsonReturn(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 편의 메서드: long도 지원 */
|
/**
|
||||||
|
* 편의 메서드: long도 지원
|
||||||
|
*/
|
||||||
public PringoJsonReturnResponseDto jsonReturn(long returnKey) {
|
public PringoJsonReturnResponseDto jsonReturn(long returnKey) {
|
||||||
return jsonReturn(Long.toString(returnKey));
|
return jsonReturn(Long.toString(returnKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 내부 fallback builder (원하시면 별도 클래스로 분리)
|
// 내부 fallback builder (원하시면 별도 클래스로 분리)
|
||||||
private static final class PringoJsonReturnErrorDtoBuilder {
|
private static final class PringoJsonReturnErrorDtoBuilder {
|
||||||
|
|
||||||
static PringoJsonReturnErrorDto noResultFallback() {
|
static PringoJsonReturnErrorDto noResultFallback() {
|
||||||
PringoJsonReturnErrorDto e = new PringoJsonReturnErrorDto();
|
PringoJsonReturnErrorDto e = new PringoJsonReturnErrorDto();
|
||||||
e.setResult("0");
|
e.setResult("0");
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ public class PringoJsonReturnErrorDto {
|
|||||||
@JsonProperty("typeAlias")
|
@JsonProperty("typeAlias")
|
||||||
private String typeAlias;
|
private String typeAlias;
|
||||||
|
|
||||||
/** 예: "0" */
|
/**
|
||||||
|
* 예: "0"
|
||||||
|
*/
|
||||||
private String result;
|
private String result;
|
||||||
|
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|||||||
@@ -18,19 +18,27 @@ public class PringoJsonReturnItemDto {
|
|||||||
@JsonProperty("email")
|
@JsonProperty("email")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
/** "O" / "X" */
|
/**
|
||||||
|
* "O" / "X"
|
||||||
|
*/
|
||||||
@JsonProperty("open")
|
@JsonProperty("open")
|
||||||
private String open;
|
private String open;
|
||||||
|
|
||||||
/** "O" / "X" */
|
/**
|
||||||
|
* "O" / "X"
|
||||||
|
*/
|
||||||
@JsonProperty("send_success")
|
@JsonProperty("send_success")
|
||||||
private String sendSuccess;
|
private String sendSuccess;
|
||||||
|
|
||||||
/** "yyyy-MM-dd HH:mm:ss" (문자열로 보관 권장) */
|
/**
|
||||||
|
* "yyyy-MM-dd HH:mm:ss" (문자열로 보관 권장)
|
||||||
|
*/
|
||||||
@JsonProperty("send_time")
|
@JsonProperty("send_time")
|
||||||
private String sendTime;
|
private String sendTime;
|
||||||
|
|
||||||
/** ex) "250" */
|
/**
|
||||||
|
* ex) "250"
|
||||||
|
*/
|
||||||
@JsonProperty("status")
|
@JsonProperty("status")
|
||||||
private String status;
|
private String status;
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
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 lombok.*;
|
import com.kri.common.feature.util.StringUtil;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -20,13 +25,23 @@ public class PringoJsonReturnRequestDto {
|
|||||||
private String returnKey;
|
private String returnKey;
|
||||||
|
|
||||||
public void applyDefaults(String defaultApiKey, String defaultTemplateId) {
|
public void applyDefaults(String defaultApiKey, String defaultTemplateId) {
|
||||||
if (this.apiKey == null || this.apiKey.isBlank()) this.apiKey = defaultApiKey;
|
if (this.apiKey == null || this.apiKey.isBlank()) {
|
||||||
if (this.templateId == null || this.templateId.isBlank()) this.templateId = defaultTemplateId;
|
this.apiKey = defaultApiKey;
|
||||||
|
}
|
||||||
|
if (StringUtil.isNullOrBlank(this.templateId)) {
|
||||||
|
this.templateId = defaultTemplateId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateRequired() {
|
public void validateRequired() {
|
||||||
if (apiKey == null || apiKey.isBlank()) throw new IllegalArgumentException("api_key is required.");
|
if (apiKey == null || apiKey.isBlank()) {
|
||||||
if (templateId == null || templateId.isBlank()) throw new IllegalArgumentException("template_id is required.");
|
throw new IllegalArgumentException("api_key is required.");
|
||||||
if (returnKey == null || returnKey.isBlank()) throw new IllegalArgumentException("return_key is required.");
|
}
|
||||||
|
if (templateId == null || templateId.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("template_id is required.");
|
||||||
|
}
|
||||||
|
if (returnKey == null || returnKey.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("return_key is required.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package com.kri.notihub.server.common.external.pringo.dto;
|
package com.kri.notihub.server.common.external.pringo.dto;
|
||||||
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -11,10 +14,14 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PringoJsonReturnResponseDto {
|
public class PringoJsonReturnResponseDto {
|
||||||
|
|
||||||
/** 조회 결과 row들(성공 시) */
|
/**
|
||||||
|
* 조회 결과 row들(성공 시)
|
||||||
|
*/
|
||||||
private List<PringoJsonReturnItemDto> itemList;
|
private List<PringoJsonReturnItemDto> itemList;
|
||||||
|
|
||||||
/** 조회 실패/없음(실패 시) */
|
/**
|
||||||
|
* 조회 실패/없음(실패 시)
|
||||||
|
*/
|
||||||
private PringoJsonReturnErrorDto error;
|
private PringoJsonReturnErrorDto error;
|
||||||
|
|
||||||
public boolean isSuccess() {
|
public boolean isSuccess() {
|
||||||
|
|||||||
@@ -5,12 +5,15 @@ import com.fasterxml.jackson.annotation.JsonAnySetter;
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -32,7 +35,9 @@ public class PringoJsonSendRequestDto {
|
|||||||
@JsonProperty("template_id")
|
@JsonProperty("template_id")
|
||||||
private String templateId;
|
private String templateId;
|
||||||
|
|
||||||
/** sender email */
|
/**
|
||||||
|
* sender email
|
||||||
|
*/
|
||||||
private String sender;
|
private String sender;
|
||||||
|
|
||||||
@JsonProperty("sender_name")
|
@JsonProperty("sender_name")
|
||||||
@@ -41,66 +46,38 @@ public class PringoJsonSendRequestDto {
|
|||||||
@JsonProperty("recipient_name")
|
@JsonProperty("recipient_name")
|
||||||
private String recipientName;
|
private String recipientName;
|
||||||
|
|
||||||
/** recipient email */
|
/**
|
||||||
|
* recipient email
|
||||||
|
*/
|
||||||
private String recipient;
|
private String recipient;
|
||||||
|
|
||||||
/** subject */
|
/**
|
||||||
|
* subject
|
||||||
|
*/
|
||||||
private String subject;
|
private String subject;
|
||||||
|
|
||||||
/** html body */
|
/**
|
||||||
|
* html body
|
||||||
|
*/
|
||||||
private String body;
|
private String body;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pringo 템플릿 치환용 동적 변수
|
* Pringo 템플릿 치환용 동적 변수 예) body: "...[$jstest]..." vars: {"jstest":"테스트 지롱~"}
|
||||||
* 예) body: "...[$jstest]..."
|
|
||||||
* vars: {"jstest":"테스트 지롱~"}
|
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
private Map<String, Object> vars = new LinkedHashMap<>();
|
private Map<String, Object> vars = new LinkedHashMap<>();
|
||||||
|
|
||||||
@JsonAnyGetter
|
|
||||||
public Map<String, Object> any() {
|
|
||||||
return vars;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonAnySetter
|
|
||||||
public void setAny(String key, Object value) {
|
|
||||||
if (key == null) return;
|
|
||||||
if (RESERVED_KEYS.contains(key)) {
|
|
||||||
// 동적 변수로 reserved key를 덮어쓰는 실수를 방지
|
|
||||||
throw new IllegalArgumentException("Reserved key cannot be used as variable: " + key);
|
|
||||||
}
|
|
||||||
vars.put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void putVar(String key, Object value) {
|
|
||||||
setAny(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PringoJsonSendRequestDto copy() {
|
|
||||||
return PringoJsonSendRequestDto.builder()
|
|
||||||
.apiKey(this.apiKey)
|
|
||||||
.templateId(this.templateId)
|
|
||||||
.sender(this.sender)
|
|
||||||
.senderName(this.senderName)
|
|
||||||
.recipient(this.recipient)
|
|
||||||
.recipientName(this.recipientName)
|
|
||||||
.subject(this.subject)
|
|
||||||
.body(this.body)
|
|
||||||
.vars(new java.util.LinkedHashMap<>(this.vars))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TemplateBasicDto -> Pringo 발송 DTO 기본 매핑
|
* TemplateBasicDto -> Pringo 발송 DTO 기본 매핑 - recipient/recipientName 은 템플릿에 없으므로 여기서는 비워두고 이후 세팅
|
||||||
* - recipient/recipientName 은 템플릿에 없으므로 여기서는 비워두고 이후 세팅
|
|
||||||
*/
|
*/
|
||||||
public static PringoJsonSendRequestDto from(TemplateBasicDto template, String sendName, String sendEmail) {
|
public static PringoJsonSendRequestDto from(TemplateBasicDto template, String sendName,
|
||||||
|
String sendEmail) {
|
||||||
return from(template, sendName, sendEmail, null, null);
|
return from(template, sendName, sendEmail, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PringoJsonSendRequestDto from(TemplateBasicDto template, String sendName, String sendEmail, String recipient, String recipientName) {
|
public static PringoJsonSendRequestDto from(TemplateBasicDto template, String sendName,
|
||||||
|
String sendEmail, String recipient, String recipientName) {
|
||||||
Objects.requireNonNull(template, "template is required");
|
Objects.requireNonNull(template, "template is required");
|
||||||
|
|
||||||
String sender = sendEmail != null && !sendEmail.isBlank() ? sendEmail : template.getSendEml();
|
String sender = sendEmail != null && !sendEmail.isBlank() ? sendEmail : template.getSendEml();
|
||||||
@@ -134,7 +111,44 @@ public class PringoJsonSendRequestDto {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** recipient를 나중에 세팅할 수 있게 체이닝용 */
|
@JsonAnyGetter
|
||||||
|
public Map<String, Object> any() {
|
||||||
|
return vars;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonAnySetter
|
||||||
|
public void setAny(String key, Object value) {
|
||||||
|
if (key == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (RESERVED_KEYS.contains(key)) {
|
||||||
|
// 동적 변수로 reserved key를 덮어쓰는 실수를 방지
|
||||||
|
throw new IllegalArgumentException("Reserved key cannot be used as variable: " + key);
|
||||||
|
}
|
||||||
|
vars.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void putVar(String key, Object value) {
|
||||||
|
setAny(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PringoJsonSendRequestDto copy() {
|
||||||
|
return PringoJsonSendRequestDto.builder()
|
||||||
|
.apiKey(this.apiKey)
|
||||||
|
.templateId(this.templateId)
|
||||||
|
.sender(this.sender)
|
||||||
|
.senderName(this.senderName)
|
||||||
|
.recipient(this.recipient)
|
||||||
|
.recipientName(this.recipientName)
|
||||||
|
.subject(this.subject)
|
||||||
|
.body(this.body)
|
||||||
|
.vars(new java.util.LinkedHashMap<>(this.vars))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* recipient를 나중에 세팅할 수 있게 체이닝용
|
||||||
|
*/
|
||||||
public PringoJsonSendRequestDto withRecipient(String recipient, String recipientName) {
|
public PringoJsonSendRequestDto withRecipient(String recipient, String recipientName) {
|
||||||
this.recipient = recipient;
|
this.recipient = recipient;
|
||||||
this.recipientName = recipientName;
|
this.recipientName = recipientName;
|
||||||
@@ -142,8 +156,12 @@ public class PringoJsonSendRequestDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void applyDefaults(String defaultApiKey, String defaultTemplateId) {
|
public void applyDefaults(String defaultApiKey, String defaultTemplateId) {
|
||||||
if (this.apiKey == null || this.apiKey.isBlank()) this.apiKey = defaultApiKey;
|
if (this.apiKey == null || this.apiKey.isBlank()) {
|
||||||
if (this.templateId == null || this.templateId.isBlank()) this.templateId = defaultTemplateId;
|
this.apiKey = defaultApiKey;
|
||||||
|
}
|
||||||
|
if (this.templateId == null || this.templateId.isBlank()) {
|
||||||
|
this.templateId = defaultTemplateId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validateRequired() {
|
public void validateRequired() {
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ public class PringoJsonSendResponseDto {
|
|||||||
private String typeAlias;
|
private String typeAlias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 성공: 1
|
* 성공: 1 실패: "-1" (API가 숫자/문자 둘 다 줄 수 있으니 String으로 받는 편이 안전)
|
||||||
* 실패: "-1"
|
|
||||||
* (API가 숫자/문자 둘 다 줄 수 있으니 String으로 받는 편이 안전)
|
|
||||||
*/
|
*/
|
||||||
@JsonProperty("result")
|
@JsonProperty("result")
|
||||||
private String result;
|
private String result;
|
||||||
@@ -24,7 +22,9 @@ public class PringoJsonSendResponseDto {
|
|||||||
@JsonProperty("msg")
|
@JsonProperty("msg")
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
/** 응답 JSON 오타 그대로 "retrun_key" */
|
/**
|
||||||
|
* 응답 JSON 오타 그대로 "retrun_key"
|
||||||
|
*/
|
||||||
@JsonProperty("retrun_key")
|
@JsonProperty("retrun_key")
|
||||||
private Long returnKey;
|
private Long returnKey;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.kri.notihub.server.common.util;
|
package com.kri.notihub.server.common.util;
|
||||||
|
|
||||||
|
import com.kri.common.feature.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 org.jsoup.Jsoup;
|
|
||||||
import org.jsoup.safety.Safelist;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import org.jsoup.Jsoup;
|
||||||
|
import org.jsoup.nodes.Document;
|
||||||
|
import org.jsoup.safety.Safelist;
|
||||||
|
|
||||||
public final class TemplateContentSanitizer {
|
public final class TemplateContentSanitizer {
|
||||||
|
|
||||||
@@ -14,31 +14,40 @@ public final class TemplateContentSanitizer {
|
|||||||
// (KOR 환경에서 SMS는 바이트 기준으로 제한을 두는 경우가 흔함)
|
// (KOR 환경에서 SMS는 바이트 기준으로 제한을 두는 경우가 흔함)
|
||||||
private static final int SMS_MAX_BYTES_UTF8 = 90;
|
private static final int SMS_MAX_BYTES_UTF8 = 90;
|
||||||
|
|
||||||
private TemplateContentSanitizer() {}
|
private TemplateContentSanitizer() {
|
||||||
|
}
|
||||||
|
|
||||||
private static int utf8ByteLength(String s) {
|
private static int utf8ByteLength(String s) {
|
||||||
if (s == null) return 0;
|
if (s == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
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자(코드포인트 기준)로 절단 */
|
|
||||||
private static String truncateTo128CodePoints(String s) {
|
private static String truncateTo128CodePoints(String s) {
|
||||||
if (s == null) return null;
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
String trimmed = s.trim();
|
String trimmed = s.trim();
|
||||||
int cpCount = trimmed.codePointCount(0, trimmed.length());
|
int cpCount = trimmed.codePointCount(0, trimmed.length());
|
||||||
if (cpCount <= 128) return trimmed;
|
if (cpCount <= 128) {
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
|
||||||
int end = trimmed.offsetByCodePoints(0, 128);
|
int end = trimmed.offsetByCodePoints(0, 128);
|
||||||
return trimmed.substring(0, end);
|
return trimmed.substring(0, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 제어문자 제거(개행/탭은 옵션), 줄바꿈은 \n 으로 통일 */
|
/**
|
||||||
|
* 제어문자 제거(개행/탭은 옵션), 줄바꿈은 \n 으로 통일
|
||||||
|
*/
|
||||||
private static String normalizeControls(String s, boolean keepNewlines) {
|
private static String normalizeControls(String s, boolean keepNewlines) {
|
||||||
if (s == null) return null;
|
if (s == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
String v = s.replace("\r\n", "\n").replace('\r', '\n');
|
String v = s.replace("\r\n", "\n").replace('\r', '\n');
|
||||||
|
|
||||||
if (keepNewlines) {
|
if (keepNewlines) {
|
||||||
@@ -49,9 +58,13 @@ public final class TemplateContentSanitizer {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** EMAIL body: 안전한 HTML만 유지(스크립트/iframe 등 제거) */
|
/**
|
||||||
|
* EMAIL body: 안전한 HTML만 유지(스크립트/iframe 등 제거)
|
||||||
|
*/
|
||||||
private static String sanitizeEmailHtml(String html) {
|
private static String sanitizeEmailHtml(String html) {
|
||||||
if (html == null) return null;
|
if (html == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Safelist safelist = Safelist.relaxed()
|
Safelist safelist = Safelist.relaxed()
|
||||||
.addProtocols("a", "href", "http", "https", "mailto")
|
.addProtocols("a", "href", "http", "https", "mailto")
|
||||||
@@ -64,9 +77,13 @@ public final class TemplateContentSanitizer {
|
|||||||
return cleaned.trim();
|
return cleaned.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SMS/LMS body: HTML -> 평문(개행 보존) */
|
/**
|
||||||
|
* SMS/LMS body: HTML -> 평문(개행 보존)
|
||||||
|
*/
|
||||||
private static String htmlToPlainTextPreserveNewlines(String html) {
|
private static String htmlToPlainTextPreserveNewlines(String html) {
|
||||||
if (html == null) return null;
|
if (html == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String v = html;
|
String v = html;
|
||||||
v = v.replaceAll("(?i)<\\s*br\\s*/?\\s*>", "\n");
|
v = v.replaceAll("(?i)<\\s*br\\s*/?\\s*>", "\n");
|
||||||
@@ -80,19 +97,18 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1) tmplatTy별 치환/정리
|
* 1) tmplatTy별 치환/정리 2) (SMS/LMS_MMS) 치환 후 길이 기반으로 타입 재결정 - SMS는 제목 저장 안 함 - LMS_MMS는 본문 짧아도 제목
|
||||||
* 2) (SMS/LMS_MMS) 치환 후 길이 기반으로 타입 재결정
|
* 있으면 그대로 유지
|
||||||
* - SMS는 제목 저장 안 함
|
|
||||||
* - LMS_MMS는 본문 짧아도 제목 있으면 그대로 유지
|
|
||||||
*/
|
*/
|
||||||
public static SanitizedTemplate sanitizeAndNormalize(SendType originalType, String title, String body) {
|
public static SanitizedTemplate sanitizeAndNormalize(SendType originalType, String title,
|
||||||
|
String body) {
|
||||||
SendType type = originalType;
|
SendType type = originalType;
|
||||||
String outTitle = title;
|
String outTitle = title;
|
||||||
String outBody = body;
|
String outBody = body;
|
||||||
@@ -107,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);
|
||||||
@@ -116,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 유지
|
||||||
@@ -140,11 +158,14 @@ public final class TemplateContentSanitizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sanitizeAndNormalizeInPlace(TemplateBasicDto dto) {
|
public static void sanitizeAndNormalizeInPlace(TemplateBasicDto dto) {
|
||||||
SanitizedTemplate st = sanitizeAndNormalize(dto.getTmplatTy(), dto.getTmplatTitle(), dto.getTmplatBody());
|
SanitizedTemplate st = sanitizeAndNormalize(dto.getTmplatTy(), dto.getTmplatTitle(),
|
||||||
|
dto.getTmplatBody());
|
||||||
dto.setTmplatTy(st.type());
|
dto.setTmplatTy(st.type());
|
||||||
dto.setTmplatTitle(st.title());
|
dto.setTmplatTitle(st.title());
|
||||||
dto.setTmplatBody(st.body());
|
dto.setTmplatBody(st.body());
|
||||||
}
|
}
|
||||||
|
|
||||||
public record SanitizedTemplate(SendType type, String title, String body) {}
|
public record SanitizedTemplate(SendType type, String title, String body) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
15
src/main/java/com/kri/notihub/server/config/JdbcConfig.java
Normal file
15
src/main/java/com/kri/notihub/server/config/JdbcConfig.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package com.kri.notihub.server.config;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class JdbcConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
|
||||||
|
return new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.kri.notihub.server.controller;
|
package com.kri.notihub.server.controller;
|
||||||
|
|
||||||
import com.kri.common.webmvc.RequestUserContext;
|
import com.kri.common.feature.web.RequestUserContext;
|
||||||
import com.kri.common.webmvc.page.PageRequestDto;
|
import com.kri.common.feature.web.page.PageRequestDto;
|
||||||
import com.kri.common.webmvc.page.PageResponseDto;
|
import com.kri.common.feature.web.page.PageResponseDto;
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||||
@@ -12,10 +12,14 @@ import com.kri.notihub.server.service.ReportService;
|
|||||||
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;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/report")
|
@RequestMapping("/api/v1/report")
|
||||||
@@ -33,7 +37,8 @@ public class ReportController {
|
|||||||
@PathVariable String prjctCd,
|
@PathVariable String prjctCd,
|
||||||
RequestUserContext ctx
|
RequestUserContext ctx
|
||||||
) {
|
) {
|
||||||
String regCmpn = ctx.getUserRole() < NotihubConst.OUTSOURCE_USER_ROLE ? null : ctx.getUserCmpn();
|
String regCmpn =
|
||||||
|
ctx.getUserRole() < NotihubConst.OUTSOURCE_USER_ROLE ? null : ctx.getUserCmpn();
|
||||||
return reportService.getBulkSendList(sendTy, reqstSvc, prjctCd, regCmpn);
|
return reportService.getBulkSendList(sendTy, reqstSvc, prjctCd, regCmpn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,30 @@
|
|||||||
package com.kri.notihub.server.controller;
|
package com.kri.notihub.server.controller;
|
||||||
|
|
||||||
import com.kri.common.webmvc.RequestUserContext;
|
import com.kri.common.feature.web.RequestUserContext;
|
||||||
import com.kri.notihub.server.dto.send.*;
|
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
||||||
|
import com.kri.notihub.server.dto.send.BulkSendResponseDto;
|
||||||
|
import com.kri.notihub.server.dto.send.EmailPollQueueResponseDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendRequestBulkDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
||||||
import com.kri.notihub.server.service.EmailResultPoller;
|
import com.kri.notihub.server.service.EmailResultPoller;
|
||||||
import com.kri.notihub.server.service.SendEmailService;
|
import com.kri.notihub.server.service.SendEmailService;
|
||||||
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;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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
|
@RestController
|
||||||
@RequestMapping("/api/v1/send-email")
|
@RequestMapping("/api/v1/send-email")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Tag(name = "Send Email", description = "이메일 발송 API")
|
@Tag(name = "Send Email", description = "이메일 발송 API")
|
||||||
public class SendEmailController {
|
public class SendEmailController {
|
||||||
|
|
||||||
//발송 타입은 템플릿에 있음
|
//발송 타입은 템플릿에 있음
|
||||||
private final SendEmailService sendEmailService;
|
private final SendEmailService sendEmailService;
|
||||||
private final EmailResultPoller emailResultPoller;
|
private final EmailResultPoller emailResultPoller;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.kri.notihub.server.controller;
|
||||||
|
|
||||||
|
import com.kri.common.feature.web.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,23 @@
|
|||||||
package com.kri.notihub.server.controller;
|
package com.kri.notihub.server.controller;
|
||||||
|
|
||||||
import com.kri.common.webmvc.RequestUserContext;
|
import com.kri.common.feature.web.RequestUserContext;
|
||||||
import com.kri.notihub.server.dto.send.*;
|
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.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;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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
|
@RestController
|
||||||
@RequestMapping("/api/v1/send-sms")
|
@RequestMapping("/api/v1/send-sms")
|
||||||
@@ -17,12 +26,12 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
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 = "벌크 발송키 생성")
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.kri.notihub.server.controller;
|
package com.kri.notihub.server.controller;
|
||||||
|
|
||||||
import com.kri.common.webmvc.RequestUserContext;
|
import com.kri.common.feature.web.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;
|
||||||
@@ -10,11 +11,18 @@ import com.kri.notihub.server.service.TemplateService;
|
|||||||
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;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
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.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/template")
|
@RequestMapping("/api/v1/template")
|
||||||
@@ -46,8 +54,10 @@ public class TemplateController {
|
|||||||
@Valid @RequestBody TemplateBasicDto template,
|
@Valid @RequestBody TemplateBasicDto template,
|
||||||
RequestUserContext ctx
|
RequestUserContext ctx
|
||||||
) {
|
) {
|
||||||
TemplateDto newTmplat = templateService.createTemplate(template.getItrntPrjctCd(), template, ctx.getUserId());
|
TemplateDto newTmplat = templateService.createTemplate(template.getItrntPrjctCd(), template,
|
||||||
|
ctx.getUserId());
|
||||||
|
|
||||||
|
if (template.getTmplatTy() == SendType.EMAIL) {
|
||||||
String newHtml = fileService.syncOnSave(
|
String newHtml = fileService.syncOnSave(
|
||||||
newTmplat.getItrntPrjctCd(),
|
newTmplat.getItrntPrjctCd(),
|
||||||
newTmplat.getTmplatIdx(),
|
newTmplat.getTmplatIdx(),
|
||||||
@@ -56,13 +66,15 @@ public class TemplateController {
|
|||||||
newTmplat.setTmplatBody(newHtml);
|
newTmplat.setTmplatBody(newHtml);
|
||||||
|
|
||||||
templateService.updateTemplateBodyWithCreate(newTmplat);
|
templateService.updateTemplateBodyWithCreate(newTmplat);
|
||||||
|
}
|
||||||
|
|
||||||
return newTmplat;
|
return newTmplat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "시나리오 이미지 업로드")
|
@Operation(summary = "시나리오 이미지 업로드")
|
||||||
@PutMapping("/body-image/{itrntPrjctCd}")
|
@PutMapping("/body-image/{itrntPrjctCd}")
|
||||||
public String uploadContactSenarioImage(@PathVariable String itrntPrjctCd, @RequestParam("file") MultipartFile file) {
|
public String uploadContactSenarioImage(@PathVariable String itrntPrjctCd,
|
||||||
|
@RequestParam("file") MultipartFile file) {
|
||||||
return fileService.storeTempFile(itrntPrjctCd, file);
|
return fileService.storeTempFile(itrntPrjctCd, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,12 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -78,7 +81,9 @@ public class BulkSendInfoDto {
|
|||||||
private LocalDateTime regDt;
|
private LocalDateTime regDt;
|
||||||
|
|
||||||
public static BulkSendInfoDto from(TBulkSendEntity entity) {
|
public static BulkSendInfoDto from(TBulkSendEntity entity) {
|
||||||
if (entity == null) return null;
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return BulkSendInfoDto.builder()
|
return BulkSendInfoDto.builder()
|
||||||
.bulkSendKey(entity.getBulkSendKey())
|
.bulkSendKey(entity.getBulkSendKey())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.kri.notihub.server.dto.report;
|
package com.kri.notihub.server.dto.report;
|
||||||
|
|
||||||
import com.kri.common.excel.ExcelColumn;
|
import com.kri.common.feature.excel.ExcelColumn;
|
||||||
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.persistence.entity.TSendEntity;
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
@@ -9,10 +9,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -126,7 +129,9 @@ public class SendInfoDto {
|
|||||||
private LocalDateTime regDt;
|
private LocalDateTime regDt;
|
||||||
|
|
||||||
public static SendInfoDto from(TSendEntity entity, List<TSendResultCodeEntity> resultCodeEntity) {
|
public static SendInfoDto from(TSendEntity entity, List<TSendResultCodeEntity> resultCodeEntity) {
|
||||||
if (entity == null) return null;
|
if (entity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isEmail = entity.getSendTy() != null
|
boolean isEmail = entity.getSendTy() != null
|
||||||
&& entity.getSendTy().equals(SendType.EMAIL.getCode());
|
&& entity.getSendTy().equals(SendType.EMAIL.getCode());
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.kri.notihub.server.dto.send;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BizppurioCursorResponseDto {
|
||||||
|
|
||||||
|
@Schema(description = "SMS 결과 반영 스케줄러 커서(send_idx)")
|
||||||
|
private Long cursor;
|
||||||
|
|
||||||
|
public static BizppurioCursorResponseDto of(long cursor) {
|
||||||
|
return BizppurioCursorResponseDto.builder()
|
||||||
|
.cursor(cursor)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,9 +5,12 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -16,6 +19,16 @@ import java.time.LocalDateTime;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BulkSendCreateRequestDto {
|
public class BulkSendCreateRequestDto {
|
||||||
|
|
||||||
|
@Size(max = 32)
|
||||||
|
@NotBlank
|
||||||
|
@Schema(description = "발송 요청 회사")
|
||||||
|
String reqstCmpn;
|
||||||
|
|
||||||
|
@Size(max = 32)
|
||||||
|
@NotBlank
|
||||||
|
@Schema(description = "발송 요청자")
|
||||||
|
String reqstUser;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@Schema(description = "발송 요청 서비스 (로그용)")
|
@Schema(description = "발송 요청 서비스 (로그용)")
|
||||||
private String reqstSvc;
|
private String reqstSvc;
|
||||||
@@ -39,14 +52,4 @@ public class BulkSendCreateRequestDto {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "대상자 수")
|
@Schema(description = "대상자 수")
|
||||||
private Integer trgtCnt;
|
private Integer trgtCnt;
|
||||||
|
|
||||||
@Size(max = 32)
|
|
||||||
@NotBlank
|
|
||||||
@Schema(description = "발송 요청 회사")
|
|
||||||
String reqstCmpn;
|
|
||||||
|
|
||||||
@Size(max = 32)
|
|
||||||
@NotBlank
|
|
||||||
@Schema(description = "발송 요청자")
|
|
||||||
String reqstUser;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ public class BulkSendResponseDto {
|
|||||||
@Schema(description = "Pringo send 요청 실패(return_key 미수신) 건수")
|
@Schema(description = "Pringo send 요청 실패(return_key 미수신) 건수")
|
||||||
private Integer failCount;
|
private Integer failCount;
|
||||||
|
|
||||||
public static BulkSendResponseDto of(String bulkSendKey, Integer requestCount, Integer acceptCount, Integer failCount) {
|
public static BulkSendResponseDto of(String bulkSendKey, Integer requestCount,
|
||||||
|
Integer acceptCount, Integer failCount) {
|
||||||
return BulkSendResponseDto.builder()
|
return BulkSendResponseDto.builder()
|
||||||
.bulkSendKey(bulkSendKey)
|
.bulkSendKey(bulkSendKey)
|
||||||
.requestCount(requestCount)
|
.requestCount(requestCount)
|
||||||
|
|||||||
@@ -4,9 +4,12 @@ import com.kri.notihub.server.persistence.entity.TSendEntity;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.Email;
|
import jakarta.validation.constraints.Email;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package com.kri.notihub.server.dto.send;
|
package com.kri.notihub.server.dto.send;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@@ -30,7 +29,8 @@ public class EmailPollQueueItemDto {
|
|||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime triggerAt;
|
private LocalDateTime triggerAt;
|
||||||
|
|
||||||
public static EmailPollQueueItemDto of(String cmid, int attempt, long remainingMs, long triggerAtEpochMs) {
|
public static EmailPollQueueItemDto of(String cmid, int attempt, long remainingMs,
|
||||||
|
long triggerAtEpochMs) {
|
||||||
return EmailPollQueueItemDto.builder()
|
return EmailPollQueueItemDto.builder()
|
||||||
.cmid(cmid)
|
.cmid(cmid)
|
||||||
.attempt(attempt)
|
.attempt(attempt)
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package com.kri.notihub.server.dto.send;
|
package com.kri.notihub.server.dto.send;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import java.util.List;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class EmailPollQueueResponseDto {
|
public class EmailPollQueueResponseDto {
|
||||||
|
|
||||||
@Schema(description = "Queue size (snapshot)")
|
@Schema(description = "Queue size (snapshot)")
|
||||||
private Integer size;
|
private Integer size;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ package com.kri.notihub.server.dto.send;
|
|||||||
|
|
||||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package com.kri.notihub.server.dto.send;
|
|||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.Email;
|
import jakarta.validation.constraints.Email;
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Schema(description = "일괄 발송 요청 정보")
|
@Schema(description = "일괄 발송 요청 정보")
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
package com.kri.notihub.server.dto.send;
|
package com.kri.notihub.server.dto.send;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.kri.common.datetime.LenientLocalDateTime;
|
import com.kri.common.feature.datetime.LenientLocalDateTime;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Schema(description = "단건 발송 요청 정보")
|
@Schema(description = "단건 발송 요청 정보")
|
||||||
public class SendRequestSingleDto extends SendRequestBasicDto {
|
public class SendRequestSingleDto extends SendRequestBasicDto {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Schema(description = "수신자 정보")
|
||||||
|
DestInfoDto destInfo;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Schema(description = "발송 템플릿")
|
@Schema(description = "발송 템플릿")
|
||||||
private long tmplatIdx;
|
private long tmplatIdx;
|
||||||
@@ -33,8 +37,4 @@ public class SendRequestSingleDto extends SendRequestBasicDto {
|
|||||||
@LenientLocalDateTime
|
@LenientLocalDateTime
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime sendDt;
|
private LocalDateTime sendDt;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Schema(description = "수신자 정보")
|
|
||||||
DestInfoDto destInfo;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.kri.notihub.server.dto.send;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class SmsCursorResponseDto {
|
|
||||||
|
|
||||||
@Schema(description = "SMS 결과 반영 스케줄러 커서(send_idx)")
|
|
||||||
private Long cursor;
|
|
||||||
|
|
||||||
public static SmsCursorResponseDto of(long cursor) {
|
|
||||||
return SmsCursorResponseDto.builder()
|
|
||||||
.cursor(cursor)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -50,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())
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ package com.kri.notihub.server.dto.template;
|
|||||||
|
|
||||||
import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.*;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -11,11 +15,12 @@ import lombok.*;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Schema(description = "템플릿 요약 정보")
|
@Schema(description = "템플릿 요약 정보")
|
||||||
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()
|
||||||
|
|||||||
@@ -4,19 +4,17 @@ import jakarta.persistence.Column;
|
|||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "`BIZ_LOG`")
|
@Table(name = "`BIZ_LOG`")
|
||||||
public class BizLogEntity {
|
public class BizLogEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@Column(name = "`CMID`", length = 32)
|
@Column(name = "`CMID`", length = 32)
|
||||||
|
|||||||
@@ -7,10 +7,13 @@ import jakarta.persistence.Id;
|
|||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -20,6 +23,7 @@ import java.time.LocalDateTime;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table(name = "`BIZ_MSG`")
|
@Table(name = "`BIZ_MSG`")
|
||||||
public class BizMsgEntity {
|
public class BizMsgEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@Column(name = "`CMID`", nullable = false, length = 32)
|
@Column(name = "`CMID`", nullable = false, length = 32)
|
||||||
@@ -85,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)
|
||||||
@@ -132,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)
|
||||||
@@ -172,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())
|
||||||
@@ -188,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
package com.kri.notihub.server.persistence.entity;
|
package com.kri.notihub.server.persistence.entity;
|
||||||
|
|
||||||
import com.kri.common.jpa.BaseUuidEntity;
|
import com.kri.common.feature.jpa.BaseUuidEntity;
|
||||||
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -18,6 +24,7 @@ import java.time.LocalDateTime;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@Table(name = "t_bulk_send")
|
@Table(name = "t_bulk_send")
|
||||||
public class TBulkSendEntity extends BaseUuidEntity {
|
public class TBulkSendEntity extends BaseUuidEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@Column(name = "bulk_send_key", nullable = false, length = 32)
|
@Column(name = "bulk_send_key", nullable = false, length = 32)
|
||||||
@@ -38,6 +45,7 @@ public class TBulkSendEntity extends BaseUuidEntity {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Column(name = "is_resve", nullable = false)
|
@Column(name = "is_resve", nullable = false)
|
||||||
|
@Builder.Default
|
||||||
private Boolean resve = false;
|
private Boolean resve = false;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
package com.kri.notihub.server.persistence.entity;
|
package com.kri.notihub.server.persistence.entity;
|
||||||
|
|
||||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.*;
|
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
import org.hibernate.annotations.Type;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|||||||
@@ -6,16 +6,26 @@ 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.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
import org.hibernate.annotations.Type;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
@Getter
|
@Getter
|
||||||
@@ -46,6 +56,7 @@ public class TSendEntity {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Column(name = "is_resve", nullable = false)
|
@Column(name = "is_resve", nullable = false)
|
||||||
|
@Builder.Default
|
||||||
private boolean resve = false;
|
private boolean resve = false;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -78,6 +89,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;
|
||||||
@@ -145,9 +172,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,
|
||||||
@@ -156,16 +182,16 @@ public class TSendEntity {
|
|||||||
LocalDateTime sendDt,
|
LocalDateTime sendDt,
|
||||||
LocalDateTime regDt
|
LocalDateTime regDt
|
||||||
) {
|
) {
|
||||||
if (req == null) return null;
|
if (req == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
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,
|
||||||
@@ -180,12 +206,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,
|
||||||
@@ -195,24 +219,33 @@ public class TSendEntity {
|
|||||||
String bulkSendKey,
|
String bulkSendKey,
|
||||||
LocalDateTime regDt
|
LocalDateTime regDt
|
||||||
) {
|
) {
|
||||||
if (basic == null) return null;
|
if (basic == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (dest == null) return null;
|
if (dest == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
Short sendCorp = sendTy == SendType.EMAIL ? SendCorpType.PRINGO.getCode() : SendCorpType.BIZ_PPURIO.getCode();
|
Short sendCorp = tmplat.getTmplatTy() == SendType.EMAIL ? SendCorpType.PRINGO.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())
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import lombok.Setter;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "t_send_result_code")
|
@Table(name = "t_send_result_code")
|
||||||
public class TSendResultCodeEntity {
|
public class TSendResultCodeEntity {
|
||||||
|
|
||||||
@EmbeddedId
|
@EmbeddedId
|
||||||
private TSendResultCodeEntityId id;
|
private TSendResultCodeEntityId id;
|
||||||
|
|
||||||
@@ -35,7 +36,11 @@ public class TSendResultCodeEntity {
|
|||||||
@Column(name = "memo", length = 128)
|
@Column(name = "memo", length = 128)
|
||||||
private String memo;
|
private String memo;
|
||||||
|
|
||||||
public short getSendCorp() { return id.getSendCorp(); }
|
public short getSendCorp() {
|
||||||
|
return id.getSendCorp();
|
||||||
public short getResultCode() { return id.getResultCode(); }
|
}
|
||||||
|
|
||||||
|
public short getResultCode() {
|
||||||
|
return id.getResultCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,17 +3,17 @@ package com.kri.notihub.server.persistence.entity;
|
|||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Embeddable;
|
import jakarta.persistence.Embeddable;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.hibernate.Hibernate;
|
import org.hibernate.Hibernate;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Embeddable
|
@Embeddable
|
||||||
public class TSendResultCodeEntityId implements Serializable {
|
public class TSendResultCodeEntityId implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -53054354660031517L;
|
private static final long serialVersionUID = -53054354660031517L;
|
||||||
@NotNull
|
@NotNull
|
||||||
@Column(name = "send_corp", nullable = false)
|
@Column(name = "send_corp", nullable = false)
|
||||||
@@ -25,8 +25,12 @@ public class TSendResultCodeEntityId implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
TSendResultCodeEntityId entity = (TSendResultCodeEntityId) o;
|
TSendResultCodeEntityId entity = (TSendResultCodeEntityId) o;
|
||||||
return Objects.equals(this.sendCorp, entity.sendCorp) &&
|
return Objects.equals(this.sendCorp, entity.sendCorp) &&
|
||||||
Objects.equals(this.resultCode, entity.resultCode);
|
Objects.equals(this.resultCode, entity.resultCode);
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
package com.kri.notihub.server.persistence.entity;
|
package com.kri.notihub.server.persistence.entity;
|
||||||
|
|
||||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
@Getter
|
@Getter
|
||||||
@@ -17,6 +26,7 @@ import java.time.LocalDateTime;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TTmplatEntity {
|
public class TTmplatEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "tmplat_idx", columnDefinition = "int UNSIGNED not null")
|
@Column(name = "tmplat_idx", columnDefinition = "int UNSIGNED not null")
|
||||||
@@ -42,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;
|
||||||
|
|
||||||
@@ -80,6 +106,7 @@ public class TTmplatEntity {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@ColumnDefault("0")
|
@ColumnDefault("0")
|
||||||
@Column(name = "is_del", nullable = false)
|
@Column(name = "is_del", nullable = false)
|
||||||
|
@Builder.Default
|
||||||
private Boolean del = false;
|
private Boolean del = false;
|
||||||
|
|
||||||
@Size(max = 32)
|
@Size(max = 32)
|
||||||
@@ -89,17 +116,22 @@ public class TTmplatEntity {
|
|||||||
@Column(name = "del_dt")
|
@Column(name = "del_dt")
|
||||||
private LocalDateTime delDt;
|
private LocalDateTime delDt;
|
||||||
|
|
||||||
public static TTmplatEntity create(String itrntPrjctCd, TemplateBasicDto template, String regUser, LocalDateTime regDt) {
|
public static TTmplatEntity create(String itrntPrjctCd, TemplateBasicDto template, String regUser,
|
||||||
|
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)
|
||||||
@@ -108,14 +140,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;
|
||||||
|
|||||||
@@ -3,15 +3,23 @@ package com.kri.notihub.server.persistence.entity;
|
|||||||
import com.kri.notihub.server.common.enums.TemplateEventType;
|
import com.kri.notihub.server.common.enums.TemplateEventType;
|
||||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||||
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
import io.hypersistence.utils.hibernate.type.json.JsonType;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.*;
|
import java.time.LocalDateTime;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
import org.hibernate.annotations.Type;
|
import org.hibernate.annotations.Type;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Builder
|
@Builder
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@@ -20,6 +28,7 @@ import java.time.LocalDateTime;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TTmplatEventLogEntity {
|
public class TTmplatEventLogEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "tmplat_event_idx", columnDefinition = "int UNSIGNED not null")
|
@Column(name = "tmplat_event_idx", columnDefinition = "int UNSIGNED not null")
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package com.kri.notihub.server.persistence.jdbc;
|
||||||
|
|
||||||
|
import com.kri.notihub.server.persistence.entity.BizMsgEntity;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.sql.Types;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BizMsgBulkJdbcWriter {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
private static final String INSERT_BIZ_MSG_SQL = """
|
||||||
|
insert into `BIZ_MSG` (
|
||||||
|
`CMID`,
|
||||||
|
`UMID`,
|
||||||
|
`MSG_TYPE`,
|
||||||
|
`STATUS`,
|
||||||
|
`CALL_STATUS`,
|
||||||
|
`REQUEST_TIME`,
|
||||||
|
`SEND_TIME`,
|
||||||
|
`REPORT_TIME`,
|
||||||
|
`DEST_PHONE`,
|
||||||
|
`DEST_NAME`,
|
||||||
|
`SEND_PHONE`,
|
||||||
|
`SEND_NAME`,
|
||||||
|
`SUBJECT`,
|
||||||
|
`MSG_BODY`,
|
||||||
|
`NATION_CODE`,
|
||||||
|
`SENDER_KEY`,
|
||||||
|
`TEMPLATE_CODE`,
|
||||||
|
`RESPONSE_METHOD`,
|
||||||
|
`TIMEOUT`,
|
||||||
|
`RE_TYPE`,
|
||||||
|
`RE_BODY`,
|
||||||
|
`RE_PART`,
|
||||||
|
`COVER_FLAG`,
|
||||||
|
`SMS_FLAG`,
|
||||||
|
`REPLY_FLAG`,
|
||||||
|
`RETRY_CNT`,
|
||||||
|
`ATTACHED_FILE`,
|
||||||
|
`VXML_FILE`,
|
||||||
|
`USE_PAGE`,
|
||||||
|
`USE_TIME`,
|
||||||
|
`SN_RESULT`,
|
||||||
|
`TEL_INFO`,
|
||||||
|
`CINFO`,
|
||||||
|
`USER_KEY`,
|
||||||
|
`AD_FLAG`
|
||||||
|
) values (
|
||||||
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
|
?, ?, ?, ?, ?
|
||||||
|
)
|
||||||
|
""";
|
||||||
|
|
||||||
|
public void bulkInsert(List<BizMsgEntity> entityList) {
|
||||||
|
if (entityList == null || entityList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
jdbcTemplate.batchUpdate(INSERT_BIZ_MSG_SQL, new BatchPreparedStatementSetter() {
|
||||||
|
@Override
|
||||||
|
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||||
|
BizMsgEntity e = entityList.get(index);
|
||||||
|
|
||||||
|
int p = 1;
|
||||||
|
ps.setString(p++, e.getCmid());
|
||||||
|
setNullableString(ps, p++, e.getUmid());
|
||||||
|
setNullableInteger(ps, p++, e.getMsgType());
|
||||||
|
setNullableInteger(ps, p++, e.getStatus());
|
||||||
|
setNullableString(ps, p++, e.getCallStatus());
|
||||||
|
setNullableDateTime(ps, p++, e.getRequestTime());
|
||||||
|
setNullableDateTime(ps, p++, e.getSendTime());
|
||||||
|
setNullableDateTime(ps, p++, e.getReportTime());
|
||||||
|
ps.setString(p++, e.getDestPhone());
|
||||||
|
setNullableString(ps, p++, e.getDestName());
|
||||||
|
ps.setString(p++, e.getSendPhone());
|
||||||
|
setNullableString(ps, p++, e.getSendName());
|
||||||
|
setNullableString(ps, p++, e.getSubject());
|
||||||
|
ps.setString(p++, e.getMsgBody());
|
||||||
|
setNullableString(ps, p++, e.getNationCode());
|
||||||
|
setNullableString(ps, p++, e.getSenderKey());
|
||||||
|
setNullableString(ps, p++, e.getTemplateCode());
|
||||||
|
setNullableString(ps, p++, e.getResponseMethod());
|
||||||
|
setNullableString(ps, p++, e.getTimeout());
|
||||||
|
setNullableString(ps, p++, e.getReType());
|
||||||
|
setNullableString(ps, p++, e.getReBody());
|
||||||
|
setNullableString(ps, p++, e.getRePart());
|
||||||
|
setNullableInteger(ps, p++, e.getCoverFlag());
|
||||||
|
setNullableInteger(ps, p++, e.getSmsFlag());
|
||||||
|
setNullableInteger(ps, p++, e.getReplyFlag());
|
||||||
|
setNullableInteger(ps, p++, e.getRetryCnt());
|
||||||
|
setNullableString(ps, p++, e.getAttachedFile());
|
||||||
|
setNullableString(ps, p++, e.getVxmlFile());
|
||||||
|
setNullableInteger(ps, p++, e.getUsePage());
|
||||||
|
setNullableInteger(ps, p++, e.getUseTime());
|
||||||
|
setNullableInteger(ps, p++, e.getSnResult());
|
||||||
|
setNullableString(ps, p++, e.getTelInfo());
|
||||||
|
setNullableString(ps, p++, e.getCinfo());
|
||||||
|
setNullableString(ps, p++, e.getUserKey());
|
||||||
|
setNullableString(ps, p++, e.getAdFalg());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBatchSize() {
|
||||||
|
return entityList.size();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNullableString(PreparedStatement ps, int index, String value) throws SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
ps.setNull(index, Types.VARCHAR);
|
||||||
|
} else {
|
||||||
|
ps.setString(index, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNullableInteger(PreparedStatement ps, int index, Integer value) throws SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
ps.setNull(index, Types.INTEGER);
|
||||||
|
} else {
|
||||||
|
ps.setInt(index, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNullableDateTime(PreparedStatement ps, int index, LocalDateTime value) throws SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
ps.setNull(index, Types.TIMESTAMP);
|
||||||
|
} else {
|
||||||
|
ps.setTimestamp(index, Timestamp.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package com.kri.notihub.server.persistence.jdbc;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.sql.Types;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Component
|
||||||
|
public class SendBulkJdbcWriter {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
private static final String INSERT_T_SEND_SQL = """
|
||||||
|
insert into t_send (
|
||||||
|
cmid,
|
||||||
|
bulk_send_key,
|
||||||
|
send_ty,
|
||||||
|
is_resve,
|
||||||
|
send_corp,
|
||||||
|
send_status,
|
||||||
|
result_code,
|
||||||
|
itrnt_prjct_cd,
|
||||||
|
reqst_svc,
|
||||||
|
prjct_cd,
|
||||||
|
tmplat_idx,
|
||||||
|
sender_key,
|
||||||
|
kko_tmplat_cd,
|
||||||
|
nation_cd,
|
||||||
|
atch_fl,
|
||||||
|
send_eml,
|
||||||
|
send_tel,
|
||||||
|
send_nm,
|
||||||
|
send_dt,
|
||||||
|
sid,
|
||||||
|
msg_title,
|
||||||
|
msg_body,
|
||||||
|
msg_param,
|
||||||
|
dest_eml,
|
||||||
|
dest_tel,
|
||||||
|
dest_nm,
|
||||||
|
report_dt,
|
||||||
|
reg_cmpn,
|
||||||
|
reg_user,
|
||||||
|
reg_dt
|
||||||
|
) values (
|
||||||
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||||
|
?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||||
|
)
|
||||||
|
""";
|
||||||
|
|
||||||
|
public void bulkInsert(List<TSendEntity> entityList) {
|
||||||
|
if (entityList == null || entityList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
jdbcTemplate.batchUpdate(INSERT_T_SEND_SQL, new BatchPreparedStatementSetter() {
|
||||||
|
@Override
|
||||||
|
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||||
|
TSendEntity e = entityList.get(index);
|
||||||
|
|
||||||
|
int p = 1;
|
||||||
|
ps.setString(p++, e.getCmid());
|
||||||
|
setNullableString(ps, p++, e.getBulkSendKey());
|
||||||
|
ps.setShort(p++, e.getSendTy());
|
||||||
|
ps.setBoolean(p++, e.isResve());
|
||||||
|
ps.setShort(p++, e.getSendCorp());
|
||||||
|
ps.setShort(p++, e.getSendStatus());
|
||||||
|
ps.setShort(p++, e.getResultCode());
|
||||||
|
ps.setString(p++, e.getItrntPrjctCd());
|
||||||
|
ps.setString(p++, e.getReqstSvc());
|
||||||
|
ps.setString(p++, e.getPrjctCd());
|
||||||
|
setNullableLong(ps, p++, e.getTmplatIdx());
|
||||||
|
setNullableString(ps, p++, e.getSenderKey());
|
||||||
|
setNullableString(ps, p++, e.getKkoTmplatCd());
|
||||||
|
setNullableString(ps, p++, e.getNationCd());
|
||||||
|
setNullableString(ps, p++, e.getAtchFl());
|
||||||
|
setNullableString(ps, p++, e.getSendEml());
|
||||||
|
setNullableString(ps, p++, e.getSendTel());
|
||||||
|
setNullableString(ps, p++, e.getSendNm());
|
||||||
|
setNullableDateTime(ps, p++, e.getSendDt());
|
||||||
|
ps.setString(p++, e.getSid());
|
||||||
|
setNullableString(ps, p++, e.getMsgTitle());
|
||||||
|
ps.setString(p++, e.getMsgBody());
|
||||||
|
ps.setString(p++, toJson(e.getMsgParam()));
|
||||||
|
setNullableString(ps, p++, e.getDestEml());
|
||||||
|
setNullableString(ps, p++, e.getDestTel());
|
||||||
|
setNullableString(ps, p++, e.getDestNm());
|
||||||
|
setNullableDateTime(ps, p++, e.getReportDt());
|
||||||
|
ps.setString(p++, e.getRegCmpn());
|
||||||
|
ps.setString(p++, e.getRegUser());
|
||||||
|
setNullableDateTime(ps, p++, e.getRegDt());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBatchSize() {
|
||||||
|
return entityList.size();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String toJson(Map<String, String> value) throws SQLException {
|
||||||
|
try {
|
||||||
|
return objectMapper.writeValueAsString(value != null ? value : Map.of());
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new SQLException("msg_param JSON 직렬화 실패", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNullableString(PreparedStatement ps, int index, String value) throws SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
ps.setNull(index, Types.VARCHAR);
|
||||||
|
} else {
|
||||||
|
ps.setString(index, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNullableLong(PreparedStatement ps, int index, Long value) throws SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
ps.setNull(index, Types.BIGINT);
|
||||||
|
} else {
|
||||||
|
ps.setLong(index, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNullableDateTime(PreparedStatement ps, int index, LocalDateTime value) throws SQLException {
|
||||||
|
if (value == null) {
|
||||||
|
ps.setNull(index, Types.TIMESTAMP);
|
||||||
|
} else {
|
||||||
|
ps.setTimestamp(index, Timestamp.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
package com.kri.notihub.server.persistence.repository;
|
package com.kri.notihub.server.persistence.repository;
|
||||||
|
|
||||||
import com.kri.notihub.server.persistence.entity.BizLogEntity;
|
import com.kri.notihub.server.persistence.entity.BizLogEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface BizLogRepository extends JpaRepository<BizLogEntity, String> {
|
public interface BizLogRepository extends JpaRepository<BizLogEntity, String> {
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ import com.kri.notihub.server.persistence.entity.BizMsgEntity;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface BizMsgRepository extends JpaRepository<BizMsgEntity, String> {
|
public interface BizMsgRepository extends JpaRepository<BizMsgEntity, String> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package com.kri.notihub.server.persistence.repository;
|
package com.kri.notihub.server.persistence.repository;
|
||||||
|
|
||||||
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
public interface BulkSendRepository extends JpaRepository<TBulkSendEntity, String> {
|
public interface BulkSendRepository extends JpaRepository<TBulkSendEntity, String> {
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package com.kri.notihub.server.persistence.repository;
|
package com.kri.notihub.server.persistence.repository;
|
||||||
|
|
||||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
public interface SendRepository extends JpaRepository<TSendEntity, Long> {
|
||||||
|
|
||||||
Optional<TSendEntity> findByCmid(String cmid);
|
Optional<TSendEntity> findByCmid(String cmid);
|
||||||
@@ -17,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("""
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.kri.notihub.server.persistence.entity.TSendResultCodeEntity;
|
|||||||
import com.kri.notihub.server.persistence.entity.TSendResultCodeEntityId;
|
import com.kri.notihub.server.persistence.entity.TSendResultCodeEntityId;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface SendResultCodeRepository extends JpaRepository<TSendResultCodeEntity, TSendResultCodeEntityId> {
|
public interface SendResultCodeRepository extends
|
||||||
|
JpaRepository<TSendResultCodeEntity, TSendResultCodeEntityId> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.kri.notihub.server.persistence.entity.TTmplatEventLogEntity;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
public interface TemplateEventLogRepository extends JpaRepository<TTmplatEventLogEntity, Long>, JpaSpecificationExecutor<TTmplatEventLogEntity> {
|
public interface TemplateEventLogRepository extends JpaRepository<TTmplatEventLogEntity, Long>,
|
||||||
|
JpaSpecificationExecutor<TTmplatEventLogEntity> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
package com.kri.notihub.server.persistence.repository;
|
package com.kri.notihub.server.persistence.repository;
|
||||||
|
|
||||||
import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
import org.springframework.data.jpa.repository.Modifying;
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
public interface TemplateRepository extends JpaRepository<TTmplatEntity, Long>,
|
||||||
import java.util.List;
|
JpaSpecificationExecutor<TTmplatEntity> {
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface TemplateRepository extends JpaRepository<TTmplatEntity, Long>, JpaSpecificationExecutor<TTmplatEntity> {
|
|
||||||
|
|
||||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Query("""
|
@Query("""
|
||||||
@@ -23,7 +23,8 @@ public interface TemplateRepository extends JpaRepository<TTmplatEntity, Long>,
|
|||||||
""")
|
""")
|
||||||
int softDeleteByTmplatIdx(long idx, String delUser, LocalDateTime delDt);
|
int softDeleteByTmplatIdx(long idx, String delUser, LocalDateTime delDt);
|
||||||
|
|
||||||
List<TTmplatEntity> findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(List<Short> tmplatTyList, String itrntPrjctCd);
|
List<TTmplatEntity> findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(List<Short> tmplatTyList,
|
||||||
|
String itrntPrjctCd);
|
||||||
|
|
||||||
Optional<TTmplatEntity> findByTmplatIdxAndDelFalse(long tmplatIdx);
|
Optional<TTmplatEntity> findByTmplatIdxAndDelFalse(long tmplatIdx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.feature.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.feature.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,22 +11,28 @@ 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.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@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;
|
||||||
@@ -36,11 +43,13 @@ public class BizLogResultScheduler {
|
|||||||
|
|
||||||
TimeWindow window = buildWindow(1L); // hours는 추후 파라미터화
|
TimeWindow window = buildWindow(1L); // hours는 추후 파라미터화
|
||||||
|
|
||||||
List<Short> sendTyList = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
List<Short> sendTyList = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode(), SendType.KKO_AT.getCode());
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
List<TSendEntity> batch = fetchRefreshTargets(sendTyList, window, 1000);
|
List<TSendEntity> batch = fetchRefreshTargets(sendTyList, window, 1000);
|
||||||
if (batch.isEmpty()) return;
|
if (batch.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BulkContext bulkCtx = loadBulkContext(batch);
|
BulkContext bulkCtx = loadBulkContext(batch);
|
||||||
|
|
||||||
@@ -55,7 +64,8 @@ public class BizLogResultScheduler {
|
|||||||
return new TimeWindow(toDt.minusHours(hours), toDt);
|
return new TimeWindow(toDt.minusHours(hours), toDt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TSendEntity> fetchRefreshTargets(List<Short> sendTyList, TimeWindow window, int size) {
|
private List<TSendEntity> fetchRefreshTargets(List<Short> sendTyList, TimeWindow window,
|
||||||
|
int size) {
|
||||||
return sendRepository.findSendListToRefreshWithinHours(
|
return sendRepository.findSendListToRefreshWithinHours(
|
||||||
sendTyList,
|
sendTyList,
|
||||||
SendStatusType.STANDBY.getCode(),
|
SendStatusType.STANDBY.getCode(),
|
||||||
@@ -65,7 +75,9 @@ public class BizLogResultScheduler {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** batch에서 bulkKey 수집 + bulk 엔티티 로딩 + Map 인덱싱 */
|
/**
|
||||||
|
* batch에서 bulkKey 수집 + bulk 엔티티 로딩 + Map 인덱싱
|
||||||
|
*/
|
||||||
private BulkContext loadBulkContext(List<TSendEntity> batch) {
|
private BulkContext loadBulkContext(List<TSendEntity> batch) {
|
||||||
Set<String> bulkKeys = extractBulkKeys(batch);
|
Set<String> bulkKeys = extractBulkKeys(batch);
|
||||||
|
|
||||||
@@ -93,7 +105,9 @@ public class BizLogResultScheduler {
|
|||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** BizLog 반영 + send/bulk delta 수집 */
|
/**
|
||||||
|
* BizLog 반영 + send/bulk delta 수집
|
||||||
|
*/
|
||||||
private BatchResult applyResultsAndCollectDeltas(List<TSendEntity> batch, BulkContext bulkCtx) {
|
private BatchResult applyResultsAndCollectDeltas(List<TSendEntity> batch, BulkContext bulkCtx) {
|
||||||
|
|
||||||
Map<String, Integer> successDelta = new HashMap<>();
|
Map<String, Integer> successDelta = new HashMap<>();
|
||||||
@@ -101,7 +115,9 @@ public class BizLogResultScheduler {
|
|||||||
List<TSendEntity> updatedSends = new ArrayList<>();
|
List<TSendEntity> updatedSends = new ArrayList<>();
|
||||||
|
|
||||||
for (TSendEntity s : batch) {
|
for (TSendEntity s : batch) {
|
||||||
if (!isResultPending(s)) continue;
|
if (!isResultPending(s)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Short beforeStatus = s.getSendStatus();
|
Short beforeStatus = s.getSendStatus();
|
||||||
|
|
||||||
@@ -117,13 +133,17 @@ public class BizLogResultScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isResultPending(TSendEntity s) {
|
private boolean isResultPending(TSendEntity s) {
|
||||||
if (s == null) return false;
|
if (s == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Short resultCode = s.getResultCode();
|
Short resultCode = s.getResultCode();
|
||||||
return resultCode != null
|
return resultCode != null
|
||||||
&& (resultCode == NotihubConst.SMS_STANDBY || resultCode == NotihubConst.LMS_MMS_STANDBY);
|
&& (resultCode == NotihubConst.SMS_STANDBY || resultCode == NotihubConst.LMS_MMS_STANDBY || resultCode == NotihubConst.KKO_AT_STANDBY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** STANDBY -> SUCCESS/FAIL 전이일 때만 bulk delta 누적 */
|
/**
|
||||||
|
* STANDBY -> SUCCESS/FAIL 전이일 때만 bulk delta 누적
|
||||||
|
*/
|
||||||
private void accumulateBulkDeltaIfNeeded(
|
private void accumulateBulkDeltaIfNeeded(
|
||||||
TSendEntity s,
|
TSendEntity s,
|
||||||
Short beforeStatus,
|
Short beforeStatus,
|
||||||
@@ -132,10 +152,16 @@ public class BizLogResultScheduler {
|
|||||||
Map<String, Integer> failDelta
|
Map<String, Integer> failDelta
|
||||||
) {
|
) {
|
||||||
String key = s.getBulkSendKey();
|
String key = s.getBulkSendKey();
|
||||||
if (key == null || key.isBlank()) return;
|
if (StringUtil.isNullOrBlank(key)) {
|
||||||
if (!bulkMap.containsKey(key)) return;
|
return;
|
||||||
|
}
|
||||||
|
if (!bulkMap.containsKey(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Objects.equals(beforeStatus, SendStatusType.STANDBY.getCode())) return;
|
if (!Objects.equals(beforeStatus, SendStatusType.STANDBY.getCode())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Objects.equals(s.getSendStatus(), SendStatusType.SUCCESS.getCode())) {
|
if (Objects.equals(s.getSendStatus(), SendStatusType.SUCCESS.getCode())) {
|
||||||
successDelta.merge(key, 1, Integer::sum);
|
successDelta.merge(key, 1, Integer::sum);
|
||||||
@@ -144,7 +170,9 @@ public class BizLogResultScheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 저장 + cursor + bulk 카운트 반영 */
|
/**
|
||||||
|
* 저장 + cursor + bulk 카운트 반영
|
||||||
|
*/
|
||||||
private void persistChanges(BatchResult result, BulkContext bulkCtx) {
|
private void persistChanges(BatchResult result, BulkContext bulkCtx) {
|
||||||
|
|
||||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
@@ -157,7 +185,9 @@ public class BizLogResultScheduler {
|
|||||||
cursorStore.set(result.updatedSends().get(result.updatedSends().size() - 1).getSendIdx());
|
cursorStore.set(result.updatedSends().get(result.updatedSends().size() - 1).getSendIdx());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bulkCtx.bulkMap().isEmpty()) return;
|
if (bulkCtx.bulkMap().isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
applyBulkCountDeltas(bulkCtx.bulkMap(), result.successDelta(), result.failDelta(), now);
|
applyBulkCountDeltas(bulkCtx.bulkMap(), result.successDelta(), result.failDelta(), now);
|
||||||
|
|
||||||
@@ -193,9 +223,13 @@ public class BizLogResultScheduler {
|
|||||||
// 완료 처리: trgt_cnt <= succes_cnt + fail_cnt 되는 순간 complete_dt 세팅
|
// 완료 처리: trgt_cnt <= succes_cnt + fail_cnt 되는 순간 complete_dt 세팅
|
||||||
for (String k : touched) {
|
for (String k : touched) {
|
||||||
TBulkSendEntity e = bulkMap.get(k);
|
TBulkSendEntity e = bulkMap.get(k);
|
||||||
if (e == null) continue;
|
if (e == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.getCompleteDt() != null) continue; // 이미 완료면 재세팅 방지
|
if (e.getCompleteDt() != null) {
|
||||||
|
continue; // 이미 완료면 재세팅 방지
|
||||||
|
}
|
||||||
|
|
||||||
int trgt = e.getTrgtCnt() == null ? 0 : e.getTrgtCnt();
|
int trgt = e.getTrgtCnt() == null ? 0 : e.getTrgtCnt();
|
||||||
int success = e.getSuccesCnt() == null ? 0 : e.getSuccesCnt();
|
int success = e.getSuccesCnt() == null ? 0 : e.getSuccesCnt();
|
||||||
@@ -214,7 +248,7 @@ public class BizLogResultScheduler {
|
|||||||
|
|
||||||
short callStatus = safeParseShort(log.getCallStatus(), NotihubConst.SMS_NOT_RESULT);
|
short callStatus = safeParseShort(log.getCallStatus(), NotihubConst.SMS_NOT_RESULT);
|
||||||
|
|
||||||
if (callStatus == NotihubConst.SMS_SUCCESS || callStatus == NotihubConst.LMS_MMS_SUCCESS) {
|
if (callStatus == NotihubConst.SMS_SUCCESS || callStatus == NotihubConst.LMS_MMS_SUCCESS || callStatus == NotihubConst.KKO_AT_SUCCESS) {
|
||||||
s.setSendStatus(SendStatusType.SUCCESS.getCode());
|
s.setSendStatus(SendStatusType.SUCCESS.getCode());
|
||||||
s.setResultCode(callStatus);
|
s.setResultCode(callStatus);
|
||||||
} else {
|
} else {
|
||||||
@@ -224,13 +258,27 @@ public class BizLogResultScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private short safeParseShort(String v, short fallback) {
|
private short safeParseShort(String v, short fallback) {
|
||||||
if (v == null || v.isBlank()) return fallback;
|
if (v == null || v.isBlank()) {
|
||||||
try { return Short.parseShort(v.trim()); } catch (Exception e) { return fallback; }
|
return fallback;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Short.parseShort(v.trim());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record TimeWindow(LocalDateTime from, LocalDateTime to) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private record BulkContext(Set<String> bulkKeys, Map<String, TBulkSendEntity> bulkMap) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private record TimeWindow(LocalDateTime from, LocalDateTime to) {}
|
|
||||||
private record BulkContext(Set<String> bulkKeys, Map<String, TBulkSendEntity> bulkMap) {}
|
|
||||||
private record BatchResult(List<TSendEntity> updatedSends,
|
private record BatchResult(List<TSendEntity> updatedSends,
|
||||||
Map<String, Integer> successDelta,
|
Map<String, Integer> successDelta,
|
||||||
Map<String, Integer> failDelta) {}
|
Map<String, Integer> failDelta) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.kri.notihub.server.scheduler;
|
package com.kri.notihub.server.scheduler;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
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;
|
||||||
@@ -8,23 +8,22 @@ import com.kri.notihub.server.common.external.pringo.dto.PringoJsonSendRequestDt
|
|||||||
import com.kri.notihub.server.dto.send.DestInfoDto;
|
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.persistence.entity.TSendEntity;
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
|
import com.kri.notihub.server.persistence.jdbc.SendBulkJdbcWriter;
|
||||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
import com.kri.notihub.server.service.SendEmailService;
|
import com.kri.notihub.server.service.SendEmailService;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SendReservationEmailScheduler {
|
public class SendReservationEmailScheduler {
|
||||||
|
|
||||||
private final PringoApiClient pringoApiClient;
|
|
||||||
private final SendEmailService sendEmlService;
|
private final SendEmailService sendEmlService;
|
||||||
private final SendRepository sendRepository;
|
private final SendRepository sendRepository;
|
||||||
|
|
||||||
@@ -43,7 +42,9 @@ public class SendReservationEmailScheduler {
|
|||||||
PageRequest.of(0, 1000)
|
PageRequest.of(0, 1000)
|
||||||
);
|
);
|
||||||
|
|
||||||
if(reservationList.isEmpty()) return;
|
if (reservationList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (TSendEntity s : reservationList) {
|
for (TSendEntity s : reservationList) {
|
||||||
PringoJsonSendRequestDto pringoReq = sendEmlService.buildPringoSendRequest(
|
PringoJsonSendRequestDto pringoReq = sendEmlService.buildPringoSendRequest(
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
package com.kri.notihub.server.scheduler;
|
package com.kri.notihub.server.scheduler;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.*;
|
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class TempFileCleanupScheduler {
|
public class TempFileCleanupScheduler {
|
||||||
@@ -27,8 +29,7 @@ public class TempFileCleanupScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 매일 자정(00:00)에 실행.
|
* 매일 자정(00:00)에 실행. 필요하면 application.yml 에서 kri.body-image.temp-cleanup-cron 으로 변경 가능.
|
||||||
* 필요하면 application.yml 에서 kri.body-image.temp-cleanup-cron 으로 변경 가능.
|
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "${kri.body-image.temp-cleanup-cron:0 0 0 * * *}")
|
@Scheduled(cron = "${kri.body-image.temp-cleanup-cron:0 0 0 * * *}")
|
||||||
public void cleanupOldTempFiles() {
|
public void cleanupOldTempFiles() {
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
|
import com.kri.common.feature.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.jdbc.BizMsgBulkJdbcWriter;
|
||||||
|
import com.kri.notihub.server.persistence.jdbc.SendBulkJdbcWriter;
|
||||||
|
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 AbstractSendService {
|
||||||
|
|
||||||
|
private final BizMsgBulkJdbcWriter bizMsgBulkJdbcWriter;
|
||||||
|
private final BizMsgRepository bizMsgRepository;
|
||||||
|
|
||||||
|
protected AbstractBizppurioSendService(
|
||||||
|
SendBulkJdbcWriter sendBulkJdbcWriter,
|
||||||
|
BizMsgBulkJdbcWriter bizMsgBulkJdbcWriter,
|
||||||
|
TemplateRepository templateRepository,
|
||||||
|
BulkSendRepository bulkSendRepository,
|
||||||
|
BizMsgRepository bizMsgRepository,
|
||||||
|
SendRepository sendRepository,
|
||||||
|
TemplateService templateService
|
||||||
|
) {
|
||||||
|
super(sendBulkJdbcWriter, templateRepository, bulkSendRepository, sendRepository, templateService);
|
||||||
|
this.bizMsgBulkJdbcWriter = bizMsgBulkJdbcWriter;
|
||||||
|
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();
|
||||||
|
bizMsgBulkJdbcWriter.bulkInsert(msgList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.feature.util.CommonUtil;
|
||||||
|
import com.kri.common.feature.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.jdbc.SendBulkJdbcWriter;
|
||||||
|
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 AbstractSendService {
|
||||||
|
|
||||||
|
private final PringoApiClient pringoApiClient;
|
||||||
|
private final EmailResultPoller emailResultPoller;
|
||||||
|
|
||||||
|
protected AbstractPringoSendService(
|
||||||
|
SendBulkJdbcWriter sendBulkJdbcWriter,
|
||||||
|
TemplateRepository templateRepository,
|
||||||
|
BulkSendRepository bulkSendRepository,
|
||||||
|
SendRepository sendRepository,
|
||||||
|
TemplateService templateService,
|
||||||
|
PringoApiClient pringoApiClient,
|
||||||
|
EmailResultPoller emailResultPoller
|
||||||
|
) {
|
||||||
|
super(sendBulkJdbcWriter, 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,375 @@
|
|||||||
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.StringUtils.firstNonBlank;
|
||||||
|
|
||||||
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
|
import com.kri.common.feature.web.BusinessException;
|
||||||
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
|
import com.kri.notihub.server.common.enums.ChannelType;
|
||||||
|
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||||
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
|
import com.kri.notihub.server.dto.send.BulkSendCreateRequestDto;
|
||||||
|
import com.kri.notihub.server.dto.send.BulkSendResponseDto;
|
||||||
|
import com.kri.notihub.server.dto.send.DestInfoDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendInternalResultDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendRequestBulkDto;
|
||||||
|
import com.kri.notihub.server.dto.send.SendRequestSingleDto;
|
||||||
|
import com.kri.notihub.server.dto.template.TemplateDto;
|
||||||
|
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
||||||
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
|
import com.kri.notihub.server.persistence.jdbc.SendBulkJdbcWriter;
|
||||||
|
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.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public abstract class AbstractSendService {
|
||||||
|
|
||||||
|
protected final SendBulkJdbcWriter sendBulkJdbcWriter;
|
||||||
|
protected final TemplateRepository templateRepository;
|
||||||
|
protected final BulkSendRepository bulkSendRepository;
|
||||||
|
protected final SendRepository sendRepository;
|
||||||
|
protected final TemplateService templateService;
|
||||||
|
|
||||||
|
protected static void sleepSilently(long ms) {
|
||||||
|
if (ms <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(ms);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String issueBulkKey(BulkSendCreateRequestDto req) {
|
||||||
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
|
if (req == null || req.getTmplatIdx() == null) {
|
||||||
|
throw BusinessException.badRequest("BULK_CREATE_INVALID", "tmplatIdx은 필수 입니다.");
|
||||||
|
}
|
||||||
|
if (req.getTrgtCnt() == null || req.getTrgtCnt() <= 0) {
|
||||||
|
throw BusinessException.badRequest("BULK_CREATE_INVALID", "trgtCnt는 0보다 커야 합니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.getResve()) {
|
||||||
|
if (req.getSendDt() == null) {
|
||||||
|
throw BusinessException.badRequest("BULK_CREATE_INVALID", "예약 발송의 경우 희망 발송일시가 필수 입니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.getSendDt().isAfter(now)) { // now보다 커야 함(같으면 불가)
|
||||||
|
throw BusinessException.badRequest("BULK_CREATE_INVALID",
|
||||||
|
"예약 발송의 경우 희망 발송일시는 현재시간 이후여야 합니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
||||||
|
validateTemplateType(tmplat);
|
||||||
|
|
||||||
|
TBulkSendEntity bulk = TBulkSendEntity.from(req, now);
|
||||||
|
TBulkSendEntity saved = bulkSendRepository.save(bulk);
|
||||||
|
|
||||||
|
return saved.getBulkSendKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void validateTemplateType(TemplateDto tmplat) {
|
||||||
|
ChannelType requiredType = getChannelType();
|
||||||
|
|
||||||
|
if (tmplat == null || requiredType == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int tmplatTy = tmplat.getTmplatTy().getCode() / 10;
|
||||||
|
int required = requiredType.getCode();
|
||||||
|
|
||||||
|
if (tmplat.getTmplatTy() == null || tmplatTy != required) {
|
||||||
|
throw BusinessException.badRequest("WRONG_TEMPLATE_TYPE", "템플릿 타입이 잘 못 됐습니다.")
|
||||||
|
.with("tmplatIdx", tmplat.getTmplatIdx())
|
||||||
|
.with("required", requiredType)
|
||||||
|
.with("tmplatTy", tmplat.getTmplatTy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void doSendSingle(SendRequestSingleDto req, String regCmpn, String regUser) {
|
||||||
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
|
if (req == null || req.getDestInfo() == null) {
|
||||||
|
throw BusinessException.badRequest("DEST_INFO_REQUIRED", "destInfo 는 필수입니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.getResve()) {
|
||||||
|
if (req.getSendDt() == null) {
|
||||||
|
throw BusinessException.badRequest("SEND_SINGLE_INVALID", "예약 발송의 경우 희망 발송일시가 필수 입니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.getSendDt().isAfter(now)) { // now보다 커야 함(같으면 불가)
|
||||||
|
throw BusinessException.badRequest("SEND_SINGLE_INVALID",
|
||||||
|
"예약 발송의 경우 희망 발송일시는 현재시간 이후여야 합니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
||||||
|
validateTemplateType(tmplat);
|
||||||
|
|
||||||
|
LocalDateTime sendDt = req.getSendDt() != null ? req.getSendDt() : now;
|
||||||
|
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
||||||
|
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
||||||
|
String sendFrom = isEmailChannel() ? sendEml : sendTel;
|
||||||
|
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
||||||
|
|
||||||
|
if (sendFrom == null || sendFrom.isBlank()) {
|
||||||
|
if (isEmailChannel()) {
|
||||||
|
throw BusinessException.badRequest("SEND_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
||||||
|
} else {
|
||||||
|
throw BusinessException.badRequest("SEND_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DestInfoDto dest = req.getDestInfo();
|
||||||
|
String sendTo = isEmailChannel() ? dest.getDestEml() : dest.getDestTel();
|
||||||
|
if (sendTo == null || sendTo.isBlank()) {
|
||||||
|
if (isEmailChannel()) {
|
||||||
|
throw BusinessException.badRequest("DEST_EMAIL_REQUIRED", "destEml은 필수 입니다.");
|
||||||
|
} else {
|
||||||
|
throw BusinessException.badRequest("DEST_TEL_REQUIRED", "destTel은 필수 입니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String msgTitle = replacePlaceholder(tmplat.getTmplatTitle(), dest.getMsgParam());
|
||||||
|
String msgBody = replacePlaceholder(tmplat.getTmplatBody(), dest.getMsgParam());
|
||||||
|
|
||||||
|
SendInternalResultDto sendResult = doSendInternal(
|
||||||
|
req.getResve(),
|
||||||
|
null,
|
||||||
|
tmplat.getTmplatTy(),
|
||||||
|
sendFrom,
|
||||||
|
sendNm,
|
||||||
|
msgTitle,
|
||||||
|
msgBody,
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
|
||||||
|
req.setSendEml(sendEml);
|
||||||
|
req.setSendTel(sendTel);
|
||||||
|
req.setSendNm(sendNm);
|
||||||
|
|
||||||
|
List<TSendEntity> sendInfo = new ArrayList<>(List.of(
|
||||||
|
TSendEntity.from(
|
||||||
|
req,
|
||||||
|
tmplat,
|
||||||
|
sendResult,
|
||||||
|
msgTitle,
|
||||||
|
msgBody,
|
||||||
|
regCmpn,
|
||||||
|
regUser,
|
||||||
|
req.getResve(),
|
||||||
|
sendDt,
|
||||||
|
now
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
sendRepository.save(sendInfo.get(0));
|
||||||
|
sendRepository.flush();
|
||||||
|
|
||||||
|
afterPersistSendEntities(sendInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final BulkSendResponseDto doSendBulk(SendRequestBulkDto req) {
|
||||||
|
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
|
String bulkSendKey = req.getBulkSendKey();
|
||||||
|
if (bulkSendKey.isBlank()) {
|
||||||
|
throw BusinessException.badRequest("BULK_SEND_KEY_REQUIRED", "bulkSendKey는 필수입니다.");
|
||||||
|
}
|
||||||
|
if (req == null || req.getDestInfoList() == null || req.getDestInfoList().isEmpty()) {
|
||||||
|
throw BusinessException.badRequest("DEST_LIST_REQUIRED", "수신 정보가 없습니다.");
|
||||||
|
}
|
||||||
|
|
||||||
|
TBulkSendEntity bulk = bulkSendRepository.findById(bulkSendKey)
|
||||||
|
.orElseThrow(() ->
|
||||||
|
BusinessException.badRequest("BULK_SEND_KEY_NOT_FOUND", "bulkSendKey가 잘 못 됐습니다.")
|
||||||
|
.with("bulkSendKey", bulkSendKey)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (bulk.getTrgtCnt() <= bulk.getSendCnt()) {
|
||||||
|
BusinessException.badRequest("OVERFLOW_SEND_CNT", "해당 bulkSendKey로 발송할 수 있는 한도를 초과 했습니다.")
|
||||||
|
.with("bulkSendKey", bulkSendKey)
|
||||||
|
.with("trgtCnt", bulk.getTrgtCnt())
|
||||||
|
.with("sendCnt", bulk.getSendCnt());
|
||||||
|
}
|
||||||
|
|
||||||
|
TemplateDto tmplat = templateService.getTemplate(bulk.getTmplatIdx());
|
||||||
|
validateTemplateType(tmplat);
|
||||||
|
|
||||||
|
Boolean isResve = bulk.getResve();
|
||||||
|
LocalDateTime sendDt = bulk.getSendDt() != null ? bulk.getSendDt() : now;
|
||||||
|
|
||||||
|
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
||||||
|
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
||||||
|
String sendFrom = isEmailChannel() ? sendEml : sendTel;
|
||||||
|
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
||||||
|
|
||||||
|
if (sendFrom == null || sendFrom.isBlank()) {
|
||||||
|
if (isEmailChannel()) {
|
||||||
|
throw BusinessException.badRequest("SENDER_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
||||||
|
} else {
|
||||||
|
throw BusinessException.badRequest("SENDER_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.setSendEml(sendEml);
|
||||||
|
req.setSendTel(sendTel);
|
||||||
|
req.setSendNm(sendNm);
|
||||||
|
|
||||||
|
int requestCnt = req.getDestInfoList().size();
|
||||||
|
int acceptCnt = 0;
|
||||||
|
int failCnt = 0;
|
||||||
|
|
||||||
|
List<TSendEntity> buffer = new ArrayList<>(
|
||||||
|
Math.min(requestCnt, NotihubConst.INSERT_CHUNK_SIZE));
|
||||||
|
|
||||||
|
for (int offset = 0; offset < requestCnt; offset += NotihubConst.CHUNK_SIZE) {
|
||||||
|
int end = Math.min(offset + NotihubConst.CHUNK_SIZE, requestCnt);
|
||||||
|
List<DestInfoDto> chunk = req.getDestInfoList().subList(offset, end);
|
||||||
|
|
||||||
|
for (DestInfoDto dest : chunk) {
|
||||||
|
String sendTo = isEmailChannel() ? dest.getDestEml() : dest.getDestTel();
|
||||||
|
if (dest == null || sendTo.isBlank()) {
|
||||||
|
failCnt++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String msgTitle = replacePlaceholder(tmplat.getTmplatTitle(), dest.getMsgParam());
|
||||||
|
String msgBody = replacePlaceholder(tmplat.getTmplatBody(), dest.getMsgParam());
|
||||||
|
|
||||||
|
SendInternalResultDto sendResult = doSendInternal(
|
||||||
|
isResve,
|
||||||
|
bulkSendKey,
|
||||||
|
tmplat.getTmplatTy(),
|
||||||
|
sendFrom,
|
||||||
|
sendNm,
|
||||||
|
msgTitle,
|
||||||
|
msgBody,
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sendResult.getStatus() == SendStatusType.SUCCESS) {
|
||||||
|
acceptCnt++;
|
||||||
|
} else if (sendResult.getStatus() == SendStatusType.FAIL) {
|
||||||
|
failCnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.add(
|
||||||
|
TSendEntity.from(
|
||||||
|
req,
|
||||||
|
dest,
|
||||||
|
tmplat,
|
||||||
|
sendResult,
|
||||||
|
bulk.getReqstSvc(),
|
||||||
|
bulk.getPrjctCd(),
|
||||||
|
msgTitle,
|
||||||
|
msgBody,
|
||||||
|
bulk.getRegCmpn(),
|
||||||
|
bulk.getRegUser(),
|
||||||
|
isResve,
|
||||||
|
sendDt,
|
||||||
|
bulkSendKey,
|
||||||
|
now
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isEmailChannel()) {
|
||||||
|
// 발송 간 딜레이(Pringo rate-limit 대응)
|
||||||
|
long delay = Math.max(tmplat.getDelayTime(), NotihubConst.EMAIL_DELAY);
|
||||||
|
sleepSilently(delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!buffer.isEmpty()) {
|
||||||
|
saveSendEntitiesChunked(buffer);
|
||||||
|
buffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// bulk 집계 업데이트(요청/성공/실패 카운트)
|
||||||
|
bulk.setSendCnt(Optional.ofNullable(bulk.getSendCnt()).orElse(0) + requestCnt);
|
||||||
|
bulk.setSuccesCnt(Optional.ofNullable(bulk.getSuccesCnt()).orElse(0) + acceptCnt);
|
||||||
|
bulk.setFailCnt(Optional.ofNullable(bulk.getFailCnt()).orElse(0) + failCnt);
|
||||||
|
bulkSendRepository.save(bulk);
|
||||||
|
|
||||||
|
return BulkSendResponseDto.of(bulkSendKey, requestCnt, acceptCnt, failCnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String replacePlaceholder(String text, Map<String, String> msgParam) {
|
||||||
|
if (text == null || text.isEmpty() || msgParam == null || msgParam.isEmpty()) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile("(?:\\[\\$|#\\{)([^\\]}]+)(?:]|})"); // [$A] 또는 #{A}
|
||||||
|
Matcher matcher = pattern.matcher(text);
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
while (matcher.find()) {
|
||||||
|
String varName = matcher.group(1);
|
||||||
|
String value = msgParam.get(varName);
|
||||||
|
|
||||||
|
if (value == null) {
|
||||||
|
// 값이 없으면 원문 유지
|
||||||
|
matcher.appendReplacement(sb, Matcher.quoteReplacement(matcher.group(0)));
|
||||||
|
} else {
|
||||||
|
// 값 치환 (정규식 replacement 안전 처리)
|
||||||
|
matcher.appendReplacement(sb, Matcher.quoteReplacement(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matcher.appendTail(sb);
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 자식 클래스가 구현: 실제 발송 수행
|
||||||
|
*/
|
||||||
|
protected abstract SendInternalResultDto doSendInternal(
|
||||||
|
Boolean isResve,
|
||||||
|
String bulkSendKey,
|
||||||
|
SendType sendType,
|
||||||
|
String sendFrom,
|
||||||
|
String sendNm,
|
||||||
|
String msgTitle,
|
||||||
|
String msgBody,
|
||||||
|
DestInfoDto dest
|
||||||
|
);
|
||||||
|
|
||||||
|
public abstract void afterPersistSendEntities(List<TSendEntity> persisted);
|
||||||
|
|
||||||
|
protected void saveSendEntitiesChunked(List<TSendEntity> entityList) {
|
||||||
|
if (entityList == null || entityList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int size = entityList.size();
|
||||||
|
for (int i = 0; i < size; i += NotihubConst.INSERT_CHUNK_SIZE) {
|
||||||
|
int end = Math.min(size, i + NotihubConst.INSERT_CHUNK_SIZE);
|
||||||
|
List<TSendEntity> sub = entityList.subList(i, end);
|
||||||
|
//sendRepository.saveAll(sub);
|
||||||
|
//sendRepository.flush();
|
||||||
|
sendBulkJdbcWriter.bulkInsert(sub);
|
||||||
|
|
||||||
|
afterPersistSendEntities(sub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isEmailChannel() {
|
||||||
|
return getChannelType() == ChannelType.EMAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract ChannelType getChannelType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
|
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BizppurioSendCursorStore {
|
||||||
|
|
||||||
|
// 프로세스 전역 커서(스레드 세이프)
|
||||||
|
private static final java.util.concurrent.atomic.AtomicLong CURSOR = new java.util.concurrent.atomic.AtomicLong(
|
||||||
|
0L);
|
||||||
|
private final SendRepository sendRepository;
|
||||||
|
|
||||||
|
// 서비스 기동 시: t_send에서 sendTy=SMS의 max(send_idx)로 초기화
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long get() {
|
||||||
|
return CURSOR.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(long sendIdx) {
|
||||||
|
CURSOR.set(sendIdx);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,16 +6,6 @@ import com.kri.notihub.server.dto.send.EmailPollQueueItemDto;
|
|||||||
import com.kri.notihub.server.dto.send.EmailPollQueueResponseDto;
|
import com.kri.notihub.server.dto.send.EmailPollQueueResponseDto;
|
||||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
import com.kri.notihub.server.persistence.repository.SendRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.event.EventListener;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.annotation.PreDestroy;
|
import jakarta.annotation.PreDestroy;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -27,14 +17,23 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.DelayQueue;
|
import java.util.concurrent.DelayQueue;
|
||||||
import java.util.concurrent.Delayed;
|
import java.util.concurrent.Delayed;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pringo는 발송요청/결과조회가 "1건씩"만 가능하므로, 동기(요청 스레드)에서 json_return을
|
* Pringo는 발송요청/결과조회가 "1건씩"만 가능하므로, 동기(요청 스레드)에서 json_return을 반복 호출하지 않고 Poller에서 비동기로 1회만 조회해 DB를
|
||||||
* 반복 호출하지 않고 Poller에서 비동기로 1회만 조회해 DB를 갱신한다.
|
* 갱신한다.
|
||||||
*
|
* <p>
|
||||||
* - 단건/벌크 공통: 발송요청 성공(return_key 수신) -> Poller enqueue -> (지연 후) json_return 1회 조회
|
* - 단건/벌크 공통: 발송요청 성공(return_key 수신) -> Poller enqueue -> (지연 후) json_return 1회 조회 - 서비스 재기동 시:
|
||||||
* - 서비스 재기동 시: STANDBY_EMAIL + RESULT_CODE_PENDING 인 레코드를 DB에서 스캔하여 재등록
|
* STANDBY_EMAIL + RESULT_CODE_PENDING 인 레코드를 DB에서 스캔하여 재등록
|
||||||
*
|
* <p>
|
||||||
* 운영 정책(딜레이/재시도 횟수)은 설정으로 조정 가능(기본: 재시도 0회).
|
* 운영 정책(딜레이/재시도 횟수)은 설정으로 조정 가능(기본: 재시도 0회).
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -46,22 +45,22 @@ public class EmailResultPoller {
|
|||||||
private final EmailResultUpdater emailResultUpdater;
|
private final EmailResultUpdater emailResultUpdater;
|
||||||
private final SendRepository sendRepository;
|
private final SendRepository sendRepository;
|
||||||
|
|
||||||
/** 런타임 중 중복 enqueue 방지(같은 returnKey를 여러 번 등록하지 않기 위함) */
|
/**
|
||||||
|
* 런타임 중 중복 enqueue 방지(같은 returnKey를 여러 번 등록하지 않기 위함)
|
||||||
|
*/
|
||||||
private final Set<String> scheduledKeys = ConcurrentHashMap.newKeySet();
|
private final Set<String> scheduledKeys = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
private volatile boolean running = true;
|
private volatile boolean running = true;
|
||||||
private Thread worker;
|
private Thread worker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 운영 권장값은 '최종 상태가 나올 가능성이 높은 지연'이다.
|
* 운영 권장값은 '최종 상태가 나올 가능성이 높은 지연'이다. 즉시성보다 '1회 조회로 최종 상태 반영'을 우선하면 60~180초 수준이 실무적으로 안정적이다.
|
||||||
* 즉시성보다 '1회 조회로 최종 상태 반영'을 우선하면 60~180초 수준이 실무적으로 안정적이다.
|
|
||||||
*/
|
*/
|
||||||
@Value("${kri.email.result-poll.initial-delay-ms:60000}")
|
@Value("${kri.email.result-poll.initial-delay-ms:60000}")
|
||||||
private long initialDelayMs;
|
private long initialDelayMs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 사용자는 json_return을 여러 번 호출하지 않을 예정이라고 했으므로 기본은 0(재시도 없음).
|
* 사용자는 json_return을 여러 번 호출하지 않을 예정이라고 했으므로 기본은 0(재시도 없음). 필요 시 설정으로 1~2 정도만 허용하는 것을 권장.
|
||||||
* 필요 시 설정으로 1~2 정도만 허용하는 것을 권장.
|
|
||||||
*/
|
*/
|
||||||
@Value("${kri.email.result-poll.max-attempts:0}")
|
@Value("${kri.email.result-poll.max-attempts:0}")
|
||||||
private int maxAttempts;
|
private int maxAttempts;
|
||||||
@@ -76,7 +75,9 @@ public class EmailResultPoller {
|
|||||||
private int recoverPageSize;
|
private int recoverPageSize;
|
||||||
|
|
||||||
public void enqueue(String returnKey) {
|
public void enqueue(String returnKey) {
|
||||||
if (returnKey == null || returnKey.isBlank()) return;
|
if (returnKey == null || returnKey.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
enqueueInternal(returnKey.trim(), initialDelayMs, 0);
|
enqueueInternal(returnKey.trim(), initialDelayMs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,9 +110,8 @@ public class EmailResultPoller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 서비스 재기동 시 유실된 PollTask를 복구한다.
|
* 서비스 재기동 시 유실된 PollTask를 복구한다. - DB(t_send)에 STANDBY_EMAIL로 남아 있는 Pringo 이메일 중, cmid가
|
||||||
* - DB(t_send)에 STANDBY_EMAIL로 남아 있는 Pringo 이메일 중, cmid가 return_key(숫자)인 레코드를 재등록
|
* return_key(숫자)인 레코드를 재등록 - in-memory 큐를 신뢰하지 않고, DB를 단일 소스 오브 트루스로 본다
|
||||||
* - in-memory 큐를 신뢰하지 않고, DB를 단일 소스 오브 트루스로 본다
|
|
||||||
*/
|
*/
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void recoverFromDbOnStartup() {
|
public void recoverFromDbOnStartup() {
|
||||||
@@ -126,7 +126,9 @@ public class EmailResultPoller {
|
|||||||
from,
|
from,
|
||||||
pageable
|
pageable
|
||||||
);
|
);
|
||||||
if (!p.hasContent()) break;
|
if (!p.hasContent()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (TSendEntity e : p.getContent()) {
|
for (TSendEntity e : p.getContent()) {
|
||||||
if (isNumeric(e.getCmid())) {
|
if (isNumeric(e.getCmid())) {
|
||||||
@@ -135,7 +137,9 @@ public class EmailResultPoller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p.hasNext()) break;
|
if (!p.hasNext()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
pageable = p.nextPageable();
|
pageable = p.nextPageable();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -159,7 +163,8 @@ public class EmailResultPoller {
|
|||||||
|
|
||||||
boolean done = emailResultUpdater.tryUpdateEmailResult(task.returnKey);
|
boolean done = emailResultUpdater.tryUpdateEmailResult(task.returnKey);
|
||||||
if (!done && task.attempt < maxAttempts) {
|
if (!done && task.attempt < maxAttempts) {
|
||||||
long nextDelay = Math.min((long) (initialDelayMs * Math.pow(2, task.attempt + 1)), maxDelayMs);
|
long nextDelay = Math.min((long) (initialDelayMs * Math.pow(2, task.attempt + 1)),
|
||||||
|
maxDelayMs);
|
||||||
enqueueInternal(task.returnKey, nextDelay, task.attempt + 1);
|
enqueueInternal(task.returnKey, nextDelay, task.attempt + 1);
|
||||||
} else if (!done) {
|
} else if (!done) {
|
||||||
// 더 이상 재시도하지 않는 경우: 재기동 복구/중복 조회를 막기 위해 '조회 실패'로 마킹
|
// 더 이상 재시도하지 않는 경우: 재기동 복구/중복 조회를 막기 위해 '조회 실패'로 마킹
|
||||||
@@ -180,19 +185,27 @@ public class EmailResultPoller {
|
|||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void stop() {
|
public void stop() {
|
||||||
running = false;
|
running = false;
|
||||||
if (worker != null) worker.interrupt();
|
if (worker != null) {
|
||||||
|
worker.interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enqueueInternal(String returnKey, long delayMs, int attempt) {
|
private void enqueueInternal(String returnKey, long delayMs, int attempt) {
|
||||||
if (!scheduledKeys.add(returnKey)) return;
|
if (!scheduledKeys.add(returnKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
queue.offer(new PollTask(returnKey, attempt, delayMs));
|
queue.offer(new PollTask(returnKey, attempt, delayMs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNumeric(String s) {
|
private boolean isNumeric(String s) {
|
||||||
if (s == null || s.isBlank()) return false;
|
if (s == null || s.isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (int i = 0; i < s.length(); i++) {
|
for (int i = 0; i < s.length(); i++) {
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
if (c < '0' || c > '9') return false;
|
if (c < '0' || c > '9') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -211,6 +224,7 @@ public class EmailResultPoller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static final class PollTask implements Delayed {
|
static final class PollTask implements Delayed {
|
||||||
|
|
||||||
final String returnKey;
|
final String returnKey;
|
||||||
final int attempt;
|
final int attempt;
|
||||||
final long triggerAtNanos;
|
final long triggerAtNanos;
|
||||||
@@ -230,17 +244,24 @@ public class EmailResultPoller {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Delayed o) {
|
public int compareTo(Delayed o) {
|
||||||
if (o == this) return 0;
|
if (o == this) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
PollTask other = (PollTask) o;
|
PollTask other = (PollTask) o;
|
||||||
return Long.compare(this.triggerAtNanos, other.triggerAtNanos);
|
return Long.compare(this.triggerAtNanos, other.triggerAtNanos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (!(o instanceof PollTask)) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (!(o instanceof PollTask)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
PollTask pollTask = (PollTask) o;
|
PollTask pollTask = (PollTask) o;
|
||||||
return attempt == pollTask.attempt && Objects.equals(returnKey, pollTask.returnKey) && triggerAtNanos == pollTask.triggerAtNanos;
|
return attempt == pollTask.attempt && Objects.equals(returnKey, pollTask.returnKey)
|
||||||
|
&& triggerAtNanos == pollTask.triggerAtNanos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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.feature.datetime.DateTimeUtil;
|
||||||
import com.kri.common.util.CommonUtil;
|
import com.kri.common.feature.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;
|
||||||
@@ -10,13 +10,12 @@ import com.kri.notihub.server.common.external.pringo.dto.PringoJsonReturnRespons
|
|||||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
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 java.time.LocalDateTime;
|
||||||
|
import java.util.Optional;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -28,17 +27,21 @@ class EmailResultUpdater {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Pringo 결과 조회 후 t_send 갱신
|
* Pringo 결과 조회 후 t_send 갱신
|
||||||
|
*
|
||||||
* @return true: 결과 조회 성공 및 갱신 완료, false: 아직 결과 없음/조회 실패
|
* @return true: 결과 조회 성공 및 갱신 완료, false: 아직 결과 없음/조회 실패
|
||||||
*/
|
*/
|
||||||
public boolean tryUpdateEmailResult(String returnKey) {
|
public boolean tryUpdateEmailResult(String returnKey) {
|
||||||
Optional<TSendEntity> opt = sendRepository.findByCmid(returnKey);
|
Optional<TSendEntity> opt = sendRepository.findByCmid(returnKey);
|
||||||
if (opt.isEmpty()) return false;
|
if (opt.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
TSendEntity e = opt.get();
|
TSendEntity e = opt.get();
|
||||||
try {
|
try {
|
||||||
PringoJsonReturnResponseDto resp = pringoApiClient.jsonReturn(Long.valueOf(returnKey));
|
PringoJsonReturnResponseDto resp = pringoApiClient.jsonReturn(Long.valueOf(returnKey));
|
||||||
if (resp == null || !resp.isSuccess() || resp.getItemList() == null || resp.getItemList().isEmpty()) {
|
if (resp == null || !resp.isSuccess() || resp.getItemList() == null || resp.getItemList()
|
||||||
|
.isEmpty()) {
|
||||||
e.setResultCode(NotihubConst.EMAIL_NOT_RESULT);
|
e.setResultCode(NotihubConst.EMAIL_NOT_RESULT);
|
||||||
e.setReportDt(now);
|
e.setReportDt(now);
|
||||||
sendRepository.save(e);
|
sendRepository.save(e);
|
||||||
@@ -53,11 +56,11 @@ class EmailResultUpdater {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short resultCode = NumericUtil.safeParseShort(item.getStatus(), NotihubConst.EMAIL_NOT_RESULT);
|
||||||
short resultCode = CommonUtil.safeParseShort(item.getStatus(), NotihubConst.EMAIL_NOT_RESULT);
|
|
||||||
|
|
||||||
//resultCode를 대상으로 Success인지 아닌지 판별 필요
|
//resultCode를 대상으로 Success인지 아닌지 판별 필요
|
||||||
SendStatusType sendStatus = resultCode == NotihubConst.EMAIL_SUCCESS? SendStatusType.SUCCESS : SendStatusType.FAIL;
|
SendStatusType sendStatus =
|
||||||
|
resultCode == NotihubConst.EMAIL_SUCCESS ? SendStatusType.SUCCESS : SendStatusType.FAIL;
|
||||||
e.setSendStatus(sendStatus.getCode());
|
e.setSendStatus(sendStatus.getCode());
|
||||||
e.setResultCode(resultCode);
|
e.setResultCode(resultCode);
|
||||||
e.setReportDt(DateTimeUtil.parseLocalDateTime(item.getSendTime()));
|
e.setReportDt(DateTimeUtil.parseLocalDateTime(item.getSendTime()));
|
||||||
@@ -67,8 +70,7 @@ class EmailResultUpdater {
|
|||||||
bulkSendRepository.findByBulkSendKey(e.getBulkSendKey()).ifPresent(bulk -> {
|
bulkSendRepository.findByBulkSendKey(e.getBulkSendKey()).ifPresent(bulk -> {
|
||||||
if (sendStatus == SendStatusType.SUCCESS) {
|
if (sendStatus == SendStatusType.SUCCESS) {
|
||||||
bulk.setSuccesCnt(bulk.getSuccesCnt() + 1);
|
bulk.setSuccesCnt(bulk.getSuccesCnt() + 1);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
bulk.setFailCnt(bulk.getFailCnt() + 1);
|
bulk.setFailCnt(bulk.getFailCnt() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
package com.kri.notihub.server.service;
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
import com.kri.common.file.FileUtil;
|
import com.kri.common.feature.file.FileUtil;
|
||||||
import com.kri.common.util.CommonUtil;
|
import com.kri.common.feature.util.CommonUtil;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
@@ -12,14 +22,9 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.*;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class FileService {
|
public class FileService {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(FileService.class);
|
private static final Logger log = LoggerFactory.getLogger(FileService.class);
|
||||||
private final Path uploadBaseDir; // ex) /data/upload-file/body-image
|
private final Path uploadBaseDir; // ex) /data/upload-file/body-image
|
||||||
private final String publicBaseUrlPrefix; // ex) /upload-file/body-image
|
private final String publicBaseUrlPrefix; // ex) /upload-file/body-image
|
||||||
@@ -63,13 +68,13 @@ public class FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 컨택 시나리오 저장 시:
|
* 컨택 시나리오 저장 시: 1) HTML 내 Temp 이미지 -> Asset으로 이동 & src 수정 2) Asset 디렉토리에서 더 이상 사용되지 않는 파일 삭제 3)
|
||||||
* 1) HTML 내 Temp 이미지 -> Asset으로 이동 & src 수정
|
* 정리된 HTML 반환
|
||||||
* 2) Asset 디렉토리에서 더 이상 사용되지 않는 파일 삭제
|
|
||||||
* 3) 정리된 HTML 반환
|
|
||||||
*/
|
*/
|
||||||
public String syncOnSave(String prjctCd, Long tmplatIdx, String rawHtml) {
|
public String syncOnSave(String prjctCd, Long tmplatIdx, String rawHtml) {
|
||||||
if (rawHtml == null) rawHtml = "";
|
if (rawHtml == null) {
|
||||||
|
rawHtml = "";
|
||||||
|
}
|
||||||
|
|
||||||
String returnHtml = rawHtml;
|
String returnHtml = rawHtml;
|
||||||
try {
|
try {
|
||||||
@@ -81,8 +86,12 @@ public class FileService {
|
|||||||
|
|
||||||
for (Element img : imgs) {
|
for (Element img : imgs) {
|
||||||
String src = img.attr("src");
|
String src = img.attr("src");
|
||||||
if (src == null || src.isBlank()) continue;
|
if (src == null || src.isBlank()) {
|
||||||
if (!src.contains("/" + prjctCd + "/")) continue;
|
continue;
|
||||||
|
}
|
||||||
|
if (!src.contains("/" + prjctCd + "/")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String fileName = FileUtil.extractFileNameFromPath(src);
|
String fileName = FileUtil.extractFileNameFromPath(src);
|
||||||
|
|
||||||
@@ -101,7 +110,8 @@ public class FileService {
|
|||||||
|
|
||||||
copyAssetToAsset(prjctCd, fromTmplatIdx, tmplatIdx, fileName);
|
copyAssetToAsset(prjctCd, fromTmplatIdx, tmplatIdx, fileName);
|
||||||
|
|
||||||
String assetSrc = src.replace("/Asset/" + fromTmplatIdx + "/", "/Asset/" + tmplatIdx + "/");
|
String assetSrc = src.replace("/Asset/" + fromTmplatIdx + "/",
|
||||||
|
"/Asset/" + tmplatIdx + "/");
|
||||||
img.attr("src", assetSrc);
|
img.attr("src", assetSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +124,7 @@ public class FileService {
|
|||||||
|
|
||||||
// body 안의 HTML만 반환 (불필요한 <html><body> wrapper 제거)
|
// body 안의 HTML만 반환 (불필요한 <html><body> wrapper 제거)
|
||||||
returnHtml = doc.body().html();
|
returnHtml = doc.body().html();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
log.warn("temp 파일 이동 실패: {}", rawHtml, e);
|
log.warn("temp 파일 이동 실패: {}", rawHtml, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,8 +151,11 @@ public class FileService {
|
|||||||
return uploadBaseDir.resolve(prjctCd).resolve("Asset").resolve(tmplatIdx.toString());
|
return uploadBaseDir.resolve(prjctCd).resolve("Asset").resolve(tmplatIdx.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyAssetToAsset(String prjctCd, String fromTmplatIdx, Long toTmplatIdx, String fileName) throws IOException {
|
private void copyAssetToAsset(String prjctCd, String fromTmplatIdx, Long toTmplatIdx,
|
||||||
if (fileName == null || fileName.isBlank()) return;
|
String fileName) throws IOException {
|
||||||
|
if (fileName == null || fileName.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Path fromDir = getAssetDir(prjctCd, fromTmplatIdx);
|
Path fromDir = getAssetDir(prjctCd, fromTmplatIdx);
|
||||||
Path toDir = getAssetDir(prjctCd, toTmplatIdx);
|
Path toDir = getAssetDir(prjctCd, toTmplatIdx);
|
||||||
|
|
||||||
@@ -160,7 +172,9 @@ public class FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void moveTempToAsset(String prjctCd, Long tmplatIdx, String fileName) throws IOException {
|
private void moveTempToAsset(String prjctCd, Long tmplatIdx, String fileName) throws IOException {
|
||||||
if (fileName == null || fileName.isBlank()) return;
|
if (fileName == null || fileName.isBlank()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Path tempDir = getTempDir(prjctCd);
|
Path tempDir = getTempDir(prjctCd);
|
||||||
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
||||||
@@ -180,13 +194,18 @@ public class FileService {
|
|||||||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanupAssetDir(String prjctCd, Long tmplatIdx, Set<String> keepFileNames) throws IOException {
|
private void cleanupAssetDir(String prjctCd, Long tmplatIdx, Set<String> keepFileNames)
|
||||||
|
throws IOException {
|
||||||
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
Path assetDir = getAssetDir(prjctCd, tmplatIdx);
|
||||||
if (!Files.exists(assetDir)) return;
|
if (!Files.exists(assetDir)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(assetDir)) {
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(assetDir)) {
|
||||||
for (Path path : stream) {
|
for (Path path : stream) {
|
||||||
if (!Files.isRegularFile(path)) continue;
|
if (!Files.isRegularFile(path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
String fileName = path.getFileName().toString();
|
String fileName = path.getFileName().toString();
|
||||||
if (!keepFileNames.contains(fileName)) {
|
if (!keepFileNames.contains(fileName)) {
|
||||||
Files.deleteIfExists(path);
|
Files.deleteIfExists(path);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.kri.notihub.server.service;
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
import com.kri.common.excel.ExcelMapper;
|
import com.kri.common.feature.excel.ExcelMapper;
|
||||||
import com.kri.common.web.BusinessException;
|
import com.kri.common.feature.web.BusinessException;
|
||||||
import com.kri.common.webmvc.page.PageRequestDto;
|
import com.kri.common.feature.web.page.PageRequestDto;
|
||||||
import com.kri.common.webmvc.page.PageResponseDto;
|
import com.kri.common.feature.web.page.PageResponseDto;
|
||||||
import com.kri.common.webmvc.page.Pageables;
|
import com.kri.common.feature.web.page.Pageables;
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
import com.kri.notihub.server.dto.report.BulkSendInfoDto;
|
||||||
@@ -16,13 +16,6 @@ import com.kri.notihub.server.persistence.entity.TSendResultCodeEntity;
|
|||||||
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.SendResultCodeRepository;
|
import com.kri.notihub.server.persistence.repository.SendResultCodeRepository;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -30,6 +23,12 @@ import java.time.LocalDateTime;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -39,20 +38,23 @@ public class ReportService {
|
|||||||
private final BulkSendRepository bulkSendRepository;
|
private final BulkSendRepository bulkSendRepository;
|
||||||
private final SendRepository sendRepository;
|
private final SendRepository sendRepository;
|
||||||
|
|
||||||
public List<BulkSendInfoDto> getBulkSendList(SendType sendTy, String reqstSvc, String prjctCd, String regCmpn){
|
public List<BulkSendInfoDto> getBulkSendList(SendType sendTy, String reqstSvc, String prjctCd,
|
||||||
List<Short> sendTyList = sendTy == SendType.EMAIL ? List.of(SendType.EMAIL.getCode()) : List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
String regCmpn) {
|
||||||
|
List<Short> sendTyList = sendTy == SendType.EMAIL ? List.of(SendType.EMAIL.getCode())
|
||||||
|
: List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
||||||
|
|
||||||
if (regCmpn == null) {
|
if (regCmpn == null) {
|
||||||
return bulkSendRepository.findBySendTyInAndReqstSvcAndPrjctCd(sendTyList, reqstSvc, prjctCd)
|
return bulkSendRepository.findBySendTyInAndReqstSvcAndPrjctCd(sendTyList, reqstSvc, prjctCd)
|
||||||
.stream().map(BulkSendInfoDto::from).toList();
|
.stream().map(BulkSendInfoDto::from).toList();
|
||||||
}
|
} else {
|
||||||
else{
|
return bulkSendRepository.findBySendTyInAndReqstSvcAndPrjctCdAndRegCmpn(sendTyList, reqstSvc,
|
||||||
return bulkSendRepository.findBySendTyInAndReqstSvcAndPrjctCdAndRegCmpn(sendTyList, reqstSvc, prjctCd, regCmpn)
|
prjctCd, regCmpn)
|
||||||
.stream().map(BulkSendInfoDto::from).toList();
|
.stream().map(BulkSendInfoDto::from).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PageResponseDto<SendInfoDto> getBulkSendDetail(String bulkSendKey, PageRequestDto pageReq){
|
public PageResponseDto<SendInfoDto> getBulkSendDetail(String bulkSendKey,
|
||||||
|
PageRequestDto pageReq) {
|
||||||
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
List<TSendResultCodeEntity> resultCodeList = sendResultCodeRepository.findAll();
|
||||||
|
|
||||||
Pageable pageable = Pageables.of(pageReq, TSendEntity.class);
|
Pageable pageable = Pageables.of(pageReq, TSendEntity.class);
|
||||||
@@ -74,7 +76,8 @@ public class ReportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String ts = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
|
String ts = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"));
|
||||||
String fileName = "대량 발송 내역_%s_%s_%s.xlsx".formatted(bulkSend.getReqstSvc(), bulkSend.getPrjctCd(), ts);
|
String fileName = "대량 발송 내역_%s_%s_%s.xlsx".formatted(bulkSend.getReqstSvc(),
|
||||||
|
bulkSend.getPrjctCd(), ts);
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(64 * 1024);
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(64 * 1024);
|
||||||
|
|
||||||
@@ -90,7 +93,9 @@ public class ReportService {
|
|||||||
PageRequest.of(page++, NotihubConst.CHUNK_SIZE, sort)
|
PageRequest.of(page++, NotihubConst.CHUNK_SIZE, sort)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (chunkPage.isEmpty()) break;
|
if (chunkPage.isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
List<SendInfoDto> chunk = chunkPage.getContent()
|
List<SendInfoDto> chunk = chunkPage.getContent()
|
||||||
.stream()
|
.stream()
|
||||||
@@ -99,13 +104,16 @@ public class ReportService {
|
|||||||
|
|
||||||
writer.appendAll(chunk);
|
writer.appendAll(chunk);
|
||||||
|
|
||||||
if (!chunkPage.hasNext()) break;
|
if (!chunkPage.hasNext()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//최종 1회 write (XLSX 마무리)
|
//최종 1회 write (XLSX 마무리)
|
||||||
writer.writeTo(b64Out);
|
writer.writeTo(b64Out);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw BusinessException.internalError("FAIL MAKE EXCEL","엑셀(Base64) 생성 실패. " + e.getMessage())
|
throw BusinessException.internalError("FAIL MAKE EXCEL",
|
||||||
|
"엑셀(Base64) 생성 실패. " + e.getMessage())
|
||||||
.with("bulkSendKey", bulkSendKey);
|
.with("bulkSendKey", bulkSendKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,157 +1,32 @@
|
|||||||
package com.kri.notihub.server.service;
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.notihub.server.common.enums.ChannelType;
|
||||||
import com.kri.common.util.CommonUtil;
|
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
|
||||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
|
||||||
import com.kri.notihub.server.common.enums.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.persistence.jdbc.SendBulkJdbcWriter;
|
||||||
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 lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
@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(
|
||||||
|
SendBulkJdbcWriter sendBulkJdbcWriter,
|
||||||
TemplateRepository templateRepository,
|
TemplateRepository templateRepository,
|
||||||
BulkSendRepository bulkSendRepository,
|
BulkSendRepository bulkSendRepository,
|
||||||
SendRepository sendRepository,
|
SendRepository sendRepository,
|
||||||
TemplateService templateService,
|
TemplateService templateService,
|
||||||
PringoApiClient pringoApiClient,
|
PringoApiClient pringoApiClient,
|
||||||
EmailResultPoller emailResultPoller,
|
EmailResultPoller emailResultPoller
|
||||||
EmailResultUpdater emailResultUpdater
|
|
||||||
) {
|
) {
|
||||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
super(sendBulkJdbcWriter, 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,52 @@
|
|||||||
|
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.jdbc.BizMsgBulkJdbcWriter;
|
||||||
|
import com.kri.notihub.server.persistence.jdbc.SendBulkJdbcWriter;
|
||||||
|
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(
|
||||||
|
SendBulkJdbcWriter sendBulkJdbcWriter,
|
||||||
|
BizMsgBulkJdbcWriter bizMsgBulkJdbcWriter,
|
||||||
|
TemplateRepository templateRepository,
|
||||||
|
BulkSendRepository bulkSendRepository,
|
||||||
|
BizMsgRepository bizMsgRepository,
|
||||||
|
SendRepository sendRepository,
|
||||||
|
TemplateService templateService
|
||||||
|
) {
|
||||||
|
super(sendBulkJdbcWriter, bizMsgBulkJdbcWriter,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; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,350 +0,0 @@
|
|||||||
package com.kri.notihub.server.service;
|
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
|
||||||
import com.kri.common.web.BusinessException;
|
|
||||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
|
||||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
|
||||||
import com.kri.notihub.server.dto.send.*;
|
|
||||||
import com.kri.notihub.server.dto.template.TemplateDto;
|
|
||||||
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
|
||||||
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 lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static org.apache.commons.lang3.StringUtils.firstNonBlank;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public abstract class SendService {
|
|
||||||
|
|
||||||
protected final TemplateRepository templateRepository;
|
|
||||||
protected final BulkSendRepository bulkSendRepository;
|
|
||||||
protected final SendRepository sendRepository;
|
|
||||||
protected final TemplateService templateService;
|
|
||||||
|
|
||||||
public String issueBulkKey(BulkSendCreateRequestDto req) {
|
|
||||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
|
||||||
|
|
||||||
if (req == null || req.getTmplatIdx() == null) {
|
|
||||||
throw BusinessException.badRequest("BULK_CREATE_INVALID", "tmplatIdx은 필수 입니다.");
|
|
||||||
}
|
|
||||||
if (req.getTrgtCnt() == null || req.getTrgtCnt() <= 0) {
|
|
||||||
throw BusinessException.badRequest("BULK_CREATE_INVALID", "trgtCnt는 0보다 커야 합니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.getResve()) {
|
|
||||||
if (req.getSendDt() == null) {
|
|
||||||
throw BusinessException.badRequest("BULK_CREATE_INVALID", "예약 발송의 경우 희망 발송일시가 필수 입니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.getSendDt().isAfter(now)) { // now보다 커야 함(같으면 불가)
|
|
||||||
throw BusinessException.badRequest("BULK_CREATE_INVALID", "예약 발송의 경우 희망 발송일시는 현재시간 이후여야 합니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
|
||||||
validateTemplateType(tmplat, getSendType());
|
|
||||||
|
|
||||||
TBulkSendEntity bulk = TBulkSendEntity.from(req, now);
|
|
||||||
TBulkSendEntity saved = bulkSendRepository.save(bulk);
|
|
||||||
|
|
||||||
return saved.getBulkSendKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void validateTemplateType(TemplateDto tmplat, SendType requiredType) {
|
|
||||||
if (tmplat == null || requiredType == null) return;
|
|
||||||
|
|
||||||
int tmplatTy = tmplat.getTmplatTy().getCode()/10;
|
|
||||||
int required = requiredType.getCode()/10;
|
|
||||||
|
|
||||||
if (tmplat.getTmplatTy() == null || tmplatTy != required) {
|
|
||||||
throw BusinessException.badRequest("WRONG_TEMPLATE_TYPE","템플릿 타입이 잘 못 됐습니다.")
|
|
||||||
.with("tmplatIdx", tmplat.getTmplatIdx())
|
|
||||||
.with("required", requiredType)
|
|
||||||
.with("tmplatTy", tmplat.getTmplatTy());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void doSendSingle(SendRequestSingleDto req, String regCmpn, String regUser) {
|
|
||||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
|
||||||
|
|
||||||
if (req == null || req.getDestInfo() == null) {
|
|
||||||
throw BusinessException.badRequest("DEST_INFO_REQUIRED", "destInfo 는 필수입니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.getResve()) {
|
|
||||||
if (req.getSendDt() == null) {
|
|
||||||
throw BusinessException.badRequest("SEND_SINGLE_INVALID", "예약 발송의 경우 희망 발송일시가 필수 입니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.getSendDt().isAfter(now)) { // now보다 커야 함(같으면 불가)
|
|
||||||
throw BusinessException.badRequest("SEND_SINGLE_INVALID", "예약 발송의 경우 희망 발송일시는 현재시간 이후여야 합니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TemplateDto tmplat = templateService.getTemplate(req.getTmplatIdx());
|
|
||||||
validateTemplateType(tmplat, getSendType());
|
|
||||||
|
|
||||||
LocalDateTime sendDt = req.getSendDt() != null ? req.getSendDt() : now;
|
|
||||||
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
|
||||||
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
|
||||||
String sendFrom = getSendType() == SendType.EMAIL ? sendEml : sendTel;
|
|
||||||
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
|
||||||
|
|
||||||
if (sendFrom == null || sendFrom.isBlank()) {
|
|
||||||
if (getSendType() == SendType.EMAIL) {
|
|
||||||
throw BusinessException.badRequest("SEND_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
|
||||||
} else {
|
|
||||||
throw BusinessException.badRequest("SEND_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DestInfoDto dest = req.getDestInfo();
|
|
||||||
String sendTo = getSendType() == SendType.EMAIL ? dest.getDestEml() : dest.getDestTel();
|
|
||||||
if (sendTo == null || sendTo.isBlank()) {
|
|
||||||
if (getSendType() == SendType.EMAIL) {
|
|
||||||
throw BusinessException.badRequest("DEST_EMAIL_REQUIRED", "destEml은 필수 입니다.");
|
|
||||||
} else {
|
|
||||||
throw BusinessException.badRequest("DEST_TEL_REQUIRED", "destTel은 필수 입니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String msgTitle = replacePlaceholder(tmplat.getTmplatTitle(), dest.getMsgParam());
|
|
||||||
String msgBody = replacePlaceholder(tmplat.getTmplatBody(), dest.getMsgParam());
|
|
||||||
|
|
||||||
SendInternalResultDto sendResult = doSendInternal(
|
|
||||||
req.getResve(),
|
|
||||||
null,
|
|
||||||
tmplat.getTmplatTy(),
|
|
||||||
sendFrom,
|
|
||||||
sendNm,
|
|
||||||
msgTitle,
|
|
||||||
msgBody,
|
|
||||||
dest
|
|
||||||
);
|
|
||||||
|
|
||||||
req.setSendEml(sendEml);
|
|
||||||
req.setSendTel(sendTel);
|
|
||||||
req.setSendNm(sendNm);
|
|
||||||
|
|
||||||
List<TSendEntity> sendInfo = new ArrayList<>(List.of(
|
|
||||||
TSendEntity.from(
|
|
||||||
req,
|
|
||||||
tmplat.getTmplatTy(),
|
|
||||||
sendResult,
|
|
||||||
tmplat.getItrntPrjctCd(),
|
|
||||||
msgTitle,
|
|
||||||
msgBody,
|
|
||||||
regCmpn,
|
|
||||||
regUser,
|
|
||||||
req.getResve(),
|
|
||||||
sendDt,
|
|
||||||
now
|
|
||||||
)
|
|
||||||
));
|
|
||||||
|
|
||||||
sendRepository.saveAll(sendInfo);
|
|
||||||
sendRepository.flush();
|
|
||||||
|
|
||||||
afterPersistSendEntities(sendInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final BulkSendResponseDto doSendBulk(SendRequestBulkDto req) {
|
|
||||||
LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
|
||||||
|
|
||||||
String bulkSendKey = req.getBulkSendKey();
|
|
||||||
if (bulkSendKey.isBlank()) throw BusinessException.badRequest("BULK_SEND_KEY_REQUIRED", "bulkSendKey는 필수입니다.");
|
|
||||||
if (req == null || req.getDestInfoList() == null || req.getDestInfoList().isEmpty()) {
|
|
||||||
throw BusinessException.badRequest("DEST_LIST_REQUIRED", "수신 정보가 없습니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
TBulkSendEntity bulk = bulkSendRepository.findById(bulkSendKey)
|
|
||||||
.orElseThrow(() ->
|
|
||||||
BusinessException.badRequest("BULK_SEND_KEY_NOT_FOUND", "bulkSendKey가 잘 못 됐습니다.")
|
|
||||||
.with("bulkSendKey", bulkSendKey)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(bulk.getTrgtCnt() <= bulk.getSendCnt()){
|
|
||||||
BusinessException.badRequest("OVERFLOW_SEND_CNT", "해당 bulkSendKey로 발송할 수 있는 한도를 초과 했습니다.")
|
|
||||||
.with("bulkSendKey", bulkSendKey)
|
|
||||||
.with("trgtCnt", bulk.getTrgtCnt())
|
|
||||||
.with("sendCnt", bulk.getSendCnt());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TemplateDto tmplat = templateService.getTemplate(bulk.getTmplatIdx());
|
|
||||||
validateTemplateType(tmplat, getSendType());
|
|
||||||
|
|
||||||
Boolean isResve = bulk.getResve();
|
|
||||||
LocalDateTime sendDt = bulk.getSendDt() != null ? bulk.getSendDt() : now;
|
|
||||||
|
|
||||||
String sendTel = firstNonBlank(req.getSendTel(), tmplat.getSendTel());
|
|
||||||
String sendEml = firstNonBlank(req.getSendEml(), tmplat.getSendEml());
|
|
||||||
String sendFrom = getSendType() == SendType.EMAIL ? sendEml : sendTel;
|
|
||||||
String sendNm = firstNonBlank(req.getSendNm(), tmplat.getSendNm());
|
|
||||||
|
|
||||||
if (sendFrom == null || sendFrom.isBlank()) {
|
|
||||||
if (getSendType() == SendType.EMAIL) {
|
|
||||||
throw BusinessException.badRequest("SENDER_EMAIL_REQUIRED", "sendEml은 필수 입니다.");
|
|
||||||
} else {
|
|
||||||
throw BusinessException.badRequest("SENDER_TEL_REQUIRED", "sendTel은 필수 입니다.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
req.setSendEml(sendEml);
|
|
||||||
req.setSendTel(sendTel);
|
|
||||||
req.setSendNm(sendNm);
|
|
||||||
|
|
||||||
int requestCnt = req.getDestInfoList().size();
|
|
||||||
int acceptCnt = 0;
|
|
||||||
int failCnt = 0;
|
|
||||||
|
|
||||||
List<TSendEntity> buffer = new ArrayList<>(Math.min(requestCnt, NotihubConst.INSERT_CHUNK_SIZE));
|
|
||||||
|
|
||||||
for (int offset = 0; offset < requestCnt; offset += NotihubConst.CHUNK_SIZE) {
|
|
||||||
int end = Math.min(offset + NotihubConst.CHUNK_SIZE, requestCnt);
|
|
||||||
List<DestInfoDto> chunk = req.getDestInfoList().subList(offset, end);
|
|
||||||
|
|
||||||
for (DestInfoDto dest : chunk) {
|
|
||||||
String sendTo = getSendType() == SendType.EMAIL ? dest.getDestEml() : dest.getDestTel();
|
|
||||||
if (dest == null || sendTo.isBlank()) {
|
|
||||||
failCnt++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String msgTitle = replacePlaceholder(tmplat.getTmplatTitle(), dest.getMsgParam());
|
|
||||||
String msgBody = replacePlaceholder(tmplat.getTmplatBody(), dest.getMsgParam());
|
|
||||||
|
|
||||||
SendInternalResultDto sendResult = doSendInternal(
|
|
||||||
isResve,
|
|
||||||
bulkSendKey,
|
|
||||||
tmplat.getTmplatTy(),
|
|
||||||
sendFrom,
|
|
||||||
sendNm,
|
|
||||||
msgTitle,
|
|
||||||
msgBody,
|
|
||||||
dest
|
|
||||||
);
|
|
||||||
|
|
||||||
if (sendResult.getStatus() == SendStatusType.SUCCESS) {
|
|
||||||
acceptCnt++;
|
|
||||||
} else if(sendResult.getStatus() == SendStatusType.FAIL) {
|
|
||||||
failCnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.add(
|
|
||||||
TSendEntity.from(
|
|
||||||
req,
|
|
||||||
dest,
|
|
||||||
tmplat.getTmplatTy(),
|
|
||||||
sendResult,
|
|
||||||
tmplat.getItrntPrjctCd(),
|
|
||||||
bulk.getReqstSvc(),
|
|
||||||
bulk.getPrjctCd(),
|
|
||||||
bulk.getTmplatIdx(),
|
|
||||||
msgTitle,
|
|
||||||
msgBody,
|
|
||||||
bulk.getRegCmpn(),
|
|
||||||
bulk.getRegUser(),
|
|
||||||
isResve,
|
|
||||||
sendDt,
|
|
||||||
bulkSendKey,
|
|
||||||
now
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if(getSendType() == SendType.EMAIL) {
|
|
||||||
// 발송 간 딜레이(Pringo rate-limit 대응)
|
|
||||||
long delay = Math.max(tmplat.getDelayTime(), NotihubConst.EMAIL_DELAY);
|
|
||||||
sleepSilently(delay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!buffer.isEmpty()) {
|
|
||||||
saveSendEntitiesChunked(buffer);
|
|
||||||
buffer.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// bulk 집계 업데이트(요청/성공/실패 카운트)
|
|
||||||
bulk.setSendCnt(Optional.ofNullable(bulk.getSendCnt()).orElse(0) + requestCnt);
|
|
||||||
bulk.setSuccesCnt(Optional.ofNullable(bulk.getSuccesCnt()).orElse(0) + acceptCnt);
|
|
||||||
bulk.setFailCnt(Optional.ofNullable(bulk.getFailCnt()).orElse(0) + failCnt);
|
|
||||||
bulkSendRepository.save(bulk);
|
|
||||||
|
|
||||||
return BulkSendResponseDto.of(bulkSendKey, requestCnt, acceptCnt, failCnt);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String replacePlaceholder(String text, Map<String, String> msgParam){
|
|
||||||
if (text == null || text.isEmpty() || msgParam == null || msgParam.isEmpty()) {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("\\[\\$([^\\]]+)]");
|
|
||||||
Matcher matcher = pattern.matcher(text);
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
while (matcher.find()) {
|
|
||||||
String varName = matcher.group(1);
|
|
||||||
String value = msgParam.get(varName);
|
|
||||||
|
|
||||||
if (value == null) {
|
|
||||||
// 값이 없으면 원문 유지
|
|
||||||
matcher.appendReplacement(sb, Matcher.quoteReplacement(matcher.group(0)));
|
|
||||||
} else {
|
|
||||||
// 값 치환 (정규식 replacement 안전 처리)
|
|
||||||
matcher.appendReplacement(sb, Matcher.quoteReplacement(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
matcher.appendTail(sb);
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 자식 클래스가 구현: 실제 발송 수행 */
|
|
||||||
protected abstract SendInternalResultDto doSendInternal(
|
|
||||||
Boolean isResve,
|
|
||||||
String bulkSendKey,
|
|
||||||
SendType sendType,
|
|
||||||
String sendFrom,
|
|
||||||
String sendNm,
|
|
||||||
String msgTitle,
|
|
||||||
String msgBody,
|
|
||||||
DestInfoDto dest
|
|
||||||
);
|
|
||||||
|
|
||||||
public abstract void afterPersistSendEntities(List<TSendEntity> persisted);
|
|
||||||
|
|
||||||
protected void saveSendEntitiesChunked(List<TSendEntity> entityList) {
|
|
||||||
if (entityList == null || entityList.isEmpty()) return;
|
|
||||||
|
|
||||||
int size = entityList.size();
|
|
||||||
for (int i = 0; i < size; i += NotihubConst.INSERT_CHUNK_SIZE) {
|
|
||||||
int end = Math.min(size, i + NotihubConst.INSERT_CHUNK_SIZE);
|
|
||||||
List<TSendEntity> sub = entityList.subList(i, end);
|
|
||||||
sendRepository.saveAll(sub);
|
|
||||||
sendRepository.flush();
|
|
||||||
|
|
||||||
afterPersistSendEntities(sub);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void sleepSilently(long ms) {
|
|
||||||
if (ms <= 0) return;
|
|
||||||
try {
|
|
||||||
Thread.sleep(ms);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract SendType getSendType();
|
|
||||||
}
|
|
||||||
@@ -1,86 +1,57 @@
|
|||||||
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.jdbc.BizMsgBulkJdbcWriter;
|
||||||
|
import com.kri.notihub.server.persistence.jdbc.SendBulkJdbcWriter;
|
||||||
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.List;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SendSmsService extends SendService {
|
public class SendSmsService extends AbstractBizppurioSendService {
|
||||||
|
|
||||||
private final BizMsgRepository bizMsgRepository;
|
|
||||||
|
|
||||||
public SendSmsService(
|
public SendSmsService(
|
||||||
BizMsgRepository bizMsgRepository,
|
SendBulkJdbcWriter sendBulkJdbcWriter,
|
||||||
|
BizMsgBulkJdbcWriter bizMsgBulkJdbcWriter,
|
||||||
TemplateRepository templateRepository,
|
TemplateRepository templateRepository,
|
||||||
BulkSendRepository bulkSendRepository,
|
BulkSendRepository bulkSendRepository,
|
||||||
|
BizMsgRepository bizMsgRepository,
|
||||||
SendRepository sendRepository,
|
SendRepository sendRepository,
|
||||||
TemplateService templateService
|
TemplateService templateService
|
||||||
) {
|
) {
|
||||||
super(templateRepository, bulkSendRepository, sendRepository, templateService);
|
super(sendBulkJdbcWriter, bizMsgBulkJdbcWriter,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;
|
return NotihubConst.SMS_TYPE_CODE_LIST;
|
||||||
|
|
||||||
List<BizMsgEntity> msgList = new ArrayList<>(persisted.size());
|
|
||||||
|
|
||||||
for (TSendEntity s : persisted) {
|
|
||||||
if (s == null) continue;
|
|
||||||
|
|
||||||
if (NotihubConst.MOBILE_TYPE_LIST.contains(s.getSendTy())) continue;
|
|
||||||
|
|
||||||
BizMsgEntity m = BizMsgEntity.fromSend(s);
|
|
||||||
msgList.add(m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msgList.isEmpty()) {
|
@Override
|
||||||
bizMsgRepository.saveAll(msgList);
|
protected int msgType(TSendEntity sendEntity) {
|
||||||
bizMsgRepository.flush();
|
return sendEntity.getSendTy().equals(SendType.SMS.getCode()) ? 0 : 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String subject(TSendEntity sendEntity) {
|
||||||
|
return sendEntity.getSendTy().equals(SendType.SMS.getCode()) ? null : sendEntity.getMsgTitle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package com.kri.notihub.server.service;
|
|
||||||
|
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
|
||||||
import com.kri.notihub.server.persistence.repository.SendRepository;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class SmsSendCursorStore {
|
|
||||||
|
|
||||||
private final SendRepository sendRepository;
|
|
||||||
|
|
||||||
// 프로세스 전역 커서(스레드 세이프)
|
|
||||||
private static final java.util.concurrent.atomic.AtomicLong CURSOR = new java.util.concurrent.atomic.AtomicLong(0L);
|
|
||||||
|
|
||||||
// 서비스 기동 시: t_send에서 sendTy=SMS의 max(send_idx)로 초기화
|
|
||||||
@PostConstruct
|
|
||||||
public void init() {
|
|
||||||
long maxSendIdx = sendRepository.findMinSendIdxBySendTy(SendType.SMS.getCode());
|
|
||||||
CURSOR.set(maxSendIdx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long get() {
|
|
||||||
return CURSOR.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(long sendIdx) {
|
|
||||||
CURSOR.set(sendIdx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.kri.notihub.server.service;
|
package com.kri.notihub.server.service;
|
||||||
|
|
||||||
import com.kri.common.datetime.DateTimeUtil;
|
import com.kri.common.feature.datetime.DateTimeUtil;
|
||||||
import com.kri.common.web.BusinessException;
|
import com.kri.common.feature.util.StringUtil;
|
||||||
|
import com.kri.common.feature.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;
|
||||||
import com.kri.notihub.server.common.enums.SendType;
|
import com.kri.notihub.server.common.enums.SendType;
|
||||||
@@ -14,13 +15,15 @@ import com.kri.notihub.server.persistence.entity.TTmplatEntity;
|
|||||||
import com.kri.notihub.server.persistence.entity.TTmplatEventLogEntity;
|
import com.kri.notihub.server.persistence.entity.TTmplatEventLogEntity;
|
||||||
import com.kri.notihub.server.persistence.repository.TemplateEventLogRepository;
|
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.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;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
@Log4j2
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TemplateService {
|
public class TemplateService {
|
||||||
@@ -29,7 +32,11 @@ public class TemplateService {
|
|||||||
private final TemplateEventLogRepository templateEventLogRepository;
|
private final TemplateEventLogRepository templateEventLogRepository;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public TemplateDto createTemplate(String itrntPrjctCd, TemplateBasicDto template, String regUser) {
|
public TemplateDto createTemplate(
|
||||||
|
String itrntPrjctCd,
|
||||||
|
TemplateBasicDto template,
|
||||||
|
String regUser
|
||||||
|
) {
|
||||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
validateBySendType(template);
|
validateBySendType(template);
|
||||||
@@ -47,11 +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, itrntPrjctCd).stream()
|
return templateRepository.findAllByTmplatTyInAndItrntPrjctCdAndDelFalse(
|
||||||
|
tmplatTyList,
|
||||||
|
itrntPrjctCd
|
||||||
|
)
|
||||||
|
.stream()
|
||||||
.map(TemplateSummaryDto::from)
|
.map(TemplateSummaryDto::from)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
@@ -67,7 +76,8 @@ public class TemplateService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void updateTemplateBodyWithCreate(TemplateDto template) {
|
public void updateTemplateBodyWithCreate(TemplateDto template) {
|
||||||
TTmplatEntity entity = templateRepository.findByTmplatIdxAndDelFalse(template.getTmplatIdx()).orElseThrow(() ->
|
TTmplatEntity entity = templateRepository.findByTmplatIdxAndDelFalse(template.getTmplatIdx())
|
||||||
|
.orElseThrow(() ->
|
||||||
BusinessException.notFound("TEMPLATE_NOT_FOUND", "템플릿을 찾을 수 없습니다.")
|
BusinessException.notFound("TEMPLATE_NOT_FOUND", "템플릿을 찾을 수 없습니다.")
|
||||||
.with("tmplatIdx", template.getTmplatIdx())
|
.with("tmplatIdx", template.getTmplatIdx())
|
||||||
);
|
);
|
||||||
@@ -81,7 +91,8 @@ public class TemplateService {
|
|||||||
long tmplatIdx = template.getTmplatIdx();
|
long tmplatIdx = template.getTmplatIdx();
|
||||||
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
final LocalDateTime now = DateTimeUtil.nowKstLocalDateTime();
|
||||||
|
|
||||||
TTmplatEntity entity = templateRepository.findByTmplatIdxAndDelFalse(tmplatIdx).orElseThrow(() ->
|
TTmplatEntity entity = templateRepository.findByTmplatIdxAndDelFalse(tmplatIdx)
|
||||||
|
.orElseThrow(() ->
|
||||||
BusinessException.notFound("TEMPLATE_NOT_FOUND", "템플릿을 찾을 수 없습니다.")
|
BusinessException.notFound("TEMPLATE_NOT_FOUND", "템플릿을 찾을 수 없습니다.")
|
||||||
.with("tmplatIdx", tmplatIdx)
|
.with("tmplatIdx", tmplatIdx)
|
||||||
);
|
);
|
||||||
@@ -130,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", "발신자 명은 필수입니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,28 +177,40 @@ 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.SMS_TYPE_CODE_LIST.contains(ty) || NotihubConst.KKO_TYPE_CODE_LIST.contains(ty)) {
|
||||||
else if (NotihubConst.MOBILE_TYPE_LIST.contains(ty)) {
|
if (StringUtil.isNullOrBlank(template.getSendTel())) {
|
||||||
if (template.getSendTel() == null || template.getSendTel().isBlank()) {
|
|
||||||
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);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// 혹시 enum 확장 대비
|
// 혹시 enum 확장 대비
|
||||||
throw BusinessException.badRequest("INVALID_TYPE", "지원하지 않는 템플릿 타입입니다.")
|
throw BusinessException.badRequest("INVALID_TYPE", "지원하지 않는 템플릿 타입입니다.")
|
||||||
.with("tmplatTy", ty);
|
.with("tmplatTy", ty);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ kri:
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
#private 도메인
|
#private 도메인
|
||||||
url: jdbc:mysql://db-md87m.vpc-cdb.ntruss.com:3306/notice_hub?characterEncoding=UTF-8
|
url: jdbc:mysql://db-md87m.vpc-cdb.ntruss.com:3306/kri_notice_hub?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||||
username: kri_notihub
|
username: kri_notihub
|
||||||
password: notihub#51304
|
password: notihub#51304
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
@@ -8,7 +8,7 @@ kri:
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
#private 도메인
|
#private 도메인
|
||||||
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/notice_hub?characterEncoding=UTF-8
|
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/kri_notice_hub?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||||
username: kri_notihub
|
username: kri_notihub
|
||||||
password: notihub#51304
|
password: notihub#51304
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
@@ -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
|
||||||
@@ -5,7 +5,7 @@ kri:
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
#private 도메인
|
#private 도메인
|
||||||
url: jdbc:mysql://db-md87m.vpc-cdb.ntruss.com:3306/notice_hub?characterEncoding=UTF-8
|
url: jdbc:mysql://db-md87m.vpc-cdb.ntruss.com:3306/kri_notice_hub?characterEncoding=UTF-8&rewriteBatchedStatements=true
|
||||||
username: kri_notihub
|
username: kri_notihub
|
||||||
password: notihub#51304
|
password: notihub#51304
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
@@ -1,11 +1,18 @@
|
|||||||
server:
|
server:
|
||||||
port: 4011
|
port: 4011
|
||||||
|
forward-headers-strategy: framework
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: notihub-server
|
name: notihub-server
|
||||||
|
|
||||||
jpa:
|
jpa:
|
||||||
|
properties:
|
||||||
|
hibernate:
|
||||||
|
jdbc:
|
||||||
|
batch_size: 1_000
|
||||||
|
order_inserts: true
|
||||||
|
order_updates: true
|
||||||
hibernate:
|
hibernate:
|
||||||
naming:
|
naming:
|
||||||
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||||
@@ -43,13 +50,14 @@ kri:
|
|||||||
key: "4B726963-4E6F7469487562-53657276696365-402531403136"
|
key: "4B726963-4E6F7469487562-53657276696365-402531403136"
|
||||||
header-name: "X-API-Key" # API Key 헤더
|
header-name: "X-API-Key" # API Key 헤더
|
||||||
enabled: true # API Key 인증 허용 여부
|
enabled: true # API Key 인증 허용 여부
|
||||||
service-code: intranet-extension
|
service-code: notihub-service
|
||||||
preload-on-startup: true
|
preload-on-startup: true
|
||||||
# 내부 운영용(원하면)
|
# 내부 운영용(원하면)
|
||||||
admin-api-enabled: true
|
admin-api-enabled: true
|
||||||
admin-allow-ips:
|
admin-allow-ips:
|
||||||
- 127.0.0.1/32
|
- 127.0.0.1/32
|
||||||
- 0:0:0:0:0:0:0:1
|
- 0:0:0:0:0:0:0:1
|
||||||
|
- 211.254.145.130
|
||||||
# apikey 보관 DB(MySQL)
|
# apikey 보관 DB(MySQL)
|
||||||
db:
|
db:
|
||||||
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/kri_common?characterEncoding=UTF-8
|
url: jdbc:mysql://db-md87m-kr.vpc-pub-cdb.ntruss.com:3306/kri_common?characterEncoding=UTF-8
|
||||||
@@ -65,6 +73,7 @@ kri:
|
|||||||
- /swagger-ui/**
|
- /swagger-ui/**
|
||||||
- /ping
|
- /ping
|
||||||
- /body-image/**
|
- /body-image/**
|
||||||
|
- /internal/apikey/**
|
||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
enabled: true
|
enabled: true
|
||||||
@@ -78,7 +87,6 @@ kri:
|
|||||||
temp-expire-hours: 24
|
temp-expire-hours: 24
|
||||||
temp-cleanup-cron: "0 0 0 * * *" # 매일 00:00(초 분 시 일 월 요일)
|
temp-cleanup-cron: "0 0 0 * * *" # 매일 00:00(초 분 시 일 월 요일)
|
||||||
|
|
||||||
common:
|
|
||||||
web:
|
web:
|
||||||
enabled: true # 공통 Web 구성 사용 여부 (기본 true)
|
enabled: true # 공통 Web 구성 사용 여부 (기본 true)
|
||||||
webmvc:
|
webmvc:
|
||||||
|
|||||||
Reference in New Issue
Block a user