From 19c66ba052a7fb26c4d27deaa75ae46479eee342 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 01 四月 2024 10:36:44 +0800
Subject: [PATCH] 优化堆垛逻辑和入库逻辑

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs |  120 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 87 insertions(+), 33 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs"
index ef73816..8880cd9 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs"
@@ -34,6 +34,7 @@
                 Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
                 Idt_mes_headRepository mes_HeadRepository = new dt_mes_headRepository(context);
                 Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
+                IVV_Mes_WorkinfoRepository workinfoRepository = new VV_Mes_WorkinfoRepository(context);
 
                 var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "閾炬潯鏈�");
                 if (Pipeline_client == null) throw new Exception("閾炬潯鏈鸿皟搴︽湇鍔℃湭寮�鍚紒");
@@ -43,6 +44,9 @@
 
                 foreach (var item in stationinfos)
                 {
+                    //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪  
+                    if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any())
+                        continue;
 
                     var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", item.stationCode);//璇诲彇鎵樼洏淇″彿:1:鏈�,2鏃�
                     var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", item.stationCode);//璇诲彇璐х墿淇″彿:1:鏈�,2鏃�
@@ -50,31 +54,38 @@
 
                     //鏍规嵁涓嬫枡鍙g殑缁戝畾淇℃伅鏌ヨ瀵瑰簲宸ュ崟锛屾娴嬫宸ュ崟鏄惁宸插畬鎴�  瀹屾垚鍗冲彲灏嗗叾閫佸叆搴�
 
-                    dt_mes_head mesinfo = mes_HeadRepository.Find(x => x.jobID == item.Number).FirstOrDefault();
-                    if (mesinfo == null)
+                    var work = workinfoRepository.Find(x => x.workOrder == item.Number && x.drawingNo == x.drawingNo && x.heatID == item.heatNumber).FirstOrDefault();
+                    if (work == null)
                     {
-                        item.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟澶磋〃锛�";
+                        item.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟淇℃伅锛�";
                         item.location_state = LocationStateEnum.Abnormal.ToString();
                         stationinfoRepository.Update(item, true);
                         continue;
-                        //throw new Exception("鏈壘鍒板伐鍗曞ご琛紒宸ュ崟鍙凤細" + item.Number);
                     }
-                    var dt_Geometry_Data = PipelineJob.QueryMateriel(mesinfo.drawingNo);
-                    var dt_Geometry_Data1 = PipelineJob.QueryMateriel1(mesinfo.drawingNo);
 
-                    int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum);
+                    //dt_mes_head mesinfo = mes_HeadRepository.Find(x => x.workOrder == item.Number).FirstOrDefault();
+                    //if (mesinfo == null)
+                    //{
+                    //    item.remark = "瑙﹀彂鍏ュ簱浠诲姟,浣嗘湭鎵惧埌宸ュ崟澶磋〃锛�";
+                    //    item.location_state = LocationStateEnum.Abnormal.ToString();
+                    //    stationinfoRepository.Update(item, true);
+                    //    continue;
+                    //    //throw new Exception("鏈壘鍒板伐鍗曞ご琛紒宸ュ崟鍙凤細" + item.Number);
+                    //}
+                    //var dt_Geometry_Data = PipelineJob.QueryMateriel(mesinfo.drawingNo);
+                    //var dt_Geometry_Data1 = PipelineJob.QueryMateriel1(mesinfo.drawingNo);
+
+                    //int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum);
 
 
-                    //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪  
-                    if (agvtaskRepository.Find(x => x.agv_fromaddress == item.stationCode).Any())
-                        continue;
+
                     dt_stationinfo TargetLocation = null;
                     string tasktype = "";
-                    if (item.quantity == 5 || CompeletedNum == 0)  //寰幆璇诲彇杞﹁疆鏁颁负5鎴栬�呰鍗曞凡瀹屾垚鏁伴噺鐨勪笅鏂欏彛    鈫掑伐鍗曚汉宸ュ叧闂殑宸ュ崟
+                    if (item.quantity == 5 /*|| CompeletedNum == 0*/)  //寰幆璇诲彇杞﹁疆鏁颁负5鎴栬�呰鍗曞凡瀹屾垚鏁伴噺鐨勪笅鏂欏彛    鈫掑伐鍗曚汉宸ュ叧闂殑宸ュ崟
                     {
 
 
-                        if (mesinfo.quantity <= 50 || item.stationCode.Contains("3"))    //灏忎簬50浠剁洿鎺ュ嚭搴�
+                        if (/*(mesinfo.quantity <= 50 && string.IsNullOrEmpty(mesinfo.area)) ||*/ item.stationCode.Contains("3"))    //灏忎簬50浠剁洿鎺ュ嚭搴�
                         {
                             //todo 瀵绘壘鍙斁璐у鍗忔斁璐у彴
                             tasktype = "TaskType_OutsourceInbound";
@@ -85,7 +96,8 @@
                         {
                             //todo:  璋冪敤WMS鎺ュ彛鍒涘缓浠诲姟
                             tasktype = "TaskType_Inbound";
-                            TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data == null ? dt_Geometry_Data1.e : dt_Geometry_Data.e);
+                            TargetLocation = GetLocation.GetEmptyLocation(stationinfoRepository, work, item);
+                            //TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data == null ? dt_Geometry_Data1.e : dt_Geometry_Data.e);
                         }
                         if (TargetLocation != null)
                         {
@@ -103,8 +115,8 @@
                                 agv_toaddress = TargetLocation.stationCode,
                                 agv_userid = "绯荤粺",
                                 bindSN = item.bindSN,
-                                agv_worktype = Convert.ToInt32(mesinfo.processCode),
-                                agv_materbarcode = mesinfo.materialCode,
+                                agv_worktype = Convert.ToInt32(work.processCode),
+                                agv_materbarcode = work.materialCode,
                                 agv_Traytype = item.tray_type,
                                 jobID = item.Number,
                                 agv_TrayStatus = item.tray_status
@@ -116,6 +128,8 @@
 
                             TargetLocation.location_state = LocationStateEnum.InBusy.ToString();
                             TargetLocation.stationType = agvtask.agv_materielid;
+                            TargetLocation.heatNumber = item.heatNumber;
+                            TargetLocation.Number = agvtask.jobID;
                             stationinfoRepository.Update(TargetLocation, true);
                             WriteDBLog.Success("鍒涘缓鍏ュ簱浠诲姟", $"浠诲姟缂栧彿锛歿agvtask.agv_tasknum}", "PCS");
                         }
@@ -142,8 +156,10 @@
             dt_stationinfo TargetLocation = null;
 
             #region 鍚岀被鍨嬫斁涓�琛�
-            var area1 = GetArea(mesinfo.quantity, e);
-            TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault();
+            //if (area1 == "1")
+            TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo).FirstOrDefault();
+
+            //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == area1).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault();
             if (TargetLocation != null)
             {
                 #region 鍚屼竴琛屽彧鍏佽涓�涓换鍔�
@@ -152,14 +168,33 @@
                 //    return null;
                 #endregion
 
-                #region 鍑哄簱浠诲姟浼樺厛,瀛樺湪鍑哄簱浠诲姟杩欎竴琛屽垯涓嶈兘鍏ュ簱
-                var OutTask = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == area1 && x.location_state == LocationStateEnum.OutBusy.ToString()).Any();
-                if (OutTask) return null;
+                #region 鍑哄簱浠诲姟浼樺厛,瀛樺湪鍑哄簱浠诲姟鍒欎笉鑳藉叆搴�
+                bool OutTask = false;
+                if (TargetLocation.area == "1")
+                {
+                    TargetLocation = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderByDescending(x => x.line).FirstOrDefault();
+                    if (TargetLocation != null)
+                        OutTask = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.OutBusy.ToString()).Any();
+                    if (OutTask)//杩欏垪瀛樺湪鍑哄簱浠诲姟,瀵绘壘涓�鍒楃┖璐т綅
+                        TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.column).FirstOrDefault();
+                    if (TargetLocation != null) return TargetLocation;
+                }
+                else
+                {
+                    TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.column).FirstOrDefault();
+                    if (TargetLocation != null)
+                        OutTask = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any();
+                    //搴撳唴瀛樺湪鍑哄簱浠诲姟锛岄噸鏂板紑涓�琛屽叆搴�
+                    if (OutTask)
+                        TargetLocation = stationinfoRepository.Find(x => x.column == (TargetLocation.area == "2" ? 1 : 10) && x.area == TargetLocation.area && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).FirstOrDefault();
+                    if (TargetLocation != null) return TargetLocation;
+                }
+
                 #endregion
 
-                TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
-                if (TargetLocation != null)
-                    return TargetLocation;
+                //TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
+                //if (TargetLocation != null)
+                //    return TargetLocation;
             }
             #endregion
 
@@ -249,15 +284,19 @@
                 stationinfoRepository.Update(stationinfo, true);
                 return null;
             }
+
+            #region 鏌ユ壘搴撳瓨
             dt_inventory inventory = null;
             if (detail.heatID != null)
             {
-                inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).FirstOrDefault();
+                inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
             }
             else
             {
-                inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).FirstOrDefault();
+                inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
             }
+            #endregion
+
 
             #region 鏍规嵁搴撳瓨鏌ユ壘鍙叆搴撶┖璐т綅
             if (inventory != null)
@@ -277,8 +316,9 @@
 
 
 
+            var area1 = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, e) : mesinfo.area;
 
-            if (CompeletedNum <= 15)
+            if (CompeletedNum <= 15 || area1 == "1")
             {
                 TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault();
             }
@@ -289,17 +329,31 @@
                 //else if (180 < mesinfo.quantity && mesinfo.quantity <= 225 && e < 1100)
                 //    TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "3" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
                 //if (50 < mesinfo.quantity && e > 1100 || TargetLocation == null)
-                var area = GetArea(mesinfo.quantity, e);
+
+                //var area = GetArea(mesinfo.quantity, e);
 
 
-                TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+                TargetLocation = stationinfoRepository.Find(x => x.column == (area1 == "2" ? 1 : 10) && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).OrderBy(x => x.column).FirstOrDefault();
                 if (TargetLocation == null)
                 {
-                    if (area == "2")
-                        area = "3";
-                    else if (area == "3")
-                        area = "2";
-                    TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+                    if (area1 == "2")
+                        area1 = "3";
+                    else if (area1 == "3")
+                        area1 = "2";
+                    TargetLocation = stationinfoRepository.Find(x => x.column == (area1 == "2" ? 1 : 10) && x.area == area1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).OrderBy(x => x.column).FirstOrDefault();
+                    if (TargetLocation == null)
+                    {
+                        //TargetLocation = stationinfoRepository.Find(x => x.stationType == mesinfo.drawingNo && x.area == "1").OrderByDescending(x => x.column).FirstOrDefault();
+
+                        //if (TargetLocation != null)
+                        //    TargetLocation = stationinfoRepository.Find(x => x.column == TargetLocation.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderByDescending(x => x.line).FirstOrDefault();
+                        //if (TargetLocation == null)
+                        //    TargetLocation = stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).OrderByDescending(x => x.line).FirstOrDefault();
+                        if (TargetLocation == null)
+                            TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault();
+
+                    }
+
                 }
 
                 //if (TargetLocation == null)

--
Gitblit v1.9.3