diff --git a/core-module/src/main/java/com/congress/coremodule/law/application/service/LawQueryUseCase.java b/core-module/src/main/java/com/congress/coremodule/law/application/service/LawQueryUseCase.java index 38294e3..9948aef 100644 --- a/core-module/src/main/java/com/congress/coremodule/law/application/service/LawQueryUseCase.java +++ b/core-module/src/main/java/com/congress/coremodule/law/application/service/LawQueryUseCase.java @@ -124,24 +124,33 @@ public LawDetail getLawDetail(LawVoteReq req) { JsonNode rootNode = objectMapper.readTree(responseBody); JsonNode dataArray = rootNode.get("nzmimeepazxkubdpn").get(1).get("row"); - for (JsonNode dataNode : dataArray) { - - String billNo = dataNode.get("BILL_NO").asText(); - String billName = dataNode.get("BILL_NAME").asText(); - String proposer = dataNode.get("PROPOSER").asText(); - String proposeDt = dataNode.get("PROPOSE_DT").asText(); - String detailLink = dataNode.get("DETAIL_LINK").asText(); - - result.setBillNo(billNo); - result.setBillNm(billName); - result.setProposer(proposer); - result.setProposerDt(proposeDt); - result.setDetailLink(detailLink); - - if (!lawQueryService.isLawAlreadySaved(result.getBillNm())) { - lawQueryService.saveLaw(result.getBillNm()); + if (dataArray != null) { + for (JsonNode dataNode : dataArray) { + + String billNo = dataNode.get("BILL_NO").asText(); + String billName = dataNode.get("BILL_NAME").asText(); + String proposer = dataNode.get("PROPOSER").asText(); + String proposeDt = dataNode.get("PROPOSE_DT").asText(); + String detailLink = dataNode.get("DETAIL_LINK").asText(); + + result.setBillNo(billNo); + result.setBillNm(billName); + result.setProposer(proposer); + result.setProposerDt(proposeDt); + result.setDetailLink(detailLink); + + if (!lawQueryService.isLawAlreadySaved(result.getBillNm())) { + lawQueryService.saveLaw(result.getBillNm()); + } + return result; } - return result; + } else { + + result.setBillNo(""); + result.setBillNm(""); + result.setProposer(""); + result.setProposerDt(""); + result.setDetailLink(""); } } catch (IOException e) { @@ -164,56 +173,78 @@ public LegislatorDetail getLegislatorDetail(LegislatorReq req) { try { JsonNode rootNode = objectMapper.readTree(responseBody); JsonNode dataArray = rootNode.get("npffdutiapkzbfyvr").get(1).get("row"); - JsonNode dataNode = dataArray.get(0); - - String hgNm = dataNode.get("HG_NM").asText(); - String bthDate = dataNode.get("BTH_DATE").asText(); - String sexGbnNm = dataNode.get("SEX_GBN_NM").asText(); - String reeleGbnNm = dataNode.get("REELE_GBN_NM").asText(); - String units = dataNode.get("UNITS").asText(); - String unitNm = dataNode.get("UNIT_NM").asText(); - String polyNm = dataNode.get("POLY_NM").asText(); - String origNm = dataNode.get("ORIG_NM").asText(); - - result.setHgNm(hgNm); - result.setBthDate(bthDate); - result.setSexGbnNm(sexGbnNm); - result.setReeleGbnNm(reeleGbnNm); - result.setUnits(units); - result.setUnitNm(unitNm); - result.setPolyNm(polyNm); - result.setOrigNm(origNm); - - if (!lawQueryService.isLegislatorAlreadySaved(result.getHgNm())) { - lawQueryService.saveLegislator(result.getHgNm()); - } - // 의원 이력 - String apiUrlAno = "https://open.assembly.go.kr/portal/openapi/nfzegpkvaclgtscxt?KEY=86f396b109764bb6bd688b181875d6ce&Type=json&pIndex=1&pSize=100&PROFILE_UNIT_CD=100020" - + "&HG_NM=" + req.getLegislatorName(); - ResponseEntity responseEntityAno = restTemplate.getForEntity(apiUrlAno, String.class); - String responseBodyAno = responseEntityAno.getBody(); + if (dataArray != null && !dataArray.isEmpty()) { - JsonNode rootNodeAno = objectMapper.readTree(responseBodyAno); - JsonNode dataArrayAno = rootNodeAno.get("nfzegpkvaclgtscxt").get(1).get("row"); - JsonNode dataNodeAno = dataArrayAno.get(0); + JsonNode dataNode = dataArray.get(0); - result.setFtToDateOne(dataNodeAno.get("FRTO_DATE").asText()); - result.setProfileSjOne(dataNodeAno.get("PROFILE_SJ").asText()); + result.setHgNm(dataNode.get("HG_NM").asText()); + result.setBthDate(dataNode.get("BTH_DATE").asText()); + result.setSexGbnNm(dataNode.get("SEX_GBN_NM").asText()); + result.setReeleGbnNm(dataNode.get("REELE_GBN_NM").asText()); + result.setUnits(dataNode.get("UNITS").asText()); + result.setUnitNm(dataNode.get("UNIT_NM").asText()); + result.setPolyNm(dataNode.get("POLY_NM").asText()); + result.setOrigNm(dataNode.get("ORIG_NM").asText()); - // 의원 경력 - String apiUrlSnd = "https://open.assembly.go.kr/portal/openapi/nqbeopthavwwfbekw?KEY=86f396b109764bb6bd688b181875d6ce&Type=json&pIndex=1&pSize=100&PROFILE_UNIT_CD=100020" - + "&HG_NM=" + req.getLegislatorName(); - ResponseEntity responseEntitySnd = restTemplate.getForEntity(apiUrlSnd, String.class); - String responseBodySnd = responseEntitySnd.getBody(); + if (!lawQueryService.isLegislatorAlreadySaved(result.getHgNm())) { + lawQueryService.saveLegislator(result.getHgNm()); + } + + // 의원 이력 + String apiUrlAno = "https://open.assembly.go.kr/portal/openapi/nfzegpkvaclgtscxt?KEY=86f396b109764bb6bd688b181875d6ce&Type=json&pIndex=1&pSize=100&PROFILE_UNIT_CD=100020" + + "&HG_NM=" + req.getLegislatorName(); + ResponseEntity responseEntityAno = restTemplate.getForEntity(apiUrlAno, String.class); + String responseBodyAno = responseEntityAno.getBody(); - JsonNode rootNodeSnd = objectMapper.readTree(responseBodySnd); - JsonNode dataArraySnd = rootNodeSnd.get("nqbeopthavwwfbekw").get(1).get("row"); - JsonNode dataNodeSnd = dataArraySnd.get(0); + JsonNode rootNodeAno = objectMapper.readTree(responseBodyAno); + JsonNode dataArrayAno = rootNodeAno.get("nfzegpkvaclgtscxt").get(1).get("row"); - result.setFrToDateTwo(dataNodeSnd.get("FRTO_DATE").asText()); - result.setProfileSjTwo(dataNodeSnd.get("PROFILE_SJ").asText()); + if (dataArrayAno != null && dataArrayAno.size() > 0) { + JsonNode dataNodeAno = dataArrayAno.get(0); + result.setFtToDateOne(dataNodeAno.get("FRTO_DATE").asText()); + result.setProfileSjOne(dataNodeAno.get("PROFILE_SJ").asText()); + } else { + result.setFtToDateOne(""); + result.setProfileSjOne(""); + } + + // 의원 경력 + String apiUrlSnd = "https://open.assembly.go.kr/portal/openapi/nqbeopthavwwfbekw?KEY=86f396b109764bb6bd688b181875d6ce&Type=json&pIndex=1&pSize=100&PROFILE_UNIT_CD=100020" + + "&HG_NM=" + req.getLegislatorName(); + ResponseEntity responseEntitySnd = restTemplate.getForEntity(apiUrlSnd, String.class); + String responseBodySnd = responseEntitySnd.getBody(); + + JsonNode rootNodeSnd = objectMapper.readTree(responseBodySnd); + JsonNode dataArraySnd = rootNodeSnd.get("nqbeopthavwwfbekw").get(1).get("row"); + + if (dataArraySnd != null && dataArraySnd.size() > 0) { + JsonNode dataNodeSnd = dataArraySnd.get(0); + result.setFrToDateTwo(dataNodeSnd.get("FRTO_DATE").asText()); + result.setProfileSjTwo(dataNodeSnd.get("PROFILE_SJ").asText()); + } else { + + result.setFrToDateTwo(""); + result.setProfileSjTwo(""); + } + } else { + + result.setHgNm(""); + result.setBthDate(""); + result.setSexGbnNm(""); + result.setReeleGbnNm(""); + result.setUnits(""); + result.setUnitNm(""); + result.setPolyNm(""); + result.setOrigNm(""); + + result.setFtToDateOne(""); + result.setProfileSjOne(""); + + result.setFrToDateTwo(""); + result.setProfileSjTwo(""); + } } catch (IOException e) { e.printStackTrace(); }