Map.cs
4.76 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
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Rcs.Domain.Attributes;
namespace Rcs.Domain.Entities
{
[Table("maps")]
public partial class Map : Entity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column("map_id")]
public Guid MapId { get; set; }
[Required]
[Column("map_code")]
[MaxLength(100)]
public string MapCode { get; set; }
[Required]
[Column("map_name")]
[MaxLength(100)]
public string MapName { get; set; }
[Column("map_type")]
public MapTYPE MapType { get; set; }
[Required]
[Column("version")]
[MaxLength(50)]
public string Version { get; set; }
[Column("description")]
public string? Description { get; set; }
[Column("created_at", TypeName = "timestamp")]
public DateTime? CreatedAt { get; set; } = DateTime.Now;
[Column("active")]
public bool Active { get; set; }
/// <summary>
/// 地图资源URL
/// </summary>
[Column("resource_url")]
[MaxLength(512)]
public string? ResourceUrl { get; set; }
/// <summary>
/// 地图点位URL
/// </summary>
[Column("points_url")]
[MaxLength(512)]
public string? PointsUrl { get; set; }
/// <summary>
/// 是否定时获取资源
/// </summary>
[Column("resource_auto_sync")]
public bool ResourceAutoSync { get; set; }
/// <summary>
/// 资源同步间隔(秒)
/// </summary>
[Column("resource_sync_interval")]
public int ResourceSyncInterval { get; set; } = 60;
/// <summary>
/// 是否定时获取点位
/// </summary>
[Column("points_auto_sync")]
public bool PointsAutoSync { get; set; }
/// <summary>
/// 点位同步间隔(秒)
/// </summary>
[Column("points_sync_interval")]
public int PointsSyncInterval { get; set; } = 60;
#region 外键 => 导航属性,OneToMany
public virtual ICollection<MapEdge> MapEdges { get; set; } = new List<MapEdge>();
public virtual ICollection<MapNode> MapNodes { get; set; } = new List<MapNode>();
public virtual ICollection<MapResource> MapResources { get; set; } = new List<MapResource>();
#endregion
#region 一对一导航属性
/// <summary>
/// 地图文件导航属性(一对一)
/// </summary>
public virtual MapFile? MapFile { get; set; }
#endregion
public static Map Create(string mapCode, string mapName, MapTYPE mapType, string version, string? description, bool active, string? resourceUrl = null, string? pointsUrl = null, bool resourceAutoSync = false, int resourceSyncInterval = 60, bool pointsAutoSync = false, int pointsSyncInterval = 60)
{
return new Map
{
MapId = Guid.NewGuid(),
MapCode = mapCode,
MapName = mapName,
MapType = mapType,
Version = version,
Description = description,
Active = active,
ResourceUrl = resourceUrl,
PointsUrl = pointsUrl,
ResourceAutoSync = resourceAutoSync,
ResourceSyncInterval = resourceSyncInterval,
PointsAutoSync = pointsAutoSync,
PointsSyncInterval = pointsSyncInterval,
CreatedAt = DateTime.Now
};
}
public void Update(string mapCode, string mapName, MapTYPE mapType, string version, string? description, bool active, string? resourceUrl = null, string? pointsUrl = null, bool resourceAutoSync = false, int resourceSyncInterval = 60, bool pointsAutoSync = false, int pointsSyncInterval = 60)
{
if(!string.IsNullOrWhiteSpace(mapCode))MapCode = mapCode;
if(!string.IsNullOrWhiteSpace(mapCode))MapName = mapName;
if(mapCode != null) MapType = mapType;
if(!string.IsNullOrWhiteSpace(mapCode))Version = version;
if(description != null) Description = description;
Active = active;
ResourceUrl = resourceUrl;
PointsUrl = pointsUrl;
ResourceAutoSync = resourceAutoSync;
ResourceSyncInterval = resourceSyncInterval;
PointsAutoSync = pointsAutoSync;
PointsSyncInterval = pointsSyncInterval;
}
}
public enum MapTYPE
{
[EnumDescription("拓扑地图", "Topology")]
topo = 1,
[EnumDescription("雷达地图", "Radar")]
radar = 2
}
}