using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Ddd.Application;
using Yi.Framework.Rbac.Application.Contracts.Dtos.Menu;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Shared.Consts;
using Yi.Framework.Rbac.Domain.Shared.Dtos;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Application.Services.System
{
///
/// Menu服务实现
///
public class MenuService : YiCrudAppService,
IMenuService
{
private readonly ISqlSugarRepository _repository;
public MenuService(ISqlSugarRepository repository) : base(repository)
{
_repository = repository;
}
public override async Task> GetListAsync(MenuGetListInputVo input)
{
RefAsync total = 0;
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.MenuName), x => x.MenuName.Contains(input.MenuName!))
.WhereIF(input.State is not null, x => x.State == input.State)
.Where(x=>x.MenuSource==input.MenuSource)
.OrderByDescending(x => x.OrderNum)
.ToListAsync();
return new PagedResultDto(total, await MapToGetListOutputDtosAsync(entities));
}
///
/// 查询当前角色的菜单
///
///
///
public async Task> GetListRoleIdAsync(Guid roleId)
{
var entities = await _repository._DbQueryable.Where(m => SqlFunc.Subqueryable().Where(rm => rm.RoleId == roleId && rm.MenuId == m.Id).Any()).ToListAsync();
return await MapToGetListOutputDtosAsync(entities);
}
///
/// 获取所有菜单
///
///
///
[Route("menu/list")]
public async Task> GetAllListAsync(MenuGetListInputVo input)
{
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.MenuName), x => x.MenuName.Contains(input.MenuName!))
.WhereIF(input.State is not null, x => x.State == input.State)
.Where(x=>x.MenuSource==input.MenuSource)
.OrderByDescending(x => x.OrderNum)
.ToListAsync();
return await MapToGetListOutputDtosAsync(entities);
}
///
/// 获取菜单树
///
///
public async Task> GetTreeAsync()
{
var menuList = await _repository._DbQueryable.ToListAsync();
return menuList.TreeDtoBuild();
}
}
}