using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shentun.Peis.Models; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; namespace Shentun.Peis.RoleMenuInfos { /// /// 角色对菜单的权限控制 /// [ApiExplorerSettings(GroupName = "Work")] [Authorize] public class RoleMenuInfoAppService : ApplicationService { private readonly IRepository _roleMenuInfoRepository; private readonly IRepository _menuInfoRepository; public RoleMenuInfoAppService( IRepository roleMenuInfoRepository, IRepository menuInfoRepository) { this._roleMenuInfoRepository = roleMenuInfoRepository; this._menuInfoRepository = menuInfoRepository; } /// /// 获取角色对应的菜单选项 /// /// 角色ID /// [HttpGet("api/app/rolemenuinfo/getrolemenuinfolist")] public async Task> GetRoleMenuInfoListAsync(Guid RoleId) { var query = from a in await _roleMenuInfoRepository.GetQueryableAsync() join b in await _menuInfoRepository.GetQueryableAsync() on a.MenuInfoId equals b.Id into bb from ab in bb.DefaultIfEmpty() where a.RoleId == RoleId orderby ab.DisplayOrder ascending select ab; var entlistdto = query.Select(s => new GetRoleMenuInfoIdsDto { DisplayName = s.DisplayName, MenuInfoId = s.Id, ParentId = s.ParentId }).ToList(); return entlistdto; } /// /// 设置角色的菜单权限 /// /// /// [HttpPost("api/app/rolemenuinfo/setrolemenuinfo")] public async Task SetRoleMenuInfoAsync(SetRoleMenuInfoRequestDto input) { //删除原有配置 await _roleMenuInfoRepository.DeleteAsync(m => m.RoleId == input.RoleId); List roleMenuInfoList = new List(); if (input.MenuInfoIds.Any()) { //增加新配置 foreach (var item in input.MenuInfoIds) { roleMenuInfoList.Add(new RoleMenuInfo { RoleId = input.RoleId, MenuInfoId = item }); } await _roleMenuInfoRepository.InsertManyAsync(roleMenuInfoList); } } } }