병렬스트림 사용 시 키정보를 한번만 초기화하도록 수정

master
minkyu1128 3 years ago
parent 01a2a82c42
commit 96327fd687

@ -14,7 +14,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
@ -24,75 +23,94 @@ public class NiceCiService {
private final NiceCiGenerator niceCiGenerator; private final NiceCiGenerator niceCiGenerator;
@Value("${contract.nice.ci.type}") @Value("${contract.nice.ci.type}")
private String type; private String type;
/** /**
* CI . * CI .
* -.CI: (Connecting Information) * -.CI: (Connecting Information)
* -. . * -. .
* -. . * -. .
* -. -> -> CI (88 byte) * -. -> -> CI (88 byte)
* @param siteCode *
* @param sitePw * @param siteCode
* @param jids * @param sitePw
* @return * @param jids
*/ * @return
public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List<String> jids) { */
AtomicInteger i = new AtomicInteger(); public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List<String> jids) {
return ResponseVO.builder() /* ========================
.errCode(ErrCd.OK) * (rest API CI )
.errMsg(ErrCd.OK.getCodeNm()) * -. .
.resultInfo( ======================== */
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<String, Object> 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.stream()
jids.parallelStream() jids.parallelStream()
.map(jid -> { .map(jid -> {
ResponseVO responseVO = null; ResponseVO responseVO = null;
try { try {
/* ======================== /* ========================
* validate * validate
======================== */ ======================== */
if(!Optional.ofNullable(siteCode).isPresent()){ if (!Optional.ofNullable(siteCode).isPresent()) {
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트코드(은)는 필수조건 입니다.").build(); responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트코드(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg()); throw new RuntimeException(responseVO.getErrMsg());
} }
if(!Optional.ofNullable(sitePw).isPresent()){ if (!Optional.ofNullable(sitePw).isPresent()) {
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트 패스워드(은)는 필수조건 입니다.").build(); responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트 패스워드(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg()); throw new RuntimeException(responseVO.getErrMsg());
} }
if(!Optional.ofNullable(jid).isPresent()){ if (!Optional.ofNullable(jid).isPresent()) {
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("서비스 구분값(주민번호:JID)(은)는 필수조건 입니다.").build(); responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("서비스 구분값(주민번호:JID)(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg()); throw new RuntimeException(responseVO.getErrMsg());
} }
/* ======================== /* ========================
* api call * api call
======================== */ ======================== */
if("socket".equals(type)) { if ("socket".equals(type)) {
responseVO = Interop.getCI(siteCode, sitePw, jid); responseVO = Interop.getCI(siteCode, sitePw, jid);
}else if("rest".equals(type)){ } else if ("rest".equals(type)) {
if(0 == i.getAndIncrement()) responseVO = niceCiGenerator.getCI(jid, null);
if(!SymmetricKey.isValidStat()) }
niceCiGenerator.initialKey();
responseVO = niceCiGenerator.getCI(jid, null);
}
} catch (Exception e){ } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
} finally { } finally {
/* ======================== /* ========================
* result set * result set
======================== */ ======================== */
Map<String, Object> m = new HashMap<>(); Map<String, Object> m = new HashMap<>();
m.put("key", jid); m.put("key", jid);
m.put("value", responseVO); m.put("value", responseVO);
return m; return m;
} }
}) })
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2)->k1))) .collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2) -> k1)))
.build(); .build();
} }
} }

Loading…
Cancel
Save