using langguanApi.Extensions; using langguanApi.Extensions.AutoDI; using langguanApi.Model.Dto.SystemConfigurationDto; using langguanApi.Model; using langguanApi.Model.Entity; using Mapster; using NPOI.SS.Formula.Functions; using System.Linq.Expressions; using System.Threading.Tasks; using System; using System.Collections.Generic; namespace langguanApi.Service { /// /// 角色服务 /// [ServiceInjection(InjectionType.Transient)] public class RoleService : BaseService { private readonly RoleMenuServie _roleMenuServie; public RoleService(IConfiguration config, RoleMenuServie roleMenuServie) : base(config, nameof(Role)) { _roleMenuServie = roleMenuServie; } /// /// 新增角色 /// /// /// public async Task Add(AddRoleDto role) { if (await base.Exist(filter => filter.RoleName == role.RoleName)) { return new ApiResult() { code = 1, msg = "角色名称已存在" }; } var entity = role.Adapt(); await base.CreateAsync(entity); return new ApiResult() { code = 0 }; } /// /// 获取角色及菜单 /// /// /// public async Task GetRoleAndMenu(string roleId) { var role = await base.GetAsync(roleId); if (role != null) { var menus = await _roleMenuServie.GetByRoleId(roleId); return new ApiResult() { code = 0, data = new { role, menus } }; } return new ApiResult() { code = 0 }; } /// /// 删除角色 /// /// /// public async Task Remove(IEnumerable ids) { if (ids.Any()) { foreach (var item in ids) { await base.RemoveAsync(item); } } return new ApiResult() { code = 0 }; } /// /// 更新角色 /// /// /// public async Task update(UpdateRoleDto role) { var entity = role.Adapt(); await base.UpdateAsync(entity.Id, entity); return new ApiResult() { code = 0 }; } /// /// 分页取数据 /// /// /// public async Task GetPage(reqpage input) { Expression> exp = filter => filter.IsDelete == false; if (!string.IsNullOrEmpty(input.key)) { exp = exp.And(filter => filter.RoleName.Contains(input.key)); } return await base.GetPager(new ReqPaing() { pageSize = input.pageSize, current = input.current }, exp); } #region 用户管理角色相关 /// /// 根据id获取角色信息 /// /// /// public async Task GetRoleById(string roleId) { return await base.GetAsync(roleId); } /// /// 根据Id,获取多个校色信息 /// /// /// public async Task> GetRoleListByIds(IEnumerable ids) { Expression> exp = filter => ids.Contains(filter.Id) && filter.IsDelete == false; var list = (await base.GetListWithExp(exp)).ToList(); return list; } #endregion } }