From b1027b6e49aa91ef30ed24e8311310209de4d01b Mon Sep 17 00:00:00 2001 From: majian <780924089@qq.com> Date: Mon, 29 Jul 2024 15:49:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E8=B4=A7=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E3=80=81=E5=8E=9F=E6=9D=90=E6=96=99=E4=BB=93=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=B0=83=E6=95=B4=E3=80=81=E6=97=A5=E5=BF=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 85 ++++-------- .../Dto/ErpInputs/SaleShippingInput.cs | 85 ++++++++++++ .../Dto/Outputs/LocationOutput.cs | 1 + .../Entity/WmsElevatorH.cs | 2 +- .../Entity/WmsSaleD.cs | 7 + .../Entity/WmsSaleH.cs | 10 ++ .../IWareHouseService.cs | 9 ++ .../Tnb.WarehouseMgr/BaseWareHouseService.cs | 5 + .../Tnb.WarehouseMgr/DeviceProviderService.cs | 89 ++++++++++++- .../Tnb.WarehouseMgr/ErpToWmsService.cs | 124 ++++++++++++++++++ .../LocationDefinitionService.cs | 9 +- .../Tnb.WarehouseMgr/WareHouseService.cs | 10 ++ .../Tnb.WarehouseMgr/WmsCarryBindService.cs | 16 ++- .../WmsCarryStockReportService.cs | 9 +- .../WmsMaterialTransferService.cs | 8 +- 15 files changed, 393 insertions(+), 76 deletions(-) create mode 100644 WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleShippingInput.cs diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 98242b94..6196ed5d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -391,9 +391,9 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA //扫码入库 private async void ScanInStock(object? state) { - if (s_taskScan.CurrentCount == 0) + if (_wareHouseService.s_taskExecuteSemaphore_YCLInstock.CurrentCount == 0) return; - await s_taskScan.WaitAsync(); + await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try @@ -485,7 +485,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA } finally { - s_taskScan.Release(); + _wareHouseService.s_taskExecuteSemaphore_YCLInstock.Release(); stopwatch.Stop(); Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行ScanInStock {stopwatch.ElapsedMilliseconds} ms"); LoggerTimer.LogInformation($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行ScanInStock {stopwatch.ElapsedMilliseconds} ms"); @@ -634,9 +634,13 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA /// private async void YCLInternalTransfer(object? state) { - if (s_taskYCLInternalTransfer.CurrentCount == 0) + if (_wareHouseService.s_taskExecuteSemaphore_YCLInstock.CurrentCount == 0) return; - await s_taskYCLInternalTransfer.WaitAsync(); + if (_wareHouseService.s_taskExecuteSemaphore_YCLOutstock.CurrentCount == 0) + return; + + await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync(); + await _wareHouseService.s_taskExecuteSemaphore_YCLOutstock.WaitAsync(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try @@ -650,7 +654,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID, Region_id = WmsWareHouseConst.REGION_YCLCache_ID, AvoidBusyPassage = true, - Size = 5, + Size = 76, filter_carry_status = false }; List items = await _wareHouseService.OutStockStrategy(outStockStrategyInput); @@ -704,7 +708,9 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA } finally { - s_taskYCLInternalTransfer.Release(); + _wareHouseService.s_taskExecuteSemaphore_YCLInstock.Release(); + _wareHouseService.s_taskExecuteSemaphore_YCLOutstock.Release(); + stopwatch.Stop(); Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行YCLInternalTransfer {stopwatch.ElapsedMilliseconds} ms"); LoggerTimer.LogInformation($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行YCLInternalTransfer {stopwatch.ElapsedMilliseconds} ms"); @@ -716,9 +722,9 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA /// private async void YCLGLDPJInstock(object? state) { - if (s_taskYCLGLDPJInstock.CurrentCount == 0) + if (_wareHouseService.s_taskExecuteSemaphore_YCLInstock.CurrentCount == 0) return; - await s_taskYCLGLDPJInstock.WaitAsync(); + await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try @@ -752,11 +758,11 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA continue; } - // 找到未锁定且未占用的库位 - var endLocations = db_YCLGLDPJInstocktimer.Queryable() - .Where(a => a.is_lock == 0 && a.is_use == "0" && a.wh_id == WmsWareHouseConst.WAREHOUSE_YCL_ID && a.location_code.Contains("YCL-") && a.is_type == "0"); - LoggerYCLGLDPJInstock.LogInformation($"【YCLGLDPJInstock】 sql {endLocations.ToSqlString()}"); + // 找到未锁定且未占用的库位 + + InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_Purchase_ID }; + List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); if (endLocations.Count() == 0) { @@ -802,7 +808,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA } finally { - s_taskYCLGLDPJInstock.Release(); + _wareHouseService.s_taskExecuteSemaphore_YCLInstock.Release(); stopwatch.Stop(); Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行YCLGLDPJInstock {stopwatch.ElapsedMilliseconds} ms"); LoggerTimer.LogInformation($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行YCLGLDPJInstock {stopwatch.ElapsedMilliseconds} ms"); @@ -814,9 +820,9 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA /// private async void YCLWXDPJInstock(object? state) { - if (s_taskYCLWXDPJInstock.CurrentCount == 0) + if (_wareHouseService.s_taskExecuteSemaphore_YCLInstock.CurrentCount == 0) return; - await s_taskYCLWXDPJInstock.WaitAsync(); + await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try @@ -849,10 +855,8 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA } // 找到未锁定且未占用的库位 - var endLocations = db_YCLWXDPJInstocktimer.Queryable() - .Where(a => a.is_lock == 0 && a.is_use == "0" && a.wh_id == WmsWareHouseConst.WAREHOUSE_YCL_ID && a.location_code.Contains("YCL-") && a.is_type == "0"); - - LoggerYCLGLDPJInstock.LogInformation($"【YCLWXDPJInstock】 sql {endLocations.ToSqlString()}"); + InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_Purchase_ID }; + List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); if (endLocations.Count() == 0) { @@ -897,7 +901,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA } finally { - s_taskYCLWXDPJInstock.Release(); + _wareHouseService.s_taskExecuteSemaphore_YCLInstock.Release(); stopwatch.Stop(); Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行YCLWXDPJInstock {stopwatch.ElapsedMilliseconds} ms"); LoggerTimer.LogInformation($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 结束执行YCLWXDPJInstock {stopwatch.ElapsedMilliseconds} ms"); @@ -2459,41 +2463,6 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA public Task StartAsync(CancellationToken cancellationToken) { - //Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300)); - CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - SSXcodetimer = new Timer(SSXcode, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - // 八工位缓存区补充空托盘 - BGWCarrySupplementtimer = new Timer(BGWCarrySupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - - // 供料叠盘机空托盘自动入库 - YCLGLDPJInstocktimer = new Timer(YCLGLDPJInstock, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - - // 外协叠盘机空托盘自动入库 - //YCLWXDPJInstocktimer = new Timer(YCLWXDPJInstock, null, TimeSpan.Zero, TimeSpan.FromSeconds(100000)); - - // 二楼上升降机 - Floor2UpMachinecodetimer = new Timer(Floor2UpMachinecode, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - - // 二楼料架配送 - Floor2timer送空托到上升降区 = new Timer(送空托到上升降区, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - Floor2timer送满托到下升降区 = new Timer(送满托到下升降区, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - Floor2timer移走上升降区未生成预任务且满托的料架 = new Timer(移走上升降区未生成预任务且满托的料架, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - Floor2timer移走下升降区未生成预任务且空托的料架 = new Timer(移走下升降区未生成预任务且空托的料架, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - - GenTaskExecutetimer = new Timer(GenTaskExecute, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - - // 停用 - //PackOutstockServicetimer = new Timer(PackOutstockService, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); - - ElevatorTaskExceptionHandleThread = new Thread(ElevatorTaskExceptionHandle); - ElevatorTaskExceptionHandleThread.Start(); - - Floor4DMJ2MJXtimer = new Timer(Floor4DMJ2MJX, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - Floor4MJX2MJCtimer = new Timer(Floor4MJX2MJC, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - Floor4DMC2CPKtimer = new Timer(Floor4DMC2CPK, null, TimeSpan.Zero, TimeSpan.FromSeconds(2)); - - F2KTPsupplementtimer = new Timer(F2KTPsupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(2));//Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300)); CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(60)); SSXcodetimer = new Timer(SSXcode, null, TimeSpan.Zero, TimeSpan.FromSeconds(10)); @@ -2504,7 +2473,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA YCLGLDPJInstocktimer = new Timer(YCLGLDPJInstock, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); // 外协叠盘机空托盘自动入库 - //YCLWXDPJInstocktimer = new Timer(YCLWXDPJInstock, null, TimeSpan.Zero, TimeSpan.FromSeconds(100000)); + YCLWXDPJInstocktimer = new Timer(YCLWXDPJInstock, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); // 二楼上升降机 Floor2UpMachinecodetimer = new Timer(Floor2UpMachinecode, null, TimeSpan.Zero, TimeSpan.FromSeconds(20)); @@ -2528,7 +2497,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA Floor4DMC2CPKtimer = new Timer(Floor4DMC2CPK, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); F2KTPsupplementtimer = new Timer(F2KTPsupplement, null, TimeSpan.Zero, TimeSpan.FromSeconds(30)); - YCLInternalTransfertimer = new Timer(YCLInternalTransfer, null, TimeSpan.Zero, TimeSpan.FromSeconds(180)); + YCLInternalTransfertimer = new Timer(YCLInternalTransfer, null, TimeSpan.Zero, TimeSpan.FromSeconds(10800)); return Task.CompletedTask; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleShippingInput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleShippingInput.cs new file mode 100644 index 00000000..659196bd --- /dev/null +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/ErpInputs/SaleShippingInput.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tnb.WarehouseMgr.Entities.Dto.ErpInputs +{ + public class SaleShippingInput + { + /// + /// 销售发货单号 + /// + public string? bill_code { get; set; } + + /// + /// 单据类型 + /// + public string? bill_type { get; set; } + + /// + /// 单据状态 + /// + public string? bill_status { get; set; } + + /// + /// 出库仓库编号 + /// + public string? warehouse_code { get; set; } + + /// + /// 客户编码 + /// + public string? customer_code { get; set; } + + /// + /// 客户名称 + /// + public string? customer_name { get; set; } + + /// + /// 供货日期 + /// + public DateTime? ship_date { get; set; } + + /// + /// 主表主键 + /// + public string erp_pk { get; set; } + + public List details { get; set; } + } + public class SaleShippingDetail + { + /// + /// 行号 + /// + public string? lineno { get; set; } + + /// + /// 物料代码 + /// + public string? material_code { get; set; } + + /// + /// 单位代码 + /// + public string? unit_code { get; set; } + + /// + /// 批号 + /// + public string? code_batch { get; set; } + + /// + /// 发货数量 + /// + public decimal? sale_qty { get; set; } + + /// + /// 子表主键 + /// + public string erp_line_pk { get; set; } + } +} diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Outputs/LocationOutput.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Outputs/LocationOutput.cs index efc54103..ae74e9a0 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Outputs/LocationOutput.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Dto/Outputs/LocationOutput.cs @@ -13,6 +13,7 @@ namespace Tnb.WarehouseMgr.Entities.Dto public int layers { get; set; } public string carry_code { get; set; } public string material_code { get; set; } + public string code_batch { get; set; } public decimal num { get; set; } } public class ZsjOutput diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.cs index ec8eff6e..e13b112a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsElevatorH.cs @@ -99,5 +99,5 @@ public partial class WmsElevatorH : BaseEntity /// /// 占用任务 /// - public int use_tasks { get; set; } + public string use_tasks { get; set; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleD.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleD.cs index d035a196..2e84774a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleD.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleD.cs @@ -91,4 +91,11 @@ public partial class WmsSaleD : BaseEntity /// 箱号 /// public string? container_no { get; set; } + + /// + /// erp_line_pk + /// + public string? erp_line_pk { get; set; } + + } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs index 24e35d0b..2bebb16b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsSaleH.cs @@ -145,4 +145,14 @@ public partial class WmsSaleH : BaseEntity, IPurchaseAndSaleAuitEntity /// public int? audit_status { get; set; } + /// + /// erp_pk + /// + public string? erp_pk { get; set; } + + /// + /// erp_bill_code + /// + public string? erp_bill_code { get; set; } + } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs index 09289694..e7c7ecf5 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs @@ -15,6 +15,15 @@ namespace Tnb.WarehouseMgr.Interfaces /// public interface IWareHouseService { + /// + /// 原材料入库 + /// + SemaphoreSlim s_taskExecuteSemaphore_YCLInstock { get; } + /// + /// 原材料出库 + /// + SemaphoreSlim s_taskExecuteSemaphore_YCLOutstock { get; } + /// /// 入库策略 /// diff --git a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs index a27521a6..977a1e94 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/BaseWareHouseService.cs @@ -47,6 +47,11 @@ namespace Tnb.WarehouseMgr public static SemaphoreSlim s_taskExecuteSemaphore = new(1); public static SemaphoreSlim s_elevatorStatusSemaphore = new(1); + + public static SemaphoreSlim _s_taskExecuteSemaphore_YCLInstock = new(1); + public static SemaphoreSlim _s_taskExecuteSemaphore_YCLOutstock = new(1); + + protected static Dictionary _s_eleUseStatusDic; protected IEventPublisher? EventPublisher { set; get; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs b/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs index 65ce09b7..6360385c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/DeviceProviderService.cs @@ -477,16 +477,43 @@ namespace Tnb.WarehouseMgr } else { - // 排除电梯任务 其他任务取消时自动解锁终点库位 - int unlockRow = await _db.Updateable().SetColumns(r => r.is_lock == 0).Where(r => r.location_code == wmsDistaskH.endlocation_code).ExecuteCommandAsync(); - if (unlockRow > 0) + // 排除电梯任务 其他任务取消时自动解锁起点和终点库位 + + //int unlockStartRow = await _db.Updateable().SetColumns(r => r.is_lock == 0).Where(r => r.location_code == wmsDistaskH.startlocation_code).ExecuteCommandAsync(); + //if (unlockStartRow > 0) + //{ + // Logger.Information($"成功解锁起点库位{wmsDistaskH.startlocation_code}"); + //} + //else + //{ + // Logger.Information($"未成功解锁起点库位{wmsDistaskH.startlocation_code}"); + //} + + int unlockEndRow = await _db.Updateable().SetColumns(r => r.is_lock == 0).Where(r => r.location_code == wmsDistaskH.endlocation_code).ExecuteCommandAsync(); + if (unlockEndRow > 0) { - Logger.Information($"成功解锁库位{wmsDistaskH.endlocation_code}"); + Logger.Information($"成功解锁终点库位{wmsDistaskH.endlocation_code}"); } else { - Logger.Information($"未成功解锁库位{wmsDistaskH.endlocation_code}"); + Logger.Information($"未成功解锁终点库位{wmsDistaskH.endlocation_code}"); } + + int unlockCarryRow = await _db.Updateable().SetColumns(r => new WmsCarryH + { + is_lock = 0, + //location_id = wmsDistaskH.startlocation_code.Contains("BGWRKYCL0") ? WmsWareHouseConst.LOCATION_YCLBGWDRK : r.location_id, + //location_code = wmsDistaskH.startlocation_code.Contains("BGWRKYCL0") ? "YCLBGWDRK" : r.location_code + }).Where(r => r.carry_code == wmsDistaskH.carry_code).ExecuteCommandAsync(); + if (unlockCarryRow > 0) + { + Logger.Information($"成功解锁载具{wmsDistaskH.carry_code}"); + } + else + { + Logger.Information($"未成功解锁载具{wmsDistaskH.carry_code}"); + } + } } @@ -515,6 +542,58 @@ namespace Tnb.WarehouseMgr if (row > 0) { List wmsDistaskHCodes = _db.Queryable().Where(P => P.bill_code.Contains(input.taskChainCode)).Select(r => r.pretask_code).ToList(); + List wmsDistaskHs = _db.Queryable().Where(P => P.bill_code.Contains(input.taskChainCode)).ToList(); + + foreach (WmsDistaskH wmsDistaskH in wmsDistaskHs) + { + if (wmsDistaskH.startlocation_code.Contains("DT") || wmsDistaskH.endlocation_code.Contains("DT")) + { + //WmsElevatorUnlockInput wmsElevatorUnlockInput = new (); + //wmsElevatorUnlockInput.elevator_id = wmsDistaskH.device_id; + //await WmsElevatorUnlock(wmsElevatorUnlockInput); + //Logger.Information($"WCS取消任务{wmsDistaskH.bill_code},自动解占用电梯{wmsDistaskH.device_id}"); + } + else + { + // 排除电梯任务 其他任务取消时自动解锁起点和终点库位 + + //int unlockStartRow = await _db.Updateable().SetColumns(r => r.is_lock == 0).Where(r => r.location_code == wmsDistaskH.startlocation_code).ExecuteCommandAsync(); + //if (unlockStartRow > 0) + //{ + // Logger.Information($"成功起点解锁库位{wmsDistaskH.startlocation_code}"); + //} + //else + //{ + // Logger.Information($"未成功解锁起点库位{wmsDistaskH.startlocation_code}"); + //} + + int unlockEndRow = await _db.Updateable().SetColumns(r => r.is_lock == 0).Where(r => r.location_code == wmsDistaskH.endlocation_code).ExecuteCommandAsync(); + if (unlockEndRow > 0) + { + Logger.Information($"成功终点解锁库位{wmsDistaskH.endlocation_code}"); + } + else + { + Logger.Information($"未成功解锁终点库位{wmsDistaskH.endlocation_code}"); + } + + int unlockCarryRow = await _db.Updateable().SetColumns(r => new WmsCarryH + { + is_lock = 0, + //location_id = wmsDistaskH.startlocation_code.Contains("BGWRKYCL0") ? WmsWareHouseConst.LOCATION_YCLBGWDRK : wmsDistaskH.startlocation_id, + //location_code = wmsDistaskH.startlocation_code.Contains("BGWRKYCL0") ? "YCLBGWDRK" : wmsDistaskH.startlocation_code + }).Where(r => r.carry_code == wmsDistaskH.carry_code).ExecuteCommandAsync(); + if (unlockCarryRow > 0) + { + Logger.Information($"成功解锁载具{wmsDistaskH.carry_code}"); + } + else + { + Logger.Information($"未成功解锁载具{wmsDistaskH.carry_code}"); + } + } + } + await _db.Updateable().SetColumns(r => new WmsPretaskH { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs index 77e7d5b9..7cfb770c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs @@ -670,6 +670,130 @@ namespace Tnb.WarehouseMgr } } + /// + /// 销售发货单 + /// + [HttpPost, NonUnify, AllowAnonymous] + public async Task SaleShipping(SaleShippingInput input) + { + + + LoggerErp2Mes.LogInformation($"【SaleShipping】ERP传入数据:{JsonConvert.SerializeObject(input)}"); + var db = _repository.AsSugarClient(); + + if (string.IsNullOrEmpty(input.erp_pk)) + { + _LoggerErp2Mes.LogWarning($"【SaleShipping】主表主键不能为空!"); + return await ToApiResult(HttpStatusCode.InternalServerError, $"主表主键不能为空!"); + } + + int count_erp_line_pk = input.details.Where(r => string.IsNullOrEmpty(r.erp_line_pk)).Count(); + if (count_erp_line_pk > 0) + { + _LoggerErp2Mes.LogWarning($@"【SaleShipping】子表主键不能为空!"); + throw new AppFriendlyException($@"子表主键不能为空!", 500); + } + + var wmsSaleShippingsDistinct = input.details.Select(r => new + { + material_id = r.material_code, + code_batch = r.code_batch, + }).Distinct(); + if (wmsSaleShippingsDistinct.Count() < input.details.Count) + { + _LoggerErp2Mes.LogWarning($@"【SaleShipping】表体存在物料和批号重复的明细!"); + throw new AppFriendlyException($@"表体存在物料和批号重复的明细!", 500); + } + + BasWarehouse warehouse_outstock = await db.Queryable().Where(r => r.whcode == input.warehouse_code).FirstAsync(); + if (warehouse_outstock == null) + { + _LoggerErp2Mes.LogWarning($"【MaterialTransfer】无法查询到出库仓库{input.warehouse_code}的档案记录!"); + return await ToApiResult(HttpStatusCode.InternalServerError, $"无法查询到出库仓库{input.warehouse_code}的档案记录!"); + } + + try + { + await db.Ado.BeginTranAsync(); + WmsSaleH wmsSaleH = new WmsSaleH(); + string Code = await _billRuleService.GetBillNumber("WmsSale"); + + wmsSaleH.bill_code = Code; + wmsSaleH.erp_bill_code = input.bill_code; + wmsSaleH.bill_type = "25103439022357";//销售出库单 + wmsSaleH.status = WmsWareHouseConst.BILLSTATUS_ADD_ID; + wmsSaleH.warehouse_id = warehouse_outstock.id; + wmsSaleH.customer_code = input.customer_code; + var customer = await db.Queryable().Where(p => p.customer_code == input.customer_code).FirstAsync(); + if (customer != null) + { + wmsSaleH.customer_id = customer.id; + wmsSaleH.customer_name = customer.customer_name; + } + + wmsSaleH.ship_date = input.ship_date.Value; + wmsSaleH.erp_pk = input.erp_pk; + wmsSaleH.create_id = WmsWareHouseConst.ErpUserId; + wmsSaleH.create_time = DateTime.Now; + + await db.Insertable(wmsSaleH).ExecuteCommandAsync(); + + + List wmsSaleDs = new List(); + foreach (var detail in input.details) + { + WmsSaleD wmsSaleD = new WmsSaleD(); + + wmsSaleD.bill_id = wmsSaleH.id; + wmsSaleD.material_code = detail.material_code; + wmsSaleD.purchase_qty = detail.sale_qty.Value; + wmsSaleD.code_batch = detail.code_batch; + wmsSaleD.erp_line_pk = detail.erp_line_pk; + wmsSaleD.create_id = WmsWareHouseConst.ErpUserId; + wmsSaleD.create_time = DateTime.Now; + + var erpExtendField = await db.Queryable().InnerJoin((a, b) => a.table_id == b.Id).Where((a, b) => a.cunitid == detail.unit_code).Select((a, b) => b).FirstAsync(); + if (erpExtendField != null) + { + wmsSaleD.unit_id = erpExtendField.Id; + } + else + { + _LoggerErp2Mes.LogWarning($@"【MaterialTransfer】表体明细中单位{detail.unit_code}在wms系统中未找到!"); + throw new AppFriendlyException($@"表体明细中单位{detail.unit_code}在wms系统中未找到!", 500); + } + + var material = await db.Queryable().Where(p => p.code == detail.material_code).FirstAsync(); + if (material != null) + { + wmsSaleD.material_id = material.id; + wmsSaleD.material_name = material.name; + wmsSaleD.material_specification = material.material_specification; + } + + wmsSaleDs.Add(wmsSaleD); + } + + await db.Insertable(wmsSaleDs).ExecuteCommandAsync(); + + await db.Ado.CommitTranAsync(); + + LoggerErp2Mes.LogInformation($"【SaleShipping】成功生成单据:{Code}"); + return await ToApiResult(HttpStatusCode.OK, "成功"); + } + catch (Exception ex) + { + LoggerErp2Mes.LogError($"【SaleShipping】{ex.Message}"); + LoggerErp2Mes.LogError($"【SaleShipping】{ex.StackTrace}"); + await db.Ado.RollbackTranAsync(); + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); + } + finally + { + + } + } + protected Task ToApiResult(HttpStatusCode statusCode, string msg) { Entities.Dto.Outputs.Result result = new() diff --git a/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs b/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs index 15058eed..edc8da20 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/LocationDefinitionService.cs @@ -174,7 +174,7 @@ namespace Tnb.WarehouseMgr public async Task GetYCLlocation() { List> LocationOutputss=new List>(); - var list =await _db.Queryable().Where(p=> p.wh_id == "1" && p.region_id== "26125793924133"&& p.is_type == "0" && p.location_code.Length==9).OrderBy(p=>p.location_code).ToListAsync(); + var list =await _db.Queryable().Where(p=> p.wh_id == "1" && p.is_type == "0" && !p.location_code.Contains("-3")).OrderBy(p=>p.location_code).ToListAsync(); var carrys=await _db.Queryable().ToListAsync(); var carrycodes=await _db.Queryable().ToListAsync(); var lastdata=string.Empty; @@ -187,7 +187,7 @@ namespace Tnb.WarehouseMgr LocationOutputs = new List(); } LocationOutput locationOutput = new LocationOutput(); - locationOutput.location_code = data.location_code; + locationOutput.location_code = data.location_code.Replace("YCL-", ""); locationOutput.layers = data.layers; locationOutput.type = 0; if (carrys.Where(p => p.location_id == data.id).Any()) @@ -200,11 +200,16 @@ namespace Tnb.WarehouseMgr var carrycode = carrycodes.Where(p => p.carry_id == carry.id).First(); locationOutput.type = 2; locationOutput.material_code = carrycode.material_code; + locationOutput.code_batch = carrycode.code_batch; locationOutput.num = carrycode.codeqty; } } lastdata = data.location_code; LocationOutputs.Add(locationOutput); + + // 。。。。。。 + if (data.location_code == list[list.Count - 1].location_code) + LocationOutputss.Add(LocationOutputs); } return LocationOutputss; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 118053b5..a20835a2 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -87,6 +87,16 @@ namespace Tnb.WarehouseMgr public Func AddUnExecuteTask { get; set; } + + public SemaphoreSlim s_taskExecuteSemaphore_YCLInstock + { + get { return _s_taskExecuteSemaphore_YCLInstock; } + } + + public SemaphoreSlim s_taskExecuteSemaphore_YCLOutstock + { + get { return _s_taskExecuteSemaphore_YCLOutstock; } + } public WareHouseService(ISqlSugarRepository repository, IDictionaryDataService dictionaryDataService, StackExRedisHelper redisData, IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService, diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs index 4b9c7bec..fb481876 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryBindService.cs @@ -165,6 +165,17 @@ namespace Tnb.WarehouseMgr try { WmsCarryH? carry = await _db.Queryable().SingleAsync(it => it.carry_code == input.carrycode); + if (carry == null) + { + throw new Exception($"托盘{input.carrycode}不存在!"); + } + + var _WmsCarryCode = _db.Queryable().Where(it => it.carry_id == carry.id).OrderByDescending(it => it.id).First(); + if (_WmsCarryCode != null) + { + throw new Exception($"托盘{input.carrycode}已绑定物料!"); + } + List WmsCarryCodes = new List(); foreach (var detail in input.details) { @@ -183,7 +194,8 @@ namespace Tnb.WarehouseMgr await _db.Updateable().SetColumns(r => new WmsCarryH { location_id = WmsWareHouseConst.LOCATION_YCLBGWDRK, - location_code = "YCLBGWDRK" + location_code = "YCLBGWDRK", + carry_status = "1" }).Where(r => r.id == carry.id).ExecuteCommandAsync(); if (rows == 0) { @@ -194,7 +206,7 @@ namespace Tnb.WarehouseMgr { Logger.LogError(ex.Message); Logger.LogError(ex.StackTrace); - throw new AppFriendlyException($"绑定失败(1.可能是存在已被绑定的条码 2.存在其他与此载具编号相同的载具 3.存在字段传了空值) {ex.Message}", 500); + throw new AppFriendlyException($"绑定失败(1.可能是存在已被绑定的条码 2.系统中存在其他与此托盘编号相同的托盘 3.存在字段传了空值) {ex.Message}", 500); } catch (Exception ex) { diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs index 2b12868d..3f7e3105 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsCarryStockReportService.cs @@ -59,7 +59,7 @@ namespace Tnb.WarehouseMgr && ((!string.IsNullOrEmpty(b.carry_code) && b.carry_status != "0" && b.carry_status != "6") || string.IsNullOrEmpty(b.carry_code))) .WhereIF(!string.IsNullOrEmpty(warehouse_id), (a, b, c, d) => c.id == warehouse_id) .WhereIF(!string.IsNullOrEmpty(carry_code), (a, b, c, d) => b.carry_code.Contains(carry_code)) - .WhereIF(!string.IsNullOrEmpty(material_code), (a, b, c, d, e, f) => f.code.Contains(material_code)) + .WhereIF(!string.IsNullOrEmpty(material_code), (a, b, c, d, e, f) => e.material_code.Contains(material_code)) .OrderByDescending((a, b, c, d, e, f) => b.carry_code) .Select((a, b, c, d, e, f) => new WmsCarryStockReport { @@ -83,9 +83,9 @@ namespace Tnb.WarehouseMgr creator = e.create_id, bind_time = e.create_time != null ? e.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "" }) + .OrderBy((a) => a.location_code) .ToListAsync(); - // 料架 List items_LJ = await _db.Queryable() .LeftJoin((a, b) => b.location_id == a.id) @@ -123,14 +123,15 @@ namespace Tnb.WarehouseMgr creator = f.create_id, bind_time = f.create_time != null ? f.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss") : "" }) + .OrderBy((a) => a.location_code) .ToListAsync(); items.AddRange(items_LJ); // d.carrystd_name != "料架" - var storeMap = items.DistinctBy(x => new { x.carry_id }).ToDictionary(x => new { x.carry_id }, x => x); + var storeMap = items.DistinctBy(x => new { x.carry_id,x.location_code }).ToDictionary(x => new { x.carry_id, x.location_code }, x => x); - IEnumerable result = items.GroupBy(g => new { g.carry_id }).Select(itGroup => + IEnumerable result = items.GroupBy(g => new { g.carry_id, g.location_code }).Select(itGroup => { _ = storeMap.TryGetValue(itGroup.Key, out WmsCarryStockReport? report); WmsCarryStockReportH stockReport = report.Adapt(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs index 0833d66f..94f7b913 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs @@ -307,6 +307,7 @@ namespace Tnb.WarehouseMgr { try { + await _s_taskExecuteSemaphore_YCLOutstock.WaitAsync(); if (string.IsNullOrEmpty(input.source_id)) { throw new AppFriendlyException("来源单据id不可为空", 500); @@ -327,7 +328,6 @@ namespace Tnb.WarehouseMgr WmsMaterialTransferD wmsMaterialTransferD = await _db.Queryable().FirstAsync(it => it.id == input.source_id); WmsMaterialTransfer wmsMaterialTransfer = await _db.Queryable().FirstAsync(it => it.id == wmsMaterialTransferD.bill_id); - await s_taskExecuteSemaphore.WaitAsync(); if (wmsMaterialTransferD.yxfqty >= wmsMaterialTransferD.qty) { throw new AppFriendlyException("已下发数量已达到转库数量", 500); @@ -430,7 +430,7 @@ namespace Tnb.WarehouseMgr } finally { - _ = s_taskExecuteSemaphore.Release(); + _ = _s_taskExecuteSemaphore_YCLOutstock.Release(); InvokeGenPretaskExcute(); } @@ -1446,7 +1446,7 @@ namespace Tnb.WarehouseMgr throw new AppFriendlyException($"载具{input.carry_code}当前所在库位不是三工位!", 500); } - await s_taskExecuteSemaphore.WaitAsync(); + await _s_taskExecuteSemaphore_YCLInstock.WaitAsync(); await _db.Ado.BeginTranAsync(); @@ -1514,7 +1514,7 @@ namespace Tnb.WarehouseMgr } finally { - _ = s_taskExecuteSemaphore.Release(); + _ = _s_taskExecuteSemaphore_YCLInstock.Release(); InvokeGenPretaskExcute(); }