lss
2025-06-13 1285aeec470dfa1b953878a714e3bc58bba83dec
HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/wms/LocationHelper.cs
@@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static HH.WCS.JiaTong.dispatch.NDC;
@@ -201,6 +202,7 @@
        "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
        "U", "V", "W", "X", "Y", "Z"
    };
        /// <summary>
        /// 根据物料找托盘
        /// </summary>
@@ -210,7 +212,10 @@
        /// <returns></returns>
        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, string lev)
        {
            List<Location> locs;
            var db = new SqlHelper<object>().GetInstance();
            var queryable = db.Queryable<Location>()
      .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE)
@@ -242,7 +247,7 @@
            {
                locs = queryable.Where((a, b, c) => c.LEV == lev && c.S_BS_TYPE == "余料").ToList();
            }
            LogHelper.Info($"GetLocByItemCode=>查找余料,{JsonConvert.SerializeObject(locs)}");
            //   LogHelper.Info($"GetLocByItemCode=>查找余料,{JsonConvert.SerializeObject(locs)}");
            //没有余料则寻找全部物料
            if (locs.Count == 0)
@@ -282,21 +287,34 @@
        /// 根据库区获取空托
        /// </summary>
        /// <param name="areaCode">库区编码</param>
        /// <param name="lev">物料等级</param>
        /// <param name="ItemCode">物料编码</param>
        /// <returns></returns>
        internal static Location GetLocByAreacode(string areaCode)
        internal static Location GetLocByAreacode(string areaCode, string type)
        {
            Location loc = new Location();
            var db = new SqlHelper<object>().GetInstance();
            string CntrCodeWith = "";
            if (type.Trim().Contains("MA"))
            {
                CntrCodeWith = "MA";
            }
            else if (type.Trim().Contains("NA"))
            {
                CntrCodeWith = "NA";
            }
            if (CntrCodeWith == "")
            {
                LogHelper.Info($"托盘类型{type}不在规定范围");
            }
            var query = db.Queryable<Location>()
       .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE)
       .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE)
       .Where((a, b, c) => a.S_AREA_CODE == areaCode && a.N_CURRENT_NUM == 1
                       && a.N_LOCK_STATE == 0
                       && b.S_CNTR_CODE != null
                       );
   .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE)
   .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE)
   .Where((a, b, c) => a.S_AREA_CODE == areaCode && a.N_CURRENT_NUM == 1
                   && a.N_LOCK_STATE == 0
                   && b.S_CNTR_CODE != null && b.S_CNTR_CODE.Contains(CntrCodeWith) && c.S_ITEM_CODE == null
                   );
            loc = query.First();
            return loc;
        }
@@ -546,7 +564,11 @@
                }
                else
                {
                    LogHelper.Info($"锁定货位{loc}成功");
                    LogHelper.Info($"锁定货位{loc}失败,重新锁");
                    Task.Run(() =>
                    {
                        LockLoc(loc, lockState);
                    });
                }
                return res;
            }
@@ -599,16 +621,32 @@
            {
                db.BeginTran();
                var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList();
                //if (!string.IsNullOrEmpty(location.S_NOTE) && lcrList.Count > 0)
                //{
                //    if (location.S_NOTE == "叠盘" || location.S_NOTE.Trim() == "片胶堆叠位")
                //    {
                //        LogHelper.Info("叠盘货位删除托盘");
                //        cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList();
                //    }
                //}
                if (lcrList.Count > 0)
                {
                    cntrs = lcrList.Select(a => a.S_CNTR_CODE).ToList();
                }
                LogHelper.Info($"BindingLoc:开始解绑容器:{cntrs}");
                var count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE.Trim()) && it.S_LOC_CODE.Trim() == loc).ExecuteCommand();
                location.N_CURRENT_NUM = lcrList.Count - count;
                location.S_LOCK_STATE = "无";
                location.N_LOCK_STATE = 0;
                db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE, it.N_LOCK_STATE }).ExecuteCommand();
                LogHelper.Info($"BindingLoc:解绑容器:{cntrs},成功");
                db.CommitTran();
                res = true;
            }
            catch (Exception ex)
            {
                LogHelper.Info($"BindingLoc Error:{ex}");
                db.RollbackTran();
            }
            return res;