feat: 신한라이프 대내MCI/EAI JSON 연계 표준(ShinhanMciSender) 신규 구현
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package io.shinhanlife.axhub.common.integration.mci.config;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.axhub.common.integration.mci.config
|
||||
* @className ShinhanIntegrationProperties
|
||||
* @description AX HUB 시스템 처리 클래스
|
||||
* @author 김형식
|
||||
* @create 2026.09.01
|
||||
* <pre>
|
||||
* ---------- 개정이력 ----------
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2026.09.01 김형식 최초생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "shinhan.integration")
|
||||
public class ShinhanIntegrationProperties {
|
||||
|
||||
/**
|
||||
* 환경유형코드: 운영(R), 테스트(T), 개발(D)
|
||||
*/
|
||||
private String envrTypeCd = "D";
|
||||
|
||||
private ServerInfo eai = new ServerInfo();
|
||||
private ServerInfo internalMci = new ServerInfo();
|
||||
private ServerInfo externalMci = new ServerInfo();
|
||||
private ServerInfo bancaMci = new ServerInfo();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class ServerInfo {
|
||||
private String url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.shinhanlife.axhub.common.integration.mci.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.axhub.common.integration.mci.dto
|
||||
* @className MciRequestWrapper
|
||||
* @description AX HUB 시스템 처리 클래스
|
||||
* @author 김형식
|
||||
* @create 2026.09.01
|
||||
* <pre>
|
||||
* ---------- 개정이력 ----------
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2026.09.01 김형식 최초생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MciRequestWrapper<T> {
|
||||
private ShinhanCommonHeaderDto tgrmCmnnhddValu;
|
||||
|
||||
@JsonUnwrapped
|
||||
private T body;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.shinhanlife.axhub.common.integration.mci.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.axhub.common.integration.mci.dto
|
||||
* @className MciResponseWrapper
|
||||
* @description AX HUB 시스템 처리 클래스
|
||||
* @author 김형식
|
||||
* @create 2026.09.01
|
||||
* <pre>
|
||||
* ---------- 개정이력 ----------
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2026.09.01 김형식 최초생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class MciResponseWrapper<T> {
|
||||
private ShinhanCommonHeaderDto tgrmCmnnhddValu;
|
||||
|
||||
@JsonUnwrapped
|
||||
private T body;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.shinhanlife.axhub.common.integration.mci.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.axhub.common.integration.mci.dto
|
||||
* @className ShinhanCommonHeaderDto
|
||||
* @description AX HUB 시스템 처리 클래스
|
||||
* @author 김형식
|
||||
* @create 2026.09.01
|
||||
* <pre>
|
||||
* ---------- 개정이력 ----------
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2026.09.01 김형식 최초생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ShinhanCommonHeaderDto {
|
||||
|
||||
private String glbId; // 전사공통키 (37 Byte)
|
||||
private String pgrsSriaNo; // 진행일련번호
|
||||
private String trgmVrsnInfoValu; // 전문버전정보값
|
||||
private String tgrmEncrYn; // 전문암호화여부
|
||||
private String gpcpCd; // 글로벌법인코드
|
||||
private String appliDutjCd; // 어플리케이션업무코드
|
||||
private String rcvSvcId; // 수신서비스ID
|
||||
private String envrTypeCd; // 환경유형코드 (D/T/R)
|
||||
private String reqRspnScCd; // 요청응답구분코드 (S:요청, R:응답)
|
||||
private String tnsmTypeCd; // 전송유형코드
|
||||
private String inqrTraTypeCd; // 조회거래유형코드
|
||||
private String reqTgrmTnsmDtptDt; // 요청전문전송일시
|
||||
private String itrIfId; // 인터페이스ID
|
||||
|
||||
// 대외 연계 정보 (선택)
|
||||
private String frbuCd; // 대외기관코드
|
||||
private String cmouDutjCd; // 대외업무코드
|
||||
private String cmouCssfCd; // 대외종별코드
|
||||
private String cmouTraCd; // 대외거래코드
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package io.shinhanlife.axhub.common.integration.mci.sender;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.shinhanlife.axhub.common.integration.mci.config.ShinhanIntegrationProperties;
|
||||
import io.shinhanlife.axhub.common.integration.mci.dto.MciRequestWrapper;
|
||||
import io.shinhanlife.axhub.common.integration.mci.dto.ShinhanCommonHeaderDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.axhub.common.integration.mci.sender
|
||||
* @className ShinhanMciSender
|
||||
* @description AX HUB 시스템 처리 클래스
|
||||
* @author 김형식
|
||||
* @create 2026.09.01
|
||||
* <pre>
|
||||
* ---------- 개정이력 ----------
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2026.09.01 김형식 최초생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ShinhanMciSender {
|
||||
|
||||
private final ObjectMapper jsonMapper;
|
||||
private final RestClient restClient;
|
||||
private final ShinhanIntegrationProperties properties;
|
||||
private final AtomicInteger sequenceGenerator = new AtomicInteger(1);
|
||||
|
||||
public ShinhanMciSender(ObjectMapper jsonMapper, ShinhanIntegrationProperties properties) {
|
||||
this.jsonMapper = jsonMapper;
|
||||
this.properties = properties;
|
||||
this.restClient = RestClient.create();
|
||||
}
|
||||
|
||||
public <T> String send(String targetUrl, MciRequestWrapper<T> requestWrapper) throws Exception {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
try {
|
||||
ShinhanCommonHeaderDto header = requestWrapper.getTgrmCmnnhddValu();
|
||||
if (header == null) {
|
||||
header = new ShinhanCommonHeaderDto();
|
||||
requestWrapper.setTgrmCmnnhddValu(header);
|
||||
}
|
||||
|
||||
// 필수 헤더 자동 세팅 로직
|
||||
header.setEnvrTypeCd(properties.getEnvrTypeCd());
|
||||
header.setReqRspnScCd("S"); // S: 요청
|
||||
|
||||
if (header.getGlbId() == null || header.getGlbId().isEmpty()) {
|
||||
header.setGlbId(generateGlbId());
|
||||
}
|
||||
|
||||
int currentSeq = sequenceGenerator.getAndIncrement();
|
||||
header.setPgrsSriaNo(String.format("%03d", currentSeq)); // 3자리
|
||||
|
||||
if (header.getReqTgrmTnsmDtptDt() == null) {
|
||||
header.setReqTgrmTnsmDtptDt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")));
|
||||
}
|
||||
|
||||
String jsonPayload = jsonMapper.writeValueAsString(requestWrapper);
|
||||
|
||||
log.info(" [신한 통합 MCI 어댑터] 전송 준비 완료 - URL: {}", targetUrl);
|
||||
log.debug(" [신한 통합 MCI 어댑터] 요청 Payload: {}", jsonPayload);
|
||||
|
||||
String responseJson = restClient.post()
|
||||
.uri(targetUrl)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(jsonPayload)
|
||||
.retrieve()
|
||||
.body(String.class);
|
||||
|
||||
log.info(" [신한 통합 MCI 어댑터] 응답 수신 완료");
|
||||
log.debug(" [신한 통합 MCI 어댑터] 응답 Payload: {}", responseJson);
|
||||
|
||||
return responseJson;
|
||||
|
||||
} finally {
|
||||
stopWatch.stop();
|
||||
log.info(" [SLA 모니터링 - MCI 연계] 소요시간: {} ms", stopWatch.getTotalTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
private String generateGlbId() {
|
||||
// 전사공통키 (37 Byte)
|
||||
// 전문생성상세일시(17) + 전문생성시스템명(9) + 어플리케이션업무코드(3) + 전문세션번호(8)
|
||||
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")); // 17 byte
|
||||
String systemName = String.format("%-9s", "AXHUB"); // 9 byte, left-aligned padded with spaces
|
||||
String appCode = "AXH"; // 3 byte
|
||||
String sessionNo = UUID.randomUUID().toString().substring(0, 8).toUpperCase(); // 8 byte
|
||||
return timestamp + systemName + appCode + sessionNo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package io.shinhanlife.axhub.common.integration.mci;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.shinhanlife.axhub.common.integration.mci.dto.MciRequestWrapper;
|
||||
import io.shinhanlife.axhub.common.integration.mci.dto.ShinhanCommonHeaderDto;
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @package io.shinhanlife.axhub.common.integration.mci
|
||||
* @className ShinhanMciSenderTest
|
||||
* @description AX HUB 시스템 처리 클래스
|
||||
* @author 김형식
|
||||
* @create 2026.09.01
|
||||
* <pre>
|
||||
* ---------- 개정이력 ----------
|
||||
* 수정일 수정자 수정내용
|
||||
* ---------- -------- ---------------------------
|
||||
* 2026.09.01 김형식 최초생성
|
||||
*
|
||||
* </pre>
|
||||
*/
|
||||
class ShinhanMciSenderTest {
|
||||
|
||||
@Data
|
||||
static class SampleBody {
|
||||
private String msgCd;
|
||||
private String anxMsgCt;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJsonUnwrapped() throws Exception {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
ShinhanCommonHeaderDto header = new ShinhanCommonHeaderDto();
|
||||
header.setGlbId("20211115150135679009808815NCS17007887");
|
||||
header.setPgrsSriaNo("002");
|
||||
header.setItrIfId("NCSBACO00001");
|
||||
|
||||
SampleBody body = new SampleBody();
|
||||
body.setMsgCd("12345");
|
||||
body.setAnxMsgCt("Test Message");
|
||||
|
||||
MciRequestWrapper<SampleBody> wrapper = new MciRequestWrapper<>();
|
||||
wrapper.setTgrmCmnnhddValu(header);
|
||||
wrapper.setBody(body);
|
||||
|
||||
String json = mapper.writeValueAsString(wrapper);
|
||||
|
||||
System.out.println(json);
|
||||
|
||||
// 검증: body 필드가 json root 레벨에 평탄화되어 있는지 확인
|
||||
assertThat(json).contains("\"tgrmCmnnhddValu\":{");
|
||||
assertThat(json).contains("\"msgCd\":\"12345\"");
|
||||
assertThat(json).contains("\"anxMsgCt\":\"Test Message\"");
|
||||
assertThat(json).doesNotContain("\"body\":");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user