1.完成静态规则的修改、id查询、分页查询、删除(目前直接在数据库delete)
2.新增@Slf4j进行日志记录 3.修改静态规则的新建
This commit is contained in:
@@ -2,38 +2,72 @@ package com.realtime.protection.configuration.entity.rule.staticrule;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class StaticRuleObject {
|
||||
@JsonProperty("static_rule_id")
|
||||
private int staticRuleId;
|
||||
private Integer staticRuleId;
|
||||
|
||||
@NotNull
|
||||
@JsonProperty("static_rule_name")
|
||||
private String staticRuleName;
|
||||
|
||||
@JsonProperty("static_rule_create_time")
|
||||
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;
|
||||
@JsonProperty("static_rule_modify_time")
|
||||
private LocalDateTime staticRuleModifyTime;
|
||||
|
||||
@JsonProperty("static_rule_create_username")
|
||||
private String staticRuleCreateUsername;
|
||||
@JsonProperty("static_rule_audit_status")
|
||||
private Integer staticRuleAuditStatus;
|
||||
@JsonProperty("static_rule_create_depart")
|
||||
private String staticRuleCreateDepart;
|
||||
@JsonProperty("static_rule_create_user_id")
|
||||
private Integer staticRuleCreateUserId;
|
||||
@JsonProperty("static_rule_used_task_id")
|
||||
private Integer staticRuleUsedTaskId;
|
||||
|
||||
@JsonProperty("static_rule_sip")
|
||||
private String staticRuleSip;
|
||||
@JsonProperty("static_rule_msip")
|
||||
private String staticRuleMsip;
|
||||
@JsonProperty("static_rule_sport")
|
||||
private Integer staticRuleSport;
|
||||
@JsonProperty("static_rule_msport")
|
||||
private Integer staticRuleMsport;
|
||||
@JsonProperty("static_rule_dip")
|
||||
private String staticRuleDip;
|
||||
@JsonProperty("static_rule_mdip")
|
||||
private String staticRuleMdip;
|
||||
@JsonProperty("static_rule_dport")
|
||||
private Integer staticRuleDport;
|
||||
@JsonProperty("static_rule_mdport")
|
||||
private Integer staticRuleMdport;
|
||||
@JsonProperty("static_rule_protocol")
|
||||
private String staticRuleProtocol;
|
||||
@JsonProperty("static_rule_mprotocol")
|
||||
private String staticRuleMprotocol;
|
||||
@JsonProperty("static_rule_dns")
|
||||
private String staticRuleDns;
|
||||
@JsonProperty("static_rule_url")
|
||||
private String staticRuleURL;
|
||||
|
||||
@JsonProperty("static_rule_priority")
|
||||
private Integer staticRulePriority;
|
||||
@JsonProperty("static_rule_range")
|
||||
private String staticRuleRange;
|
||||
@JsonProperty("static_rule_frequency")
|
||||
private Integer staticRuleFrequency;
|
||||
@JsonProperty("static_rule_protect_level")
|
||||
private Integer staticRuleProtectLevel;
|
||||
}
|
||||
|
||||
@@ -3,27 +3,78 @@ 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;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/staticrule")
|
||||
@Slf4j
|
||||
public class StaticRuleController {
|
||||
|
||||
@Autowired
|
||||
private StaticRuleService staticRuleService;
|
||||
private final StaticRuleService staticRuleService;
|
||||
public StaticRuleController(StaticRuleService staticRuleService) {
|
||||
this.staticRuleService = staticRuleService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增静态规则
|
||||
*/
|
||||
@RequestMapping("/new")
|
||||
public ResponseResult newStaticRuleObject(@RequestBody StaticRuleObject object){
|
||||
// log.info("新增部门: {}" , dept);
|
||||
@PostMapping("/new")
|
||||
public ResponseResult newStaticRuleObject(@RequestBody @Valid StaticRuleObject object){
|
||||
log.info("新增静态规则: {}" , object);
|
||||
//调用service新增
|
||||
staticRuleService.newStaticRuleObject(object);
|
||||
return ResponseResult.ok().setData("static_rule_name",object.getStaticRuleName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除静态规则
|
||||
*/
|
||||
@DeleteMapping("/{ids}")
|
||||
public ResponseResult delete(@PathVariable List<Integer> ids){
|
||||
log.info("根据id删除静态规则:{}",ids);
|
||||
//调用service删除
|
||||
staticRuleService.deleteStaticRule(ids);
|
||||
return ResponseResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改静态规则
|
||||
*/
|
||||
@PutMapping("/update")
|
||||
public ResponseResult updateStaticRule(@RequestBody @Valid StaticRuleObject object){
|
||||
log.info("修改静态规则: {}" , object);
|
||||
//调用service修改
|
||||
staticRuleService.updateStaticRule(object);
|
||||
return ResponseResult.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询静态规则
|
||||
* 路径参数:通过请求URL直接传递参数,使用{…}来标识该路径参数,需要使用 @PathVariable 获取路径参数
|
||||
*/
|
||||
@RequestMapping("/{id}/query")
|
||||
public ResponseResult queryStaticRuleById(@PathVariable Integer id){
|
||||
log.info("根据id查询静态规则:{}",id);
|
||||
StaticRuleObject object = staticRuleService.queryStaticRuleById(id);
|
||||
return ResponseResult.ok().setData("static_rule",object);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询静态规则
|
||||
*/
|
||||
@RequestMapping("/query")
|
||||
public ResponseResult queryStaticRule(String static_rule_name, Integer static_rule_id,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize
|
||||
){
|
||||
log.info("多查询静态规则: {},{},{},{}", static_rule_name,static_rule_id,page,pageSize);
|
||||
//调用service新增
|
||||
List<StaticRuleObject> pageResult = staticRuleService.queryStaticRule(static_rule_name,static_rule_id,page,pageSize);
|
||||
return ResponseResult.ok().setData("static_rule_list",pageResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
package com.realtime.protection.server.rule.staticrule;
|
||||
|
||||
import com.realtime.protection.configuration.entity.rule.staticrule.StaticRuleObject;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface StaticRuleMapper {
|
||||
Integer newStaticRuleObject(@Param("object") StaticRuleObject object);
|
||||
/**
|
||||
* 新建静态规则
|
||||
*/
|
||||
void newStaticRuleObject(@Param("object") StaticRuleObject object);
|
||||
|
||||
/**
|
||||
* 根据主键删除菜品数据
|
||||
*/
|
||||
@Delete("delete from t_static_rule where static_rule_id = #{id}")
|
||||
void deleteStaticRule(Integer id);
|
||||
|
||||
void updateStaticRule(StaticRuleObject object);
|
||||
|
||||
//@Select("select * from t_static_rule where static_rule_id = #{id}")
|
||||
StaticRuleObject queryStaticRuleById(Integer id);
|
||||
|
||||
List<StaticRuleObject> queryStaticRule(String static_rule_name, Integer static_rule_id,
|
||||
Integer page, Integer pageSize);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class StaticRuleService {
|
||||
@@ -22,9 +23,39 @@ public class StaticRuleService {
|
||||
/*
|
||||
待开发:设置静态规则对象的创建用户、用户所属部门等属性
|
||||
*/
|
||||
|
||||
staticRuleMapper.newStaticRuleObject(object);
|
||||
|
||||
return object.getStaticRuleId();
|
||||
}
|
||||
|
||||
public void deleteStaticRule(List<Integer> ids) {
|
||||
//判断当前静态规则是否能够删除---是否存在任务选择的静态规则??
|
||||
|
||||
//删除静态规则
|
||||
for (Integer id : ids) {
|
||||
staticRuleMapper.deleteStaticRule(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateStaticRule(StaticRuleObject object) {
|
||||
//判断当前静态规则是否能够修改---是否存在任务选择的静态规则??
|
||||
//按id查询该静态规则的used_task_id字段,如果不为空,则不能修改
|
||||
object.setStaticRuleModifyTime(LocalDateTime.now());
|
||||
//修改静态规则
|
||||
staticRuleMapper.updateStaticRule(object);
|
||||
}
|
||||
|
||||
public StaticRuleObject queryStaticRuleById(Integer id) {
|
||||
return staticRuleMapper.queryStaticRuleById(id);
|
||||
}
|
||||
|
||||
/*
|
||||
分页查询
|
||||
*/
|
||||
public List<StaticRuleObject> queryStaticRule(String static_rule_name, Integer static_rule_id, Integer page, Integer pageSize) {
|
||||
|
||||
return staticRuleMapper.queryStaticRule(static_rule_name,static_rule_id,page,pageSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user