Skip to content

Commit

Permalink
fix: null 일때 empty 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Feb 4, 2024
1 parent 0766056 commit 1b0e461
Showing 1 changed file with 91 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<String> 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<String> 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<String> 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<String> 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();
}
Expand Down

0 comments on commit 1b0e461

Please sign in to comment.