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