sys_role.go
3.4 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
package domain
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
)
type SysRole struct {
Id int64 `json:",omitempty"` // 唯一标识
CompanyId int64 `json:"companyId"` // 公司ID
Name string `json:",omitempty"` // 公司名称
Menus []int64 `json:",omitempty"` // 菜单列表
AuthUsers []int64 `json:",omitempty"` // 拥护该角色的用户列表
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
}
type SysRoleRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *SysRole) (*SysRole, error)
Update(ctx context.Context, conn transaction.Conn, dm *SysRole) (*SysRole, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *SysRole) (*SysRole, error)
Delete(ctx context.Context, conn transaction.Conn, dm *SysRole) (*SysRole, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*SysRole, error)
FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*SysRole, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*SysRole, error)
FindByEmployee(ctx context.Context, conn transaction.Conn, companyId, userId int64, queryOptions map[string]interface{}) (int64, []*SysRole, error)
}
// AddUser 添加用户
func (role *SysRole) AddUser(userId int64) {
if lo.Contains(role.AuthUsers, userId) {
return
}
role.AuthUsers = append(role.AuthUsers, userId)
}
// RemoveUser 移除用户
func (role *SysRole) RemoveUser(userId int64) {
if !lo.Contains(role.AuthUsers, userId) {
return
}
role.AuthUsers = lo.Without(role.AuthUsers, userId)
}
type SysMenu struct {
Id int64 `json:"id,omitempty"` // 菜单ID
ParentId int64 `json:"parentId"` // 父级ID
Name string `json:"name,omitempty"` // 菜单名称
Code string `json:"code,omitempty"` // 菜单编码
MenuType string `json:"menuType,omitempty"` // 菜单类型 (目录catalog、菜单menu、按钮button)
Icon string `json:"icon,omitempty"` // 图标
Sort int64 `json:"sort,omitempty"` // 排序
ParentPath string `json:"parentPath,omitempty"` // 父级目录 1,2,3
Status int64 `json:"status,omitempty"` // 启用状态 1:启用 2:禁用
Version int `json:"version,omitempty"`
}
var DefaultMenus []*SysMenu = []*SysMenu{
NewMenu(10, "工作台", "SYSTEM_WORKBENCH", 0, 1),
//NewMenu(40, "通知公告", "SYSTEM_NOTICE", 0, 1),
//NewMenu(60, "系统日志", "SYSTEM_LOG", 0, 1),
NewMenu(20, "组织架构", "SYSTEM_ORGANIZATION", 0, 2),
NewMenu(21, "成员", "SYSTEM_ORGANIZATION_EMPLOYEE", 20, 1),
NewMenu(22, "部门", "SYSTEM_ORGANIZATION_DEPARTMENT", 20, 2),
NewMenu(22, "用户组", "SYSTEM_ORGANIZATION_GROUP", 20, 3),
NewMenu(30, "应用管理", "SYSTEM_APP-MANAGER", 0, 3),
NewMenu(31, "应用中心", "SYSTEM_APP-MANAGER_APP", 30, 1),
NewMenu(50, "企业设置", "SYSTEM_COMPANY-SETTING", 0, 5),
NewMenu(51, "企业信息", "SYSTEM_COMPANY-SETTING_INFO", 50, 1),
NewMenu(52, "管理员权限", "SYSTEM_COMPANY-SETTING_ADMIN-AUTH", 50, 2),
}
func NewMenu(id int64, name, code string, pid int64, sort int64) *SysMenu {
return &SysMenu{
Id: id,
Name: name,
Code: code,
ParentId: pid,
Sort: sort,
}
}