1. 添加doris数据源
2. 添加StateMapper,准备进行oracle数据库对接
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package com.realtime.protection.configuration.entity.task;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Command {
|
||||
private Integer id;
|
||||
|
||||
private Integer type;
|
||||
private String sourceIP;
|
||||
private String sourcePort;
|
||||
private String destinationIP;
|
||||
private String destinationPort;
|
||||
private Integer protocol;
|
||||
|
||||
private String maskSourceIP;
|
||||
private String maskSourcePort;
|
||||
private String maskDestinationIP;
|
||||
private String maskDestinationPort;
|
||||
private Integer direction;
|
||||
|
||||
private LocalDateTime datetime;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.realtime.protection.configuration.utils.status.state;
|
||||
|
||||
public class PauseState implements State {
|
||||
@Override
|
||||
public Boolean handle(State newState) {
|
||||
if (!(newState instanceof RunningState)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return handleRun();
|
||||
}
|
||||
|
||||
private Boolean handleRun() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.realtime.protection.configuration.utils.status.state;
|
||||
|
||||
public interface State {
|
||||
|
||||
Boolean handle(State newState);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.realtime.protection.configuration.utils.status;
|
||||
package com.realtime.protection.server.task;
|
||||
|
||||
import com.realtime.protection.configuration.utils.status.state.State;
|
||||
import com.realtime.protection.server.task.state.State;
|
||||
|
||||
public class StatusChanger {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class TaskController {
|
||||
.setData("success", taskService.updateTask(task));
|
||||
}
|
||||
|
||||
@GetMapping("/{taskId}/{auditStatus}/audit")
|
||||
@GetMapping("/{taskId}/audit/{auditStatus}")
|
||||
public ResponseResult changeTaskAuditStatus(@PathVariable Integer auditStatus, @PathVariable Integer taskId) {
|
||||
return ResponseResult.ok()
|
||||
.setData("task_id", taskId)
|
||||
@@ -89,4 +89,11 @@ public class TaskController {
|
||||
.setData("task_id", taskId)
|
||||
.setData("success", taskService.deleteTask(taskId));
|
||||
}
|
||||
|
||||
@GetMapping("/{taskId}/running/{state}")
|
||||
public ResponseResult changeTaskStatus(@PathVariable Integer state, @PathVariable Integer taskId) {
|
||||
return ResponseResult.ok()
|
||||
.setData("task_id", taskId)
|
||||
.setData("success", taskService.changeTaskStatus(taskId, state));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.realtime.protection.server.task;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.realtime.protection.configuration.entity.task.Task;
|
||||
import com.realtime.protection.configuration.utils.status.AuditStatusValidator;
|
||||
import com.realtime.protection.server.task.state.PauseState;
|
||||
import com.realtime.protection.server.task.state.RunningState;
|
||||
import com.realtime.protection.server.task.state.State;
|
||||
import com.realtime.protection.server.task.state.StopState;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -61,4 +64,29 @@ public class TaskService {
|
||||
public Boolean deleteTask(Integer taskId) {
|
||||
return taskMapper.deleteTask(taskId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Boolean changeTaskStatus(Integer taskId, Integer stateNum) {
|
||||
State originalState = switch (taskMapper.queryTask(taskId).getTaskStatus()) {
|
||||
// 运行中
|
||||
case 1 -> new RunningState();
|
||||
// 暂停中
|
||||
case 2 -> new PauseState();
|
||||
// 停止中
|
||||
case 3 -> new StopState();
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
|
||||
State newState = switch (stateNum) {
|
||||
// 运行中
|
||||
case 1 -> new RunningState();
|
||||
// 暂停中
|
||||
case 2 -> new PauseState();
|
||||
// 停止中
|
||||
case 3 -> new StopState();
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
|
||||
return StatusChanger.setOriginal(originalState).changeState(newState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
|
||||
public class PauseState implements State {
|
||||
@Override
|
||||
public Boolean handle(State newState) {
|
||||
if (newState instanceof RunningState) {
|
||||
return handleRun();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@DS("oracle")
|
||||
private Boolean handleRun() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.realtime.protection.configuration.utils.status.state;
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
public class RunningState implements State {
|
||||
@Override
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
public interface State {
|
||||
|
||||
Boolean handle(State newState);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
import com.realtime.protection.configuration.entity.task.Command;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface StateMapper {
|
||||
Boolean sendCommand(@Param("command") Command command);
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.realtime.protection.configuration.utils.status.state;
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
public class StopState implements State {
|
||||
|
||||
@Override
|
||||
public Boolean handle(State newState) {
|
||||
if (!(newState instanceof RunningState)) {
|
||||
return false;
|
||||
if (newState instanceof RunningState) {
|
||||
return handleRun();
|
||||
}
|
||||
|
||||
return handleRun();
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean handleRun() {
|
||||
Reference in New Issue
Block a user