1、动态规则、静态规则、白名单修改完善接口设计,添加API文档
2、动态规则数据库删除event_type、source_system字段,新增template_id,HTTP接口接收template_id。 3、静态规则添加修改审核状态功能、按id删除功能
This commit is contained in:
@@ -1,20 +1,17 @@
|
||||
package com.realtime.protection.server.rule.dynamicrule;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import com.realtime.protection.configuration.response.ResponseResult;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("dynamicrule")
|
||||
@Slf4j
|
||||
public class DynamicRuleController {
|
||||
public class DynamicRuleController implements DynamicRuleControllerApi {
|
||||
|
||||
private final DynamicRuleService dynamicRuleService;
|
||||
|
||||
@@ -23,7 +20,8 @@ public class DynamicRuleController {
|
||||
}
|
||||
|
||||
// 新增 要关联防护对象!!!!
|
||||
@RequestMapping("/new")
|
||||
@Override
|
||||
@PostMapping("/new")
|
||||
public ResponseResult newDynamicRuleObject(@RequestBody @Valid DynamicRuleObject dynamicRuleObject) {
|
||||
log.info("新增动态规则: {}", dynamicRuleObject);
|
||||
//调用service新增
|
||||
@@ -34,6 +32,7 @@ public class DynamicRuleController {
|
||||
.setData("success", true);
|
||||
}
|
||||
|
||||
/*
|
||||
//以excel文件方式批量导入,但动态规则没有这个需求
|
||||
@PostMapping("/upload")
|
||||
public ResponseResult uploadFile(MultipartFile uploadFile) throws IOException {
|
||||
@@ -41,55 +40,65 @@ public class DynamicRuleController {
|
||||
new DynamicRuleDataListener(dynamicRuleService)).sheet().doRead();
|
||||
return ResponseResult.ok();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//id删除
|
||||
@RequestMapping("/{dynamicRuleId}/delete")
|
||||
public ResponseResult deleteDynamicRuleObject(@PathVariable Integer dynamicRuleId) {
|
||||
log.info("删除动态规则: {}", dynamicRuleId);
|
||||
@Override
|
||||
@DeleteMapping("/{id}/delete")
|
||||
public ResponseResult deleteDynamicRuleObject(@PathVariable Integer id) {
|
||||
log.info("删除动态规则: {}", id);
|
||||
//调用service删除
|
||||
dynamicRuleService.deleteDynamicRuleObject(dynamicRuleId);
|
||||
dynamicRuleService.deleteDynamicRuleObject(id);
|
||||
|
||||
return ResponseResult.ok();
|
||||
}
|
||||
|
||||
//批量删除
|
||||
@RequestMapping("/delete")
|
||||
public ResponseResult deleteDynamicRuleObjects(@RequestBody List<Integer> dynamicRuleIds) {
|
||||
log.info("批量删除动态规则: {}", dynamicRuleIds);
|
||||
@Override
|
||||
@DeleteMapping("/{ids}")
|
||||
public ResponseResult deleteDynamicRuleObjects(@PathVariable List<Integer> ids) {
|
||||
log.info("批量删除动态规则: {}", ids);
|
||||
//调用service删除
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("success", dynamicRuleService.deleteDynamicRuleObjects(dynamicRuleIds));
|
||||
.setData("success", dynamicRuleService.deleteDynamicRuleObjects(ids));
|
||||
}
|
||||
|
||||
//修改
|
||||
@RequestMapping("/{dynamicRuleId}/update")
|
||||
public ResponseResult updateDynamicRuleObject(@PathVariable Integer dynamicRuleId,
|
||||
@Override
|
||||
@PostMapping("/{id}/update")
|
||||
public ResponseResult updateDynamicRuleObject(@PathVariable Integer id,
|
||||
@RequestBody @Valid DynamicRuleObject dynamicRuleObject) {
|
||||
log.info("修改动态规则: {}:{}",
|
||||
dynamicRuleId, dynamicRuleObject.getDynamicRuleName());
|
||||
id, dynamicRuleObject.getDynamicRuleName());
|
||||
|
||||
dynamicRuleService.updateDynamicRuleObject(dynamicRuleId, dynamicRuleObject);
|
||||
dynamicRuleService.updateDynamicRuleObject(id, dynamicRuleObject);
|
||||
|
||||
return ResponseResult.ok()
|
||||
.setData("dynamic_rule_id", dynamicRuleId)
|
||||
.setData("dynamic_rule_id", id)
|
||||
.setData("success", true);
|
||||
}
|
||||
|
||||
//id查询
|
||||
@RequestMapping("/{dynamicRuleId}/query")
|
||||
public ResponseResult queryDynamicRuleObjectById(@PathVariable Integer dynamicRuleId) {
|
||||
log.info("查询动态规则: {}", dynamicRuleId);
|
||||
@Override
|
||||
@GetMapping("/{id}/query")
|
||||
public ResponseResult queryDynamicRuleObjectById(@PathVariable Integer id) {
|
||||
log.info("查询动态规则: {}", id);
|
||||
DynamicRuleObject dynamicRuleObject = dynamicRuleService.queryDynamicRuleById(id);
|
||||
if (dynamicRuleObject == null) {
|
||||
return ResponseResult.invalid()
|
||||
.setData("dynamic_rule", null);
|
||||
}
|
||||
//调用service查询
|
||||
return ResponseResult.ok()
|
||||
.setData("dynamic_rule", dynamicRuleService.queryDynamicRuleById(dynamicRuleId));
|
||||
.setData("dynamic_rule", dynamicRuleObject);
|
||||
}
|
||||
|
||||
//分页查询
|
||||
@RequestMapping("/query")
|
||||
public ResponseResult queryDynamicRuleObject(@RequestParam(value = "dynamic_rule_name", required = false) String dynamicRuleName,
|
||||
@RequestParam(value = "dynamic_rule_id", required = false) Integer dynamicRuleId,
|
||||
@Override
|
||||
@GetMapping("/query")
|
||||
public ResponseResult queryDynamicRuleObject(@RequestParam(value = "name", required = false) String dynamicRuleName,
|
||||
@RequestParam(value = "id", required = false) Integer dynamicRuleId,
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) {
|
||||
log.info("分页查询动态规则: {}:{}:{}:{}", dynamicRuleName, dynamicRuleId, page, pageSize);
|
||||
@@ -98,5 +107,9 @@ public class DynamicRuleController {
|
||||
.setData("dynamic_rule_list", dynamicRuleService.queryDynamicRuleObject(dynamicRuleName, dynamicRuleId, page, pageSize));
|
||||
}
|
||||
|
||||
//详情查看?? 查看什么
|
||||
//详情查看?? 就是按id查询吧
|
||||
|
||||
|
||||
//审核?不需要
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.realtime.protection.server.rule.dynamicrule;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
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.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "动态规则API", description = "动态规则模块所有接口")
|
||||
public interface DynamicRuleControllerApi {
|
||||
|
||||
@Operation(
|
||||
summary = "新建动态规则",
|
||||
description = "新建一个动态规则",
|
||||
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回新建对象结果",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(
|
||||
// title = "ResponseResult和DynamicRule的组合模型",
|
||||
// description = "ResponseResult的data内DynamicRule",
|
||||
// anyOf = {ResponseResult.class, DynamicRuleObject.class})
|
||||
implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "动态规则信息")
|
||||
)
|
||||
ResponseResult newDynamicRuleObject(@RequestBody @Valid DynamicRuleObject dynamicRuleObject) ;
|
||||
|
||||
@Operation(
|
||||
summary = "删除动态规则",
|
||||
description = "删除一个动态规则",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回删除对象结果",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
parameters = {
|
||||
@Parameter(name = "id", description = "动态规则id")
|
||||
}
|
||||
)
|
||||
ResponseResult deleteDynamicRuleObject(@PathVariable Integer id) ;
|
||||
|
||||
@Operation(
|
||||
summary = "批量删除动态规则",
|
||||
description = "批量删除动态规则",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回批量删除对象结果",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
parameters = {
|
||||
@Parameter(name = "ids", description = "动态规则id列表")
|
||||
}
|
||||
)
|
||||
public ResponseResult deleteDynamicRuleObjects(@PathVariable List<Integer> ids) ;
|
||||
|
||||
@Operation(
|
||||
summary = "修改动态规则",
|
||||
description = "修改动态规则",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回修改对象结果",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
parameters = {
|
||||
@Parameter(name = "id", description = "动态规则id")
|
||||
},
|
||||
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
|
||||
description = "动态规则信息")
|
||||
)
|
||||
public ResponseResult updateDynamicRuleObject(
|
||||
@PathVariable Integer id,
|
||||
@RequestBody @Valid DynamicRuleObject dynamicRuleObject) ;
|
||||
|
||||
@Operation(
|
||||
summary = "查询单个动态规则",
|
||||
description = "根据动态规则ID查询单个动态规则的所有详细信息",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回查询到的单个动态规则",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
parameters = {
|
||||
@Parameter(name = "id", description = "动态规则ID", example = "2")
|
||||
}
|
||||
)
|
||||
public ResponseResult queryDynamicRuleObjectById(@PathVariable Integer id) ;
|
||||
|
||||
@Operation(
|
||||
summary = "根据条件查询多个动态规则",
|
||||
description = "根据查询条件和页码等,查询多个对象并以列表返回",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "返回多个动态规则",
|
||||
content = @Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = ResponseResult.class)
|
||||
)
|
||||
)
|
||||
},
|
||||
parameters = {
|
||||
@Parameter(name = "name", description = "动态规则名称", example = "test"),
|
||||
@Parameter(name = "id", description = "动态规则ID", example = "2"),
|
||||
@Parameter(name = "page", description = "页码", example = "1"),
|
||||
@Parameter(name = "page_size", description = "每页大小", example = "10")
|
||||
}
|
||||
)
|
||||
public ResponseResult queryDynamicRuleObject(
|
||||
@RequestParam(value = "name", required = false) String dynamicRuleName,
|
||||
@RequestParam(value = "id", required = false) Integer dynamicRuleId,
|
||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(value = "page_size", defaultValue = "10") Integer pageSize) ;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.realtime.protection.server.rule.dynamicrule;
|
||||
|
||||
import com.realtime.protection.configuration.entity.defense.object.ProtectObject;
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@@ -31,4 +32,6 @@ public interface DynamicRuleMapper {
|
||||
List<DynamicRuleObject> queryDynamicRuleObject(String dynamicRuleName, Integer dynamicRuleId, Integer page, Integer pageSize);
|
||||
|
||||
void deleteDynamicRuleProtectObjectConcat(Integer dynamicRuleId);
|
||||
|
||||
Template queryTemplateByRuleId(Integer dynamicRuleId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.realtime.protection.server.rule.dynamicrule;
|
||||
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.realtime.protection.configuration.entity.defense.template.Template;
|
||||
import com.realtime.protection.configuration.entity.rule.dynamicrule.DynamicRuleObject;
|
||||
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -26,11 +27,11 @@ public class DynamicRuleService {
|
||||
dynamicRuleMapper.newDynamicRule(dynamicRule);
|
||||
|
||||
Integer dynamicRuleId = dynamicRule.getDynamicRuleId();
|
||||
if (dynamicRule.getProtectObjectIds() != null) {
|
||||
dynamicRule.getProtectObjectIds().forEach(
|
||||
protectObjectId -> dynamicRuleMapper.newDynamicRulProtectObjectConcat(dynamicRuleId, protectObjectId));
|
||||
|
||||
dynamicRule.getProtectObjectIds().forEach(
|
||||
protectObjectId -> dynamicRuleMapper.newDynamicRulProtectObjectConcat(dynamicRuleId, protectObjectId));
|
||||
|
||||
|
||||
}
|
||||
return dynamicRuleId;
|
||||
}
|
||||
|
||||
@@ -75,8 +76,15 @@ public class DynamicRuleService {
|
||||
|
||||
//查询DynamicRule
|
||||
DynamicRuleObject dynamicRuleObject = dynamicRuleMapper.queryDynamicRuleById(dynamicRuleId);
|
||||
if (dynamicRuleObject == null){
|
||||
return null;
|
||||
}
|
||||
//查询DynamicRule关联的ProtectObject
|
||||
dynamicRuleObject.setProtectObjects(dynamicRuleMapper.queryProtectObjectByRuleId(dynamicRuleId));
|
||||
//查询DynamicRule关联的template详细信息
|
||||
Template template = dynamicRuleMapper.queryTemplateByRuleId(dynamicRuleId);
|
||||
dynamicRuleObject.setDynamicRuleSourceSystem(template.getSourceSystem());
|
||||
dynamicRuleObject.setDynamicRuleEventType(template.getTemplateName());
|
||||
|
||||
return dynamicRuleObject;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user