role.go
2.2 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
package domain
import "time"
// 角色类型 1.普通角色 1024:超级管理员
const (
RoleTypeNormal = 1
RoleTypeAdmin = 1024
)
// 角色 (base)
type Role struct {
// 角色ID
RoleId int64 `json:"roleId,omitempty"`
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
// 组织ID
OrgId int64 `json:"orgId,omitempty"`
// 角色类型 1.普通角色 1024:超级管理员
RoleType int `json:"roleType,omitempty"`
// 角色名称
RoleName string `json:"roleName,omitempty"`
// 有权限的菜单
AccessMenus []int64 `json:"accessMenus,omitempty"`
// 描述
Desc int64 `json:"desc,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
type RoleRepository interface {
Save(role *Role) (*Role, error)
Remove(role *Role) (*Role, error)
FindOne(queryOptions map[string]interface{}) (*Role, error)
Find(queryOptions map[string]interface{}) (int64, []*Role, error)
}
func (role *Role) Identify() interface{} {
if role.RoleId == 0 {
return nil
}
return role.RoleId
}
func (role *Role) Update(data map[string]interface{}) error {
if companyId, ok := data["companyId"]; ok {
role.CompanyId = companyId.(int64)
}
if orgId, ok := data["orgId"]; ok {
role.OrgId = orgId.(int64)
}
if roleType, ok := data["roleType"]; ok {
role.RoleType = roleType.(int)
}
if roleName, ok := data["roleName"]; ok {
role.RoleName = roleName.(string)
}
if accessMenus, ok := data["accessMenus"]; ok {
role.AccessMenus = accessMenus.([]int64)
}
if desc, ok := data["desc"]; ok {
role.Desc = desc.(int64)
}
if userName, ok := data["userName"]; ok {
role.Ext.UserName = userName.(string)
}
if orgName, ok := data["orgName"]; ok {
role.Ext.OrgName = orgName.(string)
}
if phone, ok := data["phone"]; ok {
role.Ext.Phone = phone.(string)
}
if depName, ok := data["depName"]; ok {
role.Ext.DepName = depName.(string)
}
if parentDepName, ok := data["parentDepName"]; ok {
role.Ext.ParentDepName = parentDepName.(string)
}
if createdAt, ok := data["createdAt"]; ok {
role.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
role.UpdatedAt = updatedAt.(time.Time)
}
return nil
}