44 changed files with 46 additions and 353 deletions
@ -1,308 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using DocumentFormat.OpenXml.Math; |
|||
using Win_in.Sfs.Shared.Domain.Shared; |
|||
using Win_in.Sfs.Shared.Event; |
|||
using Win_in.Sfs.Wms.Store.Jobs.IssueJobs.CoatingIssueJobs; |
|||
using static Win_in.Sfs.Wms.Store.Domain.Shared.StoreSettings; |
|||
|
|||
namespace Win_in.Sfs.Wms.Store.Domain; |
|||
|
|||
public class CoatingMaterialRequestManager |
|||
: SfsStoreRequestManagerBase<CoatingMaterialRequest, CoatingMaterialRequestDetail> |
|||
, ICoatingMaterialRequestManager |
|||
{ |
|||
private readonly ICoatingMaterialRequestRepository _repository; |
|||
private readonly ICoatingIssueJobRepository _issueJobRepository; |
|||
|
|||
public CoatingMaterialRequestManager( |
|||
ICoatingMaterialRequestRepository repository |
|||
, ICoatingIssueJobRepository issueJobRepository |
|||
) : base(repository) |
|||
{ |
|||
_repository = repository; |
|||
_issueJobRepository = issueJobRepository; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 创建
|
|||
/// </summary>
|
|||
/// <param name="entity"></param>
|
|||
/// <returns></returns>
|
|||
public virtual async Task<CoatingMaterialRequest> CreateBynNumberAsync(CoatingMaterialRequest entity) |
|||
{ |
|||
var number = string.IsNullOrEmpty(entity.Number) ? await GenerateNumberAsync(nameof(CoatingMaterialRequest), entity.ActiveDate).ConfigureAwait(false) : entity.Number; |
|||
entity.SetIdAndNumberWithDetails(GuidGenerator, number); |
|||
entity.Submit(); |
|||
entity.Agree(); |
|||
entity.RequestStatus = EnumRequestStatus.Partial; |
|||
await LocalEventBus.PublishAsync(new SfsHandledEntityEventData<CoatingMaterialRequest>(entity), false) |
|||
.ConfigureAwait(false); |
|||
await _repository.InsertAsync(entity).ConfigureAwait(false); |
|||
return entity; |
|||
} |
|||
|
|||
public virtual async Task UpdateDetailsAsync(CoatingMaterialRequest newEntity) |
|||
{ |
|||
var oldEntity = await Repository.FindAsync(newEntity.Id, true).ConfigureAwait(false); |
|||
if(oldEntity!=null) |
|||
{ |
|||
foreach (var newDetail in newEntity.Details) |
|||
{ |
|||
oldEntity.ReplaceDetail(newDetail.Id, newDetail); |
|||
} |
|||
|
|||
foreach (var detail in oldEntity.Details) |
|||
{ |
|||
SetMaterialRequestDetailStatus(detail); |
|||
} |
|||
|
|||
await SetMaterialRequestStatus(oldEntity).ConfigureAwait(false); |
|||
|
|||
await Repository.UpdateAsync(oldEntity).ConfigureAwait(false); |
|||
} |
|||
|
|||
} |
|||
|
|||
private void SetMaterialRequestDetailStatus(CoatingMaterialRequestDetail detail) |
|||
{ |
|||
if (detail.ReceivedQty >= detail.Qty)//执行的时候 实际收料 多余 要料数
|
|||
{ |
|||
detail.Status = EnumStatus.Close; |
|||
} |
|||
else |
|||
{ |
|||
detail.Status = EnumStatus.Open; |
|||
} |
|||
} |
|||
|
|||
private async Task SetMaterialRequestStatus(CoatingMaterialRequest materialRequest) |
|||
{ |
|||
if (materialRequest.Details.All(p => p.Status == EnumStatus.Close)) |
|||
{ |
|||
materialRequest.RequestStatus = EnumRequestStatus.Completed; |
|||
} |
|||
else |
|||
{ |
|||
var issueJobs = await _issueJobRepository.GetListAsync(t => t.MaterialRequestNumber == materialRequest.Number).ConfigureAwait(false); |
|||
if (issueJobs.Count > 0) |
|||
{ |
|||
if (issueJobs.All(t => t.JobStatus is EnumJobStatus.Done or EnumJobStatus.Closed or EnumJobStatus.Cancelled)) |
|||
{ |
|||
if (materialRequest.Details.All(p => p.ReceivedQty >= p.Qty)) |
|||
{ |
|||
materialRequest.RequestStatus = EnumRequestStatus.Completed; |
|||
} |
|||
else |
|||
{ |
|||
materialRequest.RequestStatus = EnumRequestStatus.Partial; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
materialRequest.RequestStatus = EnumRequestStatus.Partial; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
materialRequest.RequestStatus = EnumRequestStatus.Partial; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public virtual async Task CompleteAsync(string number) |
|||
{ |
|||
var entity = await GetByNumberAsync(number).ConfigureAwait(false); |
|||
if (entity != null && !entity.Details.Any(p => p.ToBeIssuedQty > 0)) |
|||
{ |
|||
await CompleteAsync(entity).ConfigureAwait(false); |
|||
} |
|||
} |
|||
|
|||
#region 公有
|
|||
|
|||
/* |
|||
// /// <summary>
|
|||
// /// 处理
|
|||
// /// </summary>
|
|||
// /// <returns></returns>
|
|||
// public virtual async Task<bool> Handle(Guid id)
|
|||
// {
|
|||
// var entity =await Repository.GetAsync(id);
|
|||
// if (entity == null)
|
|||
// {
|
|||
// return false;
|
|||
// }
|
|||
// entity.Handle();
|
|||
// await Repository.UpdateAsync(entity);
|
|||
//
|
|||
// await HandledPublishAsync(entity);
|
|||
// return true;
|
|||
// }
|
|||
//
|
|||
// private async Task HandledPublishAsync(MaterialRequest entity)
|
|||
// {
|
|||
// //发布,以生成发料任务
|
|||
// var eto = BuildMaterialRequestHandledETO(entity);
|
|||
// await DistributedEventBus.PublishAsync(eto);
|
|||
// }
|
|||
//
|
|||
// /// <summary>
|
|||
// /// 关闭
|
|||
// /// </summary>
|
|||
// /// <returns></returns>
|
|||
// public virtual async Task<bool> Close(Guid id)
|
|||
// {
|
|||
// var entity = await Repository.GetAsync(id);
|
|||
// if (entity == null)
|
|||
// {
|
|||
// return false;
|
|||
// }
|
|||
// entity.Close();
|
|||
// await Repository.UpdateAsync(entity);
|
|||
//
|
|||
// //发布,以关闭发料任务
|
|||
// var eto = BuildMaterialRequestClosedETO(entity);
|
|||
// await DistributedEventBus.PublishAsync(eto);
|
|||
// return true;
|
|||
// }
|
|||
//
|
|||
// /// <summary>
|
|||
// /// 打开
|
|||
// /// </summary>
|
|||
// /// <returns></returns>
|
|||
// public virtual async Task<bool> Open(Guid id)
|
|||
// {
|
|||
// var entity = await Repository.GetAsync(id);
|
|||
// if (entity == null)
|
|||
// {
|
|||
// return false;
|
|||
// }
|
|||
// entity.Open();
|
|||
//
|
|||
// await Repository.UpdateAsync(entity);
|
|||
//
|
|||
// //发布,以打开发料任务
|
|||
// var eto = BuildMaterialRequestOpenedETO(entity);
|
|||
// await DistributedEventBus.PublishAsync(eto);
|
|||
// return true;
|
|||
// }
|
|||
|
|||
public virtual async Task<MaterialRequest> CreateAndHandleAsync(MaterialRequest entity) |
|||
{ |
|||
|
|||
await base.CreateAsync(entity); |
|||
|
|||
await base.HandleAsync(entity.Id); |
|||
|
|||
return entity; |
|||
} |
|||
*/ |
|||
|
|||
|
|||
#endregion
|
|||
|
|||
#region Import
|
|||
|
|||
/// <summary>
|
|||
/// 执行导入
|
|||
/// </summary>
|
|||
public virtual async Task ImportDataAsync(List<CoatingMaterialRequest> mergeEntities, List<CoatingMaterialRequest> deleteEntities = null) |
|||
{ |
|||
if (deleteEntities != null && deleteEntities.Count > 0) |
|||
{ |
|||
await _repository.BulkDeleteAsync(deleteEntities).ConfigureAwait(false); |
|||
} |
|||
|
|||
await CreateManyAsync(mergeEntities).ConfigureAwait(false); |
|||
} |
|||
|
|||
#endregion
|
|||
|
|||
/* |
|||
#region 私有
|
|||
|
|||
private MaterialRequestOpenedETO BuildMaterialRequestOpenedETO(MaterialRequest materialRequest) |
|||
{ |
|||
var materialRequestETO = new MaterialRequestOpenedETO() |
|||
{ |
|||
Number = materialRequest.Number, |
|||
Workshop = materialRequest.Workshop, |
|||
Status = materialRequest.Status, |
|||
Details = BuildMaterialRequestDetailETO(materialRequest.Details) |
|||
}; |
|||
return materialRequestETO; |
|||
} |
|||
|
|||
private MaterialRequestClosedETO BuildMaterialRequestClosedETO(MaterialRequest materialRequest) |
|||
{ |
|||
var materialRequestETO = new MaterialRequestClosedETO() |
|||
{ |
|||
Company = materialRequest.Company, |
|||
Number = materialRequest.Number |
|||
}; |
|||
return materialRequestETO; |
|||
} |
|||
|
|||
private MaterialRequestHandledETO BuildMaterialRequestHandledETO(MaterialRequest materialRequest) |
|||
{ |
|||
var materialRequestETO = new MaterialRequestHandledETO() |
|||
{ |
|||
Company = materialRequest.Company, |
|||
Number = materialRequest.Number, |
|||
Workshop = materialRequest.Workshop, |
|||
Status = materialRequest.Status, |
|||
Details = BuildMaterialRequestDetailETO(materialRequest.Details) |
|||
}; |
|||
return materialRequestETO; |
|||
} |
|||
|
|||
private List<MaterialRequestDetailETO> BuildMaterialRequestDetailETO(List<MaterialRequestDetail> materialRequestDetail) |
|||
{ |
|||
var list = new List<MaterialRequestDetailETO>(); |
|||
foreach (var detail in materialRequestDetail) |
|||
{ |
|||
var materialRequestDetailETO = new MaterialRequestDetailETO() |
|||
{ |
|||
Number = detail.Number, |
|||
Item = detail.Item, |
|||
ItemCode = detail.ItemCode, |
|||
Qty = detail.Qty, |
|||
ToLocationCode = detail.ToLocationCode, |
|||
ProdLine = detail.ProdLine, |
|||
WorkStation = detail.WorkStation, |
|||
ExpiredTime = detail.ExpiredTime, |
|||
Status = detail.Status |
|||
}; |
|||
list.Add(materialRequestDetailETO); |
|||
} |
|||
return list; |
|||
} |
|||
|
|||
#endregion
|
|||
*/ |
|||
} |
|||
|
|||
///// <summary>
|
|||
///// 为了解决补料时 无法拿到订阅错误信息
|
|||
///// </summary>
|
|||
///// <param name="entity"></param>
|
|||
///// <param name="flag"></param>
|
|||
///// <returns></returns>
|
|||
//public virtual async Task<MaterialRequest> CreateAndHandleAsync(MaterialRequest entity, bool flag)
|
|||
//{
|
|||
// await entity.Handle();
|
|||
// foreach (var detail in entity.Details)
|
|||
// {
|
|||
// detail.Status = EnumStoreStatus.Handle;
|
|||
// }
|
|||
// await base.CreateAsync(entity);
|
|||
|
|||
// //发布,以打开发料任务??
|
|||
// //var eto = BuildMaterialRequestHandledETO(entity);
|
|||
// //await DistributedEventBus.PublishAsync(eto);
|
|||
|
|||
// return entity;
|
|||
//}
|
Loading…
Reference in new issue