From 2f3cf868d70395050d64ab4220bc38844473158a Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 15 Aug 2023 14:27:10 +0800 Subject: [PATCH] 1 --- .../Tnb.WarehouseMgr/BaseWareHouseService.cs | 21 ++++++++++++++++++- .../TimedTaskBackgroundService.cs | 2 +- .../WmsCarryMoveInStockService.cs | 13 +++++++++++- .../WmsCarryMoveOutStockService.cs | 16 +++++++++----- .../Tnb.WarehouseMgr/WmsCheckTaskService.cs | 8 ++++++- .../Tnb.WarehouseMgr/WmsDeliveryService.cs | 9 ++++++-- .../WmsEmptyInstockService.cs | 5 ++--- .../WmsEmptyOutstockService .cs | 11 ++++++++-- .../Tnb.WarehouseMgr/WmsInStockService.cs | 17 +++++++++------ .../WmsKittingInStkService.cs | 10 +++++++-- 10 files changed, 88 insertions(+), 24 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs index 2b4e3297..a7cd8a08 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs @@ -6,6 +6,7 @@ using System.Reflection; using System.Security.Claims; using System.Security.Cryptography; using System.Text; +using System.Threading.Channels; using System.Threading.Tasks; using Aspose.Cells.Drawing; using JNPF; @@ -32,6 +33,7 @@ using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Dto.Outputs; using Tnb.WarehouseMgr.Entities.Entity; using Tnb.WarehouseMgr.Interfaces; @@ -44,6 +46,12 @@ namespace Tnb.WarehouseMgr { private static Dictionary _stroageMap = new(StringComparer.OrdinalIgnoreCase); public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); + private readonly ChannelWriter _channelWriter; + + public BaseWareHouseService(ChannelWriter? channelWriter = default) + { + _channelWriter = channelWriter; + } static BaseWareHouseService() { @@ -93,7 +101,18 @@ namespace Tnb.WarehouseMgr } return Task.FromResult(isMatch); } - + /// + /// 发布消息 + /// + /// + /// + [NonAction] + protected async Task Publish(string taskName) + { + NotifyMessage message = new() { TaskName = taskName }; + if (_channelWriter != null) + await _channelWriter.WriteAsync(message); + } [NonAction] protected async Task DoUpdate(WareHouseUpInput input) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index 4e999c48..24e8b64f 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -59,7 +59,7 @@ namespace Tnb.WarehouseMgr var channelReader = _serviceProvider.GetRequiredService().Reader; CancellationTokenSource? cts = new(); - + while (channelReader != null && await channelReader.WaitToReadAsync()) { while (channelReader.TryRead(out var message)) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs index 189f6847..3fca4882 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveInStockService.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Channels; using System.Threading.Tasks; using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; @@ -21,6 +22,7 @@ using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; +using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr @@ -39,6 +41,7 @@ namespace Tnb.WarehouseMgr private readonly IWareHouseService _wareHouseService; private readonly IBillRullService _billRullService; private readonly IUserManager _userManager; + private readonly ChannelWriter _channelWriter; public WmsCarryMoveInStockService( @@ -47,7 +50,9 @@ namespace Tnb.WarehouseMgr IVisualDevService visualDevService, IWareHouseService wareHouseService, IUserManager userManager, - IBillRullService billRullService) + IBillRullService billRullService, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _runService = runService; @@ -55,6 +60,7 @@ namespace Tnb.WarehouseMgr _wareHouseService = wareHouseService; _userManager = userManager; _billRullService = billRullService; + OverideFuncs.CreateAsync = CarryMoveIn; } @@ -167,6 +173,11 @@ namespace Tnb.WarehouseMgr await _db.Ado.RollbackTranAsync(); throw; } + finally + { + //向队列写入消息 + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return Task.FromResult(true); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs index 3b7f9ecc..facb0a09 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryMoveOutStockService.cs @@ -45,7 +45,8 @@ namespace Tnb.WarehouseMgr IVisualDevService visualDevService, IWareHouseService wareHouseService, IUserManager userManager, - IBillRullService billRullService) + IBillRullService billRullService, + ITaskMessageNotify taskMessageNotify) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _runService = runService; @@ -124,10 +125,11 @@ namespace Tnb.WarehouseMgr preTask.create_time = DateTime.Now; return preTask; }).ToList(); - if (loc.is_sign ==0 ) { + if (loc.is_sign == 0) + { preTasks[^1].is_sign = 0; // 修改最后一个元素的是否签收值 } - var isOk = await _wareHouseService.GenPreTask(preTasks,null!); + var isOk = await _wareHouseService.GenPreTask(preTasks, null!); if (isOk) { var preTaskUpInput = new GenPreTaskUpInput(); @@ -142,7 +144,7 @@ namespace Tnb.WarehouseMgr await _db.Updateable().SetColumns(it => new WmsMoveOutstock { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync(); await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, - it => new WmsCarryH { is_lock = 1}, + it => new WmsCarryH { is_lock = 1 }, it => new BasLocation { is_lock = 1 }); } @@ -157,6 +159,10 @@ namespace Tnb.WarehouseMgr await _db.Ado.RollbackTranAsync(); throw; } + finally + { + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return Task.FromResult(true); } public override async Task ModifyAsync(WareHouseUpInput input) @@ -165,5 +171,5 @@ namespace Tnb.WarehouseMgr var isOk = await _db.Updateable().SetColumns(it => new WmsMoveOutstock { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandHasChangeAsync(); if (!isOk) throw Oops.Oh(ErrorCode.COM1001); } - } + } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs index e05bef60..63ee2b35 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCheckTaskService.cs @@ -43,7 +43,9 @@ namespace Tnb.WarehouseMgr IVisualDevService visualDevService, IRunService runService, IBillRullService billRullService, - IUserManager userManager) + IUserManager userManager, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _warehouseService = wareHouseService; @@ -218,6 +220,10 @@ namespace Tnb.WarehouseMgr await _db.Ado.RollbackTranAsync(); throw; } + finally + { + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return Task.FromResult(row); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs index 228a5137..0def8659 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsDeliveryService.cs @@ -54,8 +54,9 @@ namespace Tnb.WarehouseMgr IBasLocationService basLocationService, IWareHouseService wareHouseService, IUserManager userManager, - IBillRullService billRullService - ) + IBillRullService billRullService, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _runService = runService; @@ -191,6 +192,10 @@ namespace Tnb.WarehouseMgr { throw; } + finally + { + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return await Task.FromResult(true); } public override async Task ModifyAsync(WareHouseUpInput input) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs index f9b5abd4..018bb6a9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyInstockService.cs @@ -55,7 +55,7 @@ namespace Tnb.WarehouseMgr IUserManager userManager, IBillRullService billRullService, ITaskMessageNotify taskMesageNotify - ) + ) : base(taskMesageNotify.Writer) { _db = repository.AsSugarClient(); _runService = runService; @@ -188,8 +188,7 @@ namespace Tnb.WarehouseMgr finally { //向队列写入消息 - NotifyMessage message = new() { TaskName = nameof(IWareHouseService.GenTaskExecute) }; - await _channelWriter.WriteAsync(message); + await Publish(nameof(IWareHouseService.GenTaskExecute)); } return Task.FromResult(true); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs index 025e309e..a6318045 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsEmptyOutstockService .cs @@ -51,7 +51,9 @@ namespace Tnb.WarehouseMgr IVisualDevService visualDevService, IWareHouseService wareHouseService, IUserManager userManager, - IBillRullService billRullService) + IBillRullService billRullService, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _runService = runService; @@ -77,7 +79,8 @@ namespace Tnb.WarehouseMgr //判断目标库位是否自动签收 var loc = await _db.Queryable().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString()); //出库取起点,获取所有符合输入的载具规格的载具 - var OutStockStrategyInput = new OutStockStrategyQuery { + var OutStockStrategyInput = new OutStockStrategyQuery + { carrystd_id = input.data[nameof(OutStockStrategyQuery.carrystd_id)].ToString(), warehouse_id = input.data[nameof(OutStockStrategyQuery.warehouse_id)].ToString(), @@ -211,6 +214,10 @@ namespace Tnb.WarehouseMgr await _db.Ado.RollbackTranAsync(); throw; } + finally + { + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return Task.FromResult(true); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs index dc23aa1b..040507a4 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsInStockService.cs @@ -51,8 +51,9 @@ namespace Tnb.WarehouseMgr IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, - IPrdInstockService prdInstockService - ) + IPrdInstockService prdInstockService, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; @@ -70,11 +71,11 @@ namespace Tnb.WarehouseMgr public async Task GetInStockDetailsListById([FromRoute] string billId) { var dic = await _dictionaryDataService.GetDictionaryByTypeId(WmsWareHouseConst.WMS_INSTOCK_D_BILL_STATUS_TYPEID); - var items = await _db.Queryable().LeftJoin((a,b)=>a.warehouse_id == b.id) + var items = await _db.Queryable().LeftJoin((a, b) => a.warehouse_id == b.id) .Select((a, b) => new WmsInstockD { warehouse_name = b.whname - },true) + }, true) .Where(a => a.bill_id == billId).ToListAsync(); _db.ThenMapper(items, it => it.line_status = dic.ContainsKey(it.line_status) ? dic[it.line_status]?.ToString()! : ""); @@ -287,7 +288,7 @@ namespace Tnb.WarehouseMgr if (!isMatch) throw new AppFriendlyException("库位与载具规格不匹配", 500); loc = await _db.Queryable().FirstAsync(it => it.location_code == input.instock.location_code && it.is_type != EnumLocationType.存储库位.ToString()); - + //如果数据不全或有误, if (carry.IsNull() || loc.IsNull() || instockds?.Count < 1 || instockcodes?.Count < 1) { @@ -343,7 +344,7 @@ namespace Tnb.WarehouseMgr await _db.Insertable(instockCOdes).CallEntityMethod(it => it.Create(orgId)).ExecuteCommandAsync(); //生成预任务申请 - + if (sPoint != null && ePoint != null) { var points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); @@ -474,6 +475,10 @@ namespace Tnb.WarehouseMgr await _db.Ado.RollbackTranAsync(); //return await ToApiResult(JNPF.Common.Enums.HttpStatusCode.InternalServerError, ex.Message); } + finally + { + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return isSuccessFul; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs index ef3d8398..bc460308 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsKittingInStkService.cs @@ -48,7 +48,9 @@ namespace Tnb.WarehouseMgr IVisualDevService visualDevService, IWareHouseService wareHouseService, IUserManager userManager, - IBillRullService billRullService) + IBillRullService billRullService, + ITaskMessageNotify taskMessageNotify + ) : base(taskMessageNotify.Writer) { _db = repository.AsSugarClient(); _runService = runService; @@ -214,6 +216,10 @@ namespace Tnb.WarehouseMgr await _db.Ado.RollbackTranAsync(); throw; } + finally + { + await Publish(nameof(IWareHouseService.GenTaskExecute)); + } return Task.FromResult(true); } @@ -228,7 +234,7 @@ namespace Tnb.WarehouseMgr if (kittingOut != null) { var locaion = await _db.Queryable().SingleAsync(it => it.id == kittingOut.location_id); - if (locaion !=null && locaion.is_type.ToEnum() != EnumLocationType.存储库位) + if (locaion != null && locaion.is_type.ToEnum() != EnumLocationType.存储库位) { kittingOut.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID;