diff --git a/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java b/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java index e10d773c..6f25528c 100644 --- a/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java +++ b/zc-business/src/main/java/com/zc/business/controller/BroadcastController.java @@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSONObject; 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.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.request.RequestParams; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import okhttp3.Response; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -35,15 +38,17 @@ public class BroadcastController extends BaseController { private static int numberOfReconnections = 1; @Resource private RedisCache redisCache; - private static final String ID = "admin"; - - private static final String SECRET = "21232f297a57a5a743894a0e4a801fc3"; - - private static final String CALLBACKURL = "http://10.0.111.11/broadcast/logIn"; - - private final static String URL = HTTP + "10.0.81.106/api/REST-API/"; - - private final static String TOKENKEY = "tokenRoadTestBroadcastPlatform"; + @Autowired + private ISysConfigService configService; + //private static final String ID = "admin"; + // + //private static final String SECRET = "21232f297a57a5a743894a0e4a801fc3"; + // + //private static final String CALLBACKURL = "http://10.0.111.11/broadcast/logIn"; + // + //private final static String URL = HTTP + "10.0.81.106/api/REST-API/"; + // + //private final static String TOKENKEY = "tokenRoadTestBroadcastPlatform"; /** * 广播平台事件回调函数 @@ -68,10 +73,11 @@ public class BroadcastController extends BaseController { @ApiOperation("广播功能调用") @PostMapping(value = "/broadcastFunctionCall") public JSONObject nearCamListDistance(@RequestBody JSONObject params) throws HttpException, IOException { + JSONObject broadcast = JSONObject.parseObject(configService.selectConfigByKey("broadcast")); JSONObject jsonResult = null; OkHttp okHttp = new OkHttp(1); RequestParams requestParams = new RequestParams(params); - String tokenRoadTestBroadcastPlatform = redisCache.getCacheObject(TOKENKEY); + String tokenRoadTestBroadcastPlatform = redisCache.getCacheObject(broadcast.getString("TOKENKEY")); if (tokenRoadTestBroadcastPlatform == null) { tokenRoadTestBroadcastPlatform = getToken(); } @@ -79,7 +85,7 @@ public class BroadcastController extends BaseController { Response response // 请求响应 = okHttp .headers(new HashMap<>()) - .url(URL + params.getString("functionType") + ".do?accessToken=" + tokenRoadTestBroadcastPlatform) // 请求地址 + .url(broadcast.getString("URL") + params.getString("functionType") + ".do?accessToken=" + tokenRoadTestBroadcastPlatform) // 请求地址 .data(requestParams) // 请求参数 .post(); // 请求方法 if (response.body() != null) { @@ -101,12 +107,13 @@ public class BroadcastController extends BaseController { } public String getToken() throws HttpException, IOException { + JSONObject broadcast = JSONObject.parseObject(configService.selectConfigByKey("broadcast")); OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(); - requestParams.put("id", ID); - requestParams.put("secret", SECRET); - requestParams.put("callbackUrl", CALLBACKURL); + requestParams.put("id", broadcast.getString("ID")); + requestParams.put("secret", broadcast.getString("SECRET")); + requestParams.put("callbackUrl", broadcast.getString("CALLBACKURL")); Response response // 请求响应 = okHttp .headers(new HashMap<>()) @@ -115,7 +122,7 @@ public class BroadcastController extends BaseController { .post(); // 请求方法 if (response.body() != null) { String accessToken = JSONObject.parseObject(response.body().string()).getString("accessToken"); - redisCache.setCacheObject(TOKENKEY, accessToken, 5, TimeUnit.MINUTES); + redisCache.setCacheObject(broadcast.getString("TOKENKEY"), accessToken, 5, TimeUnit.MINUTES); return accessToken; } return null; diff --git a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java index a3cc223d..69a29eda 100644 --- a/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java +++ b/zc-business/src/main/java/com/zc/business/controller/NonAutomaticWarningController.java @@ -7,6 +7,7 @@ import com.hikvision.artemis.sdk.ArtemisHttpUtil; import com.hikvision.artemis.sdk.config.ArtemisConfig; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.system.service.ISysConfigService; import com.zc.business.domain.DcWarning; import com.zc.business.domain.NonAutomaticWarning; import com.zc.business.service.IDcWarningService; @@ -14,6 +15,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.*; @@ -37,16 +39,18 @@ import java.util.Objects; @RequestMapping("/nonAutomaticWarning") public class NonAutomaticWarningController extends BaseController { - private static final String APPKEY = "22825659"; - - private static final String APPSECRET = "7Qcq3fr1gaYws6QhyDqt"; - - private static final String URI = "/artemis/api/common/v1/event/getTopicInfo"; - - private static final String IP = "10.0.81.28"; + //private static final String APPKEY = "22825659"; + // + //private static final String APPSECRET = "7Qcq3fr1gaYws6QhyDqt"; + // + // private static final String URI = "/artemis/api/common/v1/event/getTopicInfo"; + // + //private static final String IP = "10.0.81.28"; @Resource private IDcWarningService dcWarningService; + @Autowired + private ISysConfigService configService; /* * 调用功能 @@ -278,10 +282,11 @@ public class NonAutomaticWarningController extends BaseController { // @PostConstruct public AjaxResult eventSubscriptionPostConstruct() throws Exception { NonAutomaticWarning stringStringHashMap = new NonAutomaticWarning(); - stringStringHashMap.setAPPKEY(APPKEY); - stringStringHashMap.setAPPSECRET(APPSECRET); - stringStringHashMap.setURI(URI); - stringStringHashMap.setIP(IP); + JSONObject nonAutomaticWarning = JSONObject.parseObject(configService.selectConfigByKey("nonAutomaticWarning")); + stringStringHashMap.setAPPKEY(nonAutomaticWarning.getString("APPKEY")); + stringStringHashMap.setAPPSECRET(nonAutomaticWarning.getString("APPSECRET")); + stringStringHashMap.setURI(nonAutomaticWarning.getString("URI")); + stringStringHashMap.setIP(nonAutomaticWarning.getString("IP")); return getAjaxResult(stringStringHashMap); } } 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 c6915458..c73819e3 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 @@ -5,17 +5,19 @@ import com.alibaba.fastjson.JSONObject; 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.DcRegion; import com.zc.business.service.impl.DcRegionServiceImpl; import com.zc.common.core.httpclient.OkHttp; +import com.zc.common.core.httpclient.exception.HttpException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import okhttp3.Response; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.io.IOException; import java.util.*; import java.util.concurrent.TimeUnit; @@ -30,29 +32,33 @@ import java.util.concurrent.TimeUnit; @RequestMapping("/weatherForecast") public class WeatherForecastController extends BaseController { - private static final String WEATHERFACTSURI = "https://devapi.qweather.com/v7/weather/now?location="; - private static final String WEATHERFACTS = "weatherFacts"; - private static final String WEATHERFACTSKEY = "f72f6415b3f04515be1cceb868b33a7e"; //谢朴峰 - private static final String METEOROLOGICALEARLYWARNINGURI = "https://devapi.qweather.com/v7/warning/now?location="; - private static final String METEOROLOGICALEARLYWARNING = "meteorologicalEarlyWarning"; - private static final String METEOROLOGICALEARLYWARNINGKEY = "8b5e521388154799a86e73444db76b1d"; // 高广超 - private static final String HOURLYWEATHERURI = "https://devapi.qweather.com/v7/weather/24h?location="; - private static final String HOURLYWEATHER = "hourlyWeather"; - private static final String HOURLYWEATHERKEY = "cfd87e0502684ac3a681eb19a712aec6"; // 孟凡峰 - private static final String KEY = "&key="; + //private static final String WEATHERFACTSURI = "https://devapi.qweather.com/v7/weather/now?location="; + //private static final String WEATHERFACTS = "weatherFacts"; + //private static final String WEATHERFACTSKEY = "f72f6415b3f04515be1cceb868b33a7e"; //谢朴峰 + //private static final String METEOROLOGICALEARLYWARNINGURI = "https://devapi.qweather.com/v7/warning/now?location="; + //private static final String METEOROLOGICALEARLYWARNING = "meteorologicalEarlyWarning"; + //private static final String METEOROLOGICALEARLYWARNINGKEY = "8b5e521388154799a86e73444db76b1d"; // 高广超 + //private static final String HOURLYWEATHERURI = "https://devapi.qweather.com/v7/weather/24h?location="; + //private static final String HOURLYWEATHER = "hourlyWeather"; + //private static final String HOURLYWEATHERKEY = "cfd87e0502684ac3a681eb19a712aec6"; // 孟凡峰 + //private static final String KEY = "&key="; @Resource private RedisCache redisCache; @Resource private DcRegionServiceImpl dcRegionService; + @Autowired + private ISysConfigService configService; + /* * 天气实况查询 * */ @ApiOperation("天气实况查询") @PostMapping(value = "/weatherFacts") public AjaxResult weatherFacts() { - return getAjaxResult(WEATHERFACTSURI, WEATHERFACTSKEY, WEATHERFACTS); + JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); + return getAjaxResult(weather.getString("WEATHERFACTSURI"), weather.getString("WEATHERFACTSKEY"), weather.getString("WEATHERFACTS")); } /* @@ -61,7 +67,8 @@ public class WeatherForecastController extends BaseController { @ApiOperation("气象预警查询") @PostMapping(value = "/meteorologicalEarlyWarning") public AjaxResult meteorologicalEarlyWarning() { - return getAjaxResult(METEOROLOGICALEARLYWARNINGURI, METEOROLOGICALEARLYWARNINGKEY, METEOROLOGICALEARLYWARNING); + JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); + return getAjaxResult(weather.getString("METEOROLOGICALEARLYWARNINGURI"), weather.getString("METEOROLOGICALEARLYWARNINGKEY"), weather.getString("METEOROLOGICALEARLYWARNING")); } /* @@ -70,8 +77,9 @@ public class WeatherForecastController extends BaseController { @ApiOperation("气象预警数量查询") @PostMapping(value = "/queryTheNumberOfMeteorologicalWarning") public AjaxResult queryTheNumberOfMeteorologicalWarning() { + JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); JSONObject jsonObject = new JSONObject(); - JSONObject cacheObject = redisCache.getCacheObject(METEOROLOGICALEARLYWARNING); + JSONObject cacheObject = redisCache.getCacheObject(weather.getString("METEOROLOGICALEARLYWARNING")); if (cacheObject != null) { jsonObject = cacheObject; @@ -88,7 +96,7 @@ public class WeatherForecastController extends BaseController { Response response // 请求响应 = okHttp .headers(new HashMap<>()) - .url(METEOROLOGICALEARLYWARNINGURI + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + KEY + METEOROLOGICALEARLYWARNINGKEY) // 请求地址 + .url(weather.getString("METEOROLOGICALEARLYWARNINGURI") + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + weather.getString("KEY") + weather.getString("METEOROLOGICALEARLYWARNINGKEY")) // 请求地址 .get(); // 请求方法 if (response.body() != null) { @@ -96,7 +104,7 @@ public class WeatherForecastController extends BaseController { JSONObject jsonResult = JSONObject.parseObject(response.body().string()); if (jsonResult.getInteger("code") == 200) { - jsonObject.put(METEOROLOGICALEARLYWARNING + dcRegion.getId(), extracted(jsonResult, "warning")); + jsonObject.put(weather.getString("METEOROLOGICALEARLYWARNING") + dcRegion.getId(), extracted(jsonResult, "warning")); } else { return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); @@ -107,7 +115,7 @@ public class WeatherForecastController extends BaseController { } } } - redisCache.setCacheObject(METEOROLOGICALEARLYWARNING, jsonObject, 13, TimeUnit.MINUTES); + redisCache.setCacheObject(weather.getString("METEOROLOGICALEARLYWARNING"), jsonObject, 13, TimeUnit.MINUTES); JSONArray meteorologicalEarlyWarning1 = jsonObject.getJSONArray("meteorologicalEarlyWarning1"); JSONArray meteorologicalEarlyWarning2 = jsonObject.getJSONArray("meteorologicalEarlyWarning2"); JSONArray meteorologicalEarlyWarning3 = jsonObject.getJSONArray("meteorologicalEarlyWarning3"); @@ -133,10 +141,12 @@ public class WeatherForecastController extends BaseController { @ApiOperation("逐小时天气查询") @PostMapping(value = "/hourlyWeather") public AjaxResult hourlyWeather() { - return getAjaxResult(HOURLYWEATHERURI, HOURLYWEATHERKEY, HOURLYWEATHER); + JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); + return getAjaxResult(weather.getString("HOURLYWEATHERURI"), weather.getString("HOURLYWEATHERKEY"), weather.getString("HOURLYWEATHER")); } private AjaxResult getAjaxResult(String uri, String accessKey, String redisKey) { + JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); JSONObject cacheObject = redisCache.getCacheObject(redisKey); @@ -159,7 +169,7 @@ public class WeatherForecastController extends BaseController { Response response // 请求响应 = okHttp .headers(new HashMap<>()) - .url(uri + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + KEY + accessKey) // 请求地址 + .url(uri + dcRegion.getLongitude() + "," + dcRegion.getLatitude() + weather.getString("KEY") + accessKey) // 请求地址 .get(); // 请求方法 if (response.body() != null) { @@ -167,15 +177,15 @@ public class WeatherForecastController extends BaseController { JSONObject jsonResult = JSONObject.parseObject(response.body().string()); if (jsonResult.getInteger("code") == 200) { - if (Objects.equals(redisKey, WEATHERFACTS)) { + if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "now")); - } else if (Objects.equals(redisKey, METEOROLOGICALEARLYWARNING)) { + } else if (Objects.equals(redisKey, weather.getString("METEOROLOGICALEARLYWARNING"))) { jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "warning")); - } else if (Objects.equals(redisKey, HOURLYWEATHER)) { + } else if (Objects.equals(redisKey, weather.getString("HOURLYWEATHER"))) { jsonObject.put(redisKey + dcRegion.getId(), extracted(jsonResult, "hourly")); } @@ -191,15 +201,15 @@ public class WeatherForecastController extends BaseController { } - if (Objects.equals(redisKey, WEATHERFACTS)) { + if (Objects.equals(redisKey, weather.getString("WEATHERFACTS"))) { redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); - } else if (Objects.equals(redisKey, METEOROLOGICALEARLYWARNING)) { + } else if (Objects.equals(redisKey, weather.getString("METEOROLOGICALEARLYWARNING"))) { redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); - } else if (Objects.equals(redisKey, HOURLYWEATHER)) { + } else if (Objects.equals(redisKey, weather.getString("HOURLYWEATHER"))) { redisCache.setCacheObject(redisKey, jsonObject, 13, TimeUnit.MINUTES); } @@ -236,4 +246,35 @@ public class WeatherForecastController extends BaseController { } return jsonObject; } + + /* + * 逐小时天气查询 + * */ + @ApiOperation("查询指定经纬度天气") + @GetMapping(value = "/queryTheSpecifiedLatitudeAndLongitudeWeather/{longitude}/{latitude}") + public AjaxResult queryTheSpecifiedLatitudeAndLongitudeWeather(@PathVariable String longitude, @PathVariable String latitude) throws HttpException, IOException { + + JSONObject weather = JSONObject.parseObject(configService.selectConfigByKey("weather")); + JSONObject jsonObject = new JSONObject(); + + OkHttp okHttp = new OkHttp(); + + Response response // 请求响应 + = okHttp + .headers(new HashMap<>()) + .url(weather.getString("WEATHERFACTSURI") + longitude + "," + latitude + weather.getString("KEY") + weather.getString("WEATHERFACTSKEY")) // 请求地址 + .get(); // 请求方法 + + if (response.body() != null) { + + JSONObject jsonResult = JSONObject.parseObject(response.body().string()); + if (jsonResult.getInteger("code") == 200) { + jsonObject.put("weatherInTheAreaWhereTheIncidentOccurred",jsonResult); + } else { + return AjaxResult.error(jsonResult.getInteger("code"), "请求失败"); + } + } + return AjaxResult.success(jsonObject); + } + }