diff --git a/DOAN.Model/PBL/Dto/LightLogDto.cs b/DOAN.Model/PBL/Dto/LightLogDto.cs index 0252d57..502127a 100644 --- a/DOAN.Model/PBL/Dto/LightLogDto.cs +++ b/DOAN.Model/PBL/Dto/LightLogDto.cs @@ -21,6 +21,8 @@ namespace DOAN.Model.PBL.Dto public string ShelfCode { get; set; } + public string LayerNum { get; set; } + public string Operationer { get; set; } public DateTime? CreatedTime { get; set; } diff --git a/DOAN.Model/PBL/LightLog.cs b/DOAN.Model/PBL/LightLog.cs index 8125a4e..5b107ee 100644 --- a/DOAN.Model/PBL/LightLog.cs +++ b/DOAN.Model/PBL/LightLog.cs @@ -25,6 +25,12 @@ namespace DOAN.Model.PBL [SugarColumn(ColumnName = "shelf_code")] public string ShelfCode { get; set; } + /// + /// 层号 + /// + [SugarColumn(ColumnName = "layer_num")] + public string LayerNum { get; set; } + /// /// PBL系统、人工 /// diff --git a/DOAN.Service/PBL/MESInteractionServcie.cs b/DOAN.Service/PBL/MESInteractionServcie.cs index 9cfd788..fc96806 100644 --- a/DOAN.Service/PBL/MESInteractionServcie.cs +++ b/DOAN.Service/PBL/MESInteractionServcie.cs @@ -5,8 +5,10 @@ using DOAN.Service.PBL.IService; using DOAN.ServiceCore.Signalr; using Infrastructure.Attribute; using Mapster; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.SignalR; using Newtonsoft.Json.Linq; +using System.Security.Cryptography.X509Certificates; namespace DOAN.Service.PBL { @@ -43,11 +45,7 @@ namespace DOAN.Service.PBL item.Id = XUEHUA; item.CreatedTime = DateTime.Now; Context.Insertable(item).ExecuteCommand(); - // 2.根据总成零件号 ,版本 查询对应零件号,使得对应料架亮灯 - - // 同一个会有多个料架 - //镜壳 料架层 List MirrorshellShelfList = Context .Queryable() .Where(it => @@ -58,63 +56,59 @@ namespace DOAN.Service.PBL .Select(it => it.MirrorshellCode) ) .ToList(); - - //镜体 料架 - // Storagelocation MirrorshellBody = Context.Queryable().Where(it => it.Partnumber == - // SqlFunc.Subqueryable().Where(It => It.Productcode == light.AssemblyPartNumber && It.Version == light.Version).Select(it => it.MirrorbodyCode)).First(); if (MirrorshellShelfList != null && MirrorshellShelfList.Count() > 0) { - foreach (var item1 in MirrorshellShelfList) + Storagelocation storagelocation = new(); + // 是否合并料架 + bool isMergeRack = MirrorshellShelfList.Count > 1; + if (isMergeRack) { - // 3.对应料架亮灯 - - //TODO PLC 交互 - // 对应料架 亮灯字段 - // 通知PLC - bool isSucesss = pLCTool.WriteBit(item1.PlcAddress, true); - if (isSucesss) + // 合并料架 判断先进先出 + foreach(var shelf in MirrorshellShelfList) { - item1.IsLight = 1; - - Context.Updateable(item1).ExecuteCommand(); + // 第一个有箱子的 + if(shelf.PackageNum > 0) + { + storagelocation = shelf; + continue; + } + } + if (storagelocation.RackCode == null) + { + storagelocation = MirrorshellShelfList[^1]; } - - //亮灯日志 - Light_Log light_Log = new Light_Log(); - light_Log.Id = XUEHUA; - light_Log.LightOperation = 1; - light_Log.ShelfCode = item1.RackCode; - light_Log.LayerNum = item1.LayerNum; - light_Log.Operationer = "PBL"; - light_Log.CreatedTime = DateTime.Now; - light_Log.IsSuccess = isSucesss; - - //Light_Log light_Log2 = new Light_Log(); - //light_Log2.Id = XUEHUA; - //light_Log2.LightOperation = 1; - - //light_Log2.ShelfCode = item1.RackCode; - - - - //light_Log2.Operationer = "PBL"; - //light_Log2.CreatedTime = DateTime.Now; - //light_Log2.IsSuccess = isSucesss; - //Context.Insertable(light_Log2).ExecuteCommand(); - result += Context.Insertable(light_Log).ExecuteCommand(); } + else + { + // 单独料架 + storagelocation = MirrorshellShelfList[0]; + } + // 3.对应料架亮灯 + bool isSucesss = pLCTool.WriteBit(storagelocation.PlcAddress, true); + if (isSucesss) { + storagelocation.IsLight = 1; + result += Context.Updateable(storagelocation).ExecuteCommand(); + } + //亮灯日志 + Light_Log light_Log = new Light_Log(); + light_Log.Id = XUEHUA; + light_Log.LightOperation = 1; + light_Log.Operationer = "PBL"; + light_Log.CreatedTime = DateTime.Now; + light_Log.ShelfCode = storagelocation.RackCode; + light_Log.LayerNum = storagelocation.LayerNum; + light_Log.IsSuccess = isSucesss; + result += Context.Insertable(light_Log).ExecuteCommand(); } else { // 发送socket 通知 - string message = - $"MES产品编号{light.AssemblyPartNumber}或者版本{light.Version},在PBL中找不到。请维护PBL料架信息"; + $"MES产品编号{light.AssemblyPartNumber}或者版本{light.Version},在PBL中找不到。请维护PBL料架信息--{DateTime.Now}"; notificationHubContext.Clients.All.SendAsync("PBL_bom_except", message); return false; } - return result > 0; } @@ -132,58 +126,39 @@ namespace DOAN.Service.PBL item.ScanCode = scan_code; item.CreatedTime = DateTime.Now; Context.Insertable(item).ExecuteCommand(); - - //2 找到对应的库存最大料架 灭灯 + //2 找到对应的亮着的料架 进行灭灯 Storagelocation storagelocation = Context .Queryable() .Where(it => it.Partnumber.Contains(scan_code)) - .OrderByDescending(it => it.PackageNum) + .Where(it => it.IsLight == 1) .First(); - if (storagelocation != null) - { - // TODO PLC 交互 - bool isSuccess = pLCTool.WriteBit(storagelocation.PlcAddress, false); - - if (isSuccess) - { - storagelocation.IsLight = 0; - // storagelocation.PackageNum -= 1; - //if (storagelocation.PackageNum < 0) - //{ - // storagelocation.PackageNum = 0; - //} - //3 扣减对应的库存 - // 合并货架的id - int[] ids = { 1, 2, 3, 4, 5, 6, 7, 8 }; - if (ids.Contains(storagelocation.Id)) - { - Context - .Updateable() - .SetColumns(it => it.IsLight == 0) - .Where(it => it.Partnumber == storagelocation.Partnumber) - .ExecuteCommand(); - } - else - { - Context.Updateable(storagelocation).ExecuteCommand(); - } - } - //灭灯日志 - Light_Log light_Log = new Light_Log(); - light_Log.Id = XUEHUA; - light_Log.LightOperation = 2; - light_Log.LayerNum = 1; - light_Log.ShelfCode = storagelocation.RackCode; - - light_Log.IsSuccess = isSuccess; - light_Log.Operationer = "PBL"; - light_Log.CreatedTime = DateTime.Now; - result += Context.Insertable(light_Log).ExecuteCommand(); - } - else + if (storagelocation == null) { + // 发送socket 通知 + string message = + $"未找到{scan_code}对应的亮灯料架。请检查信息--{DateTime.Now}"; + notificationHubContext.Clients.All.SendAsync("PBL_bom_except", message); return false; } + // TODO PLC 交互 + bool isSuccess = pLCTool.WriteBit(storagelocation.PlcAddress, false); + if (isSuccess) + { + storagelocation.IsLight = 0; + result += Context.Updateable(storagelocation).ExecuteCommand(); + } + //灭灯日志 + Light_Log light_Log = new Light_Log + { + Id = XUEHUA, + LightOperation = 2, + LayerNum = storagelocation.LayerNum, + ShelfCode = storagelocation.RackCode, + IsSuccess = isSuccess, + Operationer = "PBL", + CreatedTime = DateTime.Now + }; + result += Context.Insertable(light_Log).ExecuteCommand(); return result > 0; } } diff --git a/DOAN.ServiceCore/DoanBackgroundService.cs b/DOAN.ServiceCore/DoanBackgroundService.cs index 07171a2..4d69059 100644 --- a/DOAN.ServiceCore/DoanBackgroundService.cs +++ b/DOAN.ServiceCore/DoanBackgroundService.cs @@ -143,7 +143,6 @@ namespace DOAN.ServiceCore CurrentPackageCount = currentPackageCount, AlarmThreshold = layerItem.AlarmNum }; - string alarmMessage = System.Text.Json.JsonSerializer.Serialize(alarmData); await notificationHubContext.Clients.All.SendAsync("PBL_lack_alarm", alarmMessage); }