|
@ -7,16 +7,20 @@ import com.ruoyi.common.core.controller.BaseController; |
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
import com.ruoyi.common.core.domain.AjaxResult; |
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
import com.ruoyi.system.service.ISysConfigService; |
|
|
import com.ruoyi.system.service.ISysConfigService; |
|
|
|
|
|
import com.zc.business.domain.DcNoStakeWarningTable; |
|
|
import com.zc.business.domain.DcRegion; |
|
|
import com.zc.business.domain.DcRegion; |
|
|
import com.zc.business.enums.UniversalEnum; |
|
|
import com.zc.business.enums.UniversalEnum; |
|
|
|
|
|
import com.zc.business.service.impl.DcNoStakeWarningTableServiceImpl; |
|
|
import com.zc.business.service.impl.DcRegionServiceImpl; |
|
|
import com.zc.business.service.impl.DcRegionServiceImpl; |
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
import com.zc.common.core.httpclient.request.RequestParams; |
|
|
import com.zc.common.core.httpclient.request.RequestParams; |
|
|
|
|
|
import com.zc.common.core.websocket.WebSocketService; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import okhttp3.Response; |
|
|
import okhttp3.Response; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
@ -55,6 +59,156 @@ public class WeatherForecastController extends BaseController { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ISysConfigService configService; |
|
|
private ISysConfigService configService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DcNoStakeWarningTableServiceImpl noStakeWarningTableService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
* 定时查询气象预警信息并上报 |
|
|
|
|
|
*/ |
|
|
|
|
|
@Scheduled(cron = "0 0/1 * * * ?") |
|
|
|
|
|
public void updateDeviceState() { |
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> hashMap = new HashMap<>(); |
|
|
|
|
|
hashMap.put("roadId", UniversalEnum.ROAD_ID.getValue()); |
|
|
|
|
|
hashMap.put("earlyWorningLevel", UniversalEnum.EARLY_WORNING_LEVEL.getValue()); |
|
|
|
|
|
//hashMap.put("managerId", UniversalEnum.MANAGER_ID.getValue());
|
|
|
|
|
|
AjaxResult ajaxResult = currentWeatherWarningInformationQuery(hashMap); |
|
|
|
|
|
|
|
|
|
|
|
String code = String.valueOf(ajaxResult.get("code")); |
|
|
|
|
|
if (!Objects.equals(code, UniversalEnum.TWO_HUNDRED.getValue())) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray data = (JSONArray) JSON.toJSON(ajaxResult.get("data")); |
|
|
|
|
|
data.forEach(item -> { |
|
|
|
|
|
JSONObject jsonObject = (JSONObject) JSON.toJSON(item); |
|
|
|
|
|
String earlyWorningSignal = jsonObject.getString("earlyWorningSignal"); |
|
|
|
|
|
String[] split = earlyWorningSignal.split(UniversalEnum.EMPTY_STRING.getValue()); |
|
|
|
|
|
String earlyWarningType = split[UniversalEnum.ZERO.getNumber()]; |
|
|
|
|
|
String warningLevel = split[UniversalEnum.THREE.getNumber()]; |
|
|
|
|
|
|
|
|
|
|
|
switch (warningLevel) { |
|
|
|
|
|
case "0": |
|
|
|
|
|
//蓝色预警
|
|
|
|
|
|
jsonObject.put("warningLevelStringNumber", UniversalEnum.ZERO.getValue()); |
|
|
|
|
|
jsonObject.put("warningLevelString", UniversalEnum.BLUE_ALERT.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "1": |
|
|
|
|
|
//黄色预警
|
|
|
|
|
|
jsonObject.put("warningLevelStringNumber", UniversalEnum.ONE.getValue()); |
|
|
|
|
|
jsonObject.put("warningLevelString", UniversalEnum.YELLOW_ALERT.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "2": |
|
|
|
|
|
//橙色预警
|
|
|
|
|
|
jsonObject.put("warningLevelStringNumber", UniversalEnum.TWO.getValue()); |
|
|
|
|
|
jsonObject.put("warningLevelString", UniversalEnum.ORANGE_ALERT.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "3": |
|
|
|
|
|
//红色预警
|
|
|
|
|
|
jsonObject.put("warningLevelStringNumber", UniversalEnum.THREE.getValue()); |
|
|
|
|
|
jsonObject.put("warningLevelString", UniversalEnum.RED_ALERT.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (earlyWarningType) { |
|
|
|
|
|
case "0": |
|
|
|
|
|
//台风
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ZERO.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.TYPHOON.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "1": |
|
|
|
|
|
//暴雨
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ONE.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.RAINSTORM.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "2": |
|
|
|
|
|
//暴雪
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TWO.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.BLIZZARD.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "3": |
|
|
|
|
|
//寒潮
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.THREE.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.COLD_WAVE.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "4": |
|
|
|
|
|
//大风
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.FOUR.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.GALE.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "5": |
|
|
|
|
|
//沙尘暴
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.FIVE.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.SANDSTORM.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "6": |
|
|
|
|
|
//高温
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.SIX.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.HYPERTHERMIA.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "7": |
|
|
|
|
|
//干旱
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.SEVEN.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.ARIDITY.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "8": |
|
|
|
|
|
//雷电
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.EIGHT.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.AEGIS.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "9": |
|
|
|
|
|
//冰雹
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.NINE.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.HAILSTONE.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "10": |
|
|
|
|
|
//霜冻
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TEN.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.FROST.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "11": |
|
|
|
|
|
//大雾
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ELEVEN.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.HEAVY_FOG.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "12": |
|
|
|
|
|
//霾
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TWELVE.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.HAZE.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
case "13": |
|
|
|
|
|
//道路结冰
|
|
|
|
|
|
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.THIRTEEN.getValue()); |
|
|
|
|
|
jsonObject.put("earlyWarningTypeString", UniversalEnum.ICY_ROADS.toString()); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//List<JSONObject> currentWeatherAndForecastInformation = redisCache.getCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue());
|
|
|
|
|
|
//List<JSONObject> collect = currentWeatherAndForecastInformation.stream().filter(ite ->
|
|
|
|
|
|
// !Objects.equals(ite.getString("earlyWorningIssueDate"), jsonObject.getString("earlyWorningIssueDate"))
|
|
|
|
|
|
// && !Objects.equals(ite.getString("earlyWorningTitle"), jsonObject.getString("earlyWorningTitle"))
|
|
|
|
|
|
// && !Objects.equals(ite.getString("stationName"), jsonObject.getString("stationName"))).collect(Collectors.toList());
|
|
|
|
|
|
List<DcNoStakeWarningTable> dcNoStakeWarningTables = noStakeWarningTableService.listDcNoStakeWarningTable(new DcNoStakeWarningTable(),null,null); |
|
|
|
|
|
List<DcNoStakeWarningTable> collect = dcNoStakeWarningTables.stream().filter(ite -> |
|
|
|
|
|
Objects.equals(ite.getWarningTime(), jsonObject.getDate("earlyWorningIssueDate")) |
|
|
|
|
|
&& Objects.equals(ite.getWarningDescription(), jsonObject.getString("earlyWorningContent")) |
|
|
|
|
|
&& Objects.equals(ite.getWarningType(), UniversalEnum.TWO.getValue())).collect(Collectors.toList()); |
|
|
|
|
|
if (collect.size() == UniversalEnum.ZERO.getNumber()) { |
|
|
|
|
|
WebSocketService.broadcast(UniversalEnum.THREE.getValue(), jsonObject); //推送事件消息 不是感知事件
|
|
|
|
|
|
DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable(); |
|
|
|
|
|
dcNoStakeWarningTable.setWarningDescription(jsonObject.getString("earlyWorningContent")); |
|
|
|
|
|
dcNoStakeWarningTable.setWarningType(UniversalEnum.TWO.getValue()); |
|
|
|
|
|
dcNoStakeWarningTable.setWarningTime(jsonObject.getDate("earlyWorningIssueDate")); |
|
|
|
|
|
dcNoStakeWarningTable.setOtherConfig(String.valueOf(jsonObject)); |
|
|
|
|
|
noStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
//redisCache.setCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue(), data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* 当前气象及预报信息查询 |
|
|
* 当前气象及预报信息查询 |
|
|
* */ |
|
|
* */ |
|
@ -67,13 +221,13 @@ public class WeatherForecastController extends BaseController { |
|
|
|
|
|
|
|
|
StringBuilder numStake = new StringBuilder(); |
|
|
StringBuilder numStake = new StringBuilder(); |
|
|
|
|
|
|
|
|
for (int i = 0; i < split.length; i++) { |
|
|
for (int i = UniversalEnum.ZERO.getNumber(); i < split.length; i++) { |
|
|
String[] split1 = split[i].split("[+]"); |
|
|
String[] split1 = split[i].split("[+]"); |
|
|
String k = split1[0].replace("K", ""); |
|
|
String k = split1[UniversalEnum.ZERO.getNumber()].replace(UniversalEnum.CAPITAL_K.getValue(), UniversalEnum.EMPTY_STRING.getValue()); |
|
|
int parseInt = Integer.parseInt(k); |
|
|
int parseInt = Integer.parseInt(k); |
|
|
numStake.append("K").append(findNearestMultipleOfFive(parseInt)).append("+000"); |
|
|
numStake.append(UniversalEnum.CAPITAL_K.getValue()).append(findNearestMultipleOfFive(parseInt)).append("+000"); |
|
|
if (i != split.length - 1) { |
|
|
if (i != split.length - UniversalEnum.ONE.getNumber()) { |
|
|
numStake.append("|"); |
|
|
numStake.append(UniversalEnum.VERTICAL_LINE.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -98,31 +252,31 @@ public class WeatherForecastController extends BaseController { |
|
|
if (response.body() != null) { |
|
|
if (response.body() != null) { |
|
|
|
|
|
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { |
|
|
JSONArray data = jsonResult.getJSONArray("data"); |
|
|
JSONArray data = jsonResult.getJSONArray("data"); |
|
|
if (data.size() != 0) { |
|
|
if (data.size() != UniversalEnum.ZERO.getNumber()) { |
|
|
redisCache.setCacheList("currentWeatherAndForecastInformation", data); |
|
|
redisCache.setCacheList("currentWeatherAndForecastInformation", data); |
|
|
return AjaxResult.success(data); |
|
|
return AjaxResult.success(data); |
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.success(redisCache.getCacheList("currentWeatherAndForecastInformation")); |
|
|
return AjaxResult.success(redisCache.getCacheList("currentWeatherAndForecastInformation")); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (Exception ignored) { |
|
|
} catch (Exception ignored) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return AjaxResult.error("请求失败"); |
|
|
return AjaxResult.error(UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static int findNearestMultipleOfFive(int number) { |
|
|
public static int findNearestMultipleOfFive(int number) { |
|
|
// 计算除以5的余数
|
|
|
// 计算除以5的余数
|
|
|
int remainder = number % 5; |
|
|
int remainder = number % UniversalEnum.FIVE.getNumber(); |
|
|
|
|
|
|
|
|
// 如果余数为0,则number已经是5的倍数
|
|
|
// 如果余数为0,则number已经是5的倍数
|
|
|
if (remainder == 0) { |
|
|
if (remainder == UniversalEnum.ZERO.getNumber()) { |
|
|
return number; |
|
|
return number; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -130,7 +284,7 @@ public class WeatherForecastController extends BaseController { |
|
|
// 要么是number加上(5 - 余数)(如果余数大于或等于3)
|
|
|
// 要么是number加上(5 - 余数)(如果余数大于或等于3)
|
|
|
// 这里选择的是较小的那个值(向上或向下取整)
|
|
|
// 这里选择的是较小的那个值(向上或向下取整)
|
|
|
int lowerMultiple = number - remainder; |
|
|
int lowerMultiple = number - remainder; |
|
|
int higherMultiple = number + (5 - remainder); |
|
|
int higherMultiple = number + (UniversalEnum.FIVE.getNumber() - remainder); |
|
|
|
|
|
|
|
|
// 返回两者中较小的那个
|
|
|
// 返回两者中较小的那个
|
|
|
return (lowerMultiple < higherMultiple) ? lowerMultiple : higherMultiple; |
|
|
return (lowerMultiple < higherMultiple) ? lowerMultiple : higherMultiple; |
|
@ -162,7 +316,7 @@ public class WeatherForecastController extends BaseController { |
|
|
if (response.body() != null) { |
|
|
if (response.body() != null) { |
|
|
|
|
|
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { |
|
|
JSONArray jsonArray = jsonResult.getJSONArray("data"); |
|
|
JSONArray jsonArray = jsonResult.getJSONArray("data"); |
|
|
List<Object> collect = jsonArray.stream().filter(item -> { |
|
|
List<Object> collect = jsonArray.stream().filter(item -> { |
|
|
JSONObject jsonObject = (JSONObject) JSON.toJSON(item); |
|
|
JSONObject jsonObject = (JSONObject) JSON.toJSON(item); |
|
@ -187,21 +341,21 @@ public class WeatherForecastController extends BaseController { |
|
|
// return false;
|
|
|
// return false;
|
|
|
//}
|
|
|
//}
|
|
|
}).collect(Collectors.toList()); |
|
|
}).collect(Collectors.toList()); |
|
|
if (collect.size() != 0) { |
|
|
if (collect.size() != UniversalEnum.ZERO.getNumber()) { |
|
|
redisCache.setCacheList("currentWeatherWarningInformationQuery", collect); |
|
|
redisCache.setCacheList("currentWeatherWarningInformationQuery", collect); |
|
|
return AjaxResult.success(collect); |
|
|
return AjaxResult.success(collect); |
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery")); |
|
|
return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery")); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (Exception ignored) { |
|
|
} catch (Exception ignored) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return AjaxResult.error("请求失败"); |
|
|
return AjaxResult.error(UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -261,18 +415,18 @@ public class WeatherForecastController extends BaseController { |
|
|
Response response // 请求响应
|
|
|
Response response // 请求响应
|
|
|
= okHttp |
|
|
= okHttp |
|
|
.headers(new HashMap<>()) |
|
|
.headers(new HashMap<>()) |
|
|
.url(weather.getString("METEOROLOGICALEARLYWARNINGURI") + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + weather.getString("KEY") + weather.getString("METEOROLOGICALEARLYWARNINGKEY")) // 请求地址
|
|
|
.url(weather.getString("METEOROLOGICALEARLYWARNINGURI") + dcRegion.getLongitude() + UniversalEnum.COMMA.getNumber() + dcRegion.getLatitude() + weather.getString("KEY") + weather.getString("METEOROLOGICALEARLYWARNINGKEY")) // 请求地址
|
|
|
.get(); // 请求方法
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
|
if (response.body() != null) { |
|
|
if (response.body() != null) { |
|
|
|
|
|
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED.getNumber()) { |
|
|
|
|
|
|
|
|
jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult, "warning", dcRegion)); |
|
|
jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult, "warning", dcRegion)); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
@ -280,7 +434,7 @@ public class WeatherForecastController extends BaseController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
redisCache.setCacheObject(weather.getString("METEOROLOGICALEARLYWARNING"), jsonObject, 13, TimeUnit.MINUTES); |
|
|
redisCache.setCacheObject(weather.getString("METEOROLOGICALEARLYWARNING"), jsonObject, UniversalEnum.THIRTEEN.getNumber(), TimeUnit.MINUTES); |
|
|
JSONArray meteorologicalEarlyWarning1 = jsonObject.getJSONArray("meteorologicalEarlyWarning1"); |
|
|
JSONArray meteorologicalEarlyWarning1 = jsonObject.getJSONArray("meteorologicalEarlyWarning1"); |
|
|
JSONArray meteorologicalEarlyWarning2 = jsonObject.getJSONArray("meteorologicalEarlyWarning2"); |
|
|
JSONArray meteorologicalEarlyWarning2 = jsonObject.getJSONArray("meteorologicalEarlyWarning2"); |
|
|
JSONArray meteorologicalEarlyWarning3 = jsonObject.getJSONArray("meteorologicalEarlyWarning3"); |
|
|
JSONArray meteorologicalEarlyWarning3 = jsonObject.getJSONArray("meteorologicalEarlyWarning3"); |
|
@ -289,14 +443,14 @@ public class WeatherForecastController extends BaseController { |
|
|
JSONArray meteorologicalEarlyWarning6 = jsonObject.getJSONArray("meteorologicalEarlyWarning6"); |
|
|
JSONArray meteorologicalEarlyWarning6 = jsonObject.getJSONArray("meteorologicalEarlyWarning6"); |
|
|
JSONArray meteorologicalEarlyWarning7 = jsonObject.getJSONArray("meteorologicalEarlyWarning7"); |
|
|
JSONArray meteorologicalEarlyWarning7 = jsonObject.getJSONArray("meteorologicalEarlyWarning7"); |
|
|
JSONArray meteorologicalEarlyWarning8 = jsonObject.getJSONArray("meteorologicalEarlyWarning8"); |
|
|
JSONArray meteorologicalEarlyWarning8 = jsonObject.getJSONArray("meteorologicalEarlyWarning8"); |
|
|
return AjaxResult.success((meteorologicalEarlyWarning1 == null ? 0 : meteorologicalEarlyWarning1.size()) + |
|
|
return AjaxResult.success((meteorologicalEarlyWarning1 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning1.size()) + |
|
|
(meteorologicalEarlyWarning2 == null ? 0 : meteorologicalEarlyWarning2.size()) + |
|
|
(meteorologicalEarlyWarning2 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning2.size()) + |
|
|
(meteorologicalEarlyWarning3 == null ? 0 : meteorologicalEarlyWarning3.size()) + |
|
|
(meteorologicalEarlyWarning3 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning3.size()) + |
|
|
(meteorologicalEarlyWarning4 == null ? 0 : meteorologicalEarlyWarning4.size()) + |
|
|
(meteorologicalEarlyWarning4 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning4.size()) + |
|
|
(meteorologicalEarlyWarning5 == null ? 0 : meteorologicalEarlyWarning5.size()) + |
|
|
(meteorologicalEarlyWarning5 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning5.size()) + |
|
|
(meteorologicalEarlyWarning6 == null ? 0 : meteorologicalEarlyWarning6.size()) + |
|
|
(meteorologicalEarlyWarning6 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning6.size()) + |
|
|
(meteorologicalEarlyWarning7 == null ? 0 : meteorologicalEarlyWarning7.size()) + |
|
|
(meteorologicalEarlyWarning7 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning7.size()) + |
|
|
(meteorologicalEarlyWarning8 == null ? 0 : meteorologicalEarlyWarning8.size())); |
|
|
(meteorologicalEarlyWarning8 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning8.size())); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -324,13 +478,13 @@ public class WeatherForecastController extends BaseController { |
|
|
Response response // 请求响应
|
|
|
Response response // 请求响应
|
|
|
= okHttp |
|
|
= okHttp |
|
|
.headers(new HashMap<>()) |
|
|
.headers(new HashMap<>()) |
|
|
.url(uri + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + weather.getString("KEY") + accessKey) // 请求地址
|
|
|
.url(uri + dcRegion.getLongitude() + UniversalEnum.COMMA.getValue() + dcRegion.getLatitude() + weather.getString("KEY") + accessKey) // 请求地址
|
|
|
.get(); // 请求方法
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
|
if (response.body() != null) { |
|
|
if (response.body() != null) { |
|
|
|
|
|
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED.getNumber()) { |
|
|
|
|
|
|
|
|
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { |
|
|
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { |
|
|
|
|
|
|
|
@ -345,7 +499,7 @@ public class WeatherForecastController extends BaseController { |
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly", dcRegion)); |
|
|
jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly", dcRegion)); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
@ -358,15 +512,15 @@ public class WeatherForecastController extends BaseController { |
|
|
|
|
|
|
|
|
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { |
|
|
if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { |
|
|
|
|
|
|
|
|
redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); |
|
|
redisCache.setCacheObject(redisKey, jsonObject, UniversalEnum.THIRTEEN.getNumber(), TimeUnit.MINUTES); |
|
|
|
|
|
|
|
|
} else if (Objects.equals(redisKey, weather.getString("METEOROLOGICALEARLYWARNING"))) { |
|
|
} else if (Objects.equals(redisKey, weather.getString("METEOROLOGICALEARLYWARNING"))) { |
|
|
|
|
|
|
|
|
redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); |
|
|
redisCache.setCacheObject(redisKey, jsonObject, UniversalEnum.THIRTEEN.getNumber(), TimeUnit.MINUTES); |
|
|
|
|
|
|
|
|
} else if (Objects.equals(redisKey, weather.getString("HOURLYWEATHER"))) { |
|
|
} else if (Objects.equals(redisKey, weather.getString("HOURLYWEATHER"))) { |
|
|
|
|
|
|
|
|
redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); |
|
|
redisCache.setCacheObject(redisKey, jsonObject, UniversalEnum.THIRTEEN.getNumber(), TimeUnit.MINUTES); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return AjaxResult.success(jsonObject); |
|
|
return AjaxResult.success(jsonObject); |
|
@ -376,7 +530,7 @@ public class WeatherForecastController extends BaseController { |
|
|
private static Object extracted(JSONObject jsonResult, String type, DcRegion dcRegion) { |
|
|
private static Object extracted(JSONObject jsonResult, String type, DcRegion dcRegion) { |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
jsonObject.put("code", jsonResult.getString("code")); |
|
|
jsonObject.put("code", jsonResult.getString("code")); |
|
|
if (Objects.equals(jsonResult.getString("code"), "200")) { |
|
|
if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED.getNumber()) { |
|
|
if (Objects.equals(type, "now")) { |
|
|
if (Objects.equals(type, "now")) { |
|
|
|
|
|
|
|
|
JSONObject object = jsonResult.getJSONObject(type); |
|
|
JSONObject object = jsonResult.getJSONObject(type); |
|
@ -389,22 +543,22 @@ public class WeatherForecastController extends BaseController { |
|
|
}); |
|
|
}); |
|
|
return jsonArray; |
|
|
return jsonArray; |
|
|
} |
|
|
} |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "500")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FIVE_HUNDRED.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:无响应或超时"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FIVE_HUNDRED.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "429")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_TWENTY_NINE.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:每分钟访问次数过多,请稍后重试"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_TWENTY_NINE.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "404")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_FOUR.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:查询的地区或者数据不存在"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_FOUR.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "403")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_THREE.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:无访问权限,可能是绑定的PackageName、BundleID、域名IP地址不一致"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_THREE.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "402")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_TWO.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:超过访问次数或余额不足以支持继续访问服务"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_TWO.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "401")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_ONE.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:认证失败,可能使用了错误的KEY、数字签名错误、KEY的类型错误"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_ONE.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "400")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:请求错误,可能包含错误的请求参数或缺少必选的请求参数"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED.getValue()); |
|
|
} else if (Objects.equals(jsonResult.getString("code"), "204")) { |
|
|
} else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED_AND_FORTY.getNumber()) { |
|
|
jsonObject.put("msg", "请求失败:请求成功,但你查询的地区暂时没有你需要的数据"); |
|
|
jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED_AND_FORTY.getValue()); |
|
|
} |
|
|
} |
|
|
return jsonObject; |
|
|
return jsonObject; |
|
|
} |
|
|
} |
|
@ -424,16 +578,16 @@ public class WeatherForecastController extends BaseController { |
|
|
Response response // 请求响应
|
|
|
Response response // 请求响应
|
|
|
= okHttp |
|
|
= okHttp |
|
|
.headers(new HashMap<>()) |
|
|
.headers(new HashMap<>()) |
|
|
.url(weather.getString("WEATHERFACTSURI") + longitude + "," + latitude + weather.getString("KEY") + weather.getString("WEATHERFACTSKEY")) // 请求地址
|
|
|
.url(weather.getString("WEATHERFACTSURI") + longitude + UniversalEnum.COMMA.getValue() + latitude + weather.getString("KEY") + weather.getString("WEATHERFACTSKEY")) // 请求地址
|
|
|
.get(); // 请求方法
|
|
|
.get(); // 请求方法
|
|
|
|
|
|
|
|
|
if (response.body() != null) { |
|
|
if (response.body() != null) { |
|
|
|
|
|
|
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); |
|
|
if (jsonResult.getInteger("code") == 200) { |
|
|
if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED.getNumber()) { |
|
|
jsonObject.put("weatherInTheAreaWhereTheIncidentOccurred", jsonResult); |
|
|
jsonObject.put("weatherInTheAreaWhereTheIncidentOccurred", jsonResult); |
|
|
} else { |
|
|
} else { |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); |
|
|
return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return AjaxResult.success(jsonObject); |
|
|
return AjaxResult.success(jsonObject); |
|
|