users.go
4.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package domain
import "time"
// 用户类型
const (
UsersTypeEmployee = 1
UsersTypeCooperation = 2
UsersTypeCompanyAdmin = 1024
)
// 用户状态
const (
UserStatusEnable UsersStatus = 1
UserStatusDisable UsersStatus = 2
UserStatusDestroy UsersStatus = 3
)
// 用户
type Users struct {
// 用户Id 用户唯一标识
UsersId int64 `json:"usersId,omitempty"`
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
// 用户基础数据id
UsersBaseId int64 `json:"usersBaseId,omitempty"`
// 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
UsersType int `json:"usersType,omitempty"`
// 用户编号 企业内标识
UsersCode string `json:"usersCode,omitempty"`
// 组织机构
OrganizationId int64 `json:"organizationId,omitempty"`
// 所属部门
DepartmentId int64 `json:"departmentId,omitempty"`
// 用户信息 (冗余,数据存在usersBase里面)
UsersInfo *UsersInfo `json:"usersInfo,omitempty"`
// 用户关联的组织
UsersOrg []*Org `json:"usersOrg,omitempty"`
// 用户关联的角色
UsersRole []*Role `json:"usersRole,omitempty"`
// 收藏的菜单(工作台)(菜单编码列表)
FavoriteMenus []string `json:"favoriteMenus,omitempty"`
// 共创信息 (共创用户有效)
CooperationInfo *CooperationInfo `json:"cooperationInfo,omitempty"`
// 状态(1:启用 2:禁用 3:注销)
EnableStatus int `json:"enableStatus,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
type UsersRepository interface {
Save(users *Users) (*Users, error)
Remove(users *Users) (*Users, error)
FindOne(queryOptions map[string]interface{}) (*Users, error)
Find(queryOptions map[string]interface{}) (int64, []*Users, error)
}
func (users *Users) Identify() interface{} {
if users.UsersId == 0 {
return nil
}
return users.UsersId
}
func (users *Users) Update(data map[string]interface{}) error {
if usersId, ok := data["usersId"]; ok {
users.UsersId = usersId.(int64)
}
if companyId, ok := data["companyId"]; ok {
users.CompanyId = companyId.(int64)
}
if usersBaseId, ok := data["usersBaseId"]; ok {
users.UsersBaseId = usersBaseId.(int64)
}
if usersType, ok := data["usersType"]; ok {
users.UsersType = usersType.(int)
}
if usersCode, ok := data["usersCode"]; ok {
users.UsersCode = usersCode.(string)
}
if organizationId, ok := data["organizationId"]; ok {
users.OrganizationId = organizationId.(int64)
}
if departmentId, ok := data["departmentId"]; ok {
users.DepartmentId = departmentId.(int64)
}
if usersName, ok := data["usersName"]; ok {
users.UsersInfo.UsersName = usersName.(string)
}
if phone, ok := data["phone"]; ok {
users.UsersInfo.Phone = phone.(string)
}
if avatar, ok := data["avatar"]; ok {
users.UsersInfo.Avatar = avatar.(string)
}
if email, ok := data["email"]; ok {
users.UsersInfo.Email = email.(string)
}
if usersOrg, ok := data["usersOrg"]; ok {
users.UsersOrg = usersOrg.([]*Org)
}
if usersRole, ok := data["usersRole"]; ok {
users.UsersRole = usersRole.([]*Role)
}
if favoriteMenus, ok := data["favoriteMenus"]; ok {
users.FavoriteMenus = favoriteMenus.([]string)
}
if cooperationCompany, ok := data["cooperationCompany"]; ok {
users.CooperationInfo.CooperationCompany = cooperationCompany.(string)
}
if cooperationDeadline, ok := data["cooperationDeadline"]; ok {
users.CooperationInfo.CooperationDeadline = cooperationDeadline.(time.Time)
}
if enableStatus, ok := data["enableStatus"]; ok {
users.EnableStatus = enableStatus.(int)
}
if usersName, ok := data["usersName"]; ok {
users.Ext.UsersName = usersName.(string)
}
if orgName, ok := data["orgName"]; ok {
users.Ext.OrgName = orgName.(string)
}
if phone, ok := data["phone"]; ok {
users.Ext.Phone = phone.(string)
}
if depName, ok := data["depName"]; ok {
users.Ext.DepName = depName.(string)
}
if parentDepName, ok := data["parentDepName"]; ok {
users.Ext.ParentDepName = parentDepName.(string)
}
if createdAt, ok := data["createdAt"]; ok {
users.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
users.UpdatedAt = updatedAt.(time.Time)
}
return nil
}
type UsersStatus int