diff --git a/db/mens-iup-query.sql b/db/mens-iup-query.sql new file mode 100644 index 0000000..acce82e --- /dev/null +++ b/db/mens-iup-query.sql @@ -0,0 +1,193 @@ +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 + (302400001117, '0002', 'B0001', 1, 'TGRG', SYSDATE, SYSDATE + 30 + , 'KP', 'cntc', SYSDATE, SYSDATE+30); + + +Insert into TB_INPUT_DATA_XIT + (LNK_INPUT_ID, DATA_ID, SID, NAME, BIRTHDAY, GENDER, MSG_DATA, MSG_DTL_DATA, REG_ID, REG_DT, CAR_NO, CALL_CENTER_NO) + Values + (302400001117, '300799990000000001117', '8312181157213', '김지호', '19831218','1' + , '{"~~@@!!CAR_NO!!@@~~":"20우3412","~~@@!!DEGREE!!@@~~":"3","~~@@!!FEE!!@@~~":"1,900","~~@@!!YYYY!!@@~~":"2022","~~@@!!MM!!@@~~":"03","~~@@!!DD!!@@~~":"11","~~@@!!BANK!!@@~~":"우체국","~~@@!!ACCOUNT!!@@~~":"8608-90-80907938","~~@@!!HISTORY!!@@~~":"-2021-11-29 12:33 (별내 550)\n-2021-11-29 12:19 (양주 900)\n-2021-11-30 14:33 (불암산② 450)","~~@@!!CALL_NO!!@@~~":"(031)522-6400~1","~~@@!!HOMEPAGE!!@@~~":"https://seoulbeltway.co.kr/main/esccar.jsp"}' + , '{"details":[{"item_type":"TEXT","elements":[],"title":"미납통행료 안내문(1차)","properties":{"use_toggle":false}},{"item_type":"PRE_TEXT","elements":"수도권제1순환고속도로 안내문(1차)이 도착하였습니다.\n미납통행료 종이고지서를 모바일 전자문서로 고지하고 있으며, 본 전자문서를 받으신 경우 종이고지서는 발송되지 않습니다.","title":"","properties":{"use_toggle":false}},{"item_type":"KEY_VALUE","elements":[{"level":1,"value":"67어3853","key":"차량번호"},{"level":1,"value":"수도권제1순환","key":"미납발생\n노선명"},{"level":1,"value":"미납통행료 안내문(1차)","key":"고지서명"},{"level":1,"value":"1,260원","key":"납부하실 통행료"},{"level":1,"value":"1,260원","key":"- 미납통행료"},{"level":1,"value":"0원","key":"- 부가통행료"},{"level":1,"value":"2023년 06월 22일까지","key":"납부기한"}],"title":"안내내역","properties":{"use_toggle":false}},{"item_type":"TEXT","elements":[],"title":"상세내역","properties":{"use_toggle":false}},{"item_type":"KEY_VALUE","elements":[{"level":1,"value":"2023-05-20 13:10","key":"통행일시"},{"level":1,"value":"양주","key":"통행영업소"},{"level":1,"value":"1,260 원","key":"통행요금"},{"level":1,"value":"SC잔액부족","key":"미납사유"}],"title":"","properties":{"use_toggle":false}},{"item_type":"PRE_TEXT","elements":" \n","title":"","properties":{"use_toggle":false}},{"item_type":"PRE_TEXT","elements":"※ 해당 통행을 포함하여 최근 1년 이내에 20회 이상 통행료 미납 시 누적 20회부터 즉시 부가통행료(미납통행료의 10배)가 미납통행료와 함께 부과될 수 있음을 알려드립니다.","title":"","properties":{"style":{"highlight":{"※ 해당 통행을 포함하여 최근 1년 이내에 20회 이상 통행료 미납 시 누적 20회부터 즉시 부가통행료(미납통행료의 10배)가 미납통행료와 함께 부과될 수 있음을 알려드립니다.":{"font-color":"black","font-weight":"bold"}}},"use_toggle":false}},{"item_type":"KEY_VALUE","elements":[{"level":1,"value":"하단의 납부하기 클릭 또는\n가상계좌 납부\n(우체국 8608-89-80215603)","key":"납부방법"},{"level":1,"value":"수도권제1순환고속도로\n고객센터 ☎ (031)894-6300~1\n홈페이지 https://seoulbeltway.co.kr/main/esccar.jsp","key":"문의처"}],"title":"납부방법 및 문의처","properties":{"hyperlink":["https://seoulbeltway.co.kr/main/esccar.jsp"],"style":{"highlight":{"(031)894-6300~1":{"font-color":"blue","font-weight":"bold","font-size":"35px","use-clipboard":true},"우체국":{"font-weight":"bold"},"고객센터 ☎ ":{"font-color":"blue","font-weight":"bold","font-size":"35px"},"8608-89-80215603":{"font-weight":"bold","use-clipboard":true}}},"use_toggle":false}},{"item_type":"TABLE","elements":{"head":[""],"rows":[["발송처 : 민자도로 관리지원센터\n(044-211-3377)"]]},"title":"","properties":{"style":{"highlight":{"발송처 : 민자도로 관리지원센터":{"font-size":"25px"},"(044-211-3377)":{"font-size":"25px"}},"text_align":["right"]},"use_toggle":false}},{"item_type":"PAY_BUTTON","title":"납부하기"}]}' + , 'cntc', SYSDATE, '20우3412', '1599-2509'); +commit; + + select + intgrnsend0_.int_send_detail_id as col_0_0_, + intgrnsend0_.linked_uuid as col_1_0_, + intgrnsend0_.cur_post_se as col_2_0_, + senddetail1_.status as col_3_0_, + senddetail1_.sent_at as col_4_0_, + senddetail1_.received_at as col_5_0_, + senddetail1_.authenticated_at as col_6_0_, + senddetail1_.ott_verified_at as col_7_0_, + senddetail1_.read_at as col_8_0_, + senddetail1_.user_notified_at as col_9_0_, + senddetail1_.error_code as col_10_0_, + senddetail1_.error_message as col_11_0_, + sendmast2_.error_code as col_12_0_, + sendmast2_.error_message as col_13_0_ + from + ens_intgrn_snd_dtl intgrnsend0_ + inner join + ens_snd_dtl_kko_talk senddetail1_ + on ( + senddetail1_.send_detail_id=intgrnsend0_.send_detail_id_kko_talk + ) + inner join + ens_snd_mast sendmast2_ + on senddetail1_.send_mast_id=sendmast2_.send_mast_id + where + intgrnsend0_.cur_post_se='kkoTalk' + and intgrnsend0_.int_send_mast_id=1553; + + + + + +select * from ens_intgrn_snd_mast; +select * from ens_intgrn_snd_dtl; +select * from ens_bill; +select * from ens_tmplt_mng; +select * from ens_org_mng; +select * from ens_snd_dtl_mbl_page; + +/* accept : org_cd = 0001, tmplt_cd = A0008 */ +select * from TB_INPUT_XIT order by REG_DT desc; +select * from TB_INPUT_DATA_XIT order by REG_DT desc; +select * from ens_tmplt_mng_kko_talk; +select * from ens_tmplt_mng_kko_md; +select * from ens_snd_mast order by REGIST_DT desc; +select * from ens_bill order by REGIST_DT desc; +select * from ens_snd_dtl_kko_talk order by REGIST_DT desc; +select * from ens_snd_dtl_kko_md order by REGIST_DT desc; +select * from ens_snd_dtl_mbl_page order by REGIST_DT desc; + +select * from ENS_NICE_JID_MNG order by REGIST_DT desc; + +select * from ENS_NICE_CI_MNG order by regist_dt desc; + + + +select * + from ens_tmplt_mng etm + join ens_org_mng eom + on etm.ORG_CD = eom.ORG_CD + left join ens_tmplt_mng_intgrn etmi + on etm.ORG_CD = etmi.ORG_CD + and etm.TMPLT_CD = etmi.TMPLT_CD + left join ens_tmplt_mng_kko_at etmka + on etm.ORG_CD = etmka.ORG_CD + and etm.TMPLT_CD = etmka.TMPLT_CD + left join ens_tmplt_mng_kko_md etmkm + on etm.ORG_CD = etmkm.ORG_CD + and etm.TMPLT_CD = etmkm.TMPLT_CD + left join ens_tmplt_mng_kt_st etmks + on etm.ORG_CD = etmks.ORG_CD + and etm.TMPLT_CD = etmks.TMPLT_CD + left join ens_tmplt_mng_kt_gbs etmkg + on etm.ORG_CD = etmkg.ORG_CD + and etm.TMPLT_CD = etmkg.TMPLT_CD + left join ens_tmplt_mng_nv_st etmns + on etm.ORG_CD = etmns.ORG_CD + and etm.TMPLT_CD = etmns.TMPLT_CD + where etm.ORG_CD = '0001' + and etm.TMPLT_CD = 'A0001'; +select * from ens_org_mng where ORG_CD = '0001'; + +select * from ens_intgrn_snd_dtl; + +select * from TB_INPUT_XIT; +select * from TB_INPUT_DATA_XIT; +SELECT * FROM TB_SEND_RESULT_V2; + + + select + sendmast0_.send_mast_id as send_mast_id1_35_, + sendmast0_.last_updt_dt as last_updt_dt2_35_, + sendmast0_.regist_dt as regist_dt3_35_, + sendmast0_.accept_dt as accept_dt4_35_, + sendmast0_.close_dt as close_dt5_35_, + sendmast0_.error_code as error_code6_35_, + sendmast0_.error_message as error_message7_35_, + sendmast0_.org_cd as org_cd8_35_, + sendmast0_.post_bundle_title as post_bundle_title9_35_, + sendmast0_.read_cnt as read_cnt10_35_, + sendmast0_.send_cnt as send_cnt11_35_, + sendmast0_.send_dt as send_dt12_35_, + sendmast0_.stat_cd as stat_cd13_35_, + sendmast0_.tmplt_cd as tmplt_cd14_35_, + sendmast0_.vender as vender15_35_, + sendmast0_.post_se as post_se16_35_ + from + ens_snd_mast sendmast0_ + where + sendmast0_.send_mast_id=3302; + + select + intgrnsend0_.int_send_mast_id as col_0_0_ + from + ens_intgrn_snd_dtl intgrnsend0_ + inner join + ens_snd_dtl_kko_talk senddetail1_ + on ( + intgrnsend0_.send_detail_id_kko_talk=senddetail1_.send_detail_id + ) + where + senddetail1_.send_mast_id=3302 + group by + intgrnsend0_.int_send_mast_id; + + select + intgrnsend0_.int_send_mast_id as int_send_mast_id1_6_0_, + intgrnsend0_.last_updt_dt as last_updt_dt2_6_0_, + intgrnsend0_.regist_dt as regist_dt3_6_0_, + intgrnsend0_.accept_dt as accept_dt4_6_0_, + intgrnsend0_.close_dt as close_dt5_6_0_, + intgrnsend0_.error_code as error_code6_6_0_, + intgrnsend0_.error_message as error_message7_6_0_, + intgrnsend0_.org_cd as org_cd8_6_0_, + intgrnsend0_.post_bundle_title as post_bundle_title9_6_0_, + intgrnsend0_.read_cnt as read_cnt10_6_0_, + intgrnsend0_.send_cnt as send_cnt11_6_0_, + intgrnsend0_.send_dt as send_dt12_6_0_, + intgrnsend0_.stat_cd as stat_cd13_6_0_, + intgrnsend0_.tmplt_cd as tmplt_cd14_6_0_, + intgrnsend0_.vender as vender15_6_0_, + intgrnsend0_.try1 as try16_6_0_, + intgrnsend0_.try2 as try17_6_0_, + intgrnsend0_.try3 as try18_6_0_, + intgrnsend0_.try_cnt as try_cnt19_6_0_, + intgrnsend0_.try_seq as try_seq20_6_0_, + intgrnsend0_.try_stat_cd as try_stat_cd21_6_0_ + from + ens_intgrn_snd_mast intgrnsend0_ + where + intgrnsend0_.int_send_mast_id=2452;; select + intgrnsend0_.int_send_mast_id as int_send_mast_id1_6_0_, + intgrnsend0_.last_updt_dt as last_updt_dt2_6_0_, + intgrnsend0_.regist_dt as regist_dt3_6_0_, + intgrnsend0_.accept_dt as accept_dt4_6_0_, + intgrnsend0_.close_dt as close_dt5_6_0_, + intgrnsend0_.error_code as error_code6_6_0_, + intgrnsend0_.error_message as error_message7_6_0_, + intgrnsend0_.org_cd as org_cd8_6_0_, + intgrnsend0_.post_bundle_title as post_bundle_title9_6_0_, + intgrnsend0_.read_cnt as read_cnt10_6_0_, + intgrnsend0_.send_cnt as send_cnt11_6_0_, + intgrnsend0_.send_dt as send_dt12_6_0_, + intgrnsend0_.stat_cd as stat_cd13_6_0_, + intgrnsend0_.tmplt_cd as tmplt_cd14_6_0_, + intgrnsend0_.vender as vender15_6_0_, + intgrnsend0_.try1 as try16_6_0_, + intgrnsend0_.try2 as try17_6_0_, + intgrnsend0_.try3 as try18_6_0_, + intgrnsend0_.try_cnt as try_cnt19_6_0_, + intgrnsend0_.try_seq as try_seq20_6_0_, + intgrnsend0_.try_stat_cd as try_stat_cd21_6_0_ + from + ens_intgrn_snd_mast intgrnsend0_ + where + intgrnsend0_.int_send_mast_id=2452; diff --git a/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/domain/repository/IntgrnSendDetailRepositoryImpl.java b/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/domain/repository/IntgrnSendDetailRepositoryImpl.java index 1460d63..ca2d210 100644 --- a/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/domain/repository/IntgrnSendDetailRepositoryImpl.java +++ b/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/domain/repository/IntgrnSendDetailRepositoryImpl.java @@ -64,6 +64,8 @@ public class IntgrnSendDetailRepositoryImpl implements IntgrnSendDetailRepositor .set(intgrnSendDetail.docUserNotiedDt, data.getDocUserNotiedDt()) .set(intgrnSendDetail.error.errorCode, data.getMastErrorCode() == null && data.getErrorCode() == null ? null : String.format("[M]%s. [D]%s", data.getMastErrorCode(), data.getErrorCode())) .set(intgrnSendDetail.error.errorMessage, data.getMastErrorCode() == null && data.getErrorCode() == null ? null : String.format("[M]%s. [D]%s", data.getMastErrorMessage(), data.getErrorMessage())) + // FIXME: 카카오톡 추가 : 변경일시 추가 + .set(intgrnSendDetail.lastUpdtDt, LocalDateTime.now()) .where(intgrnSendDetail.intSendDetailId.eq(data.getIntSendDetailId())) .execute(); } diff --git a/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/service/support/IntgrnNotiRsltFetcher.java b/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/service/support/IntgrnNotiRsltFetcher.java index ea920ff..88fe88b 100644 --- a/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/service/support/IntgrnNotiRsltFetcher.java +++ b/src/main/java/cokr/xit/ens/modules/common/ctgy/intgrnnoti/service/support/IntgrnNotiRsltFetcher.java @@ -1,5 +1,6 @@ package cokr.xit.ens.modules.common.ctgy.intgrnnoti.service.support; +import java.time.*; import java.util.*; import org.springframework.stereotype.*; @@ -60,30 +61,32 @@ public class IntgrnNotiRsltFetcher extends ResultProcTemplate { respVO = EnsResponseVO.errRsltBuilder().errCode(EnsErrCd.RSLT500).errMsg(e.getMessage()).resultInfo(resultInfo).build(); } finally { - if (!CmmnUtil.isEmpty(intgrnSendMast)) + + if (!CmmnUtil.isEmpty(intgrnSendMast)) { + // FIXME: 카카오톡 추가 - 변경일자 set + intgrnSendMast.setLastUpdtDt(LocalDateTime.now()); + if (EnsErrCd.OK.equals(respVO.getErrCode())) { intgrnSendMast.setError(FieldError.initBuilder().build()); - Integer readCnt = sendDetails.stream() - .map(row -> IntgrnDtlStatCd.READ.equals(row.getCurStatCd()) ? 1 : 0) - .reduce(Integer::sum) - .orElseGet(() -> 0); + .map(row -> IntgrnDtlStatCd.READ.equals(row.getCurStatCd()) ? 1 : 0) + .reduce(Integer::sum) + .orElseGet(() -> 0); intgrnSendMast.setReadCnt(readCnt); if (StatCd.sendok.equals(intgrnSendMast.getStatCd()) - || StatCd.sendcmplt.equals(intgrnSendMast.getStatCd())) { + || StatCd.sendcmplt.equals(intgrnSendMast.getStatCd())) { if (readCnt > 0) intgrnSendMast.setStatCd(StatCd.open); else intgrnSendMast.setStatCd(StatCd.sendcmplt); } else if (StatCd.open.equals(intgrnSendMast.getStatCd()) - || StatCd.close.equals(intgrnSendMast.getStatCd())) { + || StatCd.close.equals(intgrnSendMast.getStatCd())) { } else { int sendOkCnt = 0; int sendFailCnt = 0; - for (IntgrnSendDetail sendDetail : sendDetails) { if (sendDetail.getCurStatCd().isSuccess()) sendOkCnt++; @@ -99,54 +102,49 @@ public class IntgrnNotiRsltFetcher extends ResultProcTemplate { } } else { intgrnSendMast.setError(FieldError.initBuilder() - .errorCode(respVO.getErrCode().getCode()) - .errorMessage(respVO.getErrMsg()) - .build()); + .errorCode(respVO.getErrCode().getCode()) + .errorMessage(respVO.getErrMsg()) + .build()); } + if (!CmmnUtil.isEmpty(sendDetails)) { + this.tryStatCdToClosed(intgrnSendMast, sendDetails); - if (!CmmnUtil.isEmpty(intgrnSendMast)) { + if (TryStatCd.sndRsrv.equals(intgrnSendMast.getTryStatCd()) || TryStatCd.sndRtme.equals(intgrnSendMast.getTryStatCd())) { - this.tryStatCdToClosed(intgrnSendMast, sendDetails); + PostSeCd postSeCd = intgrnSendMast.getTry1(); + if (intgrnSendMast.getTrySeq() == 2) postSeCd = intgrnSendMast.getTry2(); + else if (intgrnSendMast.getTrySeq() == 3) postSeCd = intgrnSendMast.getTry3(); + int sendOkCnt = 0; + int sendFailCnt = 0; + int unknownCnt = 0; + int curPostTotCnt = 0; + for (IntgrnSendDetail sendDetail : sendDetails) { + if (!postSeCd.equals(sendDetail.getCurPostSe())) + continue; + curPostTotCnt++; - if (TryStatCd.sndRsrv.equals(intgrnSendMast.getTryStatCd()) || TryStatCd.sndRtme.equals(intgrnSendMast.getTryStatCd())) { - PostSeCd postSeCd = intgrnSendMast.getTry1(); - if (intgrnSendMast.getTrySeq() == 2) postSeCd = intgrnSendMast.getTry2(); - else if (intgrnSendMast.getTrySeq() == 3) postSeCd = intgrnSendMast.getTry3(); - int sendOkCnt = 0; - int sendFailCnt = 0; - int unknownCnt = 0; - int curPostTotCnt = 0; - for (IntgrnSendDetail sendDetail : sendDetails) { - if (!postSeCd.equals(sendDetail.getCurPostSe())) - continue; - curPostTotCnt++; + if (sendDetail.getCurStatCd().isSuccess()) + sendOkCnt++; + else if (sendDetail.getCurStatCd().isFail()) + sendFailCnt++; + else + unknownCnt++; + } + if (unknownCnt < curPostTotCnt) + if (sendOkCnt > 0) + intgrnSendMast.setTryStatCd(TryStatCd.ok); + else if (sendFailCnt == curPostTotCnt) + intgrnSendMast.setTryStatCd(TryStatCd.fail); - if (sendDetail.getCurStatCd().isSuccess()) - sendOkCnt++; - else if (sendDetail.getCurStatCd().isFail()) - sendFailCnt++; - else - unknownCnt++; } - if (unknownCnt < curPostTotCnt) - if (sendOkCnt > 0) - intgrnSendMast.setTryStatCd(TryStatCd.ok); - else if (sendFailCnt == curPostTotCnt) - intgrnSendMast.setTryStatCd(TryStatCd.fail); - - } } } - // FIXME: 카카오톡 추가 - 명시적 반영 - // intgrnSendMastRepository.flush(); - // intgrnSendDetailRepository.flush(); - return respVO; } diff --git a/src/main/java/cokr/xit/ens/modules/kkotalk/domain/SendDetailKkoTalkStatHist.java b/src/main/java/cokr/xit/ens/modules/kkotalk/domain/SendDetailKkoTalkStatHist.java index b66d233..87b6f63 100644 --- a/src/main/java/cokr/xit/ens/modules/kkotalk/domain/SendDetailKkoTalkStatHist.java +++ b/src/main/java/cokr/xit/ens/modules/kkotalk/domain/SendDetailKkoTalkStatHist.java @@ -37,7 +37,7 @@ public class SendDetailKkoTalkStatHist { @Column(name = "envelope_id", nullable = true) - private String envelope_id; + private String envelopeId; @Column(name = "external_id", nullable = true) diff --git a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java index fb7ddc6..de8c650 100644 --- a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java +++ b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkApiService.java @@ -1,5 +1,7 @@ package cokr.xit.ens.modules.kkotalk.service.support; +import java.net.*; +import java.nio.charset.*; import java.util.*; import java.util.stream.*; @@ -8,7 +10,10 @@ import javax.validation.*; import org.apache.commons.lang3.*; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; +import org.springframework.http.client.*; import org.springframework.stereotype.*; +import org.springframework.web.client.*; +import org.springframework.web.util.*; import cokr.xit.ens.core.exception.*; import cokr.xit.ens.core.exception.code.*; @@ -279,12 +284,12 @@ public class KkoTalkApiService { return new ResponseEntity("{\""+EnsErrCd.SEND405.getCode() +"\":" + errors.toString() +"}", HttpStatus.BAD_REQUEST); } String param = "{\"envelopes\":" + JsonUtils.toJson(envelopes) + "}"; - return webClient.exchangeKkotalk( - HOST + API_BULKSEND[0].replace("{PRODUCT_CODE}", reqDTO.getProductCode()), + + return callApi( HttpMethod.valueOf(API_BULKSEND[1]), + HOST + API_BULKSEND[0].replace("{PRODUCT_CODE}", reqDTO.getProductCode()), param, - ResponseEntity.class, - getRlaybsnmInfo(reqDTO)); + getHeaders()); } /** @@ -339,7 +344,106 @@ public class KkoTalkApiService { return errList; } + // FIXME: 카카오톡 API 호출 시 API 호출 정보 추가 필요 private CmmEnsRlaybsnmDTO getRlaybsnmInfo(final CmmEnsRequestDTO request){ - return null;//CmmEnsUtils.getRlaybsnmInfo(request.getSignguCode(), request.getFfnlgCode(), SndngSeCode.KAKAO); + //return null;//CmmEnsUtils.getRlaybsnmInfo(request.getSignguCode(), request.getFfnlgCode(), SndngSeCode.KAKAO); + return CmmEnsRlaybsnmDTO.builder() + .kakaoDealerRestApiKey("kakaoDealerRestApiKey") + .kakaoPartnerRestApiKey("kakaoPartnerRestApiKey") + .kakaoSettleId("kakaoSettleId") + .build(); } + + /** + *
메소드 설명: API 호출
+     * 
+ * + * @param method + * @param url + * @param body + * @param headers + * @return ResponseEntity 요청처리 후 응답객체 + * @author: 박민규 + * @date: 2021. 8. 4. + * @apiNote: 사이트 참조 https://e2e2e2.tistory.com/15 + */ + private ResponseEntity callApi(HttpMethod method, String url, String body, HttpHeaders headers) { + + StringBuffer sb = new StringBuffer(); + ResponseEntity responseEntity = null; + try { + + HttpEntity entity = null; + UriComponents uri = null; + switch (method) { + case GET: + entity = new HttpEntity<>(headers); + uri = UriComponentsBuilder + .fromHttpUrl(String.format("%s?%s", url, body == null ? "" : body)) + // .encode(StandardCharsets.UTF_8) //"%"기호가 "%25"로 인코딩 발생하여 주석처리 함. + .build(false); + break; + case POST: + entity = new HttpEntity<>(body, headers); + uri = UriComponentsBuilder + .fromHttpUrl(url) + .encode(StandardCharsets.UTF_8) + .build(); + break; + + default: + break; + } + + + + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); + factory.setConnectTimeout(3000); + // factory.setReadTimeout(3000); + factory.setReadTimeout(10000); + RestTemplate restTemplate = new RestTemplate(factory); + sb.append("\n url => " + uri.toString()) + .append("\n method => " + method) + .append("\n headers => " + entity.getHeaders().toString()) + .append("\n body => " + entity.getBody()); + responseEntity = restTemplate.exchange(URI.create(uri.toString()), method, entity, String.class); + + /* + * HttpStatus 정보 확인 방법 + * -.코드: responseEntity.getStatusCodeValue() + * -.메시지: responseEntity.getStatusCode() + */ + + } catch (HttpServerErrorException e) { + responseEntity = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode()); + log.error("call API 서버오류\n[ url ]: {} \n[ param ]: {} \n[ error ]: {}", url, body, CmmnUtil.printStackTraceToString(e)); + } catch (HttpClientErrorException e) { + responseEntity = new ResponseEntity(e.getResponseBodyAsString(), e.getStatusCode()); + log.error("call API 클라이언트오류\n[ url ]: {} \n[ param ]: {} \n[ error ]: {}", url, body, CmmnUtil.printStackTraceToString(e)); + } catch (RestClientException e) { + responseEntity = new ResponseEntity(e.getMessage(), HttpStatus.REQUEST_TIMEOUT); + log.error("RestAPI 호출 오류\n[ url ]: {} \n[ param ]: {} \n[ error ]: {}", url, body, CmmnUtil.printStackTraceToString(e)); + } catch (Exception e) { + responseEntity = new ResponseEntity(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + log.error("call API 기타오류\n[ url ]: {} \n[ param ]: {} \n[ error ]: {}", url, body, CmmnUtil.printStackTraceToString(e)); + } finally { + log.info("카카오콕 인증톡 API\n[ REQUEST ]-----------------------------------------------------------------------\n{}\n[ RESPONSE ]-----------------------------------------------------------------------\n{}", sb.toString(), responseEntity.getBody()); + } + + + return responseEntity; + } + + // FIXME: 카카오톡 API 호출 시 API 호출 정보 추가 필요 + private HttpHeaders getHeaders(){ + HttpHeaders headers = new HttpHeaders(); + // headers.setContentType(MediaType.APPLICATION_JSON); + headers.setContentType(new MediaType(MediaType.APPLICATION_JSON, Charset.forName("utf-8"))); + headers.set(HttpHeaders.AUTHORIZATION, String.format("KakaoAK %s", "KakaoDealerRestApiKey")); + headers.set("Target-Authorization", "KakaoPartnerRestApiKey"); + headers.set("settle-Id", "KakaoSettleId"); + + return headers; + } + } diff --git a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkRsltFetcher.java b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkRsltFetcher.java index bebdf87..cf61362 100644 --- a/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkRsltFetcher.java +++ b/src/main/java/cokr/xit/ens/modules/kkotalk/service/support/KkoTalkRsltFetcher.java @@ -23,10 +23,9 @@ import cokr.xit.ens.modules.common.domain.*; import cokr.xit.ens.modules.common.domain.repository.*; import cokr.xit.ens.modules.common.domain.support.*; import cokr.xit.ens.modules.common.event.*; -import cokr.xit.ens.modules.kkomydoc.code.*; -import cokr.xit.ens.modules.kkomydoc.domain.*; import cokr.xit.ens.modules.kkomydoc.domain.repository.*; -import cokr.xit.ens.modules.kkomydoc.model.*; +import cokr.xit.ens.modules.kkotalk.code.*; +import cokr.xit.ens.modules.kkotalk.domain.*; import cokr.xit.ens.modules.kkotalk.mapper.*; import cokr.xit.ens.modules.kkotalk.model.*; import lombok.*; @@ -177,7 +176,7 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate { // FIXME: 카카오톡 코드 반영 필요 Integer readCnt = sendDetails.stream() - .map(row -> KkoMydocStatusCd.READ.equals(row.getStatus()) ? 1 : 0) + .map(row -> KkoTalkStatusCd.READ.equals(row.getStatus()) ? 1 : 0) .reduce(Integer::sum) .orElseGet(() -> 0); sendMast.setReadCnt(readCnt); @@ -228,15 +227,15 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate { * @return */ private Map toApiRespVOMap(Map row) { - KkoMydocApiRespVO kkoMydocApiRespVO = KkoMydocApiRespVO.builder() - .error_code(row.containsKey("error_code") ? String.valueOf(row.get("error_code")) : null) - .error_message(row.containsKey("error_message") ? String.valueOf(row.get("error_message")) : null) + KkoTalkApiRespVO kkoTalkApiRespVO = KkoTalkApiRespVO.builder() + .errorCode(row.containsKey("errorCode") ? String.valueOf(row.get("errorCode")) : null) + .errorMessage(row.containsKey("errorMessage") ? String.valueOf(row.get("errorMmessage")) : null) .data(row.containsKey("status_data") ? row.get("status_data") : new HashMap<>()) .build(); Map m = new HashMap<>(); - m.put("key", row.get("document_binder_uuid")); - m.put("value", kkoMydocApiRespVO); + m.put("key", row.get("envelopeId")); + m.put("value", kkoTalkApiRespVO); return m; } @@ -289,7 +288,7 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate { * @param respMsg * @return */ - private List toSendDetailStatHist(List list, String respMsg) { + private List toSendDetailStatHist(List list, String respMsg) { // Map mMydocApiRespVOByExtDocUuid = @@ -298,34 +297,34 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate { if (EnsErrCd.OK.equals(respVO.getErrCode())) { - List> documents = (List>) ((Map) respVO.getResultInfo()).get("documents"); - Map mRespVOByExtDocUuid = documents.stream() + List> documents = (List>) ((Map) respVO.getResultInfo()).get("envelopes"); + Map mRespVOByExtDocUuid = documents.stream() .map(row -> this.toApiRespVOMap(row)) - .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (KkoMydocApiRespVO) m.get("value"), (k1, k2) -> k1)); + .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> (KkoTalkApiRespVO) m.get("value"), (k1, k2) -> k1)); Gson gson = new GsonBuilder().disableHtmlEscaping().create(); return list.stream() .map(row -> { - KkoMydocApiRespVO apiRespVO = mRespVOByExtDocUuid.get(row.getDocumentBinderUuid()); + KkoTalkApiRespVO apiRespVO = mRespVOByExtDocUuid.get(row.getEnvelopeId()); Map statusData = (Map) apiRespVO.getData(); - return SendDetailKkoMydocStatHist.builder() + return SendDetailKkoTalkStatHist.builder() .sendDetailId(row.getSendDetailId()) - .documentBinderUuid(row.getDocumentBinderUuid()) - .externalDocumentUuid(row.getPropExternalDocumentUuid()) + .envelopeId(row.getEnvelopeId()) + .externalId(row.getExternalId()) // .respRawMsg(gson.toJson(statusData)) - .docBoxStatus(statusData.containsKey("doc_box_status") ? (String) statusData.get("doc_box_status") : null) - .docBoxSentAt(statusData.containsKey("doc_box_sent_at") ? (Long) statusData.get("doc_box_sent_at") : null) - .docBoxReceivedAt(statusData.containsKey("doc_box_received_at") ? (Long) statusData.get("doc_box_received_at") : null) - .authenticatedAt(statusData.containsKey("authenticated_at") ? (Long) statusData.get("authenticated_at") : null) - .tokenUsedAt(statusData.containsKey("token_used_at") ? (Long) statusData.get("token_used_at") : null) - .docBoxReadAt(statusData.containsKey("doc_box_read_at") ? (Long) statusData.get("doc_box_read_at") : null) - .userNotifiedAt(statusData.containsKey("user_notified_at") ? (Long) statusData.get("user_notified_at") : null) - .docDistributionReceivedAt(statusData.containsKey("doc_distribution_received_at") ? (Long) statusData.get("doc_distribution_received_at") : null) + .status(statusData.containsKey("doc_box_status") ? (String) statusData.get("doc_box_status") : null) +// .sentAt(statusData.containsKey("doc_box_sent_at") ? (Long) statusData.get("doc_box_sent_at") : null) +// .receivedAt(statusData.containsKey("doc_box_received_at") ? (Long) statusData.get("doc_box_received_at") : null) +// .authenticatedAt(statusData.containsKey("authenticated_at") ? (Long) statusData.get("authenticated_at") : null) +// .tokenUsedAt(statusData.containsKey("token_used_at") ? (Long) statusData.get("token_used_at") : null) +// .readAt(statusData.containsKey("doc_box_read_at") ? (Long) statusData.get("doc_box_read_at") : null) +// .userNotifiedAt(statusData.containsKey("user_notified_at") ? (Long) statusData.get("user_notified_at") : null) +// .docDistributionReceivedAt(statusData.containsKey("doc_distribution_received_at") ? (Long) statusData.get("doc_distribution_received_at") : null) .payload(statusData.containsKey("payload") ? (String) statusData.get("payload") : null) .error(FieldError.initBuilder() - .errorCode(apiRespVO.getError_code()) - .errorMessage(apiRespVO.getError_message()) + .errorCode(apiRespVO.getErrorCode()) + .errorMessage(apiRespVO.getErrorMessage()) .build()) .build(); }) @@ -334,10 +333,10 @@ public class KkoTalkRsltFetcher extends ResultProcTemplate { } else { return list.stream() .map(row -> { - return SendDetailKkoMydocStatHist.builder() + return SendDetailKkoTalkStatHist.builder() .sendDetailId(row.getSendDetailId()) - .documentBinderUuid(row.getDocumentBinderUuid()) - .externalDocumentUuid(row.getPropExternalDocumentUuid()) + .envelopeId(row.getEnvelopeId()) + .externalId(row.getExternalId()) .error(FieldError.initBuilder() .errorCode(respVO.getErrCode().getCode()) .errorMessage(respVO.getErrMsg())