2023-01-30 18:14:44 +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-01-31 18:08:27 +08:00
|
|
|
using Yi.RBAC.Domain.Shared.Identity.ConstClasses;
|
|
|
|
|
using Yi.RBAC.Domain.Identity;
|
|
|
|
|
using Yi.Framework.Uow;
|
2023-01-31 20:09:54 +08:00
|
|
|
using Yi.Framework.Ddd.Dtos;
|
|
|
|
|
using Yi.RBAC.Domain.Identity.Repositories;
|
2023-01-30 18:14:44 +08:00
|
|
|
|
|
|
|
|
namespace Yi.RBAC.Application.Identity
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// User服务实现
|
|
|
|
|
/// </summary>
|
|
|
|
|
[AppService]
|
|
|
|
|
public class UserService : CrudAppService<UserEntity, UserGetOutputDto, UserGetListOutputDto, long, UserGetListInputVo, UserCreateInputVo, UserUpdateInputVo>,
|
|
|
|
|
IUserService, IAutoApiService
|
|
|
|
|
{
|
2023-01-31 18:08:27 +08:00
|
|
|
[Autowired]
|
|
|
|
|
private UserManager _userManager { get; set; }
|
|
|
|
|
|
|
|
|
|
[Autowired]
|
|
|
|
|
private IUnitOfWorkManager _unitOfWorkManager { get; set; }
|
2023-01-31 20:09:54 +08:00
|
|
|
|
|
|
|
|
[Autowired]
|
|
|
|
|
private IUserRepository _userRepository { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<PagedResultDto<UserGetListOutputDto>> GetListAsync(UserGetListInputVo input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await MapToEntityAsync(input);
|
2023-02-06 23:08:12 +08:00
|
|
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
|
|
var entities = await _DbQueryable.WhereIF(!string.IsNullOrEmpty(input.UserName), x => x.UserName.Contains(input.UserName!)).
|
|
|
|
|
WhereIF(input.Phone is not null, x => x.Phone.ToString()!.Contains(input.Phone.ToString()!)).
|
|
|
|
|
WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name!.Contains(input.Name!)).
|
|
|
|
|
WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime).ToPageListAsync(input.PageNum, input.PageSize, total);
|
|
|
|
|
|
2023-01-31 20:09:54 +08:00
|
|
|
var result = new PagedResultDto<UserGetListOutputDto>();
|
|
|
|
|
result.Items = await MapToGetListOutputDtosAsync(entities);
|
2023-02-06 23:08:12 +08:00
|
|
|
result.Total = total;
|
2023-01-31 20:09:54 +08:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-31 18:08:27 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="UserFriendlyException"></exception>
|
|
|
|
|
public async override Task<UserGetOutputDto> CreateAsync(UserCreateInputVo input)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(input.Password))
|
|
|
|
|
{
|
|
|
|
|
throw new UserFriendlyException(UserConst.添加失败_密码为空);
|
|
|
|
|
}
|
|
|
|
|
if (await _repository.IsAnyAsync(u => input.UserName.Equals(u.UserName)))
|
|
|
|
|
{
|
|
|
|
|
throw new UserFriendlyException(UserConst.添加失败_用户存在);
|
|
|
|
|
}
|
|
|
|
|
var entities = await MapToEntityAsync(input);
|
|
|
|
|
|
|
|
|
|
entities.BuildPassword();
|
|
|
|
|
|
|
|
|
|
using (var uow = _unitOfWorkManager.CreateContext())
|
|
|
|
|
{
|
|
|
|
|
var returnEntity = await _repository.InsertReturnEntityAsync(entities);
|
|
|
|
|
await _userManager.GiveUserSetRoleAsync(new List<long> { returnEntity.Id }, input.RoleIds);
|
|
|
|
|
await _userManager.GiveUserSetPostAsync(new List<long> { returnEntity.Id }, input.PostIds);
|
|
|
|
|
uow.Commit();
|
|
|
|
|
|
|
|
|
|
var result = await MapToGetOutputDtoAsync(returnEntity);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-30 18:14:44 +08:00
|
|
|
}
|
|
|
|
|
}
|