|
@@ -2,7 +2,7 @@ package system
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
- "server/dao"
|
|
|
+ "server/dao/system"
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
"server/model/common/request"
|
|
@@ -18,11 +18,11 @@ type MenuService struct{}
|
|
|
|
|
|
var MenuServiceApp = new(MenuService)
|
|
|
|
|
|
-func (menuService *MenuService) getMenuTreeMap(authorityId uint) (treeMap map[uint][]dao.SysMenu, err error) {
|
|
|
- var allMenus []dao.SysMenu
|
|
|
- treeMap = make(map[uint][]dao.SysMenu)
|
|
|
+func (menuService *MenuService) getMenuTreeMap(authorityId uint) (treeMap map[uint][]system.SysMenu, err error) {
|
|
|
+ var allMenus []system.SysMenu
|
|
|
+ treeMap = make(map[uint][]system.SysMenu)
|
|
|
|
|
|
- SysAuthorityMenus, err := dao.QueryAuthorityMenuByAuthorityId(authorityId)
|
|
|
+ SysAuthorityMenus, err := system.QueryAuthorityMenuByAuthorityId(authorityId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -33,13 +33,13 @@ func (menuService *MenuService) getMenuTreeMap(authorityId uint) (treeMap map[ui
|
|
|
MenuIds = append(MenuIds, SysAuthorityMenus[i].MenuId)
|
|
|
}
|
|
|
|
|
|
- baseMenu, err := dao.QueryBaseMenuAndParametersByMenuId(MenuIds)
|
|
|
+ baseMenu, err := system.QueryBaseMenuAndParametersByMenuId(MenuIds)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
for i := range baseMenu {
|
|
|
- allMenus = append(allMenus, dao.SysMenu{
|
|
|
+ allMenus = append(allMenus, system.SysMenu{
|
|
|
SysBaseMenu: baseMenu[i],
|
|
|
AuthorityId: authorityId,
|
|
|
MenuId: baseMenu[i].ID,
|
|
@@ -47,7 +47,7 @@ func (menuService *MenuService) getMenuTreeMap(authorityId uint) (treeMap map[ui
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- btns, err := dao.QueryAuthorityBtnAndSysBaseMenuBtnById(authorityId)
|
|
|
+ btns, err := system.QueryAuthorityBtnAndSysBaseMenuBtnById(authorityId)
|
|
|
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -72,7 +72,7 @@ func (menuService *MenuService) getMenuTreeMap(authorityId uint) (treeMap map[ui
|
|
|
//@param: authorityId string
|
|
|
//@return: menus []system.SysMenu, err error
|
|
|
|
|
|
-func (menuService *MenuService) GetMenuTree(authorityId uint) (menus []dao.SysMenu, err error) {
|
|
|
+func (menuService *MenuService) GetMenuTree(authorityId uint) (menus []system.SysMenu, err error) {
|
|
|
menuTree, err := menuService.getMenuTreeMap(authorityId)
|
|
|
menus = menuTree[0]
|
|
|
for i := 0; i < len(menus); i++ {
|
|
@@ -87,7 +87,7 @@ func (menuService *MenuService) GetMenuTree(authorityId uint) (menus []dao.SysMe
|
|
|
//@param: menu *model.SysMenu, treeMap map[string][]model.SysMenu
|
|
|
//@return: err error
|
|
|
|
|
|
-func (menuService *MenuService) getChildrenList(menu *dao.SysMenu, treeMap map[uint][]dao.SysMenu) (err error) {
|
|
|
+func (menuService *MenuService) getChildrenList(menu *system.SysMenu, treeMap map[uint][]system.SysMenu) (err error) {
|
|
|
menu.Children = treeMap[menu.MenuId]
|
|
|
for i := 0; i < len(menu.Children); i++ {
|
|
|
err = menuService.getChildrenList(&menu.Children[i], treeMap)
|
|
@@ -101,7 +101,7 @@ func (menuService *MenuService) getChildrenList(menu *dao.SysMenu, treeMap map[u
|
|
|
//@return: list interface{}, total int64,err error
|
|
|
|
|
|
func (menuService *MenuService) GetInfoList() (list interface{}, total int64, err error) {
|
|
|
- var menuList []dao.SysBaseMenu
|
|
|
+ var menuList []system.SysBaseMenu
|
|
|
treeMap, err := menuService.getBaseMenuTreeMap()
|
|
|
menuList = treeMap[0]
|
|
|
for i := 0; i < len(menuList); i++ {
|
|
@@ -116,7 +116,7 @@ func (menuService *MenuService) GetInfoList() (list interface{}, total int64, er
|
|
|
//@param: menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu
|
|
|
//@return: err error
|
|
|
|
|
|
-func (menuService *MenuService) getBaseChildrenList(menu *dao.SysBaseMenu, treeMap map[uint][]dao.SysBaseMenu) (err error) {
|
|
|
+func (menuService *MenuService) getBaseChildrenList(menu *system.SysBaseMenu, treeMap map[uint][]system.SysBaseMenu) (err error) {
|
|
|
menu.Children = treeMap[menu.ID]
|
|
|
for i := 0; i < len(menu.Children); i++ {
|
|
|
err = menuService.getBaseChildrenList(&menu.Children[i], treeMap)
|
|
@@ -130,8 +130,8 @@ func (menuService *MenuService) getBaseChildrenList(menu *dao.SysBaseMenu, treeM
|
|
|
//@param: menu model.SysBaseMenu
|
|
|
//@return: error
|
|
|
|
|
|
-func (menuService *MenuService) AddBaseMenu(menu dao.SysBaseMenu) error {
|
|
|
- _, err := dao.QueryBaseMenuByName(menu.Name)
|
|
|
+func (menuService *MenuService) AddBaseMenu(menu system.SysBaseMenu) error {
|
|
|
+ _, err := system.QueryBaseMenuByName(menu.Name)
|
|
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
return errors.New("存在重复name,请修改name")
|
|
|
}
|
|
@@ -143,9 +143,9 @@ func (menuService *MenuService) AddBaseMenu(menu dao.SysBaseMenu) error {
|
|
|
//@description: 获取路由总树map
|
|
|
//@return: treeMap map[string][]system.SysBaseMenu, err error
|
|
|
|
|
|
-func (menuService *MenuService) getBaseMenuTreeMap() (treeMap map[uint][]dao.SysBaseMenu, err error) {
|
|
|
- treeMap = make(map[uint][]dao.SysBaseMenu)
|
|
|
- allMenus, err := dao.QueryBaseMenuAndMenuBtnAndParameters()
|
|
|
+func (menuService *MenuService) getBaseMenuTreeMap() (treeMap map[uint][]system.SysBaseMenu, err error) {
|
|
|
+ treeMap = make(map[uint][]system.SysBaseMenu)
|
|
|
+ allMenus, err := system.QueryBaseMenuAndMenuBtnAndParameters()
|
|
|
for _, v := range allMenus {
|
|
|
treeMap[v.ParentId] = append(treeMap[v.ParentId], v)
|
|
|
}
|
|
@@ -157,7 +157,7 @@ func (menuService *MenuService) getBaseMenuTreeMap() (treeMap map[uint][]dao.Sys
|
|
|
//@description: 获取基础路由树
|
|
|
//@return: menus []system.SysBaseMenu, err error
|
|
|
|
|
|
-func (menuService *MenuService) GetBaseMenuTree() (menus []dao.SysBaseMenu, err error) {
|
|
|
+func (menuService *MenuService) GetBaseMenuTree() (menus []system.SysBaseMenu, err error) {
|
|
|
treeMap, err := menuService.getBaseMenuTreeMap()
|
|
|
menus = treeMap[0]
|
|
|
for i := 0; i < len(menus); i++ {
|
|
@@ -172,8 +172,8 @@ func (menuService *MenuService) GetBaseMenuTree() (menus []dao.SysBaseMenu, err
|
|
|
//@param: menus []model.SysBaseMenu, authorityId string
|
|
|
//@return: err error
|
|
|
|
|
|
-func (menuService *MenuService) AddMenuAuthority(menus []dao.SysBaseMenu, authorityId uint) (err error) {
|
|
|
- var auth dao.SysAuthority
|
|
|
+func (menuService *MenuService) AddMenuAuthority(menus []system.SysBaseMenu, authorityId uint) (err error) {
|
|
|
+ var auth system.SysAuthority
|
|
|
auth.AuthorityId = authorityId
|
|
|
auth.SysBaseMenus = menus
|
|
|
err = AuthorityServiceApp.SetMenuAuthority(&auth)
|
|
@@ -186,8 +186,8 @@ func (menuService *MenuService) AddMenuAuthority(menus []dao.SysBaseMenu, author
|
|
|
//@param: info *request.GetAuthorityId
|
|
|
//@return: menus []system.SysMenu, err error
|
|
|
|
|
|
-func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (menus []dao.SysMenu, err error) {
|
|
|
- SysAuthorityMenus, err := dao.QueryAuthorityMenuByAuthorityId(info.AuthorityId)
|
|
|
+func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (menus []system.SysMenu, err error) {
|
|
|
+ SysAuthorityMenus, err := system.QueryAuthorityMenuByAuthorityId(info.AuthorityId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
@@ -198,10 +198,10 @@ func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (
|
|
|
MenuIds = append(MenuIds, SysAuthorityMenus[i].MenuId)
|
|
|
}
|
|
|
|
|
|
- baseMenu, err := dao.QueryBaseMenuAndParametersByMenuId(MenuIds)
|
|
|
+ baseMenu, err := system.QueryBaseMenuAndParametersByMenuId(MenuIds)
|
|
|
|
|
|
for i := range baseMenu {
|
|
|
- menus = append(menus, dao.SysMenu{
|
|
|
+ menus = append(menus, system.SysMenu{
|
|
|
SysBaseMenu: baseMenu[i],
|
|
|
AuthorityId: info.AuthorityId,
|
|
|
MenuId: baseMenu[i].ID,
|
|
@@ -214,13 +214,13 @@ func (menuService *MenuService) GetMenuAuthority(info *request.GetAuthorityId) (
|
|
|
// UserAuthorityDefaultRouter 用户角色默认路由检查
|
|
|
//
|
|
|
// Author [SliverHorn](https://github.com/SliverHorn)
|
|
|
-func (menuService *MenuService) UserAuthorityDefaultRouter(user *dao.SysUser) {
|
|
|
- menuIds, err := dao.QuerySysBaseMenuIdById(user.AuthorityId)
|
|
|
+func (menuService *MenuService) UserAuthorityDefaultRouter(user *system.SysUser) {
|
|
|
+ menuIds, err := system.QuerySysBaseMenuIdById(user.AuthorityId)
|
|
|
if err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- _, err = dao.QueryBaseMenuByIdAndDefaultRouter(user.Authority.DefaultRouter, menuIds)
|
|
|
+ _, err = system.QueryBaseMenuByIdAndDefaultRouter(user.Authority.DefaultRouter, menuIds)
|
|
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
user.Authority.DefaultRouter = "404"
|