|
@@ -8,6 +8,7 @@ import com.dahuatech.icc.exception.ClientException;
|
|
import com.huimv.common.utils.AirQualityIndexUtil;
|
|
import com.huimv.common.utils.AirQualityIndexUtil;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import com.huimv.common.utils.ResultCode;
|
|
|
|
+import com.huimv.environ.eco.entity.DayWeatherEntity;
|
|
import com.huimv.environ.eco.entity.Farm;
|
|
import com.huimv.environ.eco.entity.Farm;
|
|
import com.huimv.environ.eco.entity.WeatherResultEntity;
|
|
import com.huimv.environ.eco.entity.WeatherResultEntity;
|
|
import com.huimv.environ.eco.mapper.FarmMapper;
|
|
import com.huimv.environ.eco.mapper.FarmMapper;
|
|
@@ -33,92 +34,210 @@ public class WeatherController {
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/info")
|
|
@RequestMapping("/info")
|
|
|
|
+
|
|
public Result getAccidentRecord(@RequestParam Map<String, Object> params) throws ClientException {
|
|
public Result getAccidentRecord(@RequestParam Map<String, Object> params) throws ClientException {
|
|
|
|
+
|
|
String farmId = (String) params.get("farmId");
|
|
String farmId = (String) params.get("farmId");
|
|
|
|
+
|
|
LambdaQueryWrapper<Farm> wrapper = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<Farm> wrapper = Wrappers.lambdaQuery();
|
|
|
|
+
|
|
wrapper.eq(Farm::getId, farmId);//未删除的阈值
|
|
wrapper.eq(Farm::getId, farmId);//未删除的阈值
|
|
|
|
+
|
|
Farm farm = farmMapper.selectOne(wrapper);
|
|
Farm farm = farmMapper.selectOne(wrapper);
|
|
|
|
+
|
|
String[] location = farm.getFrontLocation().split(",");
|
|
String[] location = farm.getFrontLocation().split(",");
|
|
|
|
+
|
|
String province = location[0];
|
|
String province = location[0];
|
|
|
|
+
|
|
String city = location[1];
|
|
String city = location[1];
|
|
|
|
+
|
|
String county = location[2];
|
|
String county = location[2];
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// log.info("当前城市为=======>" +province+city+county);
|
|
// log.info("当前城市为=======>" +province+city+county);
|
|
|
|
+
|
|
//直接通过它计算出24小时之内的温度同时以一个新的数组存入表中,数据的取出和比较值后面进行
|
|
//直接通过它计算出24小时之内的温度同时以一个新的数组存入表中,数据的取出和比较值后面进行
|
|
|
|
+
|
|
String url = "https://wis.qq.com/weather/common";
|
|
String url = "https://wis.qq.com/weather/common";
|
|
|
|
+
|
|
String param = "source=xw&weather_type=observe|forecast_1h|forecast_24h|index|alarm|limit|tips&province=" + province + "&city=" + city + "&county=" + county;
|
|
String param = "source=xw&weather_type=observe|forecast_1h|forecast_24h|index|alarm|limit|tips&province=" + province + "&city=" + city + "&county=" + county;
|
|
|
|
+
|
|
String result = HttpUtil.urlWithForm(url, param, Charset.defaultCharset(), true);
|
|
String result = HttpUtil.urlWithForm(url, param, Charset.defaultCharset(), true);
|
|
|
|
+
|
|
// System.out.println(result);
|
|
// System.out.println(result);
|
|
|
|
+
|
|
String s = HttpUtil.get(result);
|
|
String s = HttpUtil.get(result);
|
|
|
|
+
|
|
//对S进行解析,首先获取当天24小时的温度情况
|
|
//对S进行解析,首先获取当天24小时的温度情况
|
|
|
|
+
|
|
JSONObject jsonObject = JSONObject.fromObject(s);
|
|
JSONObject jsonObject = JSONObject.fromObject(s);
|
|
|
|
+
|
|
Object data = jsonObject.get("data");
|
|
Object data = jsonObject.get("data");
|
|
|
|
+
|
|
JSONObject jsonData = JSONObject.fromObject(data);
|
|
JSONObject jsonData = JSONObject.fromObject(data);
|
|
|
|
+
|
|
// System.out.println(jsonData);
|
|
// System.out.println(jsonData);
|
|
|
|
+
|
|
Object forecastobject24hDetail = JSONObject.fromObject(jsonData.get("forecast_24h")).get("1"); //24小时天气预报的 “1” 为当天的天气预报
|
|
Object forecastobject24hDetail = JSONObject.fromObject(jsonData.get("forecast_24h")).get("1"); //24小时天气预报的 “1” 为当天的天气预报
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Object tomorrow = JSONObject.fromObject(jsonData.get("forecast_24h")).get("2"); //24小时天气预报的 “1” 为当天的天气预报
|
|
|
|
+
|
|
|
|
+ Object towTomorrow = JSONObject.fromObject(jsonData.get("forecast_24h")).get("3"); //24小时天气预报的 “1” 为当天的天气预报
|
|
|
|
+
|
|
|
|
+ DayWeatherEntity tomorrowEntity = new DayWeatherEntity();
|
|
|
|
+
|
|
|
|
+ tomorrowEntity.setMax_degree((String)JSONObject.fromObject(tomorrow).get("max_degree") );
|
|
|
|
+
|
|
|
|
+ tomorrowEntity.setMin_degree((String)JSONObject.fromObject(tomorrow).get("min_degree") );
|
|
|
|
+
|
|
|
|
+ tomorrowEntity.setDay_weather((String)JSONObject.fromObject(tomorrow).get("day_weather") );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ DayWeatherEntity towTomorrowEntity = new DayWeatherEntity();
|
|
|
|
+
|
|
|
|
+ towTomorrowEntity.setMax_degree((String)JSONObject.fromObject(towTomorrow).get("max_degree") );
|
|
|
|
+
|
|
|
|
+ towTomorrowEntity.setMin_degree((String)JSONObject.fromObject(towTomorrow).get("min_degree") );
|
|
|
|
+
|
|
|
|
+ towTomorrowEntity.setDay_weather((String)JSONObject.fromObject(towTomorrow).get("day_weather") );
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
Object forecastobject01hDetail = JSONObject.fromObject(jsonData.get("forecast_1h")).get("0"); //24小时天气预报的 “1” 为当天的天气预报
|
|
Object forecastobject01hDetail = JSONObject.fromObject(jsonData.get("forecast_1h")).get("0"); //24小时天气预报的 “1” 为当天的天气预报
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
Object alarm = JSONObject.fromObject(jsonData).get("alarm");//报警信息
|
|
Object alarm = JSONObject.fromObject(jsonData).get("alarm");//报警信息
|
|
|
|
+
|
|
Object degree = JSONObject.fromObject(forecastobject01hDetail).get("degree");//当前温度
|
|
Object degree = JSONObject.fromObject(forecastobject01hDetail).get("degree");//当前温度
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
Object maxDegree = JSONObject.fromObject(forecastobject24hDetail).get("max_degree");//当天最高温
|
|
Object maxDegree = JSONObject.fromObject(forecastobject24hDetail).get("max_degree");//当天最高温
|
|
- Object minDegree = JSONObject.fromObject(forecastobject24hDetail).get("min_degree");//当天最低温
|
|
|
|
|
|
+
|
|
|
|
+ Object minDegree = JSONObject.fromObject(forecastobject24hDetail).get("min_degree");//当天最 低温
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
Object day_weather = JSONObject.fromObject(forecastobject24hDetail).get("day_weather");//百天天气
|
|
Object day_weather = JSONObject.fromObject(forecastobject24hDetail).get("day_weather");//百天天气
|
|
|
|
+
|
|
Object day_wind_direction = JSONObject.fromObject(forecastobject24hDetail).get("day_wind_direction");//西风
|
|
Object day_wind_direction = JSONObject.fromObject(forecastobject24hDetail).get("day_wind_direction");//西风
|
|
|
|
+
|
|
Object day_wind_power = JSONObject.fromObject(forecastobject24hDetail).get("day_wind_power");//风力
|
|
Object day_wind_power = JSONObject.fromObject(forecastobject24hDetail).get("day_wind_power");//风力
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
Object night_weather = JSONObject.fromObject(forecastobject24hDetail).get("night_weather");//夜间天气
|
|
Object night_weather = JSONObject.fromObject(forecastobject24hDetail).get("night_weather");//夜间天气
|
|
|
|
+
|
|
Object night_wind_direction = JSONObject.fromObject(forecastobject24hDetail).get("night_wind_direction");//夜间风向
|
|
Object night_wind_direction = JSONObject.fromObject(forecastobject24hDetail).get("night_wind_direction");//夜间风向
|
|
|
|
+
|
|
Object night_wind_power = JSONObject.fromObject(forecastobject24hDetail).get("night_wind_power");//夜间风力
|
|
Object night_wind_power = JSONObject.fromObject(forecastobject24hDetail).get("night_wind_power");//夜间风力
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
Object humidityValu = JSONObject.fromObject(jsonData.get("observe")).get("humidity");//湿度
|
|
Object humidityValu = JSONObject.fromObject(jsonData.get("observe")).get("humidity");//湿度
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
String airQualityIndex = AirQualityIndexUtil.queryWeather(city.substring(0, city.length() - 1));
|
|
String airQualityIndex = AirQualityIndexUtil.queryWeather(city.substring(0, city.length() - 1));
|
|
|
|
+
|
|
// log.info("空气质量为====>" + airQualityIndex);
|
|
// log.info("空气质量为====>" + airQualityIndex);
|
|
|
|
+
|
|
JSONObject forecastByhour = JSONObject.fromObject(jsonData.get("forecast_1h")); //获得逐小时数据并遍历
|
|
JSONObject forecastByhour = JSONObject.fromObject(jsonData.get("forecast_1h")); //获得逐小时数据并遍历
|
|
|
|
+
|
|
List<String> TimeList = new ArrayList<>();
|
|
List<String> TimeList = new ArrayList<>();
|
|
|
|
+
|
|
List<String> TempList = new ArrayList<>();
|
|
List<String> TempList = new ArrayList<>();
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
for (int i = 0; i <24; i++) {
|
|
for (int i = 0; i <24; i++) {
|
|
|
|
+
|
|
//现在需要将逐小时的气温数据存在表里面 //初步实现,裁剪
|
|
//现在需要将逐小时的气温数据存在表里面 //初步实现,裁剪
|
|
|
|
+
|
|
JSONObject HoureDate = JSONObject.fromObject(forecastByhour.get(String.valueOf(i)));
|
|
JSONObject HoureDate = JSONObject.fromObject(forecastByhour.get(String.valueOf(i)));
|
|
|
|
+
|
|
String timeString = (String)HoureDate.get("update_time");
|
|
String timeString = (String)HoureDate.get("update_time");
|
|
|
|
+
|
|
//时间为这种格式,进行格式化处理 20210714180000
|
|
//时间为这种格式,进行格式化处理 20210714180000
|
|
|
|
+
|
|
StringBuffer stringDate=new StringBuffer(timeString).insert(4,"-").insert(7,"-").insert(10," ").insert(13,":").insert(16,":");
|
|
StringBuffer stringDate=new StringBuffer(timeString).insert(4,"-").insert(7,"-").insert(10," ").insert(13,":").insert(16,":");
|
|
|
|
+
|
|
//存储第二天逐小时天气预报以及信息
|
|
//存储第二天逐小时天气预报以及信息
|
|
|
|
+
|
|
TimeList.add(stringDate.toString());
|
|
TimeList.add(stringDate.toString());
|
|
|
|
+
|
|
TempList.add(HoureDate.get("degree").toString());
|
|
TempList.add(HoureDate.get("degree").toString());
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
WeatherResultEntity weatherResultEntity = new WeatherResultEntity();
|
|
WeatherResultEntity weatherResultEntity = new WeatherResultEntity();
|
|
|
|
+
|
|
weatherResultEntity.setAlarm( alarm.toString());
|
|
weatherResultEntity.setAlarm( alarm.toString());
|
|
|
|
+
|
|
weatherResultEntity.setDegree((String) degree);
|
|
weatherResultEntity.setDegree((String) degree);
|
|
|
|
+
|
|
weatherResultEntity.setMax_degree((String) maxDegree);
|
|
weatherResultEntity.setMax_degree((String) maxDegree);
|
|
|
|
+
|
|
weatherResultEntity.setMin_degree((String) minDegree);
|
|
weatherResultEntity.setMin_degree((String) minDegree);
|
|
|
|
+
|
|
weatherResultEntity.setDay_weather((String) day_weather);
|
|
weatherResultEntity.setDay_weather((String) day_weather);
|
|
|
|
+
|
|
weatherResultEntity.setDay_wind_direction((String) day_wind_direction);
|
|
weatherResultEntity.setDay_wind_direction((String) day_wind_direction);
|
|
|
|
+
|
|
weatherResultEntity.setDay_wind_power((String) day_wind_power);
|
|
weatherResultEntity.setDay_wind_power((String) day_wind_power);
|
|
|
|
+
|
|
weatherResultEntity.setNight_weather((String) night_weather);
|
|
weatherResultEntity.setNight_weather((String) night_weather);
|
|
|
|
+
|
|
weatherResultEntity.setNight_wind_direction((String)night_wind_direction);
|
|
weatherResultEntity.setNight_wind_direction((String)night_wind_direction);
|
|
|
|
+
|
|
weatherResultEntity.setNight_wind_power((String) night_wind_power);
|
|
weatherResultEntity.setNight_wind_power((String) night_wind_power);
|
|
|
|
+
|
|
weatherResultEntity.setHumidity((String) humidityValu);
|
|
weatherResultEntity.setHumidity((String) humidityValu);
|
|
|
|
+
|
|
weatherResultEntity.setAirQuility( airQualityIndex);
|
|
weatherResultEntity.setAirQuility( airQualityIndex);
|
|
|
|
+
|
|
weatherResultEntity.setSendTime(new Date());
|
|
weatherResultEntity.setSendTime(new Date());
|
|
|
|
+
|
|
weatherResultEntity.setTimeList(TimeList);
|
|
weatherResultEntity.setTimeList(TimeList);
|
|
|
|
+
|
|
weatherResultEntity.setTempList(TempList);
|
|
weatherResultEntity.setTempList(TempList);
|
|
|
|
+
|
|
|
|
+ weatherResultEntity.setTomorrow(tomorrowEntity);//明天天气
|
|
|
|
+
|
|
|
|
+ weatherResultEntity.setTowTomorrow(towTomorrowEntity);//后天天气
|
|
|
|
+
|
|
|
|
+
|
|
return new Result(ResultCode.SUCCESS, weatherResultEntity);
|
|
return new Result(ResultCode.SUCCESS, weatherResultEntity);
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
/*public static void main(String[] args) {
|
|
/*public static void main(String[] args) {
|
|
// 浙江省,杭州市,余杭区,咯咯3
|
|
// 浙江省,杭州市,余杭区,咯咯3
|
|
String province = "浙江省";
|
|
String province = "浙江省";
|