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/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs
index ca071cb4..0ffae671 100644
--- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs
+++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs
@@ -26,9 +26,7 @@ namespace Tnb.WarehouseMgr
{
private ISendMessageService? _sendService;
- protected override Task ExecuteAsync(CancellationToken stoppingToken)
- {
- return Task.Run(() =>
+ protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(() =>
{
//_sendService = App.GetRequiredService();
List toUserIds = new List() { "25398501929509" };
@@ -48,8 +46,8 @@ namespace Tnb.WarehouseMgr
//齐套分拣
var setSortingService = App.GetRequiredService();
TimedTask(cts => setSortingService.PackSortingByAdd(cts), setSortingCts, toUserIds);
- });
- }
+ }, stoppingToken);
+
private Task TimedTask(Func action, CancellationTokenSource cts, List? toUserIds = default)
{
var token = cts.Token;
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();
}
+
}
}