From 46321e340bfbdf9eb79d540f658e1ada153a91a8 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Thu, 30 May 2024 15:48:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=87=BA=E5=BA=93=E7=95=8C=E9=9D=A2=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=BD=93=E5=89=8D=E6=AD=A3=E5=9C=A8=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=87=BA=E5=BA=93=E7=9A=84=E5=8D=95=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2.后台退出了入库模式 通知前台扫码枪退出入库 3.对接盟讯公司登录Mes接口 4.接口记录增加本地日志排查问题 --- WCS.BLL/DbModels/OutOrder.cs | 6 ++ WCS.BLL/HardWare/SmartShelf.cs | 15 +++++ WCS.BLL/Manager/MXBackgroundThread.cs | 8 +-- WCS.BLL/Services/Service/OutstoreService.cs | 17 +++-- WCS.BLL/Services/Service/UserService.cs | 64 +++++++++++++++++-- WCS.BLL/Tool/Api/ApiHelp.cs | 42 ++++++++++++ .../MXBackgroundThread/mesLoginRequest.cs | 13 ++++ WCS.Model/ApiModel/OutStore/OutOrderModel.cs | 1 + .../WebSocketModel/WebSocketMessageModel.cs | 5 ++ .../RequestResponseLoggingMiddleware.cs | 25 ++++++-- WCS.WebApi/Program.cs | 2 +- 货架标准上位机/ScannerManager.cs | 2 + .../ViewModels/InInventoryViewModel.cs | 2 +- .../MXViewModel/MXOutInventoryViewModel.cs | 5 +- 货架标准上位机/Views/InInventoryView.xaml | 4 +- .../Views/MXWindows/MXOutInventoryView.xaml | 37 ++++++++--- .../Views/Windows/UserLoginView.xaml.cs | 15 +++-- 货架标准上位机/WebSocket.cs | 19 +++++- 货架标准上位机/data/jsconfig.json | 4 +- 19 files changed, 243 insertions(+), 43 deletions(-) create mode 100644 WCS.Model/ApiModel/MXBackgroundThread/mesLoginRequest.cs diff --git a/WCS.BLL/DbModels/OutOrder.cs b/WCS.BLL/DbModels/OutOrder.cs index c0e7957..0784705 100644 --- a/WCS.BLL/DbModels/OutOrder.cs +++ b/WCS.BLL/DbModels/OutOrder.cs @@ -98,6 +98,12 @@ namespace WCS.BLL.DbModels /// [SugarColumn(IsIgnore = true)] public int RowNumber { get; set; } + + /// + /// 返回当前是否正在进行出库 + /// + [SugarColumn(IsIgnore = true)] + public bool IsOuting { get; set; } = false; } } diff --git a/WCS.BLL/HardWare/SmartShelf.cs b/WCS.BLL/HardWare/SmartShelf.cs index bf6a5cd..91c81c4 100644 --- a/WCS.BLL/HardWare/SmartShelf.cs +++ b/WCS.BLL/HardWare/SmartShelf.cs @@ -291,6 +291,21 @@ namespace WCS.BLL.HardWare } //报警灯熄灭 WarningLight.CloseLight(TcpCleint); + //通知前台货架已结束入库 + Task.Run(() => + { + var warningModel = new WebSocketMessageModel() + { + IsWarning = false, + WarningType = WarningTypeEnum.通知前台结束入库, + StoreId = 0, + StoreCode = "", + ShelfCode = ShelfCode, + ShelfId = ShelfId, + ClientIp = WebSocketIpAddress, + }; + WarningManager.SendWarning(warningModel); + }); } public void GoInOutstore(List MatDetails, OutOrder outOrder) diff --git a/WCS.BLL/Manager/MXBackgroundThread.cs b/WCS.BLL/Manager/MXBackgroundThread.cs index 559dfed..bab8644 100644 --- a/WCS.BLL/Manager/MXBackgroundThread.cs +++ b/WCS.BLL/Manager/MXBackgroundThread.cs @@ -145,8 +145,8 @@ namespace WCS.BLL.Manager .ToList(); foreach (var shelf in outStoreShelf) { + Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时(5min)未退出出库模式,系统后台自动退出!出库单[{shelf.OrderNumber}]"); shelf.GoOutOutstore(); - Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时(5min)未退出出库模式,系统后台自动退出!"); } #endregion @@ -156,14 +156,14 @@ namespace WCS.BLL.Manager .ToList(); foreach (var shelf in stockTakingShelf) { + Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时(5min)未退出盘点模式,系统后台自动退出!盘点单[{shelf.OrderNumber}]"); shelf.GoOutStocktaking(); - Logs.Write($"【定时任务:定时退出模式】货架【{shelf.ShelfCode}】超时(5min)未退出盘点模式,系统后台自动退出!"); } #endregion } catch (Exception e) { - Logs.Write("【定时任务:定时退出模式】" + e.Message,LogsType.Info); + Logs.Write("【定时任务:定时退出模式】" + e.Message, LogsType.Info); } } }); @@ -286,7 +286,7 @@ namespace WCS.BLL.Manager Logs.Write($"【定时任务】:监测警示灯关灯机制,关【{shelf.ShelfCode}】灯发送指令成功!"); } } - catch (Exception ex) + catch (Exception ex) { Logs.Write($"【定时任务】:监测警示灯关灯机制,关【{shelf.ShelfCode}】灯发生异常" + ex.Message); } diff --git a/WCS.BLL/Services/Service/OutstoreService.cs b/WCS.BLL/Services/Service/OutstoreService.cs index 8f73893..6e315bd 100644 --- a/WCS.BLL/Services/Service/OutstoreService.cs +++ b/WCS.BLL/Services/Service/OutstoreService.cs @@ -474,23 +474,30 @@ namespace WCS.BLL.Services.Service var recordsQueryable = DbHelp.db.Queryable() .Where(t => request.OrderExeStatus.Contains(t.OutOrderExeStatus)) .WhereIF(request.IsMXPD != null, t => t.IsMXPD == request.IsMXPD) - .WhereIF(LocalFile.Config.IsMx, t => t.CreateTime > DateTime.Now.AddDays(-3)); + .WhereIF(LocalFile.Config.IsMx, t => t.CreateTime > DateTime.Now.AddDays(-3)) + .WhereIF(!string.IsNullOrEmpty(LocalFile.Config.GroupName), t => t.GroupName == LocalFile.Config.GroupName); var totalCount = await recordsQueryable.CountAsync(); var records = await recordsQueryable .OrderByDescending(t => t.CreateTime) - //.Take(request.PageSize) .ToListAsync(); + //获取后台当前正在进行出库的订单 将出库状态反馈给前端 + var outingOrderNumbers = ShelfManager.Shelves + .Where(t => t.CurrentMode == HardWare.Mode.出库模式).Select(t => t.OrderNumber) + .ToList(); + foreach (var record in records) + { + if (outingOrderNumbers.Contains(record.OrderNumber)) + record.IsOuting = true; + } + return new PageQueryResponse() { Code = 200, Message = $"success", Data = new PageQueryResponseData() { - //TotalCount = totalCount, - //MaxPage = request.PageSize == 0 ? 0 : (int)Math.Ceiling((decimal)totalCount / request.PageSize), - //Count = records.Count, Lists = records.ToList() } }; diff --git a/WCS.BLL/Services/Service/UserService.cs b/WCS.BLL/Services/Service/UserService.cs index 8f705c8..53a144a 100644 --- a/WCS.BLL/Services/Service/UserService.cs +++ b/WCS.BLL/Services/Service/UserService.cs @@ -5,12 +5,16 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using TouchSocket.Core; +using WCS.BLL.Config; +using WCS.BLL.DbModels; using WCS.BLL.Manager; using WCS.BLL.Services.IService; +using WCS.BLL.Tool; using WCS.DAL; using WCS.DAL.Db.AuthDb; using WCS.Model; using WCS.Model.ApiModel; +using WCS.Model.ApiModel.MXBackgroundThread; using WCS.Model.ApiModel.User; namespace WCS.BLL.Services.Service @@ -394,15 +398,67 @@ namespace WCS.BLL.Services.Service } else//登录模式需要校验密码 { - user = await AuthDbHelp.db.Queryable() - .Where(t => t.LoginName == request.UserName) - .FirstAsync(); + #region 盟讯公司登录接入系统接口 + if (LocalFile.Config.IsMx) + { + #region 调用接口 接入盟讯公司登录 + try + { + var body = new + { + uername = request.UserName, + password = request.PassWord, + }; + var Result = ApiHelp.GetDataFromHttpShortTime("http://192.168.2.23:9213/integrate/login/queryGenerLogin", body, "POST", true); + //账号密码验证成功 + if (Result != null && Result.code == 200) + { + //判断系统中是否有对应用户 + user = await AuthDbHelp.db.Queryable() + .Where(t => t.LoginName == request.UserName) + .FirstAsync(); + //Mes登录成功后wcs这边也添加一个用户 + if (user == null) + { + user = new UserBase() + { + LoginName = request.UserName, + Password = request.PassWord, + RoleIds = new List() { 2 }, + IsAdmin = false, + Time = DateTime.Now, + }; + await AuthDbHelp.db.Insertable(user).ExecuteCommandAsync(); + } + else if (user.Password != request.PassWord) + { + user.Password = request.PassWord; + await AuthDbHelp.db.Updateable(user).ExecuteCommandAsync(); + } + } + //账号密码验证失败 + else + { + + } + } + catch (Exception e) + { + + } + #endregion + } + #endregion + if (user == null) + user = await AuthDbHelp.db.Queryable() + .Where(t => t.LoginName == request.UserName) + .FirstAsync(); if (user == null) { return new ResponseCommon() { Code = 201, - Message = $"登录失败:用户名[{request.UserName}]不存在!", + Message = $"登录失败:用户名[{request.UserName}]不存在或密码输入错误!", Data = null }; } diff --git a/WCS.BLL/Tool/Api/ApiHelp.cs b/WCS.BLL/Tool/Api/ApiHelp.cs index ae463ec..4ce9b0f 100644 --- a/WCS.BLL/Tool/Api/ApiHelp.cs +++ b/WCS.BLL/Tool/Api/ApiHelp.cs @@ -312,5 +312,47 @@ namespace WCS.BLL.Tool return default(T); } } + + public static T GetDataFromHttpShortTime(string url, object dataObj, string httpMethod, bool isSaveLog = false) + { + Guid guid = Guid.NewGuid(); + var data = dataObj == null ? string.Empty : JsonConvert.SerializeObject(dataObj); + try + { + if (isSaveLog) + Logs.Write($"【{guid}】开始请求调用接口 url:{url} 请求方式:{httpMethod} 数据:{data}", LogsType.Api); + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.Method = httpMethod; + request.ContentType = "application/json"; + request.Timeout = 2000; + + if (!string.IsNullOrEmpty(data)) + { + string strContent = data; //参数data + using (StreamWriter dataStream = new StreamWriter(request.GetRequestStream())) + { + dataStream.Write(strContent); + dataStream.Close(); + } + } + + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + string encoding = response.ContentEncoding; + if (encoding == null || encoding.Length < 1) + { + encoding = "UTF-8"; //默认编码 + } + StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding)); + string retString = reader.ReadToEnd(); + if (isSaveLog) + Logs.Write($"【{guid}】请求调用接口结束 返回数据为{retString}", LogsType.Api); + return JsonConvert.DeserializeObject(retString); + } + catch (Exception ex) + { + Logs.Write($"【{guid}】请求调用遇到异常 异常信息为{ex.Message}"); + return default(T); + } + } } } diff --git a/WCS.Model/ApiModel/MXBackgroundThread/mesLoginRequest.cs b/WCS.Model/ApiModel/MXBackgroundThread/mesLoginRequest.cs new file mode 100644 index 0000000..afe181b --- /dev/null +++ b/WCS.Model/ApiModel/MXBackgroundThread/mesLoginRequest.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.MXBackgroundThread +{ + public class MXResponse + { + public int code { get; set; } + public string msg { get; set; } + public object data { get; set; } + } +} diff --git a/WCS.Model/ApiModel/OutStore/OutOrderModel.cs b/WCS.Model/ApiModel/OutStore/OutOrderModel.cs index 63cd9de..393eea9 100644 --- a/WCS.Model/ApiModel/OutStore/OutOrderModel.cs +++ b/WCS.Model/ApiModel/OutStore/OutOrderModel.cs @@ -34,6 +34,7 @@ namespace WCS.Model.ApiModel.OutStore } public bool isSelected; public int RowNumber { get; set; } + public bool IsOuting { get; set; } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) diff --git a/WCS.Model/WebSocketModel/WebSocketMessageModel.cs b/WCS.Model/WebSocketModel/WebSocketMessageModel.cs index 34b693c..e702aa7 100644 --- a/WCS.Model/WebSocketModel/WebSocketMessageModel.cs +++ b/WCS.Model/WebSocketModel/WebSocketMessageModel.cs @@ -21,6 +21,10 @@ namespace WCS.Model.WebSocketModel /// public string ClientIp { get; set; } public DateTime LastSendTime { get; set; } + /// + /// 消息创建时间 跟消息时效性有关 + /// + public DateTime CreateTime { get; set; } = DateTime.Now; public bool ClientIsReceived { get; set; } //恢复正常需要消除的报警guid @@ -57,5 +61,6 @@ namespace WCS.Model.WebSocketModel 通知刷新出库 = 51, 通知刷新盘点 = 52, 通知刷新盟讯盘点 = 53, + 通知前台结束入库 = 54, } } diff --git a/WCS.WebApi/Controllers/RequestResponseLoggingMiddleware.cs b/WCS.WebApi/Controllers/RequestResponseLoggingMiddleware.cs index 7376953..13b7eff 100644 --- a/WCS.WebApi/Controllers/RequestResponseLoggingMiddleware.cs +++ b/WCS.WebApi/Controllers/RequestResponseLoggingMiddleware.cs @@ -72,28 +72,45 @@ namespace WCS.WebApi.Controllers finally { + var guid = Guid.NewGuid(); //TO DO如何将记日志的 和不记日志的分开 解耦 if (!context.Request.Path.ToString().Contains("getInterfaceRecord")) + { try { + Logs.Write($"[记录接口日志]{guid},开始记录{context.Request.Path.ToString()}", LogsType.Api); var logRecord = new SystemApiLogRecord() { DeviceIp = context?.Connection?.RemoteIpAddress?.ToString(), - RequestUrl = context.Request.Path, + RequestUrl = context.Request?.Path, RequestBody = requestBody, - QueryString = context.Request.QueryString.ToString(), + QueryString = context.Request?.QueryString.ToString(), IsResponse = true, ResponseJson = responseBody, RequestTime = requestTime, ResponseTime = DateTime.Now, ExecutionTime = stopwatch.ElapsedMilliseconds }; - await DbHelp.dbLog.Insertable(logRecord).ExecuteCommandAsync(); + Task.Run(() => + { + try + { + DbHelp.dbLog.Insertable(logRecord).ExecuteCommand(); + } + catch (Exception ex) + { + Logs.Write($"[记录接口日志]{guid}保存数据失败!发生异常:" + ex.Message, LogsType.Api); + } + + }); } catch (Exception e) { - //TO DO txt记录失败的日志和响应实体 + Logs.Write($"[记录接口日志]{guid}失败!发生异常:" + e.Message, LogsType.Api); } + } + else + Logs.Write($"[记录接口日志]{guid},不记录getInterfaceRecord", LogsType.Api); } } } diff --git a/WCS.WebApi/Program.cs b/WCS.WebApi/Program.cs index 61af649..bd72eca 100644 --- a/WCS.WebApi/Program.cs +++ b/WCS.WebApi/Program.cs @@ -45,7 +45,7 @@ namespace WebApi { MXBackgroundThread.InitBackgroundThread(); var str = string.Empty; - //MXBackgroundThread.SendDingDingMsg("ɹ", new List { "104379" }, ref str); + MXBackgroundThread.SendDingDingMsg("̨ɹ", new List { "104379" }, ref str); } diff --git a/货架标准上位机/ScannerManager.cs b/货架标准上位机/ScannerManager.cs index c46ab88..3742621 100644 --- a/货架标准上位机/ScannerManager.cs +++ b/货架标准上位机/ScannerManager.cs @@ -71,6 +71,8 @@ namespace 货架标准上位机 /// 是否在入库模式中 /// public bool IsInstoreMode { get; set; } + + public DateTime IsInstoreModeTime { get; set; } = DateTime.MinValue; /// /// 串口号 /// diff --git a/货架标准上位机/ViewModels/InInventoryViewModel.cs b/货架标准上位机/ViewModels/InInventoryViewModel.cs index f88bfbb..a428ee5 100644 --- a/货架标准上位机/ViewModels/InInventoryViewModel.cs +++ b/货架标准上位机/ViewModels/InInventoryViewModel.cs @@ -184,6 +184,7 @@ namespace 货架标准上位机.ViewModel { Logs.Write($"扫码模组{scanner.TempCode},进入入库模式成功!", LogsType.Scanner); scanner.IsInstoreMode = true; + scanner.IsInstoreModeTime = DateTime.Now; scanner.ShelfCode = Result.Data.ShelfCode; scanner.ModulesStr = Result.Data.ModulesStr; @@ -233,7 +234,6 @@ namespace 货架标准上位机.ViewModel scanner.IsInstoreMode = false; scanner.ShelfCode = string.Empty; scanner.ModulesStr = string.Empty; - } } catch (Exception ex) diff --git a/货架标准上位机/ViewModels/MXViewModel/MXOutInventoryViewModel.cs b/货架标准上位机/ViewModels/MXViewModel/MXOutInventoryViewModel.cs index b0b6de5..e083e94 100644 --- a/货架标准上位机/ViewModels/MXViewModel/MXOutInventoryViewModel.cs +++ b/货架标准上位机/ViewModels/MXViewModel/MXOutInventoryViewModel.cs @@ -159,7 +159,7 @@ namespace 货架标准上位机.ViewModel if (Result != null && Result.Code == 200) { Growl.Warning("已成功开始出库!"); - RefreshDataGridItemSource(); + RefreshOutOrderList(SelectedOutOrderNumber); } else if (Result != null) { @@ -203,7 +203,8 @@ namespace 货架标准上位机.ViewModel if (Result != null && Result.Code == 200) { Growl.Warning("已成功结束出库!"); - RefreshDataGridItemSource(); + RefreshOutOrderList(SelectedOutOrderNumber); + //RefreshDataGridItemSource(); } else if (Result != null) { diff --git a/货架标准上位机/Views/InInventoryView.xaml b/货架标准上位机/Views/InInventoryView.xaml index efee7eb..2e62513 100644 --- a/货架标准上位机/Views/InInventoryView.xaml +++ b/货架标准上位机/Views/InInventoryView.xaml @@ -52,8 +52,8 @@ - - + + diff --git a/货架标准上位机/Views/MXWindows/MXOutInventoryView.xaml b/货架标准上位机/Views/MXWindows/MXOutInventoryView.xaml index f3f7713..7a99eed 100644 --- a/货架标准上位机/Views/MXWindows/MXOutInventoryView.xaml +++ b/货架标准上位机/Views/MXWindows/MXOutInventoryView.xaml @@ -94,7 +94,6 @@ - + @@ -112,17 +135,9 @@ - - - + + + + diff --git a/货架标准上位机/Views/Windows/UserLoginView.xaml.cs b/货架标准上位机/Views/Windows/UserLoginView.xaml.cs index 06cf0ba..248a92c 100644 --- a/货架标准上位机/Views/Windows/UserLoginView.xaml.cs +++ b/货架标准上位机/Views/Windows/UserLoginView.xaml.cs @@ -55,11 +55,12 @@ namespace 货架标准上位机 HandyControl.Controls.MessageBox.Warning("请输入账号!", "提示"); return; } - if (string.IsNullOrEmpty(pass)) - { - HandyControl.Controls.MessageBox.Warning("请输入密码!", "提示"); - return; - } + if (!LocalFile.Config.IsMx) + if (string.IsNullOrEmpty(pass)) + { + HandyControl.Controls.MessageBox.Warning("请输入密码!", "提示"); + return; + } try { @@ -73,9 +74,11 @@ namespace 货架标准上位机 PassWord = pass, IsNoLogin = false, }; + if (LocalFile.Config.IsMx) + body.IsNoLogin = true; var Result = ApiHelp.GetDataFromHttp>(LocalFile.Config.ApiIpHost + "user/userLogin", body, "POST"); - if (Result!= null && Result.Code != 200) + if (Result != null && Result.Code != 200) { HandyControl.Controls.MessageBox.Warning(Result.Message, "提示"); return; diff --git a/货架标准上位机/WebSocket.cs b/货架标准上位机/WebSocket.cs index 758acaf..3d3feb5 100644 --- a/货架标准上位机/WebSocket.cs +++ b/货架标准上位机/WebSocket.cs @@ -13,6 +13,7 @@ using TouchSocket.Core; using TouchSocket.Http.WebSockets; using TouchSocket.Sockets; using WCS.Model.WebSocketModel; +using 货架标准上位机.Views.Controls; namespace 货架标准上位机 { @@ -41,8 +42,8 @@ namespace 货架标准上位机 //自定义实现心跳和重连 Task.Run(async () => { - while (true) - { + while (true) + { await Task.Delay(4000); try { @@ -53,7 +54,7 @@ namespace 货架标准上位机 WebSocket.client.TryConnect(); } } - catch (Exception ex) + catch (Exception ex) { } @@ -121,6 +122,18 @@ namespace 货架标准上位机 TextBoxLog.AddLog(warning.WarningMessage, "InstoreLog", DateTime.Now); client.Send(e.DataFrame.ToText()); break; + case WarningTypeEnum.通知前台结束入库: + var scanner = ScannerManager.Scanners.Where(t => t.IsInstoreMode && t.ShelfCode == warning.ShelfCode && t.IsInstoreModeTime < warning.CreateTime) + .FirstOrDefault(); + if (scanner != null) + { + scanner.IsInstoreMode = false; + scanner.ShelfCode = string.Empty; + scanner.ModulesStr = string.Empty; + + scanner.ScannerDisplayControl.RefreshValues(string.Empty, string.Empty); + } + break; default: break; } return; diff --git a/货架标准上位机/data/jsconfig.json b/货架标准上位机/data/jsconfig.json index 1aa3976..de00b3b 100644 --- a/货架标准上位机/data/jsconfig.json +++ b/货架标准上位机/data/jsconfig.json @@ -2,9 +2,9 @@ //连接不上加:SslMode=none; "MySql": "server=localhost;Database=db1;Uid=root;Pwd=123456;Convert Zero Datetime=True", //货架服务器的IP和端口号 - "ApiIpHost": "http://127.0.0.1:8888/", + "ApiIpHost": "http://192.168.9.183:8888/", //WebSocket的地址 - "WebSocketUrl": "ws://127.0.0.1:7789/ws", + "WebSocketUrl": "ws://192.168.9.183:7789/ws", //货架分区 "GroupName": [ "C0"], //设备类型 可以配置为每个电脑不一样