system.service.sys.impl.SysTaskJobServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of task Show documentation
Show all versions of task Show documentation
jishi series products task on java
package system.service.sys.impl;
import com.github.pagehelper.PageInfo;
import framework.exceptions.BusinessException;
import framework.runtime.SystemContext;
import framework.vo.ResultList;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import system.entity.SysTaskJob;
import system.mapper.SysTaskJobMapper;
import system.service.sys.SysTaskJobService;
import system.task.Task;
import system.task.TaskManager;
import system.task.errors.TaskException;
import system.task.utils.TaskUtil;
import system.task.vo.SysTaskRunning;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class SysTaskJobServiceImpl implements SysTaskJobService {
@Autowired
@Getter
private SysTaskJobMapper mapper;
@Lazy
@Autowired
private TaskManager taskManager;
@Override
public int updateByName(SysTaskJob param) {
return mapper.updateByName(param);
}
@Override
public SysTaskRunning loadInfo(Long id) {
SysTaskJob info = mapper.loadById(id);
if (info == null) {
String msg = SystemContext.getMessageDefault("task.not.found", "Not found task " + id);
throw new BusinessException(msg);
}
TaskUtil.cleanJobMaxTime(info);
SysTaskRunning running = new SysTaskRunning();
Task task = null;
try {
task = this.taskManager.getTask(info.getName());
} catch (TaskException e) {
log.error("load task info failed, " + e.getMessage(), e);
}
if (task != null) {
TaskUtil.fillRunning(info, task, running);
}
return running;
}
@Override
public ResultList loadRunning(SysTaskJob param, Integer pageIndex, Integer pageSize) {
PageInfo info = this.list(param, pageIndex, pageSize);
TaskUtil.cleanJobMaxTime(info.getList());
List runningList = new ArrayList<>();
for (SysTaskJob job : info.getList()) {
SysTaskRunning running = new SysTaskRunning();
Task task = null;
try {
task = this.taskManager.getTask(job.getName());
} catch (TaskException e) {
log.error("load task info failed, " + e.getMessage(), e);
}
if (task != null) {
TaskUtil.fillRunning(job, task, running);
}
runningList.add(running);
}
return new ResultList<>(runningList, info.getTotal(), info.getPageNum(), info.getPageSize());
}
}