users.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package domain
import "time"
//用户是否可用状态:【1:正常】【 2:禁用】
const (
userStatusUsable int8 = 1
userStatusUnusable int8 = 2
)
//用户是否是主管 :【1:是主管】【 2:不是主管】
const (
UserIsCompanyCharge int8 = 1
UserIsNotCompanyCharge int8 = 2
)
//用户类型 1普通用户 2主管理员
const (
UserIsNotAdmin int8 = 1
UserIsAdmin int8 = 2
)
//Users 企业平台的用户
type Users struct {
Id int64 //用户id
CompanyId int64 //公司id
OpenId int64 //统一用户中心
Name string //用户名称
Sex int8 //性别:【0:未知】【1:男】【2:女】
JobNum string //工号
Phone string //手机号,同账号
PrivatePhone string //私人手机号
Email string //邮件
ExtensionNum string //分机号
EntryTime time.Time //入职时间
Workspace string //工作地
Status int8 //状态:【1:正常】【 2:禁用】
Avatar string ///头像
Remarks string //备注
ChargeStatus int8 //是否为当前公司主管 【1:是】【2:否】
CreateAt time.Time
UpdateAt time.Time
Permission []AdminPermissionBase //权限
AccessPartners []Partner
AdminType int8 //是否是公司负责人,即超级管理员 1普通用户 2主管理员
}
//IsUsable 用户是否可用
func (u Users) IsUsable() bool {
return u.Status == userStatusUsable
}
//IsCharge 用户是否是主管
func (u Users) IsCharge() bool {
return u.ChargeStatus == UserIsCompanyCharge
}
func (u Users) InCompany(companyid int64) bool {
return u.CompanyId == companyid
}
func (u *Users) Update(m map[string]interface{}) error {
if v, ok := m["CompanyId"]; ok {
u.CompanyId = v.(int64)
}
if v, ok := m["OpenId"]; ok {
u.OpenId = v.(int64)
}
if v, ok := m["Name"]; ok {
u.Name = v.(string)
}
if v, ok := m["Sex"]; ok {
u.Sex = v.(int8)
}
if v, ok := m["JobNum"]; ok {
u.JobNum = v.(string)
}
if v, ok := m["Phone"]; ok {
u.Phone = v.(string)
}
if v, ok := m["PrivatePhone"]; ok {
u.PrivatePhone = v.(string)
}
if v, ok := m["Email"]; ok {
u.Email = v.(string)
}
if v, ok := m["ExtensionNum"]; ok {
u.ExtensionNum = v.(string)
}
if v, ok := m["EntryTime"]; ok {
u.EntryTime = v.(time.Time)
}
if v, ok := m["Workspace"]; ok {
u.Workspace = v.(string)
}
if v, ok := m["Status"]; ok {
u.Status = v.(int8)
}
if v, ok := m["Avatar"]; ok {
u.Avatar = v.(string)
}
if v, ok := m["Remarks"]; ok {
u.Remarks = v.(string)
}
if v, ok := m["ChargeStatus"]; ok {
u.ChargeStatus = v.(int8)
}
if v, ok := m["Permission"]; ok {
u.Permission = v.([]AdminPermissionBase)
}
if v, ok := m["AccessPartners"]; ok {
u.AccessPartners = v.([]Partner)
}
if v, ok := m["AdminType"]; ok {
u.AdminType = v.(int8)
}
return nil
}
type UsersFindOneQuery struct {
Id int64
Phone string
CompanyId int64
OpenId int64
}
type UsersFindQuery struct {
AdminType int8
ChargeStatus int8
CompanyId int64
Ids []int64
Offset int
Limit int
}
type UsersRepository interface {
Add(*Users) error
Edit(*Users) error
Remove([]int64) error
FindOne(queryOptions UsersFindOneQuery) (Users, error)
Find(queryOptions UsersFindQuery) (int, []Users, error)
}