261008_01_ENH: KKO 템플릿 리스트 조회, 템플릿 상세 조회, notihub에 KKO 템플릿 등록, KKO 발송 추가
This commit is contained in:
106
src/main/java/com/kri/notihub/server/common/external/kakao/KkoTemplateApiClient.java
vendored
Normal file
106
src/main/java/com/kri/notihub/server/common/external/kakao/KkoTemplateApiClient.java
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
package com.kri.notihub.server.common.external.kakao;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.http.ExternalApiClient;
|
||||
import com.kri.common.feature.http.ExternalApiResponse;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.notihub.server.config.KkoTemplateProperties;
|
||||
import java.net.http.HttpTimeoutException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class KkoTemplateApiClient {
|
||||
|
||||
private final KkoTemplateProperties properties;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final ExternalApiClient externalApiClient;
|
||||
|
||||
@Autowired
|
||||
public KkoTemplateApiClient(KkoTemplateProperties properties, ObjectMapper objectMapper) {
|
||||
this(properties, objectMapper, new ExternalApiClient());
|
||||
}
|
||||
|
||||
KkoTemplateApiClient(KkoTemplateProperties properties, ObjectMapper objectMapper,
|
||||
ExternalApiClient externalApiClient) {
|
||||
this.properties = properties;
|
||||
this.objectMapper = objectMapper;
|
||||
this.externalApiClient = externalApiClient;
|
||||
}
|
||||
|
||||
public JsonNode list(String keyword) {
|
||||
Map<String, Object> request = credentials();
|
||||
request.put("templateStatus", "ACT");
|
||||
if (keyword == null || keyword.isBlank()) {
|
||||
request.put("page", 1);
|
||||
request.put("count", 10);
|
||||
} else {
|
||||
request.put("keyword", keyword.trim());
|
||||
}
|
||||
return post("/template/list", request);
|
||||
}
|
||||
|
||||
public JsonNode detail(String templateCode) {
|
||||
Map<String, Object> request = credentials();
|
||||
request.put("templateCode", templateCode);
|
||||
return post("/template/detail", request);
|
||||
}
|
||||
|
||||
private Map<String, Object> credentials() {
|
||||
Map<String, Object> request = new LinkedHashMap<>();
|
||||
request.put("bizId", properties.getBizId());
|
||||
request.put("apiKey", properties.getApiKey());
|
||||
request.put("senderKey", properties.getSenderKey());
|
||||
return request;
|
||||
}
|
||||
|
||||
private JsonNode post(String path, Map<String, Object> request) {
|
||||
try {
|
||||
String baseUrl = properties.getBaseUrl().replaceAll("/+$", "");
|
||||
ExternalApiResponse response = externalApiClient.post(baseUrl + path,
|
||||
Map.of("Content-Type", "application/json; charset=utf-8", "Accept", "application/json"),
|
||||
objectMapper.writeValueAsString(request));
|
||||
if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
|
||||
throw providerError();
|
||||
}
|
||||
JsonNode root = objectMapper.readTree(response.getBody());
|
||||
if (root == null || !root.isObject() || !root.path("code").isTextual()) {
|
||||
throw invalidResponse();
|
||||
}
|
||||
if (!"200".equals(root.path("code").asText())) {
|
||||
throw providerError();
|
||||
}
|
||||
if (!root.path("data").isObject()) {
|
||||
throw invalidResponse();
|
||||
}
|
||||
return root;
|
||||
} catch (BusinessException e) {
|
||||
throw e;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw invalidResponse();
|
||||
} catch (RuntimeException e) {
|
||||
for (Throwable cause = e; cause != null; cause = cause.getCause()) {
|
||||
if (cause instanceof HttpTimeoutException) {
|
||||
throw BusinessException.of(HttpStatus.GATEWAY_TIMEOUT, "KKO_TEMPLATE_TIMEOUT",
|
||||
"알림톡 템플릿 조회 시간이 초과되었습니다.");
|
||||
}
|
||||
}
|
||||
throw providerError();
|
||||
}
|
||||
}
|
||||
|
||||
public static BusinessException invalidResponse() {
|
||||
return BusinessException.of(HttpStatus.BAD_GATEWAY, "KKO_TEMPLATE_INVALID_RESPONSE",
|
||||
"알림톡 템플릿 조회 응답이 올바르지 않습니다.");
|
||||
}
|
||||
|
||||
private static BusinessException providerError() {
|
||||
return BusinessException.of(HttpStatus.BAD_GATEWAY, "KKO_TEMPLATE_PROVIDER_ERROR",
|
||||
"알림톡 템플릿을 조회하지 못했습니다.");
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,10 @@ public final class TemplateContentSanitizer {
|
||||
|
||||
outBody = sanitizeEmailHtml(outBody);
|
||||
}
|
||||
case SMS, LMS_MMS, KKO_AT -> {
|
||||
case KKO_AT -> {
|
||||
// 카카오 등록 원문과 일치하도록 미리보기 제목과 본문을 변형하지 않는다.
|
||||
}
|
||||
case SMS, LMS_MMS -> {
|
||||
// 평문화
|
||||
outTitle = htmlToPlainTextPreserveNewlines(outTitle);
|
||||
outTitle = truncateTo128CodePoints(outTitle);
|
||||
@@ -203,9 +206,7 @@ public final class TemplateContentSanitizer {
|
||||
}
|
||||
}
|
||||
|
||||
if (type == SendType.KKO_AT) {
|
||||
outTitle = null;
|
||||
} else if (SMS_TYPE_CODE_LIST.contains(type)) {
|
||||
if (SMS_TYPE_CODE_LIST.contains(type)) {
|
||||
type = determineSms(outTitle, outBody);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.kri.notihub.server.config;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Validated
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "notihub.kakao")
|
||||
public class KkoTemplateProperties {
|
||||
|
||||
@NotBlank
|
||||
private String baseUrl;
|
||||
@NotBlank
|
||||
private String bizId;
|
||||
@NotBlank
|
||||
private String apiKey;
|
||||
@NotBlank
|
||||
private String senderKey;
|
||||
}
|
||||
@@ -3,11 +3,16 @@ package com.kri.notihub.server.controller;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.dto.email.EmailAttachmentDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateDetailDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateDetailRequestDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateListRequestDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateListResponseDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateSummaryDto;
|
||||
import com.kri.notihub.server.service.FileService;
|
||||
import com.kri.notihub.server.service.TemplateService;
|
||||
import com.kri.notihub.server.service.KkoTemplateService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -23,6 +28,8 @@ 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.PostMapping;
|
||||
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.RequestPart;
|
||||
@@ -37,6 +44,24 @@ public class TemplateController {
|
||||
|
||||
private final TemplateService templateService;
|
||||
private final FileService fileService;
|
||||
private final KkoTemplateService kkoTemplateService;
|
||||
|
||||
@Operation(summary = "외부 알림톡 템플릿 목록 조회")
|
||||
@PostMapping(value = "/kko/list", consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public KkoTemplateListResponseDto getKkoTemplateList(
|
||||
@Valid @RequestBody KkoTemplateListRequestDto request) {
|
||||
return kkoTemplateService.getList(request.getKeyword());
|
||||
}
|
||||
|
||||
@Operation(summary = "외부 알림톡 템플릿 상세 조회")
|
||||
@PostMapping(value = "/kko/detail", consumes = MediaType.APPLICATION_JSON_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public KkoTemplateDetailDto getKkoTemplateDetail(
|
||||
@Valid @RequestBody KkoTemplateDetailRequestDto request) {
|
||||
return kkoTemplateService.getDetail(request.getTemplateCode());
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "템플릿 목록 조회")
|
||||
@GetMapping("/list/{chnnlTy}/{itrntPrjctCd}")
|
||||
|
||||
@@ -18,10 +18,10 @@ public class BulkSendResponseDto {
|
||||
@Schema(description = "요청 건수")
|
||||
private Integer requestCount;
|
||||
|
||||
@Schema(description = "Pringo send 요청 성공(return_key 수신) 건수")
|
||||
@Schema(description = "발송 접수 건수(대기 또는 즉시 성공)")
|
||||
private Integer acceptCount;
|
||||
|
||||
@Schema(description = "Pringo send 요청 실패(return_key 미수신) 건수")
|
||||
@Schema(description = "발송 접수 실패 건수")
|
||||
private Integer failCount;
|
||||
|
||||
public static BulkSendResponseDto of(String bulkSendKey, Integer requestCount,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.kri.notihub.server.dto.template;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class KkoTemplateDetailDto {
|
||||
|
||||
private String templateCode;
|
||||
private String templateName;
|
||||
private String templateContent;
|
||||
private String templatePreviewMessage;
|
||||
private String templateMessageType;
|
||||
private String templateEmphasizeType;
|
||||
private String inspectionStatus;
|
||||
private String status;
|
||||
private Boolean block;
|
||||
private Boolean dormant;
|
||||
private String templateExtra;
|
||||
private String templateImageName;
|
||||
private String templateImageUrl;
|
||||
private String templateTitle;
|
||||
private String templateSubtitle;
|
||||
private String templateHeader;
|
||||
private JsonNode templateItemHighlight;
|
||||
private JsonNode templateItem;
|
||||
private JsonNode templateRepresentLink;
|
||||
private List<JsonNode> buttons;
|
||||
private List<JsonNode> quickReplies;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.notihub.server.dto.template;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class KkoTemplateDetailRequestDto {
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 30)
|
||||
@Pattern(regexp = "[A-Za-z0-9_-]+")
|
||||
private String templateCode;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.notihub.server.dto.template;
|
||||
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class KkoTemplateListRequestDto {
|
||||
|
||||
@Size(min = 2, max = 50)
|
||||
private String keyword;
|
||||
|
||||
public KkoTemplateListRequestDto(String keyword) {
|
||||
setKeyword(keyword);
|
||||
}
|
||||
|
||||
public void setKeyword(String keyword) {
|
||||
this.keyword = keyword == null || keyword.isBlank() ? null : keyword.trim();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.kri.notihub.server.dto.template;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class KkoTemplateListResponseDto {
|
||||
|
||||
private int totalCount;
|
||||
private int totalPage;
|
||||
private int currentPage;
|
||||
private List<KkoTemplateSummaryDto> list;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.notihub.server.dto.template;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class KkoTemplateSummaryDto {
|
||||
|
||||
private String templateCode;
|
||||
private String templateName;
|
||||
private String serviceStatus;
|
||||
private String createdAt;
|
||||
private String modifiedAt;
|
||||
}
|
||||
@@ -43,8 +43,7 @@ public class TemplateBasicDto {
|
||||
@Schema(description = "발송시 제목")
|
||||
private String tmplatTitle;
|
||||
|
||||
@NotBlank
|
||||
@Schema(description = "발송 내용")
|
||||
@Schema(description = "발송 내용 (알림톡은 외부 상세 조회 결과로 저장)")
|
||||
private String tmplatBody;
|
||||
|
||||
@Schema(description = "비즈뿌리오 알림톡 프로필의 sender key")
|
||||
|
||||
@@ -4,7 +4,6 @@ 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.enums.SendStatusType;
|
||||
import com.kri.notihub.server.common.enums.SendType;
|
||||
import com.kri.notihub.server.persistence.entity.BizLogEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TBulkSendEntity;
|
||||
import com.kri.notihub.server.persistence.entity.TSendEntity;
|
||||
@@ -22,6 +21,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -45,7 +45,9 @@ public class BizLogResultScheduler {
|
||||
@Transactional(transactionManager = "transactionManager")
|
||||
public void syncSmsResults() {
|
||||
|
||||
List<Short> sendTyList = List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode(), SendType.KKO_AT.getCode());
|
||||
List<Short> sendTyList = Stream.concat(
|
||||
NotihubConst.SMS_TYPE_CODE_LIST.stream(),
|
||||
NotihubConst.KKO_TYPE_CODE_LIST.stream()).toList();
|
||||
List<Short> resultCodes = List.of(
|
||||
NotihubConst.SMS_STANDBY,
|
||||
NotihubConst.LMS_MMS_STANDBY,
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.common.feature.util.StringUtil;
|
||||
import com.kri.notihub.server.common.consts.NotihubConst;
|
||||
import com.kri.notihub.server.common.enums.ChannelType;
|
||||
import com.kri.notihub.server.common.enums.SendStatusType;
|
||||
@@ -24,6 +25,7 @@ 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 com.kri.notihub.server.service.PhoneVerificationService.PhoneVerificationIssue;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -266,6 +268,7 @@ public abstract class AbstractSendService {
|
||||
|
||||
int requestCnt = req.getDestInfoList().size();
|
||||
int acceptCnt = 0;
|
||||
int successCnt = 0;
|
||||
int failCnt = 0;
|
||||
|
||||
List<TSendEntity> buffer = new ArrayList<>(
|
||||
@@ -276,8 +279,13 @@ public abstract class AbstractSendService {
|
||||
List<DestInfoDto> chunk = req.getDestInfoList().subList(offset, end);
|
||||
|
||||
for (DestInfoDto dest : chunk) {
|
||||
if (dest == null) {
|
||||
failCnt++;
|
||||
continue;
|
||||
}
|
||||
|
||||
String sendTo = isEmailChannel() ? dest.getDestEml() : dest.getDestTel();
|
||||
if (dest == null || sendTo.isBlank()) {
|
||||
if (StringUtil.isNullOrBlank(sendTo)) {
|
||||
failCnt++;
|
||||
continue;
|
||||
}
|
||||
@@ -298,8 +306,11 @@ public abstract class AbstractSendService {
|
||||
dest
|
||||
);
|
||||
|
||||
if (sendResult.getStatus() == SendStatusType.SUCCESS) {
|
||||
if (sendResult.getStatus() == SendStatusType.STANDBY) {
|
||||
acceptCnt++;
|
||||
} else if (sendResult.getStatus() == SendStatusType.SUCCESS) {
|
||||
acceptCnt++;
|
||||
successCnt++;
|
||||
} else if (sendResult.getStatus() == SendStatusType.FAIL) {
|
||||
failCnt++;
|
||||
}
|
||||
@@ -333,7 +344,7 @@ public abstract class AbstractSendService {
|
||||
|
||||
// bulk 집계 업데이트(요청/성공/실패 카운트)
|
||||
bulk.setSendCnt(Optional.ofNullable(bulk.getSendCnt()).orElse(0) + requestCnt);
|
||||
bulk.setSuccesCnt(Optional.ofNullable(bulk.getSuccesCnt()).orElse(0) + acceptCnt);
|
||||
bulk.setSuccesCnt(Optional.ofNullable(bulk.getSuccesCnt()).orElse(0) + successCnt);
|
||||
bulk.setFailCnt(Optional.ofNullable(bulk.getFailCnt()).orElse(0) + failCnt);
|
||||
bulkSendRepository.save(bulk);
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.notihub.server.common.external.kakao.KkoTemplateApiClient;
|
||||
import com.kri.notihub.server.config.KkoTemplateProperties;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateDetailDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateListResponseDto;
|
||||
import com.kri.notihub.server.dto.template.KkoTemplateSummaryDto;
|
||||
import com.kri.notihub.server.dto.template.TemplateBasicDto;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class KkoTemplateService {
|
||||
|
||||
private final KkoTemplateApiClient apiClient;
|
||||
private final KkoTemplateProperties properties;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public KkoTemplateListResponseDto getList(String keyword) {
|
||||
String normalized = keyword == null || keyword.isBlank() ? null : keyword.trim();
|
||||
if (normalized != null && (normalized.length() < 2 || normalized.length() > 50)) {
|
||||
throw BusinessException.badRequest("KKO_TEMPLATE_INVALID_KEYWORD",
|
||||
"검색어는 2자 이상 50자 이하여야 합니다.");
|
||||
}
|
||||
JsonNode root = apiClient.list(normalized);
|
||||
JsonNode items = root.path("data").path("list");
|
||||
if (!items.isArray()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
List<KkoTemplateSummaryDto> list = new ArrayList<>();
|
||||
for (JsonNode item : items) {
|
||||
if (!item.isObject() || !item.path("templateCode").isTextual()
|
||||
|| !item.path("templateName").isTextual()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
list.add(read(item, KkoTemplateSummaryDto.class));
|
||||
}
|
||||
return new KkoTemplateListResponseDto(nonNegativeInt(root, "totalCount"),
|
||||
nonNegativeInt(root, "totalPage"), nonNegativeInt(root, "currentPage"), list);
|
||||
}
|
||||
|
||||
public KkoTemplateDetailDto getDetail(String templateCode) {
|
||||
validateCode(templateCode);
|
||||
JsonNode data = apiClient.detail(templateCode).path("data");
|
||||
if (!templateCode.equals(data.path("templateCode").asText())
|
||||
|| !properties.getSenderKey().equals(data.path("senderKey").asText())
|
||||
|| !data.path("templateContent").isTextual()
|
||||
|| data.path("templateContent").asText().isBlank()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
JsonNode preview = data.path("templatePreviewMessage");
|
||||
if (!preview.isMissingNode() && !preview.isNull() && !preview.isTextual()) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
return read(data, KkoTemplateDetailDto.class);
|
||||
}
|
||||
|
||||
public void synchronize(TemplateBasicDto template) {
|
||||
KkoTemplateDetailDto detail = getDetail(template.getKkoTmplatCd());
|
||||
validateAvailable(detail);
|
||||
validateBasicTextFormat(detail);
|
||||
if (detail.getTemplatePreviewMessage() != null
|
||||
&& detail.getTemplatePreviewMessage().length() > 128) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
template.setTmplatBody(detail.getTemplateContent());
|
||||
template.setTmplatTitle(detail.getTemplatePreviewMessage());
|
||||
template.setSenderKey(properties.getSenderKey());
|
||||
}
|
||||
|
||||
private void validateAvailable(KkoTemplateDetailDto detail) {
|
||||
if (!"APR".equals(detail.getInspectionStatus()) || !"A".equals(detail.getStatus())
|
||||
|| !Boolean.FALSE.equals(detail.getBlock()) || !Boolean.FALSE.equals(detail.getDormant())) {
|
||||
throw BusinessException.badRequest("KKO_TEMPLATE_UNAVAILABLE",
|
||||
"승인된 정상 상태이며 차단·휴면 상태가 아닌 알림톡 템플릿만 저장할 수 있습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateBasicTextFormat(KkoTemplateDetailDto detail) {
|
||||
// 현재 발송 경로는 기본 텍스트형만 지원한다. 버튼·이미지 등 발송 지원이 추가되면
|
||||
// 이 저장 제한을 완화하거나 제거하고, 추가 요소의 저장·발송·변수 처리도 함께 검증해야 한다.
|
||||
if (!"BA".equals(detail.getTemplateMessageType())
|
||||
|| !"NONE".equals(detail.getTemplateEmphasizeType())
|
||||
|| hasText(detail.getTemplateExtra()) || hasText(detail.getTemplateImageName())
|
||||
|| hasText(detail.getTemplateImageUrl()) || hasText(detail.getTemplateTitle())
|
||||
|| hasText(detail.getTemplateSubtitle()) || hasText(detail.getTemplateHeader())
|
||||
|| hasValue(detail.getTemplateItemHighlight()) || hasValue(detail.getTemplateItem())
|
||||
|| hasValue(detail.getTemplateRepresentLink())
|
||||
|| (detail.getButtons() != null && !detail.getButtons().isEmpty())
|
||||
|| (detail.getQuickReplies() != null && !detail.getQuickReplies().isEmpty())) {
|
||||
throw BusinessException.badRequest("KKO_TEMPLATE_UNSUPPORTED_FORMAT",
|
||||
"추가 요소가 없는 기본 텍스트형 알림톡 템플릿만 저장할 수 있습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void validateCode(String templateCode) {
|
||||
if (templateCode == null || !templateCode.matches("[A-Za-z0-9_-]{1,30}")) {
|
||||
throw BusinessException.badRequest("EMPTY_KKO_TMPLAT_CD",
|
||||
"알림톡 템플릿 코드는 영문·숫자·밑줄·하이픈으로 구성된 1~30자여야 합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasText(String value) {
|
||||
return value != null && !value.isBlank();
|
||||
}
|
||||
|
||||
private static boolean hasValue(JsonNode value) {
|
||||
return value != null && !value.isNull() && !value.isEmpty();
|
||||
}
|
||||
|
||||
private static int nonNegativeInt(JsonNode root, String name) {
|
||||
JsonNode value = root.path(name);
|
||||
if (!value.isIntegralNumber() || !value.canConvertToInt() || value.intValue() < 0) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
return value.intValue();
|
||||
}
|
||||
|
||||
private <T> T read(JsonNode node, Class<T> type) {
|
||||
try {
|
||||
return objectMapper.treeToValue(node, type);
|
||||
} catch (JsonProcessingException | IllegalArgumentException e) {
|
||||
throw KkoTemplateApiClient.invalidResponse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.kri.notihub.server.service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
record PhoneVerificationIssue(
|
||||
String verificationId,
|
||||
String verificationCode,
|
||||
String sendTel,
|
||||
String message,
|
||||
LocalDateTime regDt,
|
||||
LocalDateTime expireDt
|
||||
) {
|
||||
}
|
||||
@@ -120,4 +120,14 @@ public class PhoneVerificationService {
|
||||
private PhoneVerificationResponseDto failed(String verificationId, String sendTel) {
|
||||
return PhoneVerificationResponseDto.of(verificationId, sendTel, false, null);
|
||||
}
|
||||
|
||||
record PhoneVerificationIssue(
|
||||
String verificationId,
|
||||
String verificationCode,
|
||||
String sendTel,
|
||||
String message,
|
||||
LocalDateTime regDt,
|
||||
LocalDateTime expireDt
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,8 +87,11 @@ public class ReportService {
|
||||
|
||||
public List<BulkSendInfoDto> getBulkSendList(SendType sendTy, String reqstSvc, String prjctCd,
|
||||
String regCmpn) {
|
||||
List<Short> sendTyList = sendTy == SendType.EMAIL ? List.of(SendType.EMAIL.getCode())
|
||||
: List.of(SendType.SMS.getCode(), SendType.LMS_MMS.getCode());
|
||||
List<Short> sendTyList = switch (sendTy) {
|
||||
case EMAIL -> NotihubConst.EMAIL_TYPE_CODE_LIST;
|
||||
case SMS, LMS_MMS -> NotihubConst.SMS_TYPE_CODE_LIST;
|
||||
case KKO_AT -> NotihubConst.KKO_TYPE_CODE_LIST;
|
||||
};
|
||||
|
||||
if (regCmpn == null) {
|
||||
return bulkSendRepository.findBySendTyInAndReqstSvcAndPrjctCd(sendTyList, reqstSvc, prjctCd)
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -35,9 +37,47 @@ public class TemplateService {
|
||||
private final FileService fileService;
|
||||
private final EmailAttachmentService emailAttachmentService;
|
||||
private final MmsAttachmentService mmsAttachmentService;
|
||||
private final KkoTemplateService kkoTemplateService;
|
||||
private final PlatformTransactionManager transactionManager;
|
||||
|
||||
@Transactional
|
||||
public TemplateDto createTemplate(
|
||||
public TemplateDto createTemplate(String itrntPrjctCd, TemplateBasicDto template,
|
||||
List<MultipartFile> files, String regUser) {
|
||||
validateBySendType(template);
|
||||
prepareKkoTemplate(template, files, null);
|
||||
return new TransactionTemplate(transactionManager).execute(status ->
|
||||
createTemplateInTransaction(itrntPrjctCd, template, files, regUser));
|
||||
}
|
||||
|
||||
public TemplateDto updateTemplate(TemplateDto template, List<MultipartFile> files,
|
||||
List<String> deleteFileNames, String modUser) {
|
||||
TemplateDto stored = getTemplate(template.getTmplatIdx());
|
||||
if (template.getTmplatPurpose() == null) {
|
||||
template.setTmplatPurpose(stored.getTmplatPurpose());
|
||||
}
|
||||
validateBySendType(template);
|
||||
if (template.getTmplatTy() == SendType.KKO_AT
|
||||
&& stored.getAtchFl() != null && !stored.getAtchFl().isBlank()) {
|
||||
throw BusinessException.badRequest("ATTACHMENT_TYPE_CHANGE",
|
||||
"첨부파일을 모두 삭제한 뒤 템플릿 타입을 변경할 수 있습니다.");
|
||||
}
|
||||
prepareKkoTemplate(template, files, deleteFileNames);
|
||||
return new TransactionTemplate(transactionManager).execute(status ->
|
||||
updateTemplateInTransaction(template, files, deleteFileNames, modUser));
|
||||
}
|
||||
|
||||
private void prepareKkoTemplate(TemplateBasicDto template, List<MultipartFile> files,
|
||||
List<String> deleteFileNames) {
|
||||
if (template.getTmplatTy() != SendType.KKO_AT) {
|
||||
return;
|
||||
}
|
||||
if (hasAttachments(files) || hasDeleteFileNames(deleteFileNames)) {
|
||||
throw BusinessException.badRequest("EMAIL_ATTACHMENT_ONLY",
|
||||
"첨부파일은 이메일 또는 문자 템플릿에만 등록할 수 있습니다.");
|
||||
}
|
||||
kkoTemplateService.synchronize(template);
|
||||
}
|
||||
|
||||
private TemplateDto createTemplateInTransaction(
|
||||
String itrntPrjctCd,
|
||||
TemplateBasicDto template,
|
||||
List<MultipartFile> files,
|
||||
@@ -115,8 +155,7 @@ public class TemplateService {
|
||||
return attachmentService(type).download(tmplatIdx, entity.getAtchFl(), fileName);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public TemplateDto updateTemplate(
|
||||
private TemplateDto updateTemplateInTransaction(
|
||||
TemplateDto template,
|
||||
List<MultipartFile> files,
|
||||
List<String> deleteFileNames,
|
||||
@@ -259,7 +298,8 @@ public class TemplateService {
|
||||
throw BusinessException.badRequest("EMPTY_NAME", "템플릿 명은 필수입니다.");
|
||||
}
|
||||
|
||||
if (StringUtil.isNullOrBlank(template.getTmplatBody())) {
|
||||
if (template.getTmplatTy() != SendType.KKO_AT
|
||||
&& StringUtil.isNullOrBlank(template.getTmplatBody())) {
|
||||
throw BusinessException.badRequest("EMPTY_BODY", "내용은 필수입니다.");
|
||||
}
|
||||
|
||||
@@ -304,9 +344,6 @@ public class TemplateService {
|
||||
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는 필수입니다.");
|
||||
|
||||
@@ -124,3 +124,10 @@ kri:
|
||||
enabled: false # RedisQueueHelper 사용 시 true
|
||||
scheduling:
|
||||
enabled: true # @Scheduled 사용 시 true
|
||||
|
||||
notihub:
|
||||
kakao:
|
||||
base-url: https://kapi.ppurio.com/v3/kakao
|
||||
biz-id: kri_notihub
|
||||
api-key: weMdoq0nCGHA
|
||||
sender-key: 370c42bb833e0e3174ba47a2210ea32850349806
|
||||
|
||||
Reference in New Issue
Block a user