lss
2025-06-27 b75456f72aabf3efa9a1c696ef2a66c6445016a5
HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -118,8 +118,8 @@
                #endregion
                Location endloc = new Location();
                Location startloc = new Location();
                Location endloc = null;
                Location startloc = null;
                lock (_lockCreateTask)
                {
                    if (taskData.taskType == 1) //出库流程,通过物料机台计算线边货位
@@ -770,6 +770,7 @@
        }
        public static object _Putin = new object();
        /// <summary>
        /// 入平库
        /// </summary>
@@ -799,7 +800,8 @@
            string areacode = "";
            try
            {
                lock (_Putin)
                {
                #region 入库检查托盘物料表有无数据
                var cntritem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
                if (cntritem == null)
@@ -960,6 +962,8 @@
                }
                #endregion
                }
                return result;
            }
            catch (Exception ex)
@@ -971,6 +975,7 @@
            }
        }
        public static object _PutOut = new object();
        /// <summary>
        /// 出平库
        /// </summary>
@@ -997,7 +1002,6 @@
            string Start = "";
            string End = "";
            string CntrCode = "";
            string itemcode = model.PartNumber;
            string cntrType = "";
            string areacode = "";
@@ -1005,7 +1009,8 @@
            #endregion
            try
            {
                lock (_PutOut)
                {
                #region 根据物料编码规则 计算出库库区
                //粉料从平库出库,其他物料需要从暂存区出库
                var locJt = db.Queryable<Location>().Where(a => a.S_AREA_CODE == model.WorkCenter).First();
@@ -1059,7 +1064,7 @@
                #endregion
                #region 根据物料编码计算出库货位,送往线边位置
                var Endloc = new Location();
                    Location Endloc = null;
                //根据物料编码计算出库货位
                var loc = airlift(areacode, itemcode, model.PartLevel);
                if (loc != null)
@@ -1152,6 +1157,8 @@
                return result;
            }
            }
            catch (Exception ex)
            {
                result.code = "1";
@@ -1185,9 +1192,8 @@
            string Start = model.InitialLocation;
            string itemcode = "";
            int endlayer = 1;
            Location loc = new Location();
            Location loc = null;
            string areacode = "";
            WCSTask mst = new WCSTask();
            List<WCSTask> msts = new List<WCSTask>();
            #endregion
@@ -1318,18 +1324,23 @@
                            #endregion
                            //回库货位计算库区货位
                            loc = StorageCompute(itemcode, areacode);
                            if (loc == null)
                            if (string.IsNullOrEmpty(areacode))
                            {
                                loc = emptyRow(areacode);
                                result.code = "1";
                                result.msg = $"起点货位{startloc.S_CODE}无法找到回库库区,请检查起点货位";
                                LogHelper.Info($" {result.msg}");
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
                            loc = StorageCompute(itemcode, areacode);
                                if (loc == null)
                                {
                                    result.code = "1";
                                    result.msg = $"库区:{areacode}没有可用货位";
                                    LogHelper.Info($" {result.msg}");
                                    AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                                    // LogHelper.Info($"库区:{areacode}没有可用货位");
                                }
                            }
                            //else
                            //{
@@ -1345,7 +1356,6 @@
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"Empty==> 任务起点:{Start}找不到对应货位,请检查货位表";
                        LogHelper.Info($"{result.msg}");
@@ -1364,6 +1374,7 @@
                            AddErrorInfo("货位有锁", result.msg);
                            return result;
                        }
                        LogHelper.Info("创建空托回库任务,终点货位为空:" + JsonConvert.SerializeObject(loc));
                        //创建wcs任务
                        var wcsTask = new WCSTask
                        {
@@ -1402,7 +1413,7 @@
                        else
                        {
                            result.code = "1";
                            result.msg = $"任务创建失败";
                            result.msg = $"任务创建失败,请检查起点货位状态后重新下发";
                            AddErrorInfo("任务创建失败", result.msg, Source);
                            return result;
                        }
@@ -1454,7 +1465,7 @@
            string areacode = "";
            string cntrcode = "";
            Location startloc = new Location();
            Location startloc = null;
            //  startloc = LocationHelper.GetLocByAreacode(areacode, model.CarrierType);
            #endregion
@@ -1462,8 +1473,6 @@
            {
                lock (_lockcallfixture)
                {
                    #region 根据仓库编码判断库区 并计算出库货位
                    var endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == End).First();
                    //根据仓库 计算库区
@@ -1627,9 +1636,8 @@
            string Start = model.InitialLocation;
            string End = "";
            string itemcode = model.PartNumber;
            Location loc = new Location();
            Location loc = null;
            string areacode = "";
            WCSTask mst = new WCSTask();
            List<WCSTask> msts = new List<WCSTask>();
            #endregion
@@ -2383,22 +2391,17 @@
            var db = new SqlHelper<object>().GetInstance();
            try
            {
                lock (_lockCreateItem)
                {
                var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First();
                if (location != null)
                {
                    var loccntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList();
                    if (loccntr.Count > 0)
                    {
                        foreach (var item in loccntr)
                        {
                            string cntrcode = item.S_CNTR_CODE;
                            LocationHelper.UnBindingLoc(loc, new List<string>() { cntrcode });
                            var CntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).First();
                            if (CntrItem != null)
                            {
                                db.Deleteable<Container>().Where(it => it.S_CODE == item.S_CNTR_CODE).ExecuteCommand();
                                // db.Deleteable<LocCntrRel>().Where(it => it.S_LOC_CODE.Trim() == loc).ExecuteCommand();
                                if (db.Deleteable<CntrItemDetail>().Where(it => it.S_CNTR_CODE == cntrcode).ExecuteCommand() > 0)
                            var cntrcodes = loccntr.Select(a => a.S_CNTR_CODE.Trim()).ToList();
                            if (LocationHelper.Clear(loc, cntrcodes))
                                {
                                    LogHelper.Info($"ClearLoc 库位清除成功");
                                }
@@ -2409,13 +2412,6 @@
                                    result.msg = "库位清除失败";
                                    AddErrorInfo("库位清除失败", result.msg, Source);
                                    return result;
                                }
                            }
                            else
                            {
                                LogHelper.Info($"库区清空=》托盘:{cntrcode}无物料数据");
                            }
                        }
                    }
@@ -2429,12 +2425,14 @@
                    }
                }
                else
                {
                    result.code = "1";
                    result.msg = $"根据货位:{loc}找不到货位关系";
                    AddErrorInfo("货位为空", result.msg, Source);
                    return result;
                    }
                }
            }
            catch (Exception ex)
@@ -2557,60 +2555,22 @@
        {
            //Location result = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).First();
            var db = new SqlHelper<object>().GetInstance();
            Location result = new Location();
            var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).ToList();
            Location result = null;
            // 867C567A-183C-413B-9891-15D8F6DE1620
            // var aaa = db.Deleteable<Location>(a => a.S_ID == "867C567A-183C-413B-9891-15D8F6DE1620").ExecuteCommand();
            // var aaa = db.Deleteable<Location>(a => a.S_ID.Trim() == "867C567A-183C-413B-9891-15D8F6DE1620").ExecuteCommand();
            //LogHelper.Info($"方法:StorageCompute");
            var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE == areacode && a.N_LOCK_STATE == 0).ToList();
            // LogHelper.Info($"创建空托回库任务,终点货位集合:根据库区编码:{areacode}" + list.Count);
            //list.RemoveAll(a => string.IsNullOrEmpty(a.S_CODE.Trim()) || a.S_CODE == null || string.IsNullOrWhiteSpace(a.S_CODE.Trim()));
            // list = list.FindAll(a => a.N_ROW > 0 && a.N_COL > 0);
            //LogHelper.Info("创建空托回库任务,终点货位集合过滤:" + list.Count);
            if (list.Count > 0)
            {
                result= FindEndcolByLocList(list);
            }
            //查询所有有托盘的排没锁的排
            // var list = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.S_AREA_CODE.Trim() == areacode && a.N_LOCK_STATE == 0).OrderByDescending(a => a.N_COL).Take(1).PartitionBy(a => a.N_ROW).ToList();
            //if (list.Count > 0)
            //{
            //    for (int i = 0; i < list.Count; i++)
            //    {
            //        LogHelper.Info($"有托盘排号{list[i].N_ROW},物料编码{itemcode},库区{areacode}");
            //        //查询货位绑定托盘
            //        var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == list[i].S_CODE).First();
            //        if (cntr != null)
            //        {
            //            //查询托盘物料信息
            //            var iteminfo = ContainerHelper.GetCntrItemRel(cntr.S_CNTR_CODE).FirstOrDefault();
            //            if (string.IsNullOrEmpty(itemcode))//空托入库
            //            {
            //                if (iteminfo == null)
            //                {
            //                    //物料相同入货位后一位货位
            //                    result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL && a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0).First();
            //                }
            //            }
            //            else//满拖入库
            //            {
            //                if (iteminfo != null)
            //                {
            //                    if (iteminfo.S_ITEM_CODE == itemcode)
            //                    {
            //                        //物料相同入货位后一位货位
            //                        result = db.Queryable<Location>().OrderBy(a => a.N_COL).Where(a => a.S_AREA_CODE.Trim() == areacode && a.N_ROW == list[i].N_ROW && a.N_COL > list[i].N_COL && a.N_LOCK_STATE == 0 && a.N_CURRENT_NUM == 0).First();
            //                    }
            //                }
            //            }
            //            if (result != null)
            //            {
            //                return result;
            //            }
            //        }
            //        else
            //        {
            //            LogHelper.Info($"根据货物编码{list[i].S_CODE}未找到托盘货位绑定关系");
            //        }
            //    }
            //}
            return result;
        }
@@ -2754,7 +2714,7 @@
        /// <returns></returns>
        internal static Location Computeloc(string cntrcode, string jtcode, string cntrType)
        {
            Location End = new Location();
            Location End = null;
            var db = new SqlHelper<object>().GetInstance();
@@ -2838,7 +2798,7 @@
                        //当前排没有锁并且有空位置
                        // other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.C_ENABLE == "Y").FirstOrDefault();
                        other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).FirstOrDefault();
                        other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && !string.IsNullOrEmpty(a.S_CODE.Trim()) && !string.IsNullOrWhiteSpace(a.S_CODE.Trim())).FirstOrDefault();
                        //if (full == null)
                        //{
                        //    //没有满位,那就找最小的空位
@@ -2854,13 +2814,15 @@
                        //    other = db.Queryable<Location>().OrderBy(a => a.N_LAYER).Where(a => (string.IsNullOrEmpty(a.C_ENABLE) || a.C_ENABLE.Trim() != "禁用") && a.S_AREA_CODE == other.S_AREA_CODE && a.N_ROW == other.N_ROW && a.N_COL > other.N_COL).First();
                        //    //LogHelper.Info($"禁用选择后一个货位{result}", "成品");
                        //}
                        if (other != null)
                        {
                            if (other.S_CODE != null && !string.IsNullOrEmpty(other.S_CODE))
                        {
                            end = other;
                            break;
                        }
                        }
                    }
                }
                return end;