role.go
2.0 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
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
type Role struct {
Id int64 `json:"id"` // 角色ID
CompanyId int64 `json:"companyId"` // 公司ID
Name string `json:"name"` // 角色名称
Auths []int64 `json:"auths"` // 角色权限列表
Remark string `json:"remark"` // 备注
Users []User `json:"users"` // 绑定的用户
CreatedAt int64 `json:"createdAt,omitempty"`
UpdatedAt int64 `json:"updatedAt,omitempty"`
DeletedAt int64 `json:"deletedAt,omitempty"`
Version int `json:"version,omitempty"`
}
type RoleRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error)
Update(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Role, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Role, error)
}
func (m *Role) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
func (m *Role) GetAuth(id int64) *Auth {
for _, auth := range Auths {
if auth.Id == id {
return &auth
}
}
return nil
}
type Auth struct {
Id int64 `json:"id,omitempty"` // 菜单ID
ParentId int64 `json:"parentId"` // 父级ID
Name string `json:"name,omitempty"` // 菜单名称
Code string `json:"code,omitempty"` // 菜单编码
}
var Auths = []Auth{
NewAuth(1001, "邀请注册", "MINI_INVITE-REGISTRATION", 0),
NewAuth(1002, "帖子定性", "SYSTEM_POST-JUDGMENT", 0),
//NewAuth(1003, "圆桌判定", "SYSTEM_STUDENT-MANAGE", 0),
//NewAuth(1004, "圆桌运营", "SYSTEM_FEEDBACK-MANAGE", 0),
}
func NewAuth(id int64, name, code string, pid int64) Auth {
return Auth{
Id: id,
Name: name,
Code: code,
ParentId: pid,
}
}