AlarmLog.cs
2.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
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Rcs.Domain.Entities;
/// <summary>
/// 报警日志
/// </summary>
[Table("alarm_logs")]
public class AlarmLog : Entity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column("alarm_log_id")]
public Guid AlarmLogId { get; set; }
[Required]
[Column("alarm_code")]
[MaxLength(64)]
public string AlarmCode { get; set; } = string.Empty;
[Column("alarm_type")]
[MaxLength(64)]
public string? AlarmType { get; set; }
[Required]
[Column("level")]
[MaxLength(32)]
public string Level { get; set; } = "warning";
[Column("source_type")]
[MaxLength(64)]
public string? SourceType { get; set; }
[Column("source_code")]
[MaxLength(128)]
public string? SourceCode { get; set; }
[Column("source_name")]
[MaxLength(200)]
public string? SourceName { get; set; }
[Required]
[Column("title")]
[MaxLength(200)]
public string Title { get; set; } = string.Empty;
[Required]
[Column("message", TypeName = "text")]
public string Message { get; set; } = string.Empty;
[Column("details", TypeName = "text")]
public string? Details { get; set; }
[Column("extra_data", TypeName = "text")]
public string? ExtraData { get; set; }
[Column("is_acknowledged")]
public bool IsAcknowledged { get; private set; }
[Column("acknowledged_by")]
[MaxLength(100)]
public string? AcknowledgedBy { get; private set; }
[Column("acknowledge_remark")]
[MaxLength(500)]
public string? AcknowledgeRemark { get; private set; }
[Column("acknowledged_at", TypeName = "timestamp")]
public DateTime? AcknowledgedAt { get; private set; }
[Column("occurred_at", TypeName = "timestamp")]
public DateTime OccurredAt { get; set; }
[Column("resolved_at", TypeName = "timestamp")]
public DateTime? ResolvedAt { get; set; }
[Column("created_at", TypeName = "timestamp")]
public DateTime CreatedAt { get; set; } = DateTime.Now;
[Column("updated_at", TypeName = "timestamp")]
public DateTime? UpdatedAt { get; set; }
public void Acknowledge(string? acknowledgedBy, string? remark, DateTime? acknowledgedAt = null)
{
var now = acknowledgedAt ?? DateTime.Now;
if (!IsAcknowledged)
{
IsAcknowledged = true;
AcknowledgedAt = now;
}
if (!string.IsNullOrWhiteSpace(acknowledgedBy))
{
AcknowledgedBy = acknowledgedBy.Trim();
}
if (!string.IsNullOrWhiteSpace(remark))
{
AcknowledgeRemark = remark.Trim();
}
UpdatedAt = now;
}
}