Browse Source

날씨API - 비행계획서 좌표 값에 따른 위치 추가

Test
이학준 2 years ago
parent
commit
78d6592870
  1. 32
      src/main/java/com/palnet/biz/api/bas/flight/controller/BasFlightController.java
  2. 2
      src/main/java/com/palnet/biz/api/bas/flight/model/BasFlightWeatherModel.java
  3. 8
      src/main/java/com/palnet/biz/api/ctr/cntrl/controller/CtrCntrlController.java
  4. 3
      src/main/java/com/palnet/biz/scheduler/ctr/service/CtrTrnsLctnService.java

32
src/main/java/com/palnet/biz/api/bas/flight/controller/BasFlightController.java

@ -1,10 +1,6 @@
package com.palnet.biz.api.bas.flight.controller; package com.palnet.biz.api.bas.flight.controller;
import java.io.BufferedReader; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -20,13 +16,16 @@ import com.palnet.biz.api.bas.flight.model.BasFlightPlanModel;
import com.palnet.biz.api.bas.flight.model.BasFlightPlanPilotModel; import com.palnet.biz.api.bas.flight.model.BasFlightPlanPilotModel;
import com.palnet.biz.api.bas.flight.model.BasFlightScheduleRs; import com.palnet.biz.api.bas.flight.model.BasFlightScheduleRs;
import com.palnet.biz.api.bas.flight.model.BasFlightWeatherModel; import com.palnet.biz.api.bas.flight.model.BasFlightWeatherModel;
import com.palnet.biz.api.ctr.cntrl.model.CtrCntrlWeatherModel;
import com.palnet.biz.scheduler.ctr.model.CtrTrnsLctnModel;
import com.palnet.biz.scheduler.ctr.service.CtrTrnsLctnService;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -60,10 +59,13 @@ public class BasFlightController {
private final BasFlightService basFlightService; private final BasFlightService basFlightService;
private final Environment env; private final Environment env;
private final CtrTrnsLctnService ctrTrnsLctnService;
public BasFlightController(BasFlightService basFlightService, Environment env) { @Autowired
public BasFlightController(BasFlightService basFlightService, Environment env, CtrTrnsLctnService ctrTrnsLctnService) {
this.basFlightService = basFlightService; this.basFlightService = basFlightService;
this.env = env; this.env = env;
this.ctrTrnsLctnService = ctrTrnsLctnService;
} }
@GetMapping("/area") @GetMapping("/area")
@ -259,6 +261,8 @@ public class BasFlightController {
} }
@GetMapping("/plan/api/weather") @GetMapping("/plan/api/weather")
@ApiOperation(value = "날씨")
@Tag(name = "비행계획서", description = "비행계획서 관련 API")
public ResponseEntity<? extends BasicResponse> restApiGetWeather(BasFlightWeatherModel rs) throws IOException, ParseException { public ResponseEntity<? extends BasicResponse> restApiGetWeather(BasFlightWeatherModel rs) throws IOException, ParseException {
StringBuilder urlBuilder = new StringBuilder("http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst"); StringBuilder urlBuilder = new StringBuilder("http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst");
urlBuilder.append("?" + URLEncoder.encode("serviceKey","UTF-8") + "=r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D"); urlBuilder.append("?" + URLEncoder.encode("serviceKey","UTF-8") + "=r6RMUsk3Vtama7D6uq7MiWV9dTC9MwfIIr4%2F45y0uVNw6BaYbgpKmL%2BLUDFVTfIYUmEe4K%2FaniEjdV9mg5t82Q%3D%3D");
@ -282,12 +286,26 @@ public class BasFlightController {
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String line; String line;
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
sb.append(line); sb.append(line);
} }
CtrTrnsLctnModel weatherResult = ctrTrnsLctnService.convertLatlonToAddress(rs.getNx2(),rs.getNy2());
log.info("weatherResult >>>> : {}", weatherResult);
String str = sb.toString(); String str = sb.toString();
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(str); JSONObject jsonObject = (JSONObject) parser.parse(str);
jsonObject.put("area1",weatherResult.getArea1());
jsonObject.put("area2",weatherResult.getArea2());
jsonObject.put("area3",weatherResult.getArea3());
// CtrCntrlWeatherModel areaResult = new CtrCntrlWeatherModel();
// areaResult.setArea1(weatherResult.getArea1());
// areaResult.setArea2(weatherResult.getArea2());
// areaResult.setArea3(weatherResult.getArea3());
rd.close(); rd.close();
conn.disconnect(); conn.disconnect();
log.info(sb.toString()); log.info(sb.toString());

2
src/main/java/com/palnet/biz/api/bas/flight/model/BasFlightWeatherModel.java

@ -12,5 +12,7 @@ public class BasFlightWeatherModel {
private String base_time; private String base_time;
private String nx; private String nx;
private String ny; private String ny;
private double nx2;
private double ny2;
} }

8
src/main/java/com/palnet/biz/api/ctr/cntrl/controller/CtrCntrlController.java

@ -7,7 +7,6 @@ import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.*; import java.util.*;
@ -43,8 +42,6 @@ public class CtrCntrlController {
private final CtrCntrlService service; private final CtrCntrlService service;
private CtrTrnsLctnService ctrTrnsLctnService;
public CtrCntrlController(CtrCntrlService service) { public CtrCntrlController(CtrCntrlService service) {
this.service = service; this.service = service;
} }
@ -201,7 +198,6 @@ public class CtrCntrlController {
coord.setX(rs.getNx()); coord.setX(rs.getNx());
coord.setY(rs.getNy()); coord.setY(rs.getNy());
returnCoord = service.wheather(coord); returnCoord = service.wheather(coord);
CtrTrnsLctnModel weatherResult = ctrTrnsLctnService.convertLatlonToAddress(returnCoord.x,returnCoord.y);
double nx = returnCoord.getX(); double nx = returnCoord.getX();
double ny = returnCoord.getY(); double ny = returnCoord.getY();
@ -232,9 +228,7 @@ public class CtrCntrlController {
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
sb.append(line); sb.append(line);
} }
sb.append(weatherResult.getArea1());
sb.append(weatherResult.getArea2());
sb.append(weatherResult.getArea3());
String str = sb.toString(); String str = sb.toString();
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(str); JSONObject jsonObject = (JSONObject) parser.parse(str);

3
src/main/java/com/palnet/biz/scheduler/ctr/service/CtrTrnsLctnService.java

@ -99,9 +99,6 @@ public class CtrTrnsLctnService {
Map result = (Map)results.get(typeIndex); Map result = (Map)results.get(typeIndex);
result.forEach((resultKey, resultValue) -> { result.forEach((resultKey, resultValue) -> {
// log.debug(">>> resultKey / resultValue : {} / {}",resultKey, resultValue); // log.debug(">>> resultKey / resultValue : {} / {}",resultKey, resultValue);
model.setArea1(((Map)((Map)resultValue).get("area1")).get("name").toString());
model.setArea2(((Map)((Map)resultValue).get("area2")).get("name").toString());
model.setArea3(((Map)((Map)resultValue).get("area3")).get("name").toString());
if("region".equals(resultKey)){ if("region".equals(resultKey)){
model.setArea1(((Map)((Map)resultValue).get("area1")).get("name").toString()); model.setArea1(((Map)((Map)resultValue).get("area1")).get("name").toString());
model.setArea2(((Map)((Map)resultValue).get("area2")).get("name").toString()); model.setArea2(((Map)((Map)resultValue).get("area2")).get("name").toString());

Loading…
Cancel
Save