Browse Source

天气定时

develop
王兴琳 3 months ago
parent
commit
58408ec099
  1. 59
      zc-business/src/main/java/com/zc/business/controller/WeatherForecastController.java

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

@ -213,7 +213,66 @@ public class WeatherForecastController extends BaseController {
}
@Scheduled(cron = "0 45 * * * ?")
public void HourWeather(){
HashMap<String, Object> parameter = new HashMap<>();
parameter.put("forecastHour",UniversalEnum.TWENTY_FOUR.getNumber());
parameter.put("managerId","YG10201");
parameter.put("roadId","G003537");
parameter.put("stakeNum","K60+000|K105+000|K145+000|K165+000|K175+000|K190+000|K200+000|K205+000");
//拿到获取到的桩号值并处理拆分
String stakeNum = String.valueOf(parameter.get("stakeNum"));
String[] split = stakeNum.split("[|]");
StringBuilder numStake = new StringBuilder();
//循环执行查询周围最近的5的倍数的桩号(集团接口需求 桩号从K50+000开始 K55+000 K60+000……以此类推)
for (int i = UniversalEnum.ZERO.getNumber(); i < split.length; i++) {
String[] split1 = split[i].split("[+]");
String k = split1[UniversalEnum.ZERO.getNumber()].replace(UniversalEnum.CAPITAL_K.getValue(), UniversalEnum.EMPTY_STRING.getValue());
int parseInt = Integer.parseInt(k);
numStake.append(UniversalEnum.CAPITAL_K.getValue()).append(findNearestMultipleOfFive(parseInt)).append("+000");
if (i != split.length - UniversalEnum.ONE.getNumber()) {
numStake.append(UniversalEnum.VERTICAL_LINE.getValue());
}
}
parameter.put("stakeNum", numStake);
try {
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(parameter);
Response response // 请求响应
= okHttp
.headers(new HashMap<>())
.url(UniversalEnum.CURRENT_WEATHER_AND_FORECAST_INFORMATION.getValue()) // 请求地址
//.url("http://10.166.133.9:38999/api/weather_service/get_weather_info_jh") // 请求地址
.data(requestParams)
.post(); // 请求方法
if (response.body() != null) {
JSONObject jsonResult = JSONObject.parseObject(response.body().string());
//判断请求是否成功 成功则判断data字段数组长度是否为0 否则获取redis中的缓存进行返回
if (jsonResult.getInteger("code") == UniversalEnum.TWO_HUNDRED.getNumber()) {
JSONArray data = jsonResult.getJSONArray("data");
;
JSONArray jsonArray = processingWeatherData(data);
//判断返回data是否不为0 不为0则将数据进行返回 为0则获取redis中的缓存进行返回
if (jsonArray.size() != UniversalEnum.ZERO.getNumber()) {
redisCache.deleteObject("twentyFourHourWeather");
redisCache.setCacheObject("twentyFourHourWeather", jsonArray);
}
}
}
}catch (Exception ignored) {
logger.error(String.valueOf(ignored));
}
}
/*
* 当前气象及预报信息查询
* */

Loading…
Cancel
Save