1、策略模板、白名单增加display_id

2、所有对象的查询新增display_id字段

(cherry picked from commit b6061f58e1)
This commit is contained in:
PushM
2024-05-08 10:41:47 +08:00
parent 7f078a81fd
commit 1b7460be64
11 changed files with 65 additions and 10 deletions

View File

@@ -77,6 +77,10 @@ public class Template {
@Schema(description = "防御策略模板审核状态0为未审核1为已退回2为审核通过", example = "1", accessMode = Schema.AccessMode.READ_ONLY)
private String auditStatus;
@JsonProperty("template_display_id")
@Schema(description = "策略模板展示id", accessMode = Schema.AccessMode.READ_ONLY)
private String templateDisplayId;
/**
* 设置是否含有日常/应急/紧急防护等级态字段的字段

View File

@@ -61,4 +61,10 @@ public class WhiteListObject {
@ExcelIgnore
@Schema(description = "白名单对象审核状态0为未审核1为已退回2为审核通过", example = "2")
private Integer whiteListAuditStatus;
@JsonProperty("white_list_display_id")
@ExcelIgnore
@Schema(description = "白名单展示id", example = "BMD-20200101-123456", accessMode = Schema.AccessMode.READ_ONLY)
private String whiteListDisplayId;
}

View File

@@ -1,11 +1,14 @@
package com.realtime.protection.server.defense.template;
import com.realtime.protection.configuration.entity.defense.template.Template;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -14,9 +17,11 @@ import java.util.Map;
public class TemplateService {
private final TemplateMapper templateMapper;
private final Counter counter;
public TemplateService(TemplateMapper templateMapper) {
public TemplateService(TemplateMapper templateMapper, Counter counter) {
this.templateMapper = templateMapper;
this.counter = counter;
}
@Transactional
@@ -25,6 +30,13 @@ public class TemplateService {
templateMapper.newProtectLevel(template.getProtectLevelMedium());
templateMapper.newProtectLevel(template.getProtectLevelHigh());
template.setTemplateDisplayId(
"CLMB-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("strategy_template"))
);
templateMapper.newTemplate(template);
if (template.getTemplateId() == null) {

View File

@@ -196,7 +196,7 @@ public class StaticRuleService {
List<StaticRuleObject> StaticRuleBatch = ListUtils.newArrayListWithExpectedSize(100);
for (StaticRuleObject staticRule : list) {
staticRule.setStaticRuleCreateTime(LocalDateTime.now());
// staticRule.setStaticRuleCreateTime(LocalDateTime.now());
staticRule.setStaticRuleDisplayId(
"JTGZ-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))

View File

@@ -4,6 +4,7 @@ import com.alibaba.excel.util.ListUtils;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.entity.task.TaskCommandInfo;
import com.realtime.protection.configuration.entity.whitelist.WhiteListObject;
import com.realtime.protection.configuration.utils.Counter;
import com.realtime.protection.configuration.utils.SqlSessionWrapper;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusEnum;
import com.realtime.protection.configuration.utils.enums.audit.AuditStatusValidator;
@@ -11,6 +12,8 @@ import com.realtime.protection.server.rule.staticrule.StaticRuleMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -23,18 +26,28 @@ public class WhiteListService {
private final StaticRuleMapper staticRuleMapper;
private final SqlSessionWrapper sqlSessionWrapper;
private final Counter counter;
public WhiteListService(WhiteListMapper whiteListMapper,
StaticRuleMapper staticRuleMapper,
SqlSessionWrapper sqlSessionWrapper) {
SqlSessionWrapper sqlSessionWrapper, Counter counter) {
this.whiteListMapper = whiteListMapper;
this.staticRuleMapper = staticRuleMapper;
this.sqlSessionWrapper = sqlSessionWrapper;
this.counter = counter;
}
//新建一个whitelist
public Integer newWhiteListObject(WhiteListObject object) {
object.setWhiteListDisplayId(
"BMD-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("white_list"))
);
whiteListMapper.newWhiteListObject(object);
return object.getWhiteListId();
@@ -50,6 +63,13 @@ public class WhiteListService {
List<WhiteListObject> WhiteListBatch = ListUtils.newArrayListWithExpectedSize(100);
for (WhiteListObject whiteListObject : whiteListObjectList) {
whiteListObject.setWhiteListDisplayId(
"BMD-"
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"))
+ "-"
+ String.format("%06d", counter.generateId("white_list"))
);
WhiteListBatch.add(whiteListObject);
if (WhiteListBatch.size() < 100) {
continue;

View File

@@ -152,6 +152,8 @@
<result column="strategy_template_name" property="dynamicRuleEventType"/>
<result column="strategy_template_source_system" property="dynamicRuleSourceSystem"/>
<result column="audit_status" property="auditStatus"/>
<result column="dynamic_rule_display_id" property="dynamicRuleDisplayId"/>
</resultMap>
<select id="queryDynamicRuleById" resultMap="dynamicRuleMap">

View File

@@ -43,6 +43,8 @@
<result column="protect_object_url" property="protectObjectURL"/>
<result column="protect_object_protocol" property="protectObjectProtocol"/>
<result column="protect_object_audit_status" property="protectObjectAuditStatus"/>
<result column="protect_object_display_id" property="protectObjectDisplayId"/>
</resultMap>
<select id="queryProtectObjects" resultMap="protectObjectMap">
@@ -50,6 +52,7 @@
protect_object_id, protect_object_name, protect_object_system_name,
INET_NTOA(protect_object_ip) as protect_object_ip,
protect_object_port, protect_object_url, protect_object_protocol, protect_object_audit_status
,protect_object_display_id
FROM t_protect_object
<where>
<if test="proobj_name != null">AND protect_object_name LIKE CONCAT('%', #{proobj_name}, '%')</if>
@@ -93,7 +96,7 @@
protect_object_port,
protect_object_url,
protect_object_protocol,
protect_object_audit_status
protect_object_audit_status,protect_object_display_id
FROM t_protect_object
WHERE protect_object_id = #{proobj_id}
</select>

View File

@@ -135,6 +135,8 @@
<result column="static_rule_url" property="staticRuleURL"/>
<result column="static_rule_priority" property="staticRulePriority"/>
<result column="static_rule_frequency" property="staticRuleFrequency"/>
<result column="static_rule_display_id" property="staticRuleDisplayId"/>
</resultMap>
<select id="queryStaticRule" resultMap="staticRuleMap">

View File

@@ -59,6 +59,8 @@
<result column="task_create_username" property="taskCreateUsername"/>
<result column="task_create_depart" property="taskCreateDepart"/>
<result column="task_display_id" property="taskDisplayId"/>
</resultMap>
<select id="queryTasks" resultMap="taskMap">

View File

@@ -9,12 +9,12 @@
strategy_template_high_level_id,
strategy_template_create_user_id, strategy_template_create_username,
strategy_template_create_depart,
strategy_template_description)
strategy_template_description, strategy_template_display_id)
VALUE (#{template.templateName}, #{template.sourceSystem},
#{template.protectLevelLow.protectLevelId}, #{template.protectLevelMedium.protectLevelId},
#{template.protectLevelHigh.protectLevelId},
#{template.createUserId}, #{template.createUsername}, #{template.createDepart},
#{template.description})
#{template.description}, #{template.templateDisplayId})
</insert>
<insert id="newProtectLevel" useGeneratedKeys="true" keyProperty="protectLevelId">
@@ -38,6 +38,8 @@
<result column="strategy_template_description" property="description"/>
<result column="audit_status" property="auditStatus"/>
<result column="strategy_template_display_id" property="templateDisplayId"/>
<association property="protectLevelLow"
javaType="com.realtime.protection.configuration.entity.defense.template.ProtectLevel">
<id column="low_protect_level_id" property="protectLevelId"/>

View File

@@ -8,24 +8,24 @@
insert into t_white_list(white_list_name, white_list_system_name,
white_list_ip, white_list_port,
white_list_url, white_list_protocol,
white_list_audit_status, create_time)
white_list_audit_status, create_time, white_list_display_id)
values (#{object.whiteListName}, #{object.whiteListSystemName},
INET_ATON(#{object.whiteListIP}), #{object.whiteListPort},
#{object.whiteListUrl}, #{object.whiteListProtocol},
0, NOW())
0, NOW(), #{object.whiteListDisplayId})
</insert>
<insert id="newWhiteListObjects">
insert into t_white_list(white_list_name, white_list_system_name,
white_list_ip, white_list_port,
white_list_url, white_list_protocol,
white_list_audit_status, create_time)
white_list_audit_status, create_time, white_list_display_id)
values
<foreach collection="whiteListObjects" item="object" separator=",">
(#{object.whiteListName}, #{object.whiteListSystemName},
INET_ATON(#{object.whiteListIP}), #{object.whiteListPort},
#{object.whiteListUrl}, #{object.whiteListProtocol},
0, NOW())
0, NOW(), #{object.whiteListDisplayId})
</foreach>
</insert>
@@ -47,6 +47,8 @@
<result column="white_list_url" property="whiteListUrl"/>
<result column="white_list_protocol" property="whiteListProtocol"/>
<result column="white_list_audit_status" property="whiteListAuditStatus"/>
<result column="white_list_display_id" property="whiteListDisplayId"/>
</resultMap>
<select id="queryWhiteListObject" resultMap="whiteListMap">