Files
Yi.Admin/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/System/PostService.cs

57 lines
2.2 KiB
C#
Raw Normal View History

2023-12-11 09:55:12 +08:00
using SqlSugar;
using Volo.Abp.Application.Dtos;
using Yi.Framework.Ddd.Application;
using Yi.Framework.Rbac.Application.Contracts.Dtos.Post;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Entities;
2024-09-24 11:16:19 +08:00
using Yi.Framework.Rbac.Domain.Shared.Consts;
2023-12-11 09:55:12 +08:00
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Application.Services.System
2023-12-11 09:55:12 +08:00
{
/// <summary>
/// Post服务实现
/// </summary>
2024-09-24 11:16:19 +08:00
public class PostService : YiCrudAppService<PostAggregateRoot, PostGetOutputDto, PostGetListOutputDto, Guid,
PostGetListInputVo, PostCreateInputVo, PostUpdateInputVo>,
IPostService
2023-12-11 09:55:12 +08:00
{
2024-05-22 14:35:08 +08:00
private readonly ISqlSugarRepository<PostAggregateRoot, Guid> _repository;
2024-09-24 11:16:19 +08:00
2024-05-22 14:35:08 +08:00
public PostService(ISqlSugarRepository<PostAggregateRoot, Guid> repository) : base(repository)
2023-12-11 09:55:12 +08:00
{
_repository = repository;
}
public override async Task<PagedResultDto<PostGetListOutputDto>> GetListAsync(PostGetListInputVo input)
{
RefAsync<int> total = 0;
2024-09-24 11:16:19 +08:00
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.PostName),
x => x.PostName.Contains(input.PostName!))
.WhereIF(input.State is not null, x => x.State == input.State)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
2023-12-11 09:55:12 +08:00
return new PagedResultDto<PostGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
2024-09-24 11:16:19 +08:00
protected override async Task CheckCreateInputDtoAsync(PostCreateInputVo input)
{
var isExist =
await _repository.IsAnyAsync(x => x.PostCode == input.PostCode);
if (isExist)
{
throw new UserFriendlyException(PostConst.Exist);
}
}
protected override async Task CheckUpdateInputDtoAsync(PostAggregateRoot entity, PostUpdateInputVo input)
{
var isExist = await _repository._DbQueryable.Where(x => x.Id != entity.Id)
.AnyAsync(x => x.PostCode == input.PostCode);
if (isExist)
{
throw new UserFriendlyException(RoleConst.Exist);
}
}
2023-12-11 09:55:12 +08:00
}
2024-09-24 11:16:19 +08:00
}