diff --git a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/test/TestAppService.cs b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/test/TestAppService.cs index c07f8a8ae..a31ae087b 100644 --- a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/test/TestAppService.cs +++ b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/test/TestAppService.cs @@ -108,11 +108,11 @@ public class TestService:ApplicationService //} [HttpPost("pushOutTask4FW")] - public async Task pushOutTask4FW(AgvRequest request) + public async Task pushOutTask4FW(AgvRequest1 request) { - AgvResultObject reusltObject = new AgvResultObject(); + AgvResultObject1 reusltObject = new AgvResultObject1(); reusltObject.Code = "0"; reusltObject.Message = "OK"; reusltObject.ReqCode = "T6000001970"; @@ -151,7 +151,7 @@ public class TestService:ApplicationService /// /// 发给立体库主表 /// -public class IssueJobToRestoDetailDTO +public class IssueJobToRestoDetailDTO1 { public string WorkNo { set; get; } public string TaskNo { set; get; } @@ -162,50 +162,50 @@ public class IssueJobToRestoDetailDTO /// /// 发给立体库子表 /// -public class IssueJobToRestoDTO +public class IssueJobToRestoDTO1 { public Guid UUID { set; get; } public string OperatorName { set; get; } - public List Details { set; get; } + public List Details { set; get; } } /// /// 返回结果 /// -public class ReusltObject +public class ReusltObject1 { public string Code { set; get; } public string Message { set; get; } public string OperateTime { set; get; } } -public class AgvResultObject +public class AgvResultObject1 { public string Code { set; get; } public string Message { set; get; } public string ReqCode { set; get; } } #region AGV -public class AgvRequestHK +public class AgvRequestHK1 { [Display(Name ="请求编号")] public string ReqCode { set; get; } [Display(Name ="明细")] - public List Data { set; get; } + public List Data { set; get; } } -public class AgvRequestInputHK +public class AgvRequestInputHK1 { //[Display(Name = "请求编号")] //public string ReqCode { set; get; } [Display(Name = "明细")] - public List Data { set; get; } + public List Data { set; get; } } -public class AgvRequestHKDetail +public class AgvRequestHKDetail1 { [Display(Name = "任务类型")] public string OrderType { set; get; } @@ -244,7 +244,7 @@ public class AgvRequestHKDetail /// /// 闻荫调海康入参 /// -public class AgvRequest +public class AgvRequest1 { [Display(Name = "任务类型")] public string OrderType { set; get; } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccountService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccount.cs similarity index 83% rename from be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccountService.cs rename to be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccount.cs index f1bbb2ead..b56a635c7 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/AgvJobs/IAgvJobAccountService.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 IAgvJobAccountService: IApplicationService +public interface IAgvJobAccountService { Task AccountOutOrderAsync(AgvRequestOnlyJobHK request); diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/ProxyIssueJobDto.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/IssueJobs/ProxyIssueJobDto.cs similarity index 98% rename from be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/ProxyIssueJobDto.cs rename to be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/IssueJobs/ProxyIssueJobDto.cs index 924054049..fbda13458 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/ProxyIssueJobDto.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application.Contracts/Jobs/IssueJobs/IssueJobs/ProxyIssueJobDto.cs @@ -5,7 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Win_in.Sfs.Wms.Store.Jobs.IssueJobs.proxy; +namespace Win_in.Sfs.Wms.Store.Application.Contracts; /// /// 喷涂主表 /// 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 new file mode 100644 index 000000000..999f39ec0 --- /dev/null +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobAccountService.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Uow; +using Volo.Abp.Users; +using Win_in.Sfs.Basedata.Application.Contracts; +using Win_in.Sfs.Basedata.Domain; +using Win_in.Sfs.Basedata.Domain.Shared; +using Win_in.Sfs.Shared.Domain.Shared; +using Win_in.Sfs.Wms.Inventory.Application.Contracts; +using Win_in.Sfs.Wms.Store.Application.Contracts; +using Win_in.Sfs.Wms.Store.Domain.Shared; + +namespace Win_in.Sfs.Wms.Store.Jobs.AgvJobs; + + +[AllowAnonymous] +[Route($"{StoreConsts.RootPath}agv-job-Account")] +public class AgvJobAccountService : ApplicationService +{ + + private readonly Func _Accessor; + + + public AgvJobAccountService( + Func Accessor + + + ) + { + _Accessor = Accessor; + + } + + public async Task AccountOutOrderAsync(AgvRequestOnlyJobHK request) + { + var res = new AgvResultObject(); + res.Code = "0"; + + 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; + + } + + +} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs new file mode 100644 index 000000000..4ebaffb6d --- /dev/null +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/AgvJobs/AgvJobOutputService.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using MyNamespace; +using Volo.Abp; +using Volo.Abp.Application.Services; +using Volo.Abp.Uow; +using Volo.Abp.Users; +using Win_in.Sfs.Basedata.Application.Contracts; +using Win_in.Sfs.Basedata.Domain; +using Win_in.Sfs.Basedata.Domain.Shared; +using Win_in.Sfs.Shared.Domain.Shared; +using Win_in.Sfs.Wms.Inventory.Application.Contracts; +using Win_in.Sfs.Wms.Store.Application.Contracts; +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 Microsoft.Extensions.Logging; +using Win_in.Sfs.Shared.Application.Contracts; + +namespace Win_in.Sfs.Wms.Store.Jobs.AgvJobs; +[AllowAnonymous] +[Route($"{StoreConsts.RootPath}agv-job-in")] +public class AgvJobOutputService : ApplicationService, IAgvJobOutputService +{ + private readonly UnitOfWorkManager _unitOfWorkManager; + private readonly IHttpClientFactory _httpClientFactory; + private readonly IOptions _options; + private readonly ILogger _logger; + + public AgvJobOutputService( + UnitOfWorkManager unitOfWorkManager, + IHttpClientFactory httpClientFactory, + IOptions options, + ILogger logger + + ) + { + _logger = logger; + _unitOfWorkManager = unitOfWorkManager; + _httpClientFactory = httpClientFactory; + _options = options; + } + + + + [HttpPost("out-put-task")] + public async Task OutPutTaskAsync(AgvRequest request) + { + var httpclient = _httpClientFactory.CreateClient(); + _options.Value.Address = string.IsNullOrEmpty(_options.Value.Address) + ? "http://7e42682n64.goho.co:21171/" + : _options.Value.Address; //测试地址 + _options.Value.Token = + string.IsNullOrEmpty(_options.Value.Token) ? string.Empty : _options.Value.Token; //测试token + _options.Value.UserName = + string.IsNullOrEmpty(_options.Value.UserName) ? "" : _options.Value.UserName; //测试用户名 + _options.Value.Password = + string.IsNullOrEmpty(_options.Value.Password) ? "" : _options.Value.Password; //测试密码 + _options.Value.Path = string.IsNullOrEmpty(_options.Value.Path) + ? "zozocnApi/custom/receiveProductionPlan" + : _options.Value.Path; //测试密码 + var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); + // _logger.LogInformation($"标志{flag}开始调用高通WMS:传递值{JsonSerializer.Serialize(main)}"); + if (!string.IsNullOrEmpty(_options.Value.Token)) + { + var token = _options.Value.Token; + httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); + } + + if (!string.IsNullOrEmpty(_options.Value.UserName) && !string.IsNullOrEmpty(_options.Value.Password)) + { + var username = _options.Value.UserName; + var password = _options.Value.Password; + httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"))); + } + + var client = new AgvJobClient(_options.Value.Address, httpclient, _options.Value.Path); + var ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); + + return ret; + + } + + +} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AgvJobs/AgvJobAccountService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AgvJobs/AgvJobAccountService.cs deleted file mode 100644 index 11f0d6d9f..000000000 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AgvJobs/AgvJobAccountService.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp; -using Volo.Abp.Application.Services; -using Volo.Abp.Uow; -using Volo.Abp.Users; -using Win_in.Sfs.Basedata.Application.Contracts; -using Win_in.Sfs.Basedata.Domain; -using Win_in.Sfs.Basedata.Domain.Shared; -using Win_in.Sfs.Shared.Domain.Shared; -using Win_in.Sfs.Wms.Inventory.Application.Contracts; -using Win_in.Sfs.Wms.Store.Application.Contracts; -using Win_in.Sfs.Wms.Store.Domain.Shared; - -namespace Win_in.Sfs.Wms.Store.Jobs.IssueJobs.AgvServices; - - -[AllowAnonymous] -[Route($"{StoreConsts.RootPath}agv-job-Account")] -public class AgvJobAccountService : ApplicationService, IAgvJobAccountService -{ - private IAssembleIssueJobAppService _assembleIssueJobAppService; - private ICoatingIssueJobAppService _coatingIssueJobAppService; - private IInjectionIssueJobAppService _injectionIssueJobAppService; - private IKittingIssueJobAppService _kittingIssueJobAppService; - private ISparePartIssueJobAppService _sparePartIssueJobAppService; - - public AgvJobAccountService( - - IAssembleIssueJobAppService assembleIssueJobAppService, - ICoatingIssueJobAppService coatingIssueJobAppService, - IInjectionIssueJobAppService injectionIssueJobAppService, - IKittingIssueJobAppService kittingIssueJobAppService, - ISparePartIssueJobAppService sparePartIssueJobAppService - - ) - { - _assembleIssueJobAppService = assembleIssueJobAppService; - _coatingIssueJobAppService= coatingIssueJobAppService; - _injectionIssueJobAppService= injectionIssueJobAppService; - _kittingIssueJobAppService = kittingIssueJobAppService; - _sparePartIssueJobAppService= sparePartIssueJobAppService; - } - - 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(); - - foreach (var detail in request.Data) - { - - } - - - - - var assemb=await _assembleIssueJobAppService.GetByNumberAsync(itm.OrderNum).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; - - } - } - - return null; - } -} diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AgvJobs/AgvJobOutputService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AgvJobs/AgvJobOutputService.cs deleted file mode 100644 index a4db72739..000000000 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/AgvJobs/AgvJobOutputService.cs +++ /dev/null @@ -1,155 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http.Headers; -using System.Net.Http; -using System.Text; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using MyNamespace; -using Volo.Abp; -using Volo.Abp.Application.Services; -using Volo.Abp.Uow; -using Volo.Abp.Users; -using Win_in.Sfs.Basedata.Application.Contracts; -using Win_in.Sfs.Basedata.Domain; -using Win_in.Sfs.Basedata.Domain.Shared; -using Win_in.Sfs.Shared.Domain.Shared; -using Win_in.Sfs.Wms.Inventory.Application.Contracts; -using Win_in.Sfs.Wms.Store.Application.Contracts; -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 Microsoft.Extensions.Logging; -using Win_in.Sfs.Shared.Application.Contracts; - -namespace Win_in.Sfs.Wms.Store.Jobs.IssueJobs.AgvServices; -[AllowAnonymous] -[Route($"{StoreConsts.RootPath}agv-job-in")] -public class AgvJobOutputService : ApplicationService, IAgvJobOutputService -{ - private readonly UnitOfWorkManager _unitOfWorkManager; - private readonly IHttpClientFactory _httpClientFactory; - private readonly IOptions _options; - private readonly ILogger _logger; - - public AgvJobOutputService( - UnitOfWorkManager unitOfWorkManager, - IHttpClientFactory httpClientFactory, - IOptions options, - ILogger logger - - ) - { - _logger = logger; - _unitOfWorkManager = unitOfWorkManager; - _httpClientFactory = httpClientFactory; - _options = options; - } - - - //public async Task OutPutTaskAsync(T entity) where T : SfsJobDTOBase - // where TDetail : SfsDetailDTOBase - //{ - // if (entity is CoatingIssueJobDTO) - // { - // var coating = entity as CoatingIssueJobDTO; - // var first = coating.Details.FirstOrDefault(); - // var requst = new AgvRequest(); - // requst.MatCode = first.ItemCode; - // requst.MatQty = first.HandledToQty; - // requst.OrderNum = entity.Number; - // requst.OrderType = "1"; - // await OutPutTaskAsync(requst).ConfigureAwait(false); - // } - // else if (entity is AssembleIssueJobDTO) - // { - // var assemble = entity as AssembleIssueJobDTO; - // var first = assemble.Details.FirstOrDefault(); - // var requst = new AgvRequest(); - // requst.MatCode = first.ItemCode; - // requst.MatQty = first.HandledToQty; - // requst.OrderNum = entity.Number; - // requst.OrderType = "2"; - // return await OutPutTaskAsync(requst).ConfigureAwait(false); - // } - // else if (entity is InjectionIssueJobDTO) - // { - // var injection = entity as InjectionIssueJobDTO; - // var first = injection.Details.FirstOrDefault(); - // var requst = new AgvRequest(); - // requst.MatCode = first.ItemCode; - // requst.MatQty = first.HandledToQty; - // requst.OrderNum = entity.Number; - // requst.OrderType = "3"; - - // return await OutPutTaskAsync(requst).ConfigureAwait(false); - // } - // else if (entity is KittingIssueJobDTO) - // { - // var kitting = entity as KittingIssueJobDTO; - // var first = kitting.Details.FirstOrDefault(); - // var requst = new AgvRequest(); - // requst.MatCode = first.ItemCode; - // requst.MatQty = first.HandledToQty; - // requst.OrderNum = entity.Number; - // requst.OrderType = "4"; - - // return await OutPutTaskAsync(requst).ConfigureAwait(false); - // } - // else if (entity is SparePartIssueJobDTO) - // { - // var sparePart = entity as SparePartIssueJobDTO; - // var first = sparePart.Details.FirstOrDefault(); - // var requst = new AgvRequest(); - // requst.MatCode = first.ItemCode; - // requst.MatQty = first.HandledToQty; - // requst.OrderNum = entity.Number; - // requst.OrderType = "1"; - - // await OutPutTaskAsync(requst).ConfigureAwait(false); - // } - //} - [HttpPost("out-put-task")] - public async Task OutPutTaskAsync(AgvRequest request) - { - var httpclient = _httpClientFactory.CreateClient(); - _options.Value.Address = string.IsNullOrEmpty(_options.Value.Address) - ? "http://7e42682n64.goho.co:21171/" - : _options.Value.Address; //测试地址 - _options.Value.Token = - string.IsNullOrEmpty(_options.Value.Token) ? string.Empty : _options.Value.Token; //测试token - _options.Value.UserName = - string.IsNullOrEmpty(_options.Value.UserName) ? "" : _options.Value.UserName; //测试用户名 - _options.Value.Password = - string.IsNullOrEmpty(_options.Value.Password) ? "" : _options.Value.Password; //测试密码 - _options.Value.Path = string.IsNullOrEmpty(_options.Value.Path) - ? "zozocnApi/custom/receiveProductionPlan" - : _options.Value.Path; //测试密码 - var flag = DateTime.Now.ToString("yyyyMMddHHmmss"); - // _logger.LogInformation($"标志{flag}开始调用高通WMS:传递值{JsonSerializer.Serialize(main)}"); - if (!string.IsNullOrEmpty(_options.Value.Token)) - { - var token = _options.Value.Token; - httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); - } - - if (!string.IsNullOrEmpty(_options.Value.UserName) && !string.IsNullOrEmpty(_options.Value.Password)) - { - var username = _options.Value.UserName; - var password = _options.Value.Password; - httpclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", - Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"))); - } - - var client = new AgvJobClient(_options.Value.Address, httpclient, _options.Value.Path); - var ret = await client.PushOutTask4FWAsync(request).ConfigureAwait(false); - - return ret; - - } - - -} 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 80564bf39..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 @@ -10,10 +10,12 @@ using Castle.Components.DictionaryAdapter; using DocumentFormat.OpenXml.Spreadsheet; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MyNamespace; using Omu.ValueInjecter; +using Org.BouncyCastle.Asn1.Ocsp; using Volo.Abp; using Volo.Abp.Domain.Entities; using Volo.Abp.Uow; @@ -36,7 +38,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class AssembleIssueJobAppService : SfsJobAppServiceBase, - IAssembleIssueJobAppService, ITransferLibCallback + IAssembleIssueJobAppService, ITransferLibCallback, IAgvJobAccountService { protected IAssembleIssueRequestAppService AssembleIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -51,24 +53,31 @@ public class AssembleIssueJobAppService private readonly ILogger _logger; private readonly ICurrentUser _currentUser; private readonly UnitOfWorkManager _unitOfWorkManager; + private readonly IOptions _agvOptions; + - private readonly IAgvJobOutputService _agvOutJob; + private readonly IPostionLocationAppService _postionLocationAppService; public AssembleIssueJobAppService( ILogger logger, - IAgvJobOutputService agvOutJob, + IAssembleIssueJobRepository repository, IAssembleIssueJobManager assembleIssueJobManager, ILocationAppService locationAppService, IAssembleIssueNoteAppService assembleIssueNoteAppService, IExpectOutAppService expectOutAppService ,IHttpClientFactory httpClientFactory ,IOptions options, ITransferLibRequestAppService transferLibRequestAppService, - ICurrentUser currentUser, UnitOfWorkManager unitOfWorkManager) : base( + ICurrentUser currentUser, UnitOfWorkManager unitOfWorkManager + , IOptions agvOptions + , IPostionLocationAppService postionLocationAppService + + ) : base( repository, assembleIssueJobManager ) { + _postionLocationAppService= postionLocationAppService; _assembleIssueJobManager = assembleIssueJobManager; _locationAppService = locationAppService; _assembleIssueNoteAppService = assembleIssueNoteAppService; @@ -79,8 +88,8 @@ public class AssembleIssueJobAppService _currentUser = currentUser; _unitOfWorkManager = unitOfWorkManager; _logger = logger; - _agvOutJob = agvOutJob; - + + _agvOptions = agvOptions; } [HttpPost("get-by-number-2")] @@ -655,11 +664,6 @@ public class AssembleIssueJobAppService var dtos = ObjectMapper.Map, List>(entities); - - - - - if (input.Jobs.Count != entities.Count) { errors.Add("立体库提交出库任务和WMS任务不符,请核对! \n"); @@ -679,18 +683,13 @@ public class AssembleIssueJobAppService { errors.Add($"来源库位{detail.FromLocationCode}没查到"); } - - var toloc = await _locationAppService.GetByCodeAsync(detail.ToLocationCode) .ConfigureAwait(false); if (toloc == null) { errors.Add($"目标库位{detail.ToLocationCode}没查到"); } - - var entity = itmDetails.FirstOrDefault(p => p.ItemCode == detail.ItemCode); - if (entity == null) { errors.Add($"物料号{detail.ItemCode}不在任务明细内!"); @@ -982,26 +981,234 @@ public class AssembleIssueJobAppService assembleIssueJobDetailDto.Status, assembleIssueJobDetailDto.HandledToLot, handledToQty).ConfigureAwait(false); } - - /// - /// 调用AgvOutPut出库 - /// - /// - /// - private async Task InvokeAgvOutput(AssembleIssueJobDTO job) + + + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(AssembleIssueJobDTO job) { + var ret = new AgvResultObject + { + Code = "0", + ReqCode=job.AssembleRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledToQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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.AssembleRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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.AssembleRequestNumber, + + }; + 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 first = job.Details.FirstOrDefault(); - var requst = new AgvRequest(); - requst.MatCode = first.ItemCode; - requst.MatQty = first.HandledToQty; - requst.OrderNum = job.Number; - requst.OrderType = "2"; - return await _agvOutJob.OutPutTaskAsync(requst).ConfigureAwait(false); + 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 AssembleIssueJobDetailDTO(); + 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.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/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/CoatingIssueJobs/CoatingIssueJobAppService.cs index bf671982a..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 @@ -13,11 +13,13 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MyNamespace; +using Omu.ValueInjecter; using Volo.Abp; using Volo.Abp.Domain.Entities; using Volo.Abp.ObjectMapping; using Volo.Abp.Uow; using Volo.Abp.Users; +using Win_in.Sfs.Basedata.Application; using Win_in.Sfs.Basedata.Application.Contracts; using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Shared.Domain.Shared.Enums.Store; @@ -36,7 +38,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class CoatingIssueJobAppService : SfsJobAppServiceBase, - ICoatingIssueJobAppService, ITransferLibCallback + ICoatingIssueJobAppService, ITransferLibCallback, IAgvJobAccountService { private readonly ICoatingIssueJobManager _coatingIssueJobManager; private readonly ILocationAppService _locationAppService; @@ -48,6 +50,10 @@ public class CoatingIssueJobAppService private readonly ILogger _logger; private readonly ICurrentUser _currentUser; private readonly IAgvJobOutputService _agvOutJob; + private readonly UnitOfWorkManager _unitOfWorkManager; + private readonly IOptions _agvOptions; + private readonly IPostionLocationAppService _postionLocationAppService; + protected ICoatingIssueRequestAppService CoatingIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -59,7 +65,10 @@ public class CoatingIssueJobAppService ILocationAppService locationAppService, ICoatingIssueNoteAppService coatingIssueNoteAppService, IExpectOutAppService expectOutAppService , IHttpClientFactory httpClientFactory - , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser) : base( + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, IOptions agvOptions + , UnitOfWorkManager unitOfWorkManager + , IPostionLocationAppService postionLocationAppService + ) : base( repository, coatingIssueJobManager) { _coatingIssueJobManager = coatingIssueJobManager; @@ -72,6 +81,9 @@ public class CoatingIssueJobAppService _currentUser = currentUser; _logger = logger; _agvOutJob = agvOutJob; + _unitOfWorkManager = unitOfWorkManager; + _agvOptions = agvOptions; + _postionLocationAppService = postionLocationAppService; } [HttpPost("get-by-number-2")] @@ -724,21 +736,226 @@ public class CoatingIssueJobAppService coatingIssueJobDetailDto.Status, coatingIssueJobDetailDto.HandledToLot, handledToQty).ConfigureAwait(false); } - /// - /// 调用AgvOutPut出库 - /// - /// - /// - private async Task InvokeAgvOutput(CoatingIssueJob job) + + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(CoatingIssueJobDTO job) { - - var first = job.Details.FirstOrDefault(); - var requst = new AgvRequest(); - requst.MatCode = first.ItemCode; - requst.MatQty = first.HandledToQty; - requst.OrderNum = job.Number; - requst.OrderType = "2"; - return await _agvOutJob.OutPutTaskAsync(requst).ConfigureAwait(false); + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.CoatingRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledToQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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.CoatingRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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.CoatingRequestNumber, + + }; + 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 CoatingIssueJobDetailDTO(); + 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.CoatingRequestNumber, + Message = ex.Message, + }; + await unitOfWork.RollbackAsync(); + return ret; + } + + if (errors.Count > 0) + { + ret = new AgvResultObject + { + Code = "-1", + Message = string.Join(",", errors.ToArray()), + ReqCode = job.CoatingRequestNumber + }; + } + return ret; } 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 40aaaa7c4..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; @@ -44,17 +46,25 @@ public class InjectionIssueJobAppService private readonly IOptions _options; private readonly ICurrentUser _currentUser; private readonly IAgvJobOutputService _agvOutJob; + 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 - , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser) : base( + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser + , IOptions agvOptions + , UnitOfWorkManager unitOfWorkManager + ) : base( repository, injectionIssueJobManager) { _injectionIssueJobManager = injectionIssueJobManager; @@ -65,7 +75,10 @@ public class InjectionIssueJobAppService _options = options; _transferLibRequestAppService = transferLibRequestAppService; _currentUser = currentUser; - _agvOutJob = agvOutJob; + _agvOutJob = agvOutJob; + _unitOfWorkManager = unitOfWorkManager; + _agvOptions = agvOptions; + _logger = logger; } [HttpPost("get-by-number-2")] public async Task GetByNumber2Async(string number) @@ -673,22 +686,227 @@ public class InjectionIssueJobAppService injectionIssueJobDetailDto.Status, injectionIssueJobDetailDto.HandledToLot, handledToQty).ConfigureAwait(false); } - /// - /// 调用AgvOutPut出库 - /// - /// - /// - private async Task InvokeAgvOutput(InjectionIssueJob job) + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(InjectionIssueJobDTO job) + { + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.InjectionRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledToQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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.InjectionRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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; - var first = job.Details.FirstOrDefault(); - var requst = new AgvRequest(); - requst.MatCode = first.ItemCode; - requst.MatQty = first.HandledToQty; - requst.OrderNum = job.Number; - requst.OrderType = "2"; - return await _agvOutJob.OutPutTaskAsync(requst).ConfigureAwait(false); + _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 7836c1c9f..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,17 +35,22 @@ namespace Win_in.Sfs.Wms.Store.Application; public class KittingIssueJobAppService : SfsJobAppServiceBase, - IKittingIssueJobAppService, ITransferLibCallback + IKittingIssueJobAppService, ITransferLibCallback,IAgvJobAccountService { private readonly IKittingIssueJobManager _kittingIssueJobManager; private readonly ILocationAppService _locationAppService; private readonly IKittingIssueNoteAppService _kittingIssueNoteAppService; private readonly IExpectOutAppService _expectOutAppService; - private readonly IHttpClientFactory _httpClientFactory; + private readonly ITransferLibRequestAppService _transferLibRequestAppService; private readonly IOptions _options; private readonly ICurrentUser _currentUser; private readonly IAgvJobOutputService _agvOutJob; + private readonly UnitOfWorkManager _unitOfWorkManager; + private readonly IHttpClientFactory _httpClientFactory; + private readonly IOptions _agvOptions; + private readonly IPostionLocationAppService _postionLocationAppService; + private readonly ILogger _logger; protected IKittingIssueRequestAppService KittingIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -52,9 +59,14 @@ 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) : base( + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser + ,IOptions agvOptions, + + + UnitOfWorkManager unitOfWorkManager + ) : base( repository, kittingIssueJobManager) { _agvOutJob = agvOutJob; @@ -67,6 +79,8 @@ public class KittingIssueJobAppService _transferLibRequestAppService = transferLibRequestAppService; _currentUser = currentUser; _agvOutJob = agvOutJob; + _unitOfWorkManager = unitOfWorkManager; + _agvOptions = agvOptions; } [HttpPost("get-by-number-2")] @@ -684,21 +698,225 @@ public class KittingIssueJobAppService kittingIssueJobDetailDto.Status, kittingIssueJobDetailDto.HandledToLot, handledToQty).ConfigureAwait(false); } - /// - /// 调用AgvOutPut出库 - /// - /// - /// - private async Task InvokeAgvOutput(KittingIssueJobDTO job) + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(KittingIssueJobDTO job) { + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.KittingRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledToQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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.KittingRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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 first = job.Details.FirstOrDefault(); - var requst = new AgvRequest(); - requst.MatCode = first.ItemCode; - requst.MatQty = first.HandledToQty; - requst.OrderNum = job.Number; - requst.OrderType = "2"; - return await _agvOutJob.OutPutTaskAsync(requst).ConfigureAwait(false); + 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; } 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 755087890..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; @@ -44,6 +46,10 @@ public class SparePartIssueJobAppService private readonly IOptions _options; private readonly ICurrentUser _currentUser; private readonly IAgvJobOutputService _agvOutJob; + private readonly UnitOfWorkManager _unitOfWorkManager; + private readonly IOptions _agvOptions; + private readonly IPostionLocationAppService _postionLocationAppService; + private readonly ILogger _logger; protected ISparePartIssueRequestAppService SparePartIssueRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -54,7 +60,9 @@ public class SparePartIssueJobAppService ILocationAppService locationAppService, ISparePartIssueNoteAppService sparePartIssueNoteAppService, IExpectOutAppService expectOutAppService , IHttpClientFactory httpClientFactory - , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser) : base( + , IOptions options, ITransferLibRequestAppService transferLibRequestAppService, ICurrentUser currentUser, ILogger logger + , UnitOfWorkManager unitOfWorkManager, IOptions agvOptions + ) : base( repository, sparePartIssueJobManager) { _sparePartIssueJobManager = sparePartIssueJobManager; @@ -66,6 +74,9 @@ public class SparePartIssueJobAppService _transferLibRequestAppService = transferLibRequestAppService; _currentUser = currentUser; _agvOutJob = agvOutJob; + _unitOfWorkManager = unitOfWorkManager; + _agvOptions = agvOptions; + _logger = logger; } [HttpPost("get-by-number-2")] @@ -665,21 +676,224 @@ public class SparePartIssueJobAppService handledToQty).ConfigureAwait(false); } - /// - /// 调用AgvOutPut出库 - /// - /// - /// - private async Task InvokeAgvOutput(SparePartIssueJobDTO job) + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(SparePartIssueJobDTO job) { + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.SparePartRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledToQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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 first = job.Details.FirstOrDefault(); - var requst = new AgvRequest(); - requst.MatCode = first.ItemCode; - requst.MatQty = first.HandledToQty; - requst.OrderNum = job.Number; - requst.OrderType = "2"; - return await _agvOutJob.OutPutTaskAsync(requst).ConfigureAwait(false); + 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.SparePartRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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; } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/IssueJobToRestoClient.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/IssueJobToRestoClient.cs index 26101a196..2b7ce5e24 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/IssueJobToRestoClient.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Jobs/IssueJobs/proxy/IssueJobToRestoClient.cs @@ -19,6 +19,7 @@ namespace MyNamespace { + using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Jobs.IssueJobs; using Win_in.Sfs.Wms.Store.Jobs.IssueJobs.proxy; using System = global::System; 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 e6fad894d..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 @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http.Headers; +using System.Net.Http; +using System.Text; using System.Threading.Tasks; using Castle.Components.DictionaryAdapter; using Irony; @@ -17,6 +20,12 @@ 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 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; @@ -25,7 +34,7 @@ namespace Win_in.Sfs.Wms.Store.Application; public class UnplannedIssueJobAppService : SfsJobAppServiceBase, - IUnplannedIssueJobAppService + IUnplannedIssueJobAppService,IAgvJobAccountService { protected IUnplannedIssueRequestAppService UnplannedReceiptRequestAppService => LazyServiceProvider.LazyGetRequiredService(); @@ -38,12 +47,21 @@ public class UnplannedIssueJobAppService private readonly ILogger _logger; private readonly IItemBasicAppService _itemBasicAppService; + 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) : base(repository, unplannedIssueJobManager) + IItemBasicAppService itemBasicAppService, IOptions agvOptions, + IPostionLocationAppService postionLocationAppService + + , IHttpClientFactory httpClientFactory + ) : base(repository, unplannedIssueJobManager) { _unplannedIssueJobManager = unplannedIssueJobManager; _locationAppService = locationAppService; @@ -52,6 +70,9 @@ public class UnplannedIssueJobAppService _unitOfWorkManager = unitOfWorkManager; _logger = logger; _itemBasicAppService = itemBasicAppService; + _agvOptions = agvOptions; + _httpClientFactory = httpClientFactory; + _postionLocationAppService = postionLocationAppService; } /// @@ -631,4 +652,225 @@ public class UnplannedIssueJobAppService return handleDto; } + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(UnplannedIssueJobDTO job) + { + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.UnplannedIssueRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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.UnplannedIssueRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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 0fd0d5e92..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 @@ -15,6 +15,9 @@ using Win_in.Sfs.Wms.Store.Domain.Shared; namespace Win_in.Sfs.Wms.Store.Application; using System.Linq; +using System.Net.Http.Headers; +using System.Net.Http; +using System.Text; using System.Text.Json; using Castle.Components.DictionaryAdapter; @@ -25,13 +28,20 @@ using Win_in.Sfs.Basedata.Application.Contracts; using Win_in.Sfs.Basedata.Domain; using Win_in.Sfs.Shared.Event; using Win_in.Sfs.Wms.Inventory.Application.Contracts; +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(); @@ -41,18 +51,36 @@ public class UnplannedReceiptJobAppService private readonly IBalanceAppService _balanceAppService; private readonly IExpectOutAppService _expectOutAppService; private readonly IItemBasicAppService _itemBasicAppService; + 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) : base(repository, UnplannedReceiptJobManager) + IExpectOutAppService expectOutAppService, IItemBasicAppService itemBasicAppService, + IOptions agvOptions, + IHttpClientFactory httpClientFactory, + IUnitOfWorkManager unitOfWorkManager, + ILogger logger + + + ) : base(repository, UnplannedReceiptJobManager) { _unplannedReceiptJobManager = UnplannedReceiptJobManager; _locationAppService = locationAppService; _balanceAppService = balanceAppService; _expectOutAppService = expectOutAppService; _itemBasicAppService = itemBasicAppService; + _agvOptions = agvOptions; + _httpClientFactory = httpClientFactory; + _unitOfWorkManager = unitOfWorkManager; + _logger = logger; + _postionLocationAppService = postionLocationAppService; } @@ -295,4 +323,228 @@ public class UnplannedReceiptJobAppService } return true; } + /// + /// + /// + /// + /// + [HttpPost("PushOutTask")] + public async Task PushOutTaskAsync(UnplannedReceiptJobDTO job) + { + var ret = new AgvResultObject + { + Code = "0", + ReqCode = job.UnplannedReceiptRequestNumber, + Message = "OK" + }; + using var unitOfWork = _unitOfWorkManager.Begin(); + try + { + var first = job.Details.FirstOrDefault(); + var request = new AgvRequest(); + request.MatCode = first.ItemCode; + request.MatQty = first.HandledQty; + request.OrderNum = job.Number; + request.OrderType = "2"; + + 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.UnplannedReceiptRequestNumber; + await unitOfWork.RollbackAsync().ConfigureAwait(false); + + } + 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 =>