feat(device): 完善设备及网络接口管理功能

- 新增网络接口及地址配置相关实体类与映射
- 扩展 CreateDeviceRequest 支持嵌套接口与地址配置
- 调整设备类型实体类字段并增强逻辑删除支持
- 优化数据表结构,分离接口属性与地址配置
- 新增 DNS 服务器及相关映射实体支持
- 实现设备创建事务中同步保存接口与地址信息
- 调整 MyBatis Plus 逻辑删除配置与时间字段类型
- 重构 data.sql 初始化脚本,完善表间外键约束
This commit is contained in:
Chaos
2025-11-28 21:46:52 +08:00
parent 3f8dc871ab
commit cc70d867c1
17 changed files with 705 additions and 184 deletions

View File

@@ -1,9 +1,6 @@
package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDate;
@@ -23,7 +20,10 @@ public class Device {
private LocalDate purchaseDate;
private int status;
private String remark;
private LocalDate createTime;
private LocalDate updateTime;
@TableLogic
private LocalDate deleteTime;
@TableField(exist = false)
private DeviceType deviceType;

View File

@@ -1,18 +1,51 @@
package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
@TableName("t_device_type")
public class DeviceType {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 设备类型名称
*/
private String name;
/**
* 设备类型唯一编码
*/
private String code;
/**
* 父级类型ID (0表示顶级)
*/
private Long parentId;
/**
* 备注
*/
private String remark;
private LocalDate createTime;
private LocalDate updateTime;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 逻辑删除时间
*/
@TableLogic
private LocalDateTime deleteTime;
}

View File

@@ -0,0 +1,50 @@
package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* DNS 服务器实体
* 对应表: t_dns_server
*/
@Data
@TableName("t_dns_server")
public class DnsServer {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* DNS服务器IP地址
*/
private String dnsAddress;
/**
* DNS名称 (如: Google DNS)
*/
private String name;
/**
* 描述
*/
private String description;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 逻辑删除时间
*/
@TableLogic
private LocalDateTime deleteTime;
}

View File

@@ -0,0 +1,90 @@
package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 接口地址与VLAN配置实体 (核心配置)
* 对应表: t_interface_address_config
*/
@Data
@TableName("t_interface_address_config")
public class InterfaceAddressConfig {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 关联物理接口ID
*/
private Long interfaceId;
/**
* VLAN ID (0或NULL表示Native/Untagged)
*/
private Integer vlanId;
/**
* IP地址 (支持IPv4/IPv6)
*/
private String ipAddress;
/**
* 子网掩码/CIDR前缀
*/
private String subnetMask;
/**
* 网关IP地址
*/
private String gatewayIp;
/**
* 广播地址
*/
private String broadcastAddress;
/**
* 是否为主IP (true:主IP, false:从IP/Alias)
*/
private Boolean isPrimary;
/**
* 是否启用DHCP (true:启用, false:静态)
*/
private Boolean isDhcp;
/**
* MTU值
*/
private Integer mtu;
/**
* 配置状态 (1:启用, 0:禁用)
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 逻辑删除时间
*/
@TableLogic
private LocalDateTime deleteTime;
}

View File

@@ -0,0 +1,38 @@
package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 接口配置与DNS关联实体
* 对应表: t_interface_dns_mapping
*/
@Data
@TableName("t_interface_dns_mapping")
public class InterfaceDnsMapping {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 接口配置ID (关联 t_interface_address_config)
*/
private Long configId;
/**
* DNS服务器ID (关联 t_dns_server)
*/
private Long dnsServerId;
/**
* 优先级 (数值越小优先级越高)
*/
private Integer priority;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
}

View File

@@ -0,0 +1,80 @@
package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 网络接口基础实体 (物理/链路层属性)
* 对应表: t_network_interface
*/
@Data
@TableName("t_network_interface")
public class NetworkInterface {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 设备ID
*/
private Long deviceId;
/**
* 父接口ID (用于子接口/聚合口成员)
*/
private Long parentId;
/**
* 接口名称 (如: eth0, GE0/0/1)
*/
private String name;
/**
* 接口类型 (1:物理口, 2:聚合口, 3:虚拟口)
*/
private Integer type;
/**
* MAC地址
*/
private String macAddress;
/**
* 物理端口速率 (Mbps)
*/
private Integer portSpeed;
/**
* 双工模式 (1:全双工, 2:半双工, 3:自适应)
*/
private Integer duplex;
/**
* 接口运行状态 (1:UP, 0:DOWN)
*/
private Integer status;
/**
* 备注
*/
private String remark;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 逻辑删除时间
*/
@TableLogic
private LocalDateTime deleteTime;
}

View File

@@ -3,11 +3,11 @@ package cn.nopj.chaos_api.domain.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@@ -65,10 +65,6 @@ public class User {
*/
private Boolean accountNonLocked;
/**
* 逻辑删除 (1:已删除, 0:未删除)
*/
private Boolean deleted;
/**
* 备注信息
@@ -84,7 +80,15 @@ public class User {
* 更新时间
*/
private Date updateTime;
/**
* 删除时间
*/
@TableLogic
private LocalDateTime deleteTime;
@TableField(exist = false)
private List<Role> roles;
}

View File

@@ -1,28 +1,97 @@
package cn.nopj.chaos_api.dto.request;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import java.time.LocalDate;
import java.util.List;
/**
* 创建设备请求对象
* <p>
* 对应您的命名规范CreateDeviceRequest
* 位于 request 包下
*/
@Data
public class CreateDeviceRequest {
//限制必填 不限制特殊字符
// --- 设备基础信息 ---
@NotBlank(message = "设备名称不能为空")
private String name;
@NotNull(message = "设备类型ID不能为空")
private Long typeId;
private Long locationId;
@NotBlank(message = "设备型号不能为空")
private String model;
@NotBlank(message = "设备类型不能为空")
private Long typeId;
private Long locationId;
private String snmpCommunity;
@NotBlank(message = "设备厂商不能为空")
private String manufacturer;
@Pattern(regexp = "^[0-9]{4}-[0-9]{2}-[0-9]{2}$", message = "设备购买日期格式不正确")
private String snmpCommunity;
private LocalDate purchaseDate;
private int status;
private String remark;
}
@Valid
private List<NetworkInterfaceRequest> interfaces;
/**
* 网络接口请求参数
*/
@Data
public static class NetworkInterfaceRequest {
@NotBlank(message = "接口名称不能为空")
private String name;
@NotNull(message = "接口类型不能为空")
private Integer type; // 1:物理口, 2:聚合口, 3:虚拟口
@Pattern(regexp = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$", message = "MAC地址格式不正确")
private String macAddress;
private Integer portSpeed;
private Integer duplex;
private String remark;
@Valid
private List<InterfaceAddressConfigRequest> addressConfigs;
}
/**
* 地址与VLAN配置请求参数
*/
@Data
public static class InterfaceAddressConfigRequest {
private Integer vlanId;
@Pattern(regexp = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", message = "IP地址格式不正确")
private String ipAddress;
private String subnetMask;
private String gatewayIp;
private String broadcastAddress;
private Boolean isPrimary;
private Boolean isDhcp;
private Integer mtu;
private List<String> dnsServers;
}
}

View File

@@ -3,7 +3,7 @@ package cn.nopj.chaos_api.dto.response;
import cn.nopj.chaos_api.domain.entity.DeviceType;
import lombok.Data;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data
public class DeviceTypeResponse {
@@ -12,7 +12,8 @@ public class DeviceTypeResponse {
private String code;
private Long parentId;
private String remark;
private LocalDate createTime;
private LocalDateTime createTime;
private LocalDateTime updateTime;
public DeviceTypeResponse(DeviceType type){
this.id = type.getId();
@@ -21,5 +22,6 @@ public class DeviceTypeResponse {
this.parentId = type.getParentId();
this.remark = type.getRemark();
this.createTime = type.getCreateTime();
this.updateTime = type.getUpdateTime();
}
}