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;
@@ -136,27 +145,38 @@
        /// <param name="row">货位排</param>
        /// <param name="ItemCode">物料编码</param>
        /// <returns></returns>
        internal static List<Location> GetLocByItemCodeOrderyTime(string areaCode, string ItemCode)
        internal static Location GetLocByItemCodeOrderyTime(string areaCode, string ItemCode, string soure = "1")
        {
            List<Location> locs;
            Location loc = null;
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                locs = 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
                    && c.S_ITEM_CODE == ItemCode && a.N_LOCK_STATE == 0)
                   .GroupBy((a, b, c) => new { a.S_CODE, c.T_INBOUND_TIME ,a.N_POS })
                   .OrderBy((a, b, c) => c.T_INBOUND_TIME)
                   .OrderByDescending((a, b, c) => a.N_POS)
                   .ToList();
                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 locs;
                return loc;
            }
            catch (Exception ex)
            {
@@ -173,7 +193,7 @@
        /// <param name="row">货位排</param>
        /// <param name="ItemCode">物料编码</param>
        /// <returns></returns>
        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, int[] row)
        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, int pos)
        {
            List<Location> locs;
            var db = new SqlHelper<object>().GetInstance();
@@ -182,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 && a.N_LOCK_STATE == 0);
                   .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();
@@ -582,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;
@@ -619,6 +640,7 @@
                        count++;
                    }
                });
                location.N_CURRENT_NUM = lcrList.Count + count;
                location.N_LOCK_STATE = 0;
                location.S_LOCK_STATE = "无";