1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package service
- import (
- "iot_manager_service/app/system/dao"
- "iot_manager_service/util/common"
- )
- // 角色菜单管理服务
- var RoleMenuService = new(roleMenuService)
- type roleMenuService struct{}
- func (s *roleMenuService) UpdateRoleMenus(roleIds, menuIds []int64) error {
- roleMenu := &dao.RoleMenu{}
- err := roleMenu.DeleteRoleIds(roleIds)
- if err != nil {
- return err
- }
- var roleMenus []dao.RoleMenu
- for _, roleId := range roleIds {
- for _, menuId := range menuIds {
- roleMenus = append(roleMenus, dao.RoleMenu{
- MenuId: menuId,
- RoleId: roleId,
- })
- }
- }
- return roleMenu.BatchSave(roleMenus)
- }
- func (s *roleMenuService) GetMenuByRole(roleId int64) []dao.RoleMenu {
- roleMenu := &dao.RoleMenu{RoleId: roleId}
- if common.IsAdmin(roleId) {
- menus, err := roleMenu.GetAll()
- if err != nil {
- return nil
- }
- return menus
- } else {
- menus, err := roleMenu.GetMenusByRole()
- if err != nil {
- return nil
- }
- return menus
- }
- }
|