From ee392bb1e93f02427a0256ff7b60665a60441c1e Mon Sep 17 00:00:00 2001 From: "Jonguk. Lim" Date: Wed, 2 Oct 2024 18:07:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20NICE=20CI=20accept=20=EC=A7=84=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/mens-iup-query.sql | 12 ++-- .../kko/service/process/KkoPayUrlService.java | 3 + .../modules/nice/mapper/INiceCiMapper.java | 2 + .../nice/service/NiceCiAcceptService.java | 62 ++++++++++++++++--- .../modules/iup-niceci-mapper.xml | 10 +++ 5 files changed, 74 insertions(+), 15 deletions(-) diff --git a/db/mens-iup-query.sql b/db/mens-iup-query.sql index ed42623..786ac78 100644 --- a/db/mens-iup-query.sql +++ b/db/mens-iup-query.sql @@ -1,7 +1,7 @@ Insert into TB_INPUT_XIT (LNK_INPUT_ID, ORG_CD, JOB_CD, TOT_CNT, PRCS_CD, RUN_DT, EXPIRES_DT, SEND_TYPE, REG_ID, REG_DT, PAY_EXPIRES_DT) Values - (302400012001, '0001', 'A0001', 2, 'TRRG', SYSDATE, SYSDATE + 1 + (302400012002, '0001', 'A0001', 2, 'TGRG', SYSDATE, SYSDATE + 1 , 'NI', 'cntc', SYSDATE, SYSDATE+30); Insert into TB_INPUT_DATA_XIT @@ -9,7 +9,7 @@ Insert into TB_INPUT_DATA_XIT GENDER, MSG_DATA, REG_ID, REG_DT, UPD_ID, UPD_DT, PAY_STATUS_CD, PAY_URL, CAR_NO) Values - (302400012001, 'EL3004202408080439501', '8312181111111', '홍길동', '19831218', + (302400012002, 'EL3004202408080439501', '8312181111111', '홍길동', '19831218', '1', '{"~~@@!!CAR_NO!!@@~~":"24주9434","~~@@!!COMPANY!!@@~~":"수도권제1순환","~~@@!!TERM!!@@~~":"2020년 11월 16일~2021년 04월 15일","~~@@!!DEGREE!!@@~~":"24주9434","~~@@!!FEE!!@@~~":"147,400","~~@@!!COUNT!!@@~~":"69","~~@@!!METHOD!!@@~~":"가상계좌 및 카카오페이","~~@@!!BANK_ACCOUNT!!@@~~":"-(가상계좌) : 농협은행 792000-37-048721\n국민은행 731190-72-112238\n우리은행 283753-54-918171\n신한은행 562146-27-216570","~~@@!!DEADLINE!!@@~~":"2024년09월10일","~~@@!!CALL_NO!!@@~~":"044-211-3377"}', 'cephis00', SYSDATE, '', '', '', '', '24주9434'); @@ -18,10 +18,10 @@ Insert into TB_INPUT_DATA_XIT GENDER, MSG_DATA, REG_ID, REG_DT, UPD_ID, UPD_DT, PAY_STATUS_CD, PAY_URL, CAR_NO) Values - (302400012001, 'EL3004202408080441611', '8312181111111', '홍길동', '19831218', + (302400012002, 'EL3004202408080441611', '8312181111111', '홍길동', '19831218', '1', '{"~~@@!!CAR_NO!!@@~~":"806노9066","~~@@!!COMPANY!!@@~~":"수도권제1순환","~~@@!!TERM!!@@~~":"2024년 03월 21일~2024년 06월 04일","~~@@!!DEGREE!!@@~~":"806노9066","~~@@!!FEE!!@@~~":"988,600","~~@@!!COUNT!!@@~~":"61","~~@@!!METHOD!!@@~~":"가상계좌 및 카카오페이","~~@@!!BANK_ACCOUNT!!@@~~":"-(가상계좌) : 농협은행 792000-37-100871\n국민은행 731190-72-160185\n우리은행 282376-85-718212\n신한은행 562146-27-582924","~~@@!!DEADLINE!!@@~~":"2024년09월10일","~~@@!!CALL_NO!!@@~~":"044-211-3377"}', 'cephis00', SYSDATE, '', '', '', '', '806노9066'); - +commit; @@ -177,7 +177,3 @@ 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'); - - - - diff --git a/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnbill/kko/service/process/KkoPayUrlService.java b/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnbill/kko/service/process/KkoPayUrlService.java index abe7fd1..dd0ed21 100644 --- a/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnbill/kko/service/process/KkoPayUrlService.java +++ b/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnbill/kko/service/process/KkoPayUrlService.java @@ -113,14 +113,17 @@ public class KkoPayUrlService implements PayUrlService, S * 더즌 청구서 API 실패 시 더즌 청구서 RE API 호출 */ Optional.ofNullable(data.getBillDetail()) + // GET billerUserKey .map(billKkoPay -> { log.info("KkoPayUrlService::callApi - createMessage: {}", billKkoPay.getBillerUserKey()); return safely(() -> createMessage(billKkoPay.getBillerUserKey())); }) + // ens_org_mng 테이블 kko_bp_url_api -> PayUrlData url로 set .map(param -> { log.info("KkoPayUrlService::callApi - loadReqData: {}", param); return safely(() -> loadReqData(data, useSysUrl, param)); }) + // .map(param -> { log.info("KkoPayUrlService::callApi - payUseSysApi.payUrl", param); return safely(() -> payUseSysApi.payUrl(useSysUrl, param, null)); diff --git a/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiMapper.java b/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiMapper.java index 8810e6c..080aee7 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiMapper.java +++ b/src/main/java/cokr/xit/ens/modules/nice/mapper/INiceCiMapper.java @@ -4,6 +4,7 @@ import java.util.*; import org.apache.ibatis.annotations.*; +import cokr.xit.ens.modules.common.ctgy.sys.mng.domain.*; import cokr.xit.ens.modules.nice.model.*; /** @@ -31,4 +32,5 @@ public interface INiceCiMapper { int saveBillKko(final NiceCiDTO.BillKkoDTO billKkoDTO); int updatePayUrlOfDataInput(final NiceCiDTO.InputDataXit inputDataXit); int updatePrcsCdOfInputXit(final NiceCiDTO.InputXit inputXit); + Optional selectKkoBpApiUrlFromEnsOrgMng(String orgCd); } 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 fb5d982..fb50294 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 @@ -3,6 +3,7 @@ package cokr.xit.ens.modules.nice.service; import java.util.*; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; import org.springframework.stereotype.*; import org.springframework.transaction.annotation.*; @@ -10,10 +11,14 @@ import com.google.gson.*; import cokr.xit.ens.biz.iup.code.*; import cokr.xit.ens.core.aop.*; +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.service.process.model.*; +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.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.*; @@ -52,6 +57,9 @@ public class NiceCiAcceptService { private final NiceCiApiService niceCiApiService; private final INiceCiMapper niceCiMapper; + private final PayUseSysApi payUseSysApi; + + private Gson gson = new GsonBuilder().disableHtmlEscaping().create(); /** @@ -67,7 +75,8 @@ public class NiceCiAcceptService { * * -- 2. bill 생성 * -- 3. 카카오 청구서 생성 - * -- 4. tb_input_data_xit 테이블 pay_url 에 청구서 URL UPDATE + * -- 4. KkoPayUrlService.callApi() 호출후 tb_input_data_xit 테이블 pay_url 에 청구서 URL UPDATE + * KkoPayUrlServiceTest * -- 5. tb_input_xit 테이블 prcs_cd='GRUC' / 실패 시 prcs_cd='TGRF' * @return * @@ -78,6 +87,13 @@ public class NiceCiAcceptService { niceCiParam.setPrcsCd(IupPrcsCd.TGRG.getCode()); final List list = niceCiMapper.selectNiceCiAcceptTgts(niceCiParam); + if(list.isEmpty()){ + return EnsResponseVO.errBuilder() + .errCode(EnsErrCd.ERR404) + .errMsg(EnsErrCd.ERR404.getCodeNm()) + .build(); + } + list.forEach(d -> { niceCiParam.setLnkInputId(d.getLnkInputId()); d.setInputDataXits(niceCiMapper.selectNiceCiAcceptDatas(niceCiParam)); @@ -92,19 +108,25 @@ public class NiceCiAcceptService { .payResultUrl(BILL_HOST + BILL_PAYREUSLT_URL) .build()); final String expireAt = DateUtil.getTodayAndNowTime("YYYYMMddHHmmss"); + 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){ try { List inputDataXits = xit.getInputDataXits(); for (NiceCiDTO.InputDataXit data : inputDataXits) { - final long bilId = keySequenceService.getKeySequence("bill_id"); + + String payUrl = getPayUrl(data, orgMng); + data.setPayUrl(payUrl); + niceCiMapper.updatePayUrlOfDataInput(data); + final String billUid = IdGenerator.getShortUUID(prefixBillUid); // FIXME: bill_se_cd, org_cd 설정 및 확인 필요??? niceCiMapper.insertBill( NiceCiDTO.BillDTO.builder() - .billId(bilId) + .billId(keySequenceService.getKeySequence("Bill_id")) .billUid(billUid) .billerUserKey(data.getDataId()) .billSeCd(BillSeCd.privt.getCode()) @@ -114,7 +136,7 @@ public class NiceCiAcceptService { // FIXME: biller_notice_key, custom_url, expire_at 설정 및 확인 필요??? niceCiMapper.saveBillKko( NiceCiDTO.BillKkoDTO.builder() - .billId(bilId) + .billId(keySequenceService.getKeySequence("BillKko_id")) .billerUserKey(data.getDataId()) .billerNoticeKey(billUid) .customUrl(customUrl) @@ -123,12 +145,19 @@ public class NiceCiAcceptService { .build() ); - data.setPayUrl(customUrl); - niceCiMapper.updatePayUrlOfDataInput(data); - } + } xit.setPrcsCd(IupPrcsCd.GRUC.getCode()); niceCiMapper.updatePrcsCdOfInputXit(xit); + + // FIXME: API 호출 에러 + } catch (EnsException e) { + + if(EnsErrCd.API_COMM_ERROR.equals(e.getErrCd())){ + xit.setPrcsCd(IupPrcsCd.TGRF.getCode()); + niceCiMapper.updatePrcsCdOfInputXit(xit); + }; + } catch (Exception e){ xit.setPrcsCd(IupPrcsCd.TGRF.getCode()); niceCiMapper.updatePrcsCdOfInputXit(xit); @@ -141,5 +170,24 @@ public class NiceCiAcceptService { .build(); } + private String getPayUrl(final NiceCiDTO.InputDataXit data, final OrgMng orgMng){ + Map map = new HashMap<>(); + map.put("billerUserKey", data.getDataId()); + Map param = new HashMap<>(); + param.put("data", map); + ResponseEntity resEntity = payUseSysApi.payUrl(orgMng.getKkoBpUrlApi(), param, + null); + + // 마스터 상태 실패처리 + if(resEntity.getStatusCode() != HttpStatus.OK){ + 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 ""; + } } 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 07b31b9..5583d7f 100644 --- a/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml +++ b/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml @@ -161,4 +161,14 @@ WHERE lnk_input_id = #{lnkInputId} + + +