2023-01-31 18:08:27 +08:00
|
|
|
using Yi.RBAC.Application.Contracts.Identity;
|
|
|
|
|
using NET.AutoWebApi.Setting;
|
|
|
|
|
using Yi.RBAC.Application.Contracts.Identity.Dtos;
|
|
|
|
|
using Yi.RBAC.Domain.Identity.Entities;
|
|
|
|
|
using Yi.Framework.Ddd.Services;
|
2023-02-12 18:43:11 +08:00
|
|
|
using Yi.RBAC.Domain.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Yi.Framework.Uow;
|
2023-02-19 17:18:52 +08:00
|
|
|
using Yi.Framework.Ddd.Dtos;
|
|
|
|
|
using SqlSugar;
|
2023-01-31 18:08:27 +08:00
|
|
|
|
|
|
|
|
namespace Yi.RBAC.Application.Identity
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Role服务实现
|
|
|
|
|
/// </summary>
|
|
|
|
|
[AppService]
|
|
|
|
|
public class RoleService : CrudAppService<RoleEntity, RoleGetOutputDto, RoleGetListOutputDto, long, RoleGetListInputVo, RoleCreateInputVo, RoleUpdateInputVo>,
|
|
|
|
|
IRoleService, IAutoApiService
|
|
|
|
|
{
|
2023-02-12 18:43:11 +08:00
|
|
|
[Autowired]
|
|
|
|
|
private RoleManager _roleManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[Autowired]
|
|
|
|
|
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
|
|
|
|
|
|
2023-02-19 17:18:52 +08:00
|
|
|
|
|
|
|
|
public override async Task<PagedResultDto<RoleGetListOutputDto>> GetListAsync(RoleGetListInputVo input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await MapToEntityAsync(input);
|
|
|
|
|
|
|
|
|
|
RefAsync<int> total = 0;
|
|
|
|
|
|
|
|
|
|
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.RoleCode), x => x.RoleCode.Contains(input.RoleCode!))
|
|
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.RoleName), x => x.RoleName.Contains(input.RoleName!))
|
|
|
|
|
.WhereIF(input.State is not null, x => x.State == input.State)
|
|
|
|
|
.ToPageListAsync(input.PageNum, input.PageSize, total);
|
|
|
|
|
return new PagedResultDto<RoleGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 18:43:11 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<RoleGetOutputDto> CreateAsync(RoleCreateInputVo input)
|
|
|
|
|
{
|
|
|
|
|
RoleGetOutputDto outputDto;
|
|
|
|
|
using (var uow = _unitOfWorkManager.CreateContext())
|
|
|
|
|
{
|
|
|
|
|
var entity = await MapToEntityAsync(input);
|
|
|
|
|
await _repository.InsertAsync(entity);
|
|
|
|
|
outputDto = await MapToGetOutputDtoAsync(entity);
|
|
|
|
|
await _roleManager.GiveRoleSetMenuAsync(new List<long> { entity.Id }, input.MenuIds);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return outputDto;
|
|
|
|
|
}
|
2023-02-19 16:49:11 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改角色
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<RoleGetOutputDto> UpdateAsync(long id, RoleUpdateInputVo input)
|
|
|
|
|
{
|
|
|
|
|
var dto = new RoleGetOutputDto();
|
|
|
|
|
using (var uow = _unitOfWorkManager.CreateContext())
|
|
|
|
|
{
|
|
|
|
|
var entity = await _repository.GetByIdAsync(id);
|
|
|
|
|
await MapToEntityAsync(input, entity);
|
|
|
|
|
await _repository.UpdateAsync(entity);
|
|
|
|
|
|
|
|
|
|
await _roleManager.GiveRoleSetMenuAsync(new List<long> { id }, input.MenuIds);
|
|
|
|
|
|
|
|
|
|
dto = await MapToGetOutputDtoAsync(entity);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
}
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
2023-01-31 18:08:27 +08:00
|
|
|
}
|
|
|
|
|
}
|