From a99ceecce8c9a2521ac1fc167f4eff764cbdb123 Mon Sep 17 00:00:00 2001
From: 海波 张 <2956280567@qq.com>
Date: 星期一, 19 五月 2025 17:35:18 +0800
Subject: [PATCH] bug优化

---
 wms/LocationHelper.cs |  238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 227 insertions(+), 11 deletions(-)

diff --git a/wms/LocationHelper.cs b/wms/LocationHelper.cs
index f806d68..85bafbe 100644
--- a/wms/LocationHelper.cs
+++ b/wms/LocationHelper.cs
@@ -1,6 +1,7 @@
 锘縰sing HH.WCS.ZhongCeJinTan;
 using HH.WCS.ZhongCeJinTan.util;
 using HH.WCS.ZhongCeJinTan.wms;
+using Microsoft.Owin;
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
@@ -8,6 +9,8 @@
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using Top.Api;
+using static HH.WCS.ZhongCeJinTan.api.ApiModel;
 using static HH.WCS.ZhongCeJinTan.util.Settings;
 using static HH.WCS.ZhongCeJinTan.wms.WcsModel;
 
@@ -68,7 +71,7 @@
         internal static List<Location> GetAllLocList1(string S_AREA_CODE)
         {
             var db = new SqlHelper<object>().GetInstance();
-            return db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE).OrderBy(a=> a.N_ROW).OrderBy(a => a.N_COL).ToList();
+            return db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE && s.C_ENABLE == "Y").OrderBy(a=> a.N_ROW).OrderBy(a => a.N_COL).ToList();
         }
 
         /// <summary>
@@ -77,7 +80,7 @@
         internal static List<Location> GetAllLocList2(string S_AREA_CODE)
         {
             var db = new SqlHelper<object>().GetInstance();
-            return db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE).OrderBy(a => a.N_ROW).OrderByDescending(a => a.N_COL).ToList();
+            return db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE && s.C_ENABLE == "Y").OrderBy(a => a.N_ROW).OrderByDescending(a => a.N_COL).ToList();
         }
 
 
@@ -87,7 +90,7 @@
         internal static List<string> GetConnectionList(string S_AREA_CODE)
         {
             var db = new SqlHelper<object>().GetInstance();
-            var ConnectionList =  db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE).OrderBy(a => a.N_ROW).OrderBy(a => a.N_COL).ToList();
+            var ConnectionList =  db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE && s.C_ENABLE == "Y").OrderBy(a => a.N_ROW).OrderBy(a => a.N_COL).ToList();
             List<string> result = new List<string>();
             foreach (var item in ConnectionList)
             {
@@ -95,6 +98,31 @@
             }
             return result;
         }
+
+        /// <summary>
+        /// 杩斿洖鍧囪 鐨勬帴椹充綅闆嗗悎
+        /// </summary>
+        internal static List<connectionBalance> GetBalanceConnectionList(List<string> locList)
+        {
+            var db = new SqlHelper<object>().GetInstance();
+          
+            List<connectionBalance> result = new List<connectionBalance>();
+
+            foreach (var item in locList)
+            {
+                var ConnectionList = 0;
+                ConnectionList = db.Queryable<WMSTask>().Where(a => (a.S_END_LOC.Contains(item) || a.S_START_LOC.Contains(item)) && a.S_B_STATE != "瀹屾垚" && a.S_B_STATE != "鍙栨秷" && a.S_B_STATE != "閿欒").ToList().Count();
+                var re = new connectionBalance();
+                var con = LocationHelper.GetLoc(item);
+                re.loc = con;
+                re.taskCount = ConnectionList;
+                result.Add(re);
+            }
+            return result.OrderBy(a => a.taskCount).ToList();
+        }
+
+
+        
 
         /// <summary>
         /// 鎵剧粓鐐瑰贩閬撳彲鐢ㄧ┖璐т綅
@@ -176,10 +204,10 @@
                         {
                             other = rowList.Where(b => b.S_LOCK_STATE == "鏃�).OrderBy(a => a.N_COL).Where(a => a.N_COL > full.N_COL).FirstOrDefault();
                         }
-                        if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "绂佺敤"))
+                        if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "N"))
                         {
                             //绂佺敤浜嗛�鎷╁悗闈竴涓揣浣�-                            other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "绂佺敤") && a.S_AREA_CODE == other.S_AREA_CODE && a.S_LOCK_STATE=="鏃�&& a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
+                            other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "N") && a.S_AREA_CODE == other.S_AREA_CODE && a.S_LOCK_STATE=="鏃�&& a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
                         }
                         if (other != null)
                         {
@@ -200,6 +228,97 @@
 
         }
 
+
+        /// <summary>
+        /// 鎵剧粓鐐瑰贩閬撳彲鐢ㄧ┖璐т綅 鍧囪 
+        /// </summary>
+        /// <param name="locations"></param>
+        /// <returns></returns>
+        internal static Location FindBalanceEndcolByLocList(List<Location> locations, string endArea, string rodway = "")
+        {
+            try
+            {
+                var db = new SqlHelper<object>().GetInstance();
+                Location end = null;
+                //鏍规嵁缁堢偣璐т綅鎵剧┖闂茶揣浣�+                var rows = locations.Select(a => a.N_ROW).Distinct().ToList();
+
+                //浣滀笟娴佺▼鐨勫贩閬�+                var xd = new List<string>();
+
+                List<RoadWayEnable> rowdwa = null;
+
+                if (!string.IsNullOrEmpty(rodway))
+                {
+                    xd = rodway.Split('-').ToList();
+                    rowdwa = db.Queryable<RoadWayEnable>().Where(x => x.areaCode == endArea && x.status == "0" && xd.Contains(x.roadWay)).ToList();
+                }
+                else
+                {
+                    //鏌ユ壘鍙敤宸烽亾
+                    rowdwa = db.Queryable<RoadWayEnable>().Where(x => x.areaCode == endArea && x.status == "0").ToList();
+                }
+
+
+
+
+                for (int i = 0; i < rows.Count; i++)
+                {
+                    var rowList = locations.Where(r => r.N_ROW == rows[i]).ToList();
+
+                    var flag = false;
+                    var flag1 = false;
+
+                    foreach (var item in rowdwa)
+                    {
+                        if (rowList.Count(a => a.N_ROADWAY.ToString() == item.roadWay) > 0)
+                        {
+                            flag = true;
+                            break;
+                        }
+
+
+                    }
+
+                    foreach (var item1 in xd)
+                    {
+                        if (rowList.Count(a => a.N_ROADWAY.ToString() != item1) > 0)
+                        {
+                            flag1 = true;
+                            break;
+                        }
+                    }
+
+                    if (flag1 || flag)
+                    {
+                       locations.RemoveAll(a => a.N_ROW == rows[i]);
+                    }
+
+                    if (rowList.Count(a => a.N_CURRENT_NUM == 0) == 0)
+                    {
+                        locations.RemoveAll(a => a.N_ROW == rows[i]);
+                    }
+                }
+
+
+
+                foreach (var item in locations)
+                {
+                    if (item.S_LOCK_STATE=="鏃� && item.N_CURRENT_NUM==0)
+                    {
+                        end = item;
+                        break;
+                    }
+                }
+                return end;
+            }
+            catch (Exception)
+            {
+
+                throw;
+            }
+
+        }
 
         /// <summary>
         /// 鎵剧粓鐐瑰彲鐢ㄧ┖璐т綅鎺掗櫎涓嶅彲鐢ㄥ贩閬�@@ -253,10 +372,10 @@
                         {
                             other = rowList.Where(b => b.S_LOCK_STATE == "鏃�).OrderBy(a => a.N_COL).Where(a => a.N_COL > full.N_COL).FirstOrDefault();
                         }
-                        if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "绂佺敤"))
+                        if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "N"))
                         {
                             //绂佺敤浜嗛�鎷╁悗闈竴涓揣浣�-                            other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "绂佺敤") && a.S_AREA_CODE == other.S_AREA_CODE && a.S_LOCK_STATE == "鏃� && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
+                            other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "N") && a.S_AREA_CODE == other.S_AREA_CODE && a.S_LOCK_STATE == "鏃� && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
                         }
                         if (other != null)
                         {
@@ -313,10 +432,10 @@
                         {
                             other = rowList.Where(b => b.S_LOCK_STATE == "鏃�).OrderBy(a => a.N_COL).Where(a => a.N_COL > full.N_COL).FirstOrDefault();
                         }
-                        if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "绂佺敤"))
+                        if (other != null && (!string.IsNullOrEmpty(other.C_ENABLE) && other.C_ENABLE == "N"))
                         {
                             //绂佺敤浜嗛�鎷╁悗闈竴涓揣浣�-                            other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "绂佺敤") && a.S_AREA_CODE == other.S_AREA_CODE && a.S_LOCK_STATE == "鏃� && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
+                            other = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "N") && a.S_AREA_CODE == other.S_AREA_CODE && a.S_LOCK_STATE == "鏃� && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
                         }
                         if (other != null)
                         {
@@ -389,7 +508,7 @@
                 Location start = null;
                 var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
 
-                //鏌ユ壘鍙敤宸烽亾
+                //鏌ユ壘涓嶅彲鐢ㄥ贩閬�                 var rowdwa = db.Queryable<RoadWayEnable>().Where(x => x.areaCode == startArea && x.status == "0").ToList();
 
                 for (int i = 0; i < rowsStart.Count; i++)
@@ -447,6 +566,50 @@
                 throw;
             }
         }
+
+
+        /// <summary>
+        /// 鏍规嵁璧风偣绔嬪簱鍖烘壘绌烘墭 鏍¢獙搴撳瓨
+        /// </summary>
+        /// <param name="locations"></param>
+        /// <returns></returns>
+        internal static bool FindStartcolByLoclistAndcntrFlag(List<Location> locations, string startArea)
+        {
+            var db = new SqlHelper<object>().GetInstance();
+            try
+            {
+                var start = false;
+                var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
+
+  
+                foreach (var item in locations)
+                {
+                    if (item.N_CURRENT_NUM == 0)
+                    {
+                        continue;
+                    }
+                    var tp = db.Queryable<LocCntrRel>().Where(s => s.S_LOC_CODE == item.S_CODE).First();
+
+                    if (tp != null && item.S_LOCK_STATE == "鏃�)
+                    {
+                        var tp1 = db.Queryable<Container>().Where(s => s.S_CODE == tp.S_CNTR_CODE).First();
+
+                        if (tp1 != null && tp1.N_DETAIL_COUNT == 0)
+                        {
+                            return true;
+                        }
+                    }
+                }
+                return start;
+
+            }
+            catch (Exception)
+            {
+
+                throw;
+            }
+        }
+
 
         /// <summary>
         /// 鏍规嵁璧风偣璐ф灦鍖烘壘绌烘墭
@@ -675,6 +838,8 @@
                 LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣鎸夌敓浜ф椂闂存帓搴忕墿鏂欎俊鎭� + JsonConvert.SerializeObject(startItem), "Mes浠诲姟涓嬪彂");
                 if (startItem!=null)
                 {
+                   
+
                     var tp = db.Queryable<LocCntrRel>().Where(s => s.S_CNTR_CODE == startItem.S_CNTR_CODE).First();
                     start = LocationHelper.GetLocOne(tp.S_LOC_CODE);
                     LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣璐т綅淇℃伅" + JsonConvert.SerializeObject(start), "Mes浠诲姟涓嬪彂");
@@ -686,9 +851,60 @@
 
                 throw;
             }
-
         }
 
+
+        /// <summary>
+        /// 鏍规嵁鐗╂枡缂栫爜鎵剧珛搴撳尯璧风偣婊¤揣浣�鏍¢獙鏈夊簱瀛樹絾鏄澶囨姤璀�+        /// </summary>
+        /// <param name="locations"></param>
+        /// <returns></returns>
+        internal static bool FindStartcolByLoclistAndItemFlag(List<Location> locations, string itemCode, string endArea)
+        {
+            var db = new SqlHelper<object>().GetInstance();
+            var res = false;
+            try
+            {
+       
+                var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
+
+                DateTime date = DateTime.Now;
+                List<CntrItemRel> startList = new List<CntrItemRel>(); ;
+
+                foreach (var item in locations)
+                {
+                    if (item.N_CURRENT_NUM == 0)
+                    {
+                        continue;
+                    }
+
+                    var tp = db.Queryable<LocCntrRel>().Where(s => s.S_LOC_CODE == item.S_CODE).First();
+
+                   // LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣璐т綅瀹瑰櫒淇℃伅" + JsonConvert.SerializeObject(tp), "Mes浠诲姟涓嬪彂");
+                    if (tp != null && item.S_LOCK_STATE == "鏃�)
+                    {
+                        var tp1 = db.Queryable<CntrItemRel>().Where(s => s.S_CNTR_CODE == tp.S_CNTR_CODE).First();
+                        //LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣瀹瑰櫒鐗╂枡淇℃伅" + JsonConvert.SerializeObject(tp1), "Mes浠诲姟涓嬪彂");
+
+                        if (tp1 != null && tp1.S_ITEM_CODE == itemCode && tp1.S_ITEM_STATE == "鍚堟牸" && tp1.takeEffectTime < date && tp1.expireTime > date)
+                        {
+                            res = true;
+                            return res;
+                        }
+                    }
+                }
+
+            
+                return res;
+            }
+            catch (Exception)
+            {
+
+                throw;
+            }
+        }
+
+
         /// <summary>
         /// 鏍规嵁鐗╂枡缂栫爜鎵捐揣鏋跺尯璧风偣婊¤揣浣�         /// </summary>

--
Gitblit v1.9.1