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 2c16ff5f..d612aad8 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 @@ -7,16 +7,20 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.redis.RedisCache; 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.impl.DcNoStakeWarningTableServiceImpl; import com.zc.business.service.impl.DcRegionServiceImpl; import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.request.RequestParams; +import com.zc.common.core.websocket.WebSocketService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import okhttp3.Response; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -55,25 +59,175 @@ public class WeatherForecastController extends BaseController { @Autowired private ISysConfigService configService; + @Autowired + private DcNoStakeWarningTableServiceImpl noStakeWarningTableService; + + + /*** + * 定时查询气象预警信息并上报 + */ + @Scheduled(cron = "0 0/1 * * * ?") + public void updateDeviceState() { + + HashMap 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 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(new DcNoStakeWarningTable(),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); + } + + }); + //redisCache.setCacheList(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue(), data); + + + } + /* * 当前气象及预报信息查询 * */ @ApiOperation("当前气象及预报信息查询") @PostMapping(value = "/currentWeatherAndForecastInformation") - public AjaxResult currentWeatherAndForecastInformation(@RequestBody HashMap parameter) { + public AjaxResult currentWeatherAndForecastInformation(@RequestBody HashMap parameter) { String stakeNum = String.valueOf(parameter.get("stakeNum")); String[] split = stakeNum.split("[|]"); 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 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); - numStake.append("K").append(findNearestMultipleOfFive(parseInt)).append("+000"); - if (i != split.length - 1) { - numStake.append("|"); + numStake.append(UniversalEnum.CAPITAL_K.getValue()).append(findNearestMultipleOfFive(parseInt)).append("+000"); + if (i != split.length - UniversalEnum.ONE.getNumber()) { + numStake.append(UniversalEnum.VERTICAL_LINE.getValue()); } } @@ -98,31 +252,31 @@ public class WeatherForecastController extends BaseController { if (response.body() != null) { 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"); - if (data.size() != 0) { + if (data.size() != UniversalEnum.ZERO.getNumber()) { redisCache.setCacheList("currentWeatherAndForecastInformation", data); return AjaxResult.success(data); } else { return AjaxResult.success(redisCache.getCacheList("currentWeatherAndForecastInformation")); } } else { - return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); } } } catch (Exception ignored) { } - return AjaxResult.error("请求失败"); + return AjaxResult.error(UniversalEnum.REQUEST_FAILED.getValue()); } public static int findNearestMultipleOfFive(int number) { // 计算除以5的余数 - int remainder = number % 5; + int remainder = number % UniversalEnum.FIVE.getNumber(); // 如果余数为0,则number已经是5的倍数 - if (remainder == 0) { + if (remainder == UniversalEnum.ZERO.getNumber()) { return number; } @@ -130,7 +284,7 @@ public class WeatherForecastController extends BaseController { // 要么是number加上(5 - 余数)(如果余数大于或等于3) // 这里选择的是较小的那个值(向上或向下取整) int lowerMultiple = number - remainder; - int higherMultiple = number + (5 - remainder); + int higherMultiple = number + (UniversalEnum.FIVE.getNumber() - remainder); // 返回两者中较小的那个 return (lowerMultiple < higherMultiple) ? lowerMultiple : higherMultiple; @@ -162,7 +316,7 @@ public class WeatherForecastController extends BaseController { if (response.body() != null) { 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"); List collect = jsonArray.stream().filter(item -> { JSONObject jsonObject = (JSONObject) JSON.toJSON(item); @@ -187,21 +341,21 @@ public class WeatherForecastController extends BaseController { // return false; //} }).collect(Collectors.toList()); - if (collect.size() != 0) { + if (collect.size() != UniversalEnum.ZERO.getNumber()) { redisCache.setCacheList("currentWeatherWarningInformationQuery", collect); return AjaxResult.success(collect); } else { return AjaxResult.success(redisCache.getCacheList("currentWeatherWarningInformationQuery")); } } else { - return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); } } } catch (Exception ignored) { } - return AjaxResult.error("请求失败"); + return AjaxResult.error(UniversalEnum.REQUEST_FAILED.getValue()); } @@ -261,18 +415,18 @@ public class WeatherForecastController extends BaseController { Response response // 请求响应 = okHttp .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(); // 请求方法 if (response.body() != null) { 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)); } else { - return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); } } } 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 meteorologicalEarlyWarning2 = jsonObject.getJSONArray("meteorologicalEarlyWarning2"); JSONArray meteorologicalEarlyWarning3 = jsonObject.getJSONArray("meteorologicalEarlyWarning3"); @@ -289,14 +443,14 @@ public class WeatherForecastController extends BaseController { JSONArray meteorologicalEarlyWarning6 = jsonObject.getJSONArray("meteorologicalEarlyWarning6"); JSONArray meteorologicalEarlyWarning7 = jsonObject.getJSONArray("meteorologicalEarlyWarning7"); JSONArray meteorologicalEarlyWarning8 = jsonObject.getJSONArray("meteorologicalEarlyWarning8"); - return AjaxResult.success((meteorologicalEarlyWarning1 == null ? 0 : meteorologicalEarlyWarning1.size()) + - (meteorologicalEarlyWarning2 == null ? 0 : meteorologicalEarlyWarning2.size()) + - (meteorologicalEarlyWarning3 == null ? 0 : meteorologicalEarlyWarning3.size()) + - (meteorologicalEarlyWarning4 == null ? 0 : meteorologicalEarlyWarning4.size()) + - (meteorologicalEarlyWarning5 == null ? 0 : meteorologicalEarlyWarning5.size()) + - (meteorologicalEarlyWarning6 == null ? 0 : meteorologicalEarlyWarning6.size()) + - (meteorologicalEarlyWarning7 == null ? 0 : meteorologicalEarlyWarning7.size()) + - (meteorologicalEarlyWarning8 == null ? 0 : meteorologicalEarlyWarning8.size())); + return AjaxResult.success((meteorologicalEarlyWarning1 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning1.size()) + + (meteorologicalEarlyWarning2 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning2.size()) + + (meteorologicalEarlyWarning3 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning3.size()) + + (meteorologicalEarlyWarning4 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning4.size()) + + (meteorologicalEarlyWarning5 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning5.size()) + + (meteorologicalEarlyWarning6 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning6.size()) + + (meteorologicalEarlyWarning7 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning7.size()) + + (meteorologicalEarlyWarning8 == null ? UniversalEnum.ZERO.getNumber() : meteorologicalEarlyWarning8.size())); } @@ -324,13 +478,13 @@ public class WeatherForecastController extends BaseController { Response response // 请求响应 = okHttp .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(); // 请求方法 if (response.body() != null) { 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"))) { @@ -345,7 +499,7 @@ public class WeatherForecastController extends BaseController { jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly", dcRegion)); } } else { - return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); } } } catch (Exception e) { @@ -358,15 +512,15 @@ public class WeatherForecastController extends BaseController { 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"))) { - redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); + redisCache.setCacheObject(redisKey, jsonObject, UniversalEnum.THIRTEEN.getNumber(), TimeUnit.MINUTES); } 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); @@ -376,7 +530,7 @@ public class WeatherForecastController extends BaseController { private static Object extracted(JSONObject jsonResult, String type, DcRegion dcRegion) { JSONObject jsonObject = new JSONObject(); 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")) { JSONObject object = jsonResult.getJSONObject(type); @@ -389,22 +543,22 @@ public class WeatherForecastController extends BaseController { }); return jsonArray; } - } else if (Objects.equals(jsonResult.getString("code"), "500")) { - jsonObject.put("msg", "请求失败:无响应或超时"); - } else if (Objects.equals(jsonResult.getString("code"), "429")) { - jsonObject.put("msg", "请求失败:每分钟访问次数过多,请稍后重试"); - } else if (Objects.equals(jsonResult.getString("code"), "404")) { - jsonObject.put("msg", "请求失败:查询的地区或者数据不存在"); - } else if (Objects.equals(jsonResult.getString("code"), "403")) { - jsonObject.put("msg", "请求失败:无访问权限,可能是绑定的PackageName、BundleID、域名IP地址不一致"); - } else if (Objects.equals(jsonResult.getString("code"), "402")) { - jsonObject.put("msg", "请求失败:超过访问次数或余额不足以支持继续访问服务"); - } else if (Objects.equals(jsonResult.getString("code"), "401")) { - jsonObject.put("msg", "请求失败:认证失败,可能使用了错误的KEY、数字签名错误、KEY的类型错误"); - } else if (Objects.equals(jsonResult.getString("code"), "400")) { - jsonObject.put("msg", "请求失败:请求错误,可能包含错误的请求参数或缺少必选的请求参数"); - } else if (Objects.equals(jsonResult.getString("code"), "204")) { - jsonObject.put("msg", "请求失败:请求成功,但你查询的地区暂时没有你需要的数据"); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FIVE_HUNDRED.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FIVE_HUNDRED.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_TWENTY_NINE.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_TWENTY_NINE.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_FOUR.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_FOUR.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_THREE.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_THREE.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_TWO.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_TWO.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_ONE.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED_AND_ONE.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_FOUR_HUNDRED.getValue()); + } else if (jsonResult.getInteger("code") == UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED_AND_FORTY.getNumber()) { + jsonObject.put("msg", UniversalEnum.WEATHER_FORECAST_TWO_HUNDRED_AND_FORTY.getValue()); } return jsonObject; } @@ -424,16 +578,16 @@ public class WeatherForecastController extends BaseController { Response response // 请求响应 = okHttp .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(); // 请求方法 if (response.body() != null) { 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); } else { - return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + return AjaxResult.error(jsonResult.getInteger("code"), UniversalEnum.REQUEST_FAILED.getValue()); } } return AjaxResult.success(jsonObject); 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 3611c4c6..68208a6d 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 @@ -31,6 +31,9 @@ public enum UniversalEnum { // http HTTP(0, "http://"), + // https + HTTPS(0, "https://"), + // weixintuisontoken WEIXINTUISONTOKEN(0, "weixintuisontoken"),