mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-20 16:36:37 +08:00
DDD 应用层完善
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public interface IHasTotalCount
|
||||
{
|
||||
long Total { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public interface IListResult<T>
|
||||
{
|
||||
IReadOnlyList<T> Items { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos.Abstract
|
||||
{
|
||||
public interface IPagedAllResultRequestDto
|
||||
{
|
||||
DateTime? StartTime { get; set; }
|
||||
DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public interface IPagedAndSortedResultRequestDto
|
||||
{
|
||||
int PageIndex { get; set; }
|
||||
int PageSize { get; set; }
|
||||
string? PageSort { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public interface IPagedResult<T> : IListResult<T>, IHasTotalCount
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
[Serializable]
|
||||
public class ListResultDto<T> : IListResult<T>
|
||||
{
|
||||
public IReadOnlyList<T> Items
|
||||
{
|
||||
get { return _items ?? (_items = new List<T>()); }
|
||||
set { _items = value; }
|
||||
}
|
||||
private IReadOnlyList<T> _items;
|
||||
|
||||
public ListResultDto()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ListResultDto(IReadOnlyList<T> items)
|
||||
{
|
||||
Items = items;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public class PagedAllResultRequestDto: PagedAndSortedResultRequestDto
|
||||
{
|
||||
public DateTime? StartTime { get; set; }
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public class PagedAndSortedResultRequestDto : IPagedAndSortedResultRequestDto
|
||||
{
|
||||
public int PageIndex { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public string? PageSort { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Dtos
|
||||
{
|
||||
public class PagedResultDto<T>:ListResultDto<T>, IPagedResult<T>
|
||||
{
|
||||
public long Total { get; set; }
|
||||
|
||||
public PagedResultDto()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PagedResultDto(long totalCount, IReadOnlyList<T> items)
|
||||
: base(items)
|
||||
{
|
||||
Total = totalCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@ namespace Yi.Framework.Ddd.Entities
|
||||
//
|
||||
// 摘要:
|
||||
// Returns an array of ordered keys for this entity.
|
||||
object[] GetKeys();
|
||||
|
||||
}
|
||||
public interface IEntity<TKey> : IEntity
|
||||
{
|
||||
//
|
||||
// 摘要:
|
||||
// Unique identifier for this entity.
|
||||
TKey Id { get; }
|
||||
TKey Id { get;}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Core.Enums;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
|
||||
namespace Yi.Framework.Ddd.Repositories
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
||||
//单查
|
||||
Task<T> GetByIdAsync(dynamic id);
|
||||
Task<T> GetSingleAsync(Expression<Func<T, bool>> whereExpression);
|
||||
Task<T> GetFirstAsync(Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> IsAnyAsync(Expression<Func<T, bool>> whereExpression);
|
||||
Task<int> CountAsync(Expression<Func<T, bool>> whereExpression);
|
||||
|
||||
//多查
|
||||
Task<List<T>> GetListAsync();
|
||||
Task<List<T>> GetListAsync(Expression<Func<T, bool>> whereExpression);
|
||||
|
||||
//分页查
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page);
|
||||
Task<List<T>> GetPageListAsync(Expression<Func<T, bool>> whereExpression, IPagedAndSortedResultRequestDto page, Expression<Func<T, object>>? orderByExpression = null, OrderByEnum orderByType = OrderByEnum.Asc);
|
||||
|
||||
//插入
|
||||
Task<bool> InsertAsync(T insertObj);
|
||||
Task<bool> InsertOrUpdateAsync(T data);
|
||||
Task<bool> InsertOrUpdateAsync(List<T> datas);
|
||||
Task<int> InsertReturnIdentityAsync(T insertObj);
|
||||
Task<long> InsertReturnBigIdentityAsync(T insertObj);
|
||||
Task<long> InsertReturnSnowflakeIdAsync(T insertObj);
|
||||
Task<T> InsertReturnEntityAsync(T insertObj);
|
||||
Task<bool> InsertRangeAsync(List<T> insertObjs);
|
||||
|
||||
//更新
|
||||
Task<bool> UpdateAsync(T updateObj);
|
||||
Task<bool> UpdateRangeAsync(List<T> updateObjs);
|
||||
Task<bool> UpdateAsync(Expression<Func<T, T>> columns, Expression<Func<T, bool>> whereExpression);
|
||||
|
||||
//删除
|
||||
Task<bool> DeleteAsync(T deleteObj);
|
||||
Task<bool> DeleteAsync(List<T> deleteObjs);
|
||||
Task<bool> DeleteAsync(Expression<Func<T, bool>> whereExpression);
|
||||
Task<bool> DeleteByIdAsync(dynamic id);
|
||||
Task<bool> DeleteByIdsAsync(dynamic[] ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface IApplicationService
|
||||
{
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface ICreateAppService<TEntityDto>
|
||||
: ICreateAppService<TEntityDto, TEntityDto>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICreateAppService<TGetOutputDto, in TCreateInput>
|
||||
: IApplicationService
|
||||
{
|
||||
Task<TGetOutputDto> CreateAsync(TCreateInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface ICreateUpdateAppService<TEntityDto, in TKey>
|
||||
: ICreateUpdateAppService<TEntityDto, TKey, TEntityDto, TEntityDto>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICreateUpdateAppService<TEntityDto, in TKey, in TCreateUpdateInput>
|
||||
: ICreateUpdateAppService<TEntityDto, TKey, TCreateUpdateInput, TCreateUpdateInput>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICreateUpdateAppService<TGetOutputDto, in TKey, in TCreateUpdateInput, in TUpdateInput>
|
||||
: ICreateAppService<TGetOutputDto, TCreateUpdateInput>,
|
||||
IUpdateAppService<TGetOutputDto, TKey, TUpdateInput>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
|
||||
public interface ICrudAppService<TEntityDto, in TKey>
|
||||
: ICrudAppService<TEntityDto, TKey, PagedAndSortedResultRequestDto>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICrudAppService<TEntityDto, in TKey, in TGetListInput>
|
||||
: ICrudAppService<TEntityDto, TKey, TGetListInput, TEntityDto>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICrudAppService<TEntityDto, in TKey, in TGetListInput, in TCreateInput>
|
||||
: ICrudAppService<TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICrudAppService<TEntityDto, in TKey, in TGetListInput, in TCreateInput, in TUpdateInput>
|
||||
: ICrudAppService<TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface ICrudAppService<TGetOutputDto, TGetListOutputDto, in TKey, in TGetListInput, in TCreateInput, in TUpdateInput>
|
||||
: IReadOnlyAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput>,
|
||||
ICreateUpdateAppService<TGetOutputDto, TKey, TCreateInput, TUpdateInput>,
|
||||
IDeleteAppService<TKey>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface IDeleteAppService<in TKey> : IApplicationService
|
||||
{
|
||||
Task DeleteAsync(TKey id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using Yi.Framework.Ddd.Entities;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface IReadOnlyAppService<TEntityDto, in TKey>
|
||||
: IReadOnlyAppService<TEntityDto, TEntityDto, TKey, PagedAndSortedResultRequestDto>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IReadOnlyAppService<TEntityDto, in TKey, in TGetListInput>
|
||||
: IReadOnlyAppService<TEntityDto, TEntityDto, TKey, TGetListInput>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IReadOnlyAppService<TGetOutputDto, TGetListOutputDto, in TKey, in TGetListInput>
|
||||
: IApplicationService
|
||||
{
|
||||
Task<TGetOutputDto> GetAsync(TKey id);
|
||||
|
||||
Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services.Abstract
|
||||
{
|
||||
public interface IUpdateAppService<TEntityDto, in TKey>
|
||||
: IUpdateAppService<TEntityDto, TKey, TEntityDto>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public interface IUpdateAppService<TGetOutputDto, in TKey, in TUpdateInput>
|
||||
: IApplicationService
|
||||
{
|
||||
Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -7,6 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace Yi.Framework.Ddd.Services
|
||||
{
|
||||
public abstract class ApplicationService
|
||||
{
|
||||
{
|
||||
public IMapper _mapper { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using Yi.Framework.Ddd.Entities;
|
||||
using Yi.Framework.Ddd.Services.Abstract;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services
|
||||
{
|
||||
|
||||
public abstract class CrudAppService<TEntity, TEntityDto, TKey>
|
||||
: CrudAppService<TEntity, TEntityDto, TKey, PagedAndSortedResultRequestDto>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TEntityDto : IEntityDto<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TGetListInput>
|
||||
: CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TEntityDto>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TEntityDto : IEntityDto<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput>
|
||||
: CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TCreateInput>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TEntityDto : IEntityDto<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||
: CrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TEntityDto : IEntityDto<TKey>
|
||||
{
|
||||
protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
|
||||
{
|
||||
return MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract class CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||
: ReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput>,
|
||||
ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput, TCreateInput, TUpdateInput>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TGetOutputDto : IEntityDto<TKey>
|
||||
where TGetListOutputDto : IEntityDto<TKey>
|
||||
|
||||
{
|
||||
|
||||
protected virtual Task<TEntity> MapToEntityAsync(TCreateInput createInput)
|
||||
{
|
||||
var entity = _mapper.Map<TEntity>(createInput);
|
||||
|
||||
//这里判断实体的T,给id赋值
|
||||
|
||||
//雪花id
|
||||
//if (entity is IEntity<long>)
|
||||
//{
|
||||
// //使用反射,暂时先使用sqlsuga的雪花id提供
|
||||
// entityWithLongId.Id = SqlSugar.SnowFlakeSingle.Instance.NextId();
|
||||
//}
|
||||
|
||||
|
||||
return Task.FromResult(entity);
|
||||
}
|
||||
protected virtual Task MapToEntityAsync(TUpdateInput updateInput, TEntity entity)
|
||||
{
|
||||
_mapper.Map(updateInput, entity);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TGetOutputDto> CreateAsync(TCreateInput input)
|
||||
{
|
||||
var entity = await MapToEntityAsync(input);
|
||||
|
||||
await _repository.InsertAsync(entity);
|
||||
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public async Task DeleteAsync(TKey id)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
await _repository.DeleteByIdAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 改
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public virtual async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
var entity = await _repository.GetByIdAsync(id);
|
||||
|
||||
await MapToEntityAsync(input, entity);
|
||||
await _repository.UpdateAsync(entity);
|
||||
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using Yi.Framework.Ddd.Entities;
|
||||
using Yi.Framework.Ddd.Repositories;
|
||||
using Yi.Framework.Ddd.Services.Abstract;
|
||||
|
||||
namespace Yi.Framework.Ddd.Services
|
||||
{
|
||||
|
||||
public abstract class ReadOnlyAppService<TEntity, TEntityDto, TKey>
|
||||
: ReadOnlyAppService<TEntity, TEntityDto, TEntityDto, TKey, PagedAndSortedResultRequestDto>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TEntityDto : IEntityDto<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class ReadOnlyAppService<TEntity, TEntityDto, TKey, TGetListInput>
|
||||
: ReadOnlyAppService<TEntity, TEntityDto, TEntityDto, TKey, TGetListInput>
|
||||
where TEntity : class, IEntity<TKey>
|
||||
where TEntityDto : IEntityDto<TKey>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public abstract class ReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TGetListInput> : ApplicationService,
|
||||
IReadOnlyAppService<TGetOutputDto, TGetListOutputDto, TKey, TGetListInput>
|
||||
where TEntity : class, IEntity
|
||||
{
|
||||
protected IRepository<TEntity> _repository { get; }
|
||||
|
||||
//Mapper
|
||||
protected virtual Task<TGetOutputDto> MapToGetOutputDtoAsync(TEntity entity)
|
||||
{
|
||||
return Task.FromResult(_mapper.Map<TEntity, TGetOutputDto>(entity));
|
||||
}
|
||||
protected virtual Task<List<TGetListOutputDto>> MapToGetListOutputDtosAsync(List<TEntity> entities)
|
||||
{
|
||||
var dtos = _mapper.Map<List<TGetListOutputDto>>(entities);
|
||||
|
||||
return Task.FromResult(dtos);
|
||||
}
|
||||
protected virtual Task<TGetListOutputDto> MapToGetListOutputDtoAsync(TEntity entity)
|
||||
{
|
||||
var dto = _mapper.Map<TEntity, TGetListOutputDto>(entity);
|
||||
return Task.FromResult(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单查
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public async Task<TGetOutputDto> GetAsync(TKey id)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
|
||||
var entity = await _repository.GetByIdAsync(id);
|
||||
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全查
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<PagedResultDto<TGetListOutputDto>> GetListAsync(TGetListInput input)
|
||||
{
|
||||
|
||||
var totalCount = await _repository.CountAsync(_ => true);
|
||||
|
||||
var entities = new List<TEntity>();
|
||||
var entityDtos = new List<TGetListOutputDto>();
|
||||
|
||||
if (totalCount > 0)
|
||||
{
|
||||
if (input is IPagedAndSortedResultRequestDto sortInput)
|
||||
{
|
||||
entities = await _repository.GetPageListAsync(_ => true, sortInput);
|
||||
}
|
||||
//这里还可以追加如果是审计日志,继续拼接条件即可
|
||||
else
|
||||
{
|
||||
entities = await _repository.GetListAsync();
|
||||
}
|
||||
entityDtos = await MapToGetListOutputDtosAsync(entities);
|
||||
}
|
||||
|
||||
return new PagedResultDto<TGetListOutputDto>(
|
||||
totalCount,
|
||||
entityDtos
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<DocumentationFile>./SwaggerDoc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Core.AutoMapper\Yi.Framework.Core.AutoMapper.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,10 +4,19 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<DocumentationFile>./YiFrameworkSwaggerDoc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Core.AutoMapper\Yi.Framework.Core.AutoMapper.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Core\Yi.Framework.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="YiFrameworkSwaggerDoc.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0"?>
|
||||
<doc>
|
||||
<assembly>
|
||||
<name>Yi.Framework.Ddd</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:Yi.Framework.Ddd.Services.CrudAppService`7.CreateAsync(`5)">
|
||||
<summary>
|
||||
增
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.Ddd.Services.CrudAppService`7.DeleteAsync(`3)">
|
||||
<summary>
|
||||
删
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
<exception cref="T:System.ArgumentNullException"></exception>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.Ddd.Services.CrudAppService`7.UpdateAsync(`3,`6)">
|
||||
<summary>
|
||||
改
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
<exception cref="T:System.ArgumentNullException"></exception>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.Ddd.Services.ReadOnlyAppService`5.GetAsync(`3)">
|
||||
<summary>
|
||||
单查
|
||||
</summary>
|
||||
<param name="id"></param>
|
||||
<returns></returns>
|
||||
<exception cref="T:System.ArgumentNullException"></exception>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.Ddd.Services.ReadOnlyAppService`5.GetListAsync(`4)">
|
||||
<summary>
|
||||
全查
|
||||
</summary>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
Reference in New Issue
Block a user