use of com.dtstack.taier.develop.dto.devlop.TaskGetNotDeleteVO in project Taier by DTStack.
the class BatchTaskService method deleteTask.
/**
* 数据开发-删除任务
*
* @param taskId 任务id
* @param tenantId 项目id
* @param userId 用户id
* @return
* @author toutian
*/
@Transactional
public Long deleteTask(Long taskId, Long tenantId, Long userId, String sqlText) {
final BatchTask batchTask = this.developTaskDao.getOne(taskId);
if (batchTask == null) {
throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
}
// 判断该任务是否有子任务(调用engine接口) 工作流不需要判断
if (batchTask.getFlowId() == 0) {
List<TaskGetNotDeleteVO> notDeleteTaskVOS = getChildTasks(taskId);
if (CollectionUtils.isNotEmpty(notDeleteTaskVOS)) {
throw new RdosDefineException("(当前任务被其他任务依赖)", ErrorCode.CAN_NOT_DELETE_TASK);
}
}
final ScheduleTaskShade dbTask = this.taskService.findTaskByTaskId(taskId);
if (batchTask.getFlowId() == 0 && Objects.nonNull(dbTask) && batchTask.getScheduleStatus().intValue() == EScheduleStatus.NORMAL.getVal().intValue()) {
throw new RdosDefineException("(当前任务未被冻结)", ErrorCode.CAN_NOT_DELETE_TASK);
}
if (batchTask.getTaskType().intValue() == EScheduleJobType.WORK_FLOW.getVal()) {
final List<BatchTask> batchTasks = this.getFlowWorkSubTasks(taskId);
// 删除所有子任务相关
batchTasks.forEach(task -> this.deleteTaskInfos(task.getId(), tenantId, userId));
}
// 删除工作流中的子任务同时删除被依赖的关系
if (batchTask.getFlowId() > 0) {
this.batchTaskTaskService.deleteTaskTaskByParentId(batchTask.getId());
}
if (StringUtils.isNotBlank(sqlText)) {
final BatchTask batchTaskBean = new BatchTask();
batchTaskBean.setId(batchTask.getFlowId());
batchTaskBean.setSqlText(sqlText);
this.developTaskDao.updateSqlText(batchTaskBean);
LOGGER.info("sqlText 修改成功");
} else {
LOGGER.error("deleteTask sqlText is null");
}
// 删除任务
this.deleteTaskInfos(taskId, tenantId, userId);
return taskId;
}
Aggregations