From db6156a92cc59467bde608a00c76952ebc75e488 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 05 三月 2024 09:51:05 +0800
Subject: [PATCH] 优化代码

---
 代码管理/PCS/WCS_Server/WIDESEA_WCS/JobsPart/Common/StationTask.cs |  109 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 88 insertions(+), 21 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 04209b7..33de533 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"
@@ -16,8 +16,8 @@
     public class StationTask
     {
 
-        FreeDB freeDB = new FreeDB();
-        public void CreateTask()
+        static FreeDB freeDB = new FreeDB();
+        public static void CreateTask()
         {
             VOLContext context = new VOLContext();
             Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
@@ -30,7 +30,9 @@
                 //鏍规嵁涓嬫枡鍙g殑缁戝畾淇℃伅鏌ヨ瀵瑰簲宸ュ崟锛屾娴嬫宸ュ崟鏄惁宸插畬鎴�  瀹屾垚鍗冲彲灏嗗叾閫佸叆搴�
 
                 dt_mes_head mesinfo = freeDB.Select<dt_mes_head>().Where(x => x.jobID == item.Number).First();
+                dt_geometry_data dt_Geometry_Data = freeDB.Select<dt_geometry_data>().Where(x => x.Description == mesinfo.drawingNo).First();
                 int CompeletedNum = Convert.ToInt32(mesinfo.quantity) - Convert.ToInt32(mesinfo.finishNum);
+
 
                 //鍒ゅ畾浠诲姟鏄惁宸插垱寤�//濡傚凡瀛樺湪  
                 if (freeDB.Select<dt_agvtask>().Where(x => x.agv_fromaddress == item.stationCode).Count() > 0)
@@ -38,8 +40,11 @@
 
                 if (item.quantity == 5 || CompeletedNum == 0)  //寰幆璇诲彇杞﹁疆鏁颁负5鎴栬�呰鍗曞凡瀹屾垚鏁伴噺鐨勪笅鏂欏彛    鈫掑伐鍗曚汉宸ュ叧闂殑宸ュ崟
                 {
-                    if (mesinfo.quantity <= 50)    //灏忎簬50浠剁洿鎺ュ嚭搴�
+
+
+                    if (mesinfo.quantity <= 50 || item.stationCode.Contains("3"))    //灏忎簬50浠剁洿鎺ュ嚭搴�
                     {
+                        //var station =
                         //todo 瀵绘壘鍙斁璐у鍗忔斁璐у彴
                         dt_agvtask agvtask = new dt_agvtask()
                         {
@@ -56,7 +61,7 @@
                     }
                     else
                     {
-                        dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item);
+                        dt_stationinfo TargetLocation = GetEmptyLocation(stationinfoRepository, mesinfo, item, CompeletedNum, dt_Geometry_Data.e);
 
                         if (TargetLocation != null)
                         {
@@ -88,11 +93,10 @@
         /// <param name="workinfo">璁㈠崟</param>
         /// <param name="stationinfo">涓嬫枡鍙d俊鎭�</param>
         /// <returns></returns>
-        private dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo)
+        private static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo, int CompeletedNum, float e)
         {
             //鏀捐揣浣�
             dt_stationinfo TargetLocation = null;
-
 
             #region 鏍规嵁璁㈠崟鏁伴噺鏉ュ鎵惧搴斿簱鍖轰笖鍚岀墿鏂欑被鍨嬪簱浣�
             //if (workinfo.PlannedQuantity < 50)    //搴撳尯1 鐗╂枡绫诲瀷澶�
@@ -169,22 +173,73 @@
             //} 
             #endregion
 
-            //鏍规嵁璁㈠崟鐐夊彿/宸ュ崟鍙�/绫诲瀷
-            if (mesinfo.quantity >= 180)
+            var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First();
+            dt_inventory inventory = null;
+            if (detail.heatID != null)
             {
-                //鏌ヨ搴撳瓨璁板綍涓槸鍚﹀瓨鍦ㄥ悓绫诲瀷/宸ュ崟/鐐夊彿鐨勮褰�  濡傛湁鍒欐斁缃悓涓�琛岋紝鏃犲垯瀵绘壘鏂板簱浣�
-                var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First();
-                var inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID /*&& x.*/).First();
-                if (inventory != null)
+                inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First();
+            }
+            else
+            {
+                inventory = freeDB.Select<dt_inventory>().Where(x => x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First();
+            }
+
+            if (inventory != null)
+            {
+                var station = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode);
+                if (CompeletedNum <= 15 || station.area == "1")
                 {
-                    int line = Convert.ToInt16(inventory.stationCode.Split("-")[0]);
-                    TargetLocation = stationinfoRepository.Find(x => x.line == line && x.location_state == LocationStateEnum.Empty.ToString() && x.area == inventory.area).FirstOrDefault();
+                    TargetLocation = stationinfoRepository.Find(x => x.column == station.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.line).FirstOrDefault();
                 }
                 else
                 {
-                    TargetLocation = stationinfoRepository.Find(x => x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+                    TargetLocation = stationinfoRepository.Find(x => x.line == station.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault();
                 }
+                if (TargetLocation != null) return TargetLocation;
             }
+
+            if (CompeletedNum <= 15)
+            {
+                TargetLocation = stationinfoRepository.Find(x => x.line == 1 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault();
+            }
+            else
+            {
+                //if (50 < mesinfo.quantity && mesinfo.quantity <= 180 && e < 1100)
+                //    TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+                //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);
+                TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+                if (TargetLocation == null)
+                    TargetLocation = stationinfoRepository.Find(x => x.column == 1 && x.area == "4" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
+            }
+
+            #region
+
+            //鏍规嵁璁㈠崟鐐夊彿/宸ュ崟鍙�/绫诲瀷
+            //if (mesinfo.quantity >= 180)
+            //{
+            //    //鏌ヨ搴撳瓨璁板綍涓槸鍚﹀瓨鍦ㄥ悓绫诲瀷/宸ュ崟/鐐夊彿鐨勮褰�  濡傛湁鍒欐斁缃悓涓�琛岋紝鏃犲垯瀵绘壘鏂板簱浣�
+            //    var detail = freeDB.Select<dt_mes_detail>().Where(x => x.jobID == mesinfo.jobID).First();
+            //    var inventory = freeDB.Select<dt_inventory>().Where(x => x.HeatNumber == detail.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.jobID).First();
+            //    if (inventory != null)
+            //    {
+            //        //int line = Convert.ToInt16(inventory.stationCode.Split("-")[0]);
+            //        var line = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode).line;
+            //        TargetLocation = stationinfoRepository.Find(x => x.line == line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault();
+            //        if (TargetLocation == null && CompeletedNum <= 15)
+            //        {
+            //            TargetLocation = stationinfoRepository.Find(x => x.area == "1" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+            //        }
+            //    }
+            //    else
+            //    {
+            //        TargetLocation = stationinfoRepository.Find(x => x.area == "2" && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
+
+            //    }
+            //}
+            #endregion
 
             if (TargetLocation == null)
             {
@@ -198,14 +253,26 @@
         /// </summary>
         /// <param name="quantity"></param>
         /// <returns></returns>
-        private string GetArea(int quantity)
+        private static string GetArea(int quantity, float e)
         {
-            if (quantity >= 50 && quantity < 180)
-                return "2";
-            else if (quantity >= 180 && quantity < 180)
-                return "3";
-            else if (quantity >= 180 && quantity < 220)
+            if (e < 1100)
+            {
+                if (quantity <= 180)
+                    return "2";
+                else if (quantity <= 225)
+                    return "3";
+            }
+            else
+            {
                 return "4";
+            }
+
+            //if (quantity > 50 && quantity <= 180 && e < 1100)
+            //    return "2";
+            //else if (quantity > 180 && quantity <= 225 && e < 1100)
+            //    return "3";
+            //else if (quantity > 50 && e > 1100)
+            //    return "4";
             return null;
         }
     }

--
Gitblit v1.9.3