users.go
1.7 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
package users
import "time"
// 用户实体
type Users struct {
// dcc
Id int64 `json:"id"`
// 名称
Name string `json:"name"`
// 手机号
Phone string `json:"phone"`
// 密码
Passwd string `json:"passwd"`
// 用户角色
Roles []int64 `json:"roles"`
// 状态 1-启用 0-禁用
Status int `json:"status"`
// 1:管理员 2:普通员工
AdminType int `json:"adminType"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
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.Id == 0 {
return nil
}
return users.Id
}
func (users *Users) GetRoles() []int {
var ret []int
for _, v := range users.Roles {
ret = append(ret, int(v))
}
return ret
}
func (users *Users) Update(data map[string]interface{}) error {
if Id, ok := data["Id"]; ok {
users.Id = Id.(int64)
}
if Name, ok := data["Name"]; ok {
users.Name = Name.(string)
}
if Phone, ok := data["Phone"]; ok {
users.Phone = Phone.(string)
}
if Passwd, ok := data["Passwd"]; ok {
users.Passwd = Passwd.(string)
}
if Roles, ok := data["Roles"]; ok {
users.Roles = Roles.([]int64)
}
if Status, ok := data["Status"]; ok {
users.Status = Status.(int)
}
if AdminType, ok := data["AdminType"]; ok {
users.AdminType = AdminType.(int)
}
if CreateTime, ok := data["CreateTime"]; ok {
users.CreateTime = CreateTime.(time.Time)
}
if UpdateTime, ok := data["UpdateTime"]; ok {
users.UpdateTime = UpdateTime.(time.Time)
}
return nil
}