From 0e10a20eed94ca550aa5e1a6fc9e33ec280a50a9 Mon Sep 17 00:00:00 2001 From: JSoi Date: Sat, 30 Jul 2022 19:20:47 +0900 Subject: [PATCH] =?UTF-8?q?#18=20[Refactor]=20=EC=93=B0=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20=ED=95=A8=EC=88=98=20=EC=A0=95=EB=A6=AC,?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/PublicApiController.java | 9 +++------ .../baechelin/api/model/PublicApiV2Form.java | 11 ---------- .../api/service/PublicApiServiceV2.java | 20 ++++++++++++++----- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java b/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java index 6b34123..6291d0f 100644 --- a/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java +++ b/src/main/java/com/mpnp/baechelin/api/controller/PublicApiController.java @@ -25,13 +25,10 @@ public class PublicApiController { @ApiOperation(value="공공 API V1을 통해 DB에 정보를 저장/업데이트하는 함수") @PostMapping("/api") public SuccessResponse getPublicApi(@Valid @RequestBody PublicApiRequestDto publicApiRequestDto) { - long start = currentTimeMillis(); publicApiService.processApiV1(publicApiRequestDto); -// ResponseEntity result = ResponseEntity.ok(publicApiService.processApiToDBWithWebclientMono(publicApiRequestDto)); - log.info("Elapsed Time : {}", currentTimeMillis() - start); return new SuccessResponse("공공 API V1 적용 완료"); } - //TODO 정리하기 + @ApiOperation(value="공공 API V2을 통해 DB에 정보를 저장/업데이트하는 함수") @GetMapping("/new-api") public SuccessResponse getPublicApiV2(@RequestParam String siDoNm, @@ -40,8 +37,8 @@ public SuccessResponse getPublicApiV2(@RequestParam String siDoNm, return new SuccessResponse("공공 API V2 적용 완료"); } - @GetMapping("test") - public void go() throws IOException, InterruptedException { + @GetMapping("/api-read") + public void go(@RequestParam String serviceKey){ publicApiServiceV2.start(); } } diff --git a/src/main/java/com/mpnp/baechelin/api/model/PublicApiV2Form.java b/src/main/java/com/mpnp/baechelin/api/model/PublicApiV2Form.java index 1ff8bb1..24ddcfb 100644 --- a/src/main/java/com/mpnp/baechelin/api/model/PublicApiV2Form.java +++ b/src/main/java/com/mpnp/baechelin/api/model/PublicApiV2Form.java @@ -44,15 +44,4 @@ public boolean validateServList() { } } - public List ApiFormToStore(PublicApiV2Form publicApiV2Form) { - List mappingResult = new ArrayList<>(); - for (ServList serv : publicApiV2Form.getServList()) { - mappingResult.add(Store.builder() - .address(serv.getLcMnad()) - .latitude(new BigDecimal(serv.faclLat)) - .longitude(new BigDecimal(serv.faclLng)) - .build()); - } - return mappingResult; - } } diff --git a/src/main/java/com/mpnp/baechelin/api/service/PublicApiServiceV2.java b/src/main/java/com/mpnp/baechelin/api/service/PublicApiServiceV2.java index 02de995..adb37cf 100644 --- a/src/main/java/com/mpnp/baechelin/api/service/PublicApiServiceV2.java +++ b/src/main/java/com/mpnp/baechelin/api/service/PublicApiServiceV2.java @@ -211,18 +211,28 @@ private List getStrings(PublicApiCategoryForm.ServList serv) { return null; } - public void start() throws IOException, InterruptedException { + public void start() { List list = new ArrayList<>(); BufferedReader br = null; - File file = ResourceUtils.getFile("classpath:static/sigungu.csv"); - br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); + File file = null; + try { + file = ResourceUtils.getFile("classpath:static/sigungu.csv"); + br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)); + } catch (FileNotFoundException e) { + return; + } String line = null; - while ((line = br.readLine()) != null) { + while (true) { + try { + if (!((line = br.readLine()) != null)) break; + } catch (IOException e) { + return; + } String[] lineContents = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1); list.add(lineContents); } for (String[] strings : list) { - System.out.println("String 프린트중 : " + Arrays.toString(strings)); + log.info("{}, {} 처리중...", strings[0], strings[1]); processApi(strings[0], strings[1], 1); } }