From 0be9c59a1fe3625f707705eba2042a4ac486e0ea Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Wed, 26 Mar 2025 21:53:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WCS.BLL/HardWare/MXL4Shelf.cs | 115 ++++++++++++++++-- WCS.BLL/Tool/Api/ApiHelp.cs | 2 +- .../MKYBackgroundThread/StockQueryRequest.cs | 11 ++ .../MKYBackgroundThread/StockQueryResponse.cs | 31 +++++ 4 files changed, 150 insertions(+), 9 deletions(-) create mode 100644 WCS.Model/ApiModel/MKYBackgroundThread/StockQueryRequest.cs create mode 100644 WCS.Model/ApiModel/MKYBackgroundThread/StockQueryResponse.cs diff --git a/WCS.BLL/HardWare/MXL4Shelf.cs b/WCS.BLL/HardWare/MXL4Shelf.cs index 73852c2..e096fa4 100644 --- a/WCS.BLL/HardWare/MXL4Shelf.cs +++ b/WCS.BLL/HardWare/MXL4Shelf.cs @@ -1,4 +1,5 @@ -using System; +using Newtonsoft.Json; +using System; using System.Reflection; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -6,10 +7,12 @@ using WCS.BLL.Config; using WCS.BLL.DbModels; using WCS.BLL.DbModels.Task; using WCS.BLL.Manager; +using WCS.BLL.Tool; using WCS.DAL.Db; using WCS.DAL.DbModels; using WCS.Model; using WCS.Model.ApiModel.InOutRecord; +using WCS.Model.ApiModel.MKYBackgroundThread; using WCS.Model.ApiModel.OutStore; using WCS.Model.WebSocketModel; using static WCS.BLL.HardWare.WarningLight; @@ -64,13 +67,20 @@ namespace WCS.BLL.HardWare Logs.Write($"[test]{ShelfCode}"); try { + Logs.Write($"[test]{ShelfCode}1"); + if (TcpCleint == null) + { + await Task.Delay(2000); + continue; + } + Logs.Write($"[test]{ShelfCode}2"); //未完成首次连接时 暂不发送 if (TcpCleint.IsFirstConnected == false) { await Task.Delay(2000); continue; } - + Logs.Write($"[test]{ShelfCode}3"); //查询属于本货架的任务 var currentShelfTasks = DbHelp.db.Queryable() .Where(t => t.ShelfId == this.ShelfId) @@ -85,9 +95,11 @@ namespace WCS.BLL.HardWare { t.IsNeedRefresh = true; } }); + Logs.Write($"[test]{ShelfCode}4"); //查询是否有需要刷新的 var needRefreshModules = MXL4Modules.Where(t => t.IsNeedRefresh) .ToList(); + Logs.Write($"[test]{ShelfCode}5"); foreach (var module in needRefreshModules) { try @@ -96,9 +108,11 @@ namespace WCS.BLL.HardWare var currentTasks = currentShelfTasks.Where(t => t.ModuleId == module.ModuleId) .OrderBy(t => t.CreateTime) .ToList(); + Logs.Write($"[test]{ShelfCode}5.1"); //入库、出库、盘点等任务 if (currentTasks != null && currentTasks.Count > 0) { + Logs.Write($"[test]{ShelfCode}5.2"); var firstTask = currentTasks.First(); var taskMode = currentTasks.First().TaskMode; #region 处理模组的模式 没有Continue @@ -188,9 +202,11 @@ namespace WCS.BLL.HardWare //不存在入库、出库、盘点等任务 应该变成待机 else { + Logs.Write($"[test]{ShelfCode}5.3"); //退出对应模式到待机模式! 后续持续刷新数据! if (module.CurrentMode != TaskModeEnum.待机模式) { + Logs.Write($"[test]{ShelfCode}5.4"); // 退出对应模式 switch (module.CurrentMode) { @@ -209,14 +225,80 @@ namespace WCS.BLL.HardWare continue; } + Logs.Write($"[test]{ShelfCode}5.5"); //向上层系统获取数据 - + var stockQueryUrl = @"http://10.41.235.10:18989/ztwcs/stockQuery"; + var dataBody = new StockQueryRequest(); + dataBody.storeCodes.Add(module.ModuleCode); + Logs.Write("111", LogsType.StartBoot); + var result = ApiHelp.GetDataFromHttp(stockQueryUrl, dataBody, "POST", true); + if (result == null) + { + Logs.Write("2222", LogsType.StartBoot); + continue; + } //获取成功 有数据 绑定对应数据 + if (result.code == 200) + { + + var jsonString = result.data; + Logs.Write($"3333{jsonString}", LogsType.StartBoot); + if (!string.IsNullOrEmpty(jsonString)) + { + Logs.Write($"44", LogsType.StartBoot); + // 去除所有双引号前面的反斜杠 + jsonString = Regex.Replace(jsonString, @"\\(.)", "$1"); ; + var data = JsonConvert.DeserializeObject>(jsonString); + if (data != null && data.Count > 0) + { + //硬件只能显示7个 只保留前7个 + if (data.Count > 7) + { + data = data.Take(7).ToList(); + } + + int taskid = 1; + foreach (var item in data) + { + module.SendTaskId(taskid++, TcpCleint); + module.SendMatCode(item.material_code, TcpCleint); + module.SendMatName(item.material_name, TcpCleint); + module.SendMatSpec("-", TcpCleint); + module.SendMatBatch(item.batch_no, TcpCleint); + module.SendMatQty((int)item.qty, TcpCleint); + } + module.IsNeedRefresh = false; + continue; + } + //库存里面无数据 + else + { + Logs.Write($"6666", LogsType.StartBoot); + //获取成功 无数据 + module.StandbyNoInfoDisplay(TcpCleint); + module.IsNeedRefresh = false;//未获取到库存数据 回没有库位显示信息给硬件 + //获取失败 跳过此次循环后继续获取 + continue; + } + } + else + { + + Logs.Write($"6666", LogsType.StartBoot); + //获取成功 无数据 + module.StandbyNoInfoDisplay(TcpCleint); + module.IsNeedRefresh = false;//未获取到库存数据 回没有库位显示信息给硬件 + //获取失败 跳过此次循环后继续获取 + continue; + } + + } + else + { + continue; + } + - //获取成功 无数据 - module.StandbyNoInfoDisplay(TcpCleint); - module.IsNeedRefresh = false;//未获取到库存数据 回没有库位显示信息给硬件 - //获取失败 跳过此次循环后继续获取 } } catch (Exception ex) @@ -226,6 +308,23 @@ namespace WCS.BLL.HardWare } } + + //刷新报警灯 + if (needRefreshModules != null && needRefreshModules.Count > 0) + { + var isShelfHaveTask = DbHelp.db.Queryable() + .Where(t => t.ShelfId == this.ShelfId) + .Where(t => t.IsSended == true) + .Any(); + if (isShelfHaveTask) + { + WarningLight.GreenLight(TcpCleint); + } + else + { + WarningLight.CloseLight(TcpCleint); + } + } } catch (Exception ex) { @@ -618,7 +717,7 @@ namespace WCS.BLL.HardWare MatBatch = task.MatBatch, MatSN = task.MatSN, CreateTime = task.CreateTime, - Qty= task.Qty, + Qty = task.Qty, FinishQty = finishQty, FinishTime = DateTime.Now, }; diff --git a/WCS.BLL/Tool/Api/ApiHelp.cs b/WCS.BLL/Tool/Api/ApiHelp.cs index 4f7e96d..cb2ccb1 100644 --- a/WCS.BLL/Tool/Api/ApiHelp.cs +++ b/WCS.BLL/Tool/Api/ApiHelp.cs @@ -326,7 +326,7 @@ namespace WCS.BLL.Tool HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = httpMethod; request.ContentType = "application/json"; - request.Timeout = 3000; + request.Timeout = 5000; if (!string.IsNullOrEmpty(data)) { diff --git a/WCS.Model/ApiModel/MKYBackgroundThread/StockQueryRequest.cs b/WCS.Model/ApiModel/MKYBackgroundThread/StockQueryRequest.cs new file mode 100644 index 0000000..1b89e5c --- /dev/null +++ b/WCS.Model/ApiModel/MKYBackgroundThread/StockQueryRequest.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.MKYBackgroundThread +{ + public class StockQueryRequest + { + public List storeCodes { get; set; } = new List(); + } +} diff --git a/WCS.Model/ApiModel/MKYBackgroundThread/StockQueryResponse.cs b/WCS.Model/ApiModel/MKYBackgroundThread/StockQueryResponse.cs new file mode 100644 index 0000000..6d4ca35 --- /dev/null +++ b/WCS.Model/ApiModel/MKYBackgroundThread/StockQueryResponse.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.MKYBackgroundThread +{ + /// + /// 库存查询返回实体 + /// + public class StockQueryResponse + { + public int code { get; set; } + + public string data { get; set; } + + public string message { get; set; } + } + + public class StockQueryResponseDataItem + { + public string batch_no { get; set; } = "-"; + + public string location_code { get; set; } = "-"; + + public decimal qty { get; set; } = 0; + + public string material_name { get; set; } = "-"; + + public string material_code { get; set; } = "-"; + } +}