海波 张
2025-06-28 f80938e8a03d9343672b4fb3179836b019f6b9d8
wms/LocationHelper.cs
@@ -1,4 +1,5 @@
using HH.WCS.ZhongCeJinTan;
using HH.WCS.ZhongCeJinTan.dispatch;
using HH.WCS.ZhongCeJinTan.util;
using HH.WCS.ZhongCeJinTan.wms;
using Microsoft.Owin;
@@ -85,6 +86,7 @@
        }
        /// <summary>
        /// 获取货位信息,参数库区编号
        /// </summary>
@@ -120,6 +122,25 @@
                result.Add(re);
            }
            return result.OrderBy(a => a.taskCount).ToList();
        }
        /// <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>
@@ -333,6 +354,88 @@
        /// <summary>
        /// 找终点巷道可用空货位集合 均衡
        /// </summary>
        /// <param name="locations"></param>
        /// <returns></returns>
        internal static List<Location> FindBalanceEndLocList(List<Location> locations, string endArea, string rodway = "")
        {
            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>();
                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;
                    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;
                        }
                    }
                    if (flag1 || flag)
                    {
                        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 = RoadWayBalance1(locations);
                return balanceLocList;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 巷道均衡策略
        /// </summary>
        /// <param name="lstTrueLocation">可用的货位信息数据</param>
@@ -364,6 +467,38 @@
            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>
        /// 找终点可用空货位排除不可用巷道