From 9effa30fb0191c28ed8ba9dcb47f4a141b29f8d3 Mon Sep 17 00:00:00 2001 From: majian <780924089@qq.com> Date: Wed, 15 May 2024 12:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E6=A5=BC=E8=87=AA=E5=8A=A8=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E4=B8=AD=E5=82=A8=E4=BB=93=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.ProductionMgr/RedisBackGround.cs | 61 +++++--- .../Consts/WmsWareHouseConst.cs | 8 + .../IWareHouseService.cs | 7 + .../Tnb.WarehouseMgr/WareHouseService.cs | 143 ++++++++++++++++++ .../WmsPDACarryBindService.cs | 4 +- .../Tnb.WarehouseMgr/WmsSaleReleaseService.cs | 4 +- .../Configurations/ConnectionStrings.json | 4 +- 7 files changed, 205 insertions(+), 26 deletions(-) diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 3c2bb8a7..abd6b7b6 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -5,6 +5,7 @@ using System.Dynamic; using System.Security.Policy; using System.Text; using Aop.Api.Domain; +using Aspose.Cells.Charts; using JNPF; using JNPF.Common.Cache; using JNPF.Common.Core.Manager; @@ -36,6 +37,7 @@ using Tnb.ProductionMgr.Interfaces; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Configs; using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Entities.Dto.Inputs; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; @@ -441,7 +443,6 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA private void SSXcode(object state) { Dictionary dic = new Dictionary(); - //有问题 dic.Add("东面提升机输送线", new string[] { "下升降机判断请求", "下升降机判断条码", "下升降机判断完毕", "下升降机判断结果" }); Dictionary putdic = new Dictionary(); putdic.Add("SSX-111-011", 11); @@ -846,13 +847,24 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { throw new Exception($@"【送满托到下升降区】设定升降机满托{wmsMechanicalArmH.stackingposition}满托数量为 {LXCount} 结果为 {result}"); } - // 绑定料架 await db.Updateable().SetColumns(r => new WmsMechanicalArmH { mechanicalconfirm = 1, maxnum = LXCount }).Where(r => r.id == wmsMechanicalArmH.id).ExecuteCommandAsync(); + + LoggerFloor2UpDownMachine.LogInformation($@"【送满托到下升降区】 料架{wmsMechanicalArmH.rackid}下的料箱开始生成预任务"); + bool pretask_result = await _wareHouseService.Floor2EmptyCarryCreateZZCPretask(wmsMechanicalArmH.rackid); + if (pretask_result) + { + LoggerFloor2UpDownMachine.LogInformation($@"【送满托到下升降区】 料架{wmsMechanicalArmH.rackid}下的料箱生成预任务完成"); + } + else + { + LoggerFloor2UpDownMachine.LogInformation($@"【送满托到下升降区】 料架{wmsMechanicalArmH.rackid}下的料箱生成预任务失败"); + } + } return true; @@ -869,10 +881,11 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { string[] configs_upMachine = new string[2] { "二楼上升降机机械臂左", "二楼上升降机机械臂右" }; - // 找到没有绑定料架的且点位未锁定的料架区 + // 找到没有绑定料架的且库位未锁定的料架区 ISugarQueryable WmsMechanicalArmHsuagar = _repository.AsSugarClient().Queryable(). InnerJoin((a, b) => a.point_id == b.id) - .Where((a, b) => string.IsNullOrEmpty(a.rackcode) && b.is_lock == 0 && configs_upMachine.Contains(a.name)); + .InnerJoin((a, b, c) => b.location_id == c.id) + .Where((a, b, c) => string.IsNullOrEmpty(a.rackcode) && c.is_lock == 0 && configs_upMachine.Contains(a.name)); List WmsMechanicalArmHs = WmsMechanicalArmHsuagar.ToList(); @@ -944,10 +957,14 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { is_lock = 1 }).Where(r => r.id == startLocation.id).ExecuteCommandAsync(); - await _repository.AsSugarClient().Updateable().SetColumns(r => new WmsPointH + await _repository.AsSugarClient().Updateable().SetColumns(r => new BasLocation { is_lock = 1 - }).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); + }).Where(r => r.id == endPoint.location_id).ExecuteCommandAsync(); + //await _repository.AsSugarClient().Updateable().SetColumns(r => new WmsPointH + //{ + // is_lock = 1 + //}).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); LoggerFloor2RackDelivery.LogInformation($"【送空托到上升降区】 开始生成预任务 起点{startPoint.point_code} 终点{endPoint.point_code} 料架 {targetCarry.carry_code}"); @@ -979,13 +996,14 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA // 找到没有绑定料架的且点位未锁定的料架区 ISugarQueryable WmsMechanicalArmHsuagar = _repository.AsSugarClient().Queryable(). InnerJoin((a, b) => a.point_id == b.id) - .Where((a, b) => string.IsNullOrEmpty(a.rackcode) && b.is_lock == 0 && configs_upMachine.Contains(a.name)); + .InnerJoin((a, b, c) => b.location_id == c.id) + .Where((a, b, c) => string.IsNullOrEmpty(a.rackcode) && c.is_lock == 0 && configs_upMachine.Contains(a.name)); List WmsMechanicalArmHs = WmsMechanicalArmHsuagar.ToList(); if (WmsMechanicalArmHs.Count() == 0) { - //LoggerFloor2RackDelivery.LogWarning($"【送满托到下升降区】 无需补充料架区 {WmsMechanicalArmHsuagar.ToSqlString()}"); + LoggerFloor2RackDelivery.LogWarning($"【送满托到下升降区】 无需补充料架区 {WmsMechanicalArmHsuagar.ToSqlString()}"); return false; } @@ -1072,8 +1090,6 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA // 满料架 WmsCarryH targetCarry = wmsCarryHs[0]; - - WmsPointH startPoint = startPoints.First(); WmsPointH endPoint = endPoints.First(); @@ -1081,10 +1097,15 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { is_lock = 1 }).Where(r => r.id == startLocation.id).ExecuteCommandAsync(); - await _repository.AsSugarClient().Updateable().SetColumns(r => new WmsPointH + + await _repository.AsSugarClient().Updateable().SetColumns(r => new BasLocation { is_lock = 1 - }).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); + }).Where(r => r.id == endPoint.location_id).ExecuteCommandAsync(); + //await _repository.AsSugarClient().Updateable().SetColumns(r => new WmsPointH + //{ + // is_lock = 1 + //}).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); LoggerFloor2RackDelivery.LogInformation($"【送满托到下升降区】 开始生成预任务 起点{startPoint.point_code} 终点{endPoint.point_code} 料架 {targetCarry.carry_code}"); @@ -1177,10 +1198,10 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { is_lock = 1 }).Where(r => r.id == endLocation.id).ExecuteCommandAsync(); - await db.Updateable(r => new WmsPointH - { - is_lock = 1 - }).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); + //await db.Updateable(r => new WmsPointH + //{ + // is_lock = 1 + //}).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); LoggerFloor2RackDelivery.LogInformation($"【移走上升降区满托的料架】 开始执行预任务生成: 料架区为{wmsMechanicalArmH.name}{wmsMechanicalArmH.stackingposition} 料架为{wmsMechanicalArmH.rackcode}"); @@ -1290,10 +1311,10 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA { is_lock = 1 }).Where(r => r.id == endLocation.id).ExecuteCommandAsync(); - await db.Updateable(r => new WmsPointH - { - is_lock = 1 - }).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); + //await db.Updateable(r => new WmsPointH + //{ + // is_lock = 1 + //}).Where(r => r.id == endPoint.id).ExecuteCommandAsync(); LoggerFloor2RackDelivery.LogInformation($"【移走下升降区空托的料架】 开始执行预任务生成: 料架区为{wmsMechanicalArmH.name}{wmsMechanicalArmH.stackingposition} 料架为{wmsMechanicalArmH.rackcode}"); diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs index 5ccb9bcf..3550467c 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Consts/WmsWareHouseConst.cs @@ -314,5 +314,13 @@ /// 分拣任务生成Encode /// public const string WMS_SORTINGTASK_ENCODE = "Sortingtask"; + /// + /// 一楼中储仓出库工位 + /// + public const string ZZCSSX111011 = "32609244599317"; + /// + /// 一楼中储仓出库工位 + /// + public const string ZZCSSX111012 = "32609251845653"; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs index 2eaf6e40..5a5a9865 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Interfaces/IWareHouseService.cs @@ -97,5 +97,12 @@ namespace Tnb.WarehouseMgr.Interfaces /// /// Task Floor2MechanicalComplete(WmsDistaskH disTask, string action); + + /// + /// 二楼kiva把料架送到下升降机后生成中储仓入库任务 + /// + /// 料架id + /// + Task Floor2EmptyCarryCreateZZCPretask(string rackid); } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 9db3f2e1..7c7727f3 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -66,6 +66,8 @@ namespace Tnb.WarehouseMgr private readonly IConfiguration _configuration; private readonly RedisData _redisData; + public static SemaphoreSlim s_floor2CreatePretask = new(1); + public Func AddUnExecuteTask { get; set; } @@ -1628,6 +1630,10 @@ namespace Tnb.WarehouseMgr //更新电梯任务数量 _ = await _db.Updateable().SetColumns(it => new WmsElevatorH { task_nums = it.task_nums - 1}).Where(it => disTasks.Select(x => x.area_code).Contains(it.area_code)).ExecuteCommandAsync(); + // 更新中储仓任务数量 + _ = await _db.Updateable().SetColumns(it => new BasLocation { task_nums = it.task_nums - 1 }).Where(it => disTasks.Where(r => r.startlocation_code.Contains("SSX-111-011") || r.startlocation_code.Contains("SSX-111-012")).Select(x => x.startlocation_code).Contains(it.location_code)).ExecuteCommandAsync(); + + //更新载具,锁定状态为未锁定,更新载具的库位当前任务的目标库位 List<(string carry_id, string carry_status, string endlocation_id, string endlocation_code)> multiList = disTasks.Select(it => (it.carry_id, it.carry_status, it.endlocation_id, it.endlocation_code)).ToList(); @@ -1694,6 +1700,7 @@ namespace Tnb.WarehouseMgr await _wmsCarryBindService.CarryCodeUnbind(carryCodeUnbindInput); } } + // 成品调拨入库 else if (dt.biz_type == WmsWareHouseConst.BIZTYPE_WMSTRANSFERINSTOCK_ID) { if (dt.start_floor == 3 && dt.end_floor == 3) @@ -2205,6 +2212,142 @@ namespace Tnb.WarehouseMgr return data; } + + + /// + /// 二楼kiva把料架送到下升降机后生成中储仓入库任务 + /// + /// 料架id + /// + + public async Task Floor2EmptyCarryCreateZZCPretask(string rackid) + { + try + { + List wmsCarryCodes = _db.Queryable().Where(r => r.carry_id == rackid).ToList(); + + foreach (WmsCarryD wmsCarryD in wmsCarryCodes) + { + await s_floor2CreatePretask.WaitAsync(); + //入库取终点 //出库起点 + InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_ZC_ID, Size = 1 }; + List endLocations = await InStockStrategy(inStockStrategyInput); + if (endLocations.Count == 0) + { + Logger.LogWarning("没有可用的入库库位"); + continue; + } + WmsPointH sPoint = null!; + WmsPointH ePoint = null!; + + BasLocation basLocation011 = _db.Queryable().Where(r => r.id == WmsWareHouseConst.ZZCSSX111011).First(); + BasLocation basLocation012 = _db.Queryable().Where(r => r.id == WmsWareHouseConst.ZZCSSX111012).First(); + + BasLocation startLocation = basLocation011.task_nums >= basLocation012.task_nums ? basLocation012 : basLocation011; + + sPoint = await _db.Queryable().FirstAsync(it => it.location_id == startLocation.id); + if (endLocations?.Count > 0) + { + WmsCarryH carry = await _db.Queryable().SingleAsync(it => it.carry_code == wmsCarryD.membercarry_code); + //if (carry.carry_status == "1") + //{ + // throw new AppFriendlyException("载具已占用!", 500); + //} + //if (carry.is_lock == 1) + //{ + // throw new AppFriendlyException("载具已锁定!", 500); + //} + BasLocation loc = await _db.Queryable().SingleAsync(it => it.id == endLocations[0].id); + bool isMatch = await IsCarryAndLocationMatchByCarryStd(carry, loc); + if (!isMatch) + { + Logger.LogWarning("库位与载具规格不匹配"); + continue; + } + + ePoint = await _db.Queryable().FirstAsync(it => it.location_id == endLocations[0].id); + } + else + { + Logger.LogWarning($"库位{endLocations[0].location_code}未在点位表中维护对应点位"); + continue; + } + + + + Logger.LogInformation($"【送满托到下升降区】 开始生成一楼CTU'预任务 起点{sPoint.point_code} 终点{ePoint.point_code} 料箱 {wmsCarryD.membercarry_code}"); + List points = new List(); + points.Add(sPoint); + points.Add(ePoint); + + //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) + WmsPretaskH preTask = null; + string bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(); + List preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it => + { + WmsPointH? sPoint = it.FirstOrDefault(); + WmsPointH? ePoint = it.LastOrDefault(); + + preTask = new() + { + org_id = "", + startlocation_id = sPoint?.location_id!, + startlocation_code = sPoint?.location_code!, + endlocation_id = ePoint?.location_id!, + endlocation_code = ePoint?.location_code!, + start_floor = sPoint?.floor.ToString(), + end_floor = ePoint?.floor.ToString(), + startpoint_id = sPoint?.id!, + startpoint_code = sPoint?.point_code!, + endpoint_id = ePoint?.id!, + endpoint_code = ePoint?.point_code!, + bill_code = bill_code, + status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID, + biz_type = WmsWareHouseConst.BIZTYPE_WMSEMPTYINSTOCK_ID, + task_type = "", + carry_id = wmsCarryD.membercarry_id, + carry_code = wmsCarryD.membercarry_code, + area_id = sPoint?.area_id!, + area_code = it.Key, + require_id = "", + require_code = "", + create_id = "", + create_time = DateTime.Now + }; + + return preTask; + }).ToList(); + //更新页面 + //赋值签收状态 + + Logger.LogInformation($"开始执行 GenPreTask {JsonConvert.SerializeObject(preTasks)}"); + bool result = await GenPreTask(preTasks, null!); + Logger.LogInformation($"GenPreTask 结果 {result}"); + if (result) + { + _ = await _db.Updateable().SetColumns(it => new BasLocation { is_lock = 1 }).Where(r => r.id == endLocations[0].id).ExecuteCommandAsync(); + _ = await _db.Updateable().SetColumns(it => new BasLocation { task_nums = it.task_nums + 1 }).Where(r => r.id == startLocation.id).ExecuteCommandAsync(); + Logger.LogInformation($"成功生成预任务:{preTasks.First().bill_code}"); + } + else + { + Logger.LogInformation($"【二楼kiva把料架送到下升降机后生成中储仓入库任务】 未成功生成预任务 起点{sPoint.point_code} 终点{ePoint.point_code} 料箱 {wmsCarryD.membercarry_code}"); + } + s_floor2CreatePretask.Release(); + } + return true; + } + catch(Exception ex) + { + Logger.LogInformation($"【二楼kiva把料架送到下升降机后生成中储仓入库任务】:{ex}"); + s_floor2CreatePretask.Release(); + return false; + } + finally + { + s_floor2CreatePretask.Release(); + } + } #endregion } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs index 0bdbd943..38a8e726 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDACarryBindService.cs @@ -341,7 +341,7 @@ namespace Tnb.WarehouseMgr catch (Exception ex) { await _db.Ado.RollbackTranAsync(); - throw; + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); } finally { @@ -389,7 +389,7 @@ namespace Tnb.WarehouseMgr catch (Exception ex) { await _db.Ado.RollbackTranAsync(); - throw; + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); } return await ToApiResult(HttpStatusCode.OK, "成功"); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleReleaseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleReleaseService.cs index ff94d00f..24ff3d29 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleReleaseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsSaleReleaseService.cs @@ -325,7 +325,7 @@ namespace Tnb.WarehouseMgr catch (Exception ex) { await _db.Ado.RollbackTranAsync(); - throw; + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); } finally { @@ -379,7 +379,7 @@ namespace Tnb.WarehouseMgr catch (Exception ex) { await _db.Ado.RollbackTranAsync(); - throw; + return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); } return await ToApiResult(HttpStatusCode.OK, "成功"); diff --git a/apihost/Tnb.API.Entry/Configurations/ConnectionStrings.json b/apihost/Tnb.API.Entry/Configurations/ConnectionStrings.json index cedc7a1b..3195bfb6 100644 --- a/apihost/Tnb.API.Entry/Configurations/ConnectionStrings.json +++ b/apihost/Tnb.API.Entry/Configurations/ConnectionStrings.json @@ -2,8 +2,8 @@ "ConnectionStrings": { "ConfigId": "default", "DBType": "PostgreSQL", //MySql;SqlServer;Oracle;PostgreSQL;Dm;Kdbndp;Sqlite; - //"Host": "192.168.11.109", - "Host": "127.0.0.1", + "Host": "192.168.11.109", + //"Host": "127.0.0.1", "Port": "5432", //"DBName": "tianyi_db", //"UserName": "postgres",