Repository navigation
Expand file tree
/
Copy pathEntities.cs
More file actions
143 lines (128 loc) · 5.38 KB
/
Copy pathEntities.cs
File metadata and controls
143 lines (128 loc) · 5.38 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
namespace MyBaseSystem.Domain;
public abstract class Entity
{
public Guid Id { get; set; } = Guid.NewGuid();
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
public Guid? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public Guid? UpdatedBy { get; set; }
public bool IsDeleted { get; set; }
}
public sealed class User : Entity
{
public required string UserName { get; set; }
public required string Email { get; set; }
public required string PasswordHash { get; set; }
public string DisplayName { get; set; } = "";
public string? Avatar { get; set; }
public string? Phone { get; set; }
public Guid? DepartmentId { get; set; }
public bool IsEnabled { get; set; } = true;
public DateTimeOffset? LastLoginAt { get; set; }
public ICollection<UserRole> UserRoles { get; set; } = [];
public void UpdateProfile(string displayName,string email,string? phone,Guid? departmentId,bool enabled){DisplayName=displayName;Email=email;Phone=phone;DepartmentId=departmentId;IsEnabled=enabled;UpdatedAt=DateTimeOffset.UtcNow;}
public void Delete(){if(UserName=="admin")throw new InvalidOperationException("内置管理员不能删除");IsDeleted=true;UpdatedAt=DateTimeOffset.UtcNow;}
}
public sealed class Role : Entity
{
public required string Code { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public bool IsSystem { get; set; }
public bool IsEnabled { get; set; } = true;
public ICollection<UserRole> UserRoles { get; set; } = [];
public ICollection<RolePermission> RolePermissions { get; set; } = [];
public void Rename(string name,string? description,bool enabled){Name=name;Description=description;IsEnabled=enabled;UpdatedAt=DateTimeOffset.UtcNow;}
public void Delete(){if(IsSystem)throw new InvalidOperationException("系统角色不能删除");IsDeleted=true;UpdatedAt=DateTimeOffset.UtcNow;}
}
public sealed class Permission : Entity
{
public required string Code { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public string Group { get; set; } = "system";
}
public sealed class Menu : Entity
{
public Guid? ParentId { get; set; }
public required string Name { get; set; }
public required string Path { get; set; }
public string? Component { get; set; }
public string? Icon { get; set; }
public string? PermissionCode { get; set; }
public int Sort { get; set; }
public MenuType Type { get; set; } = MenuType.Page;
public bool Hidden { get; set; }
public bool IsEnabled { get; set; } = true;
}
public enum MenuType { Directory, Page, ExternalLink }
public sealed class Department : Entity
{
public Guid? ParentId { get; set; }
public required string Code { get; set; }
public required string Name { get; set; }
public int Sort { get; set; }
public bool IsEnabled { get; set; } = true;
}
public sealed class DictionaryType : Entity
{
public required string Code { get; set; }
public required string Name { get; set; }
public bool IsSystem { get; set; }
}
public sealed class DictionaryItem : Entity
{
public Guid DictionaryTypeId { get; set; }
public required string Label { get; set; }
public required string Value { get; set; }
public int Sort { get; set; }
public bool IsEnabled { get; set; } = true;
}
public sealed class SystemSetting : Entity
{
public required string Key { get; set; }
public required string Value { get; set; }
public string Group { get; set; } = "default";
public string? Description { get; set; }
public bool IsPublic { get; set; }
}
public sealed class RefreshToken : Entity
{
public Guid UserId { get; set; }
public required string TokenHash { get; set; }
public DateTimeOffset ExpiresAt { get; set; }
public DateTimeOffset? RevokedAt { get; set; }
public string? ReplacedByTokenHash { get; set; }
}
public sealed class AuditLog : Entity
{
public Guid? UserId { get; set; }
public string UserName { get; set; } = "anonymous";
public required string Method { get; set; }
public required string Path { get; set; }
public int StatusCode { get; set; }
public long ElapsedMilliseconds { get; set; }
public string? IpAddress { get; set; }
public string? UserAgent { get; set; }
public string? Error { get; set; }
}
public sealed class LoginLog : Entity
{
public string Account { get; set; } = "";
public bool Success { get; set; }
public string? Message { get; set; }
public string? IpAddress { get; set; }
public string? UserAgent { get; set; }
}
/// <summary>用户站内通知,支持已读状态和业务跳转。</summary>
public sealed class Notification : Entity
{
public Guid? UserId { get; set; }
public required string Title { get; set; }
public required string Message { get; set; }
public string Type { get; set; } = "info";
public bool IsRead { get; set; }
public string? ActionUrl { get; set; }
}
public sealed class UserRole { public Guid UserId { get; set; } public User User { get; set; } = null!; public Guid RoleId { get; set; } public Role Role { get; set; } = null!; }
public sealed class RolePermission { public Guid RoleId { get; set; } public Role Role { get; set; } = null!; public Guid PermissionId { get; set; } public Permission Permission { get; set; } = null!; }