1. 添加doris数据源
2. 添加StateMapper,准备进行oracle数据库对接
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.realtime.protection.server.task;
|
||||
|
||||
import com.realtime.protection.server.task.state.State;
|
||||
|
||||
public class StatusChanger {
|
||||
|
||||
private final State state;
|
||||
|
||||
public StatusChanger(State state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public static StatusChanger setOriginal(State original) {
|
||||
return new StatusChanger(original);
|
||||
}
|
||||
|
||||
public Boolean changeState(State newState) {
|
||||
return this.state.handle(newState);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
public class RunningState implements State {
|
||||
@Override
|
||||
public Boolean handle(State newState) {
|
||||
if (newState instanceof RunningState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newState instanceof PauseState) {
|
||||
return handlePause();
|
||||
}
|
||||
|
||||
if (newState instanceof StopState) {
|
||||
return handleStop();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Boolean handlePause() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Boolean handleStop() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.realtime.protection.server.task.state;
|
||||
|
||||
public class StopState implements State {
|
||||
|
||||
@Override
|
||||
public Boolean handle(State newState) {
|
||||
if (newState instanceof RunningState) {
|
||||
return handleRun();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Boolean handleRun() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user