261008_01_ENH: 알림톡 템플릿 관련내용 구현 및 발송 구현
This commit is contained in:
@@ -15,7 +15,9 @@ public enum ChannelType implements CodeEnum<Short> {
|
||||
@Schema(description = "이메일")
|
||||
EMAIL((short) 1),
|
||||
@Schema(description = "문자")
|
||||
SMS((short) 2);
|
||||
SMS((short) 2),
|
||||
@Schema(description = "알림톡")
|
||||
KKO_AT((short) 3);
|
||||
|
||||
private final Short code;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.kri.contact.server.common.external.notihub;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kri.common.feature.http.bypass.BypassClient;
|
||||
import com.kri.common.feature.http.bypass.BypassForwardOptions;
|
||||
@@ -14,6 +13,10 @@ import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubBulkSendCreateRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubBulkSendInfoDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubBulkSendResponseDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListResponseDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubReportExcelResponseDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubReportPageRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubReportPageResponseDto;
|
||||
@@ -74,7 +77,7 @@ public class NotiHubApiClient {
|
||||
public NotiHubTemplateDto getTemplate(Long tmplatIdx) {
|
||||
String url = notiHubBaseUrl + "/template/" + tmplatIdx;
|
||||
try {
|
||||
ExternalApiResponse response = externalApiClient.get(url, headers());
|
||||
ExternalApiResponse response = externalApiClient.get(url, headers()).requireSuccess();
|
||||
return objectMapper.readValue(response.getBody(), NotiHubTemplateDto.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw BusinessException.badRequest("NOTI_HUB_RESPONSE_PARSE_FAILED", "noti-hub 응답을 해석할 수 없습니다.")
|
||||
@@ -96,6 +99,37 @@ public class NotiHubApiClient {
|
||||
return postSingle("/send-sms/single", request, ctx);
|
||||
}
|
||||
|
||||
public NotiHubSendSingleResponseDto sendKkoSingle(
|
||||
NotiHubSendRequestSingleDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return postSingle("/send-kko/single", request, ctx);
|
||||
}
|
||||
|
||||
public String createKkoBulk(NotiHubBulkSendCreateRequestDto request) {
|
||||
return createBulk("/send-kko/create/bulk", request);
|
||||
}
|
||||
|
||||
public NotiHubBulkSendResponseDto sendKkoBulk(NotiHubSendRequestBulkDto request) {
|
||||
return sendBulk("/send-kko/bulk", request);
|
||||
}
|
||||
|
||||
public ResponseEntity<NotiHubKkoTemplateListResponseDto> getKkoTemplateList(
|
||||
NotiHubKkoTemplateListRequestDto body,
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return relay(request, body, NotiHubKkoTemplateListResponseDto.class, ctx);
|
||||
}
|
||||
|
||||
public ResponseEntity<NotiHubKkoTemplateDetailDto> getKkoTemplateDetail(
|
||||
NotiHubKkoTemplateDetailRequestDto body,
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return relay(request, body, NotiHubKkoTemplateDetailDto.class, ctx);
|
||||
}
|
||||
|
||||
public String createEmailBulk(NotiHubBulkSendCreateRequestDto request) {
|
||||
return createBulk("/send-email/create/bulk", request);
|
||||
}
|
||||
@@ -240,8 +274,13 @@ public class NotiHubApiClient {
|
||||
}
|
||||
|
||||
private String createBulk(String path, NotiHubBulkSendCreateRequestDto request) {
|
||||
ExternalApiResponse response = put(notiHubBaseUrl + path, request);
|
||||
return response.getBody();
|
||||
ExternalApiResponse response = put(notiHubBaseUrl + path, request).requireSuccess();
|
||||
String bulkSendKey = response.getBody();
|
||||
if (bulkSendKey == null || bulkSendKey.isBlank() || bulkSendKey.length() != 32) {
|
||||
throw BusinessException.of(HttpStatus.BAD_GATEWAY, "NOTI_HUB_BULK_KEY_INVALID",
|
||||
"noti-hub 대량 발송 키가 올바르지 않습니다.");
|
||||
}
|
||||
return bulkSendKey;
|
||||
}
|
||||
|
||||
private NotiHubBulkSendResponseDto sendBulk(String path, NotiHubSendRequestBulkDto request) {
|
||||
@@ -257,7 +296,7 @@ public class NotiHubApiClient {
|
||||
|
||||
private ExternalApiResponse post(String url, Object request) {
|
||||
try {
|
||||
return externalApiClient.post(url, headers(), objectMapper.writeValueAsString(request));
|
||||
return externalApiClient.post(url, headers(), objectMapper.writeValueAsString(request)).requireSuccess();
|
||||
} catch (JsonProcessingException e) {
|
||||
throw BusinessException.badRequest("NOTI_HUB_REQUEST_SERIALIZE_FAILED", "noti-hub 요청을 생성할 수 없습니다.")
|
||||
.with("url", url);
|
||||
@@ -270,6 +309,9 @@ public class NotiHubApiClient {
|
||||
} catch (JsonProcessingException e) {
|
||||
throw BusinessException.badRequest("NOTI_HUB_REQUEST_SERIALIZE_FAILED", "noti-hub 요청을 생성할 수 없습니다.")
|
||||
.with("url", url);
|
||||
} catch (RuntimeException e) {
|
||||
throw BusinessException.of(HttpStatus.BAD_GATEWAY, "NOTI_HUB_CALL_FAILED",
|
||||
"noti-hub에 연결할 수 없습니다.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +396,7 @@ public class NotiHubApiClient {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.putAll(response.getHeaders());
|
||||
// JSON serialization changes the bytes; upstream representation headers no longer apply.
|
||||
headers.remove(HttpHeaders.CONTENT_LENGTH);
|
||||
headers.remove(HttpHeaders.CONTENT_LENGTH);
|
||||
headers.remove(HttpHeaders.CONTENT_ENCODING);
|
||||
headers.remove(HttpHeaders.ETAG);
|
||||
if (headers.getContentType() == null) {
|
||||
@@ -374,32 +416,6 @@ public class NotiHubApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
private void requireSuccessfulResponse(ResponseEntity<byte[]> response) {
|
||||
if (response.getStatusCode().is2xxSuccessful()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HttpStatus status = HttpStatus.resolve(response.getStatusCode().value());
|
||||
if (status == null) {
|
||||
status = HttpStatus.BAD_GATEWAY;
|
||||
}
|
||||
String code = "NOTI_HUB_ERROR";
|
||||
String message = status.getReasonPhrase();
|
||||
byte[] body = response.getBody();
|
||||
if (body != null && body.length > 0) {
|
||||
try {
|
||||
JsonNode error = objectMapper.readTree(body);
|
||||
if (error != null) {
|
||||
code = error.path("code").asText(code);
|
||||
message = error.path("detail").asText(message);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// An invalid error body retains the HTTP status and its standard message.
|
||||
}
|
||||
}
|
||||
throw BusinessException.of(status, code, message);
|
||||
}
|
||||
|
||||
private ResponseEntity<byte[]> forward(
|
||||
HttpServletRequest request,
|
||||
byte[] body,
|
||||
@@ -425,9 +441,7 @@ public class NotiHubApiClient {
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
ResponseEntity<byte[]> result = toResponseEntity(response, request);
|
||||
requireSuccessfulResponse(result);
|
||||
return result;
|
||||
return toResponseEntity(response, request);
|
||||
}
|
||||
|
||||
private ResponseEntity<byte[]> relayMultipart(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.contact.server.common.external.notihub.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -24,6 +25,7 @@ public class NotiHubBulkSendCreateRequestDto {
|
||||
@Schema(description = "resve")
|
||||
private Boolean resve;
|
||||
@Schema(description = "sendDt")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime sendDt;
|
||||
@Schema(description = "trgtCnt")
|
||||
private Integer trgtCnt;
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.kri.contact.server.common.external.notihub.dto;
|
||||
|
||||
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 NotiHubKkoTemplateDetailDto {
|
||||
|
||||
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.contact.server.common.external.notihub.dto;
|
||||
|
||||
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 NotiHubKkoTemplateDetailRequestDto {
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 30)
|
||||
@Pattern(regexp = "[A-Za-z0-9_-]+")
|
||||
private String templateCode;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.contact.server.common.external.notihub.dto;
|
||||
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
public class NotiHubKkoTemplateListRequestDto {
|
||||
|
||||
@Size(min = 2, max = 50)
|
||||
private String keyword;
|
||||
|
||||
public NotiHubKkoTemplateListRequestDto(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.contact.server.common.external.notihub.dto;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class NotiHubKkoTemplateListResponseDto {
|
||||
|
||||
private int totalCount;
|
||||
private int totalPage;
|
||||
private int currentPage;
|
||||
private List<NotiHubKkoTemplateSummaryDto> list;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.kri.contact.server.common.external.notihub.dto;
|
||||
|
||||
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 NotiHubKkoTemplateSummaryDto {
|
||||
|
||||
private String templateCode;
|
||||
private String templateName;
|
||||
private String serviceStatus;
|
||||
private String createdAt;
|
||||
private String modifiedAt;
|
||||
}
|
||||
@@ -33,7 +33,6 @@ public class NotiHubTemplateBasicDto extends NotiHubExtensibleDto {
|
||||
@Size(max = 128)
|
||||
private String tmplatTitle;
|
||||
|
||||
@NotBlank
|
||||
private String tmplatBody;
|
||||
|
||||
private String senderKey;
|
||||
|
||||
@@ -44,6 +44,26 @@ public class MessageSendController {
|
||||
return messageSendService.sendEmailBulk(prjctIdx, request, ctx);
|
||||
}
|
||||
|
||||
@Operation(summary = "Kakao Alimtalk single send")
|
||||
@PostMapping("/kko/single/{prjctIdx}")
|
||||
public MessageSendSingleResponseDto sendKkoSingle(
|
||||
@PathVariable Long prjctIdx,
|
||||
@Valid @RequestBody MessageSendSingleRequestDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return messageSendService.sendKkoSingle(prjctIdx, request, ctx);
|
||||
}
|
||||
|
||||
@Operation(summary = "Kakao Alimtalk bulk send")
|
||||
@PostMapping("/kko/bulk/{prjctIdx}")
|
||||
public MessageSendBulkResponseDto sendKkoBulk(
|
||||
@PathVariable Long prjctIdx,
|
||||
@Valid @RequestBody MessageSendBulkRequestDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return messageSendService.sendKkoBulk(prjctIdx, request, ctx);
|
||||
}
|
||||
|
||||
@Operation(summary = "SMS single send")
|
||||
@PostMapping("/sms/single/{prjctIdx}")
|
||||
public MessageSendSingleResponseDto sendSmsSingle(
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.kri.contact.server.controller;
|
||||
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListResponseDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateBasicDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateDetailDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateSummaryDto;
|
||||
@@ -15,7 +19,9 @@ import org.springframework.http.ResponseEntity;
|
||||
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.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.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
@@ -30,6 +36,24 @@ public class MessageTemplateController {
|
||||
|
||||
private final MessageTemplateService messageTemplateService;
|
||||
|
||||
@PostMapping(value = "/kko/list", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<NotiHubKkoTemplateListResponseDto> getKkoTemplateList(
|
||||
@Valid @RequestBody NotiHubKkoTemplateListRequestDto body,
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return messageTemplateService.getKkoTemplateList(body, request, ctx);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/kko/detail", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<NotiHubKkoTemplateDetailDto> getKkoTemplateDetail(
|
||||
@Valid @RequestBody NotiHubKkoTemplateDetailRequestDto body,
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return messageTemplateService.getKkoTemplateDetail(body, request, ctx);
|
||||
}
|
||||
|
||||
@GetMapping("/list/{chnnlTy}/{itrntPrjctCd}")
|
||||
public ResponseEntity<List<NotiHubTemplateSummaryDto>> getTemplateList(
|
||||
@PathVariable Integer chnnlTy,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.contact.server.dto.message;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.kri.contact.server.dto.list.ListFilterDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -26,6 +27,7 @@ public class MessageSendBulkRequestDto {
|
||||
private Boolean resve;
|
||||
|
||||
@Schema(description = "예약 발송 일시")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime sendDt;
|
||||
|
||||
@Valid
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.kri.contact.server.dto.message;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -23,6 +24,7 @@ public class MessageSendSingleRequestDto {
|
||||
@Schema(description = "resve")
|
||||
private Boolean resve;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Schema(description = "sendDt")
|
||||
private LocalDateTime sendDt;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.kri.contact.server.dto.message.MessageSendBulkRequestDto;
|
||||
import com.kri.contact.server.dto.message.MessageSendSingleRequestDto;
|
||||
import com.kri.contact.server.dto.message.MessageSendSingleResponseDto;
|
||||
import com.kri.contact.server.dto.project.ProjectInfoDto;
|
||||
import com.kri.contact.server.dto.project.ProjectSurveyDto;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -81,6 +82,24 @@ public class MessageSendService {
|
||||
return sendBulk(prjctIdx, request, ctx, ChannelType.SMS);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public MessageSendSingleResponseDto sendKkoSingle(
|
||||
Long prjctIdx,
|
||||
MessageSendSingleRequestDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return sendSingle(prjctIdx, request, ctx, ChannelType.KKO_AT);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public MessageSendBulkResponseDto sendKkoBulk(
|
||||
Long prjctIdx,
|
||||
MessageSendBulkRequestDto request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return sendBulk(prjctIdx, request, ctx, ChannelType.KKO_AT);
|
||||
}
|
||||
|
||||
private MessageSendSingleResponseDto sendSingle(
|
||||
Long prjctIdx,
|
||||
MessageSendSingleRequestDto request,
|
||||
@@ -124,6 +143,8 @@ public class MessageSendService {
|
||||
|
||||
if (channelType == ChannelType.EMAIL) {
|
||||
response = notiHubApiClient.sendEmailSingle(notiRequest, ctx);
|
||||
} else if (channelType == ChannelType.KKO_AT) {
|
||||
response = notiHubApiClient.sendKkoSingle(notiRequest, ctx);
|
||||
} else {
|
||||
response = notiHubApiClient.sendSmsSingle(notiRequest, ctx);
|
||||
}
|
||||
@@ -237,7 +258,7 @@ public class MessageSendService {
|
||||
) {
|
||||
List<NotiHubDestInfoDto> result = new ArrayList<>();
|
||||
for (ListSearchService.DownloadListRow row : rows) {
|
||||
Map<String, String> msgParam = createMessageParams(row, messageContext.paramHeaderByName());
|
||||
Map<String, String> msgParam = createMessageParams(row, messageContext);
|
||||
String destNm = resolveHeaderValue(row, messageContext.headerById().get(destNameHeaderId));
|
||||
|
||||
for (Integer destHeaderId : destHeaderIds) {
|
||||
@@ -274,7 +295,7 @@ public class MessageSendService {
|
||||
Set<String> bodyParams = extractTemplateParams(template.getTmplatBody());
|
||||
Set<String> templateParams = SetUtils.union(titleParams, bodyParams);
|
||||
|
||||
Map<Integer, ListHeaderDto> headerById = listHeaderService.getHeader(prjctIdx).stream()
|
||||
Map<Integer, ListHeaderDto> headerById = listHeaderService.getHeader(prjctIdx).stream()
|
||||
.collect(Collectors.toMap(
|
||||
ListHeaderDto::getListHderId,
|
||||
header -> header,
|
||||
@@ -299,7 +320,29 @@ public class MessageSendService {
|
||||
LinkedHashMap::new
|
||||
));
|
||||
|
||||
return new MessageContext(project, template, headerById, paramHeaderByName);
|
||||
Map<String, String> surveyUrlByName = new LinkedHashMap<>();
|
||||
if (project.getSurveys() != null) {
|
||||
for (ProjectSurveyDto survey : project.getSurveys()) {
|
||||
String name = survey.getSurveyName();
|
||||
String url = normalizeBlank(survey.getSurveyUrl());
|
||||
if (!templateParams.contains(name) || paramHeaderByName.containsKey(name) || url == null) {
|
||||
continue;
|
||||
}
|
||||
if (surveyUrlByName.putIfAbsent(name, url) != null) {
|
||||
throw BusinessException.badRequest("DUPLICATE_SURVEY_NAME", "치환할 설문명이 중복됩니다.")
|
||||
.with("surveyName", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> requiredHeaderParams = new HashSet<>(templateParams);
|
||||
surveyUrlByName.values().forEach(url -> requiredHeaderParams.addAll(extractTemplateParams(url)));
|
||||
headerById.values().stream()
|
||||
.filter(header -> requiredHeaderParams.contains(header.getListHderNm()))
|
||||
.forEach(header -> paramHeaderByName.putIfAbsent(header.getListHderNm(), header));
|
||||
|
||||
return new MessageContext(project, template, headerById, paramHeaderByName,
|
||||
templateParams, surveyUrlByName);
|
||||
}
|
||||
|
||||
private String createBulkSendKey(
|
||||
@@ -320,9 +363,11 @@ public class MessageSendService {
|
||||
.trgtCnt(targetCount)
|
||||
.build();
|
||||
|
||||
return channelType == ChannelType.EMAIL
|
||||
? notiHubApiClient.createEmailBulk(notiRequest)
|
||||
: notiHubApiClient.createSmsBulk(notiRequest);
|
||||
return switch (channelType) {
|
||||
case EMAIL -> notiHubApiClient.createEmailBulk(notiRequest);
|
||||
case SMS -> notiHubApiClient.createSmsBulk(notiRequest);
|
||||
case KKO_AT -> notiHubApiClient.createKkoBulk(notiRequest);
|
||||
};
|
||||
}
|
||||
|
||||
private NotiHubBulkSendResponseDto sendBulkChunk(
|
||||
@@ -335,25 +380,44 @@ public class MessageSendService {
|
||||
.destInfoList(destInfos)
|
||||
.build();
|
||||
|
||||
return channelType == ChannelType.EMAIL
|
||||
? notiHubApiClient.sendEmailBulk(request)
|
||||
: notiHubApiClient.sendSmsBulk(request);
|
||||
return switch (channelType) {
|
||||
case EMAIL -> notiHubApiClient.sendEmailBulk(request);
|
||||
case SMS -> notiHubApiClient.sendSmsBulk(request);
|
||||
case KKO_AT -> notiHubApiClient.sendKkoBulk(request);
|
||||
};
|
||||
}
|
||||
|
||||
private Map<String, String> createMessageParams(
|
||||
ListSearchService.DownloadListRow row,
|
||||
Map<String, ListHeaderDto> paramHeaderByName
|
||||
MessageContext messageContext
|
||||
) {
|
||||
Map<String, String> headerParams = new LinkedHashMap<>();
|
||||
Map<String, String> msgParam = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, ListHeaderDto> entry : paramHeaderByName.entrySet()) {
|
||||
for (Map.Entry<String, ListHeaderDto> entry : messageContext.paramHeaderByName().entrySet()) {
|
||||
String value = resolveHeaderValue(row, entry.getValue());
|
||||
if (value != null) {
|
||||
msgParam.put(entry.getKey(), value);
|
||||
headerParams.put(entry.getKey(), value);
|
||||
if (messageContext.templateParams().contains(entry.getKey())) {
|
||||
msgParam.put(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
messageContext.surveyUrlByName().forEach((name, url) ->
|
||||
msgParam.put(name, resolveSurveyUrlParams(url, headerParams)));
|
||||
return msgParam;
|
||||
}
|
||||
|
||||
private String resolveSurveyUrlParams(String url, Map<String, String> headerParams) {
|
||||
Matcher matcher = TEMPLATE_PARAM_PATTERN.matcher(url);
|
||||
StringBuilder resolved = new StringBuilder();
|
||||
while (matcher.find()) {
|
||||
String value = headerParams.get(normalizeBlank(matcher.group(1)));
|
||||
matcher.appendReplacement(resolved, Matcher.quoteReplacement(value == null ? matcher.group() : value));
|
||||
}
|
||||
matcher.appendTail(resolved);
|
||||
return resolved.toString();
|
||||
}
|
||||
|
||||
private String resolveHeaderValue(ListSearchService.DownloadListRow row, ListHeaderDto header) {
|
||||
if (header == null) {
|
||||
return null;
|
||||
@@ -419,7 +483,7 @@ public class MessageSendService {
|
||||
if (normalized == null) {
|
||||
return null;
|
||||
}
|
||||
if (channelType == ChannelType.SMS) {
|
||||
if (channelType == ChannelType.SMS || channelType == ChannelType.KKO_AT) {
|
||||
String digits = normalized.replaceAll("\\D", "");
|
||||
return digits.isBlank() ? null : digits;
|
||||
}
|
||||
@@ -461,7 +525,9 @@ public class MessageSendService {
|
||||
ProjectInfoDto project,
|
||||
NotiHubTemplateDto template,
|
||||
Map<Integer, ListHeaderDto> headerById,
|
||||
Map<String, ListHeaderDto> paramHeaderByName
|
||||
Map<String, ListHeaderDto> paramHeaderByName,
|
||||
Set<String> templateParams,
|
||||
Map<String, String> surveyUrlByName
|
||||
) {}
|
||||
|
||||
private static class ListFilterDtoFactory {
|
||||
|
||||
@@ -2,6 +2,10 @@ package com.kri.contact.server.service;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.common.feature.web.RequestUserContext;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateDetailRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListRequestDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubKkoTemplateListResponseDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateBasicDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateDetailDto;
|
||||
import com.kri.contact.server.common.external.notihub.dto.NotiHubTemplateSummaryDto;
|
||||
@@ -19,6 +23,22 @@ public class MessageTemplateService {
|
||||
|
||||
private final NotiHubApiClient notiHubApiClient;
|
||||
|
||||
public ResponseEntity<NotiHubKkoTemplateListResponseDto> getKkoTemplateList(
|
||||
NotiHubKkoTemplateListRequestDto body,
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return notiHubApiClient.getKkoTemplateList(body, request, ctx);
|
||||
}
|
||||
|
||||
public ResponseEntity<NotiHubKkoTemplateDetailDto> getKkoTemplateDetail(
|
||||
NotiHubKkoTemplateDetailRequestDto body,
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
) {
|
||||
return notiHubApiClient.getKkoTemplateDetail(body, request, ctx);
|
||||
}
|
||||
|
||||
public ResponseEntity<List<NotiHubTemplateSummaryDto>> getTemplateList(
|
||||
HttpServletRequest request,
|
||||
RequestUserContext ctx
|
||||
|
||||
Reference in New Issue
Block a user