Search in sources :

Example 1 with SchTask

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;
}
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 SchTask

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));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SchTask(com.yh.weatherpush.entity.SchTask) TaskRelTag(com.yh.weatherpush.entity.TaskRelTag) ApiException(com.yh.weatherpush.exception.ApiException) QuartzBean(com.yh.weatherpush.dto.QuartzBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SchTask

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);
}
Also used : ArrayList(java.util.ArrayList) SchTask(com.yh.weatherpush.entity.SchTask) TaskRelTag(com.yh.weatherpush.entity.TaskRelTag) QuartzBean(com.yh.weatherpush.dto.QuartzBean) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SchTask (com.yh.weatherpush.entity.SchTask)3 TaskRelTag (com.yh.weatherpush.entity.TaskRelTag)3 ArrayList (java.util.ArrayList)3 QuartzBean (com.yh.weatherpush.dto.QuartzBean)2 Transactional (org.springframework.transaction.annotation.Transactional)2 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 Tag (com.yh.weatherpush.entity.Tag)1 ApiException (com.yh.weatherpush.exception.ApiException)1 List (java.util.List)1