using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Model.ModelDto.SysDto;
|
using WMS.Entity;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.ISysServer;
|
using WMS.IDAL;
|
using WMS.IDAL.ISysInterface;
|
using Model.ModelVm.SysVm;
|
|
namespace WMS.BLL.SysServer
|
{
|
/// <summary>
|
/// RBAC服务实践
|
/// </summary>
|
public class RBACServer : IRBACServer
|
{
|
/// <summary>
|
/// 依赖注入
|
/// </summary>
|
public IRBACRepository _rbac { get; set; }
|
private readonly IMenuRepository _menu;
|
private readonly IRoleRightRepository _roleright;
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="rbac"></param>
|
/// <param name="menu"></param>
|
/// <param name="roleright"></param>
|
public RBACServer(IRBACRepository rbac, IMenuRepository menu, IRoleRightRepository roleright)
|
{
|
_rbac = rbac;
|
_menu = menu;
|
_roleright = roleright;
|
}
|
|
/// <summary>
|
/// 获取rbac信息列表
|
/// </summary>
|
/// <returns></returns>
|
public async Task<List<RBAC>> GetRBACLists(int roleid)
|
{
|
List<RBAC> rbaclist = await _rbac.GetRBACLists(roleid);
|
return rbaclist;
|
}
|
|
/// <summary>
|
/// 根据角色id获取对应菜单权限
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public List<RoleRightDto> GetRoleRightList(int id)
|
{
|
List<RoleRightDto> roleRightDtos = _roleright.GetRoleRightListById(id);
|
return roleRightDtos;
|
}
|
|
/// <summary>
|
/// 根据角色Id获取对应的菜单选中
|
/// </summary>
|
/// <param name="id"></param>
|
/// <returns></returns>
|
public object GetMenuByroleIdNew(int id)
|
{
|
try
|
{
|
List<RoleRightDto> rolerightlist = _roleright.GetRoleRightListById(id);
|
//var list = DataContext.WmsSysRight.Where(m => m.UserGroupId == id).ToList();
|
var str = new List<string>();
|
foreach (var item in rolerightlist)
|
{
|
str.Add(item.MenuNo);
|
}
|
string sql1 = $"select * from SysFunctionMenu where IsDel = '0' and ParentNo = ''";
|
List<FunctionMenuDto> parent = _menu.GetMenuList(sql1).OrderBy(m => m.MenuNo).Select(m => new FunctionMenuDto()
|
{
|
//Id = m.Id,
|
MenuNo = m.MenuNo,
|
ParentId = m.ParentNo,
|
title = m.MenuName,
|
//expand = str.Contains(m.Id),
|
@checked = str.Contains(m.MenuNo)
|
}).ToList();
|
|
string sql2 = $"select * from SysFunctionMenu where IsDel = '0' and ParentNo != ''";
|
List<FunctionMenuDto> child = _menu.GetMenuList(sql2).OrderBy(m => m.MenuNo).Select(m => new FunctionMenuDto()
|
{
|
//Id = m.Id,
|
MenuNo = m.MenuNo,
|
ParentId = m.ParentNo,
|
title = m.MenuName,
|
Expand = str.Contains(m.MenuNo),
|
@checked = str.Contains(m.MenuNo)
|
}).ToList();
|
|
List<FunctionMenuDto> data = new List<FunctionMenuDto>();
|
|
foreach (var item in parent)
|
{
|
data.Add(item);
|
FunNew(child, item);
|
}
|
return data;
|
|
}
|
catch (Exception ex)
|
{
|
throw new Exception("获取角色对应的菜单信息" + ex.Message);
|
}
|
}
|
public void FunNew(List<FunctionMenuDto> all, FunctionMenuDto curItem)
|
{
|
List<FunctionMenuDto> childItems = all.Where(m => m.ParentId == curItem.MenuNo).ToList(); //得到子节点
|
curItem.children = childItems; //将子节点加入
|
|
//遍历子节点,进行递归,寻找子节点的子节点
|
foreach (var subItem in childItems)
|
{
|
FunNew(all, subItem);
|
}
|
|
}
|
|
|
|
/// <summary>
|
/// 分配权限显示
|
/// </summary>
|
/// <param name="MenuNo"></param>
|
/// <param name="UserId"></param>
|
/// <returns></returns>
|
public List<FunctionMenuDto> GetRoleRightRBAC(string MenuNo, string UserId)
|
{
|
List<FunctionMenuDto> menudto = _menu.GetMenuDtoList(MenuNo,UserId);
|
|
return menudto;
|
}
|
}
|
}
|