feat: KT API 반영

dev
gitea-관리자 1 year ago
parent b0b058bb2f
commit 49e7cc4210

@ -0,0 +1,24 @@
package kr.xit.biz.kt.mapper;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
/**
* <pre>
* description :
*
* packageName : kr.xit.biz.kt.mapper
* fileName : IBizKtMmsMapper
* author : limju
* date : 2023-10-12
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-10-12 limju
*
* </pre>
*/
@Mapper
public interface IBizKtMmsMapper {
int updateRlaybsnmKtInfo(final CmmEnsRlaybsnmDTO dto);
}

@ -0,0 +1,332 @@
package kr.xit.biz.kt.service;
import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse;
import kr.xit.biz.kt.mapper.IBizKtMmsMapper;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.ens.kt.service.IKtMmsService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.egovframe.rte.fdl.cmmn.EgovAbstractServiceImpl;
import org.springframework.stereotype.Service;
/**
* <pre>
* description :
*
* packageName : kr.xit.biz.kt.service
* fileName : BizKtMmsService
* author : limju
* date : 2023-09-22
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-22 limju
*
* </pre>
*/
@RequiredArgsConstructor
@Service
public class BizKtMmsService extends EgovAbstractServiceImpl implements IBizKtMmsService {
private static final String profile = System.getProperty("spring.profiles.active");
private final IKtMmsService ktMmsService;
private final ICmmEnsCacheService cacheService;
private final IBizKtMmsMapper mapper;
/**
* kt Access token
* 1. kt Access token
* 2. DB
* 3.
* @param paramDTO
* @return
*/
@Override
public KtTokenResponse requestToken(final KtMnsRequest paramDTO) {
KtTokenResponse resDTO = ktMmsService.requestToken(paramDTO);
if(StringUtils.isEmpty(resDTO.getAccessToken())){
throw BizRuntimeException.create("fail.api.kt.token.request");
}
mapper.updateRlaybsnmKtInfo(
CmmEnsRlaybsnmDTO.builder()
.signguCode(paramDTO.getSignguCode())
.ffnlgCode(paramDTO.getFfnlgCode())
.profile(profile)
.ktAccessToken(resDTO.getAccessToken())
.ktTokenExpiresIn(resDTO.getExpiresIn())
.ktScope(resDTO.getScope())
.ktTokenJti(resDTO.getJti())
.build()
);
cacheService.removeRlaybsnmInfoCache(paramDTO);
return resDTO;
}
// /**
// * 사전 문자 수신 등록 요청(BC-AG-SN-001)
// * @param reqDTO
// */
// @Override
// public KtCommonResponse beforeSend(final KtBefSendRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_BEFORE_SEND,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
//
// /*List<ErrorMsg> errors = new ArrayList<>();
// errors.add(new ErrorMsg("error1"));
// errors.add(new ErrorMsg("error2"));
//
// return KtCommonResponse.builder()
// .resultCd("00")
// .resultDt(DateUtils.getTodayAndNowTime("yyyyMMddHHmmss"))
// .errors(errors)
// .build();*/
// }
//
// @Override
// public KtCommonResponse mainSend(final KtMainSendRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_MAIN_SEND,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse blacklist(final KtBlacklistRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_BLACKLIST,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse cfmToken(final KtTokenDTO.KtTokenConfirmRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_CFM_TOKEN,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse readToken(final KtTokenReadRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_READ_TOKEN,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse messageResult(final KtMsgRsltRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_RESULT_MESSAGE,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtSendSttcResponse sendSttc(final KtSendSttcRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_SEND_STTC,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtSendSttcResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtSendSttcDtlResponse sendSttcDtl(final KtSendSttcDtlRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_SEND_STTCDTL,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtSendSttcDtlResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse whitelist(final KtWhitelistRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_WHITELIST,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse refuseRcv(final KtRefuseRcvRequest reqDTO) {
// //final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return KtCommonResponse.builder()
// .resultCd("")
// .resultDt("")
// .build();
// }
//
// @Override
// public KtCommonResponse approveRcv(final KtApproveRcvRequest reqDTO) {
// //final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return KtCommonResponse.builder()
// .resultCd("")
// .resultDt("")
// .build();
// }
//
// @Override
// public KtAcmdCerfResponse cerfAcmd(final KtAcmdCerfRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_CERF_ACMD,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtAcmdCerfResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtCommonResponse excaAcmd(KtTokenExcaRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_EXCA_ACMD,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtCommonResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtExcaResponse exca(final KtExcaRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_EXCA,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtExcaResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtAcmdInfoResponse infoAcmd(final KtAcmdInfoRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_INFO_ACMD,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtAcmdInfoResponse.class,
// ktMnsInfo
// );
// }
//
// @Override
// public KtAcmdInfoCfmResponse cfmAcmd(final KtAcmdInfoCfmRequest reqDTO) {
// final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
// //reqDTO.setServiceCd(ktMnsInfo.get);
// //reqDTO.setServiceKey(ktMnsInfo.get);
// CmmEnsUtils.validate(reqDTO);
//
// return webClient.exchangeKt(
// HOST + API_CFM_ACMD,
// HttpMethod.POST,
// JsonUtils.toJson(reqDTO),
// KtAcmdInfoCfmResponse.class,
// ktMnsInfo
// );
// }
}

@ -0,0 +1,45 @@
package kr.xit.biz.kt.service;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenResponse;
/**
* <pre>
* description :
*
* packageName : kr.xit.biz.kt.service
* fileName : IBizKtMmsService
* author : limju
* date : 2023-09-22
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-22 limju
*
* </pre>
*/
public interface IBizKtMmsService {
KtTokenResponse requestToken(final KtMnsRequest paramDTO);
// KtCommonResponse beforeSend(final KtBefSendRequest reqDTO);
// KtCommonResponse mainSend(final KtMainSendRequest reqDTO);
// KtCommonResponse blacklist(final KtBlacklistRequest reqDTO);
// KtCommonResponse cfmToken(final KtTokenConfirmRequest reqDTO);
// KtCommonResponse readToken(final KtTokenReadRequest reqDTO);
// KtCommonResponse messageResult(final KtMsgRsltRequest reqDTO);
// KtSendSttcResponse sendSttc(final KtSendSttcRequest reqDTO);
// KtSendSttcDtlResponse sendSttcDtl(final KtSendSttcDtlRequest reqDTO);
// KtCommonResponse whitelist(final KtWhitelistRequest reqDTO);
//
// KtCommonResponse refuseRcv(final KtRefuseRcvRequest reqDTO);
// KtCommonResponse approveRcv(final KtApproveRcvRequest reqDTO);
//
// KtAcmdCerfResponse cerfAcmd(final KtAcmdCerfRequest reqDTO);
//
// KtCommonResponse excaAcmd(final KtTokenExcaRequest reqDTO);
// KtExcaResponse exca(final KtExcaRequest reqDTO);
// KtAcmdInfoResponse infoAcmd(final KtAcmdInfoRequest reqDTO);
// KtAcmdInfoCfmResponse cfmAcmd(final KtAcmdInfoCfmRequest reqDTO);
}

@ -0,0 +1,186 @@
package kr.xit.biz.kt.web;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.kt.service.IBizKtMmsService;
import kr.xit.core.model.ApiResponseDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
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;
/**
* <pre>
* description :
*
* packageName : kr.xit.biz.kt.web
* fileName : BizKtMmsController
* author : limju
* date : 2023-09-22
* ======================================================================
*
* ----------------------------------------------------------------------
* 2023-09-22 limju
*
* </pre>
*/
@Tag(name = "BizKtMmsController", description = "KT MMS 업무처리 Controller")
@RequiredArgsConstructor
@RestController
@RequestMapping(value = "/api/biz/kt/v1")
public class BizKtMmsController {
private final IBizKtMmsService service;
@Operation(summary = "기관용 토큰 발급 요청", description = "기관용 토큰 발급 요청")
@PostMapping(value = "/requestToken", produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseDTO<?> requestToken(@RequestBody final KtMnsRequest paramDTO) {
return ApiResponseDTO.success(service.requestToken(paramDTO));
}
//
// /*
// @io.swagger.v3.oas.annotations.parameters.RequestBody(required = true, content = {
// @Content(
// mediaType = "application/json",
// examples = {
// @ExampleObject(
// value = """
// {
// "signguCode": "",
// "ffnlgCode": "11",
// "service_cd": "NPS",
// "service_key": "A3AD41349D759DD3",
// "msg_cd": "10006",
// "msg_type": "2",
// "make_dt": "20211229102000",
// "sndn_ex_time": "20211229180000",
// "sndn_tot_cnt": 1,
// "reqs": [
// {
// "src_key": "S20211229102000001",
// "src_seq": "1",
// "ci": "gdlIa53FZGQz5aKa3wLk33nW57N3mDpcwHytWlWMhzxHKulk7EZs143442394326642342364238648423864237",
// "mdn": "01011112222", "rcve_rf_str":" ○ 수신거부 및 수신 휴대폰 지정하기 :"
// }
// ],
// "opt_type": "2",
// "mktn_rcve_csyn": "N",
// "m_type": "2"
// }
// """)
// })
// })*/
// @Operation(summary = "사전 문자 수신 등록 요청", description = "사전 문자 수신 등록 요청(BC-AG-SN-001)")
// @PostMapping(value = "/beforeSend", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> beforeSend(@RequestBody final KtBefSendRequest reqDTO) {
// KtCommonResponse dto = service.beforeSend(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "본문자 수신 등록 요청", description = "본문자 수신 등록 요청(BC-AG-SN-002)")
// @PostMapping(value = "/mainSend", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> mainSend(@RequestBody final KtMainSendRequest reqDTO) {
// KtCommonResponse dto = service.mainSend(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "수신 거부 등록 요청", description = "수신 거부 등록 요청(BC-AG-SN-007)")
// @PostMapping(value = "/blacklist", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> blacklist(@RequestBody final KtBlacklistRequest reqDTO) {
// KtCommonResponse dto = service.blacklist(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "토큰인증확인 조회", description = "토큰인증확인조회요청(BC-AG-SN-008)")
// @PostMapping(value = "/cfmToken", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> cfmToken(@RequestBody final KtTokenConfirmRequest reqDTO) {
// KtCommonResponse dto = service.cfmToken(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "토큰열람확인결과 전송", description = "토큰열람확인결과 전송(BC-AG-SN-009)")
// @PostMapping(value = "/readToken", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> readToken(@RequestBody final KtTokenReadRequest reqDTO) {
// KtCommonResponse dto = service.readToken(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "사전/본 문자 발송/수신 결과 전송 요청", description = "사전/본 문자 발송/수신 결과 전송 요청(BC-AG-SN-010)")
// @PostMapping(value = "/messageResult", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> messageResult(@RequestBody final KtMsgRsltRequest reqDTO) {
// KtCommonResponse dto = service.messageResult(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "백오피스 발송 통계 연계 조회 요청", description = "백오피스 발송 통계 연계 조회 요청(BC-AG-SN-011)")
// @PostMapping(value = "/sendSttc", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> sendSttc(@RequestBody final KtSendSttcRequest reqDTO) {
// KtMmsDTO.KtSendSttcResponse dto = service.sendSttc(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "백오피스 발송 결과 연계 조회 요청", description = "백오피스 발송 결과 연계 조회 요청(BC-AG-SN-012)")
// @PostMapping(value = "/sendSttcDtl", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> sendSttcDtl(@RequestBody final KtSendSttcDtlRequest reqDTO) {
// KtMmsDTO.KtSendSttcDtlResponse dto = service.sendSttcDtl(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "whitelist 등록 요청", description = "whitelist 등록 요청(BC-AG-SN-013)")
// @PostMapping(value = "/whitelist", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> whitelist(@RequestBody final KtWhitelistRequest reqDTO) {
// KtCommonResponse dto = service.whitelist(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "수신거부상태 전송", description = "수신거부상태전송(BC-AG-SN-014)")
// @PostMapping(value = "/refuseRcv", produces = MediaType.APPLICATION_JSON_VALUE)
// public KtCommonResponse refuseRcv(@RequestBody final KtRefuseRcvRequest reqDTO) {
// KtCommonResponse dto = service.refuseRcv(reqDTO);
// return dto;
// }
//
// @Operation(summary = "수신동의상태 전송", description = "수신동의상태전송(BC-AG-SN-015)")
// @PostMapping(value = "/approveRcv", produces = MediaType.APPLICATION_JSON_VALUE)
// public KtCommonResponse approveRcv(@RequestBody final KtApproveRcvRequest reqDTO) {
// KtCommonResponse dto = service.approveRcv(reqDTO);
// return dto;
// }
//
// @Operation(summary = "유통증명서발급처리 요청", description = "유통증명서발급처리 요청(BC-AG-SM-001)")
// @PostMapping(value = "/cerfAcmd", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> cerfAcmd(@RequestBody final KtAcmdCerfRequest reqDTO) {
// KtAcmdCerfResponse dto = service.cerfAcmd(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "가상정산화면 연계토큰 인증 요청", description = "가상정산화면 연계토큰 인증 요청(BC-AG-SM-002)")
// @PostMapping(value = "/excaAcmd", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> excaAcmd(@RequestBody final KtTokenExcaRequest reqDTO) {
// KtCommonResponse dto = service.excaAcmd(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "정산연계자료조회", description = "정산연계자료조회(BC-AG-EC-001)")
// @PostMapping(value = "/exca", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> exca(@RequestBody final KtExcaRequest reqDTO) {
// KtExcaResponse dto = service.exca(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "전자문서 유통정보 수치 조회", description = "전자문서 유통정보 수치 조회(BC-AG-HS-001)")
// @PostMapping(value = "/infoAcmd", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> infoAcmd(@RequestBody final KtAcmdInfoRequest reqDTO) {
// KtAcmdInfoResponse dto = service.infoAcmd(reqDTO);
// return ApiResponseDTO.success(dto);
// }
//
// @Operation(summary = "전자문서 유통정보 수치확인서 발급 처리", description = "전자문서 유통정보 수치확인서 발급 처리(BC-AG-HS-002)")
// @PostMapping(value = "/cfmAcmd", produces = MediaType.APPLICATION_JSON_VALUE)
// public ApiResponseDTO<?> cfmAcmd(@RequestBody final KtAcmdInfoCfmRequest reqDTO) {
// KtAcmdInfoCfmResponse dto = service.cfmAcmd(reqDTO);
// return ApiResponseDTO.success(dto);
// }
}

@ -1,15 +1,14 @@
package kr.xit.core.spring.util; package kr.xit.core.spring.util;
import egovframework.com.cmm.EgovMessageSource;
import kr.xit.biz.cmm.service.CmmEnsCacheService; import kr.xit.biz.cmm.service.CmmEnsCacheService;
import kr.xit.biz.cmm.service.ICmmEnsCacheService; import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.core.spring.config.support.ApplicationContextProvider; import kr.xit.core.spring.config.support.ApplicationContextProvider;
import kr.xit.ens.kt.service.IKtMmsService;
import kr.xit.ens.nice.service.INiceCiService; import kr.xit.ens.nice.service.INiceCiService;
import kr.xit.ens.nice.service.NiceCiDummyTestService; import kr.xit.ens.nice.service.NiceCiDummyTestService;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
/** /**
* <pre> * <pre>
@ -55,6 +54,10 @@ public class ApiSpringUtils {
return (INiceCiService)getBean(INiceCiService.class); return (INiceCiService)getBean(INiceCiService.class);
} }
public static IKtMmsService getKtMmsService(){
return (IKtMmsService)getBean(IKtMmsService.class);
}
public static NiceCiDummyTestService getDummyNiceCiService(){ public static NiceCiDummyTestService getDummyNiceCiService(){
return (NiceCiDummyTestService)getBean(NiceCiDummyTestService.class); return (NiceCiDummyTestService)getBean(NiceCiDummyTestService.class);
} }

@ -2,17 +2,16 @@ package kr.xit.ens.kt.cmm;
import egovframework.com.cmm.EgovMessageSource; import egovframework.com.cmm.EgovMessageSource;
import kr.xit.biz.cmm.service.ICmmEnsCacheService; import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.biz.ens.model.cmm.CmmEnsRequestDTO;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO; import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.core.exception.BizRuntimeException; import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.spring.util.ApiSpringUtils; import kr.xit.core.spring.util.ApiSpringUtils;
import kr.xit.core.spring.util.CoreSpringUtils; import kr.xit.core.spring.util.CoreSpringUtils;
import kr.xit.core.support.utils.DateUtils;
import kr.xit.ens.kt.service.IKtMmsService;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.core.env.Environment;
import java.util.Objects;
/** /**
* <pre> * <pre>
@ -34,7 +33,8 @@ import java.util.Objects;
public class CmmKtMmsUtils { public class CmmKtMmsUtils {
private static final EgovMessageSource messageSource = CoreSpringUtils.getMessageSource(); private static final EgovMessageSource messageSource = CoreSpringUtils.getMessageSource();
private static final ICmmEnsCacheService cacheService = ApiSpringUtils.getCmmEnsCacheService(); private static final ICmmEnsCacheService cacheService = ApiSpringUtils.getCmmEnsCacheService();
private static final Environment env = CoreSpringUtils.getEnvironment(); private static final IKtMmsService ktMmsService = ApiSpringUtils.getKtMmsService();
private static final String profile = System.getProperty("spring.profiles.active"); private static final String profile = System.getProperty("spring.profiles.active");
/** /**
@ -42,16 +42,22 @@ public class CmmKtMmsUtils {
* @return * @return
*/ */
public static CmmEnsRlaybsnmDTO getRlaybsnmInfo(final String signguCode, final String ffnlgCode) { public static CmmEnsRlaybsnmDTO getRlaybsnmInfo(final String signguCode, final String ffnlgCode) {
final CmmEnsRlaybsnmDTO dto = cacheService.getRlaybsnmInfoCache( KtMnsRequest ktReqDTO = KtMnsRequest.builder()
CmmEnsRequestDTO.builder()
.signguCode(signguCode) .signguCode(signguCode)
.ffnlgCode(ffnlgCode) .ffnlgCode(ffnlgCode)
.profile(profile) .profile(profile)
.build()); .build();
if(ObjectUtils.isEmpty(dto)) throw BizRuntimeException.create(messageSource.getMessage("fail.api.rlaybsnm.info"));
final CmmEnsRlaybsnmDTO dto = cacheService.getRlaybsnmInfoCache(ktReqDTO);
cacheService.logCache(); cacheService.logCache();
return dto; if(ObjectUtils.isEmpty(dto)) throw BizRuntimeException.create(messageSource.getMessage("fail.api.rlaybsnm.info"));
// 토큰 유효기간 체크
if(DateUtils.getTodayAndNowTime("yyyy-MM-dd HH:mm:ss").compareTo(dto.getKtTokenExpiresIn()) < 0) return dto;
ktMmsService.requestToken(ktReqDTO);
return cacheService.getRlaybsnmInfoCache(ktReqDTO);
} }

@ -1,6 +1,5 @@
package kr.xit.ens.kt.service; package kr.xit.ens.kt.service;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO; import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
@ -149,11 +148,6 @@ public class KtMmsService extends EgovAbstractServiceImpl implements IKtMmsServi
@Value("${contract.kt.api.approve-rcv}") @Value("${contract.kt.api.approve-rcv}")
private String API_APPROVE_RCV; private String API_APPROVE_RCV;
private static final String AUTH_TYPE_BEARER = "Bearer";
private final ApiWebClientUtil webClient; private final ApiWebClientUtil webClient;
/** /**
@ -163,36 +157,24 @@ public class KtMmsService extends EgovAbstractServiceImpl implements IKtMmsServi
public KtTokenResponse requestToken(final KtMnsRequest paramDTO) { public KtTokenResponse requestToken(final KtMnsRequest paramDTO) {
final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(paramDTO.getSignguCode(), paramDTO.getFfnlgCode()); final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(paramDTO.getSignguCode(), paramDTO.getFfnlgCode());
final KtTokenRequest reqDTO = KtTokenRequest.builder() final KtTokenRequest reqDTO = KtTokenRequest.builder()
//.clientId(ktMnsInfo.getKtClientId()) .clientId(ktMnsInfo.getKtSvcClientId())
.clientId(URLEncoder.encode(ktMnsInfo.getKtSvcClientId())) .clientSecret(ktMnsInfo.getKtSvcClientSecret())
.clientSecret(URLEncoder.encode(ktMnsInfo.getKtSvcClientSecret())) .scope(ktMnsInfo.getKtScope())
.scope(URLEncoder.encode(ktMnsInfo.getKtScope()))
.build(); .build();
CmmEnsUtils.validate(reqDTO); CmmEnsUtils.validate(reqDTO);
final Map<String,String> headerMap = new HashMap<>(); final Map<String,String> headerMap = new HashMap<>();
headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
// headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
headerMap.put("client-id", ktMnsInfo.getKtClientId()); headerMap.put("client-id", ktMnsInfo.getKtClientId());
headerMap.put("client-tp", ktMnsInfo.getKtClientTp()); headerMap.put("client-tp", ktMnsInfo.getKtClientTp());
// headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, "access-token"));
return webClient.exchange( return webClient.exchangeFormData(
HOST + API_GENERATE_TOKEN, HOST + API_GENERATE_TOKEN,
HttpMethod.POST, HttpMethod.POST,
JsonUtils.toJson(reqDTO), reqDTO,
KtTokenResponse.class, KtTokenResponse.class,
headerMap headerMap
); );
// return KtTokenResponse.builder()
// .accessToken("eyJhbGciOiJSUzI1NiIsI…")
// .expiresIn("7776000")
// .scope("ag.api")
// .jti("67410d77-0064-4694-9da9..")
// .error("sjj")
// .errorDescription("jjjjjjj")
// .build();
} }
/** /**
@ -204,6 +186,10 @@ public class KtMmsService extends EgovAbstractServiceImpl implements IKtMmsServi
final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode()); final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
//reqDTO.setServiceCd(ktMnsInfo.get); //reqDTO.setServiceCd(ktMnsInfo.get);
//reqDTO.setServiceKey(ktMnsInfo.get); //reqDTO.setServiceKey(ktMnsInfo.get);
reqDTO.setServiceCd(ktMnsInfo.getKtServiceCode());
reqDTO.setSignguCode(null);
reqDTO.setFfnlgCode(null);
reqDTO.setProfile(null);
CmmEnsUtils.validate(reqDTO); CmmEnsUtils.validate(reqDTO);
return webClient.exchangeKt( return webClient.exchangeKt(
@ -230,6 +216,10 @@ public class KtMmsService extends EgovAbstractServiceImpl implements IKtMmsServi
final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode()); final CmmEnsRlaybsnmDTO ktMnsInfo = CmmKtMmsUtils.getRlaybsnmInfo(reqDTO.getSignguCode(), reqDTO.getFfnlgCode());
//reqDTO.setServiceCd(ktMnsInfo.get); //reqDTO.setServiceCd(ktMnsInfo.get);
//reqDTO.setServiceKey(ktMnsInfo.get); //reqDTO.setServiceKey(ktMnsInfo.get);
reqDTO.setServiceCd(ktMnsInfo.getKtServiceCode());
reqDTO.setSignguCode(null);
reqDTO.setFfnlgCode(null);
reqDTO.setProfile(null);
CmmEnsUtils.validate(reqDTO); CmmEnsUtils.validate(reqDTO);
return webClient.exchangeKt( return webClient.exchangeKt(

@ -5,33 +5,35 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import kr.xit.biz.cmm.service.ICmmEnsCacheService; import kr.xit.biz.cmm.service.ICmmEnsCacheService;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdCerfRequest; import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdCerfRequest;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdCerfResponse; import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdCerfResponse;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoRequest;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoResponse;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoCfmRequest; import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoCfmRequest;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoCfmResponse; import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoCfmResponse;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoRequest;
import kr.xit.biz.ens.model.kt.KtAcmdDTO.KtAcmdInfoResponse;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse; import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest; import kr.xit.biz.ens.model.kt.KtCommonDTO.KtMnsRequest;
import kr.xit.biz.ens.model.kt.KtExcaDTO; import kr.xit.biz.ens.model.kt.KtExcaDTO.KtExcaRequest;
import kr.xit.biz.ens.model.kt.KtExcaDTO.KtExcaResponse;
import kr.xit.biz.ens.model.kt.KtInputDTO.KtApproveRcvRequest; import kr.xit.biz.ens.model.kt.KtInputDTO.KtApproveRcvRequest;
import kr.xit.biz.ens.model.kt.KtInputDTO.KtRefuseRcvRequest; import kr.xit.biz.ens.model.kt.KtInputDTO.KtRefuseRcvRequest;
import kr.xit.biz.ens.model.kt.KtMmsDTO; import kr.xit.biz.ens.model.kt.KtMmsDTO;
import kr.xit.biz.ens.model.kt.KtMmsDTO.KtSendSttcRequest;
import kr.xit.biz.ens.model.kt.KtMmsDTO.KtSendSttcDtlRequest;
import kr.xit.biz.ens.model.kt.KtMmsDTO.KtBlacklistRequest; import kr.xit.biz.ens.model.kt.KtMmsDTO.KtBlacklistRequest;
import kr.xit.biz.ens.model.kt.KtMmsDTO.KtSendSttcDtlRequest;
import kr.xit.biz.ens.model.kt.KtMmsDTO.KtSendSttcRequest;
import kr.xit.biz.ens.model.kt.KtMmsDTO.KtWhitelistRequest; import kr.xit.biz.ens.model.kt.KtMmsDTO.KtWhitelistRequest;
import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtMsgRsltRequest;
import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtMainSendRequest;
import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtBefSendRequest; import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtBefSendRequest;
import kr.xit.biz.ens.model.kt.KtExcaDTO.KtExcaRequest; import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtMainSendRequest;
import kr.xit.biz.ens.model.kt.KtExcaDTO.KtExcaResponse; import kr.xit.biz.ens.model.kt.KtMmsSendDTO.KtMsgRsltRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenConfirmRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenExcaRequest; import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenExcaRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenReadRequest; import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenReadRequest;
import kr.xit.biz.ens.model.kt.KtTokenDTO.KtTokenConfirmRequest;
import kr.xit.core.model.ApiResponseDTO; import kr.xit.core.model.ApiResponseDTO;
import kr.xit.ens.kt.service.IKtMmsService; import kr.xit.ens.kt.service.IKtMmsService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; 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;
/** /**
* <pre> * <pre>

@ -103,7 +103,7 @@ public class PplusService extends EgovAbstractServiceImpl implements IPplusServi
// headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, "access-token")); // headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, "access-token"));
return webClient.exchangeFile( return webClient.exchangeFileData(
HOST + ACCEPT, HOST + ACCEPT,
HttpMethod.POST, HttpMethod.POST,
pstFiles, pstFiles,

@ -52,7 +52,7 @@
IF(#{profile} = 'prod', kt_prod_service_cerf_key, kt_dev_service_cerf_key) AS ktSvcCerfKey, /* KT client secret */ IF(#{profile} = 'prod', kt_prod_service_cerf_key, kt_dev_service_cerf_key) AS ktSvcCerfKey, /* KT client secret */
kt_access_token, /* KT access token */ kt_access_token, /* KT access token */
kt_company_cd, /* KT company code */ kt_company_cd, /* KT company code */
DATE_ADD(from_unixtime(kt_token_expires_in, '%Y%m%d%H%i%s'), INTERVAL -1 HOUR) AS ktTokenExpiresIn, /* KT 토큰 유효기간 */ DATE_ADD(NOW(), INTERVAL kt_token_expires_in - 86400 SECOND) AS ktTokenExpiresIn, /* KT 토큰 유효기간 : (7775999)(90일) */
kt_token_jti, /* KT 토큰 식별자 */ kt_token_jti, /* KT 토큰 식별자 */
epost_service_key, /* epost service key */ epost_service_key, /* epost service key */
pplus_api_key, /* postplus api key */ pplus_api_key, /* postplus api key */

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.xit.biz.kt.mapper.IBizKtMmsMapper">
<update id="updateRlaybsnmKtInfo" parameterType="kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO">
/** ens-kt-mysql-mapper|updateRlaybsnmKtInfo-kt token 정보 갱신|julim */
UPDATE tb_ens_rlaybsnm_manage
SET kt_access_token = #{ktAccessToken},
kt_token_expires_in = #{ktTokenExpiresIn},
kt_token_jti = #{ktTokenJti},
kt_scope = #{ktScope},
updt_dt = now(),
updusr = 'api-biz'
WHERE signgu_code = #{signguCode}
AND ffnlg_code = #{ffnlgCode}
</update>
</mapper>

@ -6,3 +6,4 @@ fail.api.nice.revoke.token=\uD1A0\uD070(NICE) \uD3D0\uAE30\uC5D0 \uC2E4\uD328\uD
fail.api.nice.invalid.tranId=NICE \uC778\uC99D \uC694\uCCAD\uC5D0 \uC2E4\uD328\uD558\uC600\uC2B5\uB2C8\uB2E4(TRAN_ID \uBD88\uC77C\uCE58) fail.api.nice.invalid.tranId=NICE \uC778\uC99D \uC694\uCCAD\uC5D0 \uC2E4\uD328\uD558\uC600\uC2B5\uB2C8\uB2E4(TRAN_ID \uBD88\uC77C\uCE58)
fail.api.rlaybsnm.info=\uBB38\uC11C\uC911\uACC4\uC790 \uC778\uC99D \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. fail.api.rlaybsnm.info=\uBB38\uC11C\uC911\uACC4\uC790 \uC778\uC99D \uC815\uBCF4\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.
fail.api.kt.token.request=KT \uD1A0\uD070 \uC694\uCCAD\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4.

@ -38,6 +38,10 @@ public class CmmEnsRlaybsnmDTO extends AuditFields implements Serializable {
* *
*/ */
private String ffnlgCode; private String ffnlgCode;
/**
* profile
*/
private String profile;
/** /**
* *
*/ */

@ -11,6 +11,7 @@ import javax.validation.Valid;
import javax.validation.constraints.Digits; import javax.validation.constraints.Digits;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse; import kr.xit.biz.ens.model.kt.KtCommonDTO.KtCommonResponse;
import kr.xit.core.support.utils.DateUtils;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;
@ -87,7 +88,7 @@ public class KtMmsSendDTO {
* Mapping * Mapping
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "문서코드", example = "10006") @Schema(requiredMode = RequiredMode.REQUIRED, title = "문서코드", example = "DP112")
@Size(min = 5, max = 5, message = "문서 코드는 필수 입니다(max:5)") @Size(min = 5, max = 5, message = "문서 코드는 필수 입니다(max:5)")
private String msgCd; private String msgCd;
@ -401,7 +402,7 @@ public class KtMmsSendDTO {
* Mapping * Mapping
* </pre> * </pre>
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "문서코드", example = "10006") @Schema(requiredMode = RequiredMode.REQUIRED, title = "문서코드", example = "DP112")
@Size(min = 5, max = 5, message = "문서 코드는 필수 입니다(max:5)") @Size(min = 5, max = 5, message = "문서 코드는 필수 입니다(max:5)")
private String msgCd; private String msgCd;
@ -934,7 +935,7 @@ public class KtMmsSendDTO {
*/ */
@Schema(requiredMode = RequiredMode.REQUIRED, title = "발송타임스탬프", example = " ") @Schema(requiredMode = RequiredMode.REQUIRED, title = "발송타임스탬프", example = " ")
@Size(min = 14, max = 14, message = "발송타임스탬프는 필수 입니다(YYYYMMDDHHMISS)") @Size(min = 14, max = 14, message = "발송타임스탬프는 필수 입니다(YYYYMMDDHHMISS)")
private String mmsSndgTmst; private final String mmsSndgTmst = DateUtils.getTodayAndNowTime("yyyyMMddHHmmss");
/** /**
* <pre> * <pre>

@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector;
@ -71,6 +72,7 @@ public class WebClientConfig {
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY); factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY);
return WebClient.builder() return WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.uriBuilderFactory(factory) .uriBuilderFactory(factory)
.clientConnector(new ReactorClientHttpConnector(defaultHttpClient())) .clientConnector(new ReactorClientHttpConnector(defaultHttpClient()))
.codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(2 * 1024 * 1024)) .codecs(configurer -> configurer.defaultCodecs().maxInMemorySize(2 * 1024 * 1024))
@ -148,7 +150,7 @@ public class WebClientConfig {
/** /**
* reponse logging && error Handling * reponse logging && error Handling
* @return * @return ExchangeFilterFunction
*/ */
private ExchangeFilterFunction responseFilter() { private ExchangeFilterFunction responseFilter() {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> { return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {

@ -7,31 +7,28 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO; import kr.xit.biz.ens.model.cmm.CmmEnsRlaybsnmDTO;
import kr.xit.core.consts.Constants; import kr.xit.core.consts.Constants;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.model.ApiResponseDTO; import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.spring.config.support.WebClientConfig; import kr.xit.core.spring.config.support.WebClientConfig;
import kr.xit.core.spring.util.error.ClientError; import kr.xit.core.spring.util.error.ClientError;
import kr.xit.core.spring.util.error.ErrorParse; import kr.xit.core.spring.util.error.ErrorParse;
import kr.xit.core.spring.util.error.ServerError; import kr.xit.core.spring.util.error.ServerError;
import kr.xit.core.support.utils.JsonUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.client.MultipartBodyBuilder; import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;
/** /**
* <pre> * <pre>
* description : react Restfull Util * description : react Restfull Util
* * error(.onStatus) ExchangeFilterFunction {@link WebClientConfig#responseFilter responseFilter}
* packageName : kr.xit.core.spring.util * packageName : kr.xit.core.spring.util
* fileName : ApiWebClientUtil * fileName : ApiWebClientUtil
* author : julim * author : julim
@ -42,6 +39,7 @@ import reactor.core.publisher.Mono;
* 2023-09-06 julim * 2023-09-06 julim
* *
* </pre> * </pre>
* @see WebClientConfig
* @see kr.xit.core.spring.config.AsyncExecutorConfig * @see kr.xit.core.spring.config.AsyncExecutorConfig
* @see ClientError * @see ClientError
* @see ServerError * @see ServerError
@ -52,44 +50,63 @@ import reactor.core.publisher.Mono;
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
public class ApiWebClientUtil { public class ApiWebClientUtil {
private static final String AUTH_TYPE_BEARER = "Bearer"; private static final String AUTH_TYPE_BEARER = "bearer";
private final WebClientConfig webClientConfig; private final WebClientConfig webClientConfig;
private enum EnsDIV{ /**
KKO, * WebClient GET
KT, * (.onStatus status.is4xxClientError() || status.is5xxServerError())
PPLUS * -> {@link WebClientConfig#responseFilter responseFilter}
}; * @param url
* @param responseDtoClass
* @param headerMap
* @return responseDtoClass
*/
public <T> T get(final String url, final Class<T> responseDtoClass, Map<String, String> headerMap) { public <T> T get(final String url, final Class<T> responseDtoClass, Map<String, String> headerMap) {
return webClientConfig.webClient().method(HttpMethod.GET) return webClientConfig.webClient()
.method(HttpMethod.GET)
.uri(url) .uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap)) .headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.retrieve() .retrieve()
.onStatus(
status -> status.is4xxClientError() || status.is5xxServerError(),
res -> res.bodyToMono(String.class).map(BizRuntimeException::create))
.bodyToMono(responseDtoClass) .bodyToMono(responseDtoClass)
.block(); .block();
} }
/**
* WebClient POST
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig#responseFilter responseFilter}
* @param url
* @param requestDto
* @param responseDtoClass
* @param headerMap
* @return responseDtoClass
*/
public <T, V> T post(final String url, final V requestDto, final Class<T> responseDtoClass, Map<String, String> headerMap) { public <T, V> T post(final String url, final V requestDto, final Class<T> responseDtoClass, Map<String, String> headerMap) {
return webClientConfig.webClient().method(HttpMethod.POST) return webClientConfig.webClient()
.method(HttpMethod.POST)
.uri(url) .uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap)) .headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.bodyValue(Objects.requireNonNullElse(requestDto, "")) .bodyValue(Objects.requireNonNullElse(requestDto, ""))
.retrieve() .retrieve()
.onStatus(
status -> status.is4xxClientError() || status.is5xxServerError(),
res -> res.bodyToMono(String.class).map(BizRuntimeException::create))
.bodyToMono(responseDtoClass) .bodyToMono(responseDtoClass)
.block(); .block();
} }
/**
* kakao WebClient
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig#responseFilter responseFilter}
* @param url
* @param method
* @param body
* @param rtnClzz
* @param ensDTO CmmEnsRlaybsnmDTO
* @return rtnClzz
*/
public <T> T exchangeKko(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) { public <T> T exchangeKko(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
map.put(HttpHeaders.AUTHORIZATION, map.put(HttpHeaders.AUTHORIZATION,
String.format("%s %s", Constants.JwtToken.GRANT_TYPE.getCode(), ensDTO.getKakaoAccessToken())); String.format("%s %s", Constants.JwtToken.GRANT_TYPE.getCode(), ensDTO.getKakaoAccessToken()));
map.put(Constants.HeaderName.UUID.getCode(), ensDTO.getKakaoContractUuid()); map.put(Constants.HeaderName.UUID.getCode(), ensDTO.getKakaoContractUuid());
@ -99,17 +116,19 @@ public class ApiWebClientUtil {
public <T> T exchangeKt(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) { public <T> T exchangeKt(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final CmmEnsRlaybsnmDTO ensDTO) {
final Map<String,String> headerMap = new HashMap<>(); final Map<String,String> headerMap = new HashMap<>();
headerMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, ensDTO.getKtAccessToken())); headerMap.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, ensDTO.getKtAccessToken()));
headerMap.put("client-id", ensDTO.getKtClientId()); headerMap.put("client-id", ensDTO.getKtClientId());
headerMap.put("client-tp", "10"); headerMap.put("client-tp", ensDTO.getKtClientTp());
return exchange(url, method, body, rtnClzz, headerMap); return exchange(url, method, body, rtnClzz, headerMap);
} }
/** /**
* <pre> * <pre>
* Async call - Response Entity() * WebClient
* GET url (?key=value&key2=value2)
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig#responseFilter responseFilter}
* @param url call url * @param url call url
* @param method POST|GET * @param method POST|GET
* @param body JSON String type * @param body JSON String type
@ -125,26 +144,51 @@ public class ApiWebClientUtil {
.uri(url) .uri(url)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap)) .headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.bodyValue(Objects.requireNonNullElse(body, "")) .bodyValue(Objects.requireNonNullElse(body, ""))
.exchangeToMono(res -> res.bodyToMono(rtnClzz) .exchangeToMono(res -> res.bodyToMono(rtnClzz))
.map(dto -> { .block();
if (res.statusCode().is2xxSuccessful()) {
log.info("API 요청에 성공했습니다.");
return dto;
} }
if (res.statusCode().is4xxClientError()) { /**
log.error("API 요청 중 4xx 에러가 발생했습니다. 요청 데이터를 확인해주세요."); * <pre>
throw BizRuntimeException.create(String.format("4xx 외부 요청 오류. statusCode: %s, response: %s, header: %s", res.rawStatusCode(), res.bodyToMono(String.class), res.headers().asHttpHeaders())); * WebClient form data
} * -> application/x-www-form-urlencoded
* GET url (?key=value&key2=value2)
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig#responseFilter responseFilter}
* @param url call url
* @param method POST|GET
* @param body JSON String type
* @param rtnClzz rtnClzz return type class
* (ex: new KkopayDocDTO.DocStatusResponse().getClass())
* @return T rtnClzz return DTO
* </pre>
*/
public <T> T exchangeFormData(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final Map<String,String> headerMap) {
log.error("API 요청 중 Tree 서버에서 5xx 에러가 발생했습니다."); return webClientConfig.webClient()
throw BizRuntimeException.create(String.format("5xx 외부 시스템 오류. %s", res.bodyToMono(String.class))); .method(method)
}) .uri(url)
) .headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.body(BodyInserters.fromFormData(JsonUtils.toMultiValue(body)))
.exchangeToMono(res -> res.bodyToMono(rtnClzz))
.block(); .block();
} }
public <T> T exchangeFile(final String url, final HttpMethod method, final List<MultipartFile> files, final String uploadFileName, final Class<T> rtnClzz, final Map<String,String> headerMap) { /**
* webclient file data
* -> multipart/form-data
* GET url (?key=value&key2=value2)
* (.onStatus status.is4xxClientError() || status.is5xxServerError())
* -> {@link WebClientConfig#responseFilter responseFilter}
* @param url
* @param method
* @param files
* @param uploadFileName
* @param rtnClzz
* @param headerMap
* @return rtnClzz
*/
public <T> T exchangeFileData(final String url, final HttpMethod method, final List<MultipartFile> files, final String uploadFileName, final Class<T> rtnClzz, final Map<String,String> headerMap) {
MultipartBodyBuilder builder = new MultipartBodyBuilder(); MultipartBodyBuilder builder = new MultipartBodyBuilder();
for(MultipartFile mf : files) { for(MultipartFile mf : files) {
builder.part(mf.getOriginalFilename(), mf.getResource()); builder.part(mf.getOriginalFilename(), mf.getResource());
@ -156,78 +200,14 @@ public class ApiWebClientUtil {
.contentType(MediaType.MULTIPART_FORM_DATA) .contentType(MediaType.MULTIPART_FORM_DATA)
.headers(httpHeaders -> getHeaders(httpHeaders, headerMap)) .headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
.body(BodyInserters.fromMultipartData(builder.build())) .body(BodyInserters.fromMultipartData(builder.build()))
.exchangeToMono(res -> res.bodyToMono(rtnClzz) .exchangeToMono(res -> res.bodyToMono(rtnClzz))
.map(dto -> {
if (res.statusCode().is2xxSuccessful()) {
log.info("API 요청에 성공했습니다.");
return dto;
}
if (res.statusCode().is4xxClientError()) {
log.error("API 요청 중 4xx 에러가 발생했습니다. 요청 데이터를 확인해주세요.");
throw BizRuntimeException.create(String.format("4xx 외부 요청 오류. statusCode: %s, response: %s, header: %s", res.rawStatusCode(), res.bodyToMono(String.class), res.headers().asHttpHeaders()));
}
log.error("API 요청 중 Tree 서버에서 5xx 에러가 발생했습니다.");
throw BizRuntimeException.create(String.format("5xx 외부 시스템 오류. %s", res.bodyToMono(String.class)));
})
)
.block(); .block();
} }
// public <T> T exchange(final String url, final HttpMethod method, final Object body, final Class<T> rtnClzz, final Map<String,String> headerMap) {
//
// return webClientConfig.webClient()
// .method(method)
// .uri(url)
// .headers(httpHeaders -> getHeaders(httpHeaders, headerMap))
// .bodyValue(Objects.requireNonNullElse(body, ""))
// .exchangeToMono(res -> res.bodyToMono(rtnClzz)
// .map(dto -> {
// if (res.statusCode().is2xxSuccessful()) {
// log.info("API 요청에 성공했습니다.");
// return dto;
// }
//
// if (res.statusCode().is4xxClientError()) {
// log.error("API 요청 중 4xx 에러가 발생했습니다. 요청 데이터를 확인해주세요.");
// throw BizRuntimeException.create(String.format("4xx 외부 요청 오류. statusCode: %s, response: %s, header: %s", res.rawStatusCode(), res.bodyToMono(String.class), res.headers().asHttpHeaders()));
// }
//
// log.error("API 요청 중 Tree 서버에서 5xx 에러가 발생했습니다.");
// throw BizRuntimeException.create(String.format("5xx 외부 시스템 오류. %s", res.bodyToMono(String.class)));
// })
// )
// .block();
// }
public <T> ApiResponseDTO<T> sendError(final Throwable e) { public <T> ApiResponseDTO<T> sendError(final Throwable e) {
return ErrorParse.extractError(e.getCause()); return ErrorParse.extractError(e.getCause());
} }
// private Map<String,String> getHeaderMap(final EnsDIV ensDIV, final CmmEnsRlaybsnmDTO ensDTO){
// Map<String, String> map = new HashMap<>();
//
// switch(ensDIV){
// case KKO:
// map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
// map.put(HttpHeaders.AUTHORIZATION,
// String.format("%s %s", Constants.JwtToken.GRANT_TYPE.getCode(), ensDTO.getKakaoAccessToken()));
// map.put(Constants.HeaderName.UUID.getCode(), ensDTO.getKakaoContractUuid());
// break;
// case KT:
// map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
// map.put(HttpHeaders.AUTHORIZATION, String.format("%s %s", AUTH_TYPE_BEARER, ensDTO.getKtAccessToken()));
// map.put("client-id", ensDTO.getKtClientId());
// map.put("client-tp", "10");
// break;
// default:
// throw BizRuntimeException.create("서비스 불가한 문서중계자 입니다");
// }
// return map;
// }
private URI createUrl(final String endPoint, final String... value) { private URI createUrl(final String endPoint, final String... value) {
return UriComponentsBuilder.fromUriString(endPoint) return UriComponentsBuilder.fromUriString(endPoint)
.build(value); .build(value);
@ -240,21 +220,4 @@ public class ApiWebClientUtil {
} }
return headers; return headers;
} }
private ExchangeFilterFunction errorHandler() {
return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> {
HttpStatus status = clientResponse.statusCode();
if (clientResponse.statusCode().is4xxClientError()) {
return clientResponse.bodyToMono(String.class)
.flatMap(errorBody -> Mono.error(new ClientError(status, errorBody)));
} else if (clientResponse.statusCode().is5xxServerError()) {
return clientResponse.bodyToMono(String.class)
.flatMap(errorBody -> Mono.error(new ServerError(status, errorBody)));
}
return Mono.just(clientResponse);
});
}
} }

@ -13,6 +13,8 @@ import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
/** /**
@ -123,6 +125,23 @@ public class JsonUtils {
} }
} }
/**
* Object key value
* -> key, value JSONObject return
* @param obj key, value Object
* @param keyName key JSON key name
* @param valueName value JSON key name
* @return JSONObject key, value JSONObject
*/
public static MultiValueMap<String, String> toMultiValue(final Object obj){
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
JSONObject jsonObj = toObjByObj(obj, JSONObject.class);
for (Object key : jsonObj.keySet()) {
formData.add((String) key, (String) jsonObj.get(key));
}
return formData;
}
/** /**
* Object key value * Object key value
* -> key, value JSONObject return * -> key, value JSONObject return

Loading…
Cancel
Save