From f9936899bf55a17946734be0f3c7b0bbedb8bc21 Mon Sep 17 00:00:00 2001 From: hen715 Date: Tue, 21 May 2024 23:23:27 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=82=A0=EC=94=A8=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WeatherController.java | 2 +- .../inuportal/service/WeatherService.java | 37 ++++++++++++++----- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/kr/inuappcenterportal/inuportal/controller/WeatherController.java b/src/main/java/kr/inuappcenterportal/inuportal/controller/WeatherController.java index 274f282..1ee36c5 100644 --- a/src/main/java/kr/inuappcenterportal/inuportal/controller/WeatherController.java +++ b/src/main/java/kr/inuappcenterportal/inuportal/controller/WeatherController.java @@ -25,7 +25,7 @@ public class WeatherController { private final WeatherService weatherService; - @Operation(summary = "날씨 가져오기",description = "날씨의 종류에는 맑음, 구름, 비, 눈, 진눈깨비가 있습니다. ") + @Operation(summary = "날씨 가져오기",description = "날씨의 종류에는 맑음, 구름, 비, 눈, 진눈깨비가 있습니다. 미세먼지의 상태에는 좋음, 보통, 나쁨, 매우나쁨이 있습니다.") @ApiResponses({ @ApiResponse(responseCode = "200",description = "날씨 가져오기 성공",content = @Content(schema = @Schema(implementation = WeatherResponseDto.class))), }) diff --git a/src/main/java/kr/inuappcenterportal/inuportal/service/WeatherService.java b/src/main/java/kr/inuappcenterportal/inuportal/service/WeatherService.java index 418bb4a..ba0508a 100644 --- a/src/main/java/kr/inuappcenterportal/inuportal/service/WeatherService.java +++ b/src/main/java/kr/inuappcenterportal/inuportal/service/WeatherService.java @@ -1,16 +1,15 @@ package kr.inuappcenterportal.inuportal.service; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import jakarta.annotation.PostConstruct; -import kr.inuappcenterportal.inuportal.dto.FireResponseDto; import kr.inuappcenterportal.inuportal.dto.WeatherResponseDto; import kr.inuappcenterportal.inuportal.exception.ex.MyErrorCode; import kr.inuappcenterportal.inuportal.exception.ex.MyException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import oracle.jdbc.proxy.annotation.Post; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatusCode; import org.springframework.scheduling.annotation.Scheduled; @@ -31,8 +30,8 @@ public class WeatherService { @Value("${weatherKey}") private String weatherKey; - private String x = "54"; - private String y = "123"; + private final String x = "54"; + private final String y = "123"; @Scheduled(cron = "0 45 * * * *") public void getSky(){ @@ -180,10 +179,31 @@ public void getDust(){ "&ver=1.0"; JsonObject item = getSongdoInformation(url); - String pm10Value = item.get("pm10Value").getAsString(); - String pm10Grade = getGrade(item.get("pm10Grade").getAsString()); - String pm25Value = item.get("pm25Value").getAsString(); - String pm25Grade = getGrade(item.get("pm25Grade").getAsString()); + log.info("item : {}",item); + String pm10Value = "-1"; + String pm10Grade = "보통"; + String pm25Value = "-1"; + String pm25Grade = "보통"; + + JsonElement pm10ValueElement = item.get("pm10Value"); + if (pm10ValueElement != null && !pm10ValueElement.isJsonNull()) { + pm10Value = pm10ValueElement.getAsString(); + } + + JsonElement pm10GradeElement = item.get("pm10Grade"); + if (pm10GradeElement != null && !pm10GradeElement.isJsonNull()) { + pm10Grade = getGrade(pm10GradeElement.getAsString()); + } + + JsonElement pm25ValueElement = item.get("pm25Value"); + if (pm25ValueElement != null && !pm25ValueElement.isJsonNull()) { + pm25Value = pm25ValueElement.getAsString(); + } + + JsonElement pm25GradeElement = item.get("pm25Grade"); + if (pm25GradeElement != null && !pm25GradeElement.isJsonNull()) { + pm25Grade = getGrade(pm25GradeElement.getAsString()); + } redisService.storeDust(pm10Value,pm10Grade,pm25Value,pm25Grade); } public String getGrade(String level){ @@ -223,7 +243,6 @@ public JsonObject getSongdoInformation(String url) { for (int i = 0; i < itemList.size(); i++) { JsonObject item = itemList.get(i).getAsJsonObject(); if ("송도".equals(item.get("stationName").getAsString())) { - return item; } }