feat: NICE CI accept 진행

BillHistory save 반영
dev
Jonguk. Lim 1 month ago
parent 6d524ddecb
commit f02f92aede

@ -177,3 +177,9 @@ Insert into ENS_BILL_HIS
Values Values
(40336145, TO_TIMESTAMP('2024/10/02 PM 4:45:05.331000','YYYY/MM/DD AM fmHH12fm:MI:SS.FF'), TO_TIMESTAMP('2024/10/02 PM 4:45:05.331000','YYYY/MM/DD AM fmHH12fm:MI:SS.FF'), 'bpKko', 'intgrnNoti-1727843102-fn.x8QpG4JnaBd6psESO6l', (40336145, TO_TIMESTAMP('2024/10/02 PM 4:45:05.331000','YYYY/MM/DD AM fmHH12fm:MI:SS.FF'), TO_TIMESTAMP('2024/10/02 PM 4:45:05.331000','YYYY/MM/DD AM fmHH12fm:MI:SS.FF'), 'bpKko', 'intgrnNoti-1727843102-fn.x8QpG4JnaBd6psESO6l',
'EL3020202408060407773', 'VD_URL', '{"data":{"biller_user_key":"EL3020202408060407773","expire_at":"20241010235900","parameters":{"orgCd":"0001"},"custom_url":{"notice_url":"https://phts-manager.koti.re.kr/iup/kakao/notice","prepay_url":"https://phts-manager.koti.re.kr/iup/kakao/prepay","pay_result_url":"https://phts-manager.koti.re.kr/iup/kakao/pay-result"}}}', '{"res_code":"OK","message":"정상응답","data":{"url":"https://billgates-web.kakao.com/r/platform/pages/paynow/search/1832/11/1a481760-b0da-4a77-9a7a-74951db5fa01"}}', '0001'); 'EL3020202408060407773', 'VD_URL', '{"data":{"biller_user_key":"EL3020202408060407773","expire_at":"20241010235900","parameters":{"orgCd":"0001"},"custom_url":{"notice_url":"https://phts-manager.koti.re.kr/iup/kakao/notice","prepay_url":"https://phts-manager.koti.re.kr/iup/kakao/prepay","pay_result_url":"https://phts-manager.koti.re.kr/iup/kakao/pay-result"}}}', '{"res_code":"OK","message":"정상응답","data":{"url":"https://billgates-web.kakao.com/r/platform/pages/paynow/search/1832/11/1a481760-b0da-4a77-9a7a-74951db5fa01"}}', '0001');
select nvl(max(id), 0) + 1
from IUP.ENS_BILL_HIS
where id = 99999999999999999999

@ -0,0 +1,25 @@
package cokr.xit.ens.modules.nice.mapper;
import org.apache.ibatis.annotations.*;
import cokr.xit.ens.modules.nice.model.*;
/**
* <pre>
* description :
* packageName : cokr.xit.ens.modules.nice.mapper
* fileName : INiceMapper
* author : limju
* date : 2024 9 30
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024 9 30 limju
*
* </pre>
*/
@Mapper
public interface INiceCiBillHistoryMapper {
int insertBillHistory(final NiceCiDTO.BillHistDTO billHistDTO);
int updateBillHistory(final NiceCiDTO.BillHistDTO billHistDTO);
}

@ -4,9 +4,9 @@ import java.time.*;
import java.util.*; import java.util.*;
import cokr.xit.ens.biz.iup.code.*; import cokr.xit.ens.biz.iup.code.*;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.code.*;
import io.swagger.v3.oas.annotations.media.*; import io.swagger.v3.oas.annotations.media.*;
import lombok.*; import lombok.*;
import lombok.experimental.*;
/** /**
* <pre> * <pre>
@ -27,8 +27,7 @@ public class NiceCiDTO {
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@SuperBuilder @Builder
@EqualsAndHashCode(callSuper = false)
public static class NiceCiParam { public static class NiceCiParam {
/** /**
* *
@ -112,8 +111,7 @@ public class NiceCiDTO {
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@SuperBuilder @Builder
@EqualsAndHashCode(callSuper = false)
public static class InputXit { public static class InputXit {
/** /**
* *
@ -182,8 +180,7 @@ public class NiceCiDTO {
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@SuperBuilder @Builder
@EqualsAndHashCode(callSuper = false)
public static class InputDataXit { public static class InputDataXit {
private String dataId; private String dataId;
private Long lnkInputId; private Long lnkInputId;
@ -222,7 +219,7 @@ public class NiceCiDTO {
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@SuperBuilder @Builder
public static class BillDTO { public static class BillDTO {
private Long billId; private Long billId;
@ -271,7 +268,7 @@ public class NiceCiDTO {
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@SuperBuilder @Builder
public static class BillKkoDTO { public static class BillKkoDTO {
private Long billId; private Long billId;
private String billUid; private String billUid;
@ -387,4 +384,48 @@ public class NiceCiDTO {
} }
@Schema(name = "BillHistDTO DTO", description = "BillHistDTO DTO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public static class BillHistDTO {
private Long id;
/**
*
*/
private String billUid;
/**
* : - "bpKko"
*/
@Builder.Default
private String billSe = BillSeCd.bpKko.getCode();
/**
* : - "VD_URL"
*/
@Builder.Default
private String reqSe = BillReqSeCd.VD_URL.getCode();
/**
*
*/
private String orgCd;
/**
*
*/
private String linkedUuid;
private String requestData;
private String responseData;
private String errorCode;
private String errorMessage;
}
} }

@ -15,6 +15,7 @@ import cokr.xit.ens.core.exception.*;
import cokr.xit.ens.core.exception.code.*; import cokr.xit.ens.core.exception.code.*;
import cokr.xit.ens.core.utils.*; import cokr.xit.ens.core.utils.*;
import cokr.xit.ens.modules.common.code.*; import cokr.xit.ens.modules.common.code.*;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.model.*;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.service.process.model.*; import cokr.xit.ens.modules.common.ctgy.intgrnbill.kko.service.process.model.*;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.api.*; import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.api.*;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.code.*; import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.code.*;
@ -22,7 +23,6 @@ import cokr.xit.ens.modules.common.ctgy.sys.mng.domain.*;
import cokr.xit.ens.modules.common.ctgy.sys.mng.service.*; import cokr.xit.ens.modules.common.ctgy.sys.mng.service.*;
import cokr.xit.ens.modules.nice.mapper.*; import cokr.xit.ens.modules.nice.mapper.*;
import cokr.xit.ens.modules.nice.model.*; import cokr.xit.ens.modules.nice.model.*;
import cokr.xit.ens.modules.nice.service.support.*;
import lombok.*; import lombok.*;
import lombok.extern.slf4j.*; import lombok.extern.slf4j.*;
@ -54,7 +54,8 @@ public class NiceCiAcceptService {
private String BILL_PAYREUSLT_URL; private String BILL_PAYREUSLT_URL;
private final KeySequenceService keySequenceService; private final KeySequenceService keySequenceService;
private final NiceCiApiService niceCiApiService; private final NiceCiBillHistoryService billHistoryService;
private final INiceCiMapper niceCiMapper; private final INiceCiMapper niceCiMapper;
private final PayUseSysApi payUseSysApi; private final PayUseSysApi payUseSysApi;
@ -102,26 +103,34 @@ public class NiceCiAcceptService {
//List<NiceCiDTO.BillDTO> bills = new ArrayList<>(); //List<NiceCiDTO.BillDTO> bills = new ArrayList<>();
//List<NiceCiDTO.BillKkoDTO> billKkos = new ArrayList<>(); //List<NiceCiDTO.BillKkoDTO> billKkos = new ArrayList<>();
final String prefixBillUid = PostSeCd.intgrnNoti.getCode() + "-" + IdGenerator.getCurrentTimeSec(); final String prefixBillUid = PostSeCd.intgrnNoti.getCode() + "-" + IdGenerator.getCurrentTimeSec();
final String customUrl = gson.toJson(CustomUrl.builder()
.noticeUrl(BILL_HOST + BILL_NOTICE_URL)
.prepayUrl(BILL_HOST + BILL_PREPAY_URL)
.payResultUrl(BILL_HOST + BILL_PAYREUSLT_URL)
.build());
final String expireAt = DateUtil.getTodayAndNowTime("YYYYMMddHHmmss"); final String expireAt = DateUtil.getTodayAndNowTime("YYYYMMddHHmmss");
final KkoPayUrlRespData kkoPayUrlRespData = KkoPayUrlRespData.builder()
.customUrl(CustomUrl.builder()
.noticeUrl(BILL_HOST + BILL_NOTICE_URL)
.prepayUrl(BILL_HOST + BILL_PREPAY_URL)
.payResultUrl(BILL_HOST + BILL_PAYREUSLT_URL)
.build())
.expireAt(expireAt)
.build();
final OrgMng orgMng = niceCiMapper.selectKkoBpApiUrlFromEnsOrgMng(list.get(0).getOrgCd()) final OrgMng orgMng = niceCiMapper.selectKkoBpApiUrlFromEnsOrgMng(list.get(0).getOrgCd())
.orElseThrow(() -> new EnsException(EnsErrCd.NO_DATA_FOUND, EnsErrCd.NO_DATA_FOUND.getCodeNm())); .orElseThrow(() -> new EnsException(EnsErrCd.NO_DATA_FOUND, EnsErrCd.NO_DATA_FOUND.getCodeNm()));
for(NiceCiDTO.InputXit xit : list){ for(NiceCiDTO.InputXit xit : list){
NiceCiDTO.BillHistDTO billHistDTO = null;
try { try {
List<NiceCiDTO.InputDataXit> inputDataXits = xit.getInputDataXits(); List<NiceCiDTO.InputDataXit> inputDataXits = xit.getInputDataXits();
for (NiceCiDTO.InputDataXit data : inputDataXits) { for (NiceCiDTO.InputDataXit data : inputDataXits) {
BillKkoApiRespDTO<?> respDTO = getPayUrl(xit, data, billHistDTO, orgMng, kkoPayUrlRespData);
String payUrl = getPayUrl(data, orgMng); data.setPayUrl(String.valueOf(respDTO.getData()));
data.setPayUrl(payUrl);
niceCiMapper.updatePayUrlOfDataInput(data); niceCiMapper.updatePayUrlOfDataInput(data);
final String billUid = IdGenerator.getShortUUID(prefixBillUid); final String billUid = IdGenerator.getShortUUID(prefixBillUid);
// FIXME: API 호출 결과 로그 저장
billHistDTO.setBillUid(billUid);
billHistDTO.setResponseData(String.valueOf(respDTO.getData()));
billHistoryService.updateBillHistory(billHistDTO);
// FIXME: bill_se_cd, org_cd 설정 및 확인 필요??? // FIXME: bill_se_cd, org_cd 설정 및 확인 필요???
niceCiMapper.insertBill( niceCiMapper.insertBill(
@ -139,7 +148,7 @@ public class NiceCiAcceptService {
.billId(keySequenceService.getKeySequence("BillKko_id")) .billId(keySequenceService.getKeySequence("BillKko_id"))
.billerUserKey(data.getDataId()) .billerUserKey(data.getDataId())
.billerNoticeKey(billUid) .billerNoticeKey(billUid)
.customUrl(customUrl) .customUrl(gson.toJson(kkoPayUrlRespData.getCustomUrl()))
.expireAt(expireAt) //d.getExpiresDt() .expireAt(expireAt) //d.getExpiresDt()
.billUid(billUid) .billUid(billUid)
.build() .build()
@ -156,7 +165,7 @@ public class NiceCiAcceptService {
if(EnsErrCd.API_COMM_ERROR.equals(e.getErrCd())){ if(EnsErrCd.API_COMM_ERROR.equals(e.getErrCd())){
xit.setPrcsCd(IupPrcsCd.TGRF.getCode()); xit.setPrcsCd(IupPrcsCd.TGRF.getCode());
niceCiMapper.updatePrcsCdOfInputXit(xit); niceCiMapper.updatePrcsCdOfInputXit(xit);
}; }
} catch (Exception e){ } catch (Exception e){
xit.setPrcsCd(IupPrcsCd.TGRF.getCode()); xit.setPrcsCd(IupPrcsCd.TGRF.getCode());
@ -180,24 +189,38 @@ public class NiceCiAcceptService {
* @param orgMng * @param orgMng
* @return * @return
*/ */
private String getPayUrl(final NiceCiDTO.InputDataXit data, final OrgMng orgMng){ private BillKkoApiRespDTO<?> getPayUrl(final NiceCiDTO.InputXit xitData, final NiceCiDTO.InputDataXit dataXit, NiceCiDTO.BillHistDTO billHistDTO, final OrgMng orgMng, final KkoPayUrlRespData kkoPayUrlRespData){
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("billerUserKey", data.getDataId()); map.put("biller_user_key", dataXit.getDataId());
map.put("expire_at", kkoPayUrlRespData.getExpireAt());
map.put("custom_url", gson.toJsonTree(kkoPayUrlRespData.getCustomUrl()));
Map<String, Object> param = new HashMap<>(); Map<String, Object> param = new HashMap<>();
param.put("data", map); param.put("data", map);
// FIXME: API 호출 로그 저장
billHistDTO = NiceCiDTO.BillHistDTO.builder()
.linkedUuid(dataXit.getDataId())
.orgCd(orgMng.getOrgCd())
.requestData(gson.toJson(param))
.build();
billHistoryService.insertBillHistory(billHistDTO);
ResponseEntity<String> resEntity = payUseSysApi.payUrl(orgMng.getKkoBpUrlApi(), param, ResponseEntity<String> resEntity = payUseSysApi.payUrl(orgMng.getKkoBpUrlApi(), param,
null); null);
// 마스터 상태 실패처리 // 마스터 상태 실패처리
if(resEntity.getStatusCode() != HttpStatus.OK){ if(resEntity.getStatusCode() != HttpStatus.OK){
billHistDTO.setErrorCode(resEntity.getStatusCode().toString());
//billHistDTO.setErrorCode(EnsErrCd.API_COMM_ERROR.getCode());
billHistDTO.setErrorMessage(resEntity.getBody());
billHistoryService.updateBillHistory(billHistDTO);
throw new EnsException(EnsErrCd.API_COMM_ERROR, EnsErrCd.API_COMM_ERROR.getCodeNm()); throw new EnsException(EnsErrCd.API_COMM_ERROR, EnsErrCd.API_COMM_ERROR.getCodeNm());
} }
String rsltStr = resEntity.getBody(); String rsltStr = resEntity.getBody();
log.info(rsltStr); return BillKkoApiRespDTO.okBuilder()
//try { .data(resEntity.getBody())
Map<String, Object> m = gson.fromJson(rsltStr, Map.class); .build();
log.info("{}", m);
return "";
} }
} }

@ -0,0 +1,40 @@
package cokr.xit.ens.modules.nice.service;
import org.springframework.stereotype.*;
import org.springframework.transaction.annotation.*;
import cokr.xit.ens.modules.nice.mapper.*;
import cokr.xit.ens.modules.nice.model.*;
import lombok.*;
import lombok.extern.slf4j.*;
/**
* <pre>
* description :
* packageName : cokr.xit.ens.modules.nice.service
* fileName : NiceCiBillHistoryService
* author : limju
* date : 2024 9 27
* ======================================================================
*
* ----------------------------------------------------------------------
* 2024 9 27 limju
*
* </pre>
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class NiceCiBillHistoryService {
private final INiceCiBillHistoryMapper mapper;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void insertBillHistory(final NiceCiDTO.BillHistDTO histDTO){
mapper.insertBillHistory(histDTO);
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateBillHistory(final NiceCiDTO.BillHistDTO histDTO){
mapper.updateBillHistory(histDTO);
}
}

@ -0,0 +1,41 @@
<?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="cokr.xit.ens.modules.nice.mapper.INiceCiBillHistoryMapper">
<insert id="insertBillHistory" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$BillHistDTO">
/** iup-niceci-bill-history-mapper|insertBillHistory-Bill API(NICE CI) call history save|julim */
<selectKey keyProperty="id" resultType="long" order="BEFORE">
SELECT NVL(MAX(id), 0) + 1
FROM ens_bill_his
</selectKey>
INSERT INTO ens_bill_his (
id,
linked_uuid,
org_cd,
req_se,
bill_se,
request_data,
regist_dt
) VALUES (
#{id},
#{linkedUuid},
#{orgCd},
#{reqSe},
#{billSe},
#{requestData},
sysdate
)
</insert>
<update id="updateBillHistory" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$BillHistDTO">
/** iup-niceci-bill-history-mapper|updateBillHistory-Bill API(NICE CI) call history save|julim */
UPDATE ens_bill_his
SET bill_uid = #{billUid}
, response_data = #{responseData}
, error_code = #{errorCode}
, error_message = #{errorMessage}
, last_updt_dt = sysdate
WHERE id = #{id}
</update>
</mapper>

@ -85,47 +85,48 @@
<!--// FIXME: NICE CI INSERT UPDATE 항목 확인 적용 필요 --> <!--// FIXME: NICE CI INSERT UPDATE 항목 확인 적용 필요 -->
<insert id="saveBillKko" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$BillKkoDTO"> <insert id="saveBillKko" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$BillKkoDTO">
/** iup-niceci-mapper|saveBill-NICE CI 청구서 생성|julim */ /** iup-niceci-mapper|saveBill-NICE CI 청구서 생성|julim */
MERGE INTO ens_bill_kko MERGE
USING DUAL INTO ens_bill_kko
ON (bill_id = #{billId}) USING DUAL
WHEN MATCHED THEN ON (bill_id = #{billId})
UPDATE WHEN MATCHED THEN
SET amount = #{amount} UPDATE
, details = #{details} SET amount = #{amount}
, url = #{url} , details = #{details}
, title = #{title} , url = #{url}
, expire_type = #{expireType} , title = #{title}
, pay_expire_date = #{payExpireDate} , expire_type = #{expireType}
, second_pay_expire_date = #{secondPayExpireDate} , pay_expire_date = #{payExpireDate}
, billed_year_month = #{billedYearMonth} , second_pay_expire_date = #{secondPayExpireDate}
, ordinal = #{ordinal} , billed_year_month = #{billedYearMonth}
, parameters = #{parameters} , ordinal = #{ordinal}
, bank_accounts = #{bankAccounts} , parameters = #{parameters}
, tax_free_amount = #{taxFreeAmount} , bank_accounts = #{bankAccounts}
, vat_amount = #{vatAmount} , tax_free_amount = #{taxFreeAmount}
, last_paid_at = TO_CHAR(sysdate, 'YYYYMMDDHH24MISS') , vat_amount = #{vatAmount}
, last_pay_id = #{lastPayId} , last_paid_at = TO_CHAR(sysdate, 'YYYYMMDDHH24MISS')
, error_code = #{errorCode} , last_pay_id = #{lastPayId}
, error_message = #{errorMessage} , error_code = #{errorCode}
, last_updt_dt = sysdate , error_message = #{errorMessage}
WHEN NOT MATCHED THEN , last_updt_dt = sysdate
INSERT ( WHEN NOT MATCHED THEN
bill_id, INSERT (
bill_uid, bill_id,
biller_user_key, bill_uid,
biller_notice_key, biller_user_key,
custom_url, biller_notice_key,
expire_at, custom_url,
regist_dt expire_at,
) VALUES ( regist_dt
#{billId} ) VALUES (
, #{billUid} #{billId}
, #{billerUserKey} , #{billUid}
, #{billerNoticeKey} , #{billerUserKey}
, #{customUrl} , #{billerNoticeKey}
, #{expireAt} , #{customUrl}
, sysdate , #{expireAt}
) , sysdate
)
</insert> </insert>
<!-- <!--
amount, amount,
@ -147,6 +148,7 @@
error_message, error_message,
last_updt_dt last_updt_dt
--> -->
<update id="updatePayUrlOfDataInput" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$InputDataXit"> <update id="updatePayUrlOfDataInput" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$InputDataXit">
/** iup-niceci-mapper|updatePayUrlOfDataInput-payUrl update|julim */ /** iup-niceci-mapper|updatePayUrlOfDataInput-payUrl update|julim */
UPDATE tb_input_data_xit UPDATE tb_input_data_xit

Loading…
Cancel
Save