using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Text; using System.Threading.Tasks; using AutoMapper; using Model.ModelDto.SysDto; using Model.ModelVm.SysVm; using WMS.DAL.SystemService; using WMS.Entity.SysEntity; using WMS.IBLL.ISysServer; using WMS.IDAL.ISysInterface; namespace WMS.BLL.SysServer { /// /// 角色权限服务实践 /// public class RoleRightServer : IRoleRightServer { /// /// 依赖注入 /// public IRoleRightRepository _rolerights { get; set; } /// /// 构造函数 /// /// public RoleRightServer(IRoleRightRepository rolerights) { _rolerights = rolerights; } /// /// 获取用户的菜单权限 ----csc /// /// 用户Id /// public List GetRoleMenuList(int userId) { try { var user = _rolerights.GetRoleMenuList(userId); return user; } catch (Exception e) { throw new Exception(e.Message); } } /// /// 获取角色权限信息列表 /// 多表:角色权限、角色、菜单 /// /// public List GetRoleRightList() { List roleRightDtos = _rolerights.GetRoleRightList(); return roleRightDtos; } /// /// 根据id获取角色权限信息列表(单表) /// /// 角色权限id /// public List GetRoleRightOneListById(int id) { List roleRights = _rolerights.GetRoleRightOneListById(id); return roleRights; } /// /// 根据角色号获取角色权限信息列表(单表) /// /// 角色好 /// public List GetRoleRightOneListByNo(string roleno) { List roleRights = _rolerights.GetRoleRightOneListByNo(roleno); return roleRights; } /// /// 新增角色权限信息 /// /// 菜单号 /// 角色号 /// /// 捕获异常 public async Task InsertRoleRight(string MenuNo, string RoleNo, string userId) { //捕获异常 try { //将菜单号进行分割 存储数组中 var arr = MenuNo.Split(','); int i = 0; //查询该角色是否拥有权限 List rolelist = GetRoleRightOneListByNo(RoleNo); //有 if (rolelist.Count > 0) { //删除该角色所有菜单信息 i = await DeleteRoleRight(RoleNo); } //无 else if (rolelist.Count == 0) { i = 1; } //开始新增权限 if (i > 0) { SysRoleRight roleright = new SysRoleRight(); //循环将菜单数组分别加入到数据模型中 for (int j = 0; j < arr.Count(); j++) { roleright.RoleNo = RoleNo;//角色号 roleright.MenuNo = arr[j];//菜单号 roleright.CreateUser = Convert.ToInt32(userId);//创建人 //成功 将菜单号和角色号新增为新的数据 i = await _rolerights.InsertRoleRight(roleright); } //返回 return i; } else { return i; } } catch (Exception ex) { //抛出异常 throw new Exception("新增角色权限信息异常", ex); } } /// /// 删除角色权限信息 /// /// 角色号 /// /// 捕获异常 public async Task DeleteRoleRight(string RoleNo) { //捕获异常 try { //删除 int i = await _rolerights.DeleteRoleRight(RoleNo); return i; } catch (Exception ex) { //抛出异常 throw new Exception("删除角色权限信息异常", ex); } } } }