From 46f7bf1ee45c97b688a370bbe45d149efb403cc1 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期二, 07 五月 2024 17:26:18 +0800 Subject: [PATCH] 检测上料逻辑修改,无有料货位时写入不允许桁架进入信号 --- 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs | 287 +++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 198 insertions(+), 89 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs" index 787ff0d..b6f94b8 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs" @@ -1,20 +1,26 @@ -锘縰sing System; +锘縰sing OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using WIDESEA_Comm; using WIDESEA_Comm.LogInfo; +using WIDESEA_Common; using WIDESEA_Core.BaseProvider; using WIDESEA_Core.EFDbContext; using WIDESEA_Entity.DomainModels; +using WIDESEA_Entity.ToAGV; using WIDESEA_WCS.IRepositories; using WIDESEA_WCS.Repositories; using WIDESEA_WCS.WCSClient; using WIDESEA_WMS.IRepositories; using WIDESEA_WMS.IServices; using WIDESEA_WMS.Repositories; +using static FreeSql.Internal.GlobalFilter; +using static System.Collections.Specialized.BitVector32; namespace WIDESEA_WCS.JobsPart.Common { @@ -28,103 +34,206 @@ try { VOLContext Context = new VOLContext(); - Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context); - Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context); - var tasks = agvtaskService.Find(x => x.agv_taskstate == "Queue").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).ToList(); - foreach (var task in tasks) + + #region 闃熷垪浠诲姟 + var agvtasks = agvtaskService.Find(x => x.agv_taskstate == AGVTaskStateEnum.Queue.ToString()).ToList(); + + var AGVTaskTypes = Enum.GetNames(typeof(AGVTaskTypeEnum)); + foreach (var AGVTaskType in AGVTaskTypes) { - if (task.agv_tasktype == "TaskType_EmptyPallet")//绌烘墭浠诲姟 + var agvtask = agvtasks.Where(x => x.agv_tasktype == AGVTaskType).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault(); + if (agvtask != null) UpdateQueue(agvtaskService, agvtask); + } + #endregion + + #region MyRegion + //var tasks = agvtaskService.Find(x => x.agv_taskstate == "Queue").OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).ToList(); + //foreach (var task in tasks) + //{ + // try + // { + // if (task.agv_tasktype == "TaskType_EmptyPallet")//绌烘墭浠诲姟 + // { + // if (task.agv_fromaddress == "" && DateTime.Now - task.agv_createtime >= TimeSpan.FromMinutes(2)) + // { + // if (task.agv_tasknum.Contains("_")) + // { + // string mainTaskNum = task.agv_tasknum.Split('_')[0]; + // if (agvtaskService.Find(x => x.agv_tasknum == mainTaskNum && task.agv_taskstate != "Executing" && task.agv_taskstate != "Create").Any() || !agvtaskService.Find(x => x.agv_tasknum == mainTaskNum).Any()) + // GetStation.EmptyPalletStation(task); + // } + // else + // GetStation.EmptyPalletStation(task); + + // WriteDBLog.Success("鏇存柊绌烘墭闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); + // continue; + // } + // } + // else if (task.agv_tasktype == "TaskType_OutsourceInbound" || task.agv_tasktype == "TaskType_Inbound")//澶栧崗搴撳叆搴�/AB搴撳叆搴� + // { + // if (task.agv_toaddress == "") + // { + // var stationinfo = stationinfoRepository.Find(x => x.stationCode == task.agv_fromaddress).FirstOrDefault(); + // var work = workinfoRepository.Find(x => x.workOrder == stationinfo.Number && x.drawingNo == stationinfo.stationType && x.heatID == stationinfo.heatNumber && x.processCode == "17").FirstOrDefault(); + // var TargetLocation = task.agv_tasktype == "TaskType_Inbound" ? GetLocation.GetEmptyLocation(stationinfoRepository, work, task) : StationTask.GetEmptyLocation(stationinfoRepository); + // if (TargetLocation != null) + // { + // if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue; + // task.agv_taskstate = "Create"; + // task.agv_toaddress = TargetLocation.stationCode; + // TargetLocation.location_state = LocationStateEnum.InBusy.ToString(); + // TargetLocation.billetID = stationinfo.billetID; + // TargetLocation.stationType = task.agv_materielid; + // TargetLocation.heatNumber = stationinfo.heatNumber; + // TargetLocation.Number = task.jobID; + // stationinfoRepository.Update(TargetLocation, true); + // agvtaskService.Update(task, true); + // WriteDBLog.Success("鏇存柊鍏ュ簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); + // continue; + // } + // } + // } + // else if (task.agv_tasktype == "TaskType_OutsourceOutbound" || task.agv_tasktype == "TaskType_Outbound")//澶栧崗搴撳嚭搴�/AB搴撳嚭搴� + // { + // if (task.agv_toaddress == "") + // { + // var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && (x.tray_status == "EmptyTray" || x.location_state == "Empty") && x.enable).ToList(); + // foreach (var EmptyStation in EmptyStations) + // { + // if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue; + // task.agv_taskstate = "Create"; + // task.agv_toaddress = EmptyStation.stationCode; + // EmptyStation.location_state = LocationStateEnum.Busy.ToString(); + // stationinfoRepository.Update(EmptyStation, true); + // agvtaskService.Update(task, true); + // WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); + // return; + // } + // } + // } + // else if (task.agv_tasktype == "TaskType_OutsourceCarry")//绉诲簱澶栧崗 + // { + // if (task.agv_toaddress == "") + // { + // var TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository); + // if (TargetLocation != null) + // { + // if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue; + + // task.agv_taskstate = "Create"; + // task.agv_toaddress = TargetLocation.stationCode; + // TargetLocation.location_state = LocationStateEnum.OutBusy.ToString(); + // TargetLocation.stationType = task.agv_materielid; + // stationinfoRepository.Update(TargetLocation, true); + // agvtaskService.Update(task, true); + // WriteDBLog.Success("鏇存柊绉诲簱澶栧崗闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); + // continue; + // } + // } + // } + // } + // catch (Exception ex) + // { + // //WriteDBLog.Error("鏇存柊闃熷垪浠诲姟", $"閿欒淇℃伅锛歿ex.Message}", "PCS"); + // WriteLog.Write_Log("鏇存柊闃熷垪浠诲姟", "鏇存柊澶辫触", "", $"閿欒淇℃伅锛歿ex.Message}"); + // } + //} + #endregion + + } + catch (Exception ex) + { + WriteDBLog.Error("鏇存柊闃熷垪浠诲姟", $"閿欒淇℃伅锛歿ex.Message}", "PCS"); + } + } + + public static void UpdateQueue(Idt_agvtaskRepository agvtaskService, dt_agvtask agvtask) + { + VOLContext Context = new VOLContext(); + Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context); + IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context); + try + { + if (agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_EmptyPallet.ToString())//绌烘墭浠诲姟 + { + if (agvtask.agv_fromaddress == "" && agvtask.agv_toaddress.Contains("W")) + GetStation.EmptyPalletStation(agvtask); + else if (agvtask.agv_fromaddress == "" && DateTime.Now - agvtask.agv_createtime >= TimeSpan.FromMinutes(2)) { - if (task.agv_fromaddress == "") + if (agvtask.agv_tasknum.Contains("_")) { - var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�"); - if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒"); - if (!Pipeline_client.IsConnected) throw new Exception("涓庨摼鏉℃満杩炴帴瓒呮椂锛�"); - var area = task.agv_Traytype == "SmallTray" ? "11" : "10"; - //鎵�1搴撳尯鐨勭┖鎵樹綅 - var EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains("A") /*&& x.location_state == "Stroge"*//*LocationStateEnum.Stroge.ToString()*/ && x.enable).OrderBy(x => x.column).ThenBy(x => x.line).FirstOrDefault(); - if (EmptyStation != null) - if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) EmptyStation = null; - #region 涓�涓尯鍩熷彧鑳芥湁涓�涓┖鎵樹换鍔� - //bool ok = false; - //if (EmptyStation != null) - // ok = agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any(); - //if (EmptyStation == null || ok) - // EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" /*LocationStateEnum.Stroge.ToString()*/ && x.enable) - // .OrderBy(x => x.line).OrderByDescending(x => x.column).FirstOrDefault(); - #endregion - if (EmptyStation == null) - EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.enable).OrderByDescending(x => x.column).FirstOrDefault(); - if (EmptyStation == null) continue; - #region 搴撳唴瀛樺湪浠诲姟鍗犵敤 - if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) - continue; - #endregion - - if (EmptyStation == null) - EmptyStation = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.stationCode.Contains(area == "10" ? "D" : "C") && x.location_state == "Stroge" && x.enable).OrderByDescending(x => x.column).FirstOrDefault(); - if (EmptyStation != null) - { - #region 搴撳唴瀛樺湪浠诲姟鍗犵敤 - //if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) - // continue; - #endregion - - //if (agvtaskService.Find(x => x.agv_fromaddress == EmptyStation.stationCode || x.agv_toaddress == EmptyStation.stationCode).Any()) - // return; - #region 琛ュ簱鍐呯┖鎵樼洏锛屼笉闇�瑕佸厜鐢靛垽鏂� - var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", task.agv_toaddress);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃� - var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", task.agv_toaddress);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃� - if (PalletSignal == 2 && MaterialSignal == 2) - { - task.agv_fromaddress = EmptyStation.stationCode; - task.StarQuantity = EmptyStation.quantity - 1; - task.agv_taskstate = "Create"; - agvtaskService.Update(task, true); - EmptyStation.location_state = LocationStateEnum.Busy.ToString(); - stationinfoRepository.Update(EmptyStation, true); - WriteDBLog.Success("鏇存柊绌虹洏闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); - } - #endregion - } + string mainTaskNum = agvtask.agv_tasknum.Split('_')[0]; + if (agvtaskService.Find(x => x.agv_tasknum == mainTaskNum && agvtask.agv_taskstate != AGVTaskStateEnum.Executing.ToString() && agvtask.agv_taskstate != AGVTaskStateEnum.Create.ToString()).Any() || !agvtaskService.Find(x => x.agv_tasknum == mainTaskNum).Any()) + GetStation.EmptyPalletStation(agvtask); } + else + GetStation.EmptyPalletStation(agvtask); } - else if (task.agv_tasktype == "TaskType_OutsourceOutbound" || task.agv_tasktype == "TaskType_Outbound")//澶栧崗搴撳嚭搴�/AB搴撳嚭搴� + WriteDBLog.Success("鏇存柊绌烘墭闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS"); + } + else if (agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceInbound.ToString() || agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_Inbound.ToString())//澶栧崗搴撳叆搴�/AB搴撳叆搴� + { + if (agvtask.agv_toaddress == "") { - if (task.agv_toaddress == "") + var stationinfo = stationinfoRepository.Find(x => x.stationCode == agvtask.agv_fromaddress).FirstOrDefault(); + var work = workinfoRepository.Find(x => x.workOrder == stationinfo.Number && x.drawingNo == stationinfo.stationType && x.heatID == stationinfo.heatNumber && x.processCode == "17").FirstOrDefault(); + var TargetLocation = agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_Inbound.ToString() ? GetLocation.GetEmptyLocation(stationinfoRepository, work, agvtask) : StationTask.GetEmptyLocation(stationinfoRepository); + if (TargetLocation != null) { - var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && x.location_state == "Empty" && x.enable).ToList(); - foreach (var EmptyStation in EmptyStations) + if (!agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) { - if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue; - task.agv_taskstate = "Create"; - task.agv_toaddress = EmptyStation.stationCode; - EmptyStation.location_state = LocationStateEnum.Busy.ToString(); - stationinfoRepository.Update(EmptyStation, true); - agvtaskService.Update(task, true); - WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); - return; - } - } - } - else if (task.agv_tasktype == "TaskType_OutsourceCarry")//澶栧崗绉诲簱 - { - if (task.agv_toaddress == "") - { - var TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository); - if (TargetLocation != null) - { - if (agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) continue; - - task.agv_taskstate = "Create"; - task.agv_toaddress = TargetLocation.stationCode; - TargetLocation.location_state = LocationStateEnum.OutBusy.ToString(); - TargetLocation.stationType = task.agv_materielid; + agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString(); + agvtask.agv_toaddress = TargetLocation.stationCode; + TargetLocation.location_state = LocationStateEnum.InBusy.ToString(); + TargetLocation.billetID = stationinfo.billetID; + TargetLocation.stationType = agvtask.agv_materielid; + TargetLocation.heatNumber = stationinfo.heatNumber; + TargetLocation.Number = agvtask.jobID; stationinfoRepository.Update(TargetLocation, true); - agvtaskService.Update(task, true); - WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); - return; + agvtaskService.Update(agvtask, true); + WriteDBLog.Success("鏇存柊鍏ュ簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS"); + } + } + } + } + else if (agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceOutbound.ToString() || agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString())//澶栧崗搴撳嚭搴�/AB搴撳嚭搴� + { + if (agvtask.agv_toaddress == "") + { + if (agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_Outbound.ToString()) + if (GetStation.QueueStation(agvtask.agv_fromaddress)) return;//闄愬埗涓�琛屼竴娆″彧鑳藉嚭涓�涓换鍔� + var EmptyStations = stationinfoRepository.Find(x => x.stationCode.Contains("S01001") && (x.tray_status == TrayStateEnum.EmptyTray.ToString() || x.location_state == LocationStateEnum.Empty.ToString()) && x.enable).ToList(); + foreach (var EmptyStation in EmptyStations) + { + if (agvtaskService.Find(x => x.agv_toaddress == EmptyStation.stationCode).Any()) continue; + agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString(); + agvtask.agv_toaddress = EmptyStation.stationCode; + EmptyStation.location_state = LocationStateEnum.Busy.ToString(); + stationinfoRepository.Update(EmptyStation, true); + agvtaskService.Update(agvtask, true); + WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS"); + return; + } + } + } + else if (agvtask.agv_tasktype == AGVTaskTypeEnum.TaskType_OutsourceCarry.ToString())//绉诲簱澶栧崗 + { + if (agvtask.agv_toaddress == "") + { + if (GetStation.QueueStation(agvtask.agv_fromaddress)) return;//闄愬埗涓�琛屼竴娆″彧鑳藉嚭涓�涓换鍔� + var TargetLocation = StationTask.GetEmptyLocation(stationinfoRepository); + if (TargetLocation != null) + { + if (!agvtaskService.Find(x => x.agv_toaddress == TargetLocation.stationCode).Any()) + { + agvtask.agv_taskstate = AGVTaskStateEnum.Create.ToString(); + agvtask.agv_toaddress = TargetLocation.stationCode; + TargetLocation.location_state = LocationStateEnum.OutBusy.ToString(); + TargetLocation.stationType = agvtask.agv_materielid; + stationinfoRepository.Update(TargetLocation, true); + agvtaskService.Update(agvtask, true); + WriteDBLog.Success("鏇存柊绉诲簱澶栧崗闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS"); } } } @@ -132,7 +241,7 @@ } catch (Exception ex) { - WriteDBLog.Error("鏇存柊闃熷垪浠诲姟", $"閿欒淇℃伅锛歿ex.Message}", "PCS"); + WriteLog.Write_Log("鏇存柊闃熷垪浠诲姟", "鏇存柊澶辫触", "", $"閿欒淇℃伅锛歿ex.Message}"); } } } -- Gitblit v1.9.3