permission.go
1.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
package domain
// 权限
type Permission struct {
// 权限id
PermissionId int `json:"permissionId"`
// 公司名称
Name string `json:"name"`
// 权限编码
Code string `json:"code"`
// 父级id
ParentId int `json:"parentId"`
// 排序
Sort int `json:"sort"`
// 图标
Icon string `json:"icon"`
}
type PermissionRepository interface {
Save(permission *Permission) (*Permission, error)
Remove(permission *Permission) (*Permission, error)
FindOne(queryOptions map[string]interface{}) (*Permission, error)
Find(queryOptions map[string]interface{}) (int64, []*Permission, error)
}
func (permission *Permission) Identify() interface{} {
if permission.PermissionId == 0 {
return nil
}
return permission.PermissionId
}
func (permission *Permission) Update(data map[string]interface{}) error {
if permissionId, ok := data["permissionId"]; ok {
permission.PermissionId = permissionId.(int)
}
if name, ok := data["name"]; ok {
permission.Name = name.(string)
}
if code, ok := data["code"]; ok {
permission.Code = code.(string)
}
if parentId, ok := data["parentId"]; ok {
permission.ParentId = parentId.(int)
}
if sort, ok := data["sort"]; ok {
permission.Sort = sort.(int)
}
if icon, ok := data["icon"]; ok {
permission.Icon = icon.(string)
}
return nil
}