@ -3,6 +3,7 @@ package cokr.xit.ens.modules.nice.service;
import java.util.* ;
import java.util.* ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.http.* ;
import org.springframework.stereotype.* ;
import org.springframework.stereotype.* ;
import org.springframework.transaction.annotation.* ;
import org.springframework.transaction.annotation.* ;
@ -10,10 +11,14 @@ import com.google.gson.*;
import cokr.xit.ens.biz.iup.code.* ;
import cokr.xit.ens.biz.iup.code.* ;
import cokr.xit.ens.core.aop.* ;
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.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.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.code.* ;
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.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.* ;
@ -52,6 +57,9 @@ public class NiceCiAcceptService {
private final NiceCiApiService niceCiApiService ;
private final NiceCiApiService niceCiApiService ;
private final INiceCiMapper niceCiMapper ;
private final INiceCiMapper niceCiMapper ;
private final PayUseSysApi payUseSysApi ;
private Gson gson = new GsonBuilder ( ) . disableHtmlEscaping ( ) . create ( ) ;
private Gson gson = new GsonBuilder ( ) . disableHtmlEscaping ( ) . create ( ) ;
/ * *
/ * *
@ -67,7 +75,8 @@ public class NiceCiAcceptService {
*
*
* - - 2. bill 생 성
* - - 2. bill 생 성
* - - 3. 카 카 오 청 구 서 생 성
* - - 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 '
* - - 5. tb_input_xit 테 이 블 prcs_cd = ' GRUC ' / 실 패 시 prcs_cd = ' TGRF '
* @return
* @return
* < / pre >
* < / pre >
@ -78,6 +87,13 @@ public class NiceCiAcceptService {
niceCiParam . setPrcsCd ( IupPrcsCd . TGRG . getCode ( ) ) ;
niceCiParam . setPrcsCd ( IupPrcsCd . TGRG . getCode ( ) ) ;
final List < NiceCiDTO . InputXit > list = niceCiMapper . selectNiceCiAcceptTgts ( niceCiParam ) ;
final List < NiceCiDTO . InputXit > list = niceCiMapper . selectNiceCiAcceptTgts ( niceCiParam ) ;
if ( list . isEmpty ( ) ) {
return EnsResponseVO . errBuilder ( )
. errCode ( EnsErrCd . ERR404 )
. errMsg ( EnsErrCd . ERR404 . getCodeNm ( ) )
. build ( ) ;
}
list . forEach ( d - > {
list . forEach ( d - > {
niceCiParam . setLnkInputId ( d . getLnkInputId ( ) ) ;
niceCiParam . setLnkInputId ( d . getLnkInputId ( ) ) ;
d . setInputDataXits ( niceCiMapper . selectNiceCiAcceptDatas ( niceCiParam ) ) ;
d . setInputDataXits ( niceCiMapper . selectNiceCiAcceptDatas ( niceCiParam ) ) ;
@ -92,19 +108,25 @@ public class NiceCiAcceptService {
. payResultUrl ( BILL_HOST + BILL_PAYREUSLT_URL )
. payResultUrl ( BILL_HOST + BILL_PAYREUSLT_URL )
. build ( ) ) ;
. build ( ) ) ;
final String expireAt = DateUtil . getTodayAndNowTime ( "YYYYMMddHHmmss" ) ;
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 ) {
for ( NiceCiDTO . InputXit xit : list ) {
try {
try {
List < NiceCiDTO . InputDataXit > inputDataXits = xit . getInputDataXits ( ) ;
List < NiceCiDTO . InputDataXit > inputDataXits = xit . getInputDataXits ( ) ;
for ( NiceCiDTO . InputDataXit data : inputDataXits ) {
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 ) ;
final String billUid = IdGenerator . getShortUUID ( prefixBillUid ) ;
// FIXME: bill_se_cd, org_cd 설정 및 확인 필요???
// FIXME: bill_se_cd, org_cd 설정 및 확인 필요???
niceCiMapper . insertBill (
niceCiMapper . insertBill (
NiceCiDTO . BillDTO . builder ( )
NiceCiDTO . BillDTO . builder ( )
. billId ( bilId )
. billId ( keySequenceService. getKeySequence ( "Bill_id" ) )
. billUid ( billUid )
. billUid ( billUid )
. billerUserKey ( data . getDataId ( ) )
. billerUserKey ( data . getDataId ( ) )
. billSeCd ( BillSeCd . privt . getCode ( ) )
. billSeCd ( BillSeCd . privt . getCode ( ) )
@ -114,7 +136,7 @@ public class NiceCiAcceptService {
// FIXME: biller_notice_key, custom_url, expire_at 설정 및 확인 필요???
// FIXME: biller_notice_key, custom_url, expire_at 설정 및 확인 필요???
niceCiMapper . saveBillKko (
niceCiMapper . saveBillKko (
NiceCiDTO . BillKkoDTO . builder ( )
NiceCiDTO . BillKkoDTO . builder ( )
. billId ( bilId )
. billId ( keySequenceService. getKeySequence ( "BillKko_id" ) )
. billerUserKey ( data . getDataId ( ) )
. billerUserKey ( data . getDataId ( ) )
. billerNoticeKey ( billUid )
. billerNoticeKey ( billUid )
. customUrl ( customUrl )
. customUrl ( customUrl )
@ -123,12 +145,19 @@ public class NiceCiAcceptService {
. build ( )
. build ( )
) ;
) ;
data . setPayUrl ( customUrl ) ;
niceCiMapper . updatePayUrlOfDataInput ( data ) ;
}
}
xit . setPrcsCd ( IupPrcsCd . GRUC . getCode ( ) ) ;
xit . setPrcsCd ( IupPrcsCd . GRUC . getCode ( ) ) ;
niceCiMapper . updatePrcsCdOfInputXit ( xit ) ;
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 ) {
} catch ( Exception e ) {
xit . setPrcsCd ( IupPrcsCd . TGRF . getCode ( ) ) ;
xit . setPrcsCd ( IupPrcsCd . TGRF . getCode ( ) ) ;
niceCiMapper . updatePrcsCdOfInputXit ( xit ) ;
niceCiMapper . updatePrcsCdOfInputXit ( xit ) ;
@ -141,5 +170,24 @@ public class NiceCiAcceptService {
. build ( ) ;
. build ( ) ;
}
}
private String getPayUrl ( final NiceCiDTO . InputDataXit data , final OrgMng orgMng ) {
Map < String , Object > map = new HashMap < > ( ) ;
map . put ( "billerUserKey" , data . getDataId ( ) ) ;
Map < String , Object > param = new HashMap < > ( ) ;
param . put ( "data" , map ) ;
ResponseEntity < String > 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 < String , Object > m = gson . fromJson ( rsltStr , Map . class ) ;
log . info ( "{}" , m ) ;
return "" ;
}
}
}