1、解决指令按条件查询总数bug

2、动态、静态规则新增批量查询功能
This commit is contained in:
Hao Miao
2024-01-23 23:26:15 +08:00
parent 389483989c
commit 31277b7246
11 changed files with 104 additions and 36 deletions

View File

@@ -81,7 +81,6 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
@Override
@GetMapping("/{id}/query")
public ResponseResult queryDynamicRuleObjectById(@PathVariable Integer id) {
log.info("查询动态规则: {}", id);
DynamicRuleObject dynamicRuleObject = dynamicRuleService.queryDynamicRuleById(id);
//调用service查询
return ResponseResult.ok()
@@ -89,6 +88,16 @@ public class DynamicRuleController implements DynamicRuleControllerApi {
.setData("dynamic_rule", dynamicRuleObject);
}
@Override
@GetMapping("/query/{ids}")
public ResponseResult queryDynamicRuleObjectByIds(@PathVariable List<Integer> ids) {
List<DynamicRuleObject> dynamicRuleObjects = dynamicRuleService.queryDynamicRuleByIds(ids);
//调用service查询
return ResponseResult.ok()
.setData("success", true)
.setData("dynamic_rule", dynamicRuleObjects);
}
//分页查询
@Override
@GetMapping("/query")

View File

@@ -10,6 +10,7 @@ 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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
@@ -186,6 +187,24 @@ public interface DynamicRuleControllerApi {
)
public ResponseResult queryDynamicRuleObjectById(@PathVariable Integer id) ;
@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})
))},
parameters = {@Parameter(name = "ids", description = "动态规则ID列表", example = "dynamicrule/query/5,11")}
)
@GetMapping("/query/{ids}")
ResponseResult queryDynamicRuleObjectByIds(@PathVariable List<Integer> ids);
@Operation(
summary = "根据条件查询多个动态规则",
description = "根据查询条件和页码等,查询多个对象并以列表返回",

View File

@@ -43,4 +43,6 @@ public interface DynamicRuleMapper {
Integer queryDynamicRuleTotalNum(String dynamicRuleName, Integer dynamicRuleId,
String sourceSystem, String creator);
List<DynamicRuleObject> queryDynamicRuleByIds(List<Integer> ids);
}

View File

@@ -166,4 +166,8 @@ public class DynamicRuleService {
return dynamicRuleMapper.queryDynamicRuleTotalNum(dynamicRuleName, dynamicRuleId,
protectObjectSourceSystem, creator);
}
public List<DynamicRuleObject> queryDynamicRuleByIds(List<Integer> ids) {
return dynamicRuleMapper.queryDynamicRuleByIds(ids);
}
}

View File

@@ -143,6 +143,16 @@ public class StaticRuleController implements StaticRuleControllerApi {
static_rule_creator, static_rule_ip));
}
@Override
@GetMapping("/query/{ids}")
public ResponseResult queryStaticRuleByIds(@PathVariable List<Integer> ids) {
List<StaticRuleObject> staticRuleObjects = staticRuleService.queryStaticRuleByIds(ids);
//调用service查询
return ResponseResult.ok()
.setData("success", true)
.setData("static_rule", staticRuleObjects);
}
/**
* 修改审核状态
*/

View File

@@ -10,10 +10,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
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 org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
@@ -213,6 +210,24 @@ public interface StaticRuleControllerApi {
);
@Operation( summary = "批量查询静态规则",
description = "根据静态规则ID列表查询多个静态规则的所有详细信息",
responses = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(
description = "返回查询到的多个静态规则",
content = @Content(
mediaType = "application/json",
schema = @Schema(title = "ResponseResult和StaticRule的对象属性",
anyOf = {ResponseResult.class, StaticRuleObject.class})
)
)
},
parameters = {@Parameter(name = "ids", description = "静态规则ID列表", example = "staticrule/query/15,16,17")}
)
@GetMapping("/query/{ids}")
ResponseResult queryStaticRuleByIds(@PathVariable List<Integer> ids);
@Operation(
summary = "按id删除静态规则",
description = "按id删除静态规则",
@@ -240,6 +255,8 @@ public interface StaticRuleControllerApi {
@Operation(
summary = "更新静态规则审批状态",
description = "更新静态规则审批状态0未审核、1审核不通过、2审核通过",

View File

@@ -41,4 +41,6 @@ public interface StaticRuleMapper {
Integer queryStaticRuleTotalNum(String static_rule_name, Integer static_rule_id,
String static_rule_create_username, String ip);
List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids);
}

View File

@@ -153,4 +153,8 @@ public class StaticRuleService {
return staticRuleMapper.queryStaticRuleTotalNum(static_rule_name, static_rule_id,
static_rule_creator, static_rule_ip);
}
public List<StaticRuleObject> queryStaticRuleByIds(List<Integer> ids) {
return staticRuleMapper.queryStaticRuleByIds(ids);
}
}

View File

@@ -182,37 +182,12 @@
SELECT COUNT(COMMAND_ID)
FROM t_command
<where>
<if test="command_info.taskId != null">AND TASK_ID = #{command_info.taskId}</if>
<if test="command_info.fiveTupleWithMask.sourceIP != null">
AND SRC_IP = #{command_info.fiveTupleWithMask.sourceIP}
</if>
<if test="command_info.fiveTupleWithMask.destinationIP != null">
AND DST_IP = #{command_info.fiveTupleWithMask.destinationIP}
</if>
<if test="command_info.fiveTupleWithMask.sourcePort != null">
AND SRC_PORT = #{command_info.fiveTupleWithMask.sourcePort}
</if>
<if test="command_info.fiveTupleWithMask.destinationPort != null">
AND DST_PORT = #{command_info.fiveTupleWithMask.destinationPort}
</if>
<if test="command_info.fiveTupleWithMask.protocol != null">
AND PROTOCOL = #{command_info.fiveTupleWithMask.protocol}
</if>
<if test="command_info.fiveTupleWithMask.maskSourceIP != null">
AND MASK_SRC_IP = #{command_info.fiveTupleWithMask.maskSourceIP}
</if>
<if test="command_info.fiveTupleWithMask.maskSourcePort != null">
AND MASK_SOURCE_PORT = #{command_info.fiveTupleWithMask.maskSourcePort}
</if>
<if test="command_info.fiveTupleWithMask.maskDestinationIP != null">
AND MASK_DST_IP = #{command_info.fiveTupleWithMask.maskDestinationIP}
</if>
<if test="command_info.fiveTupleWithMask.maskDestinationPort != null">
AND MASK_DST_PORT = #{command_info.fiveTupleWithMask.maskDestinationPort}
</if>
<if test="command_info.fiveTupleWithMask.maskProtocol != null">
AND MASK_PROTOCOL = #{command_info.fiveTupleWithMask.maskProtocol}
</if>
AND TASK_ID = #{task_id}
AND IS_DELETED = FALSE
<if test="src_ip != null">AND SRC_IP = #{src_ip}</if>
<if test="dst_ip != null">AND DST_IP = #{dst_ip}</if>
<if test="src_port != null">AND SRC_PORT = #{src_port}</if>
<if test="dst_port != null">AND DST_PORT = #{dst_port}</if>
</where>
</select>
</mapper>

View File

@@ -224,6 +224,18 @@
</if>
</where>
</select>
<select id="queryDynamicRuleByIds"
resultMap="dynamicRulePageQueryMap">
select *
from t_dynamic_rule
left join t_strategy_template
on t_dynamic_rule.template_id = t_strategy_template.strategy_template_id
where dynamic_rule_id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@@ -177,5 +177,19 @@
</if>
</where>
</select>
<select id="queryStaticRuleByIds"
resultMap="staticRuleMap">
SELECT *,
INET_NTOA(static_rule_sip) as static_rule_sip_d,
INET_NTOA(static_rule_msip) as static_rule_msip_d,
INET_NTOA(static_rule_dip) as static_rule_dip_d,
INET_NTOA(static_rule_mdip) as static_rule_mdip_d
FROM t_static_rule
left join t_task on t_static_rule.static_rule_used_task_id = t_task.task_id
where static_rule_id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>