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
(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');
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 cokr.xit.ens.biz.iup.code.*;
import cokr.xit.ens.modules.common.ctgy.intgrnbill.support.code.*;
import io.swagger.v3.oas.annotations.media.*;
import lombok.*;
import lombok.experimental.*;
/**
* <pre>
@ -27,8 +27,7 @@ public class NiceCiDTO {
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
@Builder
public static class NiceCiParam {
/**
*
@ -112,8 +111,7 @@ public class NiceCiDTO {
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
@Builder
public static class InputXit {
/**
*
@ -182,8 +180,7 @@ public class NiceCiDTO {
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = false)
@Builder
public static class InputDataXit {
private String dataId;
private Long lnkInputId;
@ -222,7 +219,7 @@ public class NiceCiDTO {
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Builder
public static class BillDTO {
private Long billId;
@ -271,7 +268,7 @@ public class NiceCiDTO {
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Builder
public static class BillKkoDTO {
private Long billId;
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.utils.*;
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.support.api.*;
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.nice.mapper.*;
import cokr.xit.ens.modules.nice.model.*;
import cokr.xit.ens.modules.nice.service.support.*;
import lombok.*;
import lombok.extern.slf4j.*;
@ -54,7 +54,8 @@ public class NiceCiAcceptService {
private String BILL_PAYREUSLT_URL;
private final KeySequenceService keySequenceService;
private final NiceCiApiService niceCiApiService;
private final NiceCiBillHistoryService billHistoryService;
private final INiceCiMapper niceCiMapper;
private final PayUseSysApi payUseSysApi;
@ -102,26 +103,34 @@ public class NiceCiAcceptService {
//List<NiceCiDTO.BillDTO> bills = new ArrayList<>();
//List<NiceCiDTO.BillKkoDTO> billKkos = new ArrayList<>();
final String prefixBillUid = PostSeCd.intgrnNoti.getCode() + "-" + IdGenerator.getCurrentTimeSec();
final String customUrl = gson.toJson(CustomUrl.builder()
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());
final String expireAt = DateUtil.getTodayAndNowTime("YYYYMMddHHmmss");
.build())
.expireAt(expireAt)
.build();
final OrgMng orgMng = niceCiMapper.selectKkoBpApiUrlFromEnsOrgMng(list.get(0).getOrgCd())
.orElseThrow(() -> new EnsException(EnsErrCd.NO_DATA_FOUND, EnsErrCd.NO_DATA_FOUND.getCodeNm()));
for(NiceCiDTO.InputXit xit : list){
NiceCiDTO.BillHistDTO billHistDTO = null;
try {
List<NiceCiDTO.InputDataXit> inputDataXits = xit.getInputDataXits();
for (NiceCiDTO.InputDataXit data : inputDataXits) {
BillKkoApiRespDTO<?> respDTO = getPayUrl(xit, data, billHistDTO, orgMng, kkoPayUrlRespData);
String payUrl = getPayUrl(data, orgMng);
data.setPayUrl(payUrl);
data.setPayUrl(String.valueOf(respDTO.getData()));
niceCiMapper.updatePayUrlOfDataInput(data);
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 설정 및 확인 필요???
niceCiMapper.insertBill(
@ -139,7 +148,7 @@ public class NiceCiAcceptService {
.billId(keySequenceService.getKeySequence("BillKko_id"))
.billerUserKey(data.getDataId())
.billerNoticeKey(billUid)
.customUrl(customUrl)
.customUrl(gson.toJson(kkoPayUrlRespData.getCustomUrl()))
.expireAt(expireAt) //d.getExpiresDt()
.billUid(billUid)
.build()
@ -156,7 +165,7 @@ public class NiceCiAcceptService {
if(EnsErrCd.API_COMM_ERROR.equals(e.getErrCd())){
xit.setPrcsCd(IupPrcsCd.TGRF.getCode());
niceCiMapper.updatePrcsCdOfInputXit(xit);
};
}
} catch (Exception e){
xit.setPrcsCd(IupPrcsCd.TGRF.getCode());
@ -180,24 +189,38 @@ public class NiceCiAcceptService {
* @param orgMng
* @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.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<>();
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,
null);
// 마스터 상태 실패처리
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());
}
String rsltStr = resEntity.getBody();
log.info(rsltStr);
//try {
Map<String, Object> m = gson.fromJson(rsltStr, Map.class);
log.info("{}", m);
return "";
return BillKkoApiRespDTO.okBuilder()
.data(resEntity.getBody())
.build();
}
}

@ -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,7 +85,8 @@
<!--// FIXME: NICE CI INSERT UPDATE 항목 확인 적용 필요 -->
<insert id="saveBillKko" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$BillKkoDTO">
/** iup-niceci-mapper|saveBill-NICE CI 청구서 생성|julim */
MERGE INTO ens_bill_kko
MERGE
INTO ens_bill_kko
USING DUAL
ON (bill_id = #{billId})
WHEN MATCHED THEN
@ -147,6 +148,7 @@
error_message,
last_updt_dt
-->
<update id="updatePayUrlOfDataInput" parameterType="cokr.xit.ens.modules.nice.model.NiceCiDTO$InputDataXit">
/** iup-niceci-mapper|updatePayUrlOfDataInput-payUrl update|julim */
UPDATE tb_input_data_xit

Loading…
Cancel
Save