From 25724888bc329401891bf1600a8a83d8aae338b3 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期六, 27 四月 2024 18:37:37 +0800 Subject: [PATCH] 叠盘入库功能开发,空托入库逻辑优化 --- 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/RestockHCJ.cs | 139 ++++++++++++++++++++++++++-------------------- 1 files changed, 78 insertions(+), 61 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 14b31a9..2825cc2 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" @@ -9,12 +9,15 @@ 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 { @@ -29,83 +32,97 @@ { VOLContext Context = new VOLContext(); Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context); + IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(Context); Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context); - var tasks = agvtaskService.Find(x => x.agv_taskstate == "Queue").OrderBy(x => x.agv_createtime).ToList(); + 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) { - if (task.agv_tasktype == "TaskType_EmptyPallet")//绌烘墭浠诲姟 + try { - if (task.agv_fromaddress == "") + if (task.agv_tasktype == "TaskType_EmptyPallet")//绌烘墭浠诲姟 { - 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).OrderBy(x => x.line).FirstOrDefault(); - - #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) + if (task.agv_fromaddress == "" && DateTime.Now - task.agv_createtime >= TimeSpan.FromMinutes(2)) { - #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) + if (task.agv_tasknum.Contains("_")) { - task.agv_fromaddress = EmptyStation.stationCode; - task.StarQuantity = EmptyStation.quantity - 1; + 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); - WriteDBLog.Success("鏇存柊绌虹洏闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); + agvtaskService.Update(task, true); + WriteDBLog.Success("鏇存柊鍑哄簱闃熷垪浠诲姟", $"浠诲姟缂栧彿锛歿task.agv_tasknum}", "PCS"); + return; } - #endregion + } + } + 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; + } } } } - else if (task.agv_tasktype == "TaskType_OutsourceOutbound" || task.agv_tasktype == "TaskType_Outbound")//澶栧崗搴撳嚭搴�/AB搴撳嚭搴� + catch (Exception ex) { - if (task.agv_toaddress == "") - { - 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 == 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; - } - } + //WriteDBLog.Error("鏇存柊闃熷垪浠诲姟", $"閿欒淇℃伅锛歿ex.Message}", "PCS"); + WriteLog.Write_Log("鏇存柊闃熷垪浠诲姟","鏇存柊澶辫触", "", $"閿欒淇℃伅锛歿ex.Message}"); } } } -- Gitblit v1.9.3