| | |
| | | using AutoMapper; |
| | | using Model.ModelDto.SysDto; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Utility; |
| | | using WMS.Entity.Context; |
| | | using WMS.Entity.SysEntity; |
| | | using WMS.IBLL.ISysServer; |
| | | using WMS.IDAL.ISysInterface; |
| | |
| | | /// <summary> |
| | | /// 依赖注入 |
| | | /// </summary> |
| | | public IRolesRepository _roles { get; set; } |
| | | private readonly IMapper _mapper; |
| | | private static readonly SqlSugarScope Db = DataContext.Db; |
| | | private readonly UserManager _userManager; |
| | | /// <summary> |
| | | /// 构造函数 |
| | | /// </summary> |
| | | /// <param name="roles">角色</param> |
| | | /// <param name="mapper">automapper</param> |
| | | public RolesServer(IRolesRepository roles,IMapper mapper) |
| | | public RolesServer(IMapper mapper, UserManager userManager) |
| | | { |
| | | _roles = roles; //角色 |
| | | _mapper = mapper; //automapper |
| | | _userManager = userManager; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <param name="RoleNo">角色号</param> |
| | | /// <param name="RoleName">角色名称</param> |
| | | /// <returns></returns> |
| | | public List<RoleDto> GetRoleList(string RoleNo, string RoleName,string UserId) |
| | | public async Task<List<RoleDto>> GetRoleList(string RoleNo, string RoleName) |
| | | { |
| | | //获取角色信息 |
| | | List<RoleDto> rolelist = _roles.GetRoleList(RoleNo, RoleName, UserId); |
| | | //返回数据 |
| | | return rolelist; |
| | | var modUser = await Db.Queryable<SysUserInfor>().FirstAsync(s => s.Id == _userManager.UserId); |
| | | return await Db.Queryable<SysRoles>() |
| | | .LeftJoin<SysUserInfor>((a, b) => a.CreateUser == b.Id) |
| | | .LeftJoin<SysUserInfor>((a, b, c) => a.UpdateUser == c.Id) |
| | | .WhereIF(modUser.UserName.ToUpper() != "ADMIN", a => a.CreateUser == _userManager.UserId) |
| | | .WhereIF(!string.IsNullOrEmpty(RoleNo), a => a.RoleNo.Contains(RoleNo)) |
| | | .WhereIF(!string.IsNullOrEmpty(RoleName), a => a.RoleName.Contains(RoleName)) |
| | | .Where(a => a.IsDel == "0") |
| | | .Select<RoleDto>((a, b, c) => new RoleDto() |
| | | { |
| | | CreateUserName = b.RealName, |
| | | UpdateUserName = c.RealName |
| | | }, true) |
| | | .ToListAsync(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="RoleNo">角色编号</param> |
| | | /// <returns></returns> |
| | | public int GetRoleByNo(string RoleNo) |
| | | public async Task<int> GetRoleByNo(string RoleNo) |
| | | { |
| | | List<SysRoles> role = _roles.GetRoleByNo(RoleNo); |
| | | return role.Count; |
| | | return await Db.Queryable<SysRoles>().CountAsync(s => s.RoleNo == RoleNo && s.IsDel == "0"); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <exception cref="Exception">捕获异常</exception> |
| | | public async Task<int> InsertRoleInfo(RoleDto roledto) |
| | | { |
| | | //捕获异常 |
| | | try |
| | | { |
| | | //模型映射 |
| | | SysRoles roles = _mapper.Map<SysRoles>(roledto); |
| | | //判断角色号是否唯一 |
| | | int count = GetRoleByNo(roledto.RoleNo); |
| | | int i = 0; |
| | | int count = await GetRoleByNo(roledto.RoleNo); |
| | | if (count > 0) |
| | | { |
| | | i = 3; |
| | | throw Oops.Bah("角色号必须唯一"); |
| | | } |
| | | else if (count == 0) |
| | | { |
| | | //新增角色信息 |
| | | i = await _roles.InsertRoleInfo(roles); |
| | | } |
| | | |
| | | roles.CreateTime = DateTime.Now; |
| | | roles.CreateUser = _userManager.UserId; |
| | | var i = await Db.Insertable(roles).ExecuteCommandAsync(); |
| | | if (i <= 0) |
| | | throw Oops.Bah("新增角色数据信息失败"); |
| | | return i; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //抛出异常 |
| | | throw new Exception("角色信息新增异常", ex); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | /// <returns></returns> |
| | | public async Task<int> DeleteRoleInfo(SysRoles roles) |
| | | { |
| | | int i = await _roles.DeleteRoleInfo(roles); |
| | | return i; |
| | | return await Db.Updateable<SysRoles>() |
| | | .Where(s => s.Id == roles.Id) |
| | | .SetColumns(s => s.IsDel == "1") |
| | | .SetColumns(s => s.UpdateTime == DateTime.Now) |
| | | .SetColumns(s => s.UpdateUser == _userManager.UserId) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | } |
| | | |
| | |
| | | /// <returns></returns> |
| | | public async Task<int> UpdateRoleInfo(SysRoles role) |
| | | { |
| | | //修改 |
| | | int i = await _roles.UpdateRoleInfo(role); |
| | | int count = await Db.Queryable<SysRoles>().CountAsync(s => s.RoleNo == role.RoleNo && s.Id != role.Id && s.IsDel == "0"); |
| | | if (count > 0) |
| | | throw Oops.Bah("角色号必须唯一"); |
| | | role.UpdateTime = DateTime.Now; |
| | | role.UpdateUser = _userManager.UserId; |
| | | int i = await Db.Updateable(role) |
| | | .UpdateColumns(s => new { s.RoleNo, s.RoleName, s.Demo, s.UpdateUser, s.UpdateTime }) |
| | | .ExecuteCommandAsync(); |
| | | if (i <= 0) |
| | | throw Oops.Bah("修改角色数据信息失败"); |
| | | return i; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="roleids">角色id</param> |
| | | /// <returns></returns> |
| | | public SysRoles GetRoleInfoById(int roleids) |
| | | public async Task<SysRoles> GetRoleInfoById(int roleids) |
| | | { |
| | | SysRoles role= _roles.GetRoleInfoById(roleids); |
| | | return role; |
| | | return await Db.Queryable<SysRoles>().FirstAsync(s => s.Id == roleids && s.IsDel == "0"); |
| | | } |
| | | |
| | | } |