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
{
///
/// RBAC服务实践
///
public class RBACServer : IRBACServer
{
///
/// 依赖注入
///
public IRBACRepository _rbac { get; set; }
private readonly IMenuRepository _menu;
private readonly IRoleRightRepository _roleright;
///
/// 构造函数
///
///
///
///
public RBACServer(IRBACRepository rbac, IMenuRepository menu, IRoleRightRepository roleright)
{
_rbac = rbac;
_menu = menu;
_roleright = roleright;
}
///
/// 获取rbac信息列表
///
///
public async Task> GetRBACLists(int roleid)
{
List rbaclist = await _rbac.GetRBACLists(roleid);
return rbaclist;
}
///
/// 根据角色id获取对应菜单权限
///
///
///
public List GetRoleRightList(int id)
{
List roleRightDtos = _roleright.GetRoleRightListById(id);
return roleRightDtos;
}
///
/// 根据角色Id获取对应的菜单选中
///
///
///
public object GetMenuByroleIdNew(int id)
{
try
{
List rolerightlist = _roleright.GetRoleRightListById(id);
//var list = DataContext.WmsSysRight.Where(m => m.UserGroupId == id).ToList();
var str = new List();
foreach (var item in rolerightlist)
{
str.Add(item.MenuNo);
}
string sql1 = $"select * from SysFunctionMenu where IsDel = '0' and ParentNo = ''";
List 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 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 data = new List();
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 all, FunctionMenuDto curItem)
{
List childItems = all.Where(m => m.ParentId == curItem.MenuNo).ToList(); //得到子节点
curItem.children = childItems; //将子节点加入
//遍历子节点,进行递归,寻找子节点的子节点
foreach (var subItem in childItems)
{
FunNew(all, subItem);
}
}
///
/// 分配权限显示
///
///
///
///
public List GetRoleRightRBAC(string MenuNo, string UserId)
{
List menudto = _menu.GetMenuDtoList(MenuNo,UserId);
return menudto;
}
}
}