Skip to content

Commit

Permalink
#18 [Refactor] PublicNewApiService->PublicApiService로 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoi committed Jul 18, 2022
1 parent ce78075 commit fc5dfda
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 121 deletions.
90 changes: 90 additions & 0 deletions src/main/java/com/mpnp/baechelin/api/service/PublicApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mpnp.baechelin.api.model.BarrierCode;
import com.mpnp.baechelin.api.model.PublicApiCategoryForm;
import com.mpnp.baechelin.api.model.PublicApiForm;
import com.mpnp.baechelin.config.httpclient.HttpConfig;
import com.mpnp.baechelin.api.dto.*;
import com.mpnp.baechelin.api.model.LocationKeywordSearchForm;
import com.mpnp.baechelin.store.domain.Category;
import com.mpnp.baechelin.store.domain.Store;
import com.mpnp.baechelin.store.dto.StoreCardResponseDto;
import com.mpnp.baechelin.store.repository.StoreRepository;
import com.mpnp.baechelin.store.service.StoreService;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.*;
Expand Down Expand Up @@ -44,6 +50,8 @@ public class PublicApiService {
*/
private final StoreRepository storeRepository;
private final LocationService locationService;
private final StoreService storeService;

// private final HttpConfig httpConfig;
//
// public PublicApiResponseDto processApiToDBWithWebclientMono(PublicApiRequestDto publicApiRequestDto) throws UnsupportedEncodingException {
Expand Down Expand Up @@ -173,6 +181,88 @@ private void saveDTO(List<PublicApiResponseDto.Row> rows) {
}
}

public List<StoreCardResponseDto> processNewApi(String key, int requestSize, String siDoNm) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
headers.setAccept(List.of(MediaType.APPLICATION_XML));
URI uri = UriComponentsBuilder
.fromUriString("http://apis.data.go.kr/B554287/DisabledPersonConvenientFacility/getDisConvFaclList")
.queryParam("serviceKey", key)
.queryParam("numOfRows", requestSize)
.queryParam("siDoNm", siDoNm)
.queryParam("faclTyCd", "UC0B01")
.build()
.encode()
.toUri();

RestTemplate restTemplate = new RestTemplate();
log.warn(uri.toString());
ResponseEntity<PublicApiForm> resultRe = restTemplate.exchange(
uri, HttpMethod.GET, new HttpEntity<>(headers), PublicApiForm.class
);
PublicApiForm result = resultRe.getBody();
if (result == null || result.getServList()==null) return null;
List<Store> storeList = new ArrayList<>();
for (PublicApiForm.ServList servList : result.getServList()) {
// servList + Barrier Free Tag 합치기 + category
List<String> barrierTagList = processNewApiSecondStage(key, servList.getWfcltId());
log.info("barrierlist : {}", barrierTagList.toString());
Map<String, Object> infoMap = locationService.convertGeoAndStoreNameToKeyword(servList.getFaclLat(), servList.getFaclLng(), servList.getFaclNm());
if ((boolean) infoMap.get("status")) {
int storeId = (Integer) infoMap.get("storeId");
String category = (String) infoMap.get("category");
String phoneNumber = (String) infoMap.get("phoneNumber");
String storeName = (String) infoMap.get("storeName");
Store nStore = new Store(storeId, servList, barrierTagList, phoneNumber, category, storeName);
if(!storeRepository.existsById(nStore.getId())){
storeRepository.save(nStore);
storeList.add(nStore);
}
}
}
return storeList.stream().map(StoreCardResponseDto::new).collect(Collectors.toList());
}

public List<String> processNewApiSecondStage(String key, String sisulNum) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
headers.setAccept(List.of(MediaType.APPLICATION_XML));
URI uri = UriComponentsBuilder
.fromUriString("http://apis.data.go.kr/B554287/DisabledPersonConvenientFacility/getFacInfoOpenApiJpEvalInfoList")
.queryParam("serviceKey", key)
.queryParam("wfcltId", sisulNum)
.build()
.encode()
.toUri();

RestTemplate restTemplate = new RestTemplate();
log.warn(uri.toString());
ResponseEntity<PublicApiCategoryForm> resultRe = restTemplate.exchange(
uri, HttpMethod.GET, new HttpEntity<>(headers), PublicApiCategoryForm.class
);
PublicApiCategoryForm result = resultRe.getBody();
List<String> barrierTagResult = new ArrayList<>(); // 태그 결과들을 담을 리스트
if (result == null || result.getServList() == null) {
return barrierTagResult;
} else {
PublicApiCategoryForm.ServList first = result.getServList().stream().findFirst().orElse(null);
// Input 한 개당 하나의 배리어 프리 정보가 생성되므로 하나만 찾는다
if (first != null && first.getEvalInfo() != null) { // 결과가 존재할 떄
String[] splitInput = first.getEvalInfo().split(",");
return Arrays.stream(splitInput)
.map(BarrierCode::getColumnFromDesc)
.filter(code -> code != null && !code.equals(""))
.collect(Collectors.toList());
}
}
return barrierTagResult;
}

/*
*계단 또는 승강설비,대변기,복도,소변기,일반사항,장애인전용주차구역,주출입구 높이차이 제거,주출입구 접근로,출입구(문),해당시설 층수
* */


private String categoryFilter(String category) {
if (category == null) {
return Category.ETC.getDesc();
Expand Down
121 changes: 0 additions & 121 deletions src/main/java/com/mpnp/baechelin/api/service/PublicNewApiService.java

This file was deleted.

0 comments on commit fc5dfda

Please sign in to comment.