Search in sources :

Example 1 with Tag

use of com.yh.weatherpush.entity.Tag in project weather-push by yangh124.

the class SchTaskServiceImpl method pageList.

@Override
public IPage<SchTaskPageDTO> pageList(PageParam pageParam) {
    IPage<SchTask> page = new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize());
    page = super.page(page);
    IPage<SchTaskPageDTO> res = new Page<>();
    BeanUtil.copyProperties(page, res);
    List<SchTask> records = page.getRecords();
    List<SchTaskPageDTO> resRecords = new ArrayList<>(records.size());
    if (CollUtil.isNotEmpty(records)) {
        List<Long> taskIds = records.stream().map(SchTask::getId).collect(Collectors.toList());
        Map<Long, List<Tag>> map = getTaskTagMap(taskIds);
        for (SchTask record : records) {
            SchTaskPageDTO dto = new SchTaskPageDTO();
            BeanUtil.copyProperties(record, dto);
            Long taskId = record.getId();
            List<Tag> tagList = map.get(taskId);
            dto.setTagList(tagList);
            String taskName = record.getTaskName();
            String desc = TaskEnum.getDescByName(taskName);
            dto.setTaskName(desc);
            resRecords.add(dto);
        }
    }
    res.setRecords(resRecords);
    return res;
}
Also used : ArrayList(java.util.ArrayList) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) SchTask(com.yh.weatherpush.entity.SchTask) ArrayList(java.util.ArrayList) List(java.util.List) TaskRelTag(com.yh.weatherpush.entity.TaskRelTag) Tag(com.yh.weatherpush.entity.Tag) SchTaskPageDTO(com.yh.weatherpush.dto.schtask.SchTaskPageDTO)

Example 2 with Tag

use of com.yh.weatherpush.entity.Tag in project weather-push by yangh124.

the class TagServiceImpl method create.

@Override
public void create(AddTagParam param) {
    String code = weatherService.getLocation(param.getTagName());
    Tag tag = qywxService.createTag(param.getTagId(), param.getTagName());
    tag.setCode(code);
    tag.setCtime(LocalDateTime.now());
    super.save(tag);
}
Also used : TaskRelTag(com.yh.weatherpush.entity.TaskRelTag) Tag(com.yh.weatherpush.entity.Tag)

Example 3 with Tag

use of com.yh.weatherpush.entity.Tag in project weather-push by yangh124.

the class WeatherServiceImpl method getTodayWeather.

@Override
public Map<Integer, String> getTodayWeather(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 weatherUrl = hfConfig.getGetUrl();
        weatherUrl = weatherUrl.replace("code", code);
        ResponseEntity<HfWeatherResp> weatherResponse = restTemplate.getForEntity(weatherUrl, HfWeatherResp.class);
        HfWeatherResp weatherBody = weatherResponse.getBody();
        if (null == weatherBody) {
            throw new ApiException("获取天气异常!");
        }
        // 天气指数
        String weatherIndexUrl = hfConfig.getIndexUrl();
        weatherIndexUrl = weatherIndexUrl.replace("code", code);
        ResponseEntity<HfWeatherIndexResp> weatherIndexResponse = restTemplate.getForEntity(weatherIndexUrl, HfWeatherIndexResp.class);
        HfWeatherIndexResp weatherIndexBody = weatherIndexResponse.getBody();
        if (null == weatherIndexBody) {
            throw new ApiException("获取天气指数异常!");
        }
        // 24小时天气
        String weatherHourUrl = hfConfig.getHourUrl();
        weatherHourUrl = weatherHourUrl.replace("code", code);
        ResponseEntity<HfWeatherHourResp> weatherHourResponse = restTemplate.getForEntity(weatherHourUrl, HfWeatherHourResp.class);
        HfWeatherHourResp weatherHourBody = weatherHourResponse.getBody();
        if (null == weatherHourBody) {
            throw new ApiException("获取天气指数异常!");
        }
        String s = covertWeatherData(tagname, weatherBody.getNow(), weatherIndexBody.getDaily(), weatherHourBody.getHourly());
        res.put(tagid, s);
    }
    return res;
}
Also used : HashMap(java.util.HashMap) Tag(com.yh.weatherpush.entity.Tag) ApiException(com.yh.weatherpush.exception.ApiException)

Example 4 with Tag

use of com.yh.weatherpush.entity.Tag in project weather-push by yangh124.

the class WeatherServiceImpl method getWeatherWarn.

@Override
public Map<Integer, String> getWeatherWarn(List<Tag> tags) {
    Map<Integer, String> map = new HashMap<>();
    for (Tag tag : tags) {
        String url = hfConfig.getWarnUrl();
        url = url.replace("code", tag.getCode());
        ResponseEntity<HfWeatherWarnResp> response = restTemplate.getForEntity(url, HfWeatherWarnResp.class);
        HfWeatherWarnResp body = response.getBody();
        if (null == body) {
            throw new ApiException("获取天气预警失败!");
        }
        String code = body.getCode();
        if (!"200".equals(code)) {
            throw new ApiException("获取天气预警失败! -> " + body);
        }
        String fxLink = body.getFxLink();
        List<WeatherWarn> warning = body.getWarning();
        if (CollectionUtils.isEmpty(warning)) {
            continue;
        }
        WeatherWarn weatherWarn = warning.get(0);
        String id = weatherWarn.getId();
        Boolean exist;
        try {
            exist = redisTemplate.hasKey(id);
            if (null != exist && exist) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
        Boolean res;
        try {
            res = redisTemplate.opsForValue().setIfAbsent(id, id);
            if (null != res && res) {
                String text = weatherWarn.getText();
                String sb = text + "\n详细信息请查看 -> " + "<a href=\"" + fxLink + "\">和风天气</a>";
                map.put(tag.getTagId(), sb);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Tag(com.yh.weatherpush.entity.Tag) ApiException(com.yh.weatherpush.exception.ApiException) ApiException(com.yh.weatherpush.exception.ApiException)

Example 5 with Tag

use of com.yh.weatherpush.entity.Tag in project weather-push by yangh124.

the class WeatherServiceImpl method getRedisWeather.

@Override
public Map<Integer, String> getRedisWeather(List<Tag> tags) {
    Map<Integer, String> res = new HashMap<>();
    LocalDate now = LocalDate.now();
    String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    for (Tag tag : tags) {
        Integer tagid = tag.getTagId();
        String key = format + ":" + tagid;
        String s = stringRedisTemplate.opsForValue().get(key);
        if (null != s) {
            res.put(tagid, s);
        }
    }
    return res;
}
Also used : HashMap(java.util.HashMap) Tag(com.yh.weatherpush.entity.Tag) LocalDate(java.time.LocalDate)

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