2024-01-03 09:13:22 +08:00
|
|
|
package com.realtime.protection.server.task;
|
|
|
|
|
|
2024-01-12 14:31:34 +08:00
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
2024-01-03 09:13:22 +08:00
|
|
|
import com.realtime.protection.configuration.entity.task.Task;
|
2024-01-11 19:49:07 +08:00
|
|
|
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
|
2024-01-08 20:01:20 +08:00
|
|
|
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
2024-01-03 09:13:22 +08:00
|
|
|
import org.springframework.stereotype.Service;
|
2024-01-05 09:32:19 +08:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
2024-01-03 22:53:02 +08:00
|
|
|
import java.util.List;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class TaskService {
|
2024-01-03 22:53:02 +08:00
|
|
|
private final TaskMapper taskMapper;
|
2024-01-03 09:13:22 +08:00
|
|
|
|
2024-01-08 20:01:20 +08:00
|
|
|
public TaskService(TaskMapper taskMapper) {
|
2024-01-03 22:53:02 +08:00
|
|
|
this.taskMapper = taskMapper;
|
2024-01-03 09:13:22 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-08 20:01:20 +08:00
|
|
|
@Transactional
|
2024-01-11 19:49:07 +08:00
|
|
|
public Long newTask(Task task) {
|
2024-01-08 20:01:20 +08:00
|
|
|
taskMapper.newTask(task);
|
|
|
|
|
|
2024-01-12 14:31:34 +08:00
|
|
|
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty())
|
|
|
|
|
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
|
|
|
|
|
|
|
|
|
if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty())
|
|
|
|
|
taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds());
|
2024-01-08 20:01:20 +08:00
|
|
|
|
2024-01-03 09:13:22 +08:00
|
|
|
return task.getTaskId();
|
|
|
|
|
}
|
2024-01-03 22:53:02 +08:00
|
|
|
|
|
|
|
|
public List<Task> queryTasks(Integer taskStatus,
|
|
|
|
|
String taskType, String taskName, String taskCreator,
|
|
|
|
|
Integer page, Integer pageSize) {
|
|
|
|
|
return taskMapper.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
public Task queryTask(Long id) {
|
2024-01-08 20:01:20 +08:00
|
|
|
return taskMapper.queryTask(id);
|
2024-01-03 22:53:02 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-05 09:32:19 +08:00
|
|
|
@Transactional
|
2024-01-08 20:01:20 +08:00
|
|
|
public Boolean updateTask(Task task) {
|
2024-01-05 09:32:19 +08:00
|
|
|
taskMapper.updateTask(task);
|
2024-01-03 22:53:02 +08:00
|
|
|
|
2024-01-05 09:32:19 +08:00
|
|
|
taskMapper.clearTaskConnectedStaticRule(task.getTaskId());
|
2024-01-08 20:01:20 +08:00
|
|
|
taskMapper.clearTaskConnectedDynamicRule(task.getTaskId());
|
2024-01-03 22:53:02 +08:00
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
if (task.getStaticRuleIds() != null && !task.getStaticRuleIds().isEmpty())
|
|
|
|
|
taskMapper.newTaskStaticRuleConcat(task.getTaskId(), task.getStaticRuleIds());
|
|
|
|
|
|
|
|
|
|
if (task.getDynamicRuleIds() != null && !task.getDynamicRuleIds().isEmpty())
|
|
|
|
|
taskMapper.newTaskDynamicRuleConcat(task.getTaskId(), task.getDynamicRuleIds());
|
2024-01-08 20:01:20 +08:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional
|
2024-01-11 19:49:07 +08:00
|
|
|
public Boolean changeTaskAuditStatus(Long taskId, Integer taskAuditStatus) {
|
|
|
|
|
Integer originalAuditStatus = taskMapper.queryTaskAuditStatus(taskId);
|
|
|
|
|
if (originalAuditStatus == null) {
|
2024-01-13 10:23:48 +08:00
|
|
|
throw new IllegalArgumentException("无法找到任务ID为" + taskId + "的任务,也许任务不存在?");
|
2024-01-11 19:49:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (AuditStatusValidator.setOriginal(originalAuditStatus).checkValidate(taskAuditStatus))
|
2024-01-08 20:01:20 +08:00
|
|
|
taskMapper.changeTaskAuditStatus(taskId, taskAuditStatus);
|
|
|
|
|
else return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-11 19:49:07 +08:00
|
|
|
public Boolean deleteTask(Long taskId) {
|
2024-01-08 20:01:20 +08:00
|
|
|
return taskMapper.deleteTask(taskId);
|
2024-01-03 22:53:02 +08:00
|
|
|
}
|
2024-01-09 09:20:13 +08:00
|
|
|
|
2024-01-12 14:31:34 +08:00
|
|
|
@DS("mysql")
|
2024-01-11 19:49:07 +08:00
|
|
|
public Boolean changeTaskStatus(Long taskId, Integer stateNum) {
|
|
|
|
|
return taskMapper.changeTaskStatus(taskId, stateNum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<TaskCommandInfo> getStaticCommandInfos(Long taskId) {
|
|
|
|
|
return taskMapper.getStaticCommands(taskId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer queryTaskAuditStatus(Long taskId) {
|
|
|
|
|
return taskMapper.queryTaskAuditStatus(taskId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer queryTaskStatus(Long taskId) {
|
|
|
|
|
return taskMapper.queryTaskStatus(taskId);
|
2024-01-09 09:20:13 +08:00
|
|
|
}
|
2024-01-03 09:13:22 +08:00
|
|
|
}
|