diff --git a/db/mens-iup-query.sql b/db/mens-iup-query.sql index b58f800..6850ecc 100644 --- a/db/mens-iup-query.sql +++ b/db/mens-iup-query.sql @@ -283,3 +283,13 @@ SELECT etm.* WHERE etm.tmplt_cd='A0001'; +SELECT + TO_CHAR(MIN(run_dt), + 'YYYYMMDD')||'000000000000' AS searchPdFrom , + TO_CHAR(MAX(run_dt+1), + 'YYYYMMDD')||'000000000000' AS searchPdTo + FROM + tb_input_xit + WHERE + send_type = 'NI' + AND prcs_cd = 'IPCP'; 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 483e270..cb2b381 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 @@ -23,13 +23,13 @@ import cokr.xit.ens.modules.nice.model.*; */ @Mapper public interface INiceCiMapper { - List selectNiceCiTgts(final NiceCiDTO.NiceCiParam niceCiParam); - List selectNiceCiAcceptDatas(final NiceCiDTO.NiceCiParam niceCiParam); + List selectInputXits(final NiceCiDTO.NiceCiParam niceCiParam); + List selectInputDataXits(final NiceCiDTO.NiceCiParam niceCiParam); int insertBill(final NiceCiDTO.BillDTO billDTO); int updateBill(final NiceCiDTO.BillDTO billDTO); - //int saveBill(final NiceCiDTO.BillDTO billDTO); - int saveBillKko(final NiceCiDTO.BillKkoDTO billKkoDTO); + + int mergeBillKko(final NiceCiDTO.BillKkoDTO billKkoDTO); int updatePayUrlOfDataInput(final NiceCiDTO.InputDataXit inputDataXit); int updatePrcsCdAndErrorOfInputXit(final NiceCiDTO.InputXit inputXit); Optional selectKkoBpApiUrlFromEnsOrgMng(final String orgCd); @@ -40,9 +40,10 @@ public interface INiceCiMapper { int insertNiceSmsSndngRequest(final NiceCiApiSendDTO.Request requestDTO); int insertNiceSmsSndngResponse(final NiceCiApiSendDTO.Response responseDTO); + Optional selectFromAndToOfStatusParam(final NiceCiDTO.NiceCiParam niceCiParam); Optional selectNiceCiInqireId(); int insertNiceSmsSndngInquireRequest(final NiceCiApiStatusDTO.Request requestDTO); int insertNiceSmsSndngInquireResponse(final NiceCiApiStatusDTO.Response responseDTO); int insertNiceSmsSndngInquireResponseRepeat(final List resultList); - + int mergeSendResult(final NiceCiDTO.SendResult sendResult); } diff --git a/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiApiStatusDTO.java b/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiApiStatusDTO.java index 0bac38b..0ed8e98 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiApiStatusDTO.java +++ b/src/main/java/cokr/xit/ens/modules/nice/model/NiceCiApiStatusDTO.java @@ -84,9 +84,9 @@ public class NiceCiApiStatusDTO { */ @Schema(title = "검색기간 from", example = " ") @Size(min = 20, max = 20, message = "검색기간 from") - private String searchPdFrom = StringUtils.rightPad(StringUtils.EMPTY, 20, StringUtils.SPACE); + private String searchPdFrom; public void setSearchPdFrom(String searchPdFrom) { - this.searchPdFrom = StringUtils.rightPad(nvl(searchPdFrom), 20, StringUtils.SPACE); + this.searchPdFrom = StringUtils.rightPad(nvl(searchPdFrom), 20, "0"); } /** @@ -97,9 +97,9 @@ public class NiceCiApiStatusDTO { */ @Schema(title = "검색기간 to", example = " ") @Size(min = 20, max = 20, message = "검색기간 to") - private String searchPdTo = StringUtils.rightPad(StringUtils.EMPTY, 20, StringUtils.SPACE); + private String searchPdTo; public void setSearchPdTo(String searchPdTo) { - this.searchPdTo = StringUtils.rightPad(nvl(searchPdTo), 20, StringUtils.SPACE); + this.searchPdTo = StringUtils.rightPad(nvl(searchPdTo), 20, "0"); } /** @@ -162,9 +162,9 @@ public class NiceCiApiStatusDTO { */ @Schema(title = "요청건수", example = " ") @Pattern(regexp = "^[\\s\\S]{10}$", message = "요청건수는 10자리(max 100)입니다") - private String requstCo = StringUtils.rightPad(StringUtils.EMPTY, 10, StringUtils.SPACE); + private String requstCo; public void setRequstCo(String requstCo){ - this.requstCo = StringUtils.rightPad(nvl(requstCo), 10, StringUtils.SPACE); + this.requstCo = StringUtils.leftPad(nvl(requstCo), 10, "0"); } /** @@ -176,9 +176,9 @@ public class NiceCiApiStatusDTO { @Schema(title = "누적수신건수", example = " ") @Size(min = 10, max = 10, message = "누적수신건수는 10자리 입니다.") @Pattern(regexp = "^\\d{10}$", message = "요청건수는 10자리(max 100)입니다") - private String accmltRecptnCo = "0000000000"; + private String accmltRecptnCo; public void setAccmltRecptnCo(String accmltRecptnCo) { - this.accmltRecptnCo = StringUtils.rightPad(nvl(accmltRecptnCo), 10, StringUtils.SPACE); + this.accmltRecptnCo = StringUtils.leftPad(nvl(accmltRecptnCo), 10, "0"); } /** 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 b317dbb..1e9bcb6 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 @@ -459,4 +459,75 @@ public class NiceCiDTO { private LocalDateTime lastUpdtDt; } + + @Schema(name = "SendResult DTO", description = "SendResult DTO") + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class SendResult { + /** + * 연계입수아이디 - PK + */ + private Long lnkInputId; + + /** + * 데이터 아이디 - PK + */ + private String dataId; + + /** + * 처리차수 - PK + */ + private String prcsOdr; + + /** + * 발송상태코드 + */ + private String sendSttusCd; + + /** + * 발송구분 : NI:알림톡, KP: 인증톡 + */ + private String sendType; + + /** + * 발송 일시 + */ + private LocalDateTime runDt; + + /** + * 사업자요청일시 + */ + private LocalDateTime bizSendDt; + + /** + * 사업자조회일시 + */ + private LocalDateTime bizRecvDt; + + /** + * 사업자열람일시 + */ + private LocalDateTime bizReadDt; + + /** + * 사업자 오류내용 + */ + private String bizErrMsg; + + /** + * 마감일시 + */ + private LocalDateTime expiresDt; + + /** + * 처리여부 - 엑스아이티 + */ + private String prcsYn; + + private String regId; + + private LocalDateTime regDt; + } } 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 5f57398..8a79e8e 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 @@ -78,7 +78,8 @@ public class NiceCiAcceptService { * -- 4. KkoPayUrlService.callApi() 호출후 tb_input_data_xit 테이블 pay_url 에 청구서 URL UPDATE * KkoPayUrlServiceTest * -- 5. tb_input_xit 테이블 prcs_cd='GRUC' / 실패 시 prcs_cd='TGRF' - * @return + * + * @return EnsResponseVO * */ @Transactional(propagation = Propagation.REQUIRES_NEW) @@ -88,7 +89,7 @@ public class NiceCiAcceptService { .prcsCd(IupPrcsCd.TGRG.getCode()) .build(); - final List list = niceCiMapper.selectNiceCiTgts(niceCiParam); + final List list = niceCiMapper.selectInputXits(niceCiParam); if(list.isEmpty()){ return EnsResponseVO.errBuilder() .errCode(EnsErrCd.ERR404) @@ -98,7 +99,7 @@ public class NiceCiAcceptService { list.forEach(d -> { niceCiParam.setLnkInputId(d.getLnkInputId()); - d.setInputDataXits(niceCiMapper.selectNiceCiAcceptDatas(niceCiParam)); + d.setInputDataXits(niceCiMapper.selectInputDataXits(niceCiParam)); }); @@ -120,8 +121,18 @@ public class NiceCiAcceptService { try { List inputDataXits = xit.getInputDataXits(); for (NiceCiDTO.InputDataXit data : inputDataXits) { + + //---------------------------------------------------------- + // pay Url API call & Get Result START + //---------------------------------------------------------- PayApiRespDTO> respDTO = getPayUrl(data, billHistDTO, orgMng, kkoPayUrlRespData); + //---------------------------------------------------------- + // pay Url API call & Get Result START + //---------------------------------------------------------- + //---------------------------------------------------------- + // API Call 후처리 START - response 반영 & 결제 이력 생성 + //---------------------------------------------------------- // FIXME: API 호출 결과 SET - 연계 설정후 확인 필요 data.setPayUrl(String.valueOf(respDTO.getData())); niceCiMapper.updatePayUrlOfDataInput(data); @@ -143,7 +154,7 @@ public class NiceCiAcceptService { .build() ); // FIXME: biller_notice_key, custom_url, expire_at 설정 및 확인 필요??? - niceCiMapper.saveBillKko( + niceCiMapper.mergeBillKko( NiceCiDTO.BillKkoDTO.builder() .billId(keySequenceService.getKeySequence("BillKko_id")) .billerUserKey(data.getDataId()) @@ -154,7 +165,9 @@ public class NiceCiAcceptService { .billUid(billUid) .build() ); - + //---------------------------------------------------------- + // API Call 후처리 END - response 반영 & 결제 이력 생성 + //---------------------------------------------------------- } xit.setPrcsCd(IupPrcsCd.GRUC.getCode()); diff --git a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiSendBulkService.java b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiSendBulkService.java index e3542af..b5c8055 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiSendBulkService.java +++ b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiSendBulkService.java @@ -45,13 +45,28 @@ public class NiceCiSendBulkService { private final INiceCiMapper niceCiMapper; private Gson gson = new GsonBuilder().disableHtmlEscaping().create(); + /** + *
+     * -- 1. 대상 조회
+     * SELECT *
+     * FROM tb_input_xit tix
+     * WHERE tix.send_type='NI'
+     *   AND tix.prcs_cd='GRUC'
+     *   AND tix.RUN_DT < SYSDATE;
+     *
+     * -- 2. 나이스 연계
+     *
+     * -- 3. tb_input_xit 테이블 prcs_cd='IPCP' / 실패 시 prcs_cd='FAIL'
+     * @return EnsResponseVO
+     * 
> + */ public EnsResponseVO requestSendBulk() { final NiceCiDTO.NiceCiParam niceCiParam = NiceCiDTO.NiceCiParam.builder() .sendType(IupSendTypeCd.NI.getCode()) .prcsCd(IupPrcsCd.GRUC.getCode()) .build(); - final List list = niceCiMapper.selectNiceCiTgts(niceCiParam); + final List list = niceCiMapper.selectInputXits(niceCiParam); if(list.isEmpty()){ return EnsResponseVO.errBuilder() .errCode(EnsErrCd.ERR404) @@ -61,7 +76,7 @@ public class NiceCiSendBulkService { list.forEach(d -> { niceCiParam.setLnkInputId(d.getLnkInputId()); - d.setInputDataXits(niceCiMapper.selectNiceCiAcceptDatas(niceCiParam)); + d.setInputDataXits(niceCiMapper.selectInputDataXits(niceCiParam)); }); for(NiceCiDTO.InputXit xit : list) { @@ -96,17 +111,36 @@ public class NiceCiSendBulkService { ciRequest.getQueryRequests().add(queryRequest); ciRequest.getButtonRequests().add(btnRequest); + //---------------------------------------------------------- + // API Call 전처리 START - request 저장 + //---------------------------------------------------------- ciRequest.setNiceSmsSndngRequstId(niceSmsReqId); ciRequest.setDataId(data.getDataId()); niceCiMapper.insertNiceSmsSndngRequest(ciRequest); + //---------------------------------------------------------- + // API Call 전처리 END - request 저장 + //---------------------------------------------------------- + //---------------------------------------------------------- + // Status API call & Get Result START + //---------------------------------------------------------- // FIXME : 연계 이후 확인 필요 EnsResponseVO responseVO = niceCiApiService.requestSendBulk(ciRequest); if (!EnsErrCd.OK.equals(responseVO.getErrCode())) throw new EnsException(responseVO.getErrCode(), responseVO.getErrMsg()); NiceCiApiSendDTO.Response resDTO = (NiceCiApiSendDTO.Response)responseVO.getResultInfo(); + //---------------------------------------------------------- + // Status API call & Get Result END + //---------------------------------------------------------- + + //---------------------------------------------------------- + // API Call 후처리 START - response 저장 + //---------------------------------------------------------- resDTO.setNiceSmsSndngRequstId(niceSmsReqId); niceCiMapper.insertNiceSmsSndngResponse(resDTO); + //---------------------------------------------------------- + // API Call 후처리 START - response 저장 + //---------------------------------------------------------- log.info(responseVO.toString()); } diff --git a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiStatBulkService.java b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiStatBulkService.java index 8a12516..df3a653 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiStatBulkService.java +++ b/src/main/java/cokr/xit/ens/modules/nice/service/NiceCiStatBulkService.java @@ -46,13 +46,30 @@ public class NiceCiStatBulkService { private final INiceCiMapper niceCiMapper; + /** + *
+     * -- 1. 대상 조회
+     * SELECT *
+     * FROM tb_input_xit tix
+     * WHERE tix.send_type='NI'
+     *   AND tix.prcs_cd='IPCP';
+     *
+     * -- 2.결과 INSERT OR UPDATE tb_send_result
+     * SELECT * FROM tb_send_result;
+     *   send_sttus_cd 발송 처리 코드
+     *   TALK_SEND 카카오 알림톡 발송 성공
+     *   SMS_SEND KT 문자 발송 성공
+     *   FAIL 발송 실패
+     * @return EnsResponseVO
+     * 
+ */ public EnsResponseVO findBulkStatus() { final NiceCiDTO.NiceCiParam niceCiParam = NiceCiDTO.NiceCiParam.builder() .sendType(IupSendTypeCd.NI.getCode()) .prcsCd(IupPrcsCd.IPCP.getCode()) .build(); - final List list = niceCiMapper.selectNiceCiTgts(niceCiParam); + final List list = niceCiMapper.selectInputXits(niceCiParam); if(list.isEmpty()){ return EnsResponseVO.errBuilder() .errCode(EnsErrCd.ERR404) @@ -62,7 +79,7 @@ public class NiceCiStatBulkService { list.forEach(d -> { niceCiParam.setLnkInputId(d.getLnkInputId()); - d.setInputDataXits(niceCiMapper.selectNiceCiAcceptDatas(niceCiParam)); + d.setInputDataXits(niceCiMapper.selectInputDataXits(niceCiParam)); }); for(NiceCiDTO.InputXit xit : list) { @@ -70,6 +87,8 @@ public class NiceCiStatBulkService { try { List inputDataXits = xit.getInputDataXits(); + NiceCiDTO.SendResult sendResult = null; + for (NiceCiDTO.InputDataXit data : inputDataXits) { // 기관전문관리번호, TB_NICE_SMS_SNDNG_REQUEST - NICE_SMS_SNDNG_REQUST_ID @@ -77,7 +96,9 @@ public class NiceCiStatBulkService { () -> new EnsException(EnsErrCd.MAKE521, EnsErrCd.MAKE521.getCodeNm()) ); - NiceCiApiStatusDTO.Request ciRequest = new NiceCiApiStatusDTO.Request(); + // 검색기간 (from ~ to) 조회 및 SET + NiceCiApiStatusDTO.Request ciRequest = niceCiMapper.selectFromAndToOfStatusParam(niceCiParam) + .orElseThrow(() -> new EnsException(EnsErrCd.MAKE521, "검색기간 설정 조회 실패")); NiceCiApiCommon nCommon = new NiceCiApiCommon(); // 공통부 set @@ -87,27 +108,21 @@ public class NiceCiStatBulkService { // 개별요청부 set setNiceCiApiPrivateReq(ciRequest); - // API request 저장 - ciRequest.setNiceSmsSndngInqireId(niceSmsInqId); - niceCiMapper.insertNiceSmsSndngInquireRequest(ciRequest); - - EnsResponseVO responseVO = niceCiApiService.findBulkStatus(ciRequest); - if (!EnsErrCd.OK.equals(responseVO.getErrCode())) - throw new EnsException(responseVO.getErrCode(), responseVO.getErrMsg()); + int totCo = 0; + int repeat = 0; + do { + ciRequest.setAccmltRecptnCo(Integer.toString(repeat)); + NiceCiApiStatusDTO.Response resDTO = repeatStatusBulk( + ciRequest, + xit, + data + //sendResult + ); + if(totCo == 0) totCo = Integer.parseInt(resDTO.getTotCo()); + repeat += 100; + } while(totCo > 100 && totCo > repeat); - NiceCiApiStatusDTO.Response resDTO = (NiceCiApiStatusDTO.Response)responseVO.getResultInfo(); - resDTO.setNiceSmsSndngInqireId(niceSmsInqId); - // API response 저장 - niceCiMapper.insertNiceSmsSndngInquireResponse(resDTO); - - // API response 반복부 저장 - niceCiMapper.insertNiceSmsSndngInquireResponseRepeat( - resDTO.getNiceCiResults() - .stream().peek(d -> d.setNiceSmsSndngInqireId(niceSmsInqId)) - .collect(Collectors.toList())); - - log.info(responseVO.toString()); } } catch (EnsException e) { // FIXME : API 통신에러 인경우 skip - 재시도 되어야 @@ -205,12 +220,82 @@ public class NiceCiStatBulkService { // 개별요청부 : default end //--------------------------------------------------------- - ciRequest.setSearchPdFrom(DateUtil.getNowTimeMicrosecond()); // 검색기간 - from - ciRequest.setSearchPdTo(DateUtil.getNowTimeMicrosecond()); // 검색기간 - to - ciRequest.setRequstCo("?"); // 요청건수 - //ciRequest.setAccmltRecptnCo(); // 누적수신건수 + // selectFromAndToOfStatusParam 에서 SET + // ciRequest.setSearchPdFrom(DateUtil.getNowTimeMicrosecond()); // 검색기간 - from + // ciRequest.setSearchPdTo(DateUtil.getNowTimeMicrosecond()); // 검색기간 - to + ciRequest.setRequstCo("100"); // 요청건수 + ciRequest.setAccmltRecptnCo("0000000000"); // 누적수신건수 //////////////////////////////////////////////////////////// // 개별요청부 END //////////////////////////////////////////////////////////// } + + private NiceCiApiStatusDTO.Response repeatStatusBulk( + NiceCiApiStatusDTO.Request ciRequest, + NiceCiDTO.InputXit xit, + NiceCiDTO.InputDataXit data){ + // 기관전문관리번호, TB_NICE_SMS_SNDNG_REQUEST - NICE_SMS_SNDNG_REQUST_ID + final String niceSmsInqId = niceCiMapper.selectNiceCiInqireId().orElseThrow( + () -> new EnsException(EnsErrCd.MAKE521, EnsErrCd.MAKE521.getCodeNm()) + ); + + //---------------------------------------------------------- + // API Call 전처리 START - request & 결과테이블 저장 + //---------------------------------------------------------- + ciRequest.setNiceSmsSndngInqireId(niceSmsInqId); + niceCiMapper.insertNiceSmsSndngInquireRequest(ciRequest); + + NiceCiDTO.SendResult sendResult = NiceCiDTO.SendResult.builder() + .lnkInputId(xit.getLnkInputId()) + .dataId(data.getDataId()) + .prcsOdr("1") + .sendType(xit.getSendType()) + .runDt(xit.getRunDt()) + .expiresDt(xit.getExpiresDt()) + .prcsYn("N") + .build(); + + // 결과 테이블 데이타 생성 or update + niceCiMapper.mergeSendResult(sendResult); + //---------------------------------------------------------- + // API Call 전처리 END - request & 결과테이블 저장 + //---------------------------------------------------------- + + //---------------------------------------------------------- + // Status API call & Get Result START + //---------------------------------------------------------- + EnsResponseVO responseVO = niceCiApiService.findBulkStatus(ciRequest); + if (!EnsErrCd.OK.equals(responseVO.getErrCode())) + throw new EnsException(responseVO.getErrCode(), responseVO.getErrMsg()); + + NiceCiApiStatusDTO.Response resDTO = (NiceCiApiStatusDTO.Response)responseVO.getResultInfo(); + //---------------------------------------------------------- + // Status API call & Get Result END + //---------------------------------------------------------- + + //---------------------------------------------------------- + // API Call 후처리 START - response & 결과테이블 저장 + //---------------------------------------------------------- + // API response 저장 + resDTO.setNiceSmsSndngInqireId(niceSmsInqId); + niceCiMapper.insertNiceSmsSndngInquireResponse(resDTO); + + // API response 반복부 저장 + niceCiMapper.insertNiceSmsSndngInquireResponseRepeat( + resDTO.getNiceCiResults() + .stream().peek(d -> d.setNiceSmsSndngInqireId(niceSmsInqId)) + .collect(Collectors.toList())); + + + // FIXME: 아래 값으로 set + //mssageSndngResultSe 1 -> TALK_SEND, 2 -> SMS_SEND, FAIL + // 결과 테이블 데이타 update + sendResult.setSendSttusCd(""); + niceCiMapper.mergeSendResult(sendResult); + //---------------------------------------------------------- + // API Call 후처리 END - response & 결과테이블 저장 + //---------------------------------------------------------- + + return resDTO; + } } 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 bf4ea86..6add527 100644 --- a/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml +++ b/src/main/resources/mybatis-mapper/modules/iup-niceci-mapper.xml @@ -6,8 +6,8 @@ - + /** iup-niceci-mapper|selectInputXits-NICE CI 대상 조회|julim */ SELECT lnk_input_id , err_msg , expires_dt @@ -31,8 +31,8 @@ - + /** iup-niceci-mapper|selectInputDataXits-NICE CI 발송 대상 조회|julim */ SELECT data_id , birthday , call_center_no @@ -86,8 +86,8 @@ - - /** iup-niceci-mapper|saveBill-NICE CI 청구서 생성|julim */ + + /** iup-niceci-mapper|mergeBill-NICE CI 청구서 생성|julim */ MERGE INTO ens_bill_kko USING DUAL @@ -176,7 +176,13 @@ FROM ens_org_mng WHERE org_cd = #{orgCd} + + + + + + + /** iup-niceci-mapper|selectFromAndToOfStatusParam-상태조회 조회시작일과 종료일 조회|julim */ + SELECT TO_CHAR(MIN(run_dt), 'YYYYMMDD')||'000000000000' AS searchPdFrom + , TO_CHAR(MAX(run_dt+1), 'YYYYMMDD')||'000000000000' AS searchPdTo + FROM tb_input_xit + WHERE send_type = #{sendType} + AND prcs_cd = #{prcsCd} +