diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccount.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccount.cs index b1936ea13..b56a635c7 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccount.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccount.cs @@ -7,7 +7,7 @@ using Volo.Abp; using Volo.Abp.Application.Services; namespace Win_in.Sfs.Wms.Store.Application.Contracts; -public interface IAgvJobAccount +public interface IAgvJobAccountService { Task AccountOutOrderAsync(AgvRequestOnlyJobHK request); diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobAccountService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobAccountService.cs index e61672ebf..999f39ec0 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobAccountService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobAccountService.cs @@ -24,108 +24,38 @@ namespace Win_in.Sfs.Wms.Store.Jobs.AgvJobs; [Route($"{StoreConsts.RootPath}agv-job-Account")] public class AgvJobAccountService : ApplicationService { - private IAssembleIssueJobAppService _assembleIssueJobAppService; - private ICoatingIssueJobAppService _coatingIssueJobAppService; - private IInjectionIssueJobAppService _injectionIssueJobAppService; - private IKittingIssueJobAppService _kittingIssueJobAppService; - private ISparePartIssueJobAppService _sparePartIssueJobAppService; - private IProductionLineAppService _productionLineAppService; + private readonly Func _Accessor; + + public AgvJobAccountService( + Func Accessor + - IAssembleIssueJobAppService assembleIssueJobAppService, - ICoatingIssueJobAppService coatingIssueJobAppService, - IInjectionIssueJobAppService injectionIssueJobAppService, - IKittingIssueJobAppService kittingIssueJobAppService, - ISparePartIssueJobAppService sparePartIssueJobAppService, - IProductionLineAppService productionLineAppService ) { - _assembleIssueJobAppService = assembleIssueJobAppService; - _coatingIssueJobAppService = coatingIssueJobAppService; - _injectionIssueJobAppService = injectionIssueJobAppService; - _kittingIssueJobAppService = kittingIssueJobAppService; - _sparePartIssueJobAppService = sparePartIssueJobAppService; - _productionLineAppService = productionLineAppService; + _Accessor = Accessor; + } public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) { var res = new AgvResultObject(); res.Code = "0"; - foreach (var itm in request.Data) - { - switch (itm.OrderType) - { - case "1": - var assemblejob = new AssembleIssueJobDTO(); - var assemb = await _assembleIssueJobAppService.GetByNumberAsync(itm.OrderNum).ConfigureAwait(false); - var assembDetail = assemb.Details.FirstOrDefault(); - - - foreach (var detail in request.Data) - { - var begin = detail.BeginPosition; - var end = detail.EndPosition; - - await _productionLineAppService.GetByCodeAsync(begin).ConfigureAwait(false); - await _productionLineAppService.GetByCodeAsync(end).ConfigureAwait(false); - - } - - - - - - await _assembleIssueJobAppService.CompleteAsync(assemb.Id).ConfigureAwait(false); - res.ReqCode = assemb.AssembleRequestNumber; - res.Message = "OK"; - break; - case "2": - var coating = await _coatingIssueJobAppService.GetByNumberAsync(itm.OrderNum).ConfigureAwait(false); - await _coatingIssueJobAppService.CompleteAsync(coating.Id).ConfigureAwait(false); - break; - case "3": - var injection = await _injectionIssueJobAppService.GetByNumberAsync(itm.OrderNum).ConfigureAwait(false); - await _injectionIssueJobAppService.CompleteAsync(injection.Id).ConfigureAwait(false); - break; - case "4": - var kitting = await _kittingIssueJobAppService.GetByNumberAsync(itm.OrderNum).ConfigureAwait(false); - await _kittingIssueJobAppService.CompleteAsync(kitting.Id).ConfigureAwait(false); - - break; - case "5": - var sparePart = await _sparePartIssueJobAppService.GetByNumberAsync(itm.OrderNum).ConfigureAwait(false); - await _sparePartIssueJobAppService.CompleteAsync(sparePart.Id).ConfigureAwait(false); - break; + var first=request.Data.FirstOrDefault(); + var agvJobAccountService = _Accessor(first.OrderType); + var result = await agvJobAccountService.AccountOutOrderAsync(request).ConfigureAwait(false); + if (result.Code!= "0") + { + res.Code = "1"; + res.Message = result.Message; + } - } + return res; - return null; - } - private async Task CheckPostionLocation(AgvRequestOnlyJobHK request, Action action, List errors) - { - foreach (var detail in request.Data) - { - - - - - var begin = detail.BeginPosition; - var end = detail.EndPosition; - var beginLocation = await _productionLineAppService.GetByCodeAsync(begin).ConfigureAwait(false); - if (beginLocation == null) - { - errors.Add($"任务号:{detail.OrderNum}开始工作位置号:{begin}没找到对应库位"); - } - var endLocation = await _productionLineAppService.GetByCodeAsync(end).ConfigureAwait(false); - if (endLocation == null) - { - errors.Add($"任务号:{detail.OrderNum}结束工作位置号:{end}没找到对应库位"); - } - } } + } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AssembleIssueJobs/AssembleIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AssembleIssueJobs/AssembleIssueJobAppService.cs index 5d271e3c9..c86024a0b 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AssembleIssueJobs/AssembleIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AssembleIssueJobs/AssembleIssueJobAppService.cs @@ -38,7 +38,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class AssembleIssueJobAppService : SfsJobAppServiceBase, - IAssembleIssueJobAppService, ITransferLibCallback, IAgvJobAccount + IAssembleIssueJobAppService, ITransferLibCallback, IAgvJobAccountService { protected IAssembleIssueRequestAppService AssembleIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -804,7 +804,7 @@ public class AssembleIssueJobAppService #if DEBUG - ret.Code = 1; + return; #endif diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs index b6dcb1c52..9ab045668 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs @@ -38,7 +38,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class CoatingIssueJobAppService : SfsJobAppServiceBase, - ICoatingIssueJobAppService, ITransferLibCallback,IAgvJobAccount + ICoatingIssueJobAppService, ITransferLibCallback, IAgvJobAccountService { private readonly ICoatingIssueJobManager _coatingIssueJobManager; private readonly ILocationAppService _locationAppService; @@ -54,6 +54,7 @@ public class CoatingIssueJobAppService private readonly IOptions _agvOptions; private readonly IPostionLocationAppService _postionLocationAppService; + protected ICoatingIssueRequestAppService CoatingIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs index 56f97e819..e72132c66 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/InjectionIssueJobs/InjectionIssueJobAppService.cs @@ -9,8 +9,10 @@ using System.Threading.Tasks; using Castle.Components.DictionaryAdapter; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MyNamespace; +using Omu.ValueInjecter; using Volo.Abp; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; @@ -33,7 +35,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class InjectionIssueJobAppService : SfsJobAppServiceBase, - IInjectionIssueJobAppService, ITransferLibCallback + IInjectionIssueJobAppService, ITransferLibCallback, IAgvJobAccountService { private readonly IInjectionIssueJobManager _injectionIssueJobManager; private readonly ILocationAppService _locationAppService; @@ -47,13 +49,15 @@ public class InjectionIssueJobAppService private readonly UnitOfWorkManager _unitOfWorkManager; private readonly IOptions _agvOptions; private readonly IPostionLocationAppService _postionLocationAppService; + private readonly ILogger _logger; + protected IInjectionIssueRequestAppService InjectionIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); public InjectionIssueJobAppService( IAgvJobOutputService agvOutJob, - IInjectionIssueJobRepository repository, IInjectionIssueJobManager injectionIssueJobManager, + IInjectionIssueJobRepository repository, IInjectionIssueJobManager injectionIssueJobManager, ILogger logger, ILocationAppService locationAppService, IInjectionIssueNoteAppService injectionIssueNoteAppService, IExpectOutAppService expectOutAppService , IHttpClientFactory httpClientFactory @@ -74,6 +78,7 @@ public class InjectionIssueJobAppService _agvOutJob = agvOutJob; _unitOfWorkManager = unitOfWorkManager; _agvOptions = agvOptions; + _logger = logger; } [HttpPost("get-by-number-2")] public async Task GetByNumber2Async(string number) @@ -744,6 +749,163 @@ public class InjectionIssueJobAppService } return ret; } + [HttpPost("accountOutOrder")] + public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) + { + var json = JsonSerializer.Serialize(request); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json); +#if DEBUG +#endif + var errors = new List(); + var first = request.Data.FirstOrDefault(); + var job = await _repository.GetAsync(p => p.Number == first.OrderNum).ConfigureAwait(false); + + var ret = new AgvResultObject + { + Code = "0", + Message = "OK", + ReqCode = job.InjectionRequestNumber, + + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + if (request.Data.Count > 0) + { + var jobs = request.Data; + var numbers = jobs.Select(p => p.OrderNum); + var query = _repository.WithDetails() + .Where(p => numbers.Contains(p.Number) && p.JobStatus != EnumJobStatus.Done); + var entities = query.ToList(); + if (entities.Count == 0) + { + errors.Add($"任务号{string.Join(",", numbers)}不存在!"); + } + + var dtos = ObjectMapper.Map, List>(entities); + foreach (var itm in dtos) + { + var arys = jobs.Where(p => p.OrderNum == itm.Number); + var itmDetails = itm.Details.ToList(); + var details = new List(); + foreach (var detail in arys) + { + + var fromloc = await _postionLocationAppService.GetByCodeAsync(detail.BeginPosition).ConfigureAwait(false); + if (fromloc == null) + { + errors.Add($"来源起始点{detail.BeginPosition}没查到"); + } + + LocationDTO fromlocation = null; + + if (fromloc != null) + { + fromlocation = await _locationAppService.GetByCodeAsync(fromloc.Code).ConfigureAwait(false); + } + if (fromlocation == null) + { + errors.Add($"来源起始点{detail.BeginPosition}库位没查到"); + } + + var toloc = await _postionLocationAppService.GetByCodeAsync(detail.EndPosition) + .ConfigureAwait(false); + if (toloc == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + LocationDTO tolocation = null; + + if (toloc != null) + { + tolocation = await _locationAppService.GetByCodeAsync(toloc.Code).ConfigureAwait(false); + } + if (tolocation == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + + var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); + if (entity == null) + { + errors.Add($"物料号{detail.MatCode}不在任务明细内!"); + } + + var dto = new InjectionIssueJobDetailDTO(); + dto.InjectFrom(entity); + dto.HandledToLocationCode = toloc.Code; + dto.HandledToLocationGroup = tolocation.LocationGroupCode; + dto.HandledToLocationArea = tolocation.AreaCode; + dto.HandledToLocationErpCode = tolocation.ErpLocationCode; + + dto.HandledToWarehouseCode = tolocation.WarehouseCode; + dto.HandledToQty = detail.MatQty; + dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; + dto.HandledToPackingCode = string.Empty; + + dto.HandledFromWarehouseCode = fromlocation.WarehouseCode; + dto.HandledFromLocationCode = fromlocation.Code; + dto.HandledFromLocationGroup = fromlocation.LocationGroupCode; + dto.HandledFromLocationArea = fromlocation.AreaCode; + dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode; + dto.HandledFromQty = detail.MatQty; + dto.HandledFromLot = string.Empty; + dto.HandledFromPackingCode = string.Empty; + details.Add(dto); + + + + + + //await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); + } + + if (errors.Count > 0) + { + ret = new AgvResultObject() + { + Code = "-1", + ReqCode = "", + Message = string.Join(",", errors.ToArray()) + }; + } + itm.Worker = "AGV"; + itm.Details = details; + + _logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成"); + } + } + else + { + errors.Add("Agv确认单据里无数据! \n"); + } + } + catch (Exception ex) + { + ret = new AgvResultObject + { + Code = "-1", + ReqCode = job.InjectionRequestNumber, + Message = ex.Message, + }; + await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.InjectionRequestNumber + }; + } + return ret; + } #endregion diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs index c962b4744..f80d37205 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/KittingIssueJobs/KittingIssueJobAppService.cs @@ -9,8 +9,10 @@ using System.Threading.Tasks; using Castle.Components.DictionaryAdapter; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MyNamespace; +using Omu.ValueInjecter; using Volo.Abp; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; @@ -33,7 +35,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class KittingIssueJobAppService : SfsJobAppServiceBase, - IKittingIssueJobAppService, ITransferLibCallback + IKittingIssueJobAppService, ITransferLibCallback,IAgvJobAccountService { private readonly IKittingIssueJobManager _kittingIssueJobManager; private readonly ILocationAppService _locationAppService; @@ -48,6 +50,7 @@ public class KittingIssueJobAppService private readonly IHttpClientFactory _httpClientFactory; private readonly IOptions _agvOptions; private readonly IPostionLocationAppService _postionLocationAppService; + private readonly ILogger _logger; protected IKittingIssueRequestAppService KittingIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -56,7 +59,7 @@ public class KittingIssueJobAppService IAgvJobOutputService agvOutJob, IKittingIssueJobRepository repository, IKittingIssueJobManager kittingIssueJobManager, ILocationAppService locationAppService, - IKittingIssueNoteAppService kittingIssueNoteAppService, IExpectOutAppService expectOutAppService + IKittingIssueNoteAppService kittingIssueNoteAppService, IExpectOutAppService expectOutAppService, ILogger logger , IHttpClientFactory httpClientFactory , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser ,IOptions agvOptions, @@ -758,6 +761,163 @@ public class KittingIssueJobAppService } return ret; } + [HttpPost("accountOutOrder")] + public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) + { + var json = JsonSerializer.Serialize(request); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json); +#if DEBUG +#endif + var errors = new List(); + var first = request.Data.FirstOrDefault(); + var job = await _repository.GetAsync(p => p.Number == first.OrderNum).ConfigureAwait(false); + + var ret = new AgvResultObject + { + Code = "0", + Message = "OK", + ReqCode = job.KittingRequestNumber, + + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + if (request.Data.Count > 0) + { + var jobs = request.Data; + var numbers = jobs.Select(p => p.OrderNum); + var query = _repository.WithDetails() + .Where(p => numbers.Contains(p.Number) && p.JobStatus != EnumJobStatus.Done); + var entities = query.ToList(); + if (entities.Count == 0) + { + errors.Add($"任务号{string.Join(",", numbers)}不存在!"); + } + + var dtos = ObjectMapper.Map, List>(entities); + foreach (var itm in dtos) + { + var arys = jobs.Where(p => p.OrderNum == itm.Number); + var itmDetails = itm.Details.ToList(); + var details = new List(); + foreach (var detail in arys) + { + + var fromloc = await _postionLocationAppService.GetByCodeAsync(detail.BeginPosition).ConfigureAwait(false); + if (fromloc == null) + { + errors.Add($"来源起始点{detail.BeginPosition}没查到"); + } + + LocationDTO fromlocation = null; + + if (fromloc != null) + { + fromlocation = await _locationAppService.GetByCodeAsync(fromloc.Code).ConfigureAwait(false); + } + if (fromlocation == null) + { + errors.Add($"来源起始点{detail.BeginPosition}库位没查到"); + } + + var toloc = await _postionLocationAppService.GetByCodeAsync(detail.EndPosition) + .ConfigureAwait(false); + if (toloc == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + LocationDTO tolocation = null; + + if (toloc != null) + { + tolocation = await _locationAppService.GetByCodeAsync(toloc.Code).ConfigureAwait(false); + } + if (tolocation == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + + var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); + if (entity == null) + { + errors.Add($"物料号{detail.MatCode}不在任务明细内!"); + } + + var dto = new KittingIssueJobDetailDTO(); + dto.InjectFrom(entity); + dto.HandledToLocationCode = toloc.Code; + dto.HandledToLocationGroup = tolocation.LocationGroupCode; + dto.HandledToLocationArea = tolocation.AreaCode; + dto.HandledToLocationErpCode = tolocation.ErpLocationCode; + + dto.HandledToWarehouseCode = tolocation.WarehouseCode; + dto.HandledToQty = detail.MatQty; + dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; + dto.HandledToPackingCode = string.Empty; + + dto.HandledFromWarehouseCode = fromlocation.WarehouseCode; + dto.HandledFromLocationCode = fromlocation.Code; + dto.HandledFromLocationGroup = fromlocation.LocationGroupCode; + dto.HandledFromLocationArea = fromlocation.AreaCode; + dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode; + dto.HandledFromQty = detail.MatQty; + dto.HandledFromLot = string.Empty; + dto.HandledFromPackingCode = string.Empty; + details.Add(dto); + + + + + + //await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); + } + + if (errors.Count > 0) + { + ret = new AgvResultObject() + { + Code = "-1", + ReqCode = "", + Message = string.Join(",", errors.ToArray()) + }; + } + itm.Worker = "AGV"; + itm.Details = details; + + _logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成"); + } + } + else + { + errors.Add("Agv确认单据里无数据! \n"); + } + } + catch (Exception ex) + { + ret = new AgvResultObject + { + Code = "-1", + ReqCode = job.KittingRequestNumber, + Message = ex.Message, + }; + await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.KittingRequestNumber + }; + } + return ret; + } #endregion diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs index c69f7d8a1..8a06554c4 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/SparePartIssueJobs/SparePartIssueJobAppService.cs @@ -9,8 +9,10 @@ using System.Threading.Tasks; using Castle.Components.DictionaryAdapter; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MyNamespace; +using Omu.ValueInjecter; using Volo.Abp; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; @@ -33,7 +35,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class SparePartIssueJobAppService : SfsJobAppServiceBase, - ISparePartIssueJobAppService, ITransferLibCallback + ISparePartIssueJobAppService, ITransferLibCallback, IAgvJobAccountService { private readonly ISparePartIssueJobManager _sparePartIssueJobManager; private readonly ILocationAppService _locationAppService; @@ -47,6 +49,7 @@ public class SparePartIssueJobAppService private readonly UnitOfWorkManager _unitOfWorkManager; private readonly IOptions _agvOptions; private readonly IPostionLocationAppService _postionLocationAppService; + private readonly ILogger _logger; protected ISparePartIssueRequestAppService SparePartIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -57,7 +60,7 @@ public class SparePartIssueJobAppService ILocationAppService locationAppService, ISparePartIssueNoteAppService sparePartIssueNoteAppService, IExpectOutAppService expectOutAppService , IHttpClientFactory httpClientFactory - , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, ILogger logger , UnitOfWorkManager unitOfWorkManager, IOptions agvOptions ) : base( repository, sparePartIssueJobManager) @@ -72,7 +75,8 @@ public class SparePartIssueJobAppService _currentUser = currentUser; _agvOutJob = agvOutJob; _unitOfWorkManager = unitOfWorkManager; - _agvOptions = agvOptions; + _agvOptions = agvOptions; + _logger = logger; } [HttpPost("get-by-number-2")] @@ -734,6 +738,163 @@ public class SparePartIssueJobAppService } return ret; } + [HttpPost("accountOutOrder")] + public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) + { + var json = JsonSerializer.Serialize(request); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json); +#if DEBUG +#endif + var errors = new List(); + var first = request.Data.FirstOrDefault(); + var job = await _repository.GetAsync(p => p.Number == first.OrderNum).ConfigureAwait(false); + + var ret = new AgvResultObject + { + Code = "0", + Message = "OK", + ReqCode = job.SparePartRequestNumber, + + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + if (request.Data.Count > 0) + { + var jobs = request.Data; + var numbers = jobs.Select(p => p.OrderNum); + var query = _repository.WithDetails() + .Where(p => numbers.Contains(p.Number) && p.JobStatus != EnumJobStatus.Done); + var entities = query.ToList(); + if (entities.Count == 0) + { + errors.Add($"任务号{string.Join(",", numbers)}不存在!"); + } + + var dtos = ObjectMapper.Map, List>(entities); + foreach (var itm in dtos) + { + var arys = jobs.Where(p => p.OrderNum == itm.Number); + var itmDetails = itm.Details.ToList(); + var details = new List(); + foreach (var detail in arys) + { + + var fromloc = await _postionLocationAppService.GetByCodeAsync(detail.BeginPosition).ConfigureAwait(false); + if (fromloc == null) + { + errors.Add($"来源起始点{detail.BeginPosition}没查到"); + } + + LocationDTO fromlocation = null; + + if (fromloc != null) + { + fromlocation = await _locationAppService.GetByCodeAsync(fromloc.Code).ConfigureAwait(false); + } + if (fromlocation == null) + { + errors.Add($"来源起始点{detail.BeginPosition}库位没查到"); + } + + var toloc = await _postionLocationAppService.GetByCodeAsync(detail.EndPosition) + .ConfigureAwait(false); + if (toloc == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + LocationDTO tolocation = null; + + if (toloc != null) + { + tolocation = await _locationAppService.GetByCodeAsync(toloc.Code).ConfigureAwait(false); + } + if (tolocation == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + + var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); + if (entity == null) + { + errors.Add($"物料号{detail.MatCode}不在任务明细内!"); + } + + var dto = new SparePartIssueJobDetailDTO(); + dto.InjectFrom(entity); + dto.HandledToLocationCode = toloc.Code; + dto.HandledToLocationGroup = tolocation.LocationGroupCode; + dto.HandledToLocationArea = tolocation.AreaCode; + dto.HandledToLocationErpCode = tolocation.ErpLocationCode; + + dto.HandledToWarehouseCode = tolocation.WarehouseCode; + dto.HandledToQty = detail.MatQty; + dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; + dto.HandledToPackingCode = string.Empty; + + dto.HandledFromWarehouseCode = fromlocation.WarehouseCode; + dto.HandledFromLocationCode = fromlocation.Code; + dto.HandledFromLocationGroup = fromlocation.LocationGroupCode; + dto.HandledFromLocationArea = fromlocation.AreaCode; + dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode; + dto.HandledFromQty = detail.MatQty; + dto.HandledFromLot = string.Empty; + dto.HandledFromPackingCode = string.Empty; + details.Add(dto); + + + + + + //await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); + } + + if (errors.Count > 0) + { + ret = new AgvResultObject() + { + Code = "-1", + ReqCode = "", + Message = string.Join(",", errors.ToArray()) + }; + } + itm.Worker = "AGV"; + itm.Details = details; + + _logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成"); + } + } + else + { + errors.Add("Agv确认单据里无数据! \n"); + } + } + catch (Exception ex) + { + ret = new AgvResultObject + { + Code = "-1", + ReqCode = job.SparePartRequestNumber, + Message = ex.Message, + }; + await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.SparePartRequestNumber + }; + } + return ret; + } #endregion diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedIssueJobs/UnplannedIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedIssueJobs/UnplannedIssueJobAppService.cs index 99326d80f..260a84d37 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedIssueJobs/UnplannedIssueJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedIssueJobs/UnplannedIssueJobAppService.cs @@ -23,6 +23,9 @@ using Win_in.Sfs.Wms.Store.Domain.Shared; using Win_in.Sfs.Wms.Store.Jobs.IssueJobs.proxy; using Microsoft.Extensions.Options; using Win_in.Sfs.Wms.Store.Options; +using Volo.Abp.ObjectMapping; +using Win_in.Sfs.Basedata.Application; +using System.Text.Json; namespace Win_in.Sfs.Wms.Store.Application; @@ -31,7 +34,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class UnplannedIssueJobAppService : SfsJobAppServiceBase, - IUnplannedIssueJobAppService + IUnplannedIssueJobAppService,IAgvJobAccountService { protected IUnplannedIssueRequestAppService UnplannedReceiptRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -46,13 +49,16 @@ public class UnplannedIssueJobAppService private readonly IOptions _agvOptions; private readonly IHttpClientFactory _httpClientFactory; + private readonly IPostionLocationAppService _postionLocationAppService; + public UnplannedIssueJobAppService( IUnplannedIssueJobRepository repository, IUnplannedIssueJobManager unplannedIssueJobManager, ILocationAppService locationAppService, IBalanceAppService balanceAppService, IExpectOutAppService expectOutAppService, IUnitOfWorkManager unitOfWorkManager, ILogger logger, - IItemBasicAppService itemBasicAppService, IOptions agvOptions + IItemBasicAppService itemBasicAppService, IOptions agvOptions, + IPostionLocationAppService postionLocationAppService , IHttpClientFactory httpClientFactory ) : base(repository, unplannedIssueJobManager) @@ -66,6 +72,7 @@ public class UnplannedIssueJobAppService _itemBasicAppService = itemBasicAppService; _agvOptions = agvOptions; _httpClientFactory = httpClientFactory; + _postionLocationAppService = postionLocationAppService; } /// @@ -707,6 +714,163 @@ public class UnplannedIssueJobAppService } return ret; } + [HttpPost("accountOutOrder")] + public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) + { + var json = JsonSerializer.Serialize(request); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json); +#if DEBUG +#endif + var errors = new List(); + var first = request.Data.FirstOrDefault(); + var job = await _repository.GetAsync(p => p.Number == first.OrderNum).ConfigureAwait(false); + + var ret = new AgvResultObject + { + Code = "0", + Message = "OK", + ReqCode = job.UnplannedIssueRequestNumber, + + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + if (request.Data.Count > 0) + { + var jobs = request.Data; + var numbers = jobs.Select(p => p.OrderNum); + var query = _repository.WithDetails() + .Where(p => numbers.Contains(p.Number) && p.JobStatus != EnumJobStatus.Done); + var entities = query.ToList(); + if (entities.Count == 0) + { + errors.Add($"任务号{string.Join(",", numbers)}不存在!"); + } + + var dtos = ObjectMapper.Map, List>(entities); + foreach (var itm in dtos) + { + var arys = jobs.Where(p => p.OrderNum == itm.Number); + var itmDetails = itm.Details.ToList(); + var details = new List(); + foreach (var detail in arys) + { + + var fromloc = await _postionLocationAppService.GetByCodeAsync(detail.BeginPosition).ConfigureAwait(false); + if (fromloc == null) + { + errors.Add($"来源起始点{detail.BeginPosition}没查到"); + } + + LocationDTO fromlocation = null; + + if (fromloc != null) + { + fromlocation = await _locationAppService.GetByCodeAsync(fromloc.Code).ConfigureAwait(false); + } + if (fromlocation == null) + { + errors.Add($"来源起始点{detail.BeginPosition}库位没查到"); + } + + var toloc = await _postionLocationAppService.GetByCodeAsync(detail.EndPosition) + .ConfigureAwait(false); + if (toloc == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + LocationDTO tolocation = null; + + if (toloc != null) + { + tolocation = await _locationAppService.GetByCodeAsync(toloc.Code).ConfigureAwait(false); + } + if (tolocation == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + + var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); + if (entity == null) + { + errors.Add($"物料号{detail.MatCode}不在任务明细内!"); + } + + var dto = new UnplannedIssueJobDetailDTO(); + dto.InjectFrom(entity); + //dto.HandledQty = toloc.Code; + //dto.location = tolocation.LocationGroupCode; + //dto.HandledToLocationArea = tolocation.AreaCode; + //dto.HandledToLocationErpCode = tolocation.ErpLocationCode; + + //dto.HandledToWarehouseCode = tolocation.WarehouseCode; + //dto.HandledToQty = detail.MatQty; + //dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; + //dto.HandledToPackingCode = string.Empty; + + //dto.HandledFromWarehouseCode = fromlocation.WarehouseCode; + //dto.HandledFromLocationCode = fromlocation.Code; + //dto.HandledFromLocationGroup = fromlocation.LocationGroupCode; + //dto.HandledFromLocationArea = fromlocation.AreaCode; + //dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode; + //dto.HandledFromQty = detail.MatQty; + //dto.HandledFromLot = string.Empty; + //dto.HandledFromPackingCode = string.Empty; + details.Add(dto); + + + + + + //await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); + } + + if (errors.Count > 0) + { + ret = new AgvResultObject() + { + Code = "-1", + ReqCode = "", + Message = string.Join(",", errors.ToArray()) + }; + } + itm.Worker = "AGV"; + itm.Details = details; + + _logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成"); + } + } + else + { + errors.Add("Agv确认单据里无数据! \n"); + } + } + catch (Exception ex) + { + ret = new AgvResultObject + { + Code = "-1", + ReqCode = job.UnplannedIssueRequestNumber, + Message = ex.Message, + }; + await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.UnplannedIssueRequestNumber + }; + } + return ret; + } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedReceiptJobs/UnplannedReceiptJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedReceiptJobs/UnplannedReceiptJobAppService.cs index 0acea3b7f..cf7abaa6a 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedReceiptJobs/UnplannedReceiptJobAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/UnplannedReceiptJobs/UnplannedReceiptJobAppService.cs @@ -32,13 +32,16 @@ using Win_in.Sfs.Wms.Store.Jobs.IssueJobs.proxy; using Win_in.Sfs.Wms.Store.Options; using Microsoft.Extensions.Options; using Volo.Abp.Uow; +using Omu.ValueInjecter; +using Win_in.Sfs.Basedata.Application; +using Microsoft.Extensions.Logging; [Authorize] [Route($"{StoreConsts.RootPath}unplanned-receipt-job")] public class UnplannedReceiptJobAppService : SfsJobAppServiceBase, - IUnplannedReceiptJobAppService + IUnplannedReceiptJobAppService, IAgvJobAccountService { protected IUnplannedReceiptRequestAppService UnplannedReceiptRequestAppService=> LazyServiceProvider.LazyGetRequiredService(); @@ -51,16 +54,19 @@ public class UnplannedReceiptJobAppService private readonly IOptions _agvOptions; private readonly IHttpClientFactory _httpClientFactory; private readonly IUnitOfWorkManager _unitOfWorkManager; + private readonly IPostionLocationAppService _postionLocationAppService; + private readonly ILogger _logger; public UnplannedReceiptJobAppService( - IUnplannedReceiptJobRepository repository, IUnplannedReceiptJobManager UnplannedReceiptJobManager, + IUnplannedReceiptJobRepository repository, IUnplannedReceiptJobManager UnplannedReceiptJobManager, IPostionLocationAppService postionLocationAppService, ILocationAppService locationAppService, IBalanceAppService balanceAppService, IExpectOutAppService expectOutAppService, IItemBasicAppService itemBasicAppService, IOptions agvOptions, IHttpClientFactory httpClientFactory, - IUnitOfWorkManager unitOfWorkManager + IUnitOfWorkManager unitOfWorkManager, + ILogger logger ) : base(repository, UnplannedReceiptJobManager) @@ -73,6 +79,8 @@ public class UnplannedReceiptJobAppService _agvOptions = agvOptions; _httpClientFactory = httpClientFactory; _unitOfWorkManager = unitOfWorkManager; + _logger = logger; + _postionLocationAppService = postionLocationAppService; } @@ -382,4 +390,161 @@ public class UnplannedReceiptJobAppService } return ret; } + [HttpPost("accountOutOrder")] + public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) + { + var json = JsonSerializer.Serialize(request); + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + _logger.LogInformation($"{flag}接收到AGV确认单据内容:" + json); +#if DEBUG +#endif + var errors = new List(); + var first = request.Data.FirstOrDefault(); + var job = await _repository.GetAsync(p => p.Number == first.OrderNum).ConfigureAwait(false); + + var ret = new AgvResultObject + { + Code = "0", + Message = "OK", + ReqCode = job.UnplannedReceiptRequestNumber, + + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + if (request.Data.Count > 0) + { + var jobs = request.Data; + var numbers = jobs.Select(p => p.OrderNum); + var query = _repository.WithDetails() + .Where(p => numbers.Contains(p.Number) && p.JobStatus != EnumJobStatus.Done); + var entities = query.ToList(); + if (entities.Count == 0) + { + errors.Add($"任务号{string.Join(",", numbers)}不存在!"); + } + + var dtos = ObjectMapper.Map, List>(entities); + foreach (var itm in dtos) + { + var arys = jobs.Where(p => p.OrderNum == itm.Number); + var itmDetails = itm.Details.ToList(); + var details = new List(); + foreach (var detail in arys) + { + + var fromloc = await _postionLocationAppService.GetByCodeAsync(detail.BeginPosition).ConfigureAwait(false); + if (fromloc == null) + { + errors.Add($"来源起始点{detail.BeginPosition}没查到"); + } + + LocationDTO fromlocation = null; + + if (fromloc != null) + { + fromlocation = await _locationAppService.GetByCodeAsync(fromloc.Code).ConfigureAwait(false); + } + if (fromlocation == null) + { + errors.Add($"来源起始点{detail.BeginPosition}库位没查到"); + } + + var toloc = await _postionLocationAppService.GetByCodeAsync(detail.EndPosition) + .ConfigureAwait(false); + if (toloc == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + LocationDTO tolocation = null; + + if (toloc != null) + { + tolocation = await _locationAppService.GetByCodeAsync(toloc.Code).ConfigureAwait(false); + } + if (tolocation == null) + { + errors.Add($"结束点{detail.EndPosition}库位没查到"); + } + + + var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.MatCode); + if (entity == null) + { + errors.Add($"物料号{detail.MatCode}不在任务明细内!"); + } + + var dto = new UnplannedReceiptJobDetailDTO(); + dto.InjectFrom(entity); + // dto.HandledQty = toloc.Code; + //dto.location = tolocation.LocationGroupCode; + //dto.HandledToLocationArea = tolocation.AreaCode; + //dto.HandledToLocationErpCode = tolocation.ErpLocationCode; + + //dto.HandledToWarehouseCode = tolocation.WarehouseCode; + //dto.HandledToQty = detail.MatQty; + //dto.HandledToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; + //dto.HandledToPackingCode = string.Empty; + + //dto.HandledFromWarehouseCode = fromlocation.WarehouseCode; + //dto.HandledFromLocationCode = fromlocation.Code; + //dto.HandledFromLocationGroup = fromlocation.LocationGroupCode; + //dto.HandledFromLocationArea = fromlocation.AreaCode; + //dto.HandledFromLocationErpCode = fromlocation.ErpLocationCode; + //dto.HandledFromQty = detail.MatQty; + //dto.HandledFromLot = string.Empty; + //dto.HandledFromPackingCode = string.Empty; + details.Add(dto); + + + + + + //await ExecuteDetailExtAsync(itm.Id, entity.Id, dto).ConfigureAwait(false); + } + + if (errors.Count > 0) + { + ret = new AgvResultObject() + { + Code = "-1", + ReqCode = "", + Message = string.Join(",", errors.ToArray()) + }; + } + itm.Worker = "AGV"; + itm.Details = details; + + _logger.LogInformation($"{flag}接收Agv确认单据内容:" + json + "Agv任务完成"); + } + } + else + { + errors.Add("Agv确认单据里无数据! \n"); + } + } + catch (Exception ex) + { + ret = new AgvResultObject + { + Code = "-1", + ReqCode = job.UnplannedReceiptRequestNumber, + Message = ex.Message, + }; + await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.UnplannedReceiptRequestNumber + }; + } + return ret; + } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/StoreApplicationModule.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/StoreApplicationModule.cs index 5c87cbb67..9ccfaede4 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/StoreApplicationModule.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/StoreApplicationModule.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Volo.Abp.Application; @@ -6,6 +7,7 @@ using Volo.Abp.Modularity; using Volo.Abp.Settings; using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; +using Win_in.Sfs.Wms.Store.Jobs.AgvJobs; using Win_in.Sfs.Wms.Store.Options; namespace Win_in.Sfs.Wms.Store.Application; @@ -38,6 +40,46 @@ public class StoreApplicationModule : AbpModule context.Services.Replace(ServiceDescriptor.Transient()); context.Services.Replace(ServiceDescriptor.Transient()); context.Services.Replace(ServiceDescriptor.Transient()); + + context.Services.AddTransient(implementationFactory => + { + Func accesor = key => + { + if (key.Equals("1001")) + { + return implementationFactory.GetService(); + } + if (key.Equals("1002")) + { + return implementationFactory.GetService(); + } + if (key.Equals("1003")) + { + return implementationFactory.GetService(); + } + if (key.Equals("1004")) + { + return implementationFactory.GetService(); + } + if (key.Equals("1005")) + { + return implementationFactory.GetService(); + } + if (key.Equals("1005")) + { + return implementationFactory.GetService(); + } + if (key.Equals("1005")) + { + return implementationFactory.GetService(); + } + else + { + throw new ArgumentException($"Not Support key:{key}"); + } + }; return accesor; + }); + //context.Services.Replace(ServiceDescriptor.Transient()); Configure(options =>