From cfea43fe783cdb99faa14f59845e41cfcda7d974 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 16 五月 2024 17:22:48 +0800
Subject: [PATCH] AGV任务删除功能,取空托任务逻辑优化,检测上料任务下发逻辑优化(AGV备料两个)

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayTask.cs |  108 ++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 76 insertions(+), 32 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayTask.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayTask.cs"
index d7e67a8..c67fabd 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayTask.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/EmptyTrayTask.cs"
@@ -6,6 +6,7 @@
 using WIDESEA_Comm;
 using WIDESEA_Comm.LogInfo;
 using WIDESEA_Comm.TaskNo;
+using WIDESEA_Common;
 using WIDESEA_Core.EFDbContext;
 using WIDESEA_Entity.DomainModels;
 using WIDESEA_WCS.IRepositories;
@@ -43,25 +44,40 @@
                     var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", station.stationCode);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
                     if (PalletSignal == 2 && MaterialSignal == 2)
                     {
-                        dt_agvtask taskPart = new dt_agvtask()
+                        var agv_task = agvtaskRepository.Find(x => x.agv_taskstate == AGVTaskStateEnum.Queue.ToString() && x.agv_tasktype == AGVTaskTypeEnum.TaskType_EmptyPallet.ToString() && string.IsNullOrEmpty(x.agv_toaddress)).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
+                        if (agv_task != null)
                         {
-                            agv_fromaddress = "",
-                            agv_id = Guid.NewGuid(),
-                            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                            agv_grade = 2,
-                            agv_createtime = DateTime.Now,
-                            agv_taskstate = "Queue",
-                            agv_qty = 1,
-                            agv_tasktype = "TaskType_EmptyPallet",
-                            agv_toaddress = station.stationCode,
-                            agv_userid = "绯荤粺",
-                            agv_TrayStatus = "EmptyTray",// station.tray_status,
-                            agv_Traytype = station.tray_type
-                        };
-                        station.location_state = LocationStateEnum.Busy.ToString();
-                        stationinfoRepository.Update(station, true);
-                        agvtaskRepository.Add(taskPart, true);
-                        WriteDBLog.Success("鍒涘缓琛ョ┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿taskPart.agv_tasknum}", "PCS");
+                            agv_task.agv_taskstate = AGVTaskStateEnum.Create.ToString();
+                            //agv_task.EndQuantity = EmptyStation.quantity;
+                            agv_task.agv_toaddress = station.stationCode;
+                            agvtaskRepository.Update(agv_task, true);
+                            station.location_state = LocationStateEnum.Busy.ToString();
+                            stationinfoRepository.Update(station, true);
+                            WriteDBLog.Success("鏇存柊琛ョ┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿agv_task.agv_tasknum}", "PCS");
+                        }
+                        else
+                        {
+                            dt_agvtask taskPart = new dt_agvtask()
+                            {
+                                agv_fromaddress = "",
+                                agv_id = Guid.NewGuid(),
+                                agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+                                agv_grade = station.stationCode.Contains("W0100100") ? 3 : 2,
+                                agv_createtime = DateTime.Now,
+                                agv_taskstate = "Queue",
+                                agv_qty = 1,
+                                agv_tasktype = "TaskType_EmptyPallet",
+                                agv_toaddress = station.stationCode,
+                                agv_userid = "绯荤粺",
+                                agv_TrayStatus = "EmptyTray",// station.tray_status,
+                                agv_Traytype = station.tray_type
+                            };
+                            station.location_state = LocationStateEnum.Busy.ToString();
+                            stationinfoRepository.Update(station, true);
+                            agvtaskRepository.Add(taskPart, true);
+                            WriteDBLog.Success("鍒涘缓琛ョ┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿taskPart.agv_tasknum}", "PCS");
+                        }
+                        
                     }
                 }
             }
@@ -81,41 +97,69 @@
                 VOLContext context = new VOLContext();
                 Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                 Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
-                var stations = stationinfoRepository.Find(x => x.area == "2" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
-                if (stations.Count < 1)
-                {
-                    stations = stationinfoRepository.Find(x => x.area == "3" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
-                }
+                var stations = stationinfoRepository.Find(x => x.stationCode.Contains("C01004") && x.enable && x.location_state == LocationStateEnum.Stroge.ToString()).OrderByDescending(x => x.column).ToList();
+                //if (stations.Count < 1)
+                //{
+                //    stations = stationinfoRepository.Find(x => x.area == "3" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
+                //}
                 foreach (var station in stations)
                 {
-                    if (agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).Any())
+                    if (agvtaskRepository.Find(x => x.agv_fromaddress == station.stationCode).Any())
                         continue;
                     dt_agvtask taskPart = new dt_agvtask()
                     {
-                        agv_fromaddress = "",
+                        agv_fromaddress = station.stationCode,
                         agv_id = Guid.NewGuid(),
                         agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                        agv_grade = 2,
+                        agv_grade = 1,
                         agv_createtime = DateTime.Now,
                         agv_taskstate = "Queue",
+                        //agv_materielid = station.stationType,
                         agv_qty = 1,
+                        StarQuantity = 0,
+                        EndQuantity = 0,// EmptyStation.quantity,
                         agv_tasktype = "TaskType_EmptyPallet",
-                        agv_toaddress = station.stationCode,
+                        agv_toaddress = "",// EmptyStation.stationCode,
                         agv_userid = "绯荤粺",
-                        agv_TrayStatus = "EmptyTray",// station.tray_status, "SmallTray" : "LargeTray"
-                        agv_Traytype = station.area == "4" ? "LargeTray" : "SmallTray",
+                        agv_TrayStatus = "EmptyTray",//station.tray_status,
+                        agv_Traytype = station.tray_type,
                     };
                     agvtaskRepository.Add(taskPart, true);
-                    station.location_state = LocationStateEnum.InBusy.ToString();
+                    station.location_state = LocationStateEnum.OutBusy.ToString();
                     stationinfoRepository.Update(station, true);
-                    WriteDBLog.Success("鍒涘缓琛ュ簱鍐呯┖鎵樹换鍔�", $"浠诲姟缂栧彿锛歿taskPart.agv_tasknum}", "PCS");
+                    //WriteDBLog.Success("鍒涘缓绌烘墭浠诲姟", $"浠诲姟缂栧彿锛歿taskPart.agv_tasknum}", "PCS");
                 }
             }
             catch (Exception ex)
             {
-                WriteDBLog.Error("鍒涘缓琛ュ簱鍐呯┖鎵樹换鍔�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
+                //WriteDBLog.Error("鍒涘缓琛ュ簱鍐呯┖鎵樹换鍔�", $"閿欒淇℃伅锛歿ex.Message}", "PCS");
                 //throw;
             }
         }
+        public static void task()
+        {
+            VOLContext context = new VOLContext();
+            Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
+            Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
+            var tasks = agvtaskRepository.Find(x => x.agv_taskstate == "Queue").OrderBy(x => x.agv_createtime).ToList();
+            foreach (var task in tasks)
+            {
+                if (task.agv_tasktype == "TaskType_EmptyPallet")
+                {
+                    if (task.agv_toaddress == "")
+                    {
+                        var EmptyStation = stationinfoRepository.Find(x => x.area == "11" && x.stationCode.Contains("A") && x.quantity < 5 && x.enable).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault();
+                        if (EmptyStation == null) return;
+                        if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) return;
+                        task.agv_toaddress = EmptyStation.stationCode;
+                        task.EndQuantity = EmptyStation.quantity;
+                        task.agv_taskstate = "Create";
+                        EmptyStation.location_state = LocationStateEnum.Busy.ToString();
+                        stationinfoRepository.Update(EmptyStation, true);
+                        agvtaskRepository.Update(task, true);
+                    }
+                }
+            }
+        }
     }
 }

--
Gitblit v1.9.3