feat: NICE CI 소켓 통신 추가

- 전문 응답 parsing
dev
Jonguk. Lim 2 months ago
parent 3b2cb5b344
commit 4a3a1785d1

@ -482,7 +482,7 @@ public class NiceCiDTO {
// FIXME: 인코딩확인후 적용
//String tgtString = NiceCiUtils.covertCharset(tgtStr, "EUC-KR");
if (StringUtils.isNotBlank(tgtString) && NiceCiUtils.lengthKr(tgtString) >= 2210) {
if (StringUtils.isNotBlank(tgtString) && NiceCiUtils.lengthKr(tgtString) >= 2320) {
Response response = new Response();
int idx = 0;
response.setTrCode(StringUtils.left(tgtString, parseLength[idx]));
@ -518,7 +518,6 @@ public class NiceCiDTO {
List<NiceCiResult> resResults = IntStream.range(0, repeat)
.mapToObj(i -> {
String currentString = NiceCiUtils.substringKr(finalTgtString, i * repeatLength);
//String currentString = finalTgtString.substring(i * repeatLength, (i + 1) * repeatLength);
return NiceCiResult.parse(currentString);
})
.collect(Collectors.toList());

@ -10,6 +10,7 @@ import javax.validation.constraints.*;
import org.apache.commons.lang3.*;
import cokr.xit.ens.modules.nice.cmm.*;
import io.swagger.v3.oas.annotations.media.*;
import lombok.*;
@ -48,8 +49,8 @@ public class NiceCiHistoryDTO {
* set
* </pre>
*/
@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "TR Code", example = " ")
@Size(min = 10, max = 10, message = "트랜잭션 코드는 10자리 입니다.")
//@Schema(requiredMode = Schema.RequiredMode.REQUIRED, title = "TR Code", example = " ")
//@Size(min = 10, max = 10, message = "트랜잭션 코드는 10자리 입니다.")
private String trCode = StringUtils.EMPTY;
public void setTrCode(String trCode) {
this.trCode = StringUtils.leftPad(nvl(trCode), 10, StringUtils.SPACE);
@ -164,10 +165,10 @@ public class NiceCiHistoryDTO {
* </pre>
*/
@Schema(title = "요청건수", example = " ")
@Max(value = 100, message = "요청건수는 최대 10자리 입니다.")
private String reqCnt = StringUtils.rightPad(StringUtils.EMPTY, 9, StringUtils.SPACE);
@Pattern(regexp = "^\\s{10}$|\\d{10}", message = "요청건수는 10자리(max 100)입니다")
private String reqCnt = StringUtils.rightPad(StringUtils.EMPTY, 10, StringUtils.SPACE);
public void setReqCnt(String reqCnt){
this.reqCnt = StringUtils.rightPad(nvl(reqCnt), 13, StringUtils.SPACE);
this.reqCnt = StringUtils.rightPad(nvl(reqCnt), 10, StringUtils.SPACE);
}
/**
@ -317,7 +318,7 @@ public class NiceCiHistoryDTO {
// return sb.toString();
// }
public static Response parse(String tgtStr) {
public static Response parse(String tgtString) {
final int repeatLength = 1150;
final int[] parseLength = {
10, // tr-code
@ -327,10 +328,10 @@ public class NiceCiHistoryDTO {
10, // 누적건수
10, // 응답건수
};
// FIXME: 인코딩확인후
String tgtString = new String(tgtStr.getBytes(), StandardCharsets.UTF_8);
// FIXME: 인코딩확인후 필요시 사
//String tgtString = new String(tgtStr.getBytes(), StandardCharsets.UTF_8);
if (StringUtils.isNotBlank(tgtString) && tgtString.length() >= 1289) {
if (StringUtils.isNotBlank(tgtString) && NiceCiUtils.lengthKr(tgtString) >= 1290) {
Response nr = new Response();
int idx = 0;
nr.setTrCode(StringUtils.left(tgtString, parseLength[idx]));
@ -342,9 +343,6 @@ public class NiceCiHistoryDTO {
nr.setCommonEmptyField(StringUtils.left(tgtString, parseLength[idx]));
tgtString = tgtString.substring(parseLength[idx++]);
nr.setResCnt(StringUtils.left(tgtString, parseLength[idx]));
tgtString = tgtString.substring(parseLength[idx++]);
nr.setTotalCnt(StringUtils.left(tgtString, parseLength[idx]));
tgtString = tgtString.substring(parseLength[idx++]);
@ -354,13 +352,13 @@ public class NiceCiHistoryDTO {
nr.setResCnt(StringUtils.left(tgtString, parseLength[idx]));
tgtString = tgtString.substring(parseLength[idx++]);
if(tgtString.length() % repeatLength == 0){
int repeat = tgtString.length() / repeatLength;
if(NiceCiUtils.lengthKr(tgtString) % repeatLength == 0){
int repeat = NiceCiUtils.lengthKr(tgtString) / repeatLength;
String finalTgtString = tgtString;
List<NiceCiResult> resResults = IntStream.range(0, repeat)
.mapToObj(i -> {
String currentString = finalTgtString.substring(i * repeatLength, (i + 1) * repeatLength);
return NiceCiResult.parse(currentString);
String currentString = NiceCiUtils.substringKr(finalTgtString, i * repeatLength);
return NiceCiResult.parseHistory(currentString);
})
.collect(Collectors.toList());
nr.setNiceCiResults(resResults);

@ -331,7 +331,7 @@ public class NiceCiResult {
11, // 공란
};
if (StringUtils.isNotBlank(tgtString) && tgtString.length()%1150 == 0) {
if (StringUtils.isNotBlank(tgtString) && NiceCiUtils.lengthKr(tgtString)%1150 == 0) {
NiceCiResult result = new NiceCiResult();
int idx = 0;

@ -34,4 +34,10 @@ public class NiceCiController {
public ResponseEntity<?> sendBulk() {
return new ResponseEntity<>(niceCiService.requestSendBulk(), HttpStatus.OK);
}
@Operation(summary = "(대량)상태조회")
@PostMapping(value = "/status/bulk", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> findBulkStatus() {
return new ResponseEntity<>(niceCiService.findBulkStatus(), HttpStatus.OK);
}
}

@ -99,6 +99,52 @@ public class NiceCiService {
// String rtnMsg = niceCiApiService.requestSendBulk(ciRequest);
// NiceCiDTO.Response resDTO = NiceCiDTO.Response.parse(rtnMsg);
return niceCiApiService.requestSendBulk(ciRequest);
EnsResponseVO<?> responseVO = niceCiApiService.requestSendBulk(ciRequest);
log.info(responseVO.toString());
return responseVO;
}
public EnsResponseVO<?> findBulkStatus() {
NiceCiHistoryDTO.Request ciRequest = new NiceCiHistoryDTO.Request();
//ciRequest.setTrCode("0000006150");
// // 공통부
//
// // 개별요청부
// nr.setQueryReason(StringUtils.EMPTY);
// nr.setQueryReqCnt(46);
// nr.setSmsSndReqCode("1");
String tmp = NiceCiUtils.rightPadKr(msg, 2000, StringUtils.SPACE);
System.out.println(
String.format("[%s] kr length - %d, utf-8 length - %d", tmp, NiceCiUtils.lengthKr(tmp), tmp.length()));
// nr.setSndPhoneNo("010");
// nr.setContactSearchCode("1");
// 공통부
NiceCiCommon nc = new NiceCiCommon();
// nc.setGrpCode("grpCode");
//nc.setTrType("Type");
nc.setTrClassification("31895"); // 거래구분
nc.setOrgId(ORG_ID); // 참가기관Id - property 에서
nc.setOrgMngNo("0000000103"); // 기관관리번호
nc.setOrgSndDt("20240919");
NiceCiDTO.QueryRequest qr = new NiceCiDTO.QueryRequest();
NiceCiDTO.ButtonRequest br = new NiceCiDTO.ButtonRequest();
ciRequest.setNiceCommon(nc);
// nc.setNiceMngNo(StringUtils.EMPTY);
// nc.setNiceSndDt(StringUtils.EMPTY);
String ciTxt = ciRequest.ofString();
String ft = String.format("%s%s", StringUtils.leftPad(String.valueOf(NiceCiUtils.lengthKr(ciTxt)), 10, "0"),
ciTxt);
System.out.println(
String.format("[%s] kr length - %d, utf-8 length - %d", ft, NiceCiUtils.lengthKr(ft), ft.length()));
// String rtnMsg = niceCiApiService.requestSendBulk(ciRequest);
// NiceCiDTO.Response resDTO = NiceCiDTO.Response.parse(rtnMsg);
EnsResponseVO<?> responseVO = niceCiApiService.findBulkStatus(ciRequest);
log.info(responseVO.toString());
return responseVO;
}
}

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save