use of com.yh.weatherpush.entity.SchTask 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.SchTask in project weather-push by yangh124.
the class SchTaskServiceImpl method updateTask.
@Transactional(rollbackFor = Exception.class)
@Override
public void updateTask(Long id, UpdateTaskDTO dto) {
SchTask task = super.getById(id);
Integer status = dto.getStatus();
String cronExp = dto.getCronExp();
List<Long> tagIds = dto.getTagIds();
if (ObjectUtil.isNull(status) || StrUtil.isBlank(cronExp) || CollUtil.isEmpty(tagIds)) {
throw new ApiException("参数错误!");
}
BeanUtil.copyProperties(dto, task);
super.updateById(task);
taskRelTagService.remove(new QueryWrapper<TaskRelTag>().lambda().eq(TaskRelTag::getTaskId, id));
List<TaskRelTag> list = new ArrayList<>(tagIds.size());
for (Long tagId : tagIds) {
TaskRelTag taskRelTag = new TaskRelTag();
taskRelTag.setTaskId(id);
taskRelTag.setTagId(tagId);
taskRelTag.setCtime(LocalDateTime.now());
list.add(taskRelTag);
}
taskRelTagService.saveBatch(list);
if (StrUtil.isNotBlank(cronExp)) {
QuartzBean quartzBean = new QuartzBean();
quartzBean.setId(String.valueOf(id));
quartzBean.setCronExp(cronExp);
quartzClient.update(scheduler, quartzBean);
}
if (ObjectUtil.isNotNull(status)) {
if (0 == status) {
quartzClient.start(scheduler, String.valueOf(id));
} else {
quartzClient.stop(scheduler, String.valueOf(id));
}
}
}
use of com.yh.weatherpush.entity.SchTask in project weather-push by yangh124.
the class SchTaskServiceImpl method create.
@Transactional(rollbackFor = Exception.class)
@Override
public void create(AddTaskParam param) {
SchTask schTask = new SchTask();
BeanUtil.copyProperties(param, schTask);
schTask.setCtime(LocalDateTime.now());
super.save(schTask);
Long taskId = schTask.getId();
List<Long> tagIds = param.getTagIds();
List<TaskRelTag> list = new ArrayList<>(tagIds.size());
for (Long tagId : tagIds) {
TaskRelTag taskRelTag = new TaskRelTag();
taskRelTag.setTaskId(taskId);
taskRelTag.setTagId(tagId);
taskRelTag.setCtime(LocalDateTime.now());
list.add(taskRelTag);
}
taskRelTagService.saveBatch(list);
QuartzBean quartzBean = new QuartzBean();
BeanUtil.copyProperties(schTask, quartzBean);
quartzBean.setId(String.valueOf(taskId));
quartzClient.create(scheduler, quartzBean);
}
Aggregations