Search in sources :

Example 6 with Tag

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

the class QywxServiceImpl method createTag.

@Override
public Tag createTag(Integer tagId, String tagName) {
    String createUrl = qywxConfig.getTag().getCreateUrl();
    String token = getOtherToken();
    createUrl = createUrl.replace("ACCESS_TOKEN", token);
    JSONObject param = new JSONObject();
    if (null != tagId) {
        param.put("tagid", tagId);
    }
    param.put("tagname", tagName);
    ResponseEntity<JSONObject> response = restTemplate.postForEntity(createUrl, param, JSONObject.class);
    JSONObject body = response.getBody();
    if (null == body) {
        throw new ApiException("创建标签失败!");
    }
    Integer errcode = body.getInteger("errcode");
    if (!errcode.equals(0)) {
        throw new ApiException("创建标签失败! -> " + body.getString("errmsg"));
    }
    tagId = body.getInteger("tagid");
    Tag tag = new Tag();
    tag.setTagId(tagId);
    tag.setTagName(tagName);
    return tag;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) Tag(com.yh.weatherpush.entity.Tag) ApiException(com.yh.weatherpush.exception.ApiException)

Example 7 with Tag

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

the class WeatherTodayJob method execute.

@Override
public void execute(JobExecutionContext jobExecutionContext) {
    log.info("============= WeatherTodayJob start =============");
    String taskId = jobExecutionContext.getJobDetail().getKey().getName();
    List<Tag> tagList = tagService.getTagListForJob(taskId);
    if (CollUtil.isNotEmpty(tagList)) {
        boolean holiday = holidayService.isOffDay(LocalDate.now());
        if (holiday) {
            return;
        }
        String token = qywxService.getPushToken();
        Map<Integer, String> map = weatherService.getRedisWeather(tagList);
        qywxService.pushWeatherMsg(token, map);
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info(format + " -> 天气推送成功");
    }
    log.info("============= WeatherTodayJob end =============");
}
Also used : LocalDateTime(java.time.LocalDateTime) Tag(com.yh.weatherpush.entity.Tag)

Example 8 with Tag

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

the class WeatherTomorrowJob method execute.

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    log.info("============= WeatherTomorrowJob start =============");
    String taskId = jobExecutionContext.getJobDetail().getKey().getName();
    List<Tag> tagList = tagService.getTagListForJob(taskId);
    if (CollUtil.isNotEmpty(tagList)) {
        LocalDate date = LocalDate.now().plusDays(1);
        boolean holiday = holidayService.isOffDay(date);
        if (holiday) {
            return;
        }
        String token = qywxService.getPushToken();
        Map<Integer, String> map = weatherService.getTomWeather(tagList);
        qywxService.pushWeatherMsg(token, map);
        LocalDateTime now = LocalDateTime.now();
        String format = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        log.info(format + " -> 天气推送成功");
    }
    log.info("============= WeatherTomorrowJob end =============");
}
Also used : LocalDateTime(java.time.LocalDateTime) Tag(com.yh.weatherpush.entity.Tag) LocalDate(java.time.LocalDate)

Example 9 with Tag

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

the class TagServiceImpl method covertTagDTO.

private List<TagDTO> covertTagDTO(List<Tag> list) {
    List<TagDTO> res = new ArrayList<>(list.size());
    for (Tag tag : list) {
        TagDTO tagDTO = new TagDTO();
        BeanUtil.copyProperties(tag, tagDTO);
        res.add(tagDTO);
    }
    return res;
}
Also used : TagDTO(com.yh.weatherpush.dto.tag.TagDTO) ArrayList(java.util.ArrayList) TaskRelTag(com.yh.weatherpush.entity.TaskRelTag) Tag(com.yh.weatherpush.entity.Tag)

Example 10 with Tag

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

the class TagServiceImpl method delete.

@Override
public void delete(Long id) {
    Tag tag = super.getById(id);
    if (null == tag) {
        throw new ApiException("标签不存在");
    }
    qywxService.deleteTag(tag.getTagId());
    super.removeById(id);
}
Also used : TaskRelTag(com.yh.weatherpush.entity.TaskRelTag) 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