/
role.entity.go
55 lines (45 loc) · 1.38 KB
/
role.entity.go
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
package role
import (
"context"
"gorm.io/gorm"
"github.com/LyricTian/gin-admin/v8/internal/app/dao/util"
"github.com/LyricTian/gin-admin/v8/internal/app/schema"
"github.com/LyricTian/gin-admin/v8/pkg/util/structure"
)
// GetRoleDB 获取角色存储
func GetRoleDB(ctx context.Context, defDB *gorm.DB) *gorm.DB {
return util.GetDBWithModel(ctx, defDB, new(Role))
}
// SchemaRole 角色对象
type SchemaRole schema.Role
// ToRole 转换为角色实体
func (a SchemaRole) ToRole() *Role {
item := new(Role)
structure.Copy(a, item)
return item
}
// Role 角色实体
type Role struct {
util.Model
Name string `gorm:"size:100;index;default:'';not null;"` // 角色名称
Sequence int `gorm:"index;default:0;"` // 排序值
Memo *string `gorm:"size:1024;"` // 备注
Status int `gorm:"index;default:0;"` // 状态(1:启用 2:禁用)
Creator uint64 `gorm:""` // 创建者
}
// ToSchemaRole 转换为角色对象
func (a Role) ToSchemaRole() *schema.Role {
item := new(schema.Role)
structure.Copy(a, item)
return item
}
// Roles 角色实体列表
type Roles []*Role
// ToSchemaRoles 转换为角色对象列表
func (a Roles) ToSchemaRoles() []*schema.Role {
list := make([]*schema.Role, len(a))
for i, item := range a {
list[i] = item.ToSchemaRole()
}
return list
}