Merge remote-tracking branch 'origin/master'

This commit is contained in:
松岳 陈
2024-01-03 09:13:33 +08:00
7 changed files with 175 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
package com.realtime.protection.configuration.entity.rule.dynamicrule;
public class DynamicRuleObject {
}

View File

@@ -0,0 +1,39 @@
package com.realtime.protection.configuration.entity.rule.staticrule;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class StaticRuleObject {
@JsonProperty("static_rule_id")
private int staticRuleId;
@NotNull
@JsonProperty("static_rule_name")
private String staticRuleName;
private LocalDateTime staticRuleCreateTime;
private String StaticRuleCreateUsername;
private int StaticRuleAuditStatus;
private String StaticRuleCreateDepart;
private int StaticRuleCreateUserId;
private String StaticRuleSip;
private String StaticRuleMsip;
private int StaticRuleSport;
private int StaticRuleMsport;
private String StaticRuleDip;
private String StaticRuleMdip;
private int StaticRuleDport;
private int StaticRuleMdport;
private String StaticRuleProtocol;
private String StaticRuleMprotocol;
private String StaticRuleDns;
private String StaticRuleURL;
private int StaticRulePriority;
private String StaticRuleRange;
private int StaticRuleFrequency;
private int StaticRuleProtectLevel;
}

View File

@@ -0,0 +1,29 @@
package com.realtime.protection.server.rule.staticrule;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import com.realtime.protection.configuration.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/staticrule")
public class StaticRuleController {
@Autowired
private StaticRuleService staticRuleService;
/**
* 新增静态规则
*/
@RequestMapping("/new")
public ResponseResult newStaticRuleObject(@RequestBody StaticRuleObject object){
// log.info("新增部门: {}" , dept);
//调用service新增
staticRuleService.newStaticRuleObject(object);
return ResponseResult.ok();
}
}

View File

@@ -0,0 +1,11 @@
package com.realtime.protection.server.rule.staticrule;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface StaticRuleMapper {
Integer newStaticRuleObject(@Param("object") StaticRuleObject object);
}

View File

@@ -0,0 +1,30 @@
package com.realtime.protection.server.rule.staticrule;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@Service
public class StaticRuleService {
@Autowired
private StaticRuleMapper staticRuleMapper;
/*
新建静态规则
*/
public Integer newStaticRuleObject(StaticRuleObject object) {
object.setStaticRuleCreateTime(LocalDateTime.now());
object.setStaticRuleAuditStatus(0);
/*
待开发:设置静态规则对象的创建用户、用户所属部门等属性
*/
staticRuleMapper.newStaticRuleObject(object);
return object.getStaticRuleId();
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.realtime.protection.server.rule.staticrule.StaticRuleMapper">
<insert id="newStaticRuleObject" useGeneratedKeys="true" keyProperty="staticRuleId"
parameterType="com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject">
insert into t_static_rule(static_rule_name, static_rule_create_time,
static_rule_create_username, static_rule_create_depart,
static_rule_create_user_id, static_rule_sip, static_rule_msip,
static_rule_sport,static_rule_msport,
static_rule_dip,static_rule_mdip,static_rule_dport,static_rule_mdport,
static_rule_protocol,static_rule_mprotocol,static_rule_dns,
static_rule_url,static_rule_priority,static_rule_range,
static_rule_frequency,static_rule_protect_level,static_rule_audit_status)
values (#{object.staticRuleName}, #{object.staticRuleCreateTime},#{object.staticRuleCreateUsername},
#{object.staticRuleCreateDepart},#{object.staticRuleCreateUserId},INET_ATON(#{object.staticRuleSip}),
INET_ATON(#{object.staticRuleMsip}),#{object.staticRuleSport},#{object.staticRuleMsport},
INET_ATON(#{object.staticRuleDip}),INET_ATON(#{object.staticRuleMdip}),#{object.staticRuleDport},
#{object.staticRuleMdport},#{object.staticRuleProtocol},#{object.staticRuleMprotocol},
#{object.staticRuleDns},#{object.staticRuleURL},#{object.staticRulePriority},
#{object.staticRuleRange},#{object.staticRuleFrequency},#{object.staticRuleProtectLevel},
#{object.staticAuditStatus})
</insert>
</mapper>

View File

@@ -0,0 +1,35 @@
package com.realtime.protection.server.rule.staticrule;
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.time.LocalDateTime;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
public class StaticRuleServiceTest {
@Autowired
private StaticRuleService staticRuleService;
@Test
void testNewStaticRule(){
StaticRuleObject object = new StaticRuleObject();
object.setStaticRuleName("test_staticrule");
object.setStaticRuleCreateTime(LocalDateTime.now());
object.setStaticRuleCreateUsername("boy");
object.setStaticRuleCreateDepart("1chu");
object.setStaticRuleCreateUserId(22);
object.setStaticRulePriority(1);
object.setStaticRuleFrequency(1);
object.setStaticRuleRange("北京");
object.setStaticRuleProtectLevel(2);
Integer id = staticRuleService.newStaticRuleObject(object);
assertTrue(id>0);
}
}