diff --git a/src/main/java/cokr/xit/ens/modules/nice/model/NiceDTO.java b/src/main/java/cokr/xit/ens/modules/nice/model/NiceDTO.java index 245897e..47bc473 100644 --- a/src/main/java/cokr/xit/ens/modules/nice/model/NiceDTO.java +++ b/src/main/java/cokr/xit/ens/modules/nice/model/NiceDTO.java @@ -15,7 +15,9 @@ import lombok.*; /** *
- * description : + * description : Nice CI 전문 DTO + * Builder 패턴 사용 X + * -> setter를 사용 필드 길이 고정 필요 * packageName : cokr.xit.ens.modules.nice.model * fileName : NiceDTO * author : limju @@ -33,7 +35,6 @@ public class NiceDTO { @Data @NoArgsConstructor @AllArgsConstructor - @Builder public static class NiceRequest implements Serializable { private static final long serialVersionUID = 1L; @@ -48,7 +49,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "TR Code", example = " ") @Size(min = 0, max = 9, message = "트랜잭션 코드는 0~9자리 입니다.") - @Builder.Default private String trCode = StringUtils.rightPad(StringUtils.EMPTY, 9, StringUtils.SPACE); public void setTrCode(String trCode) { this.trCode = StringUtils.rightPad(nvl(trCode), 9, StringUtils.SPACE); @@ -69,7 +69,6 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 16, max = 16, message = "공란(16자리)") - @Builder.Default private String commonEmptyField = StringUtils.rightPad(StringUtils.EMPTY, 16, StringUtils.SPACE); /** @@ -79,7 +78,6 @@ public class NiceDTO { */ @Schema(title = "조회동의사유", example = " ") @Size(min = 1, max = 1, message = "조회동의사유는 1자리 입니다") - @Builder.Default private String queryConsentReason = StringUtils.SPACE; //---------------------------------------------------------------------------------------------- @@ -96,7 +94,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "조회사유", example = " ") @Size(min = 2, max = 2, message = "조회사유는 2자리 입니다") - @Builder.Default private String queryReason = StringUtils.rightPad(StringUtils.EMPTY, 2, StringUtils.SPACE); public void setQueryReason(String queryReason) { this.queryReason = StringUtils.rightPad(nvl(queryReason), 1, StringUtils.SPACE); @@ -110,10 +107,9 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "조회요청건수", example = " ") @Max(value = 48, message = "조회요청 최대건수는 48입니다") - @Builder.Default private String queryReqCnt = StringUtils.rightPad(StringUtils.EMPTY, 2, StringUtils.SPACE); public void setQueryReqCnt(Integer queryReqCnt) { - this.queryReqCnt = StringUtils.rightPad(nvl(queryReqCnt == null? "": queryReqCnt.toString()), 1, StringUtils.SPACE); + this.queryReqCnt = StringUtils.rightPad(nvl(queryReqCnt == null? "": queryReqCnt.toString()), 2, StringUtils.SPACE); } /** @@ -128,7 +124,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "SMS발송요청구분코드", example = " ", allowableValues = {"0", "1", "2", "3"}) @Pattern(regexp = "[0-3]", message = "SMS발송요청구분코드 0 ~ 3 입니다(1자리)") - @Builder.Default private String smsSndReqCode = StringUtils.SPACE;; /** @@ -139,7 +134,6 @@ public class NiceDTO { */ @Schema(title = "SMS 발송메세지", example = " ") @Pattern(regexp = "^$|[\\s]{10,2000}", message = "SMS발송메세지는 10 ~ 2000자리 입니다") - @Builder.Default private String sndMessage = StringUtils.rightPad(StringUtils.EMPTY, 2000, StringUtils.SPACE); public void setSndMessage(String sndMessage) { this.sndMessage = StringUtils.rightPad(nvl(sndMessage), 2000, StringUtils.SPACE); @@ -153,7 +147,6 @@ public class NiceDTO { */ @Schema(title = "SMS 발신번호", example = " ") @Pattern(regexp = "^$|[\\d]{3,12}", message = "SMS 발신번호는 3 ~ 12자리 입니다") - @Builder.Default private String sndPhoneNo = StringUtils.rightPad(StringUtils.EMPTY, 12, StringUtils.SPACE); public void setSndPhoneNo(String sndPhoneNo) { this.sndPhoneNo = StringUtils.rightPad(nvl(sndPhoneNo), 12, StringUtils.SPACE); @@ -170,7 +163,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "연락처조회구분코드", example = " ", allowableValues = {"1", "2", "3"}) @Pattern(regexp = "[1-3]", message = "연락처조회구분 코드는 1 ~ 3 입니다(1자리)") - @Builder.Default private String contactSearchCode = "3"; /** @@ -180,7 +172,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "알림톡발송요청구분", example = " ") @Size(min = 1, max = 1, message = "알림톡발송요청구분 코드는 1자리 입니다") - @Builder.Default private String alimtalkSndReqDiv = StringUtils.SPACE; /** @@ -190,7 +181,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "알림톡발송요청구분", example = " ") @Size(min = 100, max = 100, message = "알림톡발송요청구분 코드는 1자리 입니다") - @Builder.Default private String alimtalkTmpltCode = StringUtils.rightPad(StringUtils.EMPTY, 100, StringUtils.SPACE); public void setAlimtalkTmpltCode(String alimtalkTmpltCode) { this.alimtalkTmpltCode = StringUtils.rightPad(nvl(alimtalkTmpltCode), 100, StringUtils.SPACE); @@ -204,11 +194,9 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "조회요청건수", example = " ") @Max(value = 5, message = "조회요청 최대건수는 48입니다") - @Builder.Default private String btnReqCnt = StringUtils.SPACE; public void setBtnReqCnt(Integer btnReqCnt) { - this.btnReqCnt = StringUtils.rightPad(nvl(btnReqCnt == null ? "" : btnReqCnt.toString()), 1, - StringUtils.SPACE); + this.btnReqCnt = StringUtils.rightPad(nvl(btnReqCnt == null ? "" : btnReqCnt.toString()), 2, StringUtils.SPACE); } /** @@ -218,7 +206,6 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 880, max = 880, message = "공란(880자리)") - @Builder.Default private String privateEmptyField = StringUtils.rightPad(StringUtils.EMPTY, 880, StringUtils.SPACE); //---------------------------------------------------------------------------------------------- // 개별요청부 : 3000 자리 @@ -240,11 +227,11 @@ public class NiceDTO { // 버튼요청부 반복: 3000 자리 //---------------------------------------------------------------------------------------------- - public String getAsString() { + public String ofString() { StringBuilder sb = new StringBuilder(); sb.append(trCode); // 공통부 - sb.append(niceCommon.getAsString()); + sb.append(niceCommon.ofString()); sb.append(commonEmptyField); sb.append(queryConsentReason); @@ -259,8 +246,8 @@ public class NiceDTO { sb.append(alimtalkTmpltCode); sb.append(btnReqCnt); sb.append(privateEmptyField); - sb.append(queryRequests.stream().map(QueryRequest::getAsString).collect(Collectors.joining())); - sb.append(buttonRequests.stream().map(ButtonRequest::getAsString).collect(Collectors.joining())); + sb.append(queryRequests.stream().map(QueryRequest::ofString).collect(Collectors.joining())); + sb.append(buttonRequests.stream().map(ButtonRequest::ofString).collect(Collectors.joining())); return sb.toString(); } } @@ -270,7 +257,6 @@ public class NiceDTO { @Data @NoArgsConstructor @AllArgsConstructor - @Builder public static class NiceResponse implements Serializable { private static final long serialVersionUID = 1L; @@ -285,7 +271,6 @@ public class NiceDTO { */ @Schema(title = "TR Code", example = " ") @Size(min = 0, max = 9, message = "트랜잭션 코드는 0~9자리 입니다.") - @Builder.Default private String trCode = StringUtils.rightPad(StringUtils.EMPTY, 9, StringUtils.SPACE); public void setTrCode(String trCode) { this.trCode = StringUtils.rightPad(nvl(trCode), 9, StringUtils.SPACE); @@ -305,7 +290,6 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 16, max = 17, message = "공란(17자리)") - @Builder.Default private String commonEmptyField = StringUtils.rightPad(StringUtils.EMPTY, 17, StringUtils.SPACE); //---------------------------------------------------------------------------------------------- // 공통부 : 100 자리 @@ -322,10 +306,9 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "응답 건수", example = " ") @Max(value = 48, message = "응답 최대건수는 48입니다") - @Builder.Default private String resCnt = StringUtils.rightPad(StringUtils.EMPTY, 2, StringUtils.SPACE); - public void setResCnt(String resCnt) { - this.resCnt = StringUtils.rightPad(nvl(resCnt), 2, StringUtils.SPACE); + public void setResCnt(Integer resCnt) { + this.resCnt = StringUtils.rightPad(nvl(resCnt == null ? "" : resCnt.toString()), 2, StringUtils.SPACE); } /** @@ -340,7 +323,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "SMS발송요청구분코드", example = " ", allowableValues = {"0", "1", "2", "3"}) @Pattern(regexp = "[0-3]", message = "SMS발송요청구분코드 0 ~ 3 입니다(1자리)") - @Builder.Default private String smsSndReqCode = StringUtils.SPACE;; /** @@ -351,7 +333,6 @@ public class NiceDTO { */ @Schema(title = "SMS 발송메세지", example = " ") @Pattern(regexp = "^$|[\\s]{10,2000}", message = "SMS발송메세지는 10 ~ 2000자리 입니다") - @Builder.Default private String sndMessage = StringUtils.rightPad(StringUtils.EMPTY, 2000, StringUtils.SPACE); public void setSndMessage(String sndMessage) { this.sndMessage = StringUtils.rightPad(nvl(sndMessage), 2000, StringUtils.SPACE); @@ -365,7 +346,6 @@ public class NiceDTO { */ @Schema(title = "SMS 발신번호", example = " ") @Pattern(regexp = "^$|[\\d]{3,12}", message = "SMS 발신번호는 3 ~ 12자리 입니다") - @Builder.Default private String sndPhoneNo = StringUtils.rightPad(StringUtils.EMPTY, 12, StringUtils.SPACE); public void setSndPhoneNo(String sndPhoneNo) { this.sndPhoneNo = StringUtils.rightPad(nvl(sndPhoneNo), 12, StringUtils.SPACE); @@ -382,7 +362,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "연락처조회구분코드", example = " ", allowableValues = {"1", "2", "3"}) @Pattern(regexp = "[1-3]", message = "연락처조회구분 코드는 1 ~ 3 입니다(1자리)") - @Builder.Default private String contactSearchCode = "3"; /** @@ -392,7 +371,6 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 84, max = 84, message = "공란(84자리)") - @Builder.Default private String privateEmptyField = StringUtils.rightPad(StringUtils.EMPTY, 84, StringUtils.SPACE); //---------------------------------------------------------------------------------------------- // 개별응답부 : 2100 자리 @@ -406,10 +384,10 @@ public class NiceDTO { // 응답반복부 : 110 자리 //---------------------------------------------------------------------------------------------- - public String getAsString() { + public String ofString() { StringBuilder sb = new StringBuilder(); sb.append(trCode); - sb.append(niceCommon.getAsString()); + sb.append(niceCommon.ofString()); sb.append(commonEmptyField); sb.append(resCnt); sb.append(smsSndReqCode); @@ -417,16 +395,66 @@ public class NiceDTO { sb.append(sndPhoneNo); sb.append(contactSearchCode); sb.append(privateEmptyField); - sb.append(resResults.stream().map(ResResult::getAsString).collect(Collectors.joining())); + sb.append(resResults.stream().map(ResResult::ofString).collect(Collectors.joining())); return sb.toString(); } + + public NiceResponse parse(String tgtString) { + final int[] parseLength = { + 9, // tr-code + 83, // 공통부 + 17, // 공란 + 2, // 응답건수 + 1, // SMS발송요청구분코드 + 2000, // SMS 발송메세지 + 12, // SMS 발신번호 + 1, // 연락처조회구분 + 84, // 공란 + }; + + if (StringUtils.isNotBlank(tgtString) && tgtString.length() >= 2319) { + NiceResponse nr = new NiceResponse(); + int idx = 0; + nr.setTrCode(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setNiceCommon(NiceCommon.parse(tgtString)); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setCommonEmptyField(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setResCnt(Integer.valueOf(StringUtils.left(tgtString, parseLength[idx]))); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setSmsSndReqCode(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setSndMessage(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setSndPhoneNo(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setContactSearchCode(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nr.setPrivateEmptyField(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx]); + + if(tgtString.length() % 110 == 0){ + int repeat = tgtString.length() / 110; + String finalTgtString = tgtString; + ListresResults = IntStream.range(0, repeat) + .mapToObj(i -> { + String currentString = finalTgtString.substring(i * 110, (i + 1) * 110); + return ResResult.parse(currentString); + }) + .collect(Collectors.toList()); + nr.setResResults(resResults); + } + return nr; + } + return null; + } } @Schema(name = "QueryRequest", description = "NICE CI 조회 요청 DTO") @Data @NoArgsConstructor @AllArgsConstructor - @Builder public static class QueryRequest { /** * @@ -436,7 +464,6 @@ public class NiceDTO { */ @Schema(title = "개인/사업자/법인구분", example = "1") @Size(min = 1, max = 1, message = "개인/사업자/법인구분은 1자리 입니다.") - @Builder.Default private String idDiv = "1"; /** @@ -446,7 +473,6 @@ public class NiceDTO { */ @Schema(title = "주민번호", example = " ") @Size(min = 13, max = 13, message = "주민번호는 13자리 입니다.") - @Builder.Default private String jumin = StringUtils.rightPad(StringUtils.EMPTY, 13, StringUtils.SPACE); public void setJumin(String jumin) { this.jumin = StringUtils.rightPad(nvl(jumin), 13, StringUtils.SPACE); @@ -459,10 +485,9 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 36, max = 36, message = "공란(36자리)") - @Builder.Default private String emptyField = StringUtils.rightPad(StringUtils.EMPTY, 36, StringUtils.SPACE); - public String getAsString() { + public String ofString() { StringBuilder sb = new StringBuilder(); sb.append(idDiv); sb.append(jumin); @@ -475,7 +500,6 @@ public class NiceDTO { @Data @NoArgsConstructor @AllArgsConstructor - @Builder public static class ButtonRequest { /** *@@ -485,7 +509,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "버튼타입", example = " ", allowableValues = {"WL", "AL"}) @Pattern(regexp = "[WL|AL]", message = "버튼 타입은 2자리 입니다.") - @Builder.Default private String btnType = "WL"; public void setBtnType(String btnType) { this.btnType = StringUtils.rightPad(nvl(btnType), 2, StringUtils.SPACE); @@ -498,7 +521,6 @@ public class NiceDTO { */ @Schema(title = "버튼이름", example = "1") @Size(min = 56, max = 56, message = "버튼이름은 56자리 입니다.") - @Builder.Default private String btnName = StringUtils.rightPad(StringUtils.EMPTY, 56, StringUtils.SPACE); public void setBtnName(String jumin) { this.btnName = StringUtils.rightPad(nvl(btnName), 56, StringUtils.SPACE); @@ -512,7 +534,6 @@ public class NiceDTO { */ @Schema(title = "버튼URL웹링크1", example = " ") @Size(min = 1000, max = 1000, message = "버튼URL웹링크1 은 1000자리 입니다.") - @Builder.Default private String btnUrlWebLink1 = StringUtils.rightPad(StringUtils.EMPTY, 1000, StringUtils.SPACE); public void setBtnUrlWebLink1(String btnUrlWebLink1) { this.btnUrlWebLink1 = StringUtils.rightPad(nvl(btnUrlWebLink1), 1000, StringUtils.SPACE); @@ -526,7 +547,6 @@ public class NiceDTO { */ @Schema(title = "버튼URL웹링크2", example = " ") @Size(min = 1000, max = 1000, message = "버튼URL웹링크2 은 1000자리 입니다.") - @Builder.Default private String btnUrlWebLink2 = StringUtils.rightPad(StringUtils.EMPTY, 1000, StringUtils.SPACE); public void setBtnUrlWebLink2(String btnUrlWebLink2) { this.btnUrlWebLink2 = StringUtils.rightPad(nvl(btnUrlWebLink2), 1000, StringUtils.SPACE); @@ -539,10 +559,9 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 942, max = 942, message = "공란(36자리)") - @Builder.Default private String emptyField = StringUtils.rightPad(StringUtils.EMPTY, 942, StringUtils.SPACE); - public String getAsString() { + public String ofString() { StringBuilder sb = new StringBuilder(); sb.append(btnType); sb.append(btnName); @@ -557,7 +576,6 @@ public class NiceDTO { @Data @NoArgsConstructor @AllArgsConstructor - @Builder public static class ResResult { /** *@@ -567,7 +585,7 @@ public class NiceDTO { */ @Schema(title = "개인/사업자/법인구분", example = "1") @Size(min = 1, max = 1, message = "개인/사업자/법인구분은 1자리 입니다.") - @Builder.Default + @Setter private String idDiv = "1"; /** @@ -577,7 +595,6 @@ public class NiceDTO { */ @Schema(title = "주민번호", example = " ") @Size(min = 13, max = 13, message = "주민번호는 13자리 입니다.") - @Builder.Default private String jumin = StringUtils.rightPad(StringUtils.EMPTY, 13, StringUtils.SPACE); public void setJumin(String jumin) { this.jumin = StringUtils.rightPad(nvl(jumin), 13, StringUtils.SPACE); @@ -590,7 +607,6 @@ public class NiceDTO { */ @Schema(title = "이름", example = " ") @Size(min = 20, max = 20, message = "이름은 20자리 입니다.") - @Builder.Default private String name = StringUtils.rightPad(StringUtils.EMPTY, 20, StringUtils.SPACE); public void setName(String name) { this.name = StringUtils.rightPad(nvl(name), 20, StringUtils.SPACE); @@ -603,7 +619,6 @@ public class NiceDTO { */ @Schema(title = "1순위연락처", example = " ") @Size(min = 11, max = 11, message = "1순위연락처는 11자리 입니다.") - @Builder.Default private String contractOf1st = StringUtils.rightPad(StringUtils.EMPTY, 11, StringUtils.SPACE); public void setContractOf1st(String contractOf1st) { this.contractOf1st = StringUtils.rightPad(nvl(contractOf1st), 11, StringUtils.SPACE); @@ -616,7 +631,6 @@ public class NiceDTO { */ @Schema(title = "2순위연락처", example = " ") @Size(min = 11, max = 11, message = "2순위연락처는 11자리 입니다.") - @Builder.Default private String contractOf2nd = StringUtils.rightPad(StringUtils.EMPTY, 11, StringUtils.SPACE); public void setContractOf2nd(String contractOf2nd) { this.contractOf2nd = StringUtils.rightPad(nvl(contractOf2nd), 11, StringUtils.SPACE); @@ -629,7 +643,6 @@ public class NiceDTO { */ @Schema(title = "3순위연락처", example = " ") @Size(min = 11, max = 11, message = "3순위연락처는 11자리 입니다.") - @Builder.Default private String contractOf3rd = StringUtils.rightPad(StringUtils.EMPTY, 11, StringUtils.SPACE); public void setContractOf3rd(String contractOf3rd) { this.contractOf3rd = StringUtils.rightPad(nvl(contractOf3rd), 11, StringUtils.SPACE); @@ -646,8 +659,7 @@ public class NiceDTO { **/ @Schema(title = "결과구분코드", example = " ", allowableValues = {"00", "01", "02", "10", "99"}) - @Size(min = 11, max = 11, message = "결과구분코드는 2자리 입니다.") - @Builder.Default + @Size(min = 2, max = 2, message = "결과구분코드는 2자리 입니다.") private String rsltDivCode = StringUtils.rightPad(StringUtils.EMPTY, 2, StringUtils.SPACE); public void setRsltDivCode(String rsltDivCode) { this.rsltDivCode = StringUtils.rightPad(nvl(rsltDivCode), 2, StringUtils.SPACE); @@ -664,7 +676,7 @@ public class NiceDTO { */ @Schema(title = "SMS발송연락처순위", example = " ", allowableValues = {"0", "1", "2", "3"}) @Size(min = 1, max = 1, message = "SMS발송연락처순위는 1자리 입니다.") - @Builder.Default + @Setter private String smsSndContractOrder = "1"; /** @@ -674,7 +686,6 @@ public class NiceDTO { */ @Schema(title = "SMS발송연락처번호", example = " ") @Size(min = 11, max = 11, message = "SMS발송연락처번호는 11자리 입니다.") - @Builder.Default private String smsSndContractNo = StringUtils.rightPad(StringUtils.EMPTY, 11, StringUtils.SPACE); public void setSmsSndContractNo(String smsSndContractNo) { this.smsSndContractNo = StringUtils.rightPad(nvl(smsSndContractNo), 11, StringUtils.SPACE); @@ -687,7 +698,6 @@ public class NiceDTO { */ @Schema(title = "SMS발송예정일시", example = " ") @Size(min = 14, max = 14, message = "SMS발송예정일시는 14자리 입니다.") - @Builder.Default private String smsSndWillDt = StringUtils.rightPad(StringUtils.EMPTY, 14, StringUtils.SPACE); public void setSmsSndWillDt(String smsSndWillDt) { this.smsSndWillDt = StringUtils.rightPad(nvl(smsSndWillDt), 14, StringUtils.SPACE); @@ -700,10 +710,10 @@ public class NiceDTO { */ @Schema(title = "공란", example = " ") @Size(min = 15, max = 15, message = "공란(36자리)") - @Builder.Default + @Setter private String emptyField = StringUtils.rightPad(StringUtils.EMPTY, 15, StringUtils.SPACE); - public String getAsString() { + public String ofString() { StringBuilder sb = new StringBuilder(); sb.append(idDiv); sb.append(jumin); @@ -718,13 +728,56 @@ public class NiceDTO { sb.append(emptyField); return sb.toString(); } + + public static ResResult parse(String tgtString) { + final int[] parseLength = { + 1, // 개인.사업자.법인구분 + 13, // 주민번호 + 20, // 성명 + 11, // 1순위 연락처 + 11, // 2순위 연락처 + 11, // 3순위 연락처 + 2, // 결과구분 + 1, // SMS발송 연락처 순위 + 11, // SMS발송 연락처 번호 + 14, // SMS발송(예정)일시 + 15, // 공란 + }; + + if (StringUtils.isNotBlank(tgtString) && tgtString.length()%110 == 0) { + ResResult rr = new ResResult(); + int idx = 0; + rr.setIdDiv(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setJumin(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setName(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setContractOf1st(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setContractOf2nd(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setContractOf3rd(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setRsltDivCode(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setSmsSndContractOrder(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setSmsSndContractNo(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setSmsSndWillDt(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + rr.setEmptyField(StringUtils.left(tgtString, parseLength[idx])); + return rr; + } + return null; + } } @Schema(name = "NiceCommon", description = "NICE CI 전문 공통 DTO") @Data @NoArgsConstructor @AllArgsConstructor - @Builder public static class NiceCommon { /** *@@ -734,7 +787,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "전문그룹코드(9자리)", example = "NICEIF ") @Size(min = 9, max = 9, message = "전문그룹코드는 9자리 입니다.") - @Builder.Default private String grpCode = "NICEIF "; public void setGrpCode(String grpCode) { this.grpCode = StringUtils.rightPad(nvl(grpCode), 9, StringUtils.SPACE); @@ -749,7 +801,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "거래종별코드(4자리)", example = "0200") @Size(min = 4, max = 4, message = "거래 종별 코드는 4자리 입니다.") - @Builder.Default private String trType = "0200"; public void setTrType(String trType) { this.trType = StringUtils.rightPad(nvl(trType), 4, StringUtils.SPACE); @@ -763,7 +814,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "거래구분코드(5자리)", example = "31895") @Size(min = 5, max = 5, message = "거래 구분 코드는 5자리 입니다.") - @Builder.Default private String trClassification = "31895"; public void setTrClassification(String trClassification) { this.trClassification = StringUtils.rightPad(nvl(trClassification), 5, StringUtils.SPACE); @@ -778,7 +828,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "송수신플래그(1자리)", example = "B") @Size(min = 1, max = 1, message = "송수신 플래그는 1자리 입니다.") - @Builder.Default private String sndAndRcvFlag = "B"; /** @@ -789,7 +838,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "단말기구분(3자리)", example = "503") @Size(min = 1, max = 1, message = "단말기 구분은 3자리 입니다.") - @Builder.Default private String deviceClassification = "503"; public void setDeviceClassification(String deviceClassification) { this.deviceClassification = StringUtils.rightPad(nvl(deviceClassification), 3, StringUtils.SPACE); @@ -812,7 +860,6 @@ public class NiceDTO { */ @Schema(title = "응답코드(4자리)", example = " ") @Pattern(regexp = "^$|^[P|E|S][\\d]{3}$", message = "응답코드(4자리)는 4자리 입니다") - @Builder.Default private String rsltCode = StringUtils.rightPad(StringUtils.EMPTY, 4, StringUtils.SPACE); public void setRsltCode(String rsltCode) { this.rsltCode = StringUtils.rightPad(nvl(rsltCode), 4, StringUtils.SPACE); @@ -826,7 +873,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "참가기관ID(9자리)", example = "503") @Size(min = 9, max = 9, message = "참가기관ID는 3자리 입니다.") - @Builder.Default private String orgId = StringUtils.rightPad(StringUtils.EMPTY, 9, StringUtils.SPACE); public void setOrgId(String orgId) { this.orgId = StringUtils.rightPad(nvl(orgId), 9, StringUtils.SPACE); @@ -840,7 +886,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "기관전문관리번호(10자리)", example = " ") @Size(min = 10, max = 10, message = "기관전문관리번호는 10자리 입니다.") - @Builder.Default private String orgMngNo = StringUtils.rightPad(StringUtils.EMPTY, 10, StringUtils.SPACE); public void setOrgMngNo(String orgMngNo) { this.orgMngNo = StringUtils.rightPad(nvl(orgMngNo), 10, StringUtils.SPACE); @@ -854,7 +899,6 @@ public class NiceDTO { */ @Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "기관전문전송시간(14자리)", example = " ") @Size(min = 14, max = 14, message = "기관전문전송시간은 14자리 입니다.") - @Builder.Default private String orgSndDt = DateUtil.getTodayAndNowTime("yyyyMMddHHmmss"); public void setOrgSndDt(String orgSndDt) { this.orgSndDt = StringUtils.rightPad(nvl(orgSndDt), 14, StringUtils.SPACE); @@ -868,7 +912,6 @@ public class NiceDTO { */ @Schema(title = "NICE전문관리번호(10자리)", example = " ") @Size(min = 10, max = 10, message = "NICE전문관리번호 10자리 입니다.") - @Builder.Default private String niceMngNo = StringUtils.rightPad(StringUtils.EMPTY, 10, StringUtils.SPACE); public void setNiceMngNo(String niceMngNo) { this.niceMngNo = StringUtils.rightPad(nvl(niceMngNo), 10, StringUtils.SPACE); @@ -882,13 +925,12 @@ public class NiceDTO { */ @Schema(title = "NICE전문전송시간(14자리)", example = " ") @Size(min = 14, max = 14, message = "NICE전문전송시간은 14자리 입니다.") - @Builder.Default private String niceSndDt = StringUtils.rightPad(StringUtils.EMPTY, 14, StringUtils.SPACE); public void setNiceSndDt(String niceSndDt) { this.niceSndDt = StringUtils.rightPad(nvl(niceSndDt), 14, StringUtils.SPACE); } - public String getAsString() { + public String ofString() { StringBuilder sb = new StringBuilder(); sb.append(grpCode); sb.append(trType); @@ -903,6 +945,50 @@ public class NiceDTO { sb.append(niceSndDt); return sb.toString(); } + + public static NiceCommon parse(String tgtString) { + final int[] parseLength = { + 9, // 전문그룹코드 + 4, // 거래종별코드 + 5, // 거래구분코드 + 1, // 송수신Flag + 3, // 단말기구분 + 4, // 응답코드 + 9, // 참가기관ID + 10, // 기관전문관리번호 + 14, // 기관전문전송시간 + 10, //NICE 전문관리번호 + 14 // NICE 전문전송시간 + }; + + if (StringUtils.isNotBlank(tgtString) && tgtString.length() >= 83) { + NiceCommon nc = new NiceCommon(); + int idx = 0; + nc.setGrpCode(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setTrType(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setTrClassification(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setSndAndRcvFlag(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setDeviceClassification(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setRsltCode(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setOrgId(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setOrgMngNo(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setOrgSndDt(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setNiceMngNo(StringUtils.left(tgtString, parseLength[idx])); + tgtString = tgtString.substring(parseLength[idx++]); + nc.setNiceSndDt(StringUtils.left(tgtString, parseLength[idx])); + return nc; + } + return null; + } } @@ -927,9 +1013,15 @@ public class NiceDTO { // 공통부 NiceCommon nc = new NiceCommon(); - // nc.setRsltCode(StringUtils.EMPTY); - // nc.setOrgId("orgId"); - // nc.setOrgMngNo("orgMngNo"); + // nc.setGrpCode("grpCode"); + // nc.setTrType("Type"); + // nc.setTrClassification("trClassification"); + nc.setRsltCode("rslt"); + nc.setOrgId("orgId"); + nc.setOrgMngNo("orgMngNo"); + nc.setOrgSndDt("orgSndDt"); + nc.setNiceMngNo("niceMngNo"); + nc.setNiceSndDt("niceSndDt"); QueryRequest qr = new QueryRequest(); ButtonRequest br = new ButtonRequest(); @@ -944,43 +1036,45 @@ public class NiceDTO { - String fullText = nr.getAsString(); + String fullText = nr.ofString(); System.out.println(String.format("[%s] %d", fullText, fullText.length())); - NiceCommon nc2 = NiceCommon.builder() - .build(); - QueryRequest qr2 = QueryRequest.builder() - .idDiv("1") - .jumin("1234567890123") - .build(); - ButtonRequest br2 = ButtonRequest.builder() - .btnType("12") - .build(); - - NiceRequest nr2 = NiceRequest.builder() - .trCode("trCode") - .niceCommon(nc2) - .queryRequests(Collections.singletonList(qr2)) - .buttonRequests(Collections.singletonList(br2)) - .build(); - - String fullText2 = nr2.getAsString(); - System.out.println(String.format("[%s] %d", fullText2, fullText2.length())); - ResResult resResult = new ResResult(); - ResResult resResult2 = ResResult.builder().build(); + resResult.setIdDiv("1"); + resResult.setJumin("1234567890123"); + resResult.setName("name1"); + resResult.setRsltDivCode("00"); + System.out.println(resResult.ofString().length()); + + ResResult resResult2 = new ResResult(); + resResult.setIdDiv("1"); + resResult.setJumin("1234567890"); + resResult.setName("name2"); + resResult.setRsltDivCode("00"); + System.out.println(resResult.ofString().length()); NiceResponse res = new NiceResponse(); + res.setTrCode("trCode"); + res.setResCnt(24); + res.setSmsSndReqCode("1"); + res.setSndMessage("~~~~~~~~~~~~~~~~~~~~~~~"); + res.setSndPhoneNo("010"); + res.setContactSearchCode("1"); + res.setNiceCommon(nc); res.resResults.add(resResult); - NiceResponse res2 = NiceResponse.builder() - .niceCommon(nc2) - .resResults(Collections.singletonList(resResult2)) - .build(); + res.resResults.add(resResult2); + - String fullText3 = res.getAsString(); - String fullText4 = res2.getAsString(); + String fullText3 = res.ofString(); System.out.println(String.format("[%s] %d", fullText3, fullText3.length())); - System.out.println(String.format("[%s] %d", fullText4, fullText4.length())); + + + //NiceCommon niceCommon = nc.parse(nc.ofString()); + //System.out.println(niceCommon); + + //NiceCommon niceCommon2 = nc.parse(fullText.substring(0, 9+83)); + NiceResponse niceResponse = res.parse(fullText3); + System.out.println(niceResponse); } }