lss
3 天以前 17e3ef45fe0a6b6f8a147b50740834ac734f9317
HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/wms/LocationHelper.cs
@@ -5,6 +5,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HH.WCS.DaYang.wms.WMSHelper.AddChangeModel;
namespace HH.WCS.DaYang.wms
{
@@ -56,31 +57,33 @@
        /// <summary>
        /// 入库算法
        /// </summary>
        /// <param name="loc">入库起点</param>
        /// <param name="itemCode">物料编码</param>
        /// <returns></returns>
        public static Location InStorage(Location loc)
        public static Location InStorage(string itemCode)
        {
            var db = new SqlHelper<object>().GetInstance();
            Location location = null;
            List<Location> list = Locations.Values.ToList();
            string itemCode = "";
            string areaCode = "";
            string areaCode = "YCLLKQ";
            try
            {
                //根据起点获取托盘和托盘物料绑定关系
                var cntrLoc = LocationHelper.GetLocCntr(loc.S_CODE).FirstOrDefault();
                if (cntrLoc != null)
                {
                    //获取托盘物料绑定关系
                    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == cntrLoc.S_CNTR_CODE).First();
                    if (cntrItem != null)
                    {
                        itemCode = cntrItem.S_ITEM_CODE;
                    }
                }
                ////根据起点获取托盘和托盘物料绑定关系
                /// //string itemCode = "";
                //var cntrLoc = LocationHelper.GetLocCntr(loc.S_CODE).FirstOrDefault();
                //if (cntrLoc != null)
                //{
                //    //获取托盘物料绑定关系
                //    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == cntrLoc.S_CNTR_CODE).First();
                //    if (cntrItem != null)
                //    {
                //        itemCode = cntrItem.S_ITEM_CODE;
                //    }
                //}
                //托盘入库,相同物料内测排的货位
                var Locs = GetLocByItemCode(areaCode, itemCode, new int[] { 1, 4 }).OrderByDescending(b => b.N_COL).ToList();
                var Locs = GetLocByItemCode(areaCode, itemCode, 1).OrderByDescending(b => b.N_COL).ToList();
                if (Locs.Count > 0)
                {
@@ -97,9 +100,15 @@
                            case 4:
                                row = 3;
                                break;
                            case 5:
                                row = 6;
                                break;
                            case 8:
                                row = 7;
                                break;
                        }
                        //寻找外侧货位
                        var OutLoc = db.Queryable<Location>().Where(a => a.S_AREA_CODE == Locs[i].S_AREA_CODE && a.N_LAYER == Locs[i].N_LAYER && a.N_ROW == row && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
                        var OutLoc = db.Queryable<Location>().Where(a => a.S_AREA_CODE == Locs[i].S_AREA_CODE && a.N_LAYER == Locs[i].N_LAYER && a.N_ROW == row && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.N_ROADWAY == Locs[i].N_ROADWAY).First();
                        if (OutLoc != null)
                        {
                            location = OutLoc;
@@ -127,18 +136,64 @@
        }
        #endregion
        /// <summary>
        /// 根据物料获得对应的内测货位
        /// 根据物料和排号获得对应的未锁定托盘货位
        /// </summary>
        /// <param name="areaCode">库区编码</param>
        /// <param name="row">货位排</param>
        /// <param name="ItemCode">物料编码</param>
        /// <returns></returns>
        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, int[] row)
        internal static Location GetLocByItemCodeOrderyTime(string areaCode, string ItemCode, string soure = "1")
        {
            Location loc = null;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                var loc1 = 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)
                    .LeftJoin<Container>((a, b, c, d) => d.S_CODE == c.S_CNTR_CODE)
                    .Where((a, b, c, d) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode
                     && c.S_ITEM_CODE == ItemCode && d.S_SOURCE == soure)
                    .GroupBy((a, b, c) => new { a.S_CODE, c.T_INBOUND_TIME, a.N_POS, a.N_COL })
                    .OrderBy((a, b, c) => c.T_INBOUND_TIME)
                    .OrderByDescending((a, b, c) => a.N_POS)
                    .OrderBy((a, b, c) => a.N_COL)
                    .Select((a, b, c) => new
                    {
                        S_CODE = a.S_CODE,
                        T_INBOUND_TIME = c.T_INBOUND_TIME,
                        N_POS = a.N_POS
                    })
                    .ToList();
                // var LocCodes = loc1.Select(a => a.S_CODE).First();
                if (loc1.Count > 0)
                {
                    loc = db.Queryable<Location>().Where(a => a.S_CODE == loc1.First().S_CODE).First();
                }
                return loc;
            }
            catch (Exception ex)
            {
                LogHelper.Info($"GetLocByItemCode Error:{ex}");
                throw;
            }
        }
        /// <summary>
        /// 根据物料和排号获得对应的未锁定托盘货位,并按托盘物料表时间分组
        /// </summary>
        /// <param name="areaCode">库区编码</param>
        /// <param name="row">货位排</param>
        /// <param name="ItemCode">物料编码</param>
        /// <returns></returns>
        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, int pos)
        {
            List<Location> locs;
            var db = new SqlHelper<object>().GetInstance();
@@ -147,7 +202,7 @@
                var queryable = 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.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode && row.Contains(a.N_ROW) && c.S_ITEM_CODE == ItemCode);
                   .Where((a, b, c) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode && a.N_POS == pos && c.S_ITEM_CODE == ItemCode && a.N_LOCK_STATE == 0);
                locs = queryable.ToList();
@@ -171,6 +226,7 @@
        {
            var db = new SqlHelper<object>().GetInstance();
            Location location = null;
            try
            {
                //判断当前排可用货位小于2 如果小于2则不允许入
@@ -332,7 +388,7 @@
            return result;
        }
        /// <summary>
        /// 根据货位集合获取有容器的货位
        /// </summary>
@@ -470,6 +526,7 @@
                model.S_LOCK_STATE = Location.GetLockStateStr(lockState);
                res = db.Updateable(model).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE }).ExecuteCommand() > 0;
            }
            return res;
        }
@@ -545,6 +602,7 @@
                db.BeginTran();
                var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loc).ToList();
                var count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE) && it.S_LOC_CODE == loc).ExecuteCommand();
                location.N_CURRENT_NUM = lcrList.Count - count;
                location.S_LOCK_STATE = "无";
                location.N_LOCK_STATE = 0;
@@ -582,6 +640,7 @@
                        count++;
                    }
                });
                location.N_CURRENT_NUM = lcrList.Count + count;
                location.N_LOCK_STATE = 0;
                location.S_LOCK_STATE = "无";