role.go
1.1 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
package role
import "time"
// 角色实体
type Role struct {
// dcc
Id int64 `json:"id"`
// 角色名称
RoleName string `json:"roleName"`
// 父级Id
ParentId int64 `json:"parentId"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
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.Id == 0 {
return nil
}
return role.Id
}
func (role *Role) Update(data map[string]interface{}) error {
if Id, ok := data["Id"]; ok {
role.Id = Id.(int64)
}
if RoleName, ok := data["RoleName"]; ok {
role.RoleName = RoleName.(string)
}
if ParentId, ok := data["ParentId"]; ok {
role.ParentId = ParentId.(int64)
}
if CreateTime, ok := data["CreateTime"]; ok {
role.CreateTime = CreateTime.(time.Time)
}
if UpdateTime, ok := data["UpdateTime"]; ok {
role.UpdateTime = UpdateTime.(time.Time)
}
return nil
}