From 7228b74cb593634d298548ebee494212fe4cdd07 Mon Sep 17 00:00:00 2001 From: hehaibing-1996 Date: Tue, 25 Jun 2024 13:48:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E7=81=AF=E8=B0=83?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WCS.BLL/HardWare/SmartShelf.cs | 21 ++- WCS.BLL/Services/IService/IInstoreService.cs | 4 + WCS.BLL/Services/Service/InstoreService.cs | 145 +++++++++++------- WCS.BLL/Services/Service/StoreInfoService.cs | 14 +- WCS.BLL/Tool/Helper.cs | 58 ++++++- WCS.BLL/Tool/Logs.cs | 4 + .../InStore/DebugStoreinfoSingleRequest.cs | 13 ++ WCS.WebApi/Controllers/InstoreController.cs | 20 ++- 8 files changed, 211 insertions(+), 68 deletions(-) create mode 100644 WCS.Model/ApiModel/InStore/DebugStoreinfoSingleRequest.cs diff --git a/WCS.BLL/HardWare/SmartShelf.cs b/WCS.BLL/HardWare/SmartShelf.cs index 9ee8b49..2fd36ce 100644 --- a/WCS.BLL/HardWare/SmartShelf.cs +++ b/WCS.BLL/HardWare/SmartShelf.cs @@ -136,11 +136,17 @@ namespace WCS.BLL.HardWare //清空错误 ExceptionMessages.Clear(); ProcessingExceptions.Clear(); + this.IsWarning = false; //清空报警状态以免报警后 处理了异常后续无法亮灯 //货架所有模组发送指令进入入库模式 + Logs.Write($"货架{ShelfCode}开始发送指令进入入库模式", LogsType.Instore); + foreach (var module in Modules.Where(t => t.IsEnable).ToList()) { + Logs.Write($"货架{ShelfCode}模组【{module.ModuleCode}】发送指令进入入库模式", LogsType.Instore); module.GoInInstoreMode(TcpCleint); } + + Logs.Write($"货架{ShelfCode}指令发送完毕", LogsType.Instore); //延时获取异常 var timeOut = 3000; var timeSpan = TimeSpan.FromMilliseconds(0); @@ -178,7 +184,7 @@ namespace WCS.BLL.HardWare if (notInstoreList.Count > 0) { - + Logs.Write($"货架{ShelfCode}存在模组未进入入库模式", LogsType.Instore); foreach (var item in notInstoreList) { ExceptionMessages.Add($"模组{item.ModuleCode}未进入入库模式!"); @@ -205,6 +211,7 @@ namespace WCS.BLL.HardWare } //没有报警才亮蓝灯 + Logs.Write($"货架{ShelfCode},IsWarning现在为{IsWarning}", LogsType.Instore); if (!IsWarning) WarningLight.BlueLight(TcpCleint); //绑定当前进入入库PDA/WCS前端的IP @@ -399,7 +406,7 @@ namespace WCS.BLL.HardWare else { //剩余物料全出 - Logs.Write($"GoInOutstoreByModule发料单{OrderNumber},剩余物料灯全亮!", LogsType.Outstore); + Logs.Write($"GoInOutstoreByModule发料单{OrderNumber},剩余所有物料灯全亮(发送命令)!", LogsType.Outstore); } var shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId) @@ -1117,9 +1124,11 @@ namespace WCS.BLL.HardWare ClientIp = WebSocketIpAddress }; WarningManager.SendWarning(warningModel); + this.IsWarning = true; #endregion - + Logs.Write($"货架【{ShelfCode},模组{module}发现物料丢失,开始发送红灯】", LogsType.Instore); WarningLight.WaringLightAlwaysRed(TcpCleint); + Logs.Write($"货架【{ShelfCode},模组{module}发现物料丢失,发送红灯完成】", LogsType.Instore); } //库位未配置、返回数据异常 else @@ -1151,9 +1160,11 @@ namespace WCS.BLL.HardWare ClientIp = WebSocketIpAddress }; WarningManager.SendWarning(warningModel); + this.IsWarning = true; #endregion - + Logs.Write($"货架【{ShelfCode},模组{module}发现物料未扫描上架,开始发送红灯】", LogsType.Instore); WarningLight.WaringLightAlwaysRed(TcpCleint); + Logs.Write($"货架【{ShelfCode},模组{module}发现物料未扫描上架,发送红灯完成】", LogsType.Instore); } else { @@ -1809,7 +1820,7 @@ namespace WCS.BLL.HardWare else { //剩余物料全出 - Logs.Write($"发料单{OrderNumber},剩余物料灯全亮!", LogsType.Outstore); + Logs.Write($"发料单{OrderNumber},剩余所有物料灯全亮(发送命令)!", LogsType.Outstore); } var shelfIds = outOrderMatDetails.Select(t => t.StoreInfo.ShelfId) diff --git a/WCS.BLL/Services/IService/IInstoreService.cs b/WCS.BLL/Services/IService/IInstoreService.cs index c049df2..2205d2e 100644 --- a/WCS.BLL/Services/IService/IInstoreService.cs +++ b/WCS.BLL/Services/IService/IInstoreService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using WCS.Model; +using WCS.Model.ApiModel.InStore; namespace WCS.BLL.Services.IService { @@ -15,5 +16,8 @@ namespace WCS.BLL.Services.IService public Task queryByMatSnOut(QueryByMatSnRequest request); public Task queryInstoreStatus(QueryByMatSnRequest request); public Task queryInstoreStatusSingle(QueryByMatSnRequestSingle request); + + public Task debugStoreinfoSingle(DebugStoreinfoSingleRequest request); + } } diff --git a/WCS.BLL/Services/Service/InstoreService.cs b/WCS.BLL/Services/Service/InstoreService.cs index 4937048..3c52b77 100644 --- a/WCS.BLL/Services/Service/InstoreService.cs +++ b/WCS.BLL/Services/Service/InstoreService.cs @@ -1,4 +1,5 @@ using OracleInternal.SqlAndPlsqlParser.LocalParsing; +using System; using System.ComponentModel.DataAnnotations.Schema; using System.Runtime.InteropServices; using System.Text.RegularExpressions; @@ -13,6 +14,7 @@ using WCS.DAL.Db; using WCS.DAL.DbModels; using WCS.Model; using WCS.Model.ApiModel.InOutRecord; +using WCS.Model.ApiModel.InStore; using WCS.Model.ApiModel.MXBackgroundThread; namespace WCS.BLL.Services.Service @@ -23,67 +25,78 @@ namespace WCS.BLL.Services.Service public ResponseBase shelfGoInInStore(ShelfGoInInstoreRequest request) { - //校验货架编码规则 - //取配置文件中得货架编码规则 - bool isValid = false; - var patterns = LocalFile.Config.ModuleCodePatterns; - if (patterns != null && patterns.Count > 0) + try { - foreach (var pattern in patterns) + //校验货架编码规则 + //取配置文件中得货架编码规则 + bool isValid = false; + var patterns = LocalFile.Config.ModuleCodePatterns; + if (patterns != null && patterns.Count > 0) { - isValid = Regex.IsMatch(request.ModuleCode, pattern); - //匹配到第一个符合条件的货架码 就直接退出循环 认为匹配成功 - if (isValid) - break; - } - } - //如果配置文件缺失 使用默认正则进行匹配 - else - { - isValid = Regex.IsMatch(request.ModuleCode, LocalFile.DefaultModuleCodePattern); - } - - if (!isValid) - { - return new ResponseBase() - { - Code = 202, - Message = $"模组编码{request.ModuleCode}不满足模组编码规则!", - }; - } - //找到模组对应的货架 - var shelf = ShelfManager.Shelves.Where(t => t.ModulesStr.Contains(request.ModuleCode)).FirstOrDefault(); - if (shelf == null)//未找到 - { - return new ResponseBase() - { - Code = 201, - Message = "未找到模组对应的货架", - }; - } - //已找到模组对应货架 - shelf.GoInInstore(request.IpAdress); - - if (shelf.CurrentMode == Mode.入库模式) - //成功进入入库模式 - return new ShelfGoInInstoreResponse() - { - Code = 200, - Message = $"货架进入入库模式成功!{string.Join(",", shelf.ExceptionMessages)}", - Data = new ShelfGoInInstoreDto() + foreach (var pattern in patterns) { - ShelfCode = shelf.ShelfCode, - ModulesStr = shelf.ModulesStr, + isValid = Regex.IsMatch(request.ModuleCode, pattern); + //匹配到第一个符合条件的货架码 就直接退出循环 认为匹配成功 + if (isValid) + break; } - }; - else + } + //如果配置文件缺失 使用默认正则进行匹配 + else + { + isValid = Regex.IsMatch(request.ModuleCode, LocalFile.DefaultModuleCodePattern); + } + + if (!isValid) + { + return new ResponseBase() + { + Code = 202, + Message = $"模组编码{request.ModuleCode}不满足模组编码规则!", + }; + } + //找到模组对应的货架 + var shelf = ShelfManager.Shelves.Where(t => t.ModulesStr.Contains(request.ModuleCode)).FirstOrDefault(); + if (shelf == null)//未找到 + { + return new ResponseBase() + { + Code = 201, + Message = "未找到模组对应的货架", + }; + } + //已找到模组对应货架 + shelf.GoInInstore(request.IpAdress); + + if (shelf.CurrentMode == Mode.入库模式) + //成功进入入库模式 + return new ShelfGoInInstoreResponse() + { + Code = 200, + Message = $"货架进入入库模式成功!{string.Join(",", shelf.ExceptionMessages)}", + Data = new ShelfGoInInstoreDto() + { + ShelfCode = shelf.ShelfCode, + ModulesStr = shelf.ModulesStr, + } + }; + else + return new ShelfGoInInstoreResponse() + { + Code = 201, + Message = $"货架进入入库模式失败:{string.Join(",", shelf.ExceptionMessages)}", + Data = null + }; + } + catch (Exception ex) + { return new ShelfGoInInstoreResponse() { - Code = 201, - Message = $"货架进入入库模式失败:{string.Join(",", shelf.ExceptionMessages)}", + Code = 300, + Message = $"货架进入入库模式发生异常:{ex.Message}", Data = null }; - + } } public ResponseBase shelfGoOutInStore(ShelfGoOutInStoreRequest request) @@ -537,5 +550,31 @@ namespace WCS.BLL.Services.Service }; } + + public async Task debugStoreinfoSingle(DebugStoreinfoSingleRequest request) + { + //找到模组 + var module = await DbHelp.db.Queryable().Where(it => it.ModuleCode == request.ShelfCode).FirstAsync(); + if (module == null) + { + return new ResponseBase() + { + Code = 201, + Message = $"模组[{request.ShelfCode}]不存在!", + }; + } + string sendIP = module.CleintIp; //单灯IP + int PCBId = module.BoardId; //单灯PCB板ID + + TCPClient tcpClient = TCPClientManager.GetTCPClientByIPHost(sendIP); + byte[] senddata = Tool.Helper.StoreLightOnOff(PCBId, "绿", request.OnOff == true ? 0x01 : 0x00); + tcpClient.Send(senddata); //库位灯短亮一次 + + return new ResponseBase() + { + Code = 200, + Message = $"Success", + }; + } } } diff --git a/WCS.BLL/Services/Service/StoreInfoService.cs b/WCS.BLL/Services/Service/StoreInfoService.cs index a4e0c4c..2c4ce36 100644 --- a/WCS.BLL/Services/Service/StoreInfoService.cs +++ b/WCS.BLL/Services/Service/StoreInfoService.cs @@ -245,10 +245,10 @@ namespace WCS.BLL.Services.Service /// public async Task> GenerateStoreInfo() { - var shelfInfos = DbHelp.db.Queryable().ToList(); - foreach (var shelfInfo in shelfInfos) - { - var ModuleInfos = await DbHelp.db.Queryable().Where(t => t.ShelfId == shelfInfo.Id).ToListAsync(); + //var shelfInfos = DbHelp.db.Queryable().ToList(); + //foreach (var shelfInfo in shelfInfos) + //{ + var ModuleInfos = await DbHelp.db.Queryable().ToListAsync(); ModuleInfos.ForEach(moduleInfo => { for (int i = 1; i <= moduleInfo.LightCount; i++) @@ -259,8 +259,8 @@ namespace WCS.BLL.Services.Service ShelfTypeId = 1, ModuleId = moduleInfo.Id, ModuleCode = moduleInfo.ModuleCode, - ShelfId = shelfInfo.Id, - ShelfCode = shelfInfo.ShelfCode, + ShelfId = moduleInfo.ShelfId, + ShelfCode = moduleInfo.ShelfCode, BoardId = moduleInfo.BoardId, LightNumber = i, Priority = 1, @@ -274,7 +274,7 @@ namespace WCS.BLL.Services.Service DbHelp.db.Insertable(storeInfo).ExecuteCommand(); } }); - } + //} return new ResponseCommon() { Message = "111" }; } diff --git a/WCS.BLL/Tool/Helper.cs b/WCS.BLL/Tool/Helper.cs index ec56ced..71437b5 100644 --- a/WCS.BLL/Tool/Helper.cs +++ b/WCS.BLL/Tool/Helper.cs @@ -107,7 +107,7 @@ namespace WCS.BLL.Tool } //出库库位灯亮灯 - public static byte[] OutstoreLight(List board_id, string lightcolor,int status) + public static byte[] OutstoreLight(List board_id, string lightcolor, int status) { byte color = 0x00; switch (lightcolor) @@ -155,7 +155,7 @@ namespace WCS.BLL.Tool } //出库警示灯亮灯 - public static byte[] OutstoreWarnLight(int lightid ,string lightcolor, int status,int beestatus) + public static byte[] OutstoreWarnLight(int lightid, string lightcolor, int status, int beestatus) { byte color = 0x00; switch (lightcolor) @@ -230,5 +230,59 @@ namespace WCS.BLL.Tool byte[] senddata1 = Tool.Helper.Crc16(data1, data1.Length, true); return senddata1; } + + /// + /// 库位灯常亮/关闭 + /// + /// + /// + /// 0X00 关闭 0X01 常亮 0X02 闪烁 0X03 短亮一次 + /// + public static byte[] StoreLightOnOff(int board_id, string lightcolor, int status) + { + byte color = 0x00; + switch (lightcolor) + { + case "红": + color = 0x01; + break; + case "绿": + color = 0x02; + break; + case "黄": + color = 0x03; + break; + case "蓝": + color = 0x04; + break; + case "紫": + color = 0x05; + break; + case "青": + color = 0x06; + break; + case "白": + color = 0x07; + break; + case "无": + color = 0x00; + break; + } + byte[] data1 = new byte[3 + 5]; + data1[0] = 0xff; + data1[1] = 0x01; + byte[] length_base = BitConverter.GetBytes(data1.Length + 2); + data1[2] = length_base[1]; + data1[3] = length_base[0]; + data1[4] = 0x01; + + data1[5] = (byte)board_id; + data1[5 + 1] = (byte)status; + data1[5 + 2] = color; + + byte[] data = Crc16(data1, data1.Length, true); + return data; + } + } } diff --git a/WCS.BLL/Tool/Logs.cs b/WCS.BLL/Tool/Logs.cs index ad80dc1..f4d9411 100644 --- a/WCS.BLL/Tool/Logs.cs +++ b/WCS.BLL/Tool/Logs.cs @@ -41,6 +41,10 @@ namespace WCS.BLL /// 出库流程日志 /// Outstore, + /// + /// 入库流程日志 + /// + Instore, } /// diff --git a/WCS.Model/ApiModel/InStore/DebugStoreinfoSingleRequest.cs b/WCS.Model/ApiModel/InStore/DebugStoreinfoSingleRequest.cs new file mode 100644 index 0000000..8f1f425 --- /dev/null +++ b/WCS.Model/ApiModel/InStore/DebugStoreinfoSingleRequest.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WCS.Model.ApiModel.InStore +{ + public class DebugStoreinfoSingleRequest : RequestBase + { + public string ShelfCode { get; set; } + + public bool OnOff { get; set; } = false; + } +} diff --git a/WCS.WebApi/Controllers/InstoreController.cs b/WCS.WebApi/Controllers/InstoreController.cs index 1846fce..426889a 100644 --- a/WCS.WebApi/Controllers/InstoreController.cs +++ b/WCS.WebApi/Controllers/InstoreController.cs @@ -4,6 +4,7 @@ using WCS.BLL.Manager; using WCS.BLL.Services.IService; using WCS.BLL.Tool; using WCS.Model; +using WCS.Model.ApiModel.InStore; namespace WebApi.Controllers { @@ -147,7 +148,24 @@ namespace WebApi.Controllers return await _instoreService.queryInstoreStatusSingle(request); //ShelfManager. // - + } + catch (Exception ex) + { + return new ResponseCommon() + { + Code = 300, + Message = $"ʧ:{ex.Message}", + }; + } + } + + [Route("debugStoreinfoSingle")] + [HttpPost(Name = "debugStoreinfoSingle")] + public async Task debugStoreinfoSingle(DebugStoreinfoSingleRequest request) + { + try + { + return await _instoreService.debugStoreinfoSingle(request); } catch (Exception ex) {