You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
3.5 KiB
155 lines
3.5 KiB
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using CellularManagement.Domain.Entities.Common;
|
|
|
|
namespace CellularManagement.Domain.Entities.Device;
|
|
|
|
/// <summary>
|
|
/// 蜂窝设备实体
|
|
/// </summary>
|
|
public class CellularDevice : AuditableEntity
|
|
{
|
|
private CellularDevice() { }
|
|
|
|
/// <summary>
|
|
/// 设备名称
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(100)]
|
|
public string Name { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// 设备序列号
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(50)]
|
|
public string SerialNumber { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// 设备描述
|
|
/// </summary>
|
|
[MaxLength(500)]
|
|
public string Description { get; private set; }
|
|
|
|
/// <summary>
|
|
/// 协议版本集合
|
|
/// </summary>
|
|
public virtual ICollection<ProtocolVersion> ProtocolVersions { get; private set; } = new List<ProtocolVersion>();
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Agent端口
|
|
/// </summary>
|
|
[Required]
|
|
public int AgentPort { get; private set; }
|
|
|
|
/// <summary>
|
|
/// IP地址
|
|
/// </summary>
|
|
[Required]
|
|
[MaxLength(45)]
|
|
public string IpAddress { get; private set; } = null!;
|
|
|
|
/// <summary>
|
|
/// 是否启用
|
|
/// </summary>
|
|
public bool IsEnabled { get; private set; } = true;
|
|
|
|
/// <summary>
|
|
/// 设备状态(启动/未启动)
|
|
/// </summary>
|
|
public bool IsRunning { get; private set; } = false;
|
|
|
|
/// <summary>
|
|
/// 创建设备
|
|
/// </summary>
|
|
public static CellularDevice Create(
|
|
string name,
|
|
string serialNumber,
|
|
string description,
|
|
int agentPort,
|
|
string ipAddress,
|
|
string createdBy,
|
|
bool isEnabled = true,
|
|
bool isRunning = false)
|
|
{
|
|
var device = new CellularDevice
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
Name = name,
|
|
SerialNumber = serialNumber,
|
|
Description = description,
|
|
AgentPort = agentPort,
|
|
IpAddress = ipAddress,
|
|
IsEnabled = isEnabled,
|
|
IsRunning = isRunning,
|
|
CreatedAt = DateTime.UtcNow,
|
|
UpdatedAt = DateTime.UtcNow,
|
|
CreatedBy = createdBy,
|
|
UpdatedBy = createdBy
|
|
};
|
|
|
|
return device;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新设备
|
|
/// </summary>
|
|
public void Update(
|
|
string name,
|
|
string serialNumber,
|
|
string description,
|
|
int agentPort,
|
|
string ipAddress,
|
|
string updatedBy,
|
|
bool isEnabled = true,
|
|
bool isRunning = false)
|
|
{
|
|
Name = name;
|
|
SerialNumber = serialNumber;
|
|
Description = description;
|
|
AgentPort = agentPort;
|
|
IpAddress = ipAddress;
|
|
IsEnabled = isEnabled;
|
|
IsRunning = isRunning;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
UpdatedBy = updatedBy;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启用设备
|
|
/// </summary>
|
|
public void Enable()
|
|
{
|
|
IsEnabled = true;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 禁用设备
|
|
/// </summary>
|
|
public void Disable()
|
|
{
|
|
IsEnabled = false;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 启动设备
|
|
/// </summary>
|
|
public void Start()
|
|
{
|
|
IsRunning = true;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止设备
|
|
/// </summary>
|
|
public void Stop()
|
|
{
|
|
IsRunning = false;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
}
|