海波 张
2025-05-19 a99ceecce8c9a2521ac1fc167f4eff764cbdb123
wms/LocationHelper.cs
@@ -1,6 +1,7 @@
using HH.WCS.ZhongCeJinTan;
using HH.WCS.ZhongCeJinTan.util;
using HH.WCS.ZhongCeJinTan.wms;
using Microsoft.Owin;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -8,6 +9,8 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Top.Api;
using static HH.WCS.ZhongCeJinTan.api.ApiModel;
using static HH.WCS.ZhongCeJinTan.util.Settings;
using static HH.WCS.ZhongCeJinTan.wms.WcsModel;
@@ -95,6 +98,31 @@
            }
            return result;
        }
        /// <summary>
        /// 返回均衡的接驳位集合
        /// </summary>
        internal static List<connectionBalance> GetBalanceConnectionList(List<string> locList)
        {
            var db = new SqlHelper<object>().GetInstance();
            List<connectionBalance> result = new List<connectionBalance>();
            foreach (var item in locList)
            {
                var ConnectionList = 0;
                ConnectionList = db.Queryable<WMSTask>().Where(a => (a.S_END_LOC.Contains(item) || a.S_START_LOC.Contains(item)) && a.S_B_STATE != "完成" && a.S_B_STATE != "取消" && a.S_B_STATE != "错误").ToList().Count();
                var re = new connectionBalance();
                var con = LocationHelper.GetLoc(item);
                re.loc = con;
                re.taskCount = ConnectionList;
                result.Add(re);
            }
            return result.OrderBy(a => a.taskCount).ToList();
        }
        /// <summary>
        /// 找终点巷道可用空货位
@@ -200,6 +228,97 @@
        }
        /// <summary>
        /// 找终点巷道可用空货位 均衡
        /// </summary>
        /// <param name="locations"></param>
        /// <returns></returns>
        internal static Location FindBalanceEndcolByLocList(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]);
                    }
                }
                foreach (var item in locations)
                {
                    if (item.S_LOCK_STATE=="无" && item.N_CURRENT_NUM==0)
                    {
                        end = item;
                        break;
                    }
                }
                return end;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 找终点可用空货位排除不可用巷道
@@ -389,7 +508,7 @@
                Location start = null;
                var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
                //查找可用巷道
                //查找不可用巷道
                var rowdwa = db.Queryable<RoadWayEnable>().Where(x => x.areaCode == startArea && x.status == "0").ToList();
                for (int i = 0; i < rowsStart.Count; i++)
@@ -447,6 +566,50 @@
                throw;
            }
        }
        /// <summary>
        /// 根据起点立库区找空托 校验库存
        /// </summary>
        /// <param name="locations"></param>
        /// <returns></returns>
        internal static bool FindStartcolByLoclistAndcntrFlag(List<Location> locations, string startArea)
        {
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                var start = false;
                var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
                foreach (var item in locations)
                {
                    if (item.N_CURRENT_NUM == 0)
                    {
                        continue;
                    }
                    var tp = db.Queryable<LocCntrRel>().Where(s => s.S_LOC_CODE == item.S_CODE).First();
                    if (tp != null && item.S_LOCK_STATE == "无")
                    {
                        var tp1 = db.Queryable<Container>().Where(s => s.S_CODE == tp.S_CNTR_CODE).First();
                        if (tp1 != null && tp1.N_DETAIL_COUNT == 0)
                        {
                            return true;
                        }
                    }
                }
                return start;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 根据起点货架区找空托
@@ -675,6 +838,8 @@
                LogHelper.Info($"ZCSendTask出库任务下发起点按生产时间排序物料信息" + JsonConvert.SerializeObject(startItem), "Mes任务下发");
                if (startItem!=null)
                {
                    var tp = db.Queryable<LocCntrRel>().Where(s => s.S_CNTR_CODE == startItem.S_CNTR_CODE).First();
                    start = LocationHelper.GetLocOne(tp.S_LOC_CODE);
                    LogHelper.Info($"ZCSendTask出库任务下发起点货位信息" + JsonConvert.SerializeObject(start), "Mes任务下发");
@@ -686,9 +851,60 @@
                throw;
            }
        }
        /// <summary>
        /// 根据物料编码找立库区起点满货位 校验有库存但是设备报警
        /// </summary>
        /// <param name="locations"></param>
        /// <returns></returns>
        internal static bool FindStartcolByLoclistAndItemFlag(List<Location> locations, string itemCode, string endArea)
        {
            var db = new SqlHelper<object>().GetInstance();
            var res = false;
            try
            {
                var rowsStart = locations.Select(a => a.N_ROW).Distinct().ToList();
                DateTime date = DateTime.Now;
                List<CntrItemRel> startList = new List<CntrItemRel>(); ;
                foreach (var item in locations)
                {
                    if (item.N_CURRENT_NUM == 0)
                    {
                        continue;
                    }
                    var tp = db.Queryable<LocCntrRel>().Where(s => s.S_LOC_CODE == item.S_CODE).First();
                   // LogHelper.Info($"ZCSendTask出库任务下发起点货位容器信息" + JsonConvert.SerializeObject(tp), "Mes任务下发");
                    if (tp != null && item.S_LOCK_STATE == "无")
                    {
                        var tp1 = db.Queryable<CntrItemRel>().Where(s => s.S_CNTR_CODE == tp.S_CNTR_CODE).First();
                        //LogHelper.Info($"ZCSendTask出库任务下发起点容器物料信息" + JsonConvert.SerializeObject(tp1), "Mes任务下发");
                        if (tp1 != null && tp1.S_ITEM_CODE == itemCode && tp1.S_ITEM_STATE == "合格" && tp1.takeEffectTime < date && tp1.expireTime > date)
                        {
                            res = true;
                            return res;
                        }
                    }
                }
                return res;
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// 根据物料编码找货架区起点满货位
        /// </summary>