63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"cutego/modules/core/api/v1/request"
|
|
"cutego/modules/core/api/v1/response"
|
|
"cutego/modules/core/dao"
|
|
"cutego/modules/core/dataobject"
|
|
)
|
|
|
|
type MenuService struct {
|
|
menuDao dao.MenuDao
|
|
roleDao dao.RoleDao
|
|
}
|
|
|
|
// GetMenuTreeByUserId 根据用户ID查询菜单
|
|
func (s MenuService) GetMenuTreeByUserId(user *response.UserResponse) *[]dataobject.SysMenu {
|
|
var menuList *[]dataobject.SysMenu
|
|
// 判断是否是管理员
|
|
flag := dataobject.SysUser{}.IsAdmin(user.UserId)
|
|
if flag {
|
|
menuList = s.menuDao.GetMenuAll()
|
|
} else {
|
|
menuList = s.menuDao.GetMenuByUserId(user.UserId)
|
|
}
|
|
return menuList
|
|
}
|
|
|
|
// FindMenuListByRoleId 根据角色ID查询菜单树信息
|
|
func (s MenuService) FindMenuListByRoleId(id int64) *[]int64 {
|
|
role := s.roleDao.SelectRoleByRoleId(id)
|
|
return s.menuDao.SelectMenuByRoleId(id, role.MenuCheckStrictly)
|
|
}
|
|
|
|
// GetMenuList 获取菜单列表
|
|
func (s MenuService) FindMenuList(query request.MenuQuery, info *response.UserResponse) *[]dataobject.SysMenu {
|
|
if info.IsAdmin() {
|
|
return s.menuDao.SelectMenuList(query)
|
|
} else {
|
|
query.UserId = info.UserId
|
|
return s.menuDao.SelectMenuListByUserId(query)
|
|
}
|
|
}
|
|
|
|
// GetMenuByMenuId 根据菜单ID查询信息
|
|
func (s MenuService) GetMenuByMenuId(id int) *dataobject.SysMenu {
|
|
return s.menuDao.SelectMenuByMenuId(id)
|
|
}
|
|
|
|
// Save 添加菜单数据
|
|
func (s MenuService) Save(menu dataobject.SysMenu) int64 {
|
|
return s.menuDao.Insert(menu)
|
|
}
|
|
|
|
// Edit 修改菜单数据
|
|
func (s MenuService) Edit(menu dataobject.SysMenu) int64 {
|
|
return s.menuDao.Update(menu)
|
|
}
|
|
|
|
// Remove 删除菜单操作
|
|
func (s MenuService) Remove(id int) int64 {
|
|
return s.menuDao.Delete(id)
|
|
}
|