diff --git a/db/mens-iup-query.sql b/db/mens-iup-query.sql index 786ac78..7113b7c 100644 --- a/db/mens-iup-query.sql +++ b/db/mens-iup-query.sql @@ -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 diff --git a/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiBillHistoryMapper.java b/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiBillHistoryMapper.java new file mode 100644 index 0000000..38fdd65 --- /dev/null +++ b/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiBillHistoryMapper.java @@ -0,0 +1,25 @@ +package cokr.xit.ens.modules.nice.mapper; + +import org.apache.ibatis.annotations.*; + +import cokr.xit.ens.modules.nice.model.*; + +/** + *
+ * description : + * packageName : cokr.xit.ens.modules.nice.mapper + * fileName : INiceMapper + * author : limju + * date : 2024 9월 30 + * ====================================================================== + * 변경일 변경자 변경 내용 + * ---------------------------------------------------------------------- + * 2024 9월 30 limju 최초 생성 + * + *+ */ +@Mapper +public interface INiceCiBillHistoryMapper { + int insertBillHistory(final NiceCiDTO.BillHistDTO billHistDTO); + int updateBillHistory(final NiceCiDTO.BillHistDTO billHistDTO); +} diff --git a/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiDTO.java b/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiDTO.java index bd22896..6b15986 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiDTO.java +++ b/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiDTO.java @@ -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.*; /** *
@@ -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; + + } } diff --git a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiAcceptService.java b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiAcceptService.java index cd83ef7..664e70f 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiAcceptService.java +++ b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiAcceptService.java @@ -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 { //Listbills = new ArrayList<>(); //List billKkos = new ArrayList<>(); 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 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()) .orElseThrow(() -> new EnsException(EnsErrCd.NO_DATA_FOUND, EnsErrCd.NO_DATA_FOUND.getCodeNm())); for(NiceCiDTO.InputXit xit : list){ + NiceCiDTO.BillHistDTO billHistDTO = null; try { List 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 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 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 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 m = gson.fromJson(rsltStr, Map.class); - log.info("{}", m); - return ""; + return BillKkoApiRespDTO.okBuilder() + .data(resEntity.getBody()) + .build(); } + } diff --git a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiBillHistoryService.java b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiBillHistoryService.java new file mode 100644 index 0000000..4e91432 --- /dev/null +++ b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiBillHistoryService.java @@ -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.*; + +/** + * + * description : + * packageName : cokr.xit.ens.modules.nice.service + * fileName : NiceCiBillHistoryService + * author : limju + * date : 2024 9월 27 + * ====================================================================== + * 변경일 변경자 변경 내용 + * ---------------------------------------------------------------------- + * 2024 9월 27 limju 최초 생성 + * + *+ */ +@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); + } +} diff --git a/src/main/resources/mybatis-mapper/modules/iup-niceci-bill-history-mapper.xml b/src/main/resources/mybatis-mapper/modules/iup-niceci-bill-history-mapper.xml new file mode 100644 index 0000000..bdc05c8 --- /dev/null +++ b/src/main/resources/mybatis-mapper/modules/iup-niceci-bill-history-mapper.xml @@ -0,0 +1,41 @@ + + ++ + diff --git a/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml b/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml index 5583d7f..f0a1672 100644 --- a/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml +++ b/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml @@ -85,47 +85,48 @@+ /** iup-niceci-bill-history-mapper|insertBillHistory-Bill API(NICE CI) call history save|julim */ + + ++ SELECT NVL(MAX(id), 0) + 1 + FROM ens_bill_his + + 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 + ) ++ /** 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} + +/** iup-niceci-mapper|saveBill-NICE CI 청구서 생성|julim */ - MERGE INTO ens_bill_kko - USING DUAL - ON (bill_id = #{billId}) - WHEN MATCHED THEN - UPDATE - SET amount = #{amount} - , details = #{details} - , url = #{url} - , title = #{title} - , expire_type = #{expireType} - , pay_expire_date = #{payExpireDate} - , second_pay_expire_date = #{secondPayExpireDate} - , billed_year_month = #{billedYearMonth} - , ordinal = #{ordinal} - , parameters = #{parameters} - , bank_accounts = #{bankAccounts} - , tax_free_amount = #{taxFreeAmount} - , vat_amount = #{vatAmount} - , last_paid_at = TO_CHAR(sysdate, 'YYYYMMDDHH24MISS') - , last_pay_id = #{lastPayId} - , error_code = #{errorCode} - , error_message = #{errorMessage} - , last_updt_dt = sysdate - WHEN NOT MATCHED THEN - INSERT ( - bill_id, - bill_uid, - biller_user_key, - biller_notice_key, - custom_url, - expire_at, - regist_dt - ) VALUES ( - #{billId} - , #{billUid} - , #{billerUserKey} - , #{billerNoticeKey} - , #{customUrl} - , #{expireAt} - , sysdate - ) + MERGE + INTO ens_bill_kko + USING DUAL + ON (bill_id = #{billId}) + WHEN MATCHED THEN + UPDATE + SET amount = #{amount} + , details = #{details} + , url = #{url} + , title = #{title} + , expire_type = #{expireType} + , pay_expire_date = #{payExpireDate} + , second_pay_expire_date = #{secondPayExpireDate} + , billed_year_month = #{billedYearMonth} + , ordinal = #{ordinal} + , parameters = #{parameters} + , bank_accounts = #{bankAccounts} + , tax_free_amount = #{taxFreeAmount} + , vat_amount = #{vatAmount} + , last_paid_at = TO_CHAR(sysdate, 'YYYYMMDDHH24MISS') + , last_pay_id = #{lastPayId} + , error_code = #{errorCode} + , error_message = #{errorMessage} + , last_updt_dt = sysdate + WHEN NOT MATCHED THEN + INSERT ( + bill_id, + bill_uid, + biller_user_key, + biller_notice_key, + custom_url, + expire_at, + regist_dt + ) VALUES ( + #{billId} + , #{billUid} + , #{billerUserKey} + , #{billerNoticeKey} + , #{customUrl} + , #{expireAt} + , sysdate + ) +/** iup-niceci-mapper|updatePayUrlOfDataInput-payUrl update|julim */ UPDATE tb_input_data_xit