1. 修改防护对象、策略模板和任务的Swagger文档

2. 修改任务和指令部分逻辑
This commit is contained in:
EnderByEndera
2024-01-22 15:40:03 +08:00
parent 63e7270c92
commit 3d50cb9493
18 changed files with 790 additions and 81 deletions

View File

@@ -40,7 +40,6 @@ public class GlobalExceptionHandler {
@Order(2)
@ExceptionHandler(value = {
PersistenceException.class,
DuplicateKeyException.class,
SQLException.class,
SQLIntegrityConstraintViolationException.class
})
@@ -50,6 +49,14 @@ public class GlobalExceptionHandler {
"请检查json字段的完整性确保json字段按照文档中要求填写。");
}
@Order(2)
@ExceptionHandler(value = DuplicateKeyException.class)
public ResponseResult handleDuplicateKeyException(DuplicateKeyException e) {
return ResponseResult.invalid().setMessage(
"插入/更新失败,请检查当前插入字段和数据库中是否存在相同数据"
);
}
@Order(2)
@ExceptionHandler(value = MethodArgumentNotValidException.class)
public ResponseResult handleBindException(MethodArgumentNotValidException e) {

View File

@@ -1,17 +0,0 @@
package com.realtime.protection.configuration.response;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.HashMap;
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(description = "xxx")
public class ResponseData extends HashMap<String, Object> {
public Object put(String key, Object value, String description) {
return super.put(key, value);
}
}

View File

@@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
@Data
@@ -17,12 +18,12 @@ public class ResponseResult implements Serializable {
private String message;
@Schema(description = "封装数据")
private ResponseData data;
private Map<String, Object> data;
@Schema(description = "返回对象链接的另外一个返回对象")
private ResponseResult another;
public ResponseResult(int code, String message, ResponseData data) {
public ResponseResult(int code, String message, LinkedHashMap<String, Object> data) {
this.code = code;
this.message = message;
this.data = data;
@@ -30,13 +31,13 @@ public class ResponseResult implements Serializable {
public ResponseResult(int code) {
this.code = code;
this.data = new ResponseData();
this.data = new LinkedHashMap<>();
}
public ResponseResult(int code, String message) {
this.code = code;
this.message = message;
this.data = new ResponseData();
this.data = new LinkedHashMap<>();
}
public static ResponseResult ok() {
@@ -83,7 +84,7 @@ public class ResponseResult implements Serializable {
}
public ResponseResult addDataMap(Map<String, Object> data) {
this.data = (ResponseData) data;
this.data = data;
return this;
}
}

View File

@@ -18,9 +18,8 @@ public interface CommandMapper {
Boolean startCommandsByTaskId(@Param("task_id") Long taskId);
Boolean setCommandValid(@Param("command_id") String commandId);
Boolean setCommandInvalid(@Param("command_id") String commandId);
Boolean setCommandValid(@Param("command_id") String commandId,
@Param("is_valid") Boolean isValid);
List<TaskCommandInfo> queryCommandInfoByTaskId(@Param("task_id") Long taskId);

View File

@@ -2,11 +2,11 @@ package com.realtime.protection.server.command;
import com.alibaba.excel.util.ListUtils;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.UUID;
@@ -26,7 +26,7 @@ public class CommandService {
this.sqlSessionWrapper = sqlSessionWrapper;
}
@Transactional
@DSTransactional
public String createCommand(TaskCommandInfo commandInfo) {
commandInfo.setUUID(UUID.randomUUID().toString());
commandMapper.createCommand(commandInfo);
@@ -75,20 +75,12 @@ public class CommandService {
return commandMapper.stopCommandsByTaskId(taskId);
}
@DS("doris")
public Boolean removeCommandsByTaskId(Long taskId) {
return commandMapper.removeCommandsByTaskId(taskId);
}
@DS("doris")
public Object updateCommandVaid(String commandId, Integer isValid) {
if (isValid == 0) {
return commandMapper.setCommandInvalid(commandId);
}
if (isValid == 1) {
return commandMapper.setCommandValid(commandId);
}
return new IllegalArgumentException("isValid must be 0 or 1");
public Object setCommandValid(String commandId, Boolean isValid) {
return commandMapper.setCommandValid(commandId, isValid);
}

View File

@@ -76,8 +76,8 @@ public class ProtectObjectController implements ProtectObjectControllerApi {
@RequestParam("page_size") @Min(1) Integer pageSize) {
return ResponseResult.ok()
.setData("proobj_list", protectObjectService.queryProtectObjects(protectObjectName,
protectObjectId, page, pageSize));
protectObjectId, page, pageSize))
.setData("total_num", protectObjectService.queryProtectObjectsTotalNum());
}
@Override

View File

@@ -5,6 +5,7 @@ import com.realtime.protection.configuration.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -29,7 +30,28 @@ public interface ProtectObjectControllerApi {
description = "返回新建对象结果",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"proobj_name": "静态对象测试",
"success": true,
"proobj_id": 14542
}
}
""",
description = """
"proobj_name": 防护对象名称
"success": 新建防护对象是否成功
"proobj_id": 新建防护对象ID
"""
)
)
)
},
@@ -80,7 +102,56 @@ public interface ProtectObjectControllerApi {
description = "返回多个防护对象",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"proobj_list": [
{
"proobj_id": 6068,
"proobj_name": "x-2-2",
"proobj_system_name": "xxxx system",
"proobj_port": 11,
"proobj_url": "alice.bob.com",
"proobj_protocol": "UDP",
"proobj_audit_status": 1
},
{
"proobj_id": 6069,
"proobj_name": "x-2-2",
"proobj_system_name": "xxxx system",
"proobj_port": 11,
"proobj_url": "alice.bob.com",
"proobj_protocol": "UDP",
"proobj_audit_status": 0
}
],
"total_num": 8470
}
}
""",
description = """
"proobj_id": 防护对象ID
"proobj_name": 防护对象名称
"proobj_system_name": 防护对象操作系统
"proobj_ip_address": 防护对象IP地址
"proobj_port": 防护对象端口
"proobj_url": 防护对象URL
"proobj_protocol": 防护对象协议
"proobj_audit_status": 防护对象审核状态
"""
)
)
)
},
@@ -107,7 +178,44 @@ public interface ProtectObjectControllerApi {
description = "返回单个防护对象信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"protect_object": {
"proobj_id": 14544,
"proobj_name": "静态对象测试",
"proobj_system_name": "xxx操作系统",
"proobj_port": 8080,
"proobj_url": "alice.bob.com",
"proobj_protocol": "TCP",
"proobj_audit_status": 0
}
}
}
""",
description = """
"proobj_id": 防护对象ID
"proobj_name": 防护对象名称
"proobj_system_name": 防护对象操作系统
"proobj_ip_address": 防护对象IP地址
"proobj_port": 防护对象端口
"proobj_url": 防护对象URL
"proobj_protocol": 防护对象协议
"proobj_audit_status": 防护对象审核状态
"""
)
)
)
},
@@ -126,7 +234,25 @@ public interface ProtectObjectControllerApi {
description = "防护对象更新情况",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"proobj_id": 14544
}
}
""",
description = """
"success": 防护对象更新是否成功
"proobj_id": 防护对象ID
"""
)
)
)
},
@@ -148,7 +274,25 @@ public interface ProtectObjectControllerApi {
description = "防护对象删除情况",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"proobj_id": 14544
}
}
""",
description = """
"success": 防护对象删除是否成功
"proobj_id": 删除的防护对象ID
"""
)
)
)
},
@@ -167,7 +311,28 @@ public interface ProtectObjectControllerApi {
description = "防护对象删除情况",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"proobj_ids": [
14543,
14542
]
}
}
""",
description = """
"success": 防护对象删除是否成功
"proobj_ids": 删除的防护对象ID列表
"""
)
)
)
},
@@ -186,7 +351,28 @@ public interface ProtectObjectControllerApi {
description = "防护对象审核状态修改情况",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"proobj_id": 14541,
"audit_status": 2
}
}
""",
description = """
"success": 审核状态修改是否成功
"proobj_id": 防护对象ID
"audit_status": 防护对象当前审核状态
"""
)
)
)
},

View File

@@ -3,6 +3,7 @@ package com.realtime.protection.server.defense.object;
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@@ -27,4 +28,7 @@ public interface ProtectObjectMapper {
Boolean changeProtectObjectAuditStatus(@Param("proobj_id") Integer protectObjectId,
@Param("proobj_audit_status") Integer protectObjectAuditStatus);
@Select("SELECT COUNT(protect_object_id) FROM t_protect_object")
Integer queryProtectObjectsTotalNum();
}

View File

@@ -112,4 +112,8 @@ public class ProtectObjectService {
return resultMap;
}
public Integer queryProtectObjectsTotalNum() {
return protectObjectMapper.queryProtectObjectsTotalNum();
}
}

View File

@@ -43,12 +43,13 @@ public class TemplateController implements TemplateControllerApi {
List<Template> templates = templateService.queryTemplates(templateName, page, pageSize);
return ResponseResult.ok()
.setData("templates", templates);
.setData("templates", templates)
.setData("total_num", templateService.queryTemplateTotalNum());
}
@Override
@GetMapping("/{templateId}/query")
public ResponseResult queryTemplate(@PathVariable Integer templateId) throws IllegalAccessException {
public ResponseResult queryTemplate(@PathVariable Integer templateId) {
Template template = templateService.queryTemplate(templateId);
if (template == null) {
return ResponseResult.invalid()

View File

@@ -5,6 +5,7 @@ import com.realtime.protection.configuration.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -23,7 +24,25 @@ public interface TemplateControllerApi {
description = "返回新建防御策略模板结果",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"template_id": 1442
}
}
""",
description = """
"success": 新建防御策略模板是否成功
"template_id": 新建防御策略模板ID
"""
)
)
)
},
@@ -40,7 +59,108 @@ public interface TemplateControllerApi {
description = "返回所有查询到的防御策略模板",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"templates": [
{
"template_id": 18,
"template_name": "洪泛型DDOS攻击-2024-01-18T16:46:14.640176900",
"protect_level_low": {
"protectLevelId": 46,
"hasProtectObjectIP": false,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": true,
"hasProtocol": false,
"hasURL": false,
"hasDNS": false
},
"protect_level_medium": {
"protectLevelId": 47,
"hasProtectObjectIP": true,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": false,
"hasProtocol": false,
"hasURL": false,
"hasDNS": false
},
"protect_level_high": {
"protectLevelId": 48,
"hasProtectObjectIP": false,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": false,
"hasProtocol": false,
"hasURL": false,
"hasDNS": true
},
"template_used_times": 0,
"running_tasks": 0
},
{
"template_id": 24,
"template_name": "反射型DDOS攻击-2024-01-12T17:52:32.077477700",
"protect_level_low": {
"protectLevelId": 64,
"hasProtectObjectIP": false,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": true,
"hasProtocol": false,
"hasURL": false,
"hasDNS": false
},
"protect_level_medium": {
"protectLevelId": 65,
"hasProtectObjectIP": true,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": false,
"hasProtocol": false,
"hasURL": false,
"hasDNS": false
},
"protect_level_high": {
"protectLevelId": 66,
"hasProtectObjectIP": false,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": false,
"hasProtocol": false,
"hasURL": false,
"hasDNS": true
},
"template_used_times": 0,
"running_tasks": 0
}
],
"total_num": 708
}
}
""",
description = """
"template_id": 防御策略模板ID
"template_name": 防御策略模板名称
"protect_level_low": 防御策略模板日常态数据
"protect_level_medium": 防御策略模板应急态数据
"protect_level_high": 防御策略模板紧急态数据
"template_used_times": 防御策略模板使用次数
"running_tasks": 防御策略模板任务运行数量
"""
)
)
)
},
@@ -63,7 +183,69 @@ public interface TemplateControllerApi {
description = "返回单个防御策略模板信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"template": {
"template_id": 245,
"template_name": "反射型DDOS攻击-2024-01-12T18:10:49.975561700",
"protect_level_low": {
"protectLevelId": 727,
"hasProtectObjectIP": false,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": true,
"hasProtocol": false,
"hasURL": false,
"hasDNS": false
},
"protect_level_medium": {
"protectLevelId": 728,
"hasProtectObjectIP": true,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": false,
"hasProtocol": false,
"hasURL": false,
"hasDNS": false
},
"protect_level_high": {
"protectLevelId": 729,
"hasProtectObjectIP": false,
"hasProtectObjectPort": false,
"hasPeerIP": false,
"hasPeerPort": false,
"hasProtocol": false,
"hasURL": false,
"hasDNS": true
},
"template_used_times": 0,
"running_tasks": 0
}
}
}
""",
description = """
"template_id": 防御策略模板ID
"template_name": 防御策略模板名称
"protect_level_low": 防御策略模板日常态数据
"protect_level_medium": 防御策略模板应急态数据
"protect_level_high": 防御策略模板紧急态数据
"template_used_times": 防御策略模板使用次数
"running_tasks": 防御策略模板任务运行数量
"""
)
)
)
},
@@ -82,7 +264,25 @@ public interface TemplateControllerApi {
description = "返回防御策略模板信息更新结果",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"template_id": 262
}
}
""",
description = """
"success": 更新是否成功
"template_id": 更新的策略模板ID
"""
)
)
)
},
@@ -102,7 +302,25 @@ public interface TemplateControllerApi {
description = "返回防御策略模板删除结果",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"template_id": 262
}
}
""",
description = """
"success": 删除是否成功
"template_id": 删除的策略模板ID
"""
)
)
)
},

View File

@@ -2,8 +2,10 @@ package com.realtime.protection.server.defense.template;
import com.realtime.protection.configuration.entity.defense.template.ProtectLevel;
import com.realtime.protection.configuration.entity.defense.template.Template;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@@ -23,5 +25,9 @@ public interface TemplateMapper {
Template queryTemplate(@Param("template_id") Integer templateId);
@Delete("DELETE FROM t_strategy_template WHERE strategy_template_id = #{template_id}")
Boolean deleteTemplate(@Param("template_id") Integer templateId);
@Select("SELECT COUNT(strategy_template_id) FROM t_strategy_template")
Integer queryTemplateTotalNum();
}

View File

@@ -46,4 +46,8 @@ public class TemplateService {
public Boolean deleteTemplate(Integer templateId) {
return templateMapper.deleteTemplate(templateId);
}
public Integer queryTemplateTotalNum() {
return templateMapper.queryTemplateTotalNum();
}
}

View File

@@ -74,12 +74,13 @@ public class TaskController implements TaskControllerApi {
@RequestParam("page_size") @Min(1) Integer pageSize) {
List<Task> tasks = taskService.queryTasks(taskStatus, taskType, taskName, taskCreator, page, pageSize);
return ResponseResult.ok()
.setData("task_list", tasks);
.setData("task_list", tasks)
.setData("total_num", taskService.queryTaskTotalNum());
}
@Override
@GetMapping("/{id}/query")
public ResponseResult queryTask(@PathVariable @Min(1) Long id) throws IllegalAccessException {
public ResponseResult queryTask(@PathVariable @Min(1) Long id) {
Task task = taskService.queryTask(id);
if (task == null) {
@@ -136,13 +137,11 @@ public class TaskController implements TaskControllerApi {
.setData("commands", commandService.queryCommandInfoByTaskId(taskId));
}
//研判后任务 下发指令\停止指令
@PostMapping("/{commandId}/valid/{isValid}")
public ResponseResult validCommandInfoByTaskId(@PathVariable Integer isValid,
@GetMapping("/{commandId}/valid/{isValid}")
public ResponseResult setCommandValid(@PathVariable Boolean isValid,
@PathVariable String commandId) {
return ResponseResult.ok()
.setData("success", commandService.updateCommandVaid(commandId, isValid));
.setData("success", commandService.setCommandValid(commandId, isValid))
.setData("command_id", commandId);
}
}

View File

@@ -7,6 +7,7 @@ import com.realtime.protection.configuration.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -27,7 +28,28 @@ public interface TaskControllerApi {
description = "返回任务添加结果信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"task_name": "静态任务",
"success": true,
"task_id": 1939
}
}
""",
description = """
"task_name": 任务名称
"success": 任务添加是否成功
"task_id": 新建任务ID
"""
)
),
responseCode = "200"
)
@@ -46,7 +68,27 @@ public interface TaskControllerApi {
description = "返回外部任务推送结果",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"taskId": 1940
}
}
""",
description = """
"task_name": 任务名称
"success": 任务添加是否成功
"task_id": 新建任务ID
"""
)
)
)
},
@@ -63,7 +105,74 @@ public interface TaskControllerApi {
description = "返回查询到的所有任务",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"total_num": 1902,
"task_list": [
{
"task_id": 37,
"task_name": "静态任务",
"task_start_time": "2025-01-19T08:46:36",
"task_end_time": "2027-01-19T08:46:36",
"task_type": 1,
"task_create_username": "xxx",
"task_create_depart": "xxx",
"static_rule_ids": [
112
],
"dynamic_rule_ids": [],
"task_status": 4,
"task_audit_status": 0
},
{
"task_id": 38,
"task_name": "修改测试",
"task_start_time": "2024-02-29T15:16:11",
"task_end_time": "2024-03-15T04:30:18",
"task_type": 1,
"task_create_username": "xxx",
"task_create_depart": "xxx",
"static_rule_ids": [],
"dynamic_rule_ids": [],
"task_status": 4,
"task_audit_status": 2
}
]
}
}
""",
description = """
"task_id": 任务ID
"task_name": 任务名称
"task_start_time": 任务开始时间
"task_end_time": 任务结束时间
"task_type": 任务类型静态、动态、研判后对应123
"task_create_username": 任务创建人名称
"task_create_depart": 任务创建人处室
"static_rule_ids": 静态规则ID列表
"dynamic_rule_ids": 动态规则ID列表
"task_status": 任务当前运行状态
"task_audit_status": 任务当前审核状态
"total_num": 任务总数
"""
)
)
)
},
@@ -92,7 +201,54 @@ public interface TaskControllerApi {
description = "返回查询到的单个任务",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"task": {
"task_id": 38,
"task_name": "修改测试",
"task_start_time": "2024-02-29T15:16:11",
"task_end_time": "2024-03-15T04:30:18",
"task_type": 1,
"task_create_username": "xxx",
"task_create_depart": "xxx",
"static_rule_ids": [],
"dynamic_rule_ids": [],
"task_status": 4,
"task_audit_status": 2
}
}
}
""",
description = """
"task_id": 任务ID
"task_name": 任务名称
"task_start_time": 任务开始时间
"task_end_time": 任务结束时间
"task_type": 任务类型静态、动态、研判后对应123
"task_create_username": 任务创建人名称
"task_create_depart": 任务创建人处室
"static_rule_ids": 静态规则ID列表
"dynamic_rule_ids": 动态规则ID列表
"task_status": 任务当前运行状态
"task_audit_status": 任务当前审核状态
"""
)
)
)
},
@@ -109,7 +265,25 @@ public interface TaskControllerApi {
description = "返回任务更新结果信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"task_id": 637
}
}
""",
description = """
"success": 更新是否成功
"task_id": 更新任务ID
"""
)
)
)
},
@@ -131,7 +305,28 @@ public interface TaskControllerApi {
description = "返回任务审核状态修改的信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"task_id": 38,
"audit_status": 2
}
}
""",
description = """
"success": 任务审核状态修改是否成功
"task_id": 任务ID
"audit_status": 任务当前审核状态
"""
)
)
)
},
@@ -152,7 +347,25 @@ public interface TaskControllerApi {
description = "返回任务删除结果信息",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"task_id": 889
}
}
""",
description = """
"success": 任务删除是否成功
"task_id": 删除的任务ID
"""
)
)
)
},
@@ -171,7 +384,28 @@ public interface TaskControllerApi {
description = "返回任务运行状态修改结果",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"status_now": 2,
"success": true,
"task_id": 1012
}
}
""",
description = """
"status_now": 当前任务状态
"success": 任务状态更新是否成功
"task_id": 任务ID
"""
)
)
)
},
@@ -192,7 +426,45 @@ public interface TaskControllerApi {
description = "返回任务已推送指令的相关数据",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class)
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"commands": [
{
"taskAct": "篡改",
"isValid": true,
"fiveTupleWithMask": {
"sourceIP": "1.1.2.3",
"sourcePort": "80"
},
"commandSentTimes": 0,
"commandSuccessTimes": 0,
"uuid": "3b42ca64-282f-4040-bd8f-8f895fa82d23"
}
]
}
}
""",
description = """
"taskAct": 任务行为
"isValid": 指令是否生效
"fiveTupleWithMask": 指令五元组信息
"commandSentTimes": 指令下发次数
"commandSuccessTimes": 指令下发成功次数
"uuid": 指令UUID
"""
)
)
)
},
@@ -201,4 +473,38 @@ public interface TaskControllerApi {
}
)
ResponseResult queryCommandInfoByTaskId(@PathVariable Long taskId);
@Operation(
summary = "下发/取消指令下发",
description = "下发或取消下发一条指令",
responses = @ApiResponse(
description = "返回指令是否成功下发",
content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = ResponseResult.class),
examples = @ExampleObject(
name = "example",
value = """
{
"code": 200,
"message": "request succeed",
"data": {
"success": true,
"command_uuid": "85f4115b-f9ac-4489-89bc-42ee261d6cd1"
}
}
""",
description = """
"success": 指令下发是否成功
"command_uuid": 指令UUID
"""
)
)
)
)
@GetMapping("/{commandId}/valid/{isValid}")
ResponseResult setCommandValid(@PathVariable Boolean isValid,
@PathVariable String commandId);
}

View File

@@ -53,4 +53,7 @@ public interface TaskMapper {
@Select("SELECT task_id FROM t_task WHERE task_end_time < NOW() AND task_status != #{task_status}")
List<Long> queryTasksByStatus(@Param("task_status") Integer taskStatus);
@Select("SELECT COUNT(task_id) FROM t_task")
Integer queryTaskTotalNum();
}

View File

@@ -131,4 +131,8 @@ public class TaskService {
public List<Long> getFinishedTasks() {
return taskMapper.queryTasksByStatus(StateEnum.FINISHED.getStateNum());
}
public Integer queryTaskTotalNum() {
return taskMapper.queryTaskTotalNum();
}
}

View File

@@ -119,15 +119,7 @@
<update id="setCommandValid">
UPDATE t_command
SET IS_VALID = TRUE,
LAST_UPDATE = NOW()
WHERE COMMAND_ID = #{command_id}
AND IS_DELETED = FALSE
</update>
<update id="setCommandInvalid">
UPDATE t_command
SET IS_VALID = FALSE,
SET IS_VALID = #{is_valid},
LAST_UPDATE = NOW()
WHERE COMMAND_ID = #{command_id}
AND IS_DELETED = FALSE