采购订单添加物料功能

This commit is contained in:
陈淳
2023-01-05 19:21:48 +08:00
parent 7d578ce363
commit efbf799218
49 changed files with 518 additions and 191 deletions

View File

@@ -14,28 +14,18 @@ namespace Yi.Framework.Service.Base.Crud
: AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TEntityDto, TEntityDto>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateUpdateInput>
: AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateUpdateInput, TCreateUpdateInput>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateInput, TUpdateInput>
: AbstractKeyCrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TCreateInput, TUpdateInput>
public abstract class AbstractKeyCrudAppService<TEntity, TEntityDto, TKey, TCreateInputDto, TUpdateInputDto>
: AbstractKeyCrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TCreateInputDto, TUpdateInputDto>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
@@ -47,23 +37,20 @@ namespace Yi.Framework.Service.Base.Crud
}
}
public abstract class AbstractKeyCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
: AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey>,
ICrudAppService<TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
public abstract class AbstractKeyCrudAppService<TEntity, TGetOutputDto, TListOutputDto, TKey, TCreateInputDto, TUpdateInputDto>
: AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TListOutputDto, TKey>,
ICrudAppService<TGetOutputDto, TListOutputDto, TKey, TCreateInputDto, TUpdateInputDto>
where TEntity : class, IEntity, new()
{
protected AbstractKeyCrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
/// <summary>
/// 创建
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public virtual async Task<TGetOutputDto> CreateAsync(TCreateInput input)
public virtual async Task<TGetOutputDto> CreateAsync(TCreateInputDto input)
{
var entity = await MapToEntityAsync(input);
TryToSetTenantId(entity);
@@ -76,7 +63,7 @@ namespace Yi.Framework.Service.Base.Crud
}
public async virtual Task CreateAsync(IEnumerable<TCreateInput> dtos)
public async virtual Task CreateAsync(IEnumerable<TCreateInputDto> dtos)
{
var entity = await MapToEntitysAsync(dtos);
@@ -105,7 +92,7 @@ namespace Yi.Framework.Service.Base.Crud
/// <param name="id"></param>
/// <param name="dto"></param>
/// <returns></returns>
public virtual async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInput input)
public virtual async Task<TGetOutputDto> UpdateAsync(TKey id, TUpdateInputDto input)
{
var entity = await GetEntityByIdAsync(id);
@@ -123,31 +110,30 @@ namespace Yi.Framework.Service.Base.Crud
/// <param name="idEntity"></param>
/// <param name="dto"></param>
/// <returns></returns>
protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInputDto dto)
{
return Task.CompletedTask;
}
/// <summary>
/// 将 更新输入dto转化为实体的异步
/// 批量更新输入dto转化为实体的同步方法
/// </summary>
/// <param name="updateInput"></param>
/// <param name="entity"></param>
protected virtual Task MapToEntityAsync(TUpdateInput updateInput, TEntity entity)
/// <returns></returns>
protected virtual List<TEntity> MapToEntity(IEnumerable<TCreateInputDto> updateInput)
{
MapToEntity(updateInput, entity);
return Task.CompletedTask;
return ObjectMapper.Map<List<TEntity>>(updateInput);
}
/// <summary>
/// 将 批量更新输入dto转化为实体的异步
/// </summary>
/// <param name="updateInput"></param>
/// <param name="entity"></param>
protected virtual async Task<List<TEntity>> MapToEntitysAsync(IEnumerable<TCreateInput> updateInput)
protected virtual async Task<List<TEntity>> MapToEntitysAsync(IEnumerable<TCreateInputDto> updateInput)
{
List<TEntity> entitys = MapToEntitys(updateInput);
List<TEntity> entitys = MapToEntity(updateInput);
return await Task.FromResult(entitys);
}
@@ -156,28 +142,28 @@ namespace Yi.Framework.Service.Base.Crud
/// </summary>
/// <param name="updateInput"></param>
/// <param name="entity"></param>
protected virtual void MapToEntity(TUpdateInput updateInput, TEntity entity)
protected virtual void MapToEntity(TUpdateInputDto updateInput, TEntity entity)
{
ObjectMapper.Map(updateInput, entity);
}
/// <summary>
/// 批量更新输入dto转化为实体的同步方法
/// 将 更新输入dto转化为实体的异步
/// </summary>
/// <param name="updateInput"></param>
/// <returns></returns>
protected virtual List<TEntity> MapToEntitys(IEnumerable<TCreateInput> updateInput)
/// <param name="entity"></param>
protected virtual Task MapToEntityAsync(TUpdateInputDto updateInput, TEntity entity)
{
return ObjectMapper.Map<List<TEntity>>(updateInput);
MapToEntity(updateInput, entity);
return Task.CompletedTask;
}
/// <summary>
/// 创建dto 给 实体的转换的异步方法
/// </summary>
/// <param name="createInput"></param>
/// <returns></returns>
protected virtual Task<TEntity> MapToEntityAsync(TCreateInput createInput)
protected virtual Task<TEntity> MapToEntityAsync(TCreateInputDto createInput)
{
return Task.FromResult(MapToEntity(createInput));
}
@@ -187,9 +173,9 @@ namespace Yi.Framework.Service.Base.Crud
/// </summary>
/// <param name="createInput"></param>
/// <returns></returns>
protected virtual TEntity MapToEntity(TCreateInput createInput)
protected virtual TEntity MapToEntity(TCreateInputDto createInput)
{
var entity = ObjectMapper.Map<TCreateInput, TEntity>(createInput);
var entity = ObjectMapper.Map<TCreateInputDto, TEntity>(createInput);
SetIdForGuids(entity);
return entity;
}

View File

@@ -7,6 +7,9 @@ using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Exceptions;
using Yi.Framework.Interface.Base.Crud;
using Yi.Framework.Model.Base;
using Yi.Framework.Repository;
@@ -17,9 +20,6 @@ namespace Yi.Framework.Service.Base.Crud
: AbstractKeyReadOnlyAppService<TEntity, TEntityDto, TEntityDto, TKey>
where TEntity : class, IEntity, new()
{
protected AbstractKeyReadOnlyAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
@@ -27,13 +27,8 @@ namespace Yi.Framework.Service.Base.Crud
IReadOnlyAppService<TGetOutputDto, TGetListOutputDto, TKey>
where TEntity : class, IEntity, new()
{
public AbstractKeyReadOnlyAppService(IRepository<TEntity> repository, IMapper mapper) : base(mapper)
{
Repository = repository;
}
protected IRepository<TEntity> Repository { get; set; }
[Autowired]
public IRepository<TEntity> Repository { get; set; }
public async Task<List<TGetListOutputDto>> GetListAsync()
@@ -46,6 +41,10 @@ namespace Yi.Framework.Service.Base.Crud
public async Task<TGetOutputDto> GetByIdAsync(TKey id)
{
var entity = await GetEntityByIdAsync(id);
if (entity is null)
{
throw new UserFriendlyException($"主键:{id} 数据不存在",ResultCodeEnum.NotSuccess);
}
var entityDto = await MapToGetOutputDtoAsync(entity);
return entityDto;
@@ -92,6 +91,24 @@ namespace Yi.Framework.Service.Base.Crud
return dtos;
}
/// <summary>
/// 多个实体列表映射GetList输出dto列表的同步方法
/// </summary>
/// <param name="entities"></param>
/// <returns></returns>
protected virtual async Task<List<TGetListOutputDto>> MapToGetListOutputDtos(IEnumerable<TEntity> entities)
{
var dtos = new List<TGetListOutputDto>();
foreach (var entity in entities)
{
dtos.Add(await MapToGetListOutputDtoAsync(entity));
}
return dtos;
}
/// <summary>
/// 实体列表映射GetList输出dto的异步方法
/// </summary>

View File

@@ -1,16 +1,16 @@
using AutoMapper;
using AutoMapper.Internal.Mappers;
using Microsoft.Extensions.DependencyInjection;
using System;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Interface.Base.Crud;
namespace Yi.Framework.Service.Base.Crud
{
public class ApplicationService : IApplicationService
{
public ApplicationService(IMapper mapper)
{
ObjectMapper = mapper;
}
protected IMapper ObjectMapper { get; set; }
[Autowired]
public IServiceProvider ServiceProvider { get; set; }
protected IMapper ObjectMapper => ServiceProvider.GetRequiredService<IMapper>();
}
}

View File

@@ -14,28 +14,17 @@ namespace Yi.Framework.Service.Base.Crud
: CrudAppService<TEntity, TEntityDto, TKey, TEntityDto>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TCreateInput>
: CrudAppService<TEntity, TEntityDto, TKey, TCreateInput, TCreateInput>
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TCreateInputDto>
: CrudAppService<TEntity, TEntityDto, TKey, TCreateInputDto, TCreateInputDto>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
}
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TCreateInput, TUpdateInput>
: CrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TCreateInput, TUpdateInput>
public abstract class CrudAppService<TEntity, TEntityDto, TKey, TCreateInputDto, TUpdateInputDto>: CrudAppService<TEntity, TEntityDto, TEntityDto, TKey, TCreateInputDto, TUpdateInputDto>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override Task<TEntityDto> MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
@@ -47,14 +36,10 @@ namespace Yi.Framework.Service.Base.Crud
}
}
public abstract class CrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
: AbstractKeyCrudAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey, TCreateInput, TUpdateInput>
public abstract class CrudAppService<TEntity, TGetOutputDto, TListOutputDto, TKey, TCreateInputDto, TUpdateInputDto>
: AbstractKeyCrudAppService<TEntity, TGetOutputDto, TListOutputDto, TKey, TCreateInputDto, TUpdateInputDto>
where TEntity : class, IEntity<TKey>, new()
{
protected CrudAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override async Task DeleteByIdAsync(TKey id)
{
await DeleteAsync(new List<TKey> { id });
@@ -65,7 +50,7 @@ namespace Yi.Framework.Service.Base.Crud
return await Repository.GetByIdAsync(id);
}
protected override void MapToEntity(TUpdateInput updateInput, TEntity entity)
protected override void MapToEntity(TUpdateInputDto updateInput, TEntity entity)
{
if (updateInput is IEntityDto<TKey> entityDto)
{

View File

@@ -14,10 +14,6 @@ namespace Yi.Framework.Service.Base.Crud
: AbstractKeyReadOnlyAppService<TEntity, TGetOutputDto, TGetListOutputDto, TKey>
where TEntity : class, IEntity<TKey>, new()
{
protected ReadOnlyAppService(IRepository<TEntity> repository, IMapper mapper) : base(repository, mapper)
{
}
protected override async Task<TEntity> GetEntityByIdAsync(TKey id)
{
return await Repository.GetByIdAsync(id);