From 121a380d651097586384ee0ac70943ce1fc13583 Mon Sep 17 00:00:00 2001
From: 海波 张 <2956280567@qq.com>
Date: 星期三, 09 七月 2025 17:32:58 +0800
Subject: [PATCH] 金坛入库修改

---
 wms/LocationHelper.cs |  202 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 196 insertions(+), 6 deletions(-)

diff --git a/wms/LocationHelper.cs b/wms/LocationHelper.cs
index 9c7c0df..a8879c7 100644
--- a/wms/LocationHelper.cs
+++ b/wms/LocationHelper.cs
@@ -4,7 +4,9 @@
 using HH.WCS.ZhongCeJinTan.wms;
 using Microsoft.Owin;
 using Newtonsoft.Json;
+using Org.BouncyCastle.Utilities;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
@@ -116,6 +118,14 @@
                 result.Add(item.S_CODE);
             }
             return result;
+        }
+
+
+        internal static Location GetConnectionByEnd(string S_AREA_CODE,int rodway)
+        {
+            var db = new SqlHelper<object>().GetInstance();
+            return db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE && s.C_ENABLE == "Y" &&s.CONNEC_ROADWAY==rodway).First();
+            
         }
 
         /// <summary>
@@ -282,7 +292,7 @@
         /// </summary>
         /// <param name="locations"></param>
         /// <returns></returns>
-        internal static Location FindBalanceEndcolByLocList(List<Location> locations, string endArea, string rodway = "")
+        internal static Location FindBalanceEndcolByLocList(List<Location> locations, string endArea, string rodway = "",string CONNECTION = "",string taskNo="")
         {
             try
             {
@@ -293,6 +303,36 @@
 
                 //浣滀笟娴佺▼鐨勫贩閬�                 var xd = new List<string>();
+
+
+
+                //鑾峰彇string鎺ラ┏浣嶉泦鍚�+                var connectionList = LocationHelper.GetConnectionList(CONNECTION);
+
+                //涓嶅彲鐢ㄦ帴椹充綅闆嗗悎
+                var flaseConnectionList = LocationHelper.GetConnectionListByst(connectionList);
+
+                List<Location> jblist = new List<Location>();
+
+                //璇㈤棶绔嬪簱鍙敤鎺ラ┏浣�+                var usableConnectionList = WcsTask.WcsPositionAvailable(taskNo,connectionList);
+                if (usableConnectionList != null && usableConnectionList.code == "0")
+                {
+
+                    var balanceConnectionList = LocationHelper.GetConnectionListByst(usableConnectionList.available);
+                  
+
+                    List<Location> difference = flaseConnectionList
+    .Where(loc1 => !balanceConnectionList.Any(loc2 => loc2.S_CODE == loc1.S_CODE))
+    .ToList();
+
+                    jblist = difference;
+
+
+                    LogHelper.Info($"ZCSendTask鍏ュ簱浠诲姟涓嬪彂涓嶅彲鐢ㄦ帴椹充綅" + JsonConvert.SerializeObject(jblist), "Mes浠诲姟涓嬪彂");
+                }
+                    
+              
 
                 List<RoadWayEnable> rowdwa = null;
 
@@ -316,6 +356,7 @@
 
                     var flag = false;
                     var flag1 = false;
+                    var flag2 = false;
 
                     foreach (var item in rowdwa)
                     {
@@ -337,7 +378,17 @@
                         }
                     }
 
-                    if (flag1 || flag)
+
+                    foreach (var item2 in jblist)
+                    {
+                        if (rowList.Count(a => a.N_ROADWAY == item2.CONNEC_ROADWAY) > 0)
+                        {
+                            flag2 = true;
+                            break;
+                        }
+                    }
+
+                    if (flag1 || flag || flag2)
                     {
                        locations.RemoveAll(a => a.N_ROW == rows[i]);
                     }
@@ -353,6 +404,138 @@
                 foreach (var item in balanceLocList)
                 {
                     if (item.S_LOCK_STATE=="鏃� && item.N_CURRENT_NUM==0)
+                    {
+                        end = item;
+                        break;
+                    }
+                }
+                return end;
+            }
+            catch (Exception)
+            {
+
+                throw;
+            }
+
+        }
+
+
+        /// <summary>
+        /// 鎵剧粓鐐瑰贩閬撳彲鐢ㄧ┖璐т綅  宸烽亾鍧囪 鐗╂枡鍧囪 
+        /// </summary>
+        /// <param name="locations"></param>
+        /// <returns></returns>
+        internal static Location FindBalanceEndcolByLocListItem(List<Location> locations, string endArea, string rodway = "", string CONNECTION = "", string taskNo = "",string itemCode="")
+        {
+            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>();
+
+
+
+                //鑾峰彇string鎺ラ┏浣嶉泦鍚�+                var connectionList = LocationHelper.GetConnectionList(CONNECTION);
+
+                //涓嶅彲鐢ㄦ帴椹充綅闆嗗悎
+                var flaseConnectionList = LocationHelper.GetConnectionListByst(connectionList);
+
+                List<Location> jblist = new List<Location>();
+
+                //璇㈤棶绔嬪簱鍙敤鎺ラ┏浣�+                var usableConnectionList = WcsTask.WcsPositionAvailable(taskNo, connectionList);
+                if (usableConnectionList != null && usableConnectionList.code == "0")
+                {
+                    var balanceConnectionList = LocationHelper.GetConnectionListByst(usableConnectionList.available);
+
+
+                    List<Location> difference = flaseConnectionList
+                    .Where(loc1 => !balanceConnectionList.Any(loc2 => loc2.S_CODE == loc1.S_CODE))
+                    .ToList();
+
+                    jblist = difference;
+                    LogHelper.Info($"ZCSendTask鍏ュ簱浠诲姟涓嬪彂涓嶅彲鐢ㄦ帴椹充綅" + JsonConvert.SerializeObject(jblist), "Mes浠诲姟涓嬪彂");
+                }
+
+
+
+                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;
+                    var flag2 = 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;
+                        }
+                    }
+
+
+                    foreach (var item2 in jblist)
+                    {
+                        if (rowList.Count(a => a.N_ROADWAY == item2.CONNEC_ROADWAY) > 0)
+                        {
+                            flag2 = true;
+                            break;
+                        }
+                    }
+
+                    if (flag1 || flag || flag2)
+                    {
+                        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]);
+                    }
+                }
+
+                var balanceLocList = RoadWayBalance(locations);
+
+                balanceLocList = LocationHelper.RoadWayBalance1ByItem(balanceLocList, itemCode);
+
+                foreach (var item in balanceLocList)
+                {
+                    if (item.S_LOCK_STATE == "鏃�)
                     {
                         end = item;
                         break;
@@ -566,13 +749,15 @@
                 result.Add(re);
             }
 
-            
-
                result =  result.OrderBy(a=>a.taskCount).ToList();
 
                 foreach (var item in result)
                 {
-                    location_roadray.Add(item.loc);
+                    var loclist = lstTrueLocation.Where(o => o.N_ROADWAY == item.loc.N_ROADWAY && o.N_CURRENT_NUM==0 ).OrderBy(b => b.N_ROW).OrderBy(b => b.N_COL).ToList();
+                    foreach (var item1 in loclist)
+                    {
+                        location_roadray.Add(item1);
+                    }   
                 }
 
 
@@ -1052,7 +1237,7 @@
 
                 var balanceConnectionList = LocationHelper.GetConnectionListByst(connectionList);
 
-
+                
 
                 LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟鎺掗櫎涓嶅彲鐢ㄥ贩閬撳紑濮�, "Mes浠诲姟涓嬪彂");
                 //浣滀笟娴佺▼鐨勫贩閬�@@ -1155,6 +1340,11 @@
                         }
                     }
 
+
+                //var queryable = db.Queryable<Location>().LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE)
+                //    .LeftJoin<CntrItemRel>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE)
+                //    .Where((a, b, c) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == endArea);
+
                     LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣鍚堟牸鐗╂枡鏁伴噺{startList.Count}", "Mes浠诲姟涓嬪彂");
                     var startItem = startList.OrderBy(a => a.PRODUCTIONDATE).FirstOrDefault();
 

--
Gitblit v1.9.1