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.
121 lines
3.7 KiB
121 lines
3.7 KiB
using Infrastructure.Domain;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
|
|
namespace Application.Domain.Entities
|
|
{
|
|
[Display(Name = "设备")]
|
|
public class Device : BaseEntity
|
|
{
|
|
[Display(Name = "名称")]
|
|
public string Name { get; set; }
|
|
|
|
[Display(Name = "编号")]
|
|
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
|
public string Number { get; set; }
|
|
|
|
[Display(Name = "网关编号")]
|
|
public string Gateway { get; set; }
|
|
|
|
[Display(Name = "显示名称")]
|
|
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
|
public string DisplayName { get; set; }
|
|
|
|
[Display(Name = "标记")]
|
|
public string Tag { get; set; }
|
|
|
|
[Display(Name = "在线状态")]
|
|
public bool IsOnline { get; set; }
|
|
|
|
[Display(Name = "图标")]
|
|
public string Icon { get; set; }
|
|
|
|
[Display(Name = "IP")]
|
|
public string Ip { get; set; }
|
|
|
|
[Display(Name = "用户名")]
|
|
public string UserName { get; set; }
|
|
|
|
[Display(Name = "密码")]
|
|
public string Password { get; set; }
|
|
|
|
[Display(Name = "连接Id")]
|
|
public string ConnectId { get; set; }
|
|
|
|
[Display(Name = "序号")]
|
|
public int DisplayOrder { get; set; }
|
|
|
|
[Display(Name = "隐藏")]
|
|
public bool Disabled { get; set; }
|
|
|
|
[Display(Name = "产品Id")]
|
|
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
|
public Guid ProductId { get; set; }
|
|
|
|
[Display(Name = "节点Id")]
|
|
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
|
public Guid NodeId { get; set; }
|
|
|
|
[Display(Name = "产品")]
|
|
public Product Product { get; set; }
|
|
|
|
[Display(Name = "节点")]
|
|
public Node Node { get; set; }
|
|
|
|
[Display(Name = "数据")]
|
|
public List<Data> Data { get; set; } = new List<Data>();
|
|
|
|
[Display(Name = "命令")]
|
|
public List<Command> Commands { get; set; } = new List<Command>();
|
|
|
|
public Data GetData(string key)
|
|
{
|
|
return this.Data.FirstOrDefault(o => o.Key == key);
|
|
}
|
|
|
|
public string GetDataValue(string key)
|
|
{
|
|
return this.GetData(key)?.Value;
|
|
}
|
|
|
|
public Data CreateData(string key, object value, DeviceDataType type, string name, string unit = null, string description = null, bool hidden = false, long timestamp = 0)
|
|
{
|
|
return new Data
|
|
{
|
|
DeviceId = this.Id,
|
|
Key = key,
|
|
Value = Convert.ToString(value),
|
|
Type = type,
|
|
Name = name,
|
|
Unit = unit,
|
|
Description = description,
|
|
Hidden = hidden,
|
|
Timestamp = timestamp == 0 ? DateTimeOffset.Now.ToUnixTimeMilliseconds() : timestamp
|
|
};
|
|
}
|
|
|
|
public Data AddorUpdateData(Data data)
|
|
{
|
|
var oldData = this.Data.FirstOrDefault(o => o.Key == data.Key);
|
|
if (oldData == null)
|
|
{
|
|
oldData = data;
|
|
this.Data.Add(data);
|
|
}
|
|
else
|
|
{
|
|
if (oldData.Name != data.Name || oldData.Value != data.Value || oldData.Unit != data.Unit || oldData.Description != data.Description)
|
|
{
|
|
oldData.Name = data.Name;
|
|
oldData.Value = data.Value;
|
|
oldData.Unit = data.Unit;
|
|
oldData.Description = data.Description;
|
|
oldData.Timestamp = data.Timestamp;
|
|
}
|
|
}
|
|
return oldData;
|
|
}
|
|
}
|
|
} |