use of com.yh.weatherpush.entity.Tag in project weather-push by yangh124.
the class WeatherServiceImpl method getTomWeather.
@Override
public Map<Integer, String> getTomWeather(List<Tag> tags) {
Map<Integer, String> res = new HashMap<>(tags.size());
for (Tag tag : tags) {
Integer tagid = tag.getTagId();
String tagname = tag.getTagName();
String code = tag.getCode();
// 实时天气
String url = hfConfig.getDayUrl();
url = url.replace("code", code);
ResponseEntity<HfWeatherDayResp> weatherResponse = restTemplate.getForEntity(url, HfWeatherDayResp.class);
HfWeatherDayResp weatherBody = weatherResponse.getBody();
if (null == weatherBody) {
throw new ApiException("获取3天天气异常!");
}
WeatherDay weatherDay = weatherBody.getDaily().get(1);
StringBuilder builder = new StringBuilder("【明日天气】【" + tagname + "】\n\n");
builder.append(weatherDay.getTextDay()).append("\n");
builder.append("气温:").append(weatherDay.getTempMin()).append("~").append(weatherDay.getTempMax()).append("度\n\n");
builder.append("相对湿度:").append(weatherDay.getHumidity()).append("%\n");
builder.append("降水量:").append(weatherDay.getPrecip()).append(" mm\n");
builder.append(weatherDay.getWindDirDay()).append(" ").append(weatherDay.getWindScaleDay()).append("级").append("\n");
res.put(tagid, builder.toString());
}
return res;
}
Aggregations