You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB

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
{
/// <summary>
/// 角色对菜单的权限控制
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
[Authorize]
public class RoleMenuInfoAppService : ApplicationService
{
private readonly IRepository<RoleMenuInfo> _roleMenuInfoRepository;
private readonly IRepository<MenuInfo> _menuInfoRepository;
public RoleMenuInfoAppService(
IRepository<RoleMenuInfo> roleMenuInfoRepository,
IRepository<MenuInfo> menuInfoRepository)
{
this._roleMenuInfoRepository = roleMenuInfoRepository;
this._menuInfoRepository = menuInfoRepository;
}
/// <summary>
/// 获取角色对应的菜单选项
/// </summary>
/// <param name="RoleId">角色ID</param>
/// <returns></returns>
[HttpGet("api/app/rolemenuinfo/getrolemenuinfolist")]
public async Task<List<GetRoleMenuInfoIdsDto>> 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;
}
/// <summary>
/// 设置角色的菜单权限
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("api/app/rolemenuinfo/setrolemenuinfo")]
public async Task SetRoleMenuInfoAsync(SetRoleMenuInfoRequestDto input)
{
//删除原有配置
await _roleMenuInfoRepository.DeleteAsync(m => m.RoleId == input.RoleId);
List<RoleMenuInfo> roleMenuInfoList = new List<RoleMenuInfo>();
if (input.MenuInfoIds.Any())
{
//增加新配置
foreach (var item in input.MenuInfoIds)
{
roleMenuInfoList.Add(new RoleMenuInfo
{
RoleId = input.RoleId,
MenuInfoId = item
});
}
await _roleMenuInfoRepository.InsertManyAsync(roleMenuInfoList);
}
}
}
}