From cd195e83605f60ac51db6e0b4f0fcaeeb200768d Mon Sep 17 00:00:00 2001 From: Tjiny <Tjinyu23@163.com> Date: 星期五, 23 五月 2025 17:21:31 +0800 Subject: [PATCH] 海成入库货位分配逻辑开发 --- HH.WCS.Mobox3.HaiCheng/Util/Helper/AdoSqlHelper.cs | 288 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 251 insertions(+), 37 deletions(-) diff --git a/HH.WCS.Mobox3.HaiCheng/Util/Helper/AdoSqlHelper.cs b/HH.WCS.Mobox3.HaiCheng/Util/Helper/AdoSqlHelper.cs index c58034c..7d91874 100644 --- a/HH.WCS.Mobox3.HaiCheng/Util/Helper/AdoSqlHelper.cs +++ b/HH.WCS.Mobox3.HaiCheng/Util/Helper/AdoSqlHelper.cs @@ -1,6 +1,9 @@ 锘縰sing System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; +using HH.WCS.Mobox3.Template.Entity; +using SqlSugar; namespace HH.WCS.Mobox3.Template.Util.Helper { @@ -14,14 +17,14 @@ /// </summary> /// <param name="condition">鏉′欢</param> /// <returns></returns> - public static T QueryFirst(Expression<Func<T,bool>> condition) + public static T QueryFirst(Expression<Func<T, bool>> condition) { var db = new SqlHelper<object>().GetInstance(); - + // 杩斿洖鏁版嵁 return db.Queryable<T>().First(condition); } - + /// <summary> /// 鏍规嵁鏉′欢鏌ヨ澶氭潯鏁版嵁 /// </summary> @@ -29,7 +32,7 @@ public static List<T> QueryList(Expression<Func<T, bool>> condition) { var db = new SqlHelper<object>().GetInstance(); - + // 杩斿洖鏁版嵁 return db.Queryable<T>().Where(condition).ToList(); } @@ -39,11 +42,34 @@ /// </summary> /// <param name="condition">鏉′欢</param> /// <returns></returns> - public static int QueryCount(Expression<Func<T,bool>> condition) + public static int QueryCount(Expression<Func<T, bool>> condition) { var db = new SqlHelper<object>().GetInstance(); + // 杩斿洖鏁版嵁 return db.Queryable<T>().Count(condition); + } + + /// <summary> + /// 鏍规嵁鏉′欢淇敼涓�潯鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="model">闇�杩涜淇敼鐨勫璞�/param> + /// <param name="condition">淇敼鏉′欢</param> + /// <returns></returns> + public static bool UpdateFirstTran(SqlSugarClient sqlSugarClient, T model, Expression<Func<T, object>> condition) + { + // 淇敼鏁版嵁 + var executeCommand = sqlSugarClient.Updateable(model).UpdateColumns(condition).ExecuteCommand(); + + if (executeCommand > 0) + { + return true; + } + else + { + return false; + } } /// <summary> @@ -54,17 +80,56 @@ /// <returns></returns> public static bool UpdateFirst(T model, Expression<Func<T, object>> condition) { - var db = new SqlHelper<object>().GetInstance(); - + var sqlSugarClient = new SqlHelper<object>().GetInstance(); + // 淇敼鏁版嵁 - var executeCommand = db.Updateable(model).UpdateColumns(condition).ExecuteCommand(); + var executeCommand = sqlSugarClient.Updateable(model).UpdateColumns(condition).ExecuteCommand(); if (executeCommand > 0) { return true; } else + { return false; + } + } + + /// <summary> + /// 鏍规嵁鏉′欢淇敼涓�潯鏁版嵁鐨勭姸鎬�sql璇彞) + /// </summary> + /// <param name="model">闇�杩涜淇敼鐨勫璞�/param> + /// <param name="sql">淇敼鏉′欢</param> + /// <returns></returns> + public static bool UpdateFirstOutBoundStart(T model, string sql) + { + var sqlSugarClient = new SqlHelper<object>().GetInstance(); + + // 淇敼鏁版嵁 + var executeCommand = sqlSugarClient.Ado.ExecuteCommand(sql, model); + + if (executeCommand > 0) + { + return true; + } + else + { + return false; + } + } + + /// <summary> + /// 鏍规嵁鏉′欢淇敼澶氭潯鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="models"></param> + /// <param name="condition"></param> + /// <returns></returns> + public static int UpdateListTran(SqlSugarClient sqlSugarClient, List<T> models, + Expression<Func<T, object>> condition) + { + // 淇敼鏁版嵁 + return sqlSugarClient.Updateable(models).UpdateColumns(condition).ExecuteCommand(); } /// <summary> @@ -75,84 +140,168 @@ /// <returns></returns> public static int UpdateList(List<T> models, Expression<Func<T, object>> condition) { - var db = new SqlHelper<object>().GetInstance(); - + var sqlSugarClient = new SqlHelper<object>().GetInstance(); // 淇敼鏁版嵁 - return db.Updateable(models).UpdateColumns(condition).ExecuteCommand(); + return sqlSugarClient.Updateable(models).UpdateColumns(condition).ExecuteCommand(); } /// <summary> - /// 鏂板涓�潯鏁版嵁 + /// 鏂板涓�潯鏁版嵁锛堜簨鍔★級 /// </summary> - /// <param name="model"></param> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="model">闇�鏂板鐨勬暟鎹�/param> + /// <returns></returns> + public static bool AddFirstTran(SqlSugarClient sqlSugarClient, T model) + { + var executeCommand = sqlSugarClient.Insertable(model).ExecuteCommand(); + + if (executeCommand > 0) + { + return true; + } + else + { + return false; + } + } + + /// <summary> + /// 鏂板涓�潯鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="model">闇�鏂板鐨勬暟鎹�/param> /// <returns></returns> public static bool AddFirst(T model) { - var db = new SqlHelper<object>().GetInstance(); + var sqlSugarClient = new SqlHelper<object>().GetInstance(); - var executeCommand = db.Insertable(model).ExecuteCommand(); - + var executeCommand = sqlSugarClient.Insertable(model).ExecuteCommand(); + if (executeCommand > 0) + { return true; + } else + { return false; + } } - + + + /// <summary> + /// 鏂板澶氭潯鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="models">闇�鏂板鐨勬暟鎹泦鍚�/param> + /// <returns></returns> + public static int AddListTran(SqlSugarClient sqlSugarClient, List<T> models) + { + return sqlSugarClient.Insertable(models).ExecuteCommand(); + } + /// <summary> /// 鏂板澶氭潯鏁版嵁 /// </summary> - /// <param name="models"></param> + /// <param name="models">闇�鏂板鐨勬暟鎹泦鍚�/param> /// <returns></returns> public static int AddList(List<T> models) { - var db = new SqlHelper<object>().GetInstance(); - - var executeCommand = db.Insertable(models).ExecuteCommand(); - - return executeCommand; + var sqlSugarClient = new SqlHelper<object>().GetInstance(); + return sqlSugarClient.Insertable(models).ExecuteCommand(); } - + /// <summary> - /// 鍒犻櫎涓�潯鏁版嵁 + /// 鍒犻櫎涓�潯鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="model">闇�鍒犻櫎鐨勫璞�/param> + /// <returns></returns> + public static bool DeleteFirstTran(SqlSugarClient sqlSugarClient, T model) + { + var executeCommand = sqlSugarClient.Deleteable(model).ExecuteCommand(); + + if (executeCommand > 0) + { + return true; + } + else + { + return false; + } + } + + /// <summary> + /// 鍒犻櫎涓�潯鏁版嵁锛堜簨鍔★級 /// </summary> /// <param name="model">闇�鍒犻櫎鐨勫璞�/param> /// <returns></returns> public static bool DeleteFirst(T model) { - var db = new SqlHelper<object>().GetInstance(); + var sqlSugarClient = new SqlHelper<object>().GetInstance(); - var executeCommand = db.Deleteable(model).ExecuteCommand(); + var executeCommand = sqlSugarClient.Deleteable(model).ExecuteCommand(); if (executeCommand > 0) + { return true; + } else + { return false; + } } - + /// <summary> - /// 鍒犻櫎澶氭潯鏁版嵁 + /// 鍒犻櫎澶氭潯鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="models">闇�鍒犻櫎鐨勫璞¢泦鍚�/param> + /// <returns></returns> + public static int DeleteListTran(SqlSugarClient sqlSugarClient, List<T> models) + { + return sqlSugarClient.Deleteable(models).ExecuteCommand(); + } + + /// <summary> + /// 鍒犻櫎澶氭潯鏁版嵁锛堜簨鍔★級 /// </summary> /// <param name="models">闇�鍒犻櫎鐨勫璞¢泦鍚�/param> /// <returns></returns> public static int DeleteList(List<T> models) { - var db = new SqlHelper<object>().GetInstance(); - - return db.Deleteable(models).ExecuteCommand(); + var sqlSugarClient = new SqlHelper<object>().GetInstance(); + return sqlSugarClient.Deleteable(models).ExecuteCommand(); } - + /// <summary> - /// 鏍规嵁鏉′欢鍒犻櫎鏁版嵁 + /// 鏍规嵁鏉′欢鍒犻櫎鏁版嵁锛堜簨鍔★級 + /// </summary> + /// <param name="sqlSugarClient">鏁版嵁搴撲笂涓嬫枃杩炴帴</param> + /// <param name="condition">鏉′欢</param> + /// <returns></returns> + public static int DeleteListTran(SqlSugarClient sqlSugarClient, Expression<Func<T, bool>> condition) + { + return sqlSugarClient.Deleteable<T>().Where(condition).ExecuteCommand(); + } + + /// <summary> + /// 鏍规嵁鏉′欢鍒犻櫎鏁版嵁锛堜簨鍔★級 /// </summary> /// <param name="condition">鏉′欢</param> /// <returns></returns> public static int DeleteList(Expression<Func<T, bool>> condition) { - var db = new SqlHelper<object>().GetInstance(); - - return db.Deleteable<T>().Where(condition).ExecuteCommand(); + var sqlSugarClient = new SqlHelper<object>().GetInstance(); + return sqlSugarClient.Deleteable<T>().Where(condition).ExecuteCommand(); } + /// <summary> + /// 鑾峰彇鏁版嵁搴撲笂涓嬫枃杩炴帴 + /// </summary> + /// <returns></returns> + public static SqlSugarClient QuerySqlSugarClient() + { + return new SqlHelper<object>().GetInstance(); + } /// <summary> /// 鎸夌収鏃堕棿鍊掑簭鏌ヨ @@ -167,5 +316,70 @@ // 杩斿洖鏁版嵁 return db.Queryable<T>().OrderByDescending(orderBy).First(condition); } + + + #region 鐗瑰畾鏌ヨ + + /// <summary> + /// 鍒嗛厤鍏ュ簱璐т綅 + /// </summary> + /// <returns></returns> + public static Location QueryInputLocation(string itemCode) + { + var areaCodeList = new List<string> + { + "1","2","3","4" + }; + + var db = new SqlHelper<object>().GetInstance(); + + var listMaxCol = db.Queryable<Location>() + .LeftJoin<LocCntrRel>((l, lc) => l.S_CODE == lc.S_LOC_CODE) + .LeftJoin<CntrItemDetail>((l, lc, ci) => lc.S_CNTR_CODE == ci.S_CNTR_CODE) + .Where((l, lc, ci) => l.N_CURRENT_NUM > 0 + && areaCodeList.Contains(l.S_GROUP) + && ci.S_ITEM_CODE == itemCode) + .OrderByDescending((l, lc, ci) => l.N_COL) + .Take(1) + .PartitionBy((l, lc, ci) => new { l.S_GROUP, l.N_ROW }) + .ToList(); + + + // 鏈夊悓绉嶇墿鏂欐墍鍗犳嵁鐨勬帓 + if (listMaxCol.Count > 0) + { + foreach (var item in listMaxCol) + { + //鎺掓湁閿佷篃鎺掗櫎锛堥攣琛ㄧず鍚庨潰鍙兘瑕佹敼锛�+ if (db.Queryable<Location>().Count(a => + a.S_GROUP == item.S_GROUP && a.N_ROW == item.N_ROW && a.N_LOCK_STATE != 0) > 0) + { + continue; + } + + // 娌¢攣 + var end = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => + a.S_GROUP == item.S_GROUP && a.N_ROW == item.N_ROW && + a.N_CURRENT_NUM == 0 && + a.N_COL >= item.N_COL).First(); + + if (end != null) + { + return end; + } + } + } + + Location location = db.Queryable<Location>().OrderBy(a => a.S_GROUP).First(p => p.N_COL == 1 && p.N_LOCK_STATE == 0); + + if (location != null) + { + return location; + } + + return null; + } + + #endregion } } \ No newline at end of file -- Gitblit v1.9.1