2025-07-03 20:12:07 +08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2025-07-18 22:21:16 +08:00
|
|
|
|
using DMS.Core.Enums;
|
2025-06-20 18:53:29 +08:00
|
|
|
|
|
2025-07-19 09:25:01 +08:00
|
|
|
|
namespace DMS.WPF.Models;
|
2025-06-20 18:53:29 +08:00
|
|
|
|
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 表示变量数据信息。
|
|
|
|
|
|
/// </summary>
|
2025-07-17 20:13:21 +08:00
|
|
|
|
public partial class Variable : ObservableObject, IEquatable<Variable>
|
2025-06-20 18:53:29 +08:00
|
|
|
|
{
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 变量唯一标识符。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
public int Id { get; set; }
|
2025-07-03 20:12:07 +08:00
|
|
|
|
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 变量名称。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string name;
|
2025-07-03 13:17:25 +08:00
|
|
|
|
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 节点ID,用于标识变量在设备或系统中的唯一路径。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
public string NodeId { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 节点ID,用于标识变量在设备或系统中的唯一路径。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string S7Address { get; set; }
|
|
|
|
|
|
|
2025-07-08 17:33:20 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OPC UA Endpoint URL。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string? OpcUaEndpointUrl { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OPC UA Node ID。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string? OpcUaNodeId { get; set; }
|
|
|
|
|
|
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 变量描述。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 22:16:47 +08:00
|
|
|
|
[ObservableProperty]
|
2025-07-04 13:40:14 +08:00
|
|
|
|
private string description = String.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 协议类型,例如Modbus、OPC UA等。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ProtocolType ProtocolType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 信号类型,例如模拟量、数字量等。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public SignalType SignalType { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 数据类型,例如Int、Float、String等。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
public string DataType { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 变量当前原始数据值。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 22:16:47 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private string dataValue = String.Empty;
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 变量经过转换或格式化后的显示值。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 22:16:47 +08:00
|
|
|
|
[ObservableProperty]
|
2025-07-04 13:40:14 +08:00
|
|
|
|
private string displayValue = String.Empty;
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 指示变量是否处于激活状态。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-16 15:50:57 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
public bool isActive;
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
2025-07-09 19:38:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 指示变量是否被选中
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
public bool isSelect;
|
|
|
|
|
|
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 指示是否需要保存变量数据。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
public bool IsSave { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 指示是否需要对变量进行报警监测。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
public bool IsAlarm { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
2025-07-05 12:29:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 轮询级别,例如1秒、5秒等。
|
|
|
|
|
|
/// </summary>
|
2025-07-05 16:13:46 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private PollLevelType pollLevelType = PollLevelType.ThirtySeconds;
|
2025-07-05 12:29:10 +08:00
|
|
|
|
|
2025-07-10 17:16:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OPC UA更新类型,例如轮询或订阅。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private OpcUaUpdateType opcUaUpdateType = OpcUaUpdateType.OpcUaPoll;
|
|
|
|
|
|
|
2025-07-05 12:56:13 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 最后一次轮询时间。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DateTime LastPollTime { get; set; } = DateTime.MinValue;
|
|
|
|
|
|
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 指示变量是否已被逻辑删除。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
public bool IsDeleted { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
2025-07-03 20:12:07 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 指示变量是否已被修改了。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private bool isModified;
|
|
|
|
|
|
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 报警的最大值阈值。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
public double AlarmMax { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 报警的最小值阈值。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
public double AlarmMin { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 数据转换规则或表达式。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 22:16:47 +08:00
|
|
|
|
[ObservableProperty]
|
2025-07-04 13:40:14 +08:00
|
|
|
|
private string converstion = String.Empty;
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 数据保存的范围或阈值。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-06-23 17:01:06 +08:00
|
|
|
|
public double SaveRange { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// 变量数据创建时间。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-04 13:40:14 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private DateTime createTime;
|
|
|
|
|
|
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 变量数据最后更新时间。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 22:16:47 +08:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
|
private DateTime updateTime = DateTime.Now;
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 最后更新变量数据的用户。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
public User UpdateUser { get; set; }
|
2025-07-03 12:55:00 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
/// 关联的变量表ID。
|
2025-07-03 12:55:00 +08:00
|
|
|
|
/// </summary>
|
2025-07-03 13:17:25 +08:00
|
|
|
|
public int VariableTableId { get; set; }
|
2025-07-03 20:12:07 +08:00
|
|
|
|
|
2025-07-08 20:19:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关联的变量表实体。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public VariableTable? VariableTable { get; set; }
|
|
|
|
|
|
|
2025-07-04 13:40:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 关联的MQTT配置列表。
|
|
|
|
|
|
/// </summary>
|
2025-07-17 17:28:12 +08:00
|
|
|
|
public List<VariableMqtt>? VariableMqtts { get; set; }
|
2025-07-04 13:40:14 +08:00
|
|
|
|
|
2025-07-05 16:13:46 +08:00
|
|
|
|
partial void OnPollLevelTypeChanged(PollLevelType value)
|
|
|
|
|
|
{
|
|
|
|
|
|
IsModified = true;
|
|
|
|
|
|
}
|
2025-07-17 09:45:58 +08:00
|
|
|
|
|
|
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
|
{
|
2025-07-17 20:13:21 +08:00
|
|
|
|
return Equals(obj as Variable);
|
2025-07-17 09:45:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-17 20:13:21 +08:00
|
|
|
|
public bool Equals(Variable? other)
|
2025-07-17 09:45:58 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (ReferenceEquals(null, other)) return false;
|
|
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
|
|
|
|
|
|
|
|
// Compare all relevant properties for equality
|
|
|
|
|
|
return Name == other.Name &&
|
|
|
|
|
|
NodeId == other.NodeId &&
|
|
|
|
|
|
S7Address == other.S7Address &&
|
|
|
|
|
|
OpcUaEndpointUrl == other.OpcUaEndpointUrl &&
|
|
|
|
|
|
OpcUaNodeId == other.OpcUaNodeId &&
|
|
|
|
|
|
Description == other.Description &&
|
|
|
|
|
|
ProtocolType == other.ProtocolType &&
|
|
|
|
|
|
SignalType == other.SignalType &&
|
|
|
|
|
|
DataType == other.DataType &&
|
|
|
|
|
|
DataValue == other.DataValue &&
|
|
|
|
|
|
DisplayValue == other.DisplayValue &&
|
|
|
|
|
|
IsActive == other.IsActive &&
|
|
|
|
|
|
IsSave == other.IsSave &&
|
|
|
|
|
|
IsAlarm == other.IsAlarm &&
|
|
|
|
|
|
PollLevelType == other.PollLevelType &&
|
|
|
|
|
|
OpcUaUpdateType == other.OpcUaUpdateType &&
|
|
|
|
|
|
IsDeleted == other.IsDeleted &&
|
|
|
|
|
|
AlarmMax == other.AlarmMax &&
|
|
|
|
|
|
AlarmMin == other.AlarmMin &&
|
|
|
|
|
|
Converstion == other.Converstion &&
|
|
|
|
|
|
SaveRange == other.SaveRange &&
|
|
|
|
|
|
CreateTime == other.CreateTime &&
|
|
|
|
|
|
VariableTableId == other.VariableTableId;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Combine hash codes of all relevant properties
|
|
|
|
|
|
var hash = new HashCode();
|
|
|
|
|
|
hash.Add(Name);
|
|
|
|
|
|
hash.Add(NodeId);
|
|
|
|
|
|
hash.Add(S7Address);
|
|
|
|
|
|
hash.Add(OpcUaEndpointUrl);
|
|
|
|
|
|
hash.Add(OpcUaNodeId);
|
|
|
|
|
|
hash.Add(Description);
|
|
|
|
|
|
hash.Add(ProtocolType);
|
|
|
|
|
|
hash.Add(SignalType);
|
|
|
|
|
|
hash.Add(DataType);
|
|
|
|
|
|
hash.Add(DataValue);
|
|
|
|
|
|
hash.Add(DisplayValue);
|
|
|
|
|
|
hash.Add(IsActive);
|
|
|
|
|
|
hash.Add(IsSave);
|
|
|
|
|
|
hash.Add(IsAlarm);
|
|
|
|
|
|
hash.Add(PollLevelType);
|
|
|
|
|
|
hash.Add(OpcUaUpdateType);
|
|
|
|
|
|
hash.Add(IsDeleted);
|
|
|
|
|
|
hash.Add(AlarmMax);
|
|
|
|
|
|
hash.Add(AlarmMin);
|
|
|
|
|
|
hash.Add(Converstion);
|
|
|
|
|
|
hash.Add(SaveRange);
|
|
|
|
|
|
hash.Add(CreateTime);
|
|
|
|
|
|
hash.Add(VariableTableId);
|
|
|
|
|
|
return hash.ToHashCode();
|
|
|
|
|
|
}
|
2025-06-20 18:53:29 +08:00
|
|
|
|
}
|