From 89943f29476e3de04c638cc7aefbdf2dd24d00c7 Mon Sep 17 00:00:00 2001 From: 海波 张 <2956280567@qq.com> Date: 星期四, 17 七月 2025 17:31:18 +0800 Subject: [PATCH] 出库、绑定修改 --- wms/LocationHelper.cs | 655 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 583 insertions(+), 72 deletions(-) diff --git a/wms/LocationHelper.cs b/wms/LocationHelper.cs index 38141d3..ab8777d 100644 --- a/wms/LocationHelper.cs +++ b/wms/LocationHelper.cs @@ -1,9 +1,12 @@ 锘縰sing HH.WCS.ZhongCeJinTan; +using HH.WCS.ZhongCeJinTan.dispatch; using HH.WCS.ZhongCeJinTan.util; 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; @@ -14,6 +17,7 @@ using static HH.WCS.ZhongCeJinTan.api.ApiModel; using static HH.WCS.ZhongCeJinTan.util.Settings; using static HH.WCS.ZhongCeJinTan.wms.WcsModel; +using static ICSharpCode.SharpZipLib.Zip.ExtendedUnixData; namespace HH.WCS.ZhongCeJinTan.wms { @@ -85,19 +89,48 @@ } + /// <summary> /// 鑾峰彇璐т綅淇℃伅,鍙傛暟搴撳尯缂栧彿 /// </summary> 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 && s.C_ENABLE == "Y").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) { result.Add(item.S_CODE); } return result; + } + + /// <summary> + /// 鑾峰彇璐т綅淇℃伅,鍙傛暟搴撳尯缂栧彿 + /// </summary> + internal static List<string> GetConnectionListByN(string S_AREA_CODE) + { + var db = new SqlHelper<object>().GetInstance(); + var ConnectionList = db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE && s.C_ENABLE == "N").OrderBy(a => a.N_ROW).OrderBy(a => a.N_COL).ToList(); + List<string> result = new List<string>(); + foreach (var item in ConnectionList) + { + var ConnectionY = db.Queryable<Location>().Where(s => s.S_AREA_CODE == S_AREA_CODE && s.C_ENABLE == "Y" && s.CONNEC_ROADWAY== item.CONNEC_ROADWAY).First(); + if (ConnectionY==null) + { + 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> @@ -120,6 +153,36 @@ result.Add(re); } return result.OrderBy(a => a.taskCount).ToList(); + } + + /// <summary> + /// 杩斿洖鍑哄簱agv浠诲姟 + /// </summary> + internal static WMSTask GetConnectionTask(string jbLoc,string type) + { + var db = new SqlHelper<object>().GetInstance(); + + return db.Queryable<WMSTask>().Where(a => ( a.S_START_LOC.Contains(jbLoc)&& a.S_SCHEDULE_TYPE.Contains(type) && a.S_B_STATE != "瀹屾垚" && a.S_B_STATE != "鍙栨秷" && a.S_B_STATE != "澶辫触" && a.S_B_STATE != "宸插畬鎴� && a.S_B_STATE != "鏈墽琛�)).OrderBy(b=>b.T_CREATE).First(); + + } + + /// <summary> + /// 杩斿洖鎺ラ┏浣嶉泦鍚�+ /// </summary> + internal static List<Location> GetConnectionListByst(List<string> locList) + { + var db = new SqlHelper<object>().GetInstance(); + + List<Location> result = new List<Location>(); + + foreach (var item in locList) + { + + var con = LocationHelper.GetLoc(item); + + result.Add(con); + } + return result; } /// <summary> @@ -245,7 +308,282 @@ /// </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 + { + 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浠诲姟涓嬪彂"); + } + else + { + LogHelper.Info($"ZCSendTask鍏ュ簱浠诲姟{taskNo}涓嬪彂澶辫触锛屾帴椹充綅杩斿洖澶辫触", "Mes浠诲姟涓嬪彂"); + throw new Exception($"{taskNo}涓嬪彂澶辫触,鎺ラ┏浣嶈繑鍥炲け璐�); + } + + + + 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); + + 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浠诲姟涓嬪彂"); + } + else + { + LogHelper.Info($"ZCSendTask鍏ュ簱浠诲姟{taskNo}涓嬪彂澶辫触锛屾帴椹充綅杩斿洖澶辫触", "Mes浠诲姟涓嬪彂"); + throw new Exception($"{taskNo}涓嬪彂澶辫触,鎺ラ┏浣嶈繑鍥炲け璐�); + } + + + + 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; + } + } + return end; + } + catch (Exception) + { + + throw; + } + + } + + + /// <summary> + /// 鎵剧粓鐐瑰贩閬撳彲鐢ㄧ┖璐т綅闆嗗悎 鍧囪 + /// </summary> + /// <param name="locations"></param> + /// <returns></returns> + internal static List<Location> FindBalanceEndLocList(List<Location> locations, string endArea, string rodway = "") { try { @@ -270,9 +608,6 @@ 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(); @@ -287,8 +622,6 @@ flag = true; break; } - - } foreach (var item1 in xd) @@ -302,7 +635,7 @@ if (flag1 || flag) { - locations.RemoveAll(a => a.N_ROW == rows[i]); + locations.RemoveAll(a => a.N_ROW == rows[i]); } if (rowList.Count(a => a.N_CURRENT_NUM == 0) == 0) @@ -311,17 +644,12 @@ } } - var balanceLocList = RoadWayBalance(locations); + //瀵绘壘鍧囪 宸烽亾 + var balanceLocList = RoadWayBalance1(locations); - foreach (var item in balanceLocList) - { - if (item.S_LOCK_STATE=="鏃� && item.N_CURRENT_NUM==0) - { - end = item; - break; - } - } - return end; + + + return balanceLocList; } catch (Exception) { @@ -364,6 +692,127 @@ return location_roadray; } + /// <summary> + /// 宸烽亾鍧囪 绛栫暐 + /// </summary> + /// <param name="lstTrueLocation">鍙敤鐨勮揣浣嶄俊鎭暟鎹�/param> + /// <returns>璁$畻鍚庤繑鍥炵殑瀹炰綋</returns> + public static List<Location> RoadWayBalance1(List<Location> lstTrueLocation) + { + //鎸囧畾璁$畻鍚庤繑鍥炵殑瀹炰綋 + List<Location> location_roadray = new List<Location>(); + + //鎸夌収宸烽亾鍒嗙粍 骞惰幏寰楀贩閬撲腑鍙敤璐т綅鐨勬暟鎹�+ //涔嬪悗杩涜鍊掑彊 鎵惧埌鍙敤璐т綅鏈�鐨勫贩閬�+ var v = lstTrueLocation.GroupBy(x => x.N_ROADWAY).Select(g => (new + { + roadWay = g.Key, + qty = g.Count(p => p.S_LOCK_STATE == "鏃�) + })).OrderByDescending(o => o.qty); + + //鍊掑彊鎺掑垪鍚庣殑宸烽亾 寰幆 + foreach (var item in v) + { + //鍙栧緱宸烽亾鍒楄〃涓彲鐢ㄨ揣浣嶆渶澶氱殑宸烽亾 骞惰幏鍙栧贩閬撲腑鎵�湁璐т綅 + var loclist = lstTrueLocation.Where(o => o.N_ROADWAY == item.roadWay).OrderBy(b => b.N_ROW).OrderBy(b=>b.N_COL).ToList(); + + foreach (var item1 in loclist) + { + location_roadray.Add(item1); + } + } + return location_roadray; + } + + + /// <summary> + /// 鐗╂枡鍧囪 + /// </summary> + /// <param name="lstTrueLocation"></param> + /// <returns></returns> + public static List<Location> RoadWayBalance1ByItem(List<Location> lstTrueLocation, string itemCode) + { + var db = new SqlHelper<object>().GetInstance(); + + + //鎸囧畾璁$畻鍚庤繑鍥炵殑瀹炰綋 + List<Location> location_roadray = new List<Location>(); + + + List<connectionBalance> result = new List<connectionBalance>(); + + var newlstTrueLocation = lstTrueLocation.GroupBy(c => c.N_ROADWAY) + .Select(g => g.First()) // 鎴栬� g.FirstOrDefault() + .ToList(); + + foreach (var item in newlstTrueLocation) + { + var ConnectionList = 0; + + var loclist = lstTrueLocation.Where(o => o.N_ROADWAY == item.N_ROADWAY && o.N_CURRENT_NUM>0).OrderBy(b => b.N_ROW).OrderBy(b => b.N_COL).ToList(); + foreach (var item1 in loclist) + { + var tp = db.Queryable<LocCntrRel>().Where(s => s.S_LOC_CODE == item1.S_CODE).First(); + + // LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣璐т綅瀹瑰櫒淇℃伅" + JsonConvert.SerializeObject(tp), "Mes浠诲姟涓嬪彂"); + if (tp != null && item1.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) + { + ConnectionList += 1; + } + } + } + + var re = new connectionBalance(); + + var con = LocationHelper.GetLoc(item.S_CODE); + re.loc = con; + re.taskCount = ConnectionList; + result.Add(re); + } + + result = result.OrderBy(a=>a.taskCount).ToList(); + + foreach (var item in result) + { + 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); + } + } + + + return location_roadray; + } + + + + /// <summary> + /// 杩斿洖鍧囪 鐨勬帴椹充綅闆嗗悎 + /// </summary> + internal static List<connectionBalance> GetBalanceConnectionList3(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 != "澶辫触" && 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> /// 鎵剧粓鐐瑰彲鐢ㄧ┖璐т綅鎺掗櫎涓嶅彲鐢ㄥ贩閬�@@ -546,10 +995,17 @@ /// </summary> /// <param name="locations"></param> /// <returns></returns> - internal static Location FindStartcolByLoclistAndcntr(List<Location> locations,string startArea) { + internal static Location FindStartcolByLoclistAndcntr(List<Location> locations,string startArea, string CONNECTION = "") { var db = new SqlHelper<object>().GetInstance(); try { + + + var connectionList = LocationHelper.GetConnectionList(CONNECTION); + + + var balanceConnectionList = LocationHelper.GetConnectionListByst(connectionList); + Location start = null; var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList(); @@ -563,6 +1019,8 @@ var flag = false; + var flag2 = false; + foreach (var item in rowdwa) { if (rowList.Count(a => a.N_ROADWAY.ToString() == item.roadWay) > 0) @@ -572,7 +1030,17 @@ } } - if (flag) + foreach (var item2 in balanceConnectionList) + { + if (rowList.Count(a => a.N_ROADWAY != item2.CONNEC_ROADWAY) > 0) + { + flag2 = true; + break; + } + } + + + if (flag || flag2) { continue; } @@ -781,13 +1249,24 @@ /// </summary> /// <param name="locations"></param> /// <returns></returns> - internal static Location FindStartcolByLoclistAndItem(List<Location> locations,string itemCode,string endArea,string rodway="") + internal static Location FindStartcolByLoclistAndItem(List<Location> locations,string itemCode,string endArea,string rodway="",string CONNECTION="") { var db = new SqlHelper<object>().GetInstance(); try { Location start = null; var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList(); + + + var connectionList = LocationHelper.GetConnectionListByN(CONNECTION); + + + var balanceConnectionList = LocationHelper.GetConnectionListByst(connectionList); + + + + + LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟鎺掗櫎涓嶅彲鐢ㄥ贩閬撳紑濮�, "Mes浠诲姟涓嬪彂"); //浣滀笟娴佺▼鐨勫贩閬�@@ -802,7 +1281,7 @@ } else { - //鏌ユ壘鍙敤宸烽亾 + //鏌ユ壘涓嶅彲鐢ㄥ贩閬� rowdwa = db.Queryable<RoadWayEnable>().Where(x => x.areaCode == endArea && x.status == "0").ToList(); } @@ -811,7 +1290,7 @@ // LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟璧风偣搴撳尯{endArea}鎵句笉鍒板彲鐢ㄥ贩閬�, "Mes浠诲姟涓嬪彂"); // return null; //} - + for (int i = 0; i < rowsStart.Count; i++) { @@ -819,6 +1298,7 @@ var flag = false; var flag1 = false; + var flag2 = false; foreach (var item in rowdwa) { @@ -837,59 +1317,74 @@ } } - if (flag1 || flag) + foreach (var item2 in balanceConnectionList) { - locations.RemoveAll(a => a.N_ROW == rowsStart[i]); - } - - //rowList.Count(a => a.S_LOCK_STATE.Trim() != "鏃�) > 0 || - //褰撳墠鎺掓湁閿佸苟涓旀病鏈夋弧璐т綅锛屾帓闄�- if ( rowList.Count(a => a.N_CURRENT_NUM == 1) == 0) - { - locations.RemoveAll(a => a.N_ROW == rowsStart[i]); - } - } - - DateTime date = DateTime.Now; - List<CntrItemRel> startList = new List<CntrItemRel>(); ; - - LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟鎺掗櫎涓嶅彲鐢ㄥ贩閬撳畬鎴�, "Mes浠诲姟涓嬪彂"); - - 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) + if (rowList.Count(a => a.N_ROADWAY == item2.CONNEC_ROADWAY) > 0) { - LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣鍚堟牸瀹瑰櫒鐗╂枡锛屽鍣ㄥ彿{tp1.S_CNTR_CODE}", "Mes浠诲姟涓嬪彂"); - startList.Add(tp1); + flag2 = true; + break; } } - } - LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣鍚堟牸鐗╂枡鏁伴噺{startList.Count}", "Mes浠诲姟涓嬪彂"); - var startItem = startList.OrderBy(a => a.PRODUCTIONDATE).FirstOrDefault(); + if (flag1 || flag || flag2) + { + locations.RemoveAll(a => a.N_ROW == rowsStart[i]); + } - LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣鎸夌敓浜ф椂闂存帓搴忕墿鏂欎俊鎭� + JsonConvert.SerializeObject(startItem), "Mes浠诲姟涓嬪彂"); - if (startItem!=null) - { - + //rowList.Count(a => a.S_LOCK_STATE.Trim() != "鏃�) > 0 || + //褰撳墠鎺掓湁閿佸苟涓旀病鏈夋弧璐т綅锛屾帓闄�+ if (rowList.Count(a => a.N_CURRENT_NUM == 1) == 0) + { + locations.RemoveAll(a => a.N_ROW == rowsStart[i]); + } + } - 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浠诲姟涓嬪彂"); - } - return start; + DateTime date = DateTime.Now; + List<CntrItemRel> startList = new List<CntrItemRel>(); ; + + LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟鎺掗櫎涓嶅彲鐢ㄥ贩閬撳畬鎴�, "Mes浠诲姟涓嬪彂"); + + LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟鎺掗櫎瀹屾垚璐т綅鏁伴噺{locations.Count}", "Mes浠诲姟涓嬪彂"); + + 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) + { + LogHelper.Info($"ZCSendTask鍑哄簱浠诲姟涓嬪彂璧风偣鍚堟牸瀹瑰櫒鐗╂枡锛屽鍣ㄥ彿{tp1.S_CNTR_CODE}", "Mes浠诲姟涓嬪彂"); + startList.Add(tp1); + } + } + } + + + //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(); + + 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浠诲姟涓嬪彂"); + } + return start; } catch (Exception) { @@ -969,9 +1464,6 @@ for (int i = 0; i < rowsStart.Count; i++) { var rowList = locations.Where(r => r.N_ROW == rowsStart[i]).ToList().OrderByDescending(a => a.N_COL); - - - //rowList.Count(a => a.S_LOCK_STATE.Trim() != "鏃�) > 0 || //褰撳墠鎺掓湁閿佸苟涓旀病鏈夋弧璐т綅锛屾帓闄�@@ -1292,6 +1784,25 @@ } /// <summary> + /// 鑾峰彇寮傚父搴撳尯 + /// </summary> + /// <returns></returns> + internal static bool GetErroArea(string area) + { + var db = new SqlHelper<object>().GetInstance(); + var erroArea = db.Queryable<Area>().Where(a => a.S_NAME.Contains("寮傚父") && a.S_CODE.Contains(area)).First(); + + if (erroArea == null) + { + return false; + } + else { + return true; + } + } + + + /// <summary> /// 鍏ュ簱閿佸畾缁堢偣锛屽嚭搴撻攣瀹氳捣鐐� /// </summary> /// <param name="loc"></param> -- Gitblit v1.9.1