EquipmentDataRecord.cs
4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using FreeSql.DataAnnotations;
using HHECS.DAQHandle.Common.Utils;
using System.Text.Json;
namespace HHECS.DAQHandle.Models
{
/// <summary>
/// 设备数据记录
/// </summary>
[Table(Name = "daq_equipment_data_record")]
public class EquipmentDataRecord
{
/// <summary>
/// 设置值异常
/// </summary>
public static readonly byte SET_VALUE_ERROR = 0b00000001;
/// <summary>
/// 设置报警异常
/// </summary>
public static readonly byte SET_ALARM_ERROR = 0b00000010;
/// <summary>
/// 设置状态异常
/// </summary>
public static readonly byte SET_STATUS_ERROR = 0b00000100;
/// <summary>
/// 数据过期错误
/// </summary>
public static readonly byte SET_EXPIRE_ERROR = 0b00001000;
/// <summary>
/// 是否已经赋值
/// </summary>
public static readonly byte SET_VAULE_HANDLE = 0b10000000;
/// <summary>
/// 是否已经进行异常处理
/// </summary>
public static readonly byte SET_ERROR_HANDLE = 0b01000000;
/// <summary>
/// 是否已经进行状态更新
/// </summary>
public static readonly byte SET_STATUS_HANDLE = 0b00100000;
/// <summary>
/// 主键
/// </summary>
[Column(IsPrimary = true)]
public Guid Id { get; set; }
/// <summary>
/// 设备编号/IOT云平台设备SN
/// </summary>
public string EquipmentCode { get; set; } = null!;
/// <summary>
/// 设备类型编号
/// </summary>
[Column(IsIgnore = true)]
public string EquipmentTypeCode { get; set; } = null!;
/// <summary>
/// 设备名称
/// </summary>
[Column(IsIgnore = true)]
public string EquipmentName { get; set; } = null!;
private string _tags = null;
/// <summary>
/// Json数据
/// </summary>
[Column(DbType = "varchar(max)")]
public string Tags
{
get { return _tags; }
set
{
_tags = value;
try
{
if (!string.IsNullOrWhiteSpace(_tags))
{
var list = JsonSerializer.Deserialize<List<Prop>>(value);
Props = list.ToDictionary(x => x.Tag, x => x.Value);
}
}
catch (Exception ex)
{
SystemLog.PrintError($"{ex}");
}
}
}
[Column(IsIgnore = true)]
public Dictionary<string, string> Props { get; set; }
/// <summary>
/// 版本号
/// </summary>
public int Version { get; set; }
/// <summary>
/// 客户端提交时间戳
/// </summary>
public long Timestamp { get; set; }
/// <summary>
/// 是否已处理
/// </summary>
public bool IsHandle { get; set; }
/// <summary>
/// 各阶段是否处理成功
/// 第一位赋值是否报错,第二位是否记录异常成功 第三位是否记录状态成功
/// public readonly byte SET_VALUE_ERROR = 0b001;
/// public readonly byte SET_ALARM_ERROR = 0b010;
/// public readonly byte SET_STATUS_ERROR = 0b100;
/// </summary>
public byte HandleStage { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreateTime { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? UpdateTime { get; set; }
}
record Prop(string Tag, string Value);
/// <summary>
/// 数据记录处理状态
/// </summary>
[Flags]
public enum HandleStageConst : byte
{
/// <summary>
/// 设置值异常
/// </summary>
SET_VALUE_ERROR = 0b00000001,
/// <summary>
/// 设置报警异常
/// </summary>
SET_ALARM_ERROR = 0b00000010,
/// <summary>
/// 设置状态异常
/// </summary>
SET_STATUS_ERROR = 0b00000100,
/// <summary>
/// 数据过期错误
/// </summary>
SET_EXPIRE_ERROR = 0b00001000,
/// <summary>
/// 是否已经赋值
/// </summary>
SET_VAULE_HANDLE = 0b10000000,
/// <summary>
/// 是否已经进行异常处理
/// </summary>
SET_ERROR_HANDLE = 0b01000000,
/// <summary>
/// 是否已经进行状态更新
/// </summary>
SET_STATUS_HANDLE = 0b00100000,
}
}