海波 张
2025-05-22 9ad3666d15deccc40a2aa4d1b96950c78eaf165f
wms/LocationHelper.cs
@@ -10,6 +10,7 @@
using System.Text;
using System.Threading.Tasks;
using Top.Api;
using WebSocketSharp.Frame;
using static HH.WCS.ZhongCeJinTan.api.ApiModel;
using static HH.WCS.ZhongCeJinTan.util.Settings;
using static HH.WCS.ZhongCeJinTan.wms.WcsModel;
@@ -23,15 +24,15 @@
        static LocationHelper() {
            //初始化location加入到字典缓存
            locations = new Dictionary<string, Location>();
            var list = GetAllLocList();
            if (list.Count > 0) {
                list.ForEach(a => {
                    if (!locations.ContainsKey(a.S_CODE)) {
                        locations.Add(a.S_CODE, a);
                    }
                });
            }
            //locations = new Dictionary<string, Location>();
            //var list = GetAllLocList();
            //if (list.Count > 0) {
            //    list.ForEach(a => {
            //        if (!locations.ContainsKey(a.S_CODE)) {
            //            locations.Add(a.S_CODE, a);
            //        }
            //    });
            //}
            //初始化locationExt加入到集合缓存
            //locationExts = new Dictionary<string, LocationExt>();
            //var exts = GetAllLocExtList();
@@ -121,8 +122,8 @@
            return result.OrderBy(a => a.taskCount).ToList();
        }
        /// <summary>
        /// 找终点巷道可用空货位
@@ -300,9 +301,9 @@
                    }
                }
                var balanceLocList = RoadWayBalance(locations);
                foreach (var item in locations)
                foreach (var item in balanceLocList)
                {
                    if (item.S_LOCK_STATE=="无" && item.N_CURRENT_NUM==0)
                    {
@@ -319,6 +320,40 @@
            }
        }
        /// <summary>
        /// 巷道均衡策略
        /// </summary>
        /// <param name="lstTrueLocation">可用的货位信息数据</param>
        /// <returns>计算后返回的实体</returns>
        public static List<Location> RoadWayBalance(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)
            {
                //取得巷道列表中可用货位最多的巷道  并获取巷道中所有货位
                location_roadray = lstTrueLocation.Where(o => o.N_ROADWAY == item.roadWay).ToList();
                if (location_roadray != null && location_roadray.Count > 0)
                {
                    break;
                }
            }
            return location_roadray;
        }
        /// <summary>
        /// 找终点可用空货位排除不可用巷道
@@ -1506,5 +1541,34 @@
            }
            return res;
        }
        /// <summary>
        /// 获取逻辑库区货位
        /// </summary>
        /// <param name="zoneCode"></param>
        /// <returns></returns>
        public static List<Location> GetZoneLoc(string zoneCode) {
            var db = new SqlHelper<object>().GetInstance();
            LogHelper.Info($"ZCSendTask入库任务寻找逻辑库区参数{zoneCode}", "Mes任务下发");
            var zones = db.Queryable<Zone>().Where(a => a.S_ZONE_CLS_CODE == zoneCode).ToList();
            LogHelper.Info($"ZCSendTask入库任务寻找逻辑库区信息" +JsonConvert.SerializeObject(zones), "Mes任务下发");
            var locList = new List<Location>();
            foreach (var item in zones)
            {
                var locations = db.Queryable<ZoneLoc>().Includes(t => t.Loc).Where(a => a.S_ZONE_CODE == item.S_CODE).ToList();
                foreach (var item1 in locations)
                {
                    locList.Add(item1.Loc);
                }
            }
            LogHelper.Info($"ZCSendTask入库任务寻找逻辑货位数量信息{locList.Count}", "Mes任务下发");
            return locList.OrderBy(a => a.N_ROW).OrderBy(a => a.N_COL).ToList(); ;
        }
    }
}