lss
2025-06-06 8674dabad31db77cba438ab1746235fa41c08716
HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -34,6 +34,8 @@
        #region 佳通合肥接口业务
        /// <summary>
        /// 立库任务下发=》创建任务
        /// </summary>
@@ -176,6 +178,13 @@
                        //    return result;
                        //}
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"根据起点{taskData.pickStation},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                    endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
@@ -1089,6 +1098,7 @@
                        N_START_LAYER = 1,
                        N_END_LAYER = 1,
                        Z_TYPE = n_type
                    };
                    LogHelper.Info("创建出平库任务:" + JsonConvert.SerializeObject(wcsTask));
                    if (WCSHelper.CreateTask(wcsTask))
@@ -1125,6 +1135,7 @@
        }
        public static object _lockEmpty = new object();
        /// <summary>
        /// 空工装回库
        /// </summary>
@@ -1154,6 +1165,8 @@
            #endregion
            try
            {
                lock (_lockEmpty)
            {
                #region 判断托盘绑定货位是否和下发绑定起点相同
                //var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
@@ -1350,6 +1363,8 @@
                }
                #endregion
            }
            }
            catch (Exception ex)
            {
                result.code = "1";
@@ -1360,6 +1375,8 @@
            return result;
        }
        public static object _lockcallfixture = new object();
        /// <summary>
        /// 空工装呼叫
@@ -1382,13 +1399,15 @@
            #region 变量
            string Start = "";
            string End = model.TargetLocation;
            string itemcode = "";
            string areacode = "";
            string cntrcode = "";
            Location startloc = new Location();
            #endregion
            try
            {
                lock (_lockcallfixture)
            {
                #region 根据仓库编码判断库区 并计算出库货位
                var endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == End).First();
@@ -1412,7 +1431,7 @@
                    //计算出库托盘
                    startloc = LocationHelper.GetLocByAreacode(areacode);
                        startloc = LocationHelper.GetLocByAreacode(areacode,model.CarrierType);
                    if (startloc != null)
                    {
                        var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).First();
@@ -1471,8 +1490,8 @@
                        S_CNTR_CODE = cntrcode,
                        N_START_LAYER = 1,
                        N_END_LAYER = 1,
                        Z_TYPE = 5
                            Z_TYPE = 5,
                            S_NOTE = "粉料"
                    };
                    LogHelper.Info("创建呼叫空托任务:" + JsonConvert.SerializeObject(wcsTask));
                    if (WCSHelper.CreateTask(wcsTask))
@@ -1497,6 +1516,8 @@
                }
                return result;
                #endregion
                }
            }
            catch (Exception ex)
@@ -1511,6 +1532,7 @@
        }
        public static object _lockItemBack = new object();
        /// <summary>
        /// 余料返回
        /// </summary>
@@ -1542,6 +1564,8 @@
            try
            {
                lock (_lockItemBack)
                {
                #region 余料返回根据托盘找出库任务
                //余料返回根据托盘找出库任务
                //msts = WCSHelper.GetTaskBycntrcode(model.Rfid);
@@ -1571,6 +1595,34 @@
                //}
                #endregion
                    #region 判断托盘绑定货位是否和下发绑定起点相同
                    var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
                    if (CntrLoc != null)
                    {
                        if (CntrLoc.S_LOC_CODE != Start)
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}";
                            LogHelper.Info($"ItemBack:{result.msg}");
                            AddErrorInfo("托盘绑定位置不同", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        if (db.Updateable(new LocCntrRel() { S_CNTR_CODE = model.Rfid, S_LOC_CODE = Start }).UpdateColumns().ExecuteCommand() <= 0)
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,托盘:{model.Rfid}绑定货位{Start}失败";
                            LogHelper.Info($"ItemBack:{result.msg}");
                            AddErrorInfo("托盘绑定货位失败", result.msg, Source);
                            return result;
                        }
                    }
                    #endregion
                #region 根据物料编码 判断回库还是回到对应暂存区 
                var startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == Start).First();
                if (startloc != null)
@@ -1591,30 +1643,7 @@
                        }
                        else
                        {
                            #region 判断托盘绑定货位是否和下发绑定起点相同
                            var CntrLoc = db.Queryable<LocCntrRel>().Where(a => a.S_CNTR_CODE.Trim() == model.Rfid).First();
                            if (CntrLoc != null)
                            {
                                if (CntrLoc.S_LOC_CODE != Start)
                                {
                                    result.code = "1";
                                    result.msg = $"创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}";
                                    LogHelper.Info($"ItemBack:{result.msg}");
                                    AddErrorInfo("托盘绑定位置不同", result.msg, Source);
                                    return result;
                                }
                            }
                            else
                            {
                                result.code = "1";
                                result.msg = $"创建任务失败,托盘:{model.Rfid}未找到绑定货位";
                                LogHelper.Info($"ItemBack:{result.msg}");
                                AddErrorInfo("查找托盘货位失败", result.msg, Source);
                                return result;
                            }
                            #endregion
                            if (model.PartNumber.StartsWith("3"))
                            {
@@ -1733,6 +1762,23 @@
                            db.Updateable(CntrItem).UpdateColumns(a => new { a.F_WEIGHT, a.S_BS_TYPE }).ExecuteCommand();
                        }
                            else
                            {
                                var cir = new CntrItemDetail
                                {
                                    S_CNTR_CODE = model.Rfid,
                                    S_ITEM_CODE = itemcode,
                                    S_ITEM_NAME = model.PartNumber,
                                    S_ITEM_SPEC = model.PartDesc,
                                    F_QTY = float.Parse(model.LotList[0].qty),
                                    S_BS_TYPE = "余料",
                                    F_WEIGHT = model.LotList[0].Weight.ToString(),
                                    S_ITEM_STATE = model.LotList[0].QualityStatus,
                                    D_EXP_DATE = model.LotList[0].MaturityTime,
                                    D_PRD_DATE = model.LotList[0].ProductionTime
                                };
                                db.Insertable<CntrItemDetail>(cir).ExecuteCommand();
                            }
                        LogHelper.Info("创建任务成功");
                    }
                    else
@@ -1750,6 +1796,10 @@
                    return result;
                }
                #endregion
                }
                return result;
            }
@@ -2263,7 +2313,8 @@
            }
            return result;
        }  /// <summary>
        }
        /// <summary>
        /// 库位清空
        /// </summary>
        /// <param name="model"></param>
@@ -2286,17 +2337,17 @@
                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).First();
                    if (loccntr != null)
                    var loccntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList();
                    if (loccntr.Count > 0)
                    {
                        string cntrcode = loccntr.S_CNTR_CODE;
                        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)
                        {
                            LocationHelper.UnBindingLoc(loc, new List<string>() { cntrcode });
                                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)
                            {
@@ -2310,18 +2361,24 @@
                                AddErrorInfo("库位清除失败", result.msg, Source);
                                return result;
                            }
                        }
                        else
                        {
                            LogHelper.Info($"ClearLoc 托盘{cntrcode}无物料绑定关系");
                                LogHelper.Info($"库区清空=》托盘:{cntrcode}无物料数据");
                            }
                        }
                    }
                    else
                    {
                        LogHelper.Info($"ClearLoc 货位{loc}无托盘货位绑定关系");
                        result.code = "1";
                        result.msg = $" ClearLoc 货位{loc}无托盘货位绑定关系";
                        AddErrorInfo("库位清除失败", result.msg, Source);
                        return result;
                    }
                }
                else
                {
@@ -2439,6 +2496,8 @@
        #endregion
        #region 合肥佳通业务方法
        /// <summary>
        /// 托盘入库算法 
        /// </summary>
@@ -2496,6 +2555,7 @@
            //}
            return result;
        }
        /// <summary>
        /// 根据物料计算托盘出库
@@ -2702,7 +2762,7 @@
                        Location other = null;
                        //当前排没有锁并且有空位置
                        //先找满位,然后后面一层要么是空,要么不存在
                        other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0).FirstOrDefault();
                        other = rowList.OrderBy(a => a.N_COL).Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).FirstOrDefault();
                        //if (full == null)
                        //{
                        //    //没有满位,那就找最小的空位