feat: 优化rbac结构

This commit is contained in:
chenchun
2024-09-24 11:16:19 +08:00
parent 6359696bde
commit fd0edd93ea
23 changed files with 263 additions and 256 deletions

View File

@@ -5,6 +5,7 @@ using Yi.Framework.Ddd.Application;
using Yi.Framework.Rbac.Application.Contracts.Dtos.Config;
using Yi.Framework.Rbac.Application.Contracts.IServices;
using Yi.Framework.Rbac.Domain.Entities;
using Yi.Framework.Rbac.Domain.Shared.Consts;
using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.Rbac.Application.Services
@@ -12,10 +13,12 @@ namespace Yi.Framework.Rbac.Application.Services
/// <summary>
/// Config服务实现
/// </summary>
public class ConfigService : YiCrudAppService<ConfigAggregateRoot, ConfigGetOutputDto, ConfigGetListOutputDto, Guid, ConfigGetListInputVo, ConfigCreateInputVo, ConfigUpdateInputVo>,
IConfigService
public class ConfigService : YiCrudAppService<ConfigAggregateRoot, ConfigGetOutputDto, ConfigGetListOutputDto, Guid,
ConfigGetListInputVo, ConfigCreateInputVo, ConfigUpdateInputVo>,
IConfigService
{
private ISqlSugarRepository<ConfigAggregateRoot, Guid> _repository;
public ConfigService(ISqlSugarRepository<ConfigAggregateRoot, Guid> repository) : base(repository)
{
_repository = repository;
@@ -30,11 +33,33 @@ namespace Yi.Framework.Rbac.Application.Services
{
RefAsync<int> total = 0;
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.ConfigKey), x => x.ConfigKey.Contains(input.ConfigKey!))
.WhereIF(!string.IsNullOrEmpty(input.ConfigName), x => x.ConfigName!.Contains(input.ConfigName!))
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.ConfigKey),
x => x.ConfigKey.Contains(input.ConfigKey!))
.WhereIF(!string.IsNullOrEmpty(input.ConfigName), x => x.ConfigName!.Contains(input.ConfigName!))
.WhereIF(input.StartTime is not null && input.EndTime is not null,
x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
return new PagedResultDto<ConfigGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
}
protected override async Task CheckCreateInputDtoAsync(ConfigCreateInputVo input)
{
var isExist =
await _repository.IsAnyAsync(x => x.ConfigKey == input.ConfigKey);
if (isExist)
{
throw new UserFriendlyException(ConfigConst.Exist);
}
}
protected override async Task CheckUpdateInputDtoAsync(ConfigAggregateRoot entity, ConfigUpdateInputVo input)
{
var isExist = await _repository._DbQueryable.Where(x => x.Id != entity.Id)
.AnyAsync(x => x.ConfigKey == input.ConfigKey);
if (isExist)
{
throw new UserFriendlyException(ConfigConst.Exist);
}
}
}
}
}