From afd8d0915a3cb72196677c6afe0f7cf6d304b4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=A6=20=E8=B5=B5?= <89237069@qq.com> Date: Mon, 2 Dec 2024 17:20:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E8=BE=B9=E4=BB=93=E8=B0=83=E6=8B=A8?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=B7=BB=E5=8A=A0=E8=B0=83=E7=94=A8AGV?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssembleIssueJobAppService.cs | 141 +-------- .../TransferNotes/TransferNoteAppService.cs | 290 +++++++++++++++++- 2 files changed, 304 insertions(+), 127 deletions(-) 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 a8b23e951..706d8869b 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 @@ -51,23 +51,23 @@ public class AssembleIssueJobAppService private readonly IHttpClientFactory _httpClientFactory; private readonly ITransferLibRequestAppService _transferLibRequestAppService; private readonly IOptions _options; - private readonly ILogger _logger; + private readonly ICurrentUser _currentUser; private readonly UnitOfWorkManager _unitOfWorkManager; private readonly IOptions _agvOptions; - + private readonly ILogger _logger; private readonly IPostionLocationAppService _postionLocationAppService; public AssembleIssueJobAppService( ILogger logger, - + IAssembleIssueJobRepository repository, IAssembleIssueJobManager assembleIssueJobManager, ILocationAppService locationAppService, IAssembleIssueNoteAppService assembleIssueNoteAppService, IExpectOutAppService expectOutAppService - ,IHttpClientFactory httpClientFactory - ,IOptions options, ITransferLibRequestAppService transferLibRequestAppService, + , IHttpClientFactory httpClientFactory + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, UnitOfWorkManager unitOfWorkManager , IOptions agvOptions , IPostionLocationAppService postionLocationAppService @@ -78,7 +78,7 @@ public class AssembleIssueJobAppService ) { - _postionLocationAppService= postionLocationAppService; + _postionLocationAppService = postionLocationAppService; _assembleIssueJobManager = assembleIssueJobManager; _locationAppService = locationAppService; _assembleIssueNoteAppService = assembleIssueNoteAppService; @@ -89,7 +89,7 @@ public class AssembleIssueJobAppService _currentUser = currentUser; _unitOfWorkManager = unitOfWorkManager; _logger = logger; - + _agvOptions = agvOptions; } @@ -157,7 +157,7 @@ public class AssembleIssueJobAppService return assembleIssueJobDto; } - + @@ -851,10 +851,10 @@ public class AssembleIssueJobAppService var res = new ReusltObject(); List errors = new List(); - List successList= new List(); + List successList = new List(); foreach (var itm in inputs) { - var jobres= await PushOutTaskAsync(itm).ConfigureAwait(false); + var jobres = await PushOutTaskAsync(itm).ConfigureAwait(false); if (jobres.Code != "0") { _logger.LogInformation(jobres.Message); @@ -869,7 +869,7 @@ public class AssembleIssueJobAppService { res.Code = -1; res.Message = string.Join(",", errors); - res.Data=""; + res.Data = ""; return res; } return res; @@ -959,7 +959,7 @@ public class AssembleIssueJobAppService if (errors.Count > 0) { - return ret = new AgvResultObject() + return ret = new AgvResultObject() { Code = "-1", ReqCode = "", @@ -1174,7 +1174,7 @@ public class AssembleIssueJobAppService var ret = new AgvResultObject { Code = "0", - ReqCode=job.AssembleRequestNumber, + ReqCode = job.AssembleRequestNumber, Message = "OK" }; using var unitOfWork = _unitOfWorkManager.Begin(); @@ -1218,7 +1218,7 @@ public class AssembleIssueJobAppService var client = new AgvJobClient(_agvOptions.Value.Address, httpclient, _agvOptions.Value.Path); ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); - + } catch (Exception e) { @@ -1231,118 +1231,7 @@ public class AssembleIssueJobAppService } return ret; } +} - - - 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 AssembleIssueJobDetailDTO(); - dto.InjectFrom(entity); - dto.HandledToLocationCode = toLocation.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.AssembleRequestNumber, - Message = ex.Message, - }; - await unitOfWork.RollbackAsync(); - return ret; - } - - if (errors.Count > 0) - { - ret = new AgvResultObject - { - Code = "-1", - Message = string.Join(",", errors.ToArray()), - ReqCode=job.AssembleRequestNumber - }; - } - return ret; - } - - - - - #endregion -} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/TransferNotes/TransferNoteAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/TransferNotes/TransferNoteAppService.cs index 9788188ed..968f78324 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/TransferNotes/TransferNoteAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/TransferNotes/TransferNoteAppService.cs @@ -1,13 +1,19 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http.Headers; +using System.Net.Http; +using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Omu.ValueInjecter; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Win_in.Sfs.Basedata.Application; using Win_in.Sfs.Basedata.Application.Contracts; using Win_in.Sfs.Basedata.Domain.Shared; using Win_in.Sfs.Basedata.SplitPackings.Commons; @@ -18,6 +24,10 @@ using Win_in.Sfs.Wms.Inventory.Application.Contracts; using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; using Win_in.Sfs.Wms.Store.Domain.Shared; +using Win_in.Sfs.Wms.Store.Jobs.IssueJobs.proxy; +using Win_in.Sfs.Wms.Store.Options; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Win_in.Sfs.Wms.Store.Application; @@ -42,6 +52,13 @@ public class TransferNoteAppService : SfsStoreWithDetailsAppServiceBase private readonly IExpectOutAppService _expectOutAppService; // private readonly IInventoryLabelAppService _inventoryLabelAppService; + private readonly IHttpClientFactory _httpClientFactory; + + private readonly IOptions _agvOptions; + + private readonly ILogger _logger; + + private readonly IPostionLocationAppService _postionLocationAppService; @@ -57,7 +74,8 @@ public class TransferNoteAppService : SfsStoreWithDetailsAppServiceBase IInspectJobAppService inspectJobAppService, IIssueJobAppService issueJobAppService, IInventoryLabelAppService inventoryLabelAppService, - IExpectOutAppService expectOutAppService) : base(repository) + IHttpClientFactory _httpClientFactory, + IExpectOutAppService expectOutAppService) : base(repository) { _transferNoteManager = transferNoteManager; _balanceAppService = balanceAppService; @@ -598,4 +616,274 @@ public class TransferNoteAppService : SfsStoreWithDetailsAppServiceBase return ret; } + + /// + /// 调用 Agv 接口 + /// + /// + /// + /// + /// + [HttpPost("call-agv")] + public async Task CallAgvAsync(List inputs) + { + + var res = new ReusltObject(); + List errors = new List(); + List successList = new List(); + foreach (var itm in inputs) + { + var jobres = await PushOutTaskAsync(itm).ConfigureAwait(false); + if (jobres.Code != "0") + { + _logger.LogInformation(jobres.Message); + errors.Add(jobres.Message); + } + else + { + successList.Add(jobres.Message); + } + } + if (errors.Count > 0) + { + res.Code = -1; + res.Message = string.Join(",", errors); + res.Data = ""; + return res; + } + return res; + + + } + + [HttpPost("call-back-agv")] + public async Task CallBackAgvAsync(AgvRequestDto 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.RequestNumber, + }; + // 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) ); + 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.LocationCode).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.LocationCode).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}不在任务明细内!"); + } + + if (errors.Count > 0) + { + return ret = new AgvResultObject() + { + Code = "-1", + ReqCode = "", + Message = string.Join(",", errors.ToArray()) + }; + } + var dto = new TransferNoteDetailDTO(); + dto.InjectFrom(entity); + dto.ToLocationCode = toloc.Code; + dto.ToLocationGroup = tolocation.LocationGroupCode; + dto.ToLocationArea = tolocation.AreaCode; + dto.ToLocationErpCode = tolocation.ErpLocationCode; + + dto.ToWarehouseCode = tolocation.WarehouseCode; + dto.Qty = detail.MatQty; + dto.ToLot = !string.IsNullOrEmpty(detail.BatchAttr07) ? detail.BatchAttr07 : string.Empty; + dto.ToPackingCode = string.Empty; + + dto.FromWarehouseCode = fromlocation.WarehouseCode; + dto.FromLocationCode = fromlocation.Code; + dto.FromLocationGroup = fromlocation.LocationGroupCode; + dto.FromLocationArea = fromlocation.AreaCode; + dto.FromLocationErpCode = fromlocation.ErpLocationCode; + dto.Qty = detail.MatQty; + dto.FromLot = string.Empty; + dto.FromPackingCode = 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.RequestNumber, + Message = ex.Message, + }; + //await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.RequestNumber + }; + } + return ret; + } + private async Task PushOutTaskAsync(TransferNoteDTO job) + { + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.RequestNumber, + Message = "OK" + }; + //using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.Qty; + request.OrderNum = job.Number; + request.OrderType = EnumJobType.AssembleIssueJob.ToString(); + + var httpclient = _httpClientFactory.CreateClient(); + _agvOptions.Value.Address = string.IsNullOrEmpty(_agvOptions.Value.Address) + ? "http://7e42682n64.goho.co:21171/" + : _agvOptions.Value.Address; //测试地址 + _agvOptions.Value.Token = + string.IsNullOrEmpty(_agvOptions.Value.Token) ? string.Empty : _agvOptions.Value.Token; //测试token + _agvOptions.Value.UserName = + string.IsNullOrEmpty(_agvOptions.Value.UserName) ? "" : _agvOptions.Value.UserName; //测试用户名 + _agvOptions.Value.Password = + string.IsNullOrEmpty(_agvOptions.Value.Password) ? "" : _agvOptions.Value.Password; //测试密码 + _agvOptions.Value.Path = string.IsNullOrEmpty(_agvOptions.Value.Path) + ? "zozocnApi/custom/receiveProductionPlan" + : _agvOptions.Value.Path; //测试密码 + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + // _logger.LogInformation($"标志{flag}开始调用高通WMS:传递值{JsonSerializer.Serialize(main)}"); + if (!string.IsNullOrEmpty(_agvOptions.Value.Token)) + { + var token = _agvOptions.Value.Token; + httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + } + + if (!string.IsNullOrEmpty(_agvOptions.Value.UserName) && !string.IsNullOrEmpty(_agvOptions.Value.Password)) + { + var username = _agvOptions.Value.UserName; + var password = _agvOptions.Value.Password; + httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"))); + } + + var client = new AgvJobClient(_agvOptions.Value.Address, httpclient, _agvOptions.Value.Path); + ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); + + } + catch (Exception e) + { + ret = new AgvResultObject(); + ret.Code = "1"; + ret.Message = e.Message; + ret.ReqCode = job.RequestNumber; + //await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + return ret; + } + + + + + + + }