Files
mayfly-go/server/internal/sys/application/role.go

101 lines
2.5 KiB
Go
Raw Normal View History

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