From 874ceff175a7308da045943fb7def1f6c6560a51 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 26 三月 2024 11:31:08 +0800
Subject: [PATCH] 优化NG任务触发逻辑

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/新文件夹/OutboundTask_a.cs |  137 +++++++++++++++++++++++----------------------
 1 files changed, 69 insertions(+), 68 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/OutboundTask_a.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/OutboundTask_a.cs"
index bb62e0d..fefec01 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/OutboundTask_a.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/\346\226\260\346\226\207\344\273\266\345\244\271/OutboundTask_a.cs"
@@ -17,7 +17,7 @@
 using static FreeSql.Internal.GlobalFilter;
 using static System.Collections.Specialized.BitVector32;
 
-namespace WIDESEA_WCS.JobsPart.Common.鏂版枃浠跺す
+namespace WIDESEA_WCS.JobsPart.Common
 {
     public class OutboundTask_a
     {
@@ -35,7 +35,7 @@
                 Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context);
                 Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
 
-                var mes_heads = mes_HeadRepository.Find(x => x.processCode == "28").OrderBy(x => x.expectedStartTime).ToList();
+                var mes_heads = mes_HeadRepository.Find(x => x.processCode == "28").OrderByDescending(x => x.CreateTime).ToList();
                 foreach (var mes_head in mes_heads)
                 {
                     #region 鏍规嵁宸ュ崟瀛愯〃鏌ユ壘搴撳瓨
@@ -48,9 +48,12 @@
                             var Station = stationinfoRepository.Find(x => x.stationCode == inventory.stationCode).FirstOrDefault();
                             if (Station != null)
                             {
-                                var stationinfos = stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.quantity > 0 && x.enable && x.location_state == LocationStateEnum.Stroge.ToString()).OrderByDescending(x => x.column).ToList();
-                                foreach (var stationinfo in stationinfos)
+                                var stationinfo = stationinfoRepository.Find(x => x.line == Station.line && x.area == Station.area && x.enable && x.quantity > 0).OrderByDescending(x => x.column).FirstOrDefault();
+
+                                if (stationinfo != null)
                                 {
+                                    if (stationinfo.location_state == LocationStateEnum.OutBusy.ToString() || stationinfo.location_state != LocationStateEnum.Stroge.ToString()) continue;
+
                                     if (string.IsNullOrEmpty(stationinfo.bindSN))
                                     {
                                         stationinfo.remark = "杞﹁疆SN鍙蜂俊鎭紓甯�";
@@ -68,75 +71,73 @@
                                     }
 
                                     #region 璐т綅杞﹁疆鍏ㄩ儴鍖呭惈鍦ㄥ伐鍗曞唴鍒欎笅鍙戜换鍔�
-                                    bool OK = false;
+                                    //bool OK = false;
                                     foreach (var SN in lists)
                                     {
-                                        OK = mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN == SN).Any();
-                                    }
-                                    if (OK)
-                                    {
-                                        dt_agvtask agvtask = new dt_agvtask()
-                                        {
-                                            agv_fromaddress = stationinfo.stationCode,
-                                            agv_id = Guid.NewGuid(),
-                                            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                                            agv_grade = 1,
-                                            agv_createtime = DateTime.Now,
-                                            agv_taskstate = "Queue",
-                                            agv_materielid = stationinfo.stationType,
-                                            agv_qty = stationinfo.quantity,
-                                            agv_tasktype = "TaskType_Outbound",
-                                            agv_toaddress = "",
-                                            agv_userid = "绯荤粺",
-                                            bindSN = stationinfo.bindSN,
-                                            jobID = mes_head.jobID,
-                                            agv_worktype = Convert.ToInt32(mes_head.processCode),
-                                            agv_materbarcode = mes_head.materialCode,
-                                            agv_Traytype = stationinfo.tray_type,
-                                            agv_TrayStatus = stationinfo.tray_status
-                                        };
-                                        stationinfo.location_state = LocationStateEnum.OutBusy.ToString();
-                                        stationinfoRepository.Update(stationinfo, true);
-                                        agvtaskRepository.Add(agvtask, true);
-                                        WriteDBLog.Success("鍒涘缓鍑哄簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
-                                        continue;
-                                    }
-                                    #endregion
+                                        if (!mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN.Contains(SN)).Any()) return;
 
-                                    #region 璐т綅杞﹁疆鏈変竴涓寘鍚湪宸ュ崟鍐呭垯涓嬪彂浠诲姟
-                                    //foreach (var SN in lists)
-                                    //{
-                                    //    if (mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN == SN).Any())
-                                    //    {
-                                    //        dt_agvtask agvtask = new dt_agvtask()
-                                    //        {
-                                    //            agv_fromaddress = stationinfo.stationCode,
-                                    //            agv_id = Guid.NewGuid(),
-                                    //            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
-                                    //            agv_grade = 2,
-                                    //            agv_createtime = DateTime.Now,
-                                    //            agv_taskstate = "Queue",
-                                    //            agv_materielid = stationinfo.stationType,
-                                    //            agv_qty = stationinfo.quantity,
-                                    //            agv_tasktype = "TaskType_Outbound",
-                                    //            agv_toaddress = "",
-                                    //            agv_userid = "绯荤粺",
-                                    //            bindSN = stationinfo.bindSN,
-                                    //            jobID = mes_head.jobID,
-                                    //            agv_worktype = Convert.ToInt32(mes_head.processCode),
-                                    //            agv_materbarcode = mes_head.materialCode,
-                                    //            agv_Traytype = stationinfo.tray_type,
-                                    //            agv_TrayStatus = stationinfo.tray_status
-                                    //        };
-                                    //        stationinfo.location_state = LocationStateEnum.OutBusy.ToString();
-                                    //        stationinfoRepository.Update(stationinfo, true);
-                                    //        agvtaskRepository.Add(agvtask, true);
-                                    //        WriteDBLog.Success("鍒涘缓鍑哄簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
-                                    //        continue;
-                                    //    }
-                                    //}
+                                    }
+                                    dt_agvtask agvtask = new dt_agvtask()
+                                    {
+                                        agv_fromaddress = stationinfo.stationCode,
+                                        agv_id = Guid.NewGuid(),
+                                        agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+                                        agv_grade = 1,
+                                        agv_createtime = DateTime.Now,
+                                        agv_taskstate = "Queue",
+                                        agv_materielid = stationinfo.stationType,
+                                        agv_qty = stationinfo.quantity,
+                                        agv_tasktype = "TaskType_Outbound",
+                                        agv_toaddress = "",
+                                        agv_userid = "绯荤粺",
+                                        bindSN = stationinfo.bindSN,
+                                        jobID = mes_head.jobID,
+                                        agv_worktype = Convert.ToInt32(mes_head.processCode),
+                                        agv_materbarcode = mes_head.materialCode,
+                                        agv_Traytype = stationinfo.tray_type,
+                                        agv_TrayStatus = stationinfo.tray_status
+                                    };
+                                    stationinfo.location_state = LocationStateEnum.OutBusy.ToString();
+                                    stationinfoRepository.Update(stationinfo, true);
+                                    agvtaskRepository.Add(agvtask, true);
+                                    WriteDBLog.Success("鍒涘缓鍑哄簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
+                                    continue;
                                     #endregion
                                 }
+
+                                #region 璐т綅杞﹁疆鏈変竴涓寘鍚湪宸ュ崟鍐呭垯涓嬪彂浠诲姟
+                                //foreach (var SN in lists)
+                                //{
+                                //    if (mes_DetailRepository.Find(x => x.jobID == mes_head.jobID && x.SN == SN).Any())
+                                //    {
+                                //        dt_agvtask agvtask = new dt_agvtask()
+                                //        {
+                                //            agv_fromaddress = stationinfo.stationCode,
+                                //            agv_id = Guid.NewGuid(),
+                                //            agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
+                                //            agv_grade = 2,
+                                //            agv_createtime = DateTime.Now,
+                                //            agv_taskstate = "Queue",
+                                //            agv_materielid = stationinfo.stationType,
+                                //            agv_qty = stationinfo.quantity,
+                                //            agv_tasktype = "TaskType_Outbound",
+                                //            agv_toaddress = "",
+                                //            agv_userid = "绯荤粺",
+                                //            bindSN = stationinfo.bindSN,
+                                //            jobID = mes_head.jobID,
+                                //            agv_worktype = Convert.ToInt32(mes_head.processCode),
+                                //            agv_materbarcode = mes_head.materialCode,
+                                //            agv_Traytype = stationinfo.tray_type,
+                                //            agv_TrayStatus = stationinfo.tray_status
+                                //        };
+                                //        stationinfo.location_state = LocationStateEnum.OutBusy.ToString();
+                                //        stationinfoRepository.Update(stationinfo, true);
+                                //        agvtaskRepository.Add(agvtask, true);
+                                //        WriteDBLog.Success("鍒涘缓鍑哄簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
+                                //        continue;
+                                //    }
+                                //}
+                                #endregion
                             }
                         }
                     }

--
Gitblit v1.9.3