2024-05-28 16:00:38 +00:00
|
|
|
|
using langguanApi.Extensions.AutoDI;
|
|
|
|
|
|
using langguanApi.Model;
|
|
|
|
|
|
using langguanApi.Model.Entity;
|
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace langguanApi.Service
|
|
|
|
|
|
{
|
|
|
|
|
|
[ServiceInjection(InjectionType.Transient)]
|
|
|
|
|
|
public class RoleMenuServie : BaseService<RoleMenu>
|
|
|
|
|
|
{
|
|
|
|
|
|
public RoleMenuServie(IConfiguration config) : base(config, nameof(RoleMenu))
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据角色ID获取角色菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<List<RoleMenu>> GetByRoleId(string roleId)
|
|
|
|
|
|
{
|
|
|
|
|
|
Expression<Func<RoleMenu, bool>> exp = filter => filter.IsDelete == false && filter.RoleId == roleId;
|
|
|
|
|
|
return (await base.GetListWithExp(exp)).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 表中添加角色菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<ApiResult> AddRoleMenu(AddRoleMenuDTO input)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in input.MenuIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
await base.CreateAsync(new RoleMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
RoleId = input.RoleId,
|
|
|
|
|
|
MenuId = item
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return new ApiResult() { code = 0 };
|
|
|
|
|
|
}
|
2024-05-29 15:53:04 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除角色菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<ApiResult> RemoveByRoleId(string roleId)
|
2024-05-28 16:00:38 +00:00
|
|
|
|
{
|
2024-05-29 15:53:04 +00:00
|
|
|
|
Expression<Func<RoleMenu, bool>> exp = filter => filter.IsDelete == false && filter.RoleId == roleId;
|
|
|
|
|
|
await base.BatchRemoveAsync(exp);
|
|
|
|
|
|
return new ApiResult() { code = 0 };
|
2024-05-28 16:00:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新角色菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public async Task<ApiResult> UpdateRoleMenu(UpdateRoleMenuDTO input)
|
|
|
|
|
|
{
|
|
|
|
|
|
await base.BatchRemoveAsync(filter => filter.RoleId == input.RoleId);
|
|
|
|
|
|
foreach (var item in input.MenuIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
await base.CreateAsync(new RoleMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
RoleId = input.RoleId,
|
|
|
|
|
|
MenuId = item
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
return new ApiResult() { code = 0 };
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|