diff --git a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java index 9aefb910..580440a6 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcWarningController.java @@ -1,5 +1,7 @@ package com.zc.business.controller; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -15,6 +17,7 @@ import com.zc.business.domain.DcWarning; import com.zc.business.domain.DcWarningBatchConvert; import com.zc.business.enums.UniversalEnum; import com.zc.business.service.IDcWarningService; +import com.zc.business.utils.WeatherTrafficProposeUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -28,6 +31,7 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; +import java.util.stream.Collectors; /** * 预警信息Controller @@ -238,7 +242,21 @@ public class DcWarningController extends BaseController public TableDataInfo selectStakeWarningTable(){ startPage(); List list = dcWarningService.selectStakeWarningTable(); - return getDataTable(list); + + List updatedList = list.stream() + .peek(warningTable -> { + JSONObject otherConfig = JSONObject.parseObject(warningTable.getOtherConfig()); + String earlyWorningSignal = otherConfig.getString("earlyWorningSignal"); + String[] split = earlyWorningSignal.split(UniversalEnum.YJ_STRING.getValue()); + String content = WeatherTrafficProposeUtil.content( + Integer.parseInt(split[UniversalEnum.ONE.getNumber()]), + split[UniversalEnum.ZERO.getNumber()] + ); + warningTable.setWarningDescription(warningTable.getWarningDescription() + "\n" +content); + }) + .collect(Collectors.toList()); + + return getDataTable(updatedList); } diff --git a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java index 86445429..6998e207 100644 --- a/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java +++ b/zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java @@ -10,8 +10,10 @@ import com.ruoyi.system.service.ISysConfigService; import com.zc.business.domain.DcNoStakeWarningTable; import com.zc.business.domain.DcRegion; import com.zc.business.enums.UniversalEnum; +import com.zc.business.service.IDcWarningService; import com.zc.business.service.impl.DcNoStakeWarningTableServiceImpl; import com.zc.business.service.impl.DcRegionServiceImpl; +import com.zc.business.utils.WeatherTrafficProposeUtil; import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.request.RequestParams; @@ -62,6 +64,9 @@ public class WeatherForecastController extends BaseController { @Autowired private DcNoStakeWarningTableServiceImpl noStakeWarningTableService; + @Autowired + private IDcWarningService dcWarningService; + /*** * 定时查询气象预警信息并上报 @@ -87,9 +92,9 @@ public class WeatherForecastController extends BaseController { data.forEach(item -> { JSONObject jsonObject = (JSONObject) JSON.toJSON(item); String earlyWorningSignal = jsonObject.getString("earlyWorningSignal"); - String[] split = earlyWorningSignal.split(UniversalEnum.EMPTY_STRING.getValue()); + String[] split = earlyWorningSignal.split(UniversalEnum.YJ_STRING.getValue()); String earlyWarningType = split[UniversalEnum.ZERO.getNumber()]; - String warningLevel = split[UniversalEnum.THREE.getNumber()]; + String warningLevel = split[UniversalEnum.ONE.getNumber()]; switch (warningLevel) { case "0": @@ -186,25 +191,21 @@ public class WeatherForecastController extends BaseController { jsonObject.put("earlyWarningTypeString", UniversalEnum.ICY_ROADS.toString()); break; } - - //List currentWeatherAndForecastInformation = redisCache.getCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue()); - //List 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 dcNoStakeWarningTables = noStakeWarningTableService.listDcNoStakeWarningTable(noStakeWarningTable, null, null); List 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); + String content= WeatherTrafficProposeUtil.content(Integer.parseInt(warningLevel), earlyWarningType); + jsonObject.put("earlyWorningContent", jsonObject.getString("earlyWorningContent")+content); + WebSocketService.broadcast(UniversalEnum.THREE.getValue(), jsonObject); //推送事件消息 不是感知事件 } }); @@ -594,86 +595,59 @@ public class WeatherForecastController extends BaseController { @ApiOperation("当前气象预警信息查询") @PostMapping(value = "/currentWeatherWarningInformationQuery") public AjaxResult currentWeatherWarningInformationQuery(@RequestBody HashMap parameter) { - - try { - - OkHttp okHttp = new OkHttp(); - - RequestParams requestParams = new RequestParams(parameter); - Response response // 请求响应 - = okHttp - .headers(new HashMap<>()) - .url(UniversalEnum.CURRENT_WEATHER_WARNING_INFORMATION_QUERY.getValue()) // 请求地址 - //.url("http://10.166.133.9:38999/api/weather_service/get_earlyworning_info_jh") // 请求地址 - .data(requestParams) - .post(); // 请求方法 - - if (response.body() != null) { - - JSONObject jsonResult = JSONObject.parseObject(response.body().string()); - if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { - JSONArray jsonArray = jsonResult.getJSONArray("data"); - //List 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); - 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())); - //} else { - // return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery")); - //} - } else { - return AjaxResult.success(new ArrayList<>()); - } - } - } catch (Exception ignored) { - - - } - return AjaxResult.success(new ArrayList<>()); + List list = dcWarningService.selectStakeWarningTable(); + + List result = list.stream() + .map(table -> { + JSONObject otherConfig = JSONObject.parseObject(table.getOtherConfig()); + String earlyWorningSignal = otherConfig.getString("earlyWorningSignal"); + String[] split = earlyWorningSignal.split(UniversalEnum.YJ_STRING.getValue()); + String content = WeatherTrafficProposeUtil.content( + Integer.parseInt(split[UniversalEnum.ONE.getNumber()]), + split[UniversalEnum.ZERO.getNumber()] + ); + otherConfig.put("earlyWorningContent", table.getWarningDescription() + "\n" +content); + return otherConfig; + }) + .collect(Collectors.toList()); + return AjaxResult.success(result); + +// try { +// +// OkHttp okHttp = new OkHttp(); +// +// RequestParams requestParams = new RequestParams(parameter); +// Response response // 请求响应 +// = okHttp +// .headers(new HashMap<>()) +// .url(UniversalEnum.CURRENT_WEATHER_WARNING_INFORMATION_QUERY.getValue()) // 请求地址 +// .data(requestParams) +// .post(); // 请求方法 +// +// if (response.body() != null) { +// +// JSONObject jsonResult = JSONObject.parseObject(response.body().string()); +// if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) { +// JSONArray jsonArray = jsonResult.getJSONArray("data"); +// return AjaxResult.success(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()); +// }).collect(Collectors.toList())); +// } else { +// return AjaxResult.success(new ArrayList<>()); +// } +// } +// } catch (Exception ignored) { +// +// } +// return AjaxResult.success(new ArrayList<>()); } diff --git a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java index e4f1a166..2af0370b 100644 --- a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java @@ -2198,6 +2198,10 @@ RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateB // 空格 BLANK_SPACE(0, " "), + // 预警 + + YJ_STRING(0, "yj"), + // 金钱符 MONEY_SIGN(0, "$"), diff --git a/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java b/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java index 4b956ef8..d073adda 100644 --- a/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java +++ b/zc-business/src/main/java/com/zc/business/utils/WeatherTrafficProposeUtil.java @@ -73,11 +73,11 @@ public class WeatherTrafficProposeUtil { case RAIN_LEVEL_2: case FOG_LEVEL_2: case SNOW_LEVEL_2: - return "建议局部封闭、间断放行。"; + return "建议局部封闭、间断放行;"; case RAIN_LEVEL_1: case FOG_LEVEL_1: case SNOW_LEVEL_1: - return "建议全线封闭收费站、必要时可带队通行的控制措施。全线封闭时,正在高速公路通行的车辆应以不大于 20km/h 的速度就近驶出高速公路或驶入服务区。带队通行时,应保障交通有序通行。"; + return "建议全线封闭收费站、必要时可带队通行的控制措施。全线封闭时,正在高速公路通行的车辆应以不大于 20km/h 的速度就近驶出高速公路或驶入服务区。带队通行时,应保障交通有序通行;"; default: throw new IllegalArgumentException("Unknown weather condition: " + condition); } @@ -109,6 +109,12 @@ public class WeatherTrafficProposeUtil { } } + public static String content(int warningLevelStringNumber, String earlyWarningTypeStringNumber){ + WeatherCondition condition = WeatherCondition.fromLevelAndDescription(warningLevelStringNumber, earlyWarningTypeStringNumber); + System.out.println("Weather Condition: " + condition.name() + ", Level: " + condition.getLevel() + ", Description: " + condition.getDescription()); + return "建议速度为"+getSpeedLimit(condition) + " km/h ;\n" + getTrafficControlAdvice(condition) + "\n" + getVehicleControlAdvice(condition); + } + public static void main(String[] args) { int warningLevelStringNumber = 3; String earlyWarningTypeStringNumber= "1";