采购订单添加物料功能
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class MaterialService : CrudAppService<MaterialEntity, MaterialGetListOutput, long, MaterialCreateUpdateInput>, IMaterialService
|
||||
{
|
||||
public MaterialService(IRepository<MaterialEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
public async Task<PageModel<List<MaterialGetListOutput>>> PageListAsync(MaterialCreateUpdateInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
|
||||
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class PurchaseDetailsService : CrudAppService<PurchaseDetailsEntity, PurchaseDetailsGetListOutput, long, PurchaseDetailsCreateUpdateInput>, IPurchaseDetailsService
|
||||
{
|
||||
public PurchaseDetailsService(IRepository<PurchaseDetailsEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
public async Task<PageModel<List<PurchaseDetailsGetListOutput>>> PageListAsync(PurchaseDetailsCreateUpdateInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
|
||||
@@ -5,9 +5,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Attribute;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DtoModel.ERP.Purchase;
|
||||
using Yi.Framework.Interface.ERP;
|
||||
using Yi.Framework.Model.Base;
|
||||
using Yi.Framework.Model.ERP.Entitys;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service.Base.Crud;
|
||||
@@ -16,10 +18,10 @@ namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class PurchaseService : CrudAppService<PurchaseEntity, PurchaseGetListOutput, long, PurchaseCreateInput, PurchaseUpdateInput>, IPurchaseService
|
||||
{
|
||||
private readonly ISugarUnitOfWork<UnitOfWork> _unitOfWork;
|
||||
private ISugarUnitOfWork<UnitOfWork> _unitOfWork;
|
||||
private readonly IPurchaseDetailsService _purchaseDetailsService;
|
||||
public PurchaseService(IRepository<PurchaseEntity> repository, IMapper mapper, ISugarUnitOfWork<UnitOfWork> unitOfWork,
|
||||
IPurchaseDetailsService purchaseDetailsService) : base(repository, mapper)
|
||||
public PurchaseService(ISugarUnitOfWork<UnitOfWork> unitOfWork,
|
||||
IPurchaseDetailsService purchaseDetailsService)
|
||||
{
|
||||
_unitOfWork = unitOfWork;
|
||||
_purchaseDetailsService = purchaseDetailsService;
|
||||
@@ -36,20 +38,20 @@ namespace Yi.Framework.Service.ERP
|
||||
|
||||
public override async Task<PurchaseGetListOutput> CreateAsync(PurchaseCreateInput input)
|
||||
{
|
||||
|
||||
PurchaseEntity entity = null;
|
||||
using (var uow = _unitOfWork.CreateContext())
|
||||
{
|
||||
var entity = await MapToEntityAsync(input);
|
||||
entity = await MapToEntityAsync(input);
|
||||
entity.PaidMoney = 0;
|
||||
entity.TotalMoney = input.PurchaseDetails.Sum(u => u.UnitPrice * u.TotalNumber);
|
||||
entity.PurchaseState = PurchaseStateEnum.Build;
|
||||
TryToSetTenantId(entity);
|
||||
var purchaseId = await Repository.InsertReturnSnowflakeIdAsync(entity);
|
||||
|
||||
entity.Id = purchaseId;
|
||||
await _purchaseDetailsService.CreateAsync(input.PurchaseDetails);
|
||||
uow.Commit();
|
||||
}
|
||||
|
||||
return null;
|
||||
return await MapToGetListOutputDtoAsync(entity); ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class SupplierService : CrudAppService<SupplierEntity, SupplierGetListOutput, long, SupplierCreateUpdateInput>, ISupplierService
|
||||
{
|
||||
public SupplierService(IRepository<SupplierEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
public async Task<PageModel<List<SupplierGetListOutput>>> PageListAsync(SupplierCreateUpdateInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
|
||||
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class UnitService : CrudAppService<UnitEntity, UnitGetListOutput, long, UnitCreateUpdateInput>, IUnitService
|
||||
{
|
||||
public UnitService(IRepository<UnitEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
public async Task<PageModel<List<UnitGetListOutput>>> PageListAsync(UnitCreateUpdateInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
|
||||
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
|
||||
{
|
||||
public class WarehouseService : CrudAppService<WarehouseEntity, WarehouseGetListOutput, long, WarehouseCreateUpdateInput>, IWarehouseService
|
||||
{
|
||||
public WarehouseService(IRepository<WarehouseEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
public async Task<PageModel<List<WarehouseGetListOutput>>> PageListAsync(WarehouseCreateUpdateInput input, PageParModel page)
|
||||
{
|
||||
RefAsync<int> totalNumber = 0;
|
||||
|
||||
@@ -14,10 +14,6 @@ namespace Yi.Framework.Service.RABC
|
||||
{
|
||||
public class StudentService : CrudAppService<StudentEntity, StudentGetOutput, StudentListOutput, Guid, StudentCreateInput, StudentUpdateInput>, IStudentService
|
||||
{
|
||||
public StudentService(IRepository<StudentEntity> repository, IMapper mapper) : base(repository, mapper)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<StudentListOutput>> GetListAsync()
|
||||
{
|
||||
return await MapToGetListOutputDtosAsync(await Repository.GetListAsync());
|
||||
|
||||
Reference in New Issue
Block a user