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;
}
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 =============");
}
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 =============");
}
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;
}
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);
}
Aggregations