2
schangxiang@126.com
2024-06-20 90b264c675155d6fb921d256f2de48ad398845c6
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
using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
 
namespace iWare.Wms.Core
{
    /// <summary>
    /// 用户表
    /// </summary>
    [Table("sys_user")]
    [Comment("用户表")]
    public class SysUser : DEntityBase, IEntityTypeBuilder<SysUser>
    {
        /// <summary>
        /// 账号
        /// </summary>
        [Comment("账号")]
        [Required, MaxLength(50)]
        public string Account { get; set; }
 
        /// <summary>
        /// 密码(默认MD5加密)
        /// </summary>
        [Comment("密码")]
        [Required, MaxLength(50)]
        public string Password { get; set; }
 
        /// <summary>
        /// 昵称
        /// </summary>
        [Comment("昵称")]
        [MaxLength(20)]
        public string NickName { get; set; }
 
        /// <summary>
        /// 姓名
        /// </summary>
        [Comment("姓名")]
        [MaxLength(20)]
        public string Name { get; set; }
 
        /// <summary>
        /// 头像
        /// </summary>
        [Comment("头像")]
        public string Avatar { get; set; }
 
        /// <summary>
        /// 生日
        /// </summary>
        [Comment("生日")]
        public DateTimeOffset? Birthday { get; set; }
 
        /// <summary>
        /// 性别-男_1、女_2
        /// </summary>
        [Comment("性别-男_1、女_2")]
        public Gender Sex { get; set; }
 
        /// <summary>
        /// 邮箱
        /// </summary>
        [Comment("邮箱")]
        [MaxLength(50)]
        public string Email { get; set; }
 
        /// <summary>
        /// 手机
        /// </summary>
        [Comment("手机")]
        [MaxLength(20)]
        public string Phone { get; set; }
 
        /// <summary>
        /// 电话
        /// </summary>
        [Comment("电话")]
        [MaxLength(20)]
        public string Tel { get; set; }
 
        /// <summary>
        /// 最后登录IP
        /// </summary>
        [Comment("最后登录IP")]
        [MaxLength(20)]
        public string LastLoginIp { get; set; }
 
        /// <summary>
        /// 最后登录时间
        /// </summary>
        [Comment("最后登录时间")]
        public DateTimeOffset? LastLoginTime { get; set; }
 
        /// <summary>
        /// 管理员类型-超级管理员_1、管理员_2、普通账号_3
        /// </summary>
        [Comment("管理员类型-超级管理员_1、管理员_2、普通账号_3")]
        public AdminType AdminType { get; set; }
 
        /// <summary>
        /// 状态-正常_0、停用_1、删除_2
        /// </summary>
        [Comment("状态-正常_0、停用_1、删除_2")]
        public CommonStatus Status { get; set; } = CommonStatus.ENABLE;
 
        /// <summary>
        /// 多对多(角色)
        /// </summary>
        public ICollection<SysRole> SysRoles { get; set; }
 
        /// <summary>
        /// 多对多中间表(用户-角色)
        /// </summary>
        public List<SysUserRole> SysUserRoles { get; set; }
 
        /// <summary>
        /// 多对多(机构)
        /// </summary>
        public ICollection<SysOrg> SysOrgs { get; set; }
 
        /// <summary>
        /// 多对多中间表(用户-机构 数据范围)
        /// </summary>
        public List<SysUserDataScope> SysUserDataScopes { get; set; }
 
        /// <summary>
        /// 配置多对多关系
        /// </summary>
        /// <param name="entityBuilder"></param>
        /// <param name="dbContext"></param>
        /// <param name="dbContextLocator"></param>
        public void Configure(EntityTypeBuilder<SysUser> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.HasMany(p => p.SysRoles).WithMany(p => p.SysUsers).UsingEntity<SysUserRole>(
                u => u.HasOne(c => c.SysRole).WithMany(c => c.SysUserRoles).HasForeignKey(c => c.SysRoleId),
                u => u.HasOne(c => c.SysUser).WithMany(c => c.SysUserRoles).HasForeignKey(c => c.SysUserId),
                u =>
                {
                    u.HasKey(c => new { c.SysUserId, c.SysRoleId });
                });
 
            entityBuilder.HasMany(p => p.SysOrgs).WithMany(p => p.SysUsers).UsingEntity<SysUserDataScope>(
                u => u.HasOne(c => c.SysOrg).WithMany(c => c.SysUserDataScopes).HasForeignKey(c => c.SysOrgId),
                u => u.HasOne(c => c.SysUser).WithMany(c => c.SysUserDataScopes).HasForeignKey(c => c.SysUserId),
                u =>
                {
                    u.HasKey(c => new { c.SysUserId, c.SysOrgId });
                });
        }
    }
}