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
|
{
|
/// <summary>
|
/// 角色权限服务实践
|
/// </summary>
|
public class RoleRightServer : IRoleRightServer
|
{
|
/// <summary>
|
/// 依赖注入
|
/// </summary>
|
public IRoleRightRepository _rolerights { get; set; }
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="roles"></param>
|
public RoleRightServer(IRoleRightRepository rolerights)
|
{
|
_rolerights = rolerights;
|
}
|
|
/// <summary>
|
/// 获取用户的菜单权限 ----csc
|
/// </summary>
|
/// <param name="userId">用户Id</param>
|
/// <returns></returns>
|
public List<RoleRightDto> GetRoleMenuList(int userId)
|
{
|
try
|
{
|
var user = _rolerights.GetRoleMenuList(userId);
|
return user;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取角色权限信息列表
|
/// 多表:角色权限、角色、菜单
|
/// </summary>
|
/// <returns></returns>
|
public List<RoleRightDto> GetRoleRightList()
|
{
|
List<RoleRightDto> roleRightDtos = _rolerights.GetRoleRightList();
|
return roleRightDtos;
|
}
|
|
/// <summary>
|
/// 根据id获取角色权限信息列表(单表)
|
/// </summary>
|
/// <param name="rolerightids">角色权限id</param>
|
/// <returns></returns>
|
public List<SysRoleRight> GetRoleRightOneListById(int id)
|
{
|
List<SysRoleRight> roleRights = _rolerights.GetRoleRightOneListById(id);
|
return roleRights;
|
}
|
|
/// <summary>
|
/// 根据角色号获取角色权限信息列表(单表)
|
/// </summary>
|
/// <param name="roleno">角色好</param>
|
/// <returns></returns>
|
public List<SysRoleRight> GetRoleRightOneListByNo(string roleno)
|
{
|
List<SysRoleRight> roleRights = _rolerights.GetRoleRightOneListByNo(roleno);
|
return roleRights;
|
}
|
|
/// <summary>
|
/// 新增角色权限信息
|
/// </summary>
|
/// <param name="MenuNo">菜单号</param>
|
/// <param name="RoleNo">角色号</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> InsertRoleRight(string MenuNo, string RoleNo, string userId)
|
{
|
//捕获异常
|
try
|
{
|
//将菜单号进行分割 存储数组中
|
var arr = MenuNo.Split(',');
|
int i = 0;
|
//查询该角色是否拥有权限
|
List<SysRoleRight> 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);
|
}
|
}
|
|
/// <summary>
|
/// 删除角色权限信息
|
/// </summary>
|
/// <param name="RoleNo">角色号</param>
|
/// <returns></returns>
|
/// <exception cref="Exception">捕获异常</exception>
|
public async Task<int> DeleteRoleRight(string RoleNo)
|
{
|
//捕获异常
|
try
|
{
|
//删除
|
int i = await _rolerights.DeleteRoleRight(RoleNo);
|
return i;
|
}
|
catch (Exception ex)
|
{
|
//抛出异常
|
throw new Exception("删除角色权限信息异常", ex);
|
}
|
}
|
}
|
}
|