user.go
3.3 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
package domain
import "time"
const (
StatusEnable int64 = 1
StatusDisable int64 = 2
)
const (
SuperAdministrator = 1
EnterpriseAdministrator = 10
NormalUser = 100
)
// UserType
const (
Manager = 1
Partner = 2
Guest = 3
)
// 用户实体
type User struct {
// 用户id
UserId int64 `json:"userId"`
// 1.高管 2.合伙人 4:游客
UserType int `json:"userType"`
// 用户权限
Permissions []int `json:"permissions"`
// 公司Id
CompanyId int64 `json:"companyId"`
// 用户信息
UserInfo *UserInfo `json:"userInfo"`
// 合伙人信息
PartnerInfo *PartnerInfo `json:"partnerInfo"`
// 状态 1正常 2禁用
Status int64 `json:"status"`
// 管理员类型 1.超级管理员 10:企业管理员 100:普通用户
AdminType int `json:"adminType"`
// 合伙人列表 用户类型为高管时有效
AccessPartners []int64 `json:"accessPartners"`
// 创建时间
CreateAt time.Time `json:"createAt"`
// 更新时间
UpdateAt time.Time `json:"updateAt"`
// 删除时间
DeleteAt time.Time `json:"deleteAt"`
}
type UserRepository interface {
Save(user *User) (*User, error)
Remove(user *User) (*User, error)
FindOne(queryOptions map[string]interface{}) (*User, error)
Find(queryOptions map[string]interface{}) (int64, []*User, error)
}
func (user *User) Identify() interface{} {
if user.UserId == 0 {
return nil
}
return user.UserId
}
func (user *User) Update(data map[string]interface{}) error {
if userId, ok := data["userId"]; ok {
user.UserId = userId.(int64)
}
if userType, ok := data["userType"]; ok {
user.UserType = userType.(int)
}
if permissions, ok := data["permissions"]; ok {
user.Permissions = permissions.([]int)
}
if companyId, ok := data["companyId"]; ok {
user.CompanyId = companyId.(int64)
}
if isPrincipal, ok := data["isPrincipal"]; ok {
user.UserInfo.IsPrincipal = isPrincipal.(bool)
}
if uid, ok := data["uid"]; ok {
user.UserInfo.Uid = uid.(int64)
}
if userAccount, ok := data["userAccount"]; ok {
user.UserInfo.UserAccount = userAccount.(string)
}
if userAvatarUrl, ok := data["userAvatarUrl"]; ok {
user.UserInfo.UserAvatarUrl = userAvatarUrl.(string)
}
if userName, ok := data["userName"]; ok {
user.UserInfo.UserName = userName.(string)
}
if email, ok := data["email"]; ok {
user.UserInfo.Email = email.(string)
}
if gender, ok := data["gender"]; ok {
user.UserInfo.Gender = gender.(int)
}
if entryTime, ok := data["entryTime"]; ok {
user.UserInfo.EntryTime = entryTime.(time.Time)
}
if extension, ok := data["extension"]; ok {
user.UserInfo.Extension = extension.(string)
}
if workplace, ok := data["workplace"]; ok {
user.UserInfo.Workplace = workplace.(string)
}
if privateNumber, ok := data["privateNumber"]; ok {
user.UserInfo.PrivateNumber = privateNumber.(string)
}
if jobNumber, ok := data["jobNumber"]; ok {
user.UserInfo.JobNumber = jobNumber.(string)
}
if partnerAccount, ok := data["partnerAccount"]; ok {
user.PartnerInfo.PartnerAccount = partnerAccount.(string)
}
if partnerName, ok := data["partnerName"]; ok {
user.PartnerInfo.PartnerName = partnerName.(string)
}
if regionName, ok := data["regionName"]; ok {
user.PartnerInfo.RegionInfo.RegionName = regionName.(string)
}
if status, ok := data["status"]; ok {
user.PartnerInfo.Status = status.(int64)
}
return nil
}