From 74118cccf488d41e6467e9b5a50121d09afb4813 Mon Sep 17 00:00:00 2001 From: "yang.lee" Date: Tue, 31 Oct 2023 17:37:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=B1=BB=202=E3=80=81=E8=B0=83=E6=95=B4=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B0=86=E5=AE=9A=E6=97=B6=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E6=A1=86=E6=9E=B6=E7=9A=84=E4=BA=8B=E4=BB=B6=E6=80=BB?= =?UTF-8?q?=E7=BA=BF=203=E3=80=81=E7=94=B5=E6=A2=AF=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/Inputs/TaskCompleUpInput.cs | 1 + .../Dto/Inputs/TaskExecuteAfterUpInput.cs | 3 +- .../Entity/WmsElevatorH.part.cs | 49 ++++ .../Tnb.WarehouseMgr/BaseWareHouseService.cs | 20 +- .../BaseWareHouseService`1.cs | 17 +- .../ConditionalBackgroundService.cs | 30 -- .../Tnb.WarehouseMgr/DeviceProviderService.cs | 129 +++++---- WarehouseMgr/Tnb.WarehouseMgr/Dijkstra.cs | 215 -------------- WarehouseMgr/Tnb.WarehouseMgr/Dp.cs | 69 ----- .../TaskStatusChangeSubscriber.cs | 47 ++++ .../Tnb.WarehouseMgr/WareHouseService.cs | 263 +++++++++++------- .../WmsCarryMoveInStockService.cs | 8 +- .../WmsCarryMoveOutStockService.cs | 5 +- .../Tnb.WarehouseMgr/WmsCheckTaskService.cs | 6 +- .../Tnb.WarehouseMgr/WmsDeliveryService.cs | 10 +- .../WmsEmptyInstockService.cs | 7 +- .../WmsEmptyOutstockService .cs | 6 +- .../Tnb.WarehouseMgr/WmsInStockService.cs | 6 +- .../WmsKittingInStkService.cs | 6 +- .../Tnb.WarehouseMgr/WmsOutBaleService.cs | 6 +- .../Tnb.WarehouseMgr/WmsOutStockService.cs | 4 +- .../WmsPDACarryMoveInStockService.cs | 6 +- .../WmsPDACarryMoveOutStockService.cs | 7 +- .../Tnb.WarehouseMgr/WmsPDADeliveryService.cs | 6 +- .../WmsPDAEmptyInstockService.cs | 4 +- .../WmsPDAEmptyOutstockService .cs | 6 +- .../Tnb.WarehouseMgr/WmsPDAInStockService.cs | 10 +- .../Tnb.WarehouseMgr/WmsPDAInbaleService.cs | 8 +- .../WmsPDAKittingInStkService.cs | 5 +- .../WmsPDAOutBaleServiceService.cs | 6 +- .../WmsPDAScanInStockService.cs | 6 +- .../Tnb.WarehouseMgr/WmsPDATransferService.cs | 6 +- .../WmsRobotCallbackService.cs | 6 +- .../Tnb.WarehouseMgr/WmsSetSortingService.cs | 6 +- .../Tnb.WarehouseMgr/WmsTransferService.cs | 10 +- .../Tnb.WarehouseMgr/WmskittingOutService.cs | 11 +- apihost/Tnb.API.Entry/Startup.cs | 4 +- .../Constants/EventSubscribeEventConsts.cs | 17 ++ .../Sources/TaskStatusChangeSource.cs | 51 ++++ common/Tnb.Common/Extension/Extensions.cs | 8 + 40 files changed, 542 insertions(+), 548 deletions(-) delete mode 100644 WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs delete mode 100644 WarehouseMgr/Tnb.WarehouseMgr/Dijkstra.cs delete mode 100644 WarehouseMgr/Tnb.WarehouseMgr/Dp.cs create mode 100644 WarehouseMgr/Tnb.WarehouseMgr/EventSubscribers/TaskStatusChangeSubscriber.cs create mode 100644 common/Tnb.Common.Core/EventBus/Constants/EventSubscribeEventConsts.cs create mode 100644 common/Tnb.Common.Core/EventBus/Sources/TaskStatusChangeSource.cs diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskCompleUpInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskCompleUpInput.cs index b312aaeb..a9a09e06 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskCompleUpInput.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskCompleUpInput.cs @@ -15,5 +15,6 @@ namespace Tnb.WarehouseMgr.Entities.Dto.Inputs /// 任务执行Ids /// public List disTaskIds { get; set; } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskExecuteAfterUpInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskExecuteAfterUpInput.cs index 2489ece5..ccf2943c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskExecuteAfterUpInput.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Inputs/TaskExecuteAfterUpInput.cs @@ -14,6 +14,7 @@ namespace Tnb.WarehouseMgr.Entities.Dto.Inputs /// /// 任务执行Ids /// - public List disTaskIds { get; set; } + public List disTaskIds { get; set; } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.part.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.part.cs index 69a3bc44..ce417fad 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.part.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.part.cs @@ -13,4 +13,53 @@ public partial class WmsElevatorH { [SugarColumn(IsIgnore = true)] public int end_floor { get; set; } + /// + /// 上级表单ID + /// + [SugarColumn(IsIgnore = true)] + public string bill_id { get; set; } = string.Empty; + + /// + /// 库位ID + /// + [SugarColumn(IsIgnore = true)] + + public string location_id { get; set; } = string.Empty; + + /// + /// 库位编号 + /// + [SugarColumn(IsIgnore = true)] + + public string location_code { get; set; } = string.Empty; + + /// + /// 点位ID + /// + [SugarColumn(IsIgnore = true)] + + public string point_id { get; set; } = string.Empty; + + /// + /// 点位编号 + /// + [SugarColumn(IsIgnore = true)] + + public string point_code { get; set; } = string.Empty; + + /// + /// 楼层 + [SugarColumn(IsIgnore = true)] + + public int floor { get; set; } + /// + /// 执行任务Id + /// + [SugarColumn(IsIgnore = true)] + public string distask_id { get; set; } + /// + /// 设备Id + /// + [SugarColumn(IsIgnore = true)] + public string device_id { get; set; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs index 7f4e2ecd..b36c6f0a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs @@ -19,6 +19,7 @@ using JNPF.Common.Extension; using JNPF.DataEncryption; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.EventBus; using JNPF.Extras.CollectiveOAuth.Enums; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; @@ -34,6 +35,8 @@ using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using SqlSugar; using Tnb.BasicData.Entities; +using Tnb.Common.Core.EventBus.Constants; +using Tnb.Common.Core.EventBus.Sources; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Consts; @@ -53,14 +56,21 @@ namespace Tnb.WarehouseMgr private static Lazy> _stroageMapLazy; private static Dictionary _storeMap = new(StringComparer.OrdinalIgnoreCase); public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); - private readonly ChannelWriter _channelWriter; + private IEventPublisher _eventPublisher; + + protected IEventPublisher EventPublisher + { + set { _eventPublisher = value; } + get { return _eventPublisher; } + } - public BaseWareHouseService(ChannelWriter? channelWriter = default) + + /*public BaseWareHouseService(ChannelWriter? channelWriter = default) { _channelWriter = channelWriter; - } + }*/ static BaseWareHouseService() { @@ -160,9 +170,7 @@ namespace Tnb.WarehouseMgr [NonAction] protected async Task Publish(string taskName) { - NotifyMessage message = new() { TaskName = taskName }; - if (_channelWriter != null) - await _channelWriter.WriteAsync(message); + await _eventPublisher.PublishAsync(new TaskStatusChangeSource(EventSubscribeEventConsts.TaskStatusChangeEventId, taskName)); } [NonAction] diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService`1.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService`1.cs index 49f33d92..13ef3e0e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService`1.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService`1.cs @@ -6,11 +6,26 @@ using System.Threading.Tasks; using JNPF.Common.Contracts; using JNPF.Logging; using Microsoft.Extensions.Logging; +using SqlSugar; +using Tnb.WarehouseMgr.Entities; namespace Tnb.WarehouseMgr { - public class BaseWareHouseService : BaseWareHouseService + public class BaseWareHouseService : BaseWareHouseService { + protected static Dictionary _elevatorMap = new Dictionary(); + + public BaseWareHouseService(ISqlSugarClient db) + { + if (_elevatorMap.Count < 1) + { + Task.Run(async () => + { + _elevatorMap = await db.Queryable().ToDictionaryAsync(x =>x.elevator_id,x=>x.elevator_code); + }); + } + } + protected ILogger Logger => LoggerFactory.Create(builder => builder.AddFile($"{AppContext.BaseDirectory}/logs/custom{DateTime.Now:yyyyMMdd}.log", cfgOpts => { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs deleted file mode 100644 index 745a3cf2..00000000 --- a/WarehouseMgr/Tnb.WarehouseMgr/ConditionalBackgroundService.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Extensions.Hosting; - -namespace Tnb.WarehouseMgr -{ - public class ConditionalBackgroundService : IHostedService - { - private readonly IHostedService _backgroundService; - //private readonly Func _condition; - - public ConditionalBackgroundService(IHostedService backgroundService) - { - _backgroundService = backgroundService; - } - - public async Task StartAsync(CancellationToken cancellationToken) - { - await _backgroundService.StartAsync(cancellationToken); - } - public async Task StopAsync(CancellationToken cancellationToken) - { - await _backgroundService.StopAsync(cancellationToken); - } - - } -} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs b/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs index 06d111fc..53b0c000 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs @@ -61,7 +61,7 @@ namespace Tnb.WarehouseMgr IEventPublisher eventPublisher, IUserManager userManger, IElevatorControlService elevatorControlService - ) + ) : base(repository.AsSugarClient()) { _db = repository.AsSugarClient(); _wareHouseService = wareHouseService; @@ -92,32 +92,43 @@ namespace Tnb.WarehouseMgr { Log.Information("取货确认.................."); - try - { - var elevator = await _db.Queryable().LeftJoin((a, b) => a.id == b.bill_id) + var elevator = await _db.Queryable().LeftJoin((a, b) => a.id == b.bill_id) .LeftJoin((a, b, c) => b.location_id == c.startlocation_id) .LeftJoin((a, b, c, d) => c.startlocation_id == d.location_id) .Where((a, b, c, d) => d.point_code == input.sourceName && input.taskCode.Contains(c.bill_code)) + .Select((a, b, c, d) => new WmsElevatorH + { + distask_id = c.id, + device_id = c.device_id, + }, true) .FirstAsync(); - //Log.Information($"elevator!=null?{elevator!=null}"); - - (int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(_eleCtlCfg.DevName, CancellationToken.None); - Logger.Information($"电梯当前状态->系统状态:{sysStatus.ToEnum().ToString()},运行状态:{runStatus.ToEnum().ToString()},Agv状态:{agvStatus.ToEnum().ToString()},当前楼层:{floorNo}"); + if (elevator.IsNull()) + { + Logger.Error("未找到匹配的电梯任务", new Exception($"根据参数,sourceName:{input.sourceName},taskCode:{input.taskCode},未找到匹配的电梯任务")); + return await ToApiResult(HttpStatusCode.InternalServerError, $"根据参数,sourceName:{input.sourceName},taskCode:{input.taskCode},未找到匹配的电梯任务"); + } + try + { + Logger.Information($"当前任务Id:{elevator.distask_id}"); + if (_elevatorMap.TryGetValue(elevator.device_id, out var elevatorCode)) { - //var endFloor = elevator.end_floor; - var floor = 5; - if (doorStatus.ToEnum() != EnumDoorStatus.开门到位保持) + var devName = elevatorCode?.ToString() ?? _eleCtlCfg.DevName; + (int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(devName, CancellationToken.None); + Logger.Information($"电梯当前状态->系统状态:{sysStatus.ToEnum().ToString()},运行状态:{runStatus.ToEnum().ToString()},Agv状态:{agvStatus.ToEnum().ToString()},当前楼层:{floorNo}"); { - await _elevatorControlService.SendOpenCloseCmd(_eleCtlCfg.DevName, 3); //发送电梯前门开门指令 + if (doorStatus.ToEnum() != EnumDoorStatus.开门到位保持) + { + await _elevatorControlService.SendOpenCloseCmd(devName, 3); //发送电梯前门开门指令 + } + if (sysStatus.ToEnum() == EnumSysStatus.正常状态 && runStatus.ToEnum() == EnumRunStatus.停梯) + { + //elevator.current_floor = floor; + //await _db.Updateable(elevator).UpdateColumns(it => it.current_floor).ExecuteCommandAsync(); + return await ToApiResult(HttpStatusCode.OK, "成功"); + } + return await ToApiResult(HttpStatusCode.InternalServerError, "电梯还未开门,请重试!"); } - if (sysStatus.ToEnum() == EnumSysStatus.正常状态 && runStatus.ToEnum() == EnumRunStatus.停梯) - { - //elevator.current_floor = floor; - //await _db.Updateable(elevator).UpdateColumns(it => it.current_floor).ExecuteCommandAsync(); - return await ToApiResult(HttpStatusCode.OK, "成功"); - } - return await ToApiResult(HttpStatusCode.InternalServerError, "电梯还未开门,请重试!"); } } @@ -145,48 +156,59 @@ namespace Tnb.WarehouseMgr .LeftJoin((a, b, c) => b.location_id == c.endlocation_id) .LeftJoin((a, b, c, d) => c.endlocation_id == d.location_id) .Where((a, b, c, d) => d.point_code == input.targetName && c.bill_code == input.taskCode) - .Select((a, b, c, d) => new WmsElevatorH { end_floor = SqlFunc.ToInt32(c.end_floor) }, true) + .Select((a, b, c, d) => new WmsElevatorH + { + end_floor = SqlFunc.ToInt32(c.end_floor), + distask_id = c.id, + }, true) .FirstAsync(); - - (int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(_eleCtlCfg.DevName, CancellationToken.None);//elevator.elevator_code - Logger.Information($"电梯当前状态->系统状态:{sysStatus.ToEnum().ToString()},运行状态:{runStatus},门状态:{doorStatus},Agv状态:{agvStatus},当前楼层:{floorNo}"); - //判断Agv电梯是否进入状态 - if (agvStatus != (int)EnumAgvStatus.AGV运行状态) + if (elevator.IsNull()) + throw new Exception($"根据参数,sourceName:{input.sourceName},taskCode:{input.taskCode},未找到匹配的电梯任务"); + if (_elevatorMap.TryGetValue(elevator.elevator_id, out var elevatorCode)) { - await _elevatorControlService.WriteTagAsync(_eleCtlCfg.DevName, ElevatorConsts.AGVControl, 1); - } - - Logger.Information("目前正常"); - - //电梯到达目标楼层后,判断当前电梯门状态是否为开门到位保持状态 - if (doorStatus != (int)EnumDoorStatus.开门到位保持) - { - await _elevatorControlService.SendOpenCloseCmd(_eleCtlCfg.DevName, 3); //发送电梯前门开门指令 - } - if (sysStatus == (int)EnumSysStatus.正常状态 && runStatus == (int)EnumRunStatus.停梯 - && doorStatus == (int)EnumDoorStatus.开门到位保持) - { - Log.Information("进入开门状态,马上要成功了"); - try + (int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(_eleCtlCfg.DevName, CancellationToken.None);//elevator.elevator_code + Logger.Information($"电梯当前状态->系统状态:{sysStatus.ToEnum().ToString()},运行状态:{runStatus},门状态:{doorStatus},Agv状态:{agvStatus},当前楼层:{floorNo}"); + //判断Agv电梯是否进入状态 + if (agvStatus != (int)EnumAgvStatus.AGV运行状态) { - /* elevator.current_floor = elevator.end_floor; - await _db.Updateable(elevator).UpdateColumns(it => it.current_floor).ExecuteCommandAsync();*/ - - } - catch (Exception ex) - { - Logger.LogError("更新延迟队列异常", ex); - throw; + await _elevatorControlService.WriteTagAsync(_eleCtlCfg.DevName, ElevatorConsts.AGVControl, 1); } - return await ToApiResult(HttpStatusCode.OK, "成功"); + Logger.Information("目前正常"); + + //电梯到达目标楼层后,判断当前电梯门状态是否为开门到位保持状态 + if (doorStatus != (int)EnumDoorStatus.开门到位保持) + { + await _elevatorControlService.SendOpenCloseCmd(_eleCtlCfg.DevName, 3); //发送电梯前门开门指令 + } + if (sysStatus == (int)EnumSysStatus.正常状态 && runStatus == (int)EnumRunStatus.停梯 + && doorStatus == (int)EnumDoorStatus.开门到位保持) + { + Log.Information("进入开门状态,马上要成功了"); + try + { + /* elevator.current_floor = elevator.end_floor; + await _db.Updateable(elevator).UpdateColumns(it => it.current_floor).ExecuteCommandAsync();*/ + + } + catch (Exception ex) + { + Logger.LogError("更新延迟队列异常", ex); + throw; + } + + return await ToApiResult(HttpStatusCode.OK, "成功"); + } } + + return await ToApiResult(HttpStatusCode.InternalServerError, "电梯还未开门,请重试!"); } - catch (Exception) + catch (Exception ex) { + Logger.Error("放货确认失败", ex); return await ToApiResult(HttpStatusCode.InternalServerError, "电梯还未开门,请重试!"); throw; } @@ -271,7 +293,7 @@ namespace Tnb.WarehouseMgr disTaskIds = disTasks.Select(x => x.id).ToList() }; await _wareHouseService.TaskExecuteAfter(taskExecuteAfterUpInput); - Logger.Information("Agv取货完成"); + Logger.Information($"Agv取货完成,任务Id:{string.Join(",", disTasks.Select(x => x.id))}"); var elevatorQueueItem = await _db.Queryable().FirstAsync(it => disTasks.Select(x => x.id).Contains(it.distask_id) && it.task_status == "执行中"); if (elevatorQueueItem != null) { @@ -285,11 +307,6 @@ namespace Tnb.WarehouseMgr { await _elevatorControlService.SendOpenCloseCmd(elevatorQueueItem.elevator_code, 4); //向电梯发送前门关门指令 await _db.Deleteable(elevatorQueueItem).ExecuteCommandAsync(); - elevatorQueueItem = await _db.Queryable().FirstAsync(it => disTasks.Select(x => x.id).Contains(it.distask_id) && it.task_status == "待执行"); - if (!elevatorQueueItem?.elevator_code.IsNullOrEmpty() ?? false) - { - await (_wareHouseService.AddUnExecuteTask?.Invoke(elevatorQueueItem?.elevator_code!, disTask.start_floor.ParseToInt()) ?? Task.CompletedTask); - } } } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/Dijkstra.cs b/WarehouseMgr/Tnb.WarehouseMgr/Dijkstra.cs deleted file mode 100644 index c3ef70f9..00000000 --- a/WarehouseMgr/Tnb.WarehouseMgr/Dijkstra.cs +++ /dev/null @@ -1,215 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using JNPF.Common.Contracts; -using NPOI.SS.Formula.Functions; -using Tnb.WarehouseMgr.Entities; - -namespace Tnb.WarehouseMgr -{ - /// - /// 迪杰斯特拉(最短路径算法) - /// - //public class Dijkstra where T : BaseEntity, IWmsRoadEntity, new() - //{ - // public static int MAX = int.MaxValue; - - // public int mEdgNum; // 边的数量 - // public VNode[] mVexs; // 顶点数组 - // //private EData[] edges; //边的数组 - // /* - // * 创建图 - // * - // * 参数说明: - // * vexs -- 顶点数组 - // * edges -- 边 - // */ - // public Dijkstra(string[] vexs, EData[] edges) - // { - - // // 初始化"顶点数"和"边数" - // int vlen = vexs.Length; - // int elen = edges.Length; - - // // 初始化"顶点" - // mVexs = new VNode[vlen]; - // for (int i = 0; i < mVexs.Length; i++) - // { - // mVexs[i] = new VNode(); - // mVexs[i].data = vexs[i]; - // mVexs[i].firstEdge = null; - // } - - // // 初始化"边" - // mEdgNum = elen; - // for (int i = 0; i < elen; i++) - // { - // // 读取边的起始顶点和结束顶点 - // string c1 = edges[i].start; - // string c2 = edges[i].end; - // int weight = edges[i].weight; - - // // 读取边的起始顶点和结束顶点 - // int p1 = GetPosition(c1); - // int p2 = GetPosition(c2); - // // 初始化node1 - // ENode node1 = new ENode(); - // node1.ivex = p2; - // node1.weight = weight; - // // 将node1链接到"p1所在链表的末尾" - // if (mVexs[p1].firstEdge == null) - // mVexs[p1].firstEdge = node1; - // else - // LinkLast(mVexs[p1].firstEdge, node1); - // // 初始化node2 - // ENode node2 = new ENode(); - // node2.ivex = p1; - // node2.weight = weight; - // // 将node2链接到"p2所在链表的末尾" - // if (mVexs[p2].firstEdge == null) - // mVexs[p2].firstEdge = node2; - // else - // LinkLast(mVexs[p2].firstEdge, node2); - // } - // } - - // /* - // * 将node节点链接到list的最后 - // */ - // private void LinkLast(ENode list, ENode node) - // { - // ENode p = list; - - // while (p.nextEdge != null) - // p = p.nextEdge; - // p.nextEdge = node; - // } - - // /* - // * 返回ch位置 - // */ - // private int GetPosition(string ch) - // { - // for (int i = 0; i < mVexs.Length; i++) - // if (mVexs[i].data == ch) - // return i; - // return -1; - // } - - // /* - // * 获取边的权值;若start和end不是连通的,则返回无穷大。 - // */ - // private int GetWeight(int start, int end) - // { - // if (start == end) - // return 0; - - // ENode node = mVexs[start].firstEdge; - // while (node != null) - // { - // if (end == node.ivex) - // return node.weight; - // node = node.nextEdge; - // } - - // return MAX; - // } - - // /* - // * Dijkstra最短路径。 - // * 即,统计图中"起点D"到其它各个顶点的最短路径。 - // * - // * 参数说明: - // * vs -- 起始顶点(start vertex)。 - // * prev -- 前驱顶点数组。即,prev[i]的值是"起点D"到"顶点i"的最短路径所经历的全部顶点中,位于"顶点i"之前的那个顶点。 - // * dist -- 长度数组。即,dist[i]是"起点D"到"顶点i"的最短路径的长度。 - // */ - // public void CalcDijkstra(int vs, int[] prev, int[] dist, List roads) - // { - // //List vertexs = new(); //最短路径串联的点位列表 - // // flag[i]=true表示"起点D"到"顶点i"的最短路径已成功获取。 - // bool[] flag = new bool[mVexs.Length]; - - // // 初始化 - // for (int i = 0; i < mVexs.Length; i++) - // { - // flag[i] = false; // 顶点i的最短路径还没获取到。 - // prev[i] = 0; // 顶点i的前驱顶点为0。 - // dist[i] = GetWeight(vs, i); // 顶点i的最短路径为"起点D"到"顶点i"的权。 - // } - - // // 对"起点D"自身进行初始化 - // flag[vs] = true; - // dist[vs] = 0; - - // // 遍历mVexs.Length-1次;每次找出一个顶点的最短路径。 - // int k = 0; - // for (int i = 1; i < mVexs.Length; i++) - // { - // // 寻找当前最小的路径 - // // 即,在未获取最短路径的顶点中,找到离起点D最近的顶点(k)。 - // int min = MAX; - // for (int j = 0; j < mVexs.Length; j++) - // { - // if (flag[j] == false && dist[j] < min) - // { - // min = dist[j]; - // k = j; - // } - // } - // // 标记"顶点k"为已经获取到最短路径 - // flag[k] = true; - // // 更新当前最短路径和前驱顶点 - // // 即,更新"未获取最短路径的顶点的最短路径和前驱顶点"。 - // for (int j = 0; j < mVexs.Length; j++) - // { - // int tmp = GetWeight(k, j); - // tmp = (tmp == MAX ? MAX : (min + tmp)); // 防止溢出 - // if (flag[j] == false && (tmp < dist[j])) - // { - // dist[j] = tmp; - // prev[j] = k; - // } - // } - // } - // } - //} - - ///// - ///// 邻接表中表对应的链表的顶点 - ///// - //public class ENode - //{ - // public int ivex; // 该边所指向的顶点的位置 - // public int weight; // 该边的权 - // public ENode nextEdge; // 指向下一条弧的指针 - //} - - ///// - ///// 邻接表中表的顶点 - ///// - //public class VNode - //{ - // public string data; // 顶点信息 - // public ENode firstEdge; // 指向第一条依附该顶点的弧 - //} - - ///// - ///// 边的结构体 - ///// - //public class EData - //{ - // public string start; // 边的起点 - // public string end; // 边的终点 - // public int weight; // 边的权重 - - // public EData(string start, string end, int weight) - // { - // this.start = start; - // this.end = end; - // this.weight = weight; - // } - //} -} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/Dp.cs b/WarehouseMgr/Tnb.WarehouseMgr/Dp.cs deleted file mode 100644 index 50e838b1..00000000 --- a/WarehouseMgr/Tnb.WarehouseMgr/Dp.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using JNPF.Common.Extension; -using JNPF.Templates; -using Microsoft.AspNetCore.Mvc; -using NPOI.SS.Formula.Functions; -using Spire.Doc; -using Tnb.WarehouseMgr.Entities; - -namespace Tnb.WarehouseMgr -{ - /// - /// 动态规划类 - /// - public class Dp - { - private HashSet set = new HashSet(); - - /// - /// 动态规划函数 - /// - /// - public void DpFunc(List roads, List pointIds, Dictionary isVisited, string sPointId, string ePointId, dynamic ArrivedEpoint) - { - var sRoads = roads.FindAll(x => x.startpoint_id == sPointId).ToList(); - var sRoads_EPointIds = sRoads.Select(x => x.endpoint_id).ToList(); - - if (!isVisited[sPointId]) - { - pointIds.Add(sPointId); - set.Add(roads?.Find(x => x.startpoint_id == sPointId)?.startpoint_code!); - isVisited[sPointId] = true; - } - - if (sRoads_EPointIds.Contains(ePointId)) //判断是否到达终点 - { - ArrivedEpoint.isArrivedEpoint = true; - pointIds.Add(ePointId); - foreach (var kvp in isVisited) - { - isVisited[kvp.Key] = true; - } - return; - } - if (sRoads_EPointIds?.Count > 0) - { - var subRoads = roads?.FindAll(x => sRoads_EPointIds.Contains(x.startpoint_id) && !isVisited[x.endpoint_id]); - if (subRoads?.Count > 0) - { - for (int i = 0; i < subRoads.Count; i++) - { - var sIdx = subRoads[i].startpoint_id; - if (!isVisited[sIdx]) - { - DpFunc(roads, pointIds, isVisited, sIdx, ePointId, ArrivedEpoint); - } - } - } - } - if (!ArrivedEpoint.isArrivedEpoint) - { - pointIds.Remove(sPointId); - } - } - } -} diff --git a/WarehouseMgr/Tnb.WarehouseMgr/EventSubscribers/TaskStatusChangeSubscriber.cs b/WarehouseMgr/Tnb.WarehouseMgr/EventSubscribers/TaskStatusChangeSubscriber.cs new file mode 100644 index 00000000..c74e3044 --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr/EventSubscribers/TaskStatusChangeSubscriber.cs @@ -0,0 +1,47 @@ +using JNPF.Common.Configuration; +using JNPF.DependencyInjection; +using JNPF.EventBus; +using JNPF.TaskScheduler.Entitys; +using SqlSugar; +using Tnb.Common.Core.EventBus.Constants; +using Tnb.Common.Core.EventBus.Sources; +using Tnb.WarehouseMgr.Interfaces; + +namespace Tnb.WarehouseMgr.EventSubscribers; + +/// +/// 任务事件订阅. +/// +public class TaskStatusChangeSubscriber : IEventSubscriber, ISingleton +{ + /// + /// 初始化客户端. + /// + //private static SqlSugarScope? _sqlSugarClient; + private readonly IWareHouseService _wareHouseService; + /// + /// 构造函数. + /// + public TaskStatusChangeSubscriber(IWareHouseService wareHouseService) + { + _wareHouseService = wareHouseService; + } + + /// + /// 创建任务日记. + /// + /// + /// + [EventSubscribe(EventSubscribeEventConsts.TaskStatusChangeEventId)] + public async Task Excute(EventHandlerExecutingContext context) + { + var tscSource = (TaskStatusChangeSource)context.Source; + switch (tscSource.Payload) + { + case nameof(_wareHouseService.GenTaskExecute): + await _wareHouseService.GenTaskExecute(); + break; + } + + } +} \ No newline at end of file diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 0358a74d..78e1561e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -33,6 +33,7 @@ using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Entity; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; +using JNPF.Common.Extension; namespace Tnb.WarehouseMgr { @@ -47,12 +48,13 @@ namespace Tnb.WarehouseMgr private readonly IUserManager _userManager; private readonly ICacheManager _cacheManager; private readonly IElevatorControlService _elevatorControlService; - private static Dictionary _elevatorMap = new Dictionary(); + private static Dictionary _elevatorAgvCtlStatusMap = new(StringComparer.OrdinalIgnoreCase); private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build(); public Func AddUnExecuteTask { get; set; } public WareHouseService(ISqlSugarRepository repository, IDictionaryDataService dictionaryDataService, IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService) + : base(repository.AsSugarClient()) { _db = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; @@ -60,10 +62,6 @@ namespace Tnb.WarehouseMgr _userManager = userManager; _cacheManager = cacheManager; _elevatorControlService = elevatorControlService; - AddUnExecuteTask = async (code, floor) => - { - await _elevatorControlService.CallLift(code, floor, CancellationToken.None); - }; } @@ -226,10 +224,23 @@ namespace Tnb.WarehouseMgr var db = _db.CopyNew(); try { - //if (_elevatorMap.Count < 1) - //{ - // _elevatorMap = await _db.Queryable().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code); - //} + /*if (_elevatorMap.Count < 1) + { + _elevatorMap = await _db.Queryable().ToDictionaryAsync(x => x.elevator_id, x => x.elevator_code); + }*/ + //获取电梯数据 + var elevatorList = await db.Queryable().InnerJoin((a, b) => a.id == b.bill_id) + .Select((a, b) => new WmsElevatorH + { + bill_id = b.bill_id, + location_id = b.location_id, + location_code = b.location_code, + point_id = b.point_id, + point_code = b.point_code, + floor = b.floor + }, true).ToListAsync(); + + //获取所有未下发的预任务申请 var preTasks = await db.Queryable().InnerJoin((a, b) => a.startlocation_id == b.location_id && a.carry_id == b.id) .InnerJoin((a, b, c) => a.area_id == c.id) @@ -240,6 +251,14 @@ namespace Tnb.WarehouseMgr move_num = c.move_num }, true) .ToListAsync(); + var agvElevatorTasks = preTasks + .Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase) && + !it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)) + .ToList(); + var firstEleGrp = agvElevatorTasks.GroupBy(g => g.endlocation_code).Select(t => t.OrderBy(o => o.bill_code).FirstOrDefault()); + agvElevatorTasks = agvElevatorTasks.FindAll(x => firstEleGrp.Select(y => y.endlocation_code).Contains(x.endlocation_code)); + preTasks = preTasks.Where(it => !it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase)).Concat(agvElevatorTasks).ToList(); + var ids = preTasks.Select(x => x.id).Distinct().ToList(); var preTaskCodes = await db.Queryable().Where(it => ids.Contains(it.bill_id)).ToListAsync(); if (preTasks.Count > 0) @@ -323,7 +342,25 @@ namespace Tnb.WarehouseMgr } await db.Ado.BeginTranAsync(); + var endPointIds = disTasks.Where(t => t.area_code.StartsWith("ELE", StringComparison.OrdinalIgnoreCase)).Select(t => t.endpoint_id).ToList(); + if (endPointIds?.Count > 0) + { + elevatorList = elevatorList.FindAll(x => endPointIds.Contains(x.point_id)); + if (elevatorList?.Count > 0) + { + foreach (var e in elevatorList) + { + var disTask = disTasks.Find(x => x.endpoint_id == e.point_id); + if (disTask != null) + { + disTask.device_id = e.elevator_id; + } + } + } + } //disTasks.ForEach(x => x.id = SnowflakeIdHelper.NextId()); + + var row = await db.Insertable(disTasks).ExecuteCommandAsync(); if (preTaskCodes?.Count > 0) { @@ -335,24 +372,22 @@ 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(); - Log.Information($"程序运行耗时{sw.ElapsedMilliseconds}ms"); await db.Ado.CommitTranAsync(); //呼梯操作 //获取目标库位为电梯库位的任务 - var endLocCodes = disTasks - .Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase) && - !it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase) - ).Select(it => (it.endlocation_code, it.device_id, it.id, it.start_floor)).ToList(); + .Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase) && + !it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)) + .Select(it => (it.endlocation_code, it.device_id, it.id, it.start_floor)).ToList(); if (endLocCodes?.Count > 0) { + await CallingLanding(endLocCodes); } //执行电梯任务 var elevatorTasks = disTasks.Where(it => it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)).ToList(); - + if (elevatorTasks?.Count > 0) { Logger.Information($"当前电梯任务数:{elevatorTasks?.Count ?? 0}"); @@ -371,7 +406,6 @@ namespace Tnb.WarehouseMgr { await AgvDispatch(agvTasks, agvCts.Token); } - } } catch (Exception ex) when (ex is HttpRequestException hReqEx) @@ -396,59 +430,67 @@ namespace Tnb.WarehouseMgr /// private async Task CallingLanding(List<(string endlocation_code, string device_id, string id, string floorNO)> endLocCodes) { - Logger.Information($"开始呼梯操作............."); + Logger.Information($" 开始呼梯操作............."); try { - var item = endLocCodes.FirstOrDefault(); - //if (_elevatorMap.ContainsKey(item.device_id)) - var devName = _eleCtlCfg.DevName; + foreach (var (_, devId, disTaskId, floorNO) in endLocCodes) { - var agvStatus = await _elevatorControlService.GetTagAsync(devName, ElevatorConsts.AGVControl); - Logger.Information($"当前Agv状态:{agvStatus.ToEnum().ToString()}"); - //判断当前设备是否为运行状态,不是则进入Agv电梯控制状态 - if (agvStatus.ToEnum() != EnumAgvStatus.AGV运行状态) + if (!_elevatorMap.TryGetValue(devId, out var elevatorCode)) continue; + + var devName = elevatorCode.ToString(); + + Logger.Information($"当前:{devName.Match(@"\d+")}#梯"); + + await _elevatorControlService.WriteTagAsync(devName, ElevatorConsts.AGVControl, 1); + (int sysStatus, int runStatus, int curFloorNo, int doorStatus, int agvStatus) eleStatusMulti = (-1, -1, -1, -1, -1); + if (!_elevatorAgvCtlStatusMap.TryGetValue(devId, out var agvCtlStatus) || agvCtlStatus != (int)EnumAgvStatus.AGV运行状态) { - await _elevatorControlService.WriteTagAsync(devName, ElevatorConsts.AGVControl, 1); + do + { + eleStatusMulti = await _elevatorControlService.GetElevatorStatus(devName, CancellationToken.None); + await Task.Delay(500); + } while (eleStatusMulti.agvStatus != (int)EnumAgvStatus.AGV运行状态); + Logger.Information($"{devName.Match(@"\d+")}#, 当前Agv状态:{eleStatusMulti.agvStatus.ToEnum().ToString()}"); + _elevatorAgvCtlStatusMap[devId] = eleStatusMulti.agvStatus; } - } - { - (int sysStatus, int runStatus, int curFloorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(devName, CancellationToken.None); - foreach (var (_, devId, disTaskId, floorNO) in endLocCodes) + Logger.Information($"任务开始目标楼层为:{floorNO}"); + + var floorN = await GetRealFloor(floorNO.ParseToInt()); + //如果电梯在当前楼层则不呼梯 + if (floorN == eleStatusMulti.curFloorNo) { - Logger.Information($"任务开始目标楼层为:{floorNO}"); - - var floorN = await GetRealFloor(floorNO.ParseToInt()); - - Logger.Information($"实际目标楼层为:{floorN}"); - - WmsElevatorUnexecute elevatorQueueItem = new() - { - distask_id = disTaskId, - elevator_id = devId, - elevator_code = devName, - floor = floorN, //5代表4楼 - task_status = "待执行", - create_id = _userManager.UserId, - create_time = DateTime.Now - }; - var elevatorQueue = await _db.Queryable().Where(it => it.distask_id == disTaskId && it.task_status == "执行中").ToListAsync(); - if ((elevatorQueue.IsNull() || elevatorQueue.Count < 1) && floorNO.ParseToInt() != curFloorNo) - { - - elevatorQueueItem.task_status = "执行中"; - var callLiftRes = await _elevatorControlService.CallLift(devName, floorN, CancellationToken.None); - string successful = "成功", fail = "失败"; - var callLiftResult = callLiftRes ? successful : fail; - Logger.Information($"呼梯结果:{callLiftResult}"); - } - - //如果当前电梯有任务在做,将当前呼梯任务放入待执行队列 - await _db.Insertable(elevatorQueueItem).ExecuteCommandAsync(); + Logger.Information($"{devName.Match(@"\d+")}#,在当前楼层,无需呼梯"); + continue; } - } + Logger.Information($"实际目标楼层为:{floorN}"); + + WmsElevatorUnexecute elevatorQueueItem = new() + { + distask_id = disTaskId, + elevator_id = devId, + elevator_code = devName, + floor = floorN, //5代表4楼 + task_status = "待执行", + create_id = _userManager.UserId, + create_time = DateTime.Now + }; + var elevatorQueue = await _db.Queryable().Where(it => it.distask_id == disTaskId && it.task_status == "执行中").ToListAsync(); + if ((elevatorQueue.IsNull() || elevatorQueue.Count < 1) && floorN != eleStatusMulti.curFloorNo) + { + + elevatorQueueItem.task_status = "执行中"; + var callLiftRes = await _elevatorControlService.CallLift(devName, floorN, CancellationToken.None); + string successful = "成功", fail = "失败"; + var callLiftResult = callLiftRes ? successful : fail; + Logger.Information($"{devName.Match(@"\d+")}#, 呼梯结果:{callLiftResult}"); + } + + //如果当前电梯有任务在做,将当前呼梯任务放入待执行队列 + await _db.Insertable(elevatorQueueItem).ExecuteCommandAsync(); + } } catch (Exception ex) { @@ -468,54 +510,58 @@ namespace Tnb.WarehouseMgr Logger.Information($"开始执行电梯任务,任务ID:{disTask.id}"); try { -/* var elevatorQueueItem = await _db.Queryable().FirstAsync(it => it.task_status == "执行中"); - Log.Information($"是否存在电梯任务项:{elevatorQueueItem != null}"); -*/ //if (elevatorQueueItem != null) + if (!_elevatorMap.TryGetValue(disTask.device_id, out var elevatorCode)) { - //var disTask = disTasks.Find(x => x.id == elevatorQueueItem.distask_id); - //if (disTask?.status == WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID) - { - var doorStatus = -1; - var closeDoorRes = await _elevatorControlService.SendOpenCloseCmd(_eleCtlCfg.DevName, 4); //向电梯发送前门关门指令 - Logger.Information($"关门结果:{closeDoorRes}"); - do - { - doorStatus = await _elevatorControlService.GetTagAsync(_eleCtlCfg.DevName, ElevatorConsts.DoorStatus); - await Task.Delay(2000); - } while (doorStatus != 4); - Logger.Information($"当前门状态:{doorStatus}"); - - var floor = await GetRealFloor(disTask.end_floor.ParseToInt()); - - Logger.Information($"目标楼层:{floor}"); - - //发送到目标楼的指令 - var reuslt = await _elevatorControlService.WriteTagAsync(_eleCtlCfg.DevName, ElevatorConsts.FloorExecute, floor); - //电梯任务手动执行任务状态上报 - (int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) tuple = (-1, -1, -1, -1, -1); - - do - { - tuple = await _elevatorControlService.GetElevatorStatus(_eleCtlCfg.DevName, CancellationToken.None); - await Task.Delay(2000); - } while (tuple.sysStatus != 3 && tuple.runStatus != 0); - - Logger.Information($"sysStatus:{tuple.sysStatus},runStatus:{tuple.runStatus},floorNo:{tuple.floorNo},disTask.end_floor={disTask.end_floor}"); - - if (tuple.sysStatus.ToEnum() == EnumSysStatus.正常状态 && tuple.runStatus.ToEnum() == EnumRunStatus.停梯) - { - Log.Information($"disTask.require_id={disTask.require_id}"); - - List disTaskIds = new() { disTask.id }; - Log.Information($"disTaskIds={string.Join(",", disTaskIds)}"); - TaskExecuteAfterUpInput teaUpInput = new() { disTaskIds = disTaskIds }; - await TaskExecuteAfter(teaUpInput); - - TaskCompleUpInput tcUpInput = new() { disTaskIds = disTaskIds }; - await TaskComplate(tcUpInput); - } - } + return; } + var devName = _elevatorMap[disTask.device_id]?.ToString() ?? _eleCtlCfg.DevName; + + Logger.Information($"当前:{devName.Match(@"\d+")}#梯"); + + var doorStatus = -1; + var closeDoorRes = await _elevatorControlService.SendOpenCloseCmd(devName, 4); //向电梯发送前门关门指令 + Logger.Information($"关门结果:{closeDoorRes}"); + do + { + doorStatus = await _elevatorControlService.GetTagAsync(devName, ElevatorConsts.DoorStatus); + await Task.Delay(2000); + } while (doorStatus != 4); + Logger.Information($"当前门状态:{doorStatus}"); + + var floor = await GetRealFloor(disTask.end_floor.ParseToInt()); + + Logger.Information($"目标楼层:{floor}"); + + //发送到目标楼的指令 + var reuslt = await _elevatorControlService.WriteTagAsync(devName, ElevatorConsts.FloorExecute, floor); + //电梯任务手动执行任务状态上报 + (int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) tuple = (-1, -1, -1, -1, -1); + + do + { + tuple = await _elevatorControlService.GetElevatorStatus(devName, CancellationToken.None); + await Task.Delay(2000); + } while (tuple.sysStatus != 3 && tuple.runStatus != 0); + + Logger.Information($"sysStatus:{tuple.sysStatus},runStatus:{tuple.runStatus},floorNo:{tuple.floorNo},disTask.end_floor={disTask.end_floor}"); + + if (tuple.sysStatus.ToEnum() == EnumSysStatus.正常状态 && tuple.runStatus.ToEnum() == EnumRunStatus.停梯) + { + Log.Information($"disTask.require_id={disTask.require_id}"); + var disTaskIds = new List { disTask.id }; + var upInput = new { disTaskIds = disTask.id }; + TaskExecuteAfterUpInput teaUpInput = new() + { + disTaskIds = disTaskIds, + }; + await TaskExecuteAfter(teaUpInput); + TaskCompleUpInput tcUpInput = new() + { + disTaskIds = disTaskIds, + }; + await TaskComplate(tcUpInput); + } + } catch (Exception ex) { @@ -746,7 +792,7 @@ namespace Tnb.WarehouseMgr catch (Exception ex) { Logger.Error($"任务结束失败", ex); - Log .Error($"任务结束失败堆栈异常", ex.StackTrace); + Log.Error($"任务结束失败堆栈异常", ex.StackTrace); await _db.Ado.RollbackTranAsync(); throw; } @@ -916,8 +962,9 @@ namespace Tnb.WarehouseMgr } } } - catch (Exception) + catch (Exception ex) { + Logger.Error("路径算法异常", ex); throw; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs index 817be66e..bace2234 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs @@ -11,6 +11,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Interfaces.System; @@ -44,7 +45,6 @@ namespace Tnb.WarehouseMgr private readonly IWareHouseService _wareHouseService; private readonly IBillRullService _billRullService; private readonly IUserManager _userManager; - private readonly ChannelWriter _channelWriter; public WmsCarryMoveInStockService( @@ -54,8 +54,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -63,7 +63,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; - + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = CarryMoveIn; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs index facb0a09..9527fe3f 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -46,7 +47,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -54,6 +56,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = CarryMoveOut; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs index 63ee2b35..70834328 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -44,8 +45,8 @@ namespace Tnb.WarehouseMgr IRunService runService, IBillRullService billRullService, IUserManager userManager, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _warehouseService = wareHouseService; @@ -53,6 +54,7 @@ namespace Tnb.WarehouseMgr _runService = runService; _billRullService = billRullService; _userManager = userManager; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = Create; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs index 36e9af2a..f20a36dd 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs @@ -11,6 +11,7 @@ using JNPF.Common.Extension; using JNPF.Common.Security; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Interfaces.System; @@ -56,8 +57,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -66,6 +67,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = Create; } /// @@ -128,7 +130,7 @@ namespace Tnb.WarehouseMgr { var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); - Log.Information($"经过的所有点位编码:{Environment.NewLine}{string.Join("\r\n", points.Select(x=>x.point_code))}"); + Log.Information($"经过的所有点位编码:{Environment.NewLine}{string.Join("\r\n", points.Select(x => x.point_code))}"); //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) if (points?.Count > 0) @@ -139,7 +141,7 @@ namespace Tnb.WarehouseMgr var sPoint = it.FirstOrDefault(); var ePoint = it.LastOrDefault(); - Log.Information("ePoint?.point_code="+ ePoint?.point_code); + Log.Information("ePoint?.point_code=" + ePoint?.point_code); WmsPretaskH preTask = new(); preTask.org_id = _userManager.User.OrganizeId; diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs index 018bb6a9..46abdf54 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs @@ -10,6 +10,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -54,8 +55,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMesageNotify - ) : base(taskMesageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -63,7 +64,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; - _channelWriter = taskMesageNotify.Writer; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = WmsEmptyIn; } private async Task WmsEmptyIn(VisualDevModelDataCrInput input) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs index 64342d1d..dc1a1efa 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs @@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -52,8 +53,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -61,6 +62,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = WmsEmptyOut; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs index f781a043..b48358f3 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs @@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Extension; using JNPF.Common.Filter; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Interfaces.System; @@ -55,8 +56,8 @@ namespace Tnb.WarehouseMgr IBillRullService billRullService, IWareHouseService wareHouseService, IPrdInstockService prdInstockService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; @@ -64,6 +65,7 @@ namespace Tnb.WarehouseMgr _billRullService = billRullService; _wareHouseService = wareHouseService; _prdInstockService = prdInstockService; + EventPublisher = eventPublisher; } /// /// 根据入库申请单ID获取申请单明细信息 diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs index 9935c4cf..e82bb9a5 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -49,8 +50,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -58,6 +59,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = KittingInStk; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutBaleService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutBaleService.cs index 1c9f302f..e7dd0c38 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutBaleService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutBaleService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -48,8 +49,8 @@ namespace Tnb.WarehouseMgr IUserManager userManager, IBillRullService billRullService, IWmsCarryService wmsCarryService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -58,6 +59,7 @@ namespace Tnb.WarehouseMgr _userManager = userManager; _billRullService = billRullService; _wmsCarryService = wmsCarryService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = CarryOutBale; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs index 3b63c14f..fd4ae50a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs @@ -35,6 +35,7 @@ using Tnb.WarehouseMgr.Interfaces; using System.Reflection; using Tnb.WarehouseMgr.Print; using System.Runtime.InteropServices; +using JNPF.EventBus; namespace Tnb.WarehouseMgr { @@ -67,7 +68,7 @@ namespace Tnb.WarehouseMgr IBillRullService billRullService, IWmsCarryMoveInStockService wmsCarryMoveInStockService, IWmsCarryService wareCarryService, - ITaskMessageNotify taskMessageNotify) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher) { _db = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; @@ -78,6 +79,7 @@ namespace Tnb.WarehouseMgr _billRullService = billRullService; _wmsCarryMoveInStockService = wmsCarryMoveInStockService; _wareCarryService = wareCarryService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = OutStockApplyFor; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveInStockService.cs index 96211641..e9f4ce5c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveInStockService.cs @@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Interfaces.System; @@ -51,7 +52,7 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher) { _db = repository.AsSugarClient(); _runService = runService; @@ -59,6 +60,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = PDACarryMoveIn; } @@ -251,7 +253,7 @@ namespace Tnb.WarehouseMgr handleH.carry_code = input.data[nameof(WmsHandleH.carry_code)]?.ToString()!; handleH.require_id = input.data["ReturnIdentity"].ToString(); handleH.require_code = input.data[nameof(WmsHandleH.bill_code)]?.ToString()!; - handleH.create_id = _userManager.UserId ; + handleH.create_id = _userManager.UserId; handleH.create_time = DateTime.Now; preTaskUpInput.PreTaskRecord = handleH; //根据载具移入Id,回更单据状态 diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveOutStockService.cs index e04b6d4e..af06151c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryMoveOutStockService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -39,6 +40,7 @@ namespace Tnb.WarehouseMgr private readonly IWareHouseService _wareHouseService; private readonly IBillRullService _billRullService; private readonly IUserManager _userManager; + public WmsPDACarryMoveOutStockService( ISqlSugarRepository repository, IRunService runService, @@ -46,8 +48,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -55,6 +57,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = PDACarryMoveOut; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs index e17b2dac..1bcc6ecb 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDADeliveryService.cs @@ -10,6 +10,7 @@ using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.DependencyInjection; using JNPF.DynamicApiController; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -51,8 +52,8 @@ namespace Tnb.WarehouseMgr IBillRullService billRullService, IWareHouseService wareHouseService, IUserManager userManager, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -61,6 +62,7 @@ namespace Tnb.WarehouseMgr _billRullService = billRullService; _wareHouseService = wareHouseService; _userManager = userManager; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = Create; } /// diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyInstockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyInstockService.cs index 91280a06..3ca9a1b7 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyInstockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyInstockService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -48,7 +49,7 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher) { _db = repository.AsSugarClient(); _runService = runService; @@ -56,6 +57,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = PDAWmsEmptyIn; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyOutstockService .cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyOutstockService .cs index 05ea05d0..986a9a2b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyOutstockService .cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAEmptyOutstockService .cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Logging; using JNPF.Systems.Interfaces.System; @@ -49,8 +50,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -58,6 +59,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = PDAWmsEmptyOut; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs index 776bd53b..a5ade6b2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInStockService.cs @@ -10,6 +10,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -55,8 +56,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -64,6 +65,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = ScanCodeInStock; } @@ -83,7 +85,7 @@ namespace Tnb.WarehouseMgr if (input.data.ContainsKey("tablefield115")) { jArr = JArray.Parse(input.data["tablefield115"].ToString()!); - + } //入库取终点 //出库起点 var inStockStrategyInput = new InStockStrategyQuery { warehouse_id = input.data[nameof(InStockStrategyQuery.warehouse_id)].ToString()!, Size = 1 }; @@ -142,7 +144,7 @@ namespace Tnb.WarehouseMgr create_time = DateTime.Now, source_id = input.data[nameof(WmsKittingInstock.source_id)].ToString(), source_code = input.data[nameof(WmsKittingInstock.source_code)].ToString() - }; + }; return preTask; }).ToList(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInbaleService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInbaleService.cs index 5f2de722..cf387778 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInbaleService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAInbaleService.cs @@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -50,8 +51,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -59,6 +60,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = Inbale; } @@ -152,7 +154,7 @@ namespace Tnb.WarehouseMgr handleH.create_time = DateTime.Now; preTaskUpInput.PreTaskRecord = handleH; //根据载具移入Id,回更单据状态 - await _db.Updateable().SetColumns(it => new WmsInbale { status = WmsWareHouseConst.BILLSTATUS_ON_ID}).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync(); + await _db.Updateable().SetColumns(it => new WmsInbale { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync(); var baleNum = input.data[nameof(WmsCarryH.bale_num)]?.ToString(); await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAKittingInStkService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAKittingInStkService.cs index 4119a5d1..c86d5f92 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAKittingInStkService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAKittingInStkService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -39,8 +40,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(repository, runService, visualDevService, wareHouseService, userManager, billRullService, taskMessageNotify) + IEventPublisher publisher + ) : base(repository, runService, visualDevService, wareHouseService, userManager, billRullService, publisher) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAOutBaleServiceService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAOutBaleServiceService.cs index bfeb7d81..e7ea4455 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAOutBaleServiceService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAOutBaleServiceService.cs @@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -48,8 +49,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -57,6 +58,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher= eventPublisher; OverideFuncs.CreateAsync = PDAOutBale; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs index 2a32939c..58cf230a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs @@ -8,6 +8,7 @@ using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -46,8 +47,8 @@ namespace Tnb.WarehouseMgr IBillRullService billRullService, IWareHouseService wareHouseService, IPrdInstockService prdInstockService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; @@ -55,6 +56,7 @@ namespace Tnb.WarehouseMgr _billRullService = billRullService; _wareHouseService = wareHouseService; _prdInstockService = prdInstockService; + EventPublisher = eventPublisher; OverideFuncs.CreateAsync = ScanInStock; } public async Task ScanInStock(VisualDevModelDataCrInput input) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDATransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDATransferService.cs index 1411a4c5..aedb9b8e 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDATransferService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDATransferService.cs @@ -9,6 +9,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -51,8 +52,8 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher publisher + ) { _db = repository.AsSugarClient(); _runService = runService; @@ -60,6 +61,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + EventPublisher = publisher; OverideFuncs.CreateAsync = CarryTransfer; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs index 67f09f44..78aa47ba 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsRobotCallbackService.cs @@ -9,6 +9,7 @@ using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using Mapster; @@ -45,8 +46,8 @@ namespace Tnb.WarehouseMgr IWareHouseService warehouseService, IBillRullService billRullService, IWmsKittingInStkService wmsKittingInStkService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher publisher + ) { _wmsCarryBindService = wmsCarryBindService; _db = repository.AsSugarClient(); @@ -54,6 +55,7 @@ namespace Tnb.WarehouseMgr _warehouseService = warehouseService; _billRullService = billRullService; _wmsKittingInStkService = wmsKittingInStkService; + EventPublisher = publisher; } /// /// 机器人完成任务后回调接口 diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs index 964e62b0..7efd0ad9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsSetSortingService.cs @@ -13,6 +13,7 @@ using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Manager; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -59,8 +60,8 @@ namespace Tnb.WarehouseMgr ICacheManager cacheManager, IRunService runService, IVisualDevService visualDevService, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher publisher + ) { _db = repository.AsSugarClient(); _wareHouseService = wareHouseService; @@ -69,6 +70,7 @@ namespace Tnb.WarehouseMgr _cacheManager = cacheManager; _runService = runService; _visualDevService = visualDevService; + EventPublisher = publisher; //OverideFuncs.CreateAsync = Create; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsTransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsTransferService.cs index cc1fb206..d1325fe0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsTransferService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsTransferService.cs @@ -10,6 +10,7 @@ using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Enums; using JNPF.Common.Extension; using JNPF.Common.Security; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; @@ -52,7 +53,7 @@ namespace Tnb.WarehouseMgr IWareHouseService wareHouseService, IUserManager userManager, IBillRullService billRullService, - ITaskMessageNotify taskMessageNotify):base(taskMessageNotify.Writer) + IEventPublisher publisher) { _db = repository.AsSugarClient(); _runService = runService; @@ -60,7 +61,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; - + EventPublisher = publisher; OverideFuncs.CreateAsync = CarryTransfer; } @@ -76,7 +77,7 @@ namespace Tnb.WarehouseMgr // 计算路径,插入预任务申请 WmsPointH? sPoint = null; WmsPointH? ePoint = null; - + if (input.data.ContainsKey(nameof(WmsTransfer.endlocation_id))) { ePoint = await _db.Queryable().FirstAsync(it => it.location_id == input.data[nameof(WmsTransfer.endlocation_id)].ToString()); @@ -97,7 +98,7 @@ namespace Tnb.WarehouseMgr { var sPoint = it.FirstOrDefault(); var ePoint = it.LastOrDefault(); - + WmsPretaskH preTask = new(); preTask.org_id = _userManager.User.OrganizeId; preTask.startlocation_id = sPoint?.location_id!; @@ -145,6 +146,7 @@ namespace Tnb.WarehouseMgr await _db.Updateable().SetColumns(it => new BasLocation { is_lock = 1 }).Where(it => ids.Contains(it.id)).ExecuteCommandAsync(); await _db.Updateable().SetColumns(it => new WmsTransfer { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == input.data["ReturnIdentity"].ToString()).ExecuteCommandAsync(); + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs index c5ce1a7a..4fa58910 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmskittingOutService.cs @@ -19,6 +19,7 @@ using JNPF.Common.Extension; using JNPF.Common.Manager; using JNPF.Common.Security; using JNPF.DataEncryption; +using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.LinqBuilder; using JNPF.Logging; @@ -62,8 +63,8 @@ namespace Tnb.WarehouseMgr IBillRullService billRullService, IWmsCarryService carryService, ICacheManager cacheManager, - ITaskMessageNotify taskMessageNotify - ) : base(taskMessageNotify.Writer) + IEventPublisher eventPublisher + ) { _db = repository.AsSugarClient(); _warehouseService = warehouseService; @@ -71,7 +72,7 @@ namespace Tnb.WarehouseMgr _billRullService = billRullService; _carryService = carryService; _cacheManager = cacheManager; - + EventPublisher = eventPublisher; } /// /// 齐套出库(新增状态) @@ -169,7 +170,7 @@ namespace Tnb.WarehouseMgr { Log.Error("齐套出库,新增时出现错误", ex); await curDb.Ado.RollbackTranAsync(); - if(_userManager?.ToKen.IsNullOrEmpty() ?? false) + if (_userManager?.ToKen.IsNullOrEmpty() ?? false) { TimedTaskErrorInfo ei = new() { @@ -279,7 +280,7 @@ namespace Tnb.WarehouseMgr { Log.Error("齐套出库,待配送时出现错误", ex); await curDb.Ado.RollbackTranAsync(); - if(_userManager?.ToKen.IsNullOrEmpty() ?? false) + if (_userManager?.ToKen.IsNullOrEmpty() ?? false) { TimedTaskErrorInfo ei = new() { diff --git a/apihost/Tnb.API.Entry/Startup.cs b/apihost/Tnb.API.Entry/Startup.cs index b0db8282..db7c99c9 100644 --- a/apihost/Tnb.API.Entry/Startup.cs +++ b/apihost/Tnb.API.Entry/Startup.cs @@ -63,11 +63,11 @@ public class Startup : AppStartup services.AddOverideVisualDev(); //注册任务消息通知 added by ly on 20230814 - services.AddTaskMessageNotify(); + //services.AddTaskMessageNotify(); SnowflakeIdHelper.InitYitIdWorker(); //定时任务 - services.AddHostedService(); + //services.AddHostedService(); } diff --git a/common/Tnb.Common.Core/EventBus/Constants/EventSubscribeEventConsts.cs b/common/Tnb.Common.Core/EventBus/Constants/EventSubscribeEventConsts.cs new file mode 100644 index 00000000..7e2dc1a8 --- /dev/null +++ b/common/Tnb.Common.Core/EventBus/Constants/EventSubscribeEventConsts.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.Common.Core.EventBus.Constants +{ + public class EventSubscribeEventConsts + { + /// + /// 预任务执行EventId + /// + public const string TaskStatusChangeEventId = "DisTask:TaskStatusChange"; + + } +} diff --git a/common/Tnb.Common.Core/EventBus/Sources/TaskStatusChangeSource.cs b/common/Tnb.Common.Core/EventBus/Sources/TaskStatusChangeSource.cs new file mode 100644 index 00000000..fde34ead --- /dev/null +++ b/common/Tnb.Common.Core/EventBus/Sources/TaskStatusChangeSource.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using JNPF.EventBus; +using SqlSugar; + +namespace Tnb.Common.Core.EventBus.Sources +{ + public class TaskStatusChangeSource : IEventSource + { + /// + /// 构造函数. + /// + /// 事件ID. + /// 数据库连接配置. + /// 实体. + public TaskStatusChangeSource(string eventId, object payload) + { + EventId = eventId; + Payload = payload; + } + + ///// + ///// 数据库连接配置. + ///// + //public ConnectionConfigOptions ConnectionConfig { get; set; } + + /// + /// 事件 Id. + /// + public string EventId { get; } + + /// + /// 事件承载(携带)数据. + /// + public object Payload { get; } + + /// + /// 取消任务 Token. + /// + /// 用于取消本次消息处理. + public CancellationToken CancellationToken { get; } + + /// + /// 事件创建时间. + /// + public DateTime CreatedTime { get; } = DateTime.UtcNow; + } +} diff --git a/common/Tnb.Common/Extension/Extensions.cs b/common/Tnb.Common/Extension/Extensions.cs index df2b983a..97c9ff45 100644 --- a/common/Tnb.Common/Extension/Extensions.cs +++ b/common/Tnb.Common/Extension/Extensions.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Globalization; using System.Text.RegularExpressions; +using Newtonsoft.Json; namespace JNPF.Common.Extension; @@ -701,6 +702,13 @@ public static partial class Extensions { return thisValue == null; } + //added by ly on 20231030 + public static T ConvertToType(this object value) where T : class + { + var jsonData = JsonConvert.SerializeObject(value); + return JsonConvert.DeserializeObject(jsonData); + } + #endregion