cutego/modules/core/service/menu_service.go

63 lines
1.6 KiB
Go
Raw Permalink Normal View History

2022-03-01 13:50:13 +08:00
package service
import (
2023-01-18 15:40:27 +08:00
"cutego/modules/core/api/v1/request"
"cutego/modules/core/api/v1/response"
"cutego/modules/core/dao"
2023-01-18 16:00:50 +08:00
"cutego/modules/core/dataobject"
2022-03-01 13:50:13 +08:00
)
type MenuService struct {
2023-01-18 15:40:27 +08:00
menuDao dao.MenuDao
roleDao dao.RoleDao
2022-03-01 13:50:13 +08:00
}
// GetMenuTreeByUserId 根据用户ID查询菜单
2023-01-18 16:00:50 +08:00
func (s MenuService) GetMenuTreeByUserId(user *response.UserResponse) *[]dataobject.SysMenu {
var menuList *[]dataobject.SysMenu
2022-03-01 13:50:13 +08:00
// 判断是否是管理员
2023-01-18 16:00:50 +08:00
flag := dataobject.SysUser{}.IsAdmin(user.UserId)
2022-03-01 13:50:13 +08:00
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 获取菜单列表
2023-01-18 16:00:50 +08:00
func (s MenuService) FindMenuList(query request.MenuQuery, info *response.UserResponse) *[]dataobject.SysMenu {
2022-03-01 13:50:13 +08:00
if info.IsAdmin() {
return s.menuDao.SelectMenuList(query)
} else {
query.UserId = info.UserId
return s.menuDao.SelectMenuListByUserId(query)
}
}
// GetMenuByMenuId 根据菜单ID查询信息
2023-01-18 16:00:50 +08:00
func (s MenuService) GetMenuByMenuId(id int) *dataobject.SysMenu {
2022-03-01 13:50:13 +08:00
return s.menuDao.SelectMenuByMenuId(id)
}
// Save 添加菜单数据
2023-01-18 16:00:50 +08:00
func (s MenuService) Save(menu dataobject.SysMenu) int64 {
2022-03-01 13:50:13 +08:00
return s.menuDao.Insert(menu)
}
// Edit 修改菜单数据
2023-01-18 16:00:50 +08:00
func (s MenuService) Edit(menu dataobject.SysMenu) int64 {
2022-03-01 13:50:13 +08:00
return s.menuDao.Update(menu)
}
// Remove 删除菜单操作
func (s MenuService) Remove(id int) int64 {
return s.menuDao.Delete(id)
}