From 96327fd6872acd78793da040347e1d4f4ceeb738 Mon Sep 17 00:00:00 2001 From: minkyu1128 Date: Wed, 11 May 2022 14:22:32 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=91=EB=A0=AC=EC=8A=A4=ED=8A=B8=EB=A6=BC?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=20=EC=8B=9C=20=ED=82=A4=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A5=BC=20=ED=95=9C=EB=B2=88=EB=A7=8C=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/ci/api/service/NiceCiService.java | 148 ++++++++++-------- 1 file changed, 83 insertions(+), 65 deletions(-) diff --git a/src/main/java/cokr/xit/ci/api/service/NiceCiService.java b/src/main/java/cokr/xit/ci/api/service/NiceCiService.java index cff9f0d..46d5114 100644 --- a/src/main/java/cokr/xit/ci/api/service/NiceCiService.java +++ b/src/main/java/cokr/xit/ci/api/service/NiceCiService.java @@ -14,7 +14,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Slf4j @@ -24,75 +23,94 @@ public class NiceCiService { private final NiceCiGenerator niceCiGenerator; - @Value("${contract.nice.ci.type}") - private String type; + @Value("${contract.nice.ci.type}") + private String type; - /** - * 주민번호로 CI를 취득 한다. - * -.CI: 연계정보(Connecting Information) - * -.국가표준 규격에 따라 사용자의 주민번호를 암호화한 개인 식별값. - * -.서비스에 상관없이 값이 일정 함. - * -.주민번호 -> 해쉬 -> CI 값 (88 byte) - * @param siteCode - * @param sitePw - * @param jids - * @return - */ - public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List jids) { - AtomicInteger i = new AtomicInteger(); - return ResponseVO.builder() - .errCode(ErrCd.OK) - .errMsg(ErrCd.OK.getCodeNm()) - .resultInfo( + /** + * 주민번호로 CI를 취득 한다. + * -.CI: 연계정보(Connecting Information) + * -.국가표준 규격에 따라 사용자의 주민번호를 암호화한 개인 식별값. + * -.서비스에 상관없이 값이 일정 함. + * -.주민번호 -> 해쉬 -> CI 값 (88 byte) + * + * @param siteCode + * @param sitePw + * @param jids + * @return + */ + public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List jids) { + /* ======================== + * 대체키 초기화 (rest API 방식의 CI 변환 일 경우만 해당) + * -. 병렬스트림 사용 시 한번만 초기화 하기 위함 임. + ======================== */ + if ("rest".equals(type)) + if (!SymmetricKey.isValidStat()) { + ResponseVO responseVO = niceCiGenerator.initialKey(); + if (!ErrCd.OK.equals(responseVO.getErrCode())) + return ResponseVO.builder() + .errCode(ErrCd.OK) + .errMsg(ErrCd.OK.getCodeNm()) + .resultInfo(jids.stream() + .map(jid -> { + Map m = new HashMap<>(); + m.put("key", jid); + m.put("value", responseVO); + return m; + }) + .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2) -> k1))) + .build(); + } + + return ResponseVO.builder() + .errCode(ErrCd.OK) + .errMsg(ErrCd.OK.getCodeNm()) + .resultInfo( // jids.stream() - jids.parallelStream() - .map(jid -> { - ResponseVO responseVO = null; - try { - /* ======================== - * validate - ======================== */ - if(!Optional.ofNullable(siteCode).isPresent()){ - responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트코드(은)는 필수조건 입니다.").build(); - throw new RuntimeException(responseVO.getErrMsg()); - } - if(!Optional.ofNullable(sitePw).isPresent()){ - responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트 패스워드(은)는 필수조건 입니다.").build(); - throw new RuntimeException(responseVO.getErrMsg()); - } - if(!Optional.ofNullable(jid).isPresent()){ - responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("서비스 구분값(주민번호:JID)(은)는 필수조건 입니다.").build(); - throw new RuntimeException(responseVO.getErrMsg()); - } + jids.parallelStream() + .map(jid -> { + ResponseVO responseVO = null; + try { + /* ======================== + * validate + ======================== */ + if (!Optional.ofNullable(siteCode).isPresent()) { + responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트코드(은)는 필수조건 입니다.").build(); + throw new RuntimeException(responseVO.getErrMsg()); + } + if (!Optional.ofNullable(sitePw).isPresent()) { + responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트 패스워드(은)는 필수조건 입니다.").build(); + throw new RuntimeException(responseVO.getErrMsg()); + } + if (!Optional.ofNullable(jid).isPresent()) { + responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("서비스 구분값(주민번호:JID)(은)는 필수조건 입니다.").build(); + throw new RuntimeException(responseVO.getErrMsg()); + } - /* ======================== - * api call - ======================== */ - if("socket".equals(type)) { - responseVO = Interop.getCI(siteCode, sitePw, jid); - }else if("rest".equals(type)){ - if(0 == i.getAndIncrement()) - if(!SymmetricKey.isValidStat()) - niceCiGenerator.initialKey(); - responseVO = niceCiGenerator.getCI(jid, null); - } + /* ======================== + * api call + ======================== */ + if ("socket".equals(type)) { + responseVO = Interop.getCI(siteCode, sitePw, jid); + } else if ("rest".equals(type)) { + responseVO = niceCiGenerator.getCI(jid, null); + } - } catch (Exception e){ - log.error(e.getMessage()); - } finally { - /* ======================== - * result set - ======================== */ - Map m = new HashMap<>(); - m.put("key", jid); - m.put("value", responseVO); - return m; - } + } catch (Exception e) { + log.error(e.getMessage()); + } finally { + /* ======================== + * result set + ======================== */ + Map m = new HashMap<>(); + m.put("key", jid); + m.put("value", responseVO); + return m; + } - }) - .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2)->k1))) - .build(); - } + }) + .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2) -> k1))) + .build(); + } }