lss
2025-05-21 af42a9904d1d3939da7fa0a00c3a7a2ced78258e
HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/api/ApiHelper.cs
@@ -53,62 +53,61 @@
            try
            {
                var db = new SqlHelper<object>().GetInstance();
                string CntrCode = "";//托盘编码
                string ItemCode = "";//物料编码
                if (partData != null)
                {
                    CntrCode = partData.rfid;//托盘编码
                    ItemCode = partData.partNumber;//物料编码
                }
                string Start = ""; //取货点
                string CntrCode = partData.rfid;//托盘编码
                string ItemCode = partData.partNumber;//物料编码
                string End = "";
                string areacode = "";
                string note = ""; //立库下发任务需要通知mes接口物料到位,用备注自动进行区分
                                  //根据物料获取对应库区
                #region 根据物料确认出库来源
                var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == ItemCode).First();
                if (iteminfo != null)
                {
                    //LogHelper.Info($"Createtask==>物料数据:{JsonConvert.SerializeObject(iteminfo)}");
                    areacode = iteminfo.S_WH_CODE;
                }
                if (string.IsNullOrEmpty(areacode))
                {
                    LogHelper.Info($"Createtask==>根据物料编码:{ItemCode}未能找到物料来源,需同步物料数据");
                    result.code = "1";
                    result.msg = $"根据物料编码:{ItemCode}未能找到物料来源,需同步物料数据";
                    AddErrorInfo("寻找出库区失败", result.msg);
                    return result;
                }
                //var task = db.Queryable<WCSTask>().Where(a => a.S_EQ_NO.Trim() == taskData.taskNum).First();
                //if (task != null)
                #region 根据任务来源字段判断库区来源来源
                //var iteminfo = db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE.Trim() == ItemCode).First();
                //if (iteminfo != null)
                //{
                //    LogHelper.Info($"Createtask==> 任务号{taskData.taskNum},该任务已经存在,不允许创建任务");
                //    //LogHelper.Info($"Createtask==>物料数据:{JsonConvert.SerializeObject(iteminfo)}");
                //    areacode = iteminfo.S_WH_CODE;
                //}
                //if (string.IsNullOrEmpty(areacode))
                //{
                //    LogHelper.Info($"Createtask==>根据物料编码:{ItemCode}未能找到物料来源,需同步物料数据");
                //    result.code = "1";
                //    result.msg = $"任务号{taskData.taskNum},该任务已经存在,不允许创建任务";
                //    result.msg = $"根据物料编码:{ItemCode}未能找到物料来源,需同步物料数据";
                //    AddErrorInfo("寻找出库区失败", result.msg);
                //    return result;
                //}
                int n_type = 0;  //任务来源 1.钢丝立库  2.胶片库  3.预备库 ,4.原材料库,通过物料确认任务来源
                switch (areacode)
                int n_type = 0;  //任务来源 1.密炼立库  3.预备库 ,4.原材料库
                string Source = "";
                switch (taskData.source)
                {
                    case "ML":
                        n_type = 1;
                        break;
                    case "JP":
                        n_type = 2;
                        Source = "密炼";
                        break;
                    case "YBK":
                        n_type = 3;
                        Source = "预备库";
                        break;
                    case "wmwhse1":
                    case "YCL":
                        n_type = 4;
                        Source = "原材料";
                        break;
                }
                LogHelper.Info($"Createtask==>任务类型:{n_type}");
                Console.WriteLine($"Createtask==>任务来源:{n_type}");
                if (n_type == 0)
                {
                    result.code = "1";
                    result.msg = $"物料库区:{areacode}属于未定义库区,请检查物料表重新定义物料库区";
                    AddErrorInfo("物料库区未定义", result.msg);
                    result.msg = $"任务来源:{taskData.source}属于未定义库区,请检查物料来源是否属于约定字段";
                    AddErrorInfo("任务来源未定义", result.msg);
                    return result;
                }
                #endregion
                Location endloc = new Location();
@@ -122,7 +121,7 @@
                    {
                        //创建托盘物料绑定信息,并计算终点货位
                        Start = taskData.pickStation;
                        if (CreateCntrIteminfo(Start, CntrCode, ItemCode, partData.partDesc, partData.partType, partData.lotNumber, partData.unit, partData.weight, taskData.carrierType, taskData.grade))
                        if (CreateCntrIteminfo(partData, taskData))
                        {
                            endloc = Computeloc(CntrCode, taskData.dropStation, taskData.carrierType);
                            if (endloc != null)
@@ -133,7 +132,7 @@
                            {
                                result.code = "1";
                                result.msg = $"机台编码:{taskData.dropStation},未找到可用货位";
                                AddErrorInfo("寻找出库货位失败", result.msg);
                                AddErrorInfo("寻找出库货位失败", result.msg, Source);
                                return result;
                            }
                        }
@@ -141,16 +140,17 @@
                        {
                            result.code = "1";
                            result.msg = "创建托盘物料信息失败";
                            AddErrorInfo("创建托盘失败", result.msg);
                            AddErrorInfo("创建托盘失败", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        LogHelper.Info($"Putin==> 任务起点:{taskData.pickStation}找不到对应货位,请检查货位表");
                        result.code = "1";
                        result.msg = $"Putin==> 任务起点:{taskData.pickStation}找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg);
                        LogHelper.Info($"Putin==> {result.msg}");
                        AddErrorInfo("货位查找失败", result.msg, Source);
                    }
                }
                else if (taskData.taskType == 2)//入库流程,直接使用起点货位和终点货位生成任务,起点需要有托盘
@@ -168,7 +168,7 @@
                        {
                            result.code = "1";
                            result.msg = $"根据起点{Start},未找到托盘货位绑定关系";
                            AddErrorInfo("托盘查找失败", result.msg);
                            AddErrorInfo("托盘查找失败", result.msg, Source);
                            return result;
                        }
@@ -188,7 +188,7 @@
                    {
                        result.code = "1";
                        result.msg = $"根据终点{End},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg);
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                }
@@ -201,10 +201,24 @@
                    {
                        Start = taskData.pickStation;
                    }
                    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();
                    if (endloc != null)
                    {
                        End = taskData.dropStation;
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = $"根据终点{taskData.dropStation},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                }
                else if (taskData.taskType == 4)//原材料库需要判断是否需要分配电梯任务,创建分档任务
@@ -229,7 +243,7 @@
                        {
                            result.code = "1";
                            result.msg = $"创建任务失败,起点:{startloc.S_AREA_CODE},终点:{endloc.S_AREA_CODE}未找到对应库区";
                            AddErrorInfo("货位查找失败", result.msg);
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                        if (startArea.N_FLOOR == endArea.N_FLOOR)
@@ -329,27 +343,41 @@
                        return result;
                    }
                }
                else if (taskData.taskType == 5)//移库流程,直接使用起点货位和终点货位生成任务,
                else if (taskData.taskType == 5)//移库流程,直接使用起点货位和终点货位生成任务,并绑定托盘
                {
                    //创建托盘物料绑定信息,并计算终点货位
                    if (CreateCntrIteminfo(taskData.pickStation, CntrCode, ItemCode, partData.partDesc, partData.partType, partData.lotNumber, partData.unit, partData.weight, taskData.carrierType, taskData.grade))
                    if (CreateCntrIteminfo(partData, taskData))
                    {
                        startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                        if (startloc != null)
                        {
                            Start = taskData.pickStation;
                        }
                        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();
                        if (endloc != null)
                        {
                            End = taskData.dropStation;
                        }
                        else
                        {
                            result.code = "1";
                            result.msg = $"根据终点{taskData.dropStation},找不到对应货位,请检查货位表";
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                    }
                    else
                    {
                        result.code = "1";
                        result.msg = "创建托盘物料信息失败";
                        AddErrorInfo("创建托盘失败", result.msg);
                        AddErrorInfo("创建托盘失败", result.msg, Source);
                        return result;
                    }
@@ -371,7 +399,7 @@
                        {
                            result.code = "1";
                            result.msg = $"根据托盘{partData.rfid},未找到托盘货位绑定关系";
                            AddErrorInfo("货位查找失败", result.msg);
                            AddErrorInfo("货位查找失败", result.msg, Source);
                            return result;
                        }
                    }
@@ -384,7 +412,7 @@
                    {
                        result.code = "1";
                        result.msg = $"根据终点{End},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg);
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                }
@@ -393,7 +421,7 @@
                {
                    note = "异常库区入库";
                    //创建托盘物料绑定信息,并计算终点货位
                    if (CreateCntrIteminfo(taskData.pickStation, CntrCode, ItemCode, partData.partDesc, partData.partType, partData.lotNumber, partData.unit, partData.weight, taskData.carrierType, taskData.grade))
                    if (CreateCntrIteminfo(partData, taskData))
                    {
                        startloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.pickStation).First();
                        if (startloc != null)
@@ -412,7 +440,7 @@
                            {
                                result.code = "1";
                                result.msg = $"终点库区:{taskData.dropStation}无可用货位";
                                AddErrorInfo("查找库区失败", result.msg);
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
@@ -421,7 +449,7 @@
                        {
                            result.code = "1";
                            result.msg = $"根据终点库区:{taskData.dropStation},未找到对应货位";
                            AddErrorInfo("查找库区失败", result.msg);
                            AddErrorInfo("查找库区失败", result.msg, Source);
                            return result;
                        }
                    }
@@ -429,7 +457,7 @@
                    {
                        result.code = "1";
                        result.msg = "创建托盘物料信息失败";
                        AddErrorInfo("创建托盘失败", result.msg);
                        AddErrorInfo("创建托盘失败", result.msg, Source);
                        return result;
                    }
                }
@@ -445,7 +473,7 @@
                    {
                        result.code = "1";
                        result.msg = $"根据起点:{taskData.pickStation},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg);
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                    endloc = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == taskData.dropStation).First();
@@ -457,7 +485,7 @@
                    {
                        result.code = "1";
                        result.msg = $"根据终点:{End},找不到对应货位,请检查货位表";
                        AddErrorInfo("货位查找失败", result.msg);
                        AddErrorInfo("货位查找失败", result.msg, Source);
                        return result;
                    }
                }
@@ -466,7 +494,7 @@
                    LogHelper.Info($"Createtask==> 任务类型有误");
                    result.code = "1";
                    result.msg = "任务类型:{taskData.taskType}不在规定范围内";
                    AddErrorInfo("任务类型错误", result.msg);
                    AddErrorInfo("任务类型错误", result.msg, Source);
                }
                if (taskData.taskType != 4)
                {
@@ -542,8 +570,6 @@
        }
        /// <summary>
        /// 预备库任务状态下发
        /// </summary>
@@ -602,7 +628,7 @@
                LogHelper.Info($"AllowThrough==> 参数为null");
                result.code = "1";
                result.msg = "参数为null值,请检查参数格式";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, "", model.task_no);
                return result;
            }
@@ -624,7 +650,7 @@
                {
                    result.code = "1";
                    result.msg = $"根据下发任务号{model.task_no}未找到对应任务";
                    AddErrorInfo("未找到任务", result.msg);
                    AddErrorInfo("未找到任务", result.msg, "", model.task_no);
                    return result;
                }
                return result;
@@ -657,7 +683,7 @@
            try
            {
                //创建托盘数据绑定关系
                if (ContainerHelper.CreateCntrItem(model.Rfid, model.PartNumber, model.PartDesc, model.LotNumber, model.Weight,model.Qty))
                if (ContainerHelper.CreateCntrItem(model.Rfid, model.PartNumber, model.PartDesc, model.LotNumber, model.Weight, model.Qty))
                {
                    //创建成功流程
                }
@@ -665,7 +691,7 @@
                {
                    result.code = "1";
                    result.msg = "产出信息下发失败,托盘物料绑定关系创建失败";
                    AddErrorInfo("创建绑定关系失败", result.msg);
                    AddErrorInfo("创建绑定关系失败", result.msg, "Mes");
                    return result;
                }
                return result;
@@ -690,31 +716,38 @@
        internal static Result Putin(Putin model, int n_type)
        {
            Result result = new Result() { code = "200", msg = "入平库任务下发成功" };
            string Source = "Mes";
            if (n_type == 0)
            {
                Source = "PDA";
            }
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
            var db = new SqlHelper<object>().GetInstance();
            Location loc = new Location();
            string Start = model.InitialLocation;  //起点货位
            string itemcode = model.PartNumber;    //物料编码
            string areacode = "";
            try
            {
                #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)
                    {
                        LogHelper.Info($"ItemBack:创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}");
                        result.code = "1";
                        result.msg = $"创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}";
                        AddErrorInfo("托盘绑定位置不同", result.msg);
                        LogHelper.Info($"ItemBack:{result.msg}");
                        AddErrorInfo("托盘绑定位置不同", result.msg, Source);
                        return result;
                    }
                }
@@ -781,18 +814,20 @@
                    }
                    else
                    {
                        LogHelper.Info($"Putin==>库区:{areacode}无可用货位");
                        result.code = "1";
                        result.msg = $"库区:{areacode}无可用货位";
                        AddErrorInfo("查找库区失败", result.msg);
                        LogHelper.Info($"Putin==> {result.msg}");
                        AddErrorInfo("查找库区失败", result.msg, Source);
                    }
                }
                else
                {
                    LogHelper.Info($"Putin==> 任务起点:{Start}找不到对应货位,请检查货位表");
                    result.code = "1";
                    result.msg = $"任务起点:{Start}找不到对应货位,请检查货位表";
                    AddErrorInfo("查找货位失败", result.msg);
                    LogHelper.Info($"Putin==> {result.msg}");
                    AddErrorInfo("查找货位失败", result.msg, Source);
                }
                #endregion
@@ -803,7 +838,7 @@
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,起点:{Start}有锁";
                        AddErrorInfo("货位有锁", result.msg);
                        AddErrorInfo("货位有锁", result.msg, Source);
                        return result;
                    }
                    //创建wcs任务
@@ -862,11 +897,16 @@
        internal static Result PutOut(PutOut model, int n_type)
        {
            Result result = new Result() { code = "200", msg = "出平库任务下发成功" };
            string Source = "Mes";
            if (n_type == 0)
            {
                Source = "PDA";
            }
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
@@ -874,6 +914,7 @@
            string Start = "";
            string End = "";
            string CntrCode = "";
            string itemcode = model.PartNumber;
            string cntrType = "";
            string areacode = "";
@@ -900,10 +941,11 @@
                    }
                    else
                    {
                        LogHelper.Info($"ItemBack:创建任务失败,物料号{model.PartNumber}不属于规定物料");
                        result.code = "1";
                        result.msg = $"创建任务失败,物料号{model.PartNumber}不属于规定物料";
                        AddErrorInfo("物料编码格式错误", result.msg);
                        LogHelper.Info($"ItemBack:{result.msg}");
                        AddErrorInfo("物料编码格式错误", result.msg, Source);
                        return result;
                    }
                }
@@ -945,10 +987,11 @@
                }
                else
                {
                    LogHelper.Info($"PutOut==> 任务物料:{itemcode}找不到对应库存");
                    result.code = "1";
                    result.msg = $"任务物料:{itemcode}找不到对应库存";
                    AddErrorInfo("查找库区失败", result.msg);
                    LogHelper.Info($"ItemBack:{result.msg}");
                    AddErrorInfo("查找库区失败", result.msg, Source);
                }
                #endregion
@@ -959,7 +1002,7 @@
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,起点{Start}有锁";
                        AddErrorInfo("货位有锁", result.msg);
                        AddErrorInfo("货位有锁", result.msg, Source);
                        return result;
                    }
                    //创建wcs任务
@@ -1017,11 +1060,12 @@
        internal static Result Empty(Empty model)
        {
            Result result = new Result() { code = "200", msg = "空工装回库任务下发成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
@@ -1077,7 +1121,7 @@
                            {
                                result.code = "1";
                                result.msg = $"叠盘货位不可用";
                                AddErrorInfo("查找库区失败", result.msg);
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
                            else
@@ -1087,10 +1131,11 @@
                        }
                        else
                        {
                            LogHelper.Info($"根据货位备注:叠盘,货位楼层:{startloc.N_LAYER},货位仓库:{startloc.S_WH_CODE},找不到叠盘货位");
                            result.code = "1";
                            result.msg = $"叠盘货位不可用";
                            AddErrorInfo("查找货位失败", result.msg);
                            LogHelper.Info($"根据货位备注:叠盘,货位楼层:{startloc.N_LAYER},货位仓库:{startloc.S_WH_CODE},找不到叠盘货位");
                            AddErrorInfo("查找货位失败", result.msg, Source);
                            return result;
                        }
                    }
@@ -1105,7 +1150,7 @@
                            {
                                result.code = "1";
                                result.msg = $"叠盘货位不可用";
                                AddErrorInfo("查找库区失败", result.msg);
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
                            else
@@ -1118,7 +1163,7 @@
                            LogHelper.Info($"根据货位备注:片胶堆叠位,货位仓库:{startloc.S_WH_CODE},找不到叠盘货位");
                            result.code = "1";
                            result.msg = $"叠盘货位不可用";
                            AddErrorInfo("查找货位失败", result.msg);
                            AddErrorInfo("查找货位失败", result.msg, Source);
                            return result;
                        }
                    }
@@ -1138,18 +1183,20 @@
                        }
                        else
                        {
                            LogHelper.Info($"创建任务失败,根据托盘编码{model.Rfid}未找到托盘出库任务");
                            result.code = "1";
                            result.msg = $"创建任务失败,根据托盘编码{model.Rfid}未找到托盘出库任务";
                            AddErrorInfo("查找任务失败", result.msg);
                            LogHelper.Info($"{result.msg}");
                            AddErrorInfo("查找任务失败", result.msg, Source);
                            return result;
                        }
                        if (string.IsNullOrEmpty(areacode))
                        {
                            LogHelper.Info($"创建任务失败,根据托盘编码{model.Rfid}找到出库任务{mst.S_CODE}的起点库区为空");
                            result.code = "1";
                            result.msg = $"创建任务失败,根据托盘编码{model.Rfid}找到出库任务{mst.S_CODE}的起点库区为空";
                            AddErrorInfo("查找库区失败", result.msg);
                            LogHelper.Info($"{result.msg}");
                            AddErrorInfo("查找库区失败", result.msg, Source);
                            return result;
                        }
                        #endregion
@@ -1166,10 +1213,11 @@
                        }
                        else
                        {
                            LogHelper.Info($"库区:{areacode}无可用货位");
                            result.code = "1";
                            result.msg = $"库区:{areacode}无可用货位";
                            AddErrorInfo("查找货位失败", result.msg);
                            LogHelper.Info($"{result.msg}");
                            AddErrorInfo("查找货位失败", result.msg, Source);
                            return result;
                        }
                    }
@@ -1177,10 +1225,11 @@
                }
                else
                {
                    LogHelper.Info($"Empty==> 任务起点:{Start}找不到对应货位,请检查货位表");
                    result.code = "1";
                    result.msg = $"Empty==> 任务起点:{Start}找不到对应货位,请检查货位表";
                    AddErrorInfo("查找货位失败", result.msg);
                    LogHelper.Info($"{result.msg}");
                    AddErrorInfo("查找货位失败", result.msg, Source);
                    return result;
                }
                #endregion
@@ -1253,11 +1302,12 @@
        {
            var db = new SqlHelper<object>().GetInstance();
            Result result = new Result() { code = "200", msg = "空工装呼叫任务下发成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
@@ -1299,10 +1349,10 @@
                        }
                        else
                        {
                            LogHelper.Info($"callfixture:创建空工装呼叫任务==>根据货位{endloc.S_CODE}未找到托盘货位绑定关系");
                            result.code = "1";
                            result.msg = $"创建空工装呼叫任务==>根据货位{endloc.S_CODE}未找到托盘货位绑定关系";
                            AddErrorInfo("查找托盘失败", result.msg);
                            LogHelper.Info($"callfixture:{result.msg}");
                            AddErrorInfo("查找托盘失败", result.msg, Source);
                            return result;
                        }
@@ -1311,10 +1361,11 @@
                }
                else
                {
                    LogHelper.Info($"callfixture==> 任务起点:{End}找不到对应货位,请检查货位表");
                    result.code = "1";
                    result.msg = $"任务起点:{End}找不到对应货位,请检查货位表";
                    AddErrorInfo("查找货位失败", result.msg);
                    LogHelper.Info($"callfixture:{result.msg}");
                    AddErrorInfo("查找货位失败", result.msg, Source);
                }
                #endregion
@@ -1387,11 +1438,12 @@
        internal static Result ItemBack(ItemBack model)
        {
            Result result = new Result() { code = "200", msg = "余料返回任务下发成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
@@ -1415,19 +1467,21 @@
                {
                    if (CntrLoc.S_LOC_CODE != Start)
                    {
                        LogHelper.Info($"ItemBack:创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}");
                        result.code = "1";
                        result.msg = $"创建任务失败,托盘:{model.Rfid}绑定位置不是起点:{Start}";
                        AddErrorInfo("托盘绑定位置不同", result.msg);
                        LogHelper.Info($"ItemBack:{result.msg}");
                        AddErrorInfo("托盘绑定位置不同", result.msg, Source);
                        return result;
                    }
                }
                else
                {
                    LogHelper.Info($"ItemBack:创建任务失败,托盘:{model.Rfid}未找到绑定货位");
                    result.code = "1";
                    result.msg = $"创建任务失败,托盘:{model.Rfid}未找到绑定货位";
                    AddErrorInfo("查找托盘货位失败", result.msg);
                    LogHelper.Info($"ItemBack:{result.msg}");
                    AddErrorInfo("查找托盘货位失败", result.msg, Source);
                    return result;
                }
                #endregion
@@ -1483,10 +1537,11 @@
                        }
                        else
                        {
                            LogHelper.Info($"ItemBack:创建任务失败,物料号{model.PartNumber}不属于规定物料");
                            result.code = "1";
                            result.msg = $"创建任务失败,物料号{model.PartNumber}不属于规定物料";
                            AddErrorInfo("物料编码格式错误", result.msg);
                            LogHelper.Info($"ItemBack:{result.msg}");
                            AddErrorInfo("物料编码格式错误", result.msg, Source);
                            return result;
                        }
                        var EndLocs = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == areacode).ToList();
@@ -1501,7 +1556,7 @@
                            {
                                result.code = "1";
                                result.msg = $"终点库区:{areacode}无可用货位";
                                AddErrorInfo("查找库区失败", result.msg);
                                AddErrorInfo("查找库区失败", result.msg, Source);
                                return result;
                            }
@@ -1510,7 +1565,7 @@
                        {
                            result.code = "1";
                            result.msg = $"根据终点库区:{areacode},未找到对应货位";
                            AddErrorInfo("查找库区失败", result.msg);
                            AddErrorInfo("查找库区失败", result.msg, Source);
                            return result;
                        }
                        //loc = StorageCompute(itemcode, areacode);
@@ -1525,19 +1580,19 @@
                    }
                    else
                    {
                        LogHelper.Info($"库区:{areacode}无可用货位");
                        result.code = "1";
                        result.msg = $"库区:{areacode}无可用货位";
                        AddErrorInfo("查找货位失败", result.msg);
                        AddErrorInfo("查找货位失败", result.msg, Source);
                        return result;
                    }
                }
                else
                {
                    LogHelper.Info($"货位:{Start}找不到对应货位");
                    result.code = "1";
                    result.msg = $"货位:{Start}找不到对应货位";
                    AddErrorInfo("查找货位失败", result.msg);
                    AddErrorInfo("查找货位失败", result.msg, Source);
                    return result;
                }
@@ -1627,11 +1682,12 @@
                msg = "线边库存查询成功"
            };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
@@ -1678,11 +1734,12 @@
        internal static Result add(add model)
        {
            Result result = new Result() { code = "200", msg = "物料主数据创建成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
            try
@@ -1691,24 +1748,26 @@
                if (db.Queryable<TN_Material>().Where(a => a.S_ITEM_CODE == model.PartNumber).Count() > 0)
                {
                    result.code = "1";
                    result.msg = "物料主数据已存在";
                    AddErrorInfo("物料主数据已存在", result.msg);
                    result.msg = $"物料编码:{model.PartNumber}的物料主数据已存在";
                    //  AddErrorInfo("物料主数据已存在", result.msg, Source);
                    LogHelper.Info($"add:{result.msg}");
                    return result;
                }
                TN_Material itemInfo = new TN_Material();
                itemInfo.S_ITEM_CODE = model.PartNumber;
                itemInfo.ITEM_TYPE = model.PartClass;
                itemInfo.S_ITEM_NAME = model.PartDesc;
                itemInfo.REMARK1 = model.StewingTime.ToString("yyyy-MM-dd");
                itemInfo.REMARK2 = model.OverdueTime.ToString("yyyy-MM-dd");
                itemInfo.REMARK1 = model.StewingTime;
                itemInfo.REMARK2 = model.OverdueTime;
                itemInfo.S_MP_TYPE = model.Unit;
                db.Insertable<TN_Material>(itemInfo).ExecuteCommand();
                if (db.Insertable<TN_Material>(itemInfo).ExecuteCommand()>0)
                {
                    LogHelper.Info($"add:物料编码:{model.PartNumber}的物料主数据已同步");
                } ;
                return result;
            }
            catch (Exception ex)
            {
                result.code = "1";
                result.msg = $"物料主数据创建失败 错误信息:{ex}";
                LogHelper.Error("add Error:" + ex.ToString(), ex);
@@ -1724,11 +1783,12 @@
        internal static Result CreatTask(CreatTask model)
        {
            Result result = new Result() { code = "200", msg = "点对点任务创建成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
            string Start = ""; //取货点
@@ -1754,7 +1814,7 @@
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,根据起点{model.InitialLocation}未找到对应货位绑定托盘托盘";
                        AddErrorInfo("查找托盘失败", result.msg);
                        AddErrorInfo("查找托盘失败", result.msg, Source);
                        return result;
                    }
                }
@@ -1832,11 +1892,12 @@
        internal static Result CreatelevatorTask(Elevator model)
        {
            Result result = new Result() { code = "200", msg = "点对点任务创建成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
@@ -1856,17 +1917,18 @@
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,起点{startloc.S_CODE}有锁";
                        AddErrorInfo("货位有锁", result.msg);
                        AddErrorInfo("货位有锁", result.msg, Source);
                        return result;
                    }
                    var cntr = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == startloc.S_CODE).First();
                    if (cntr == null)
                    {
                        LogHelper.Info($"callfixture:创建空工装呼叫任务==>根据货位{endloc.S_CODE}未找到托盘货位绑定关系");
                        result.code = "1";
                        result.msg = $"起点{model.Data.start_loc_code}未查询绑定托盘";
                        AddErrorInfo("查找托盘失败", result.msg);
                        LogHelper.Info($"callfixture:创建空工装呼叫任务==>{result.msg}");
                        AddErrorInfo("查找托盘失败", result.msg, Source);
                        return result;
                    }
@@ -1880,7 +1942,7 @@
                    {
                        result.code = "1";
                        result.msg = $"创建任务失败,根据货位编码:{dtcode}未找到电梯货位";
                        AddErrorInfo("查找货位失败", result.msg);
                        AddErrorInfo("查找货位失败", result.msg, Source);
                        return result;
                    }
@@ -1953,8 +2015,6 @@
        }
        /// <summary>
        /// 货位信息上传
        /// </summary>
@@ -1964,6 +2024,7 @@
        {
            Result result = new Result() { code = "200", msg = "货位信息上传成功" };
            String Source = "MES";
            RequestList<UploadLoc> result1 = new RequestList<UploadLoc>();
            List<UploadLoc> listuploadloc = new List<UploadLoc>();
            var db = new SqlHelper<object>().GetInstance();
@@ -1987,7 +2048,7 @@
                {
                    result.code = "1";
                    result.msg = $"货位上传失败,根据货位编码{item.Location}未找到对应的货位信息";
                    AddErrorInfo("查找货位失败", result.msg);
                    AddErrorInfo("查找货位失败", result.msg, Source);
                    return result;
                }
            }
@@ -2018,7 +2079,7 @@
                LogHelper.Info($"物料到位回报失败=>回报地址没有配置");
                result.code = "1";
                result.msg = $"物料到位回报失败=>回报地址没有配置";
                AddErrorInfo("地址错误", result.msg);
                AddErrorInfo("地址错误", result.msg, Source);
            }
            return result;
        }
@@ -2032,11 +2093,12 @@
        internal static Result ClearLoc(ClearTask model)
        {
            Result result = new Result() { code = "200", msg = "库位清除成功" };
            string Source = "MES";
            if (model == null)
            {
                result.code = "1";
                result.msg = "参数为null";
                AddErrorInfo("参数为空", result.msg);
                AddErrorInfo("参数为空", result.msg, Source);
                return result;
            }
            string loc = model.LocationNum;
@@ -2076,7 +2138,7 @@
                {
                    result.code = "1";
                    result.msg = $"根据货位:{loc}找不到货位关系";
                    AddErrorInfo("货位为空", result.msg);
                    AddErrorInfo("货位为空", result.msg, Source);
                    return result;
                }
            }
@@ -2218,7 +2280,9 @@
            #endregion
            var loc = LocationHelper.GetLocByItemCode(areacode, itemcode, level);
            LogHelper.Info($"airlift=>根据库区编码:{areacode},物料编码:{itemcode},物料等级计算出有托盘货位{JsonConvert.SerializeObject(loc)}");
            result = FindStartcolByLoclist(loc);
            LogHelper.Info($"airlift=>可用货位为:{JsonConvert.SerializeObject(result)}");
            return result;
        }
@@ -2242,26 +2306,31 @@
            }
            return result;
        }
        /// <summary>
        /// 创建托盘物料绑定关系
        /// 立库任务下发创建托盘物料绑定关系
        /// </summary>
        /// <param name="loc">货位编码</param>
        /// <param name="cntr">托盘编码</param>
        /// <param name="partNumber">物料编码</param>
        /// <param name="partDesc">物料描述</param>
        /// <param name="partType">物料类型</param>
        /// <param name="cntrtype">托盘类型</param>
        /// <param name="unit">物料单位</param>
        /// <param name="weight">物料重量</param>
        internal static bool CreateCntrIteminfo(string loc, string cntr, string partNumber, string partDesc, string partType, string batch, string unit, string weight, string cntrtype = "1", string level = "")
        internal static bool CreateCntrIteminfo(partData partData, taskData taskData)
        {
            return ContainerHelper.CreateCntrItem(loc, cntr, partNumber, partDesc, partType, cntrtype, batch, weight, unit, level);
            if (partData == null && taskData == null)
            {
                LogHelper.Info($"CreateCntrIteminfo==> 立库任务下发参数有空,创建物料托盘绑定关系失败");
                return false;
            }
            else
            {
                return ContainerHelper.CreateCntrItem(taskData.pickStation, partData.rfid, partData.partNumber, partData.partDesc, partData.partType, taskData.carrierType, partData.lotNumber, taskData.wmsLot, partData.weight, partData.unit,
                    taskData.tyreType, taskData.supplier, taskData.receiveLot, taskData.subpool, partData.productionTime, partData.maturityTime, taskData.level);
            }
        }
        private static object _lockLocation = new object();
        /// <summary>
        /// 根据托盘编码,机台编码,工装类型计算机台线边区域
        /// </summary>
        /// <param name="cntrcode">托盘编码</param>
        /// <param name="jtcode">机台编码</param>
        /// <param name="cntrType">托盘类型</param>
        /// <returns></returns>
        internal static Location Computeloc(string cntrcode, string jtcode, string cntrType)
        {
@@ -2271,17 +2340,19 @@
            //  var location = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE.Trim() == cntrcode).First();
            var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
            if (loc != null)
            lock (_lockLocation)
            {
                End = loc;
            }
            else
            {
                LogHelper.Info($"Computeloc==》根据机台分组:{jtcode},工装类型:{cntrType} 未找到空货位数据,请检查货位表");
            }
                var loc = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == jtcode.Trim() && a.S_NOTE == cntrType && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
                if (loc != null)
                {
                    End = loc;
                }
                else
                {
                    LogHelper.Info($"Computeloc==》根据机台分组:{jtcode},工装类型:{cntrType} 未找到空货位数据,请检查货位表");
                }
            }
            return End;
        }
@@ -2301,7 +2372,7 @@
            {
                var error = new ErrorInfo
                {
                    EEEORMESSAGE = errorInfo,
                    ERRORMESSAGE = errorInfo,
                    TASKNO = taskno,
                    AREACODE = areacode,
                    REMAKE = remake,