Search in sources :

Example 11 with Tag

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;
}
Also used : HashMap(java.util.HashMap) Tag(com.yh.weatherpush.entity.Tag) ApiException(com.yh.weatherpush.exception.ApiException)

Aggregations

Tag (com.yh.weatherpush.entity.Tag)11 ApiException (com.yh.weatherpush.exception.ApiException)5 TaskRelTag (com.yh.weatherpush.entity.TaskRelTag)4 HashMap (java.util.HashMap)4 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 JSONObject (com.alibaba.fastjson.JSONObject)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 SchTaskPageDTO (com.yh.weatherpush.dto.schtask.SchTaskPageDTO)1 TagDTO (com.yh.weatherpush.dto.tag.TagDTO)1 SchTask (com.yh.weatherpush.entity.SchTask)1 List (java.util.List)1