2021-06-07 17:22:07 +08:00
|
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2022-06-02 17:41:11 +08:00
|
|
|
|
"mayfly-go/internal/sys/domain/entity"
|
|
|
|
|
|
"mayfly-go/internal/sys/domain/repository"
|
2023-07-01 14:34:42 +08:00
|
|
|
|
"mayfly-go/pkg/gormx"
|
2022-06-02 17:41:11 +08:00
|
|
|
|
"mayfly-go/pkg/model"
|
2021-07-28 18:03:19 +08:00
|
|
|
|
"strings"
|
2021-06-07 17:22:07 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
type Role interface {
|
2023-07-01 14:34:42 +08:00
|
|
|
|
GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any]
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
|
|
|
|
|
SaveRole(role *entity.Role)
|
|
|
|
|
|
|
|
|
|
|
|
DeleteRole(id uint64)
|
|
|
|
|
|
|
|
|
|
|
|
GetRoleResourceIds(roleId uint64) []uint64
|
|
|
|
|
|
|
2023-06-01 12:31:32 +08:00
|
|
|
|
GetRoleResources(roleId uint64, toEntity any)
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
// 保存角色资源关联记录
|
2023-07-20 22:41:13 +08:00
|
|
|
|
SaveRoleResource(rr []*entity.RoleResource)
|
2021-06-07 17:22:07 +08:00
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
// 删除角色资源关联记录
|
2021-06-07 17:22:07 +08:00
|
|
|
|
DeleteRoleResource(roleId uint64, resourceId uint64)
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
// 获取账号角色id列表
|
2021-06-07 17:22:07 +08:00
|
|
|
|
GetAccountRoleIds(accountId uint64) []uint64
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
// 保存账号角色关联信息
|
2021-06-07 17:22:07 +08:00
|
|
|
|
SaveAccountRole(rr *entity.AccountRole)
|
|
|
|
|
|
|
|
|
|
|
|
DeleteAccountRole(accountId, roleId uint64)
|
|
|
|
|
|
|
2023-06-01 12:31:32 +08:00
|
|
|
|
GetAccountRoles(accountId uint64, toEntity any)
|
2021-06-07 17:22:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
|
func newRoleApp(roleRepo repository.Role) Role {
|
|
|
|
|
|
return &roleAppImpl{
|
|
|
|
|
|
roleRepo: roleRepo,
|
|
|
|
|
|
}
|
2021-06-07 17:22:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
|
type roleAppImpl struct {
|
|
|
|
|
|
roleRepo repository.Role
|
2021-06-07 17:22:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-01 14:34:42 +08:00
|
|
|
|
func (m *roleAppImpl) GetPageList(condition *entity.Role, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
return m.roleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) SaveRole(role *entity.Role) {
|
|
|
|
|
|
role.Code = strings.ToUpper(role.Code)
|
2021-06-07 17:22:07 +08:00
|
|
|
|
if role.Id != 0 {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
// code不可更改,防止误传
|
|
|
|
|
|
role.Code = ""
|
2023-07-01 14:34:42 +08:00
|
|
|
|
gormx.UpdateById(role)
|
2021-06-07 17:22:07 +08:00
|
|
|
|
} else {
|
2021-07-28 18:03:19 +08:00
|
|
|
|
role.Status = 1
|
2023-07-01 14:34:42 +08:00
|
|
|
|
gormx.Insert(role)
|
2021-06-07 17:22:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) DeleteRole(id uint64) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.Delete(id)
|
|
|
|
|
|
// 删除角色与资源的关联关系
|
2023-07-01 14:34:42 +08:00
|
|
|
|
gormx.DeleteByCondition(&entity.RoleResource{RoleId: id})
|
2021-06-07 17:22:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
return m.roleRepo.GetRoleResourceIds(roleId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-01 12:31:32 +08:00
|
|
|
|
func (m *roleAppImpl) GetRoleResources(roleId uint64, toEntity any) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.GetRoleResources(roleId, toEntity)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-07-20 22:41:13 +08:00
|
|
|
|
func (m *roleAppImpl) SaveRoleResource(rr []*entity.RoleResource) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.SaveRoleResource(rr)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) DeleteRoleResource(roleId uint64, resourceId uint64) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.DeleteRoleResource(roleId, resourceId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) GetAccountRoleIds(accountId uint64) []uint64 {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
return m.roleRepo.GetAccountRoleIds(accountId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) SaveAccountRole(rr *entity.AccountRole) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.SaveAccountRole(rr)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-28 18:03:19 +08:00
|
|
|
|
func (m *roleAppImpl) DeleteAccountRole(accountId, roleId uint64) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.DeleteAccountRole(accountId, roleId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-01 12:31:32 +08:00
|
|
|
|
func (m *roleAppImpl) GetAccountRoles(accountId uint64, toEntity any) {
|
2021-06-07 17:22:07 +08:00
|
|
|
|
m.roleRepo.GetAccountRoles(accountId, toEntity)
|
|
|
|
|
|
}
|