From 3923c6a698d8a784df5b7263e2763e2c2c5bf0fa Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 7 Aug 2023 13:32:59 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=94=9F=E6=88=90=E9=A2=84=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=89=A7=E8=A1=8C=E8=B0=83=E7=94=A8Wcs=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BB=BB=E5=8A=A1=E9=93=BE=E6=8E=A5=E5=8F=A3=202?= =?UTF-8?q?=E3=80=81Common=E6=96=B0=E5=A2=9EConfigurationExtenstions?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Configs/AgvRequestConfig.cs | 25 ++++++++++++++ .../Tnb.WarehouseMgr/WareHouseService.cs | 34 +++++++++++++------ .../Configurations/AgvRequestCfgUrl.json | 6 ++++ .../Extension/ConfigurationExtensions.cs | 24 +++++++++++++ common/Tnb.Common/Utils/HttpClientHelper.cs | 6 ++-- 5 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Configs/AgvRequestConfig.cs create mode 100644 apihost/Tnb.API.Entry/Configurations/AgvRequestCfgUrl.json create mode 100644 common/Tnb.Common/Extension/ConfigurationExtensions.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Configs/AgvRequestConfig.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Configs/AgvRequestConfig.cs new file mode 100644 index 00000000..ac28e5aa --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Configs/AgvRequestConfig.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Configs +{ + public class AgvRequestConfig + { + public AgvRequestConfiguration AgvRequestUrls { get; set; } + } + + public class AgvRequestConfiguration + { + /// + /// 创建任务链url请求地址 + /// + public string CreateTaskChainUrl { get; set; } + /// + /// 取消任务链url请求地址 + /// + public string CancelTaskChainUrl { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index e3a1ca22..e779085e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Aop.Api.Domain; using Aspose.Cells.Drawing; using Dm; +using JNPF; using JNPF.Common.Contracts; using JNPF.Common.Core.Manager; using JNPF.Common.Enums; @@ -27,6 +28,7 @@ using Mapster; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.CodeAnalysis; +using Newtonsoft.Json; using NPOI.HPSF; using NPOI.OpenXmlFormats.Wordprocessing; using NPOI.SS.Formula.Functions; @@ -37,8 +39,10 @@ using Spire.Pdf.Widget; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.BasicData.Entities.Enums; +using Tnb.Common.Extension; using Tnb.Common.Utils; using Tnb.WarehouseMgr.Entities; +using Tnb.WarehouseMgr.Entities.Configs; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Entities.Dto.Inputs; @@ -193,7 +197,7 @@ namespace Tnb.WarehouseMgr .And((a, b, c) => c.wh_id == input.warehouse_id) .AndIF(!string.IsNullOrEmpty(input.material_id), (a, b, c) => b.material_id == input.material_id) .AndIF(!string.IsNullOrEmpty(input.code_batch), (a, b, c) => b.code_batch == input.code_batch) - .AndIF(!string.IsNullOrEmpty(input.carrystd_id), (a,b,c)=>a.carrystd_id == input.carrystd_id); + .AndIF(!string.IsNullOrEmpty(input.carrystd_id), (a, b, c) => a.carrystd_id == input.carrystd_id); Expression> carryStatusFilterExp = !input.material_id.IsNullOrWhiteSpace() ? (a, b, c) => a.carry_status == ((int)EnumCarryStatus.占用).ToString() : (a, b, c) => a.carry_status == ((int)EnumCarryStatus.空闲).ToString(); @@ -217,7 +221,6 @@ namespace Tnb.WarehouseMgr [HttpPost] public async Task GenTaskExecute(CancellationTokenSource? cts = default) { - Stopwatch sw = Stopwatch.StartNew(); var db = _db.CopyNew(); try @@ -313,7 +316,6 @@ namespace Tnb.WarehouseMgr disTasks.AddRange(items); } - await db.Ado.BeginTranAsync(); //disTasks.ForEach(x => x.id = SnowflakeIdHelper.NextId()); @@ -328,7 +330,13 @@ namespace Tnb.WarehouseMgr row = await db.Updateable().SetColumns(it => new WmsPretaskH { status = WmsWareHouseConst.PRETASK_BILL_STATUS_YXF_ID }).Where(it => preTaskIds.Contains(it.id)).ExecuteCommandAsync(); } + sw.Stop(); + JNPF.Logging.Log.Information($"程序运行耗时{sw.ElapsedMilliseconds}ms"); + await db.Ado.CommitTranAsync(); + + //调用AGV创建任务链接口 + var requestCfg = App.Configuration.Build(); var taskChainCodeDic = disTasks.Where(t => !t.groups.IsNullOrWhiteSpace()).GroupBy(g => g.groups!) .ToDictionary(x => x.Key, x => x.Select(it => new { @@ -336,18 +344,22 @@ namespace Tnb.WarehouseMgr sourceName = it.startlocation_code, targetName = it.endlocation_code })); - - dynamic reqBody = new ExpandoObject(); - - sw.Stop(); - JNPF.Logging.Log.Information($"程序运行耗时{sw.ElapsedMilliseconds}ms"); - await db.Ado.CommitTranAsync(); - + foreach (var (k, v) in taskChainCodeDic) + { + dynamic reqBody = new ExpandoObject(); + reqBody.taskChainCode = k; + reqBody.type = 3; + reqBody.sequential = false; + reqBody.taskChainPriority = 0; + reqBody.taskList = v; + await HttpClientHelper.PostStreamAsync(requestCfg.AgvRequestUrls.CreateTaskChainUrl, reqBody, CancellationToken.None); + //await HttpClientHelper.HttpPostAsync(url, JsonConvert.SerializeObject(reqBody)); + } } } catch (Exception ex) { - JNPF.Logging.Log.Error("生成预任务执行时出现错误",ex); + JNPF.Logging.Log.Error("生成预任务执行时出现错误", ex); await db.Ado.RollbackTranAsync(); cts?.Cancel(); throw; diff --git a/apihost/Tnb.API.Entry/Configurations/AgvRequestCfgUrl.json b/apihost/Tnb.API.Entry/Configurations/AgvRequestCfgUrl.json new file mode 100644 index 00000000..21be4b8e --- /dev/null +++ b/apihost/Tnb.API.Entry/Configurations/AgvRequestCfgUrl.json @@ -0,0 +1,6 @@ +{ + "AgvRequestUrls": { + "CreateTaskChainUrl": "http://localhost/api/task‑chain/create", + "CancelTaskChainUrl": "http://localhost/api/task‑chain/cancel" + } +} \ No newline at end of file diff --git a/common/Tnb.Common/Extension/ConfigurationExtensions.cs b/common/Tnb.Common/Extension/ConfigurationExtensions.cs new file mode 100644 index 00000000..d0c8173d --- /dev/null +++ b/common/Tnb.Common/Extension/ConfigurationExtensions.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; + +namespace Tnb.Common.Extension +{ + /// + /// 应用配置扩展 + /// added by ly on 20230807 + /// + public static class ConfigurationExtensions + { + public static T Build(this IConfiguration configuration) where T : class, new() + { + T instance = new(); + configuration.Bind(instance); + return instance; + } + + } +} diff --git a/common/Tnb.Common/Utils/HttpClientHelper.cs b/common/Tnb.Common/Utils/HttpClientHelper.cs index 274ece91..a99cce54 100644 --- a/common/Tnb.Common/Utils/HttpClientHelper.cs +++ b/common/Tnb.Common/Utils/HttpClientHelper.cs @@ -129,10 +129,10 @@ namespace Tnb.Common.Utils } - private static async Task PostStreamAsync(object content, CancellationToken cancellationToken) + public static async Task PostStreamAsync(string url,object content, CancellationToken cancellationToken) { using (var client = new HttpClient()) - using (var request = new HttpRequestMessage(HttpMethod.Post, Url)) + using (var request = new HttpRequestMessage(HttpMethod.Post, url)) using (var httpContent = CreateHttpContent(content)) { request.Content = httpContent; @@ -142,7 +142,9 @@ namespace Tnb.Common.Utils .ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); + return await response.Content.ReadAsStringAsync(); } + } }