Browse Source

优化气象预警返回参数

develop
zhaoxianglong 5 months ago
parent
commit
1a7fae8e70
  1. 285
      zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

285
zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

@ -80,130 +80,133 @@ public class WeatherForecastController extends BaseController {
return; return;
} }
JSONArray data = (JSONArray) JSON.toJSON(ajaxResult.get("data")); JSONArray data = (JSONArray) JSON.toJSON(ajaxResult.get("data"));
List<DcNoStakeWarningTable> dcNoStakeWarningTables = noStakeWarningTableService.listDcNoStakeWarningTable(new DcNoStakeWarningTable(),null,null); if (data.size() > UniversalEnum.ZERO.getNumber()) {
data.forEach(item -> {
JSONObject jsonObject = (JSONObject) JSON.toJSON(item); List<DcNoStakeWarningTable> dcNoStakeWarningTables = noStakeWarningTableService.listDcNoStakeWarningTable(new DcNoStakeWarningTable(), null, null);
String earlyWorningSignal = jsonObject.getString("earlyWorningSignal"); data.forEach(item -> {
String[] split = earlyWorningSignal.split(UniversalEnum.EMPTY_STRING.getValue()); JSONObject jsonObject = (JSONObject) JSON.toJSON(item);
String earlyWarningType = split[UniversalEnum.ZERO.getNumber()]; String earlyWorningSignal = jsonObject.getString("earlyWorningSignal");
String warningLevel = split[UniversalEnum.THREE.getNumber()]; String[] split = earlyWorningSignal.split(UniversalEnum.EMPTY_STRING.getValue());
String earlyWarningType = split[UniversalEnum.ZERO.getNumber()];
switch (warningLevel) { String warningLevel = split[UniversalEnum.THREE.getNumber()];
case "0":
//蓝色预警 switch (warningLevel) {
jsonObject.put("warningLevelStringNumber", UniversalEnum.ZERO.getValue()); case "0":
jsonObject.put("warningLevelString", UniversalEnum.BLUE_ALERT.toString()); //蓝色预警
break; jsonObject.put("warningLevelStringNumber", UniversalEnum.ZERO.getValue());
case "1": jsonObject.put("warningLevelString", UniversalEnum.BLUE_ALERT.toString());
//黄色预警 break;
jsonObject.put("warningLevelStringNumber", UniversalEnum.ONE.getValue()); case "1":
jsonObject.put("warningLevelString", UniversalEnum.YELLOW_ALERT.toString()); //黄色预警
break; jsonObject.put("warningLevelStringNumber", UniversalEnum.ONE.getValue());
case "2": jsonObject.put("warningLevelString", UniversalEnum.YELLOW_ALERT.toString());
//橙色预警 break;
jsonObject.put("warningLevelStringNumber", UniversalEnum.TWO.getValue()); case "2":
jsonObject.put("warningLevelString", UniversalEnum.ORANGE_ALERT.toString()); //橙色预警
break; jsonObject.put("warningLevelStringNumber", UniversalEnum.TWO.getValue());
case "3": jsonObject.put("warningLevelString", UniversalEnum.ORANGE_ALERT.toString());
//红色预警 break;
jsonObject.put("warningLevelStringNumber", UniversalEnum.THREE.getValue()); case "3":
jsonObject.put("warningLevelString", UniversalEnum.RED_ALERT.toString()); //红色预警
break; jsonObject.put("warningLevelStringNumber", UniversalEnum.THREE.getValue());
} jsonObject.put("warningLevelString", UniversalEnum.RED_ALERT.toString());
break;
}
switch (earlyWarningType) { switch (earlyWarningType) {
case "0": case "0":
//台风 //台风
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ZERO.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ZERO.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.TYPHOON.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.TYPHOON.toString());
break; break;
case "1": case "1":
//暴雨 //暴雨
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ONE.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ONE.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.RAINSTORM.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.RAINSTORM.toString());
break; break;
case "2": case "2":
//暴雪 //暴雪
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TWO.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TWO.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.BLIZZARD.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.BLIZZARD.toString());
break; break;
case "3": case "3":
//寒潮 //寒潮
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.THREE.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.THREE.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.COLD_WAVE.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.COLD_WAVE.toString());
break; break;
case "4": case "4":
//大风 //大风
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.FOUR.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.FOUR.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.GALE.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.GALE.toString());
break; break;
case "5": case "5":
//沙尘暴 //沙尘暴
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.FIVE.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.FIVE.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.SANDSTORM.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.SANDSTORM.toString());
break; break;
case "6": case "6":
//高温 //高温
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.SIX.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.SIX.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.HYPERTHERMIA.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.HYPERTHERMIA.toString());
break; break;
case "7": case "7":
//干旱 //干旱
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.SEVEN.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.SEVEN.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.ARIDITY.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.ARIDITY.toString());
break; break;
case "8": case "8":
//雷电 //雷电
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.EIGHT.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.EIGHT.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.AEGIS.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.AEGIS.toString());
break; break;
case "9": case "9":
//冰雹 //冰雹
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.NINE.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.NINE.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.HAILSTONE.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.HAILSTONE.toString());
break; break;
case "10": case "10":
//霜冻 //霜冻
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TEN.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TEN.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.FROST.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.FROST.toString());
break; break;
case "11": case "11":
//大雾 //大雾
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ELEVEN.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.ELEVEN.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.HEAVY_FOG.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.HEAVY_FOG.toString());
break; break;
case "12": case "12":
//霾 //霾
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TWELVE.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.TWELVE.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.HAZE.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.HAZE.toString());
break; break;
case "13": case "13":
//道路结冰 //道路结冰
jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.THIRTEEN.getValue()); jsonObject.put("earlyWarningTypeStringNumber", UniversalEnum.THIRTEEN.getValue());
jsonObject.put("earlyWarningTypeString", UniversalEnum.ICY_ROADS.toString()); jsonObject.put("earlyWarningTypeString", UniversalEnum.ICY_ROADS.toString());
break; break;
} }
//List<JSONObject> currentWeatherAndForecastInformation = redisCache.getCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue()); //List<JSONObject> currentWeatherAndForecastInformation = redisCache.getCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue());
//List<JSONObject> collect = currentWeatherAndForecastInformation.stream().filter(ite -> //List<JSONObject> collect = currentWeatherAndForecastInformation.stream().filter(ite ->
// !Objects.equals(ite.getString("earlyWorningIssueDate"), jsonObject.getString("earlyWorningIssueDate")) // !Objects.equals(ite.getString("earlyWorningIssueDate"), jsonObject.getString("earlyWorningIssueDate"))
// && !Objects.equals(ite.getString("earlyWorningTitle"), jsonObject.getString("earlyWorningTitle")) // && !Objects.equals(ite.getString("earlyWorningTitle"), jsonObject.getString("earlyWorningTitle"))
// && !Objects.equals(ite.getString("stationName"), jsonObject.getString("stationName"))).collect(Collectors.toList()); // && !Objects.equals(ite.getString("stationName"), jsonObject.getString("stationName"))).collect(Collectors.toList());
List<DcNoStakeWarningTable> collect = dcNoStakeWarningTables.stream().filter(ite -> List<DcNoStakeWarningTable> collect = dcNoStakeWarningTables.stream().filter(ite ->
Objects.equals(ite.getWarningTime(), jsonObject.getDate("earlyWorningIssueDate")) Objects.equals(ite.getWarningTime(), jsonObject.getDate("earlyWorningIssueDate"))
&& Objects.equals(ite.getWarningDescription(), jsonObject.getString("earlyWorningContent")) && Objects.equals(ite.getWarningDescription(), jsonObject.getString("earlyWorningContent"))
&& Objects.equals(ite.getWarningType(), UniversalEnum.TWO.getValue())).collect(Collectors.toList()); && Objects.equals(ite.getWarningType(), UniversalEnum.TWO.getValue())).collect(Collectors.toList());
if (collect.size() == UniversalEnum.ZERO.getNumber()) { if (collect.size() == UniversalEnum.ZERO.getNumber()) {
WebSocketService.broadcast(UniversalEnum.THREE.getValue(), jsonObject); //推送事件消息 不是感知事件 WebSocketService.broadcast(UniversalEnum.THREE.getValue(), jsonObject); //推送事件消息 不是感知事件
DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable(); DcNoStakeWarningTable dcNoStakeWarningTable = new DcNoStakeWarningTable();
dcNoStakeWarningTable.setWarningDescription(jsonObject.getString("earlyWorningContent")); dcNoStakeWarningTable.setWarningDescription(jsonObject.getString("earlyWorningContent"));
dcNoStakeWarningTable.setWarningType(UniversalEnum.TWO.getValue()); dcNoStakeWarningTable.setWarningType(UniversalEnum.TWO.getValue());
dcNoStakeWarningTable.setWarningTime(jsonObject.getDate("earlyWorningIssueDate")); dcNoStakeWarningTable.setWarningTime(jsonObject.getDate("earlyWorningIssueDate"));
dcNoStakeWarningTable.setOtherConfig(String.valueOf(jsonObject)); dcNoStakeWarningTable.setOtherConfig(String.valueOf(jsonObject));
noStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable); noStakeWarningTableService.addDcNoStakeWarningTable(dcNoStakeWarningTable);
} }
}); });
}
//redisCache.setCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue(), data); //redisCache.setCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue(), data);
@ -318,7 +321,33 @@ public class WeatherForecastController extends BaseController {
JSONObject jsonResult = JSONObject.parseObject(response.body().string()); JSONObject jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { 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);
// return Objects.equals(jsonObject.getString("stationName"), UniversalEnum.CHANGQING_COUNTY.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.PING_YIN.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.DONG_PING.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.MONKAMI.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.LIANG_SHAN.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.JIA_XIANG.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.JU_YE.getValue())
// || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.YUNCHENG_A_COUNTY_IN_SHANDONG_PROVINCE.getValue());
// //if (Objects.equals(jsonObject.getString("stationName"), "长清")
// // || Objects.equals(jsonObject.getString("stationName"), "平阴")
// // || Objects.equals(jsonObject.getString("stationName"), "东平")
// // || Objects.equals(jsonObject.getString("stationName"), "汶上")
// // || Objects.equals(jsonObject.getString("stationName"), "梁山")
// // || Objects.equals(jsonObject.getString("stationName"), "嘉祥")
// // || Objects.equals(jsonObject.getString("stationName"), "巨野")
// // || Objects.equals(jsonObject.getString("stationName"), "郓城")) {
// // return true;
// //} else {
// // return false;
// //}
//}).collect(Collectors.toList());
//if (collect.size() != UniversalEnum.ZERO.getNumber()) {
// redisCache.deleteObject("currentWeatherWarningInformationQuery");
// redisCache.setCacheList("currentWeatherWarningInformationQuery", collect);
return AjaxResult.success(jsonArray.stream().filter(item -> {
JSONObject jsonObject = (JSONObject) JSON.toJSON(item); JSONObject jsonObject = (JSONObject) JSON.toJSON(item);
return Objects.equals(jsonObject.getString("stationName"), UniversalEnum.CHANGQING_COUNTY.getValue()) return Objects.equals(jsonObject.getString("stationName"), UniversalEnum.CHANGQING_COUNTY.getValue())
|| Objects.equals(jsonObject.getString("stationName"), UniversalEnum.PING_YIN.getValue()) || Objects.equals(jsonObject.getString("stationName"), UniversalEnum.PING_YIN.getValue())
@ -340,14 +369,10 @@ public class WeatherForecastController extends BaseController {
//} else { //} else {
// return false; // return false;
//} //}
}).collect(Collectors.toList()); }).collect(Collectors.toList()));
if (collect.size() != UniversalEnum.ZERO.getNumber()) { //} else {
redisCache.deleteObject("currentWeatherWarningInformationQuery"); // return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery"));
redisCache.setCacheList("currentWeatherWarningInformationQuery", collect); //}
return AjaxResult.success(collect);
} else {
return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery"));
}
} else { } else {
return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue());
} }

Loading…
Cancel
Save