zhaowc
11 小时以前 4de417b106a062452f5ac86e626e7e225b753eab
Wms/WMS.BLL/BllTransServer/HopperTransportServer.cs
@@ -217,7 +217,7 @@
        /// <param name="lotNo">批次</param>
        /// <param name="userId">操作人</param>
        /// <exception cref="Exception"></exception>
        public void jiaoLiaoHopper(string areaNo,string endLocate,string plnStatus,string standard,string skuNo,string lotNo,string url,int userId)
        public void jiaoLiaoHopper(string areaNo,string endLocate,string plnStatus,string standard,string skuNo,string lotNo,string url, string bindUrl, int userId)
        {
            try
            {
@@ -297,17 +297,19 @@
                var locatListWai = locatList.Where(w => string.IsNullOrEmpty(w.AisleOne)).Select(s => s.LocatNo);
                //先找不需要移库的桶
                var palletModel = stockDetail.Where(w => locatListWai.Contains(w.LocatNo)).OrderBy(o => o.UpdateTime).FirstOrDefault();
                var palletModel = stockDetail.Where(w => locatListWai.Contains(w.LocatNo)).OrderByDescending(w => w.UpdateTime).FirstOrDefault();
                if (palletModel == null)
                {
                    //找需要移库的桶
                    palletModel= stockDetail.Where(w => !locatListWai.Contains(w.LocatNo)).OrderBy(o => o.UpdateTime).FirstOrDefault();
                    palletModel= stockDetail.Where(w => !locatListWai.Contains(w.LocatNo)).OrderByDescending(w => w.UpdateTime).FirstOrDefault();
                    if (palletModel == null)
                    {
                        throw new Exception("未找到对应桶信息");
                    }
                    resultYi = YikuTask(palletModel.PalletNo, taskNo, url);
                    resultYi = YikuTask(palletModel.PalletNo, taskNo, url,bindUrl);
                }
                palletModel.Status = "2";
                Db.Updateable(palletModel).ExecuteCommand();
                #endregion
                //起始储位地址信息
                var startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.Status == "1" && w.LocatNo == palletModel.LocatNo);
@@ -328,9 +330,9 @@
                    Receiver = "RCS",
                    IsSuccess = 0, //是否下发成功 0失败 1成功
                    StartLocat = "",//起始位置
                    StartLocat = startLoction.LocatNo,//起始位置
                    EndLocat = endLocate,//目标位置
                    PalletNo = "",//托盘码
                    PalletNo = palletModel.PalletNo,//托盘码
                    IsSend = 1,//是否可再次下发
                    IsCancel = 1,//是否可取消
                    IsFinish = 1,//是否可完成
@@ -358,29 +360,41 @@
                    string agvMsg = string.Empty;
                    //给下车下发任务
                    logTaskEntry.SendDate = DateTime.Now;//发送时间
                    var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                    if (agvResult)//成功
                    //下发载具类型
                    var bind = RcsHelper.BindPalletAndSite(palletModel.PalletNo, palletModel.LocatNo, bindUrl, out string agvBindMsg);
                    if (bind)
                    {
                        //请求成功修改任务表相应字段状态
                        logTaskEntry.IsSuccess = 1;
                        logTaskEntry.IsSend = 0;
                        //logTaskEntry.IsCancel = 0;
                        logTaskEntry.BackDate = DateTime.Now;
                        logTaskEntry.Status = "1";//正在执行
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                        var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                        if (agvResult)//成功
                        {
                            //请求成功修改任务表相应字段状态
                            logTaskEntry.IsSuccess = 1;
                            logTaskEntry.IsSend = 0;
                            //logTaskEntry.IsCancel = 0;
                            logTaskEntry.BackDate = DateTime.Now;
                            logTaskEntry.Status = "1";//正在执行
                            Db.Updateable(logTaskEntry).ExecuteCommand();
                        startLoction.Status = "3";//出库中
                        Db.Updateable(startLoction).ExecuteCommand();
                            startLoction.Status = "3";//出库中
                            Db.Updateable(startLoction).ExecuteCommand();
                        endLocateInfo.Status = "2";//入库中
                        Db.Updateable(endLocateInfo).ExecuteCommand();
                            endLocateInfo.Status = "2";//入库中
                            Db.Updateable(endLocateInfo).ExecuteCommand();
                        }
                        else//失败
                        {
                            logTaskEntry.IsSuccess = 0;
                            logTaskEntry.Information = agvMsg;
                            Db.Updateable(logTaskEntry).ExecuteCommand();
                        }
                    }
                    else//失败
                    else
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                        logTaskEntry.Information = "货架与货位绑定失败,原因:"+agvBindMsg;
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    }
                }
                //提交事务
                Db.CommitTran();
@@ -405,7 +419,7 @@
        /// <param name="lotNo">批次</param>
        /// <param name="userId">操作人</param>
        /// <exception cref="Exception"></exception>
        public void jiaoCheHopper(string areaNo, string StartLocate, string plnNo, string plnStatus, decimal weight,  string skuNo, string lotNo, string url,int userId)
        public void jiaoCheHopper(string areaNo, string StartLocate, string plnNo, string plnStatus, decimal weight,  string skuNo, string lotNo, string url,string bindUrl,int userId)
        {
            try
            {
@@ -430,11 +444,12 @@
                Db.BeginTran();
                //桶信息
                var pln = Db.Queryable<SysPallets>().First(w => w.IsDel == "0" && w.PalletNo == plnNo);
                var pln = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.LocatNo == StartLocate && w.AreaNo == areaNo);
                if (pln == null)
                {
                    throw new Exception("未查询到桶信息");
                }
                plnNo = pln.PalletNo;
                //起始储位信息
                var startLoction = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.AreaNo == areaNo && m.LocatNo == StartLocate);
@@ -449,10 +464,6 @@
                        throw new Exception("没有查询到物料信息");
                    }
                    skuName = sku.SkuName;
                }
                else if (plnStatus == "3")
                {
                }
                //目标楼层
                var layer = startLoction.Layer;
@@ -490,24 +501,26 @@
                        CompleteTime = DateTime.Now,
                        PalletStatus = plnStatus,
                        Status = "0",
                        Status = "2",
                        InspectMark = "0",
                        BitPalletMark = "0",
                        InspectStatus = "1",
                    };
                    Db.Insertable(stockDetailNew).ExecuteCommand();
                    Db.Updateable(stockDetailNew).ExecuteCommand();
                }
                else
                {
                    stockDetail.PalletStatus = plnStatus;
                    stockDetail.SkuNo = skuNo;
                    stockDetail.SkuName = skuName;
                    stockDetail.LotNo = lotNo;
                    stockDetail.Qty = weight;
                    stockDetail.Status = "2";
                    Db.Updateable(stockDetail).ExecuteCommand();
                }
                //分配储位
                var endLocatInfo = GetLocatModel(house.WareHouseNo, plnStatus, skuNo, pln.Standard);//目标储位
                var endLocatInfo = GetLocatModel(house.WareHouseNo, plnStatus, startLoction.WareHouseNo, skuNo, pln.Standard,lotNo);//目标储位
                //没有可用空储位
                if (endLocatInfo == null)
                {
@@ -550,29 +563,42 @@
                string agvMsg = string.Empty;
                //给下车下发任务
                logTaskEntry.SendDate = DateTime.Now;//发送时间
                var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                if (agvResult)//成功
                //下发载具与货位绑定
                var bind = RcsHelper.BindPalletAndSite(plnNo, StartLocate, bindUrl, out string agvBindMsg);
                if (bind)
                {
                    //请求成功修改任务表相应字段状态
                    logTaskEntry.IsSuccess = 1;
                    logTaskEntry.IsSend = 0;
                    //logTaskEntry.IsCancel = 0;
                    logTaskEntry.BackDate = DateTime.Now;
                    logTaskEntry.Status = "1";//正在执行
                    Db.Insertable(logTaskEntry).ExecuteCommand();
                    var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                    if (agvResult)//成功
                    {
                        //请求成功修改任务表相应字段状态
                        logTaskEntry.IsSuccess = 1;
                        logTaskEntry.IsSend = 0;
                        //logTaskEntry.IsCancel = 0;
                        logTaskEntry.BackDate = DateTime.Now;
                        logTaskEntry.Status = "1";//正在执行
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    startLoction.Status = "3";//出库中
                    Db.Updateable(startLoction).ExecuteCommand();
                        startLoction.Status = "3";//出库中
                        Db.Updateable(startLoction).ExecuteCommand();
                    endLocatInfo.Status = "2";//入库中
                    Db.Updateable(endLocatInfo).ExecuteCommand();
                        endLocatInfo.Status = "2";//入库中
                        Db.Updateable(endLocatInfo).ExecuteCommand();
                    }
                    else//失败
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    }
                }
                else//失败
                else
                {
                    logTaskEntry.IsSuccess = 0;
                    logTaskEntry.Information = agvMsg;
                    Db.Insertable(logTaskEntry).ExecuteCommand();
                    logTaskEntry.Information = "货架与货位绑定失败,原因:"+agvBindMsg;
                    Db.Updateable(logTaskEntry).ExecuteCommand();
                }
                //提交事务
                Db.CommitTran();
@@ -609,10 +635,10 @@
                {
                    throw new Exception($"任务号为:{taskNo}的任务不存在!");
                }
                if (taskInfo.Status != "1" && comeFrom != "WMS")
                {
                    throw new Exception($"任务号为:{taskNo}的任务状态异常");
                }
                //if (taskInfo.Status != "0" && comeFrom != "WMS")
                //{
                //    throw new Exception($"任务号为:{taskNo}的任务状态异常");
                //}
                #endregion
                //开启事务
                Db.BeginTran();
@@ -655,6 +681,7 @@
                    throw new Exception($"目标储位信息不存在");
                }
                endLocatInfo.Status = "1";//有物品
                endLocatInfo.UpdateTime = DateTime.Now;//更新时间
                //修改目标储位状态
                Db.Updateable(endLocatInfo).ExecuteCommand();
@@ -677,7 +704,7 @@
                }
                else if (endAreaInfo.Type == "1")//满桶区
                {
                    stockDetail.PalletStatus = "1";
                    stockDetail.PalletStatus = "2";
                    stockDetail.Status = "0";//待分配
                }
                else if (endAreaInfo.Type == "2")//脏桶区
@@ -688,6 +715,10 @@
                    stockDetail.SkuName = "";
                    stockDetail.Status = "0";//待分配
                    stockDetail.InspectStatus = "0";//待检验
                }
                else if (endAreaInfo.Type == "4")//设备区
                {
                }
                //修改库存明细
                Db.Updateable(stockDetail).ExecuteCommand();
@@ -716,11 +747,283 @@
            }
        }
        private bool YikuTask(string palletNo, string taskNo, string url)
        /// <summary>
        /// 清洗机叫料状态
        /// </summary>
        /// <param name="deviceID">清洗机编号</param>
        /// <param name="deviceStation">叫料点位:”input”-入口(叫脏桶),”output”-出口(净桶申请储位)</param>
        /// <param name="status"></param>
        /// <exception cref="Exception"></exception>
        public void RCSCleanRequest(string deviceID,string deviceStation,string status,string url,string bindUrl)
        {
            try
            {
                if (string.IsNullOrEmpty(deviceID))
                {
                    throw new Exception("清洗机编号不能为空");
                }
                if (status != "1")
                {
                    throw new Exception("非叫料状态");
                }
                switch (deviceStation)
                {
                    case "input"://叫脏桶
                        switch (deviceID)
                        {
                            case "2001":
                                deviceID = "1001";
                                break;
                            case "2002":
                                deviceID = "1003";
                                break;
                            default:
                                throw new Exception("叫脏桶点位异常");
                        }
                        break;
                    case "output"://叫车拉净桶
                        switch (deviceID)
                        {
                            case "2001":
                                deviceID = "1002";
                                break;
                            case "2002":
                                deviceID = "1004";
                                break;
                            default:
                                throw new Exception("叫净桶点位异常");
                        }
                        break;
                    default:
                        throw new Exception("叫料类型异常");
                }
                //通过设备号查找到所属设备(区域)
                var deviceInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode == deviceID);
                if (deviceInfo == null)
                {
                    throw new Exception("设备信息不存在");
                }
                var houseNo = deviceInfo.WareHouseNo;//叫桶设备所属车间编号
                var startLoction = new SysStorageLocat();//起始储位信息
                var endLoction = new SysStorageLocat();//目标储位信息
                var palletModel = new DataStockDetail();//分配桶信息
                string type = "";//叫料类型
                //开启事务
                Db.BeginTran();
                //叫料点位
                switch (deviceStation)
                {
                    case "input"://叫脏桶
                        if (deviceID == "1001" || deviceID == "1003")
                        {
                            type = "3";
                            //叫桶设备所在储位信息(目标储位)
                            endLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo);
                            // 所有待分配的脏桶
                            var stockDetail = Db.Queryable<DataStockDetail>().Where(w => w.Status == "0" && w.PalletStatus == "3").OrderByDescending(w => w.UpdateTime).ToList();
                            //判断当前清洗机设备上有几个脏桶,status:2 正在清洗的脏桶(状态触发变更为AGV叫第2个脏桶时触发)
                            int ztQty = Db.Queryable<DataStockDetail>().Count(w => w.IsDel == "0" && w.Status == "2" && w.LocatNo == deviceID);
                            if (ztQty == 1)
                            {
                                throw new Exception((deviceID == "1001"?"1":"2") + "号清洗机脏桶已满,重复叫料!");
                            }
                            //先查看叫料设备位是否有脏桶
                            if (endLoction.Status == "1")
                            {
                                //有脏桶的话,将更改此桶状态(代表此桶正在清洗中)
                                var qxStock = Db.Queryable<DataStockDetail>().Where(w => w.LocatNo == endLoction.LocatNo).First();
                                qxStock.Status = "2";
                                qxStock.UpdateTime = DateTime.Now;//清洗时间
                                Db.Updateable(qxStock).ExecuteCommand();
                                //更改设备储位状态为空储位
                                endLoction.Status = "0";
                                Db.Updateable(endLoction).ExecuteCommand();
                            }
                            //优先查找脏桶缓存车间
                            palletModel = stockDetail.Where(w => w.AreaNo == "C54").FirstOrDefault();
                            if (palletModel == null)//脏桶缓存车间没有脏桶,再从三楼中间站脏桶区查找
                            {
                                palletModel = stockDetail.Where(w => w.WareHouseNo == "M16" && w.AreaNo == "C26").FirstOrDefault();
                            }
                            if (palletModel == null)//三楼中间站脏桶区没有脏桶,再从四楼中间站脏桶区查找
                            {
                                palletModel = stockDetail.Where(w => w.WareHouseNo == "M01" && w.AreaNo == "C03").FirstOrDefault();
                            }
                            if (palletModel == null)
                            {
                                throw new Exception("无脏桶可分配");
                            }
                            //起始储位地址信息
                            startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.Status == "1" && w.LocatNo == palletModel.LocatNo);
                            if (startLoction == null)
                            {
                                throw new Exception($"起始目标储位信息不存在,桶号:{palletModel.LocatNo}");
                            }
                        }
                        else
                        {
                            throw new Exception("起始目标储位信息不存在");
                        }
                        break;
                    case "output"://净桶申请储位
                        if (deviceID == "1002" || deviceID == "1004")
                        {
                            type = "4";
                            //叫桶设备所在储位信息(起始储位)
                            startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo);
                            //获取清洗机上第一次叫的脏桶
                            string locate = deviceID == "1002"?"1001":"1003";
                            palletModel = Db.Queryable<DataStockDetail>().Where(w => w.LocatNo == locate && (w.Status == "2" || w.Status == "0")).OrderBy(o => o.CreateTime).First();
                            if (palletModel == null)
                            {
                                throw new Exception("未找到库存中正在清洗的脏桶");
                            }
                            if (!string.IsNullOrEmpty(palletModel.LocatNo))
                            {
                                palletModel.LocatNo = startLoction.LocatNo;
                                palletModel.PalletStatus = "0";
                                palletModel.Status = "0";
                                Db.Updateable(palletModel).ExecuteCommand();
                            }
                            //分配储位
                            //查找所有净桶储位
                            var jtLocate = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0")
                                                .OrderBy(w => w.Row).OrderByDescending(w => w.Column).ToList();
                            if (jtLocate.Count == 0)
                            {
                                throw new Exception("没有空余的净桶储位");
                            }
                            //优先分配四楼中间站净桶区
                            //endLoction = jtLocate.Where(w => w.WareHouseNo == "M01" && w.AreaNo == "C01")
                            //                    .OrderBy(w => w.Row).OrderByDescending(w => w.Column).FirstOrDefault();
                            //if (endLoction == null)//四楼中间站净桶区没有空储位,再从三楼中间站净桶区查找
                            //{
                            endLoction = jtLocate.Where(w => w.WareHouseNo == "M16" && w.AreaNo == "C24")
                                                .OrderBy(w => w.Row).OrderByDescending(w => w.Column).FirstOrDefault();
                            //}
                            if (endLoction == null)//三楼中间站净桶区没有空储位,再从三楼清洗间缓存区查找             PS:小车现在还不支持清洗机直接送往4楼净桶区
                            {
                                endLoction = jtLocate.Where(w => w.WareHouseNo == "M44" && w.AreaNo == "C55")
                                                .OrderBy(w => w.Row).OrderByDescending(w => w.Column).FirstOrDefault();
                            }
                            if (endLoction == null)
                            {
                                throw new Exception("未查询到合适储位");
                            }
                            //string startlono = startLoction.LocatNo == "1001" ? "1002" : "1004";//清洗完成点位
                            //startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == startlono);
                            //if (startLoction == null)
                            //{
                            //    throw new Exception("未找到清洗起始点位");
                            //}
                        }
                        else
                        {
                            throw new Exception("起始目标储位信息不存在");
                        }
                        break;
                    default:
                        throw new Exception("叫料点位异常");
                }
                var taskNo = new Common().GetMaxNo("TK");
                //添加任务
                var logTaskEntry = new LogTask
                {
                    TaskNo = taskNo,
                    Sender = "WMS",
                    Receiver = "RCS",
                    IsSuccess = 0, //是否下发成功 0失败 1成功
                    StartLocat = startLoction.LocatNo,//起始位置
                    EndLocat = endLoction.LocatNo,//目标位置
                    PalletNo = palletModel.PalletNo,//托盘码
                    IsSend = 1,//是否可再次下发
                    IsCancel = 1,//是否可取消
                    IsFinish = 1,//是否可完成
                    Type = "1",//任务类型 0 入库任务 1 出库任务  2 移库任务
                    Status = "0",//任务状态0:等待执行1正在执行2执行完成
                    OrderType = "3",//0 入库单 1 出库单  2 盘点单  3 移库单
                    CreateTime = DateTime.Now
                };
                Db.Insertable(logTaskEntry).ExecuteCommand();
                //组织下发小车任务信息
                var task = new TaskDetial
                {
                    Taskno = taskNo,//任务号
                    Startport = palletModel.LocatNo,//起始位置
                    Endport = endLoction.LocatNo,//目标位置
                    Pallno = palletModel.PalletNo,//桶号
                    Crtype = type,//叫桶
                };
                string agvMsg = string.Empty;
                //给下车下发任务
                logTaskEntry.SendDate = DateTime.Now;//发送时间
                //下发载具与货位绑定
                var bind = RcsHelper.BindPalletAndSite(palletModel.PalletNo, palletModel.LocatNo, bindUrl, out string agvBindMsg);
                if (bind)
                {
                    var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                    if (agvResult)//成功
                    {
                        //请求成功修改任务表相应字段状态
                        logTaskEntry.IsSuccess = 1;
                        logTaskEntry.IsSend = 0;
                        //logTaskEntry.IsCancel = 0;
                        logTaskEntry.BackDate = DateTime.Now;
                        logTaskEntry.Status = "1";//正在执行
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                        startLoction.Status = "3";//出库中
                        Db.Updateable(startLoction).ExecuteCommand();
                        endLoction.Status = "2";//入库中
                        Db.Updateable(endLoction).ExecuteCommand();
                    }
                    else//失败
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    }
                }
                else
                {
                    logTaskEntry.IsSuccess = 0;
                    logTaskEntry.Information = agvBindMsg;
                    Db.Updateable(logTaskEntry).ExecuteCommand();
                }
                //提交事务
                Db.CommitTran();
            }
            catch (Exception e)
            {
                //回滚事务
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        private bool YikuTask(string palletNo, string taskNo, string url,string bindUrl)
        {
            try
            {
                bool t = false;
                //分配桶的库存信息
                var palletInfo = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                if (palletInfo == null)
@@ -809,36 +1112,55 @@
                        string agvMsg = string.Empty;
                        //给下车下发任务
                        logTaskEntry.SendDate = DateTime.Now;//发送时间
                        var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg, "70");
                        if (agvResult)//成功
                        //下发载具与货位绑定
                        var bind = RcsHelper.BindPalletAndSite(palletInfoYi.LocatNo, palletInfoYi.PalletNo, bindUrl, out string agvBindMsg);
                        if (bind)
                        {
                            //请求成功修改任务表相应字段状态
                            logTaskEntry.IsSuccess = 1;
                            logTaskEntry.IsSend = 0;
                            //logTaskEntry.IsCancel = 0;
                            logTaskEntry.BackDate = DateTime.Now;
                            logTaskEntry.Status = "1";//正在执行
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg, "70");
                            if (agvResult)//成功
                            {
                                //请求成功修改任务表相应字段状态
                                logTaskEntry.IsSuccess = 1;
                                logTaskEntry.IsSend = 0;
                                //logTaskEntry.IsCancel = 0;
                                logTaskEntry.BackDate = DateTime.Now;
                                logTaskEntry.Status = "1";//正在执行
                                Db.Updateable(logTaskEntry).ExecuteCommand();
                            //修改移出储位状态
                            locatInfo.Status = "5";//移出中
                            Db.Updateable(locatInfo).ExecuteCommand();
                                //修改移出储位状态
                                locatInfo.Status = "5";//移出中
                                Db.Updateable(locatInfo).ExecuteCommand();
                            //修改移入储位状态
                            transferLocat.Status = "4";//移入中
                            Db.Updateable(transferLocat).ExecuteCommand();
                                //修改移入储位状态
                                transferLocat.Status = "4";//移入中
                                Db.Updateable(transferLocat).ExecuteCommand();
                            }
                            else//失败
                            {
                                logTaskEntry.IsSuccess = 0;
                                logTaskEntry.Information = agvMsg;
                                Db.Updateable(logTaskEntry).ExecuteCommand();
                                throw new Exception($"给小车下发移库任务失败,桶号:{palletInfoYi.PalletNo}");
                            }
                        }
                        else//失败
                        else
                        {
                            logTaskEntry.IsSuccess = 0;
                            logTaskEntry.Information = agvMsg;
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            logTaskEntry.Information = agvBindMsg;
                            Db.Updateable(logTaskEntry).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{palletInfoYi.PalletNo}");
                        }
                        t = true;
                    }
                    else
                    {
                        return t;
                    }
                }
                return true;
                return t;
            }
            catch (Exception e)
            {
@@ -851,7 +1173,7 @@
        /// <param name="taskNo"></param>
        /// <param name="url"></param>
        /// <exception cref="Exception"></exception>
        public void OutBinAgv(string taskNo,string url)
        public void OutBinAgv(string taskNo,string url, string bindUrl)
        {
            try
            {
@@ -859,7 +1181,7 @@
                Db.BeginTran();
                //查找任务信息
                var logTaskInfo = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.TaskNo == taskNo);
                var logTaskInfo = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "0" && w.TaskNo == taskNo);
                if (logTaskInfo == null)
                {
                    throw new Exception("未查询到该任务");
@@ -904,34 +1226,49 @@
                    string agvMsg = string.Empty;
                    //给下车下发任务
                    logTaskInfoZ.SendDate = DateTime.Now;//发送时间
                    var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg, "70");
                    if (agvResult)//成功
                    //下发载具与货们绑定
                    var bind = RcsHelper.BindPalletAndSite(logTaskInfoZ.PalletNo, logTaskInfoZ.StartLocat, bindUrl, out string agvBindMsg);
                    if (bind)
                    {
                        //请求成功修改任务表相应字段状态
                        logTaskInfoZ.IsSuccess = 1;
                        logTaskInfoZ.IsSend = 0;
                        //logTaskEntry.IsCancel = 0;
                        logTaskInfoZ.BackDate = DateTime.Now;
                        logTaskInfoZ.Status = "1";//正在执行
                        Db.Insertable(logTaskInfoZ).ExecuteCommand();
                        var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg, "70");
                        if (agvResult)//成功
                        {
                            //请求成功修改任务表相应字段状态
                            logTaskInfoZ.IsSuccess = 1;
                            logTaskInfoZ.IsSend = 0;
                            //logTaskEntry.IsCancel = 0;
                            logTaskInfoZ.BackDate = DateTime.Now;
                            logTaskInfoZ.Status = "1";//正在执行
                            Db.Updateable(logTaskInfoZ).ExecuteCommand();
                        //修改移出储位状态
                        startLocatInfoZ.Status = "5";//移出中
                        Db.Updateable(startLocatInfoZ).ExecuteCommand();
                            //修改移出储位状态
                            startLocatInfoZ.Status = "5";//移出中
                            Db.Updateable(startLocatInfoZ).ExecuteCommand();
                        //修改移入储位状态
                        endLocatInfoZ.Status = "4";//移入中
                        Db.Updateable(endLocatInfoZ).ExecuteCommand();
                            //修改移入储位状态
                            endLocatInfoZ.Status = "4";//移入中
                            Db.Updateable(endLocatInfoZ).ExecuteCommand();
                        }
                        else//失败
                        {
                            logTaskInfoZ.IsSuccess = 0;
                            logTaskInfoZ.Information = agvMsg;
                            Db.Updateable(logTaskInfoZ).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{logTaskInfoZ.PalletNo}");
                        }
                    }
                    else//失败
                    else
                    {
                        logTaskInfoZ.IsSuccess = 0;
                        logTaskInfoZ.Information = agvMsg;
                        Db.Insertable(logTaskInfoZ).ExecuteCommand();
                        logTaskInfoZ.Information = agvBindMsg;
                        Db.Updateable(logTaskInfoZ).ExecuteCommand();
                        throw new Exception($"给小车下发移库任务失败,桶号:{logTaskInfoZ.PalletNo}");
                    }
                }
                Db.CommitTran();
            }
            catch (Exception e)
            {
@@ -946,7 +1283,7 @@
        /// </summary>
        /// <param name="url"></param>
        /// <exception cref="Exception"></exception>
        public void TransferBackTimer(string url)
        public void TransferBackTimer(string url,string bindUrl)
        {
            try
            {
@@ -979,7 +1316,7 @@
                            continue;
                        }
                        //分配储位
                        var endLocatInfo = GetLocatModel(itemHouseNo,detailInfo.PalletStatus,detailInfo.SkuNo,detailInfo.Standard);//目标储位
                        var endLocatInfo = GetLocatModel(itemHouseNo,detailInfo.PalletStatus,"",detailInfo.SkuNo,detailInfo.Standard,detailInfo.LotNo);//目标储位
                        //没有可用空储位
                        if (endLocatInfo == null)
                        {
@@ -1019,36 +1356,49 @@
                            Crtype = "2"//叫桶
                        };
                        string agvMsg = string.Empty;
                        //给下车下发任务
                        //给下车下发任务            s
                        logTaskEntry.SendDate = DateTime.Now;//发送时间
                        var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                        if (agvResult)//成功
                        //下发载具与货位绑定
                        var bind = RcsHelper.BindPalletAndSite(detailInfo.PalletNo, detailInfo.LocatNo, bindUrl, out string agvBindMsg);
                        if (bind)
                        {
                            //请求成功修改任务表相应字段状态
                            logTaskEntry.IsSuccess = 1;
                            logTaskEntry.IsSend = 0;
                            //logTaskEntry.IsCancel = 0;
                            logTaskEntry.BackDate = DateTime.Now;
                            logTaskEntry.Status = "1";//正在执行
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            var agvResult = RcsHelper.CreateTaskForAgv(task, url, out agvMsg);
                            if (agvResult)//成功
                            {
                                //请求成功修改任务表相应字段状态
                                logTaskEntry.IsSuccess = 1;
                                logTaskEntry.IsSend = 0;
                                //logTaskEntry.IsCancel = 0;
                                logTaskEntry.BackDate = DateTime.Now;
                                logTaskEntry.Status = "1";//正在执行
                                Db.Updateable(logTaskEntry).ExecuteCommand();
                            //修改移出储位状态
                            locatModel.Status = "5";//移出中
                            Db.Updateable(locatModel).ExecuteCommand();
                                //修改移出储位状态
                                locatModel.Status = "5";//移出中
                                Db.Updateable(locatModel).ExecuteCommand();
                            //修改移入储位状态
                            endLocatInfo.Status = "4";//移入中
                            Db.Updateable(endLocatInfo).ExecuteCommand();
                                //修改移入储位状态
                                endLocatInfo.Status = "4";//移入中
                                Db.Updateable(endLocatInfo).ExecuteCommand();
                            }
                            else//失败
                            {
                                logTaskEntry.IsSuccess = 0;
                                logTaskEntry.Information = agvMsg;
                                Db.Updateable(logTaskEntry).ExecuteCommand();
                                throw new Exception($"给小车下发移库任务失败,桶号:{detailInfo.PalletNo}");
                            }
                        }
                        else//失败
                        else
                        {
                            logTaskEntry.IsSuccess = 0;
                            logTaskEntry.Information = agvMsg;
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            logTaskEntry.Information = agvBindMsg;
                            Db.Updateable(logTaskEntry).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{detailInfo.PalletNo}");
                        }
                    }
                }
                //提交事务
@@ -1071,7 +1421,7 @@
        /// <param name="standard">桶规格</param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        private SysStorageLocat GetLocatModel(string houseNo, string palletStatus,string skuNo="",string standard="")
        private SysStorageLocat GetLocatModel(string houseNo, string palletStatus,string zonghong,string skuNo="",string standard="",string lotNo = "")
        {
            try
            {
@@ -1088,44 +1438,88 @@
                                            .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First();
                        break;
                    case "2"://满桶
                             //查到到满桶区域编号
                        areaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.Type == "1").Select(s => s.AreaNo).First();
                        //分配储位
                        //先查到同物料的组
                        string sql = $@"select Row from SysStorageLocat where WareHouseNo='{houseNo}' and AreaNo='{areaNo}' and LocatNo in(
                                               select LocatNo from DataStockDetail where SkuNo='{skuNo}' and Standard='{standard}' and WareHouseNo='{houseNo}' and AreaNo='{areaNo}'
                                            ) group by Row";
                        List<int> RowList = Db.Ado.SqlQuery<int>(sql).ToList();
                        foreach (var rowItem in RowList)
                        //总混分配储位 (仓库编码M12,M13),分配逻辑:优先分配同物料的组,再分配到3楼中间站,最后分配到4楼中间站
                        if (zonghong == "M12" || zonghong == "M13")
                        {
                            endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                           && w.WareHouseNo == houseNo && w.AreaNo == areaNo && w.Row == rowItem)
                                           .OrderByDescending(o => o.Column).First();
                            //先查到同物料的组
                            string sql = $@"select Row,AreaNo from SysStorageLocat where LocatNo in(
                                                   select LocatNo from DataStockDetail where SkuNo='{skuNo}' and LotNo = '{lotNo}' and Standard='{standard}'
                                                    and AreaNo in ('C02','C25')
                                                ) group by Row,AreaNo";
                            var RowList = Db.Ado.SqlQuery<TableMan>(sql).ToList();
                            if (endLocatInfo != null)
                            foreach (var rowItem in RowList)
                            {
                                break;
                                endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.Row == rowItem.Row && w.AreaNo == rowItem.AreaNo  && (w.WareHouseNo == "M01"||w.WareHouseNo == "M16"))
                                               .OrderByDescending(o => o.Column).First();
                                if (endLocatInfo.LocatNo != null)
                                {
                                    break;
                                }
                            }
                            //没有找到相同物料同组的空储位
                            if (endLocatInfo.LocatNo == null)
                            {
                                endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                                && (w.AreaNo == "C02" || w.AreaNo == "C25"))
                                               .OrderBy(o=>o.Layer).OrderByDescending(o => o.Column).OrderBy(o => o.Row).First();
                            }
                        }
                        else {//其他区域
                            //查到到满桶区域编号
                            areaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.Type == "1").Select(s => s.AreaNo).First();
                            //分配储位
                            //先查到同物料的组
                            string sql = $@"select Row,AreaNo from SysStorageLocat where WareHouseNo='{houseNo}' and AreaNo='{areaNo}' and Status = '0' and LocatNo in(
                                                   select LocatNo from DataStockDetail where SkuNo='{skuNo}' and LotNo = '{lotNo}' and Standard='{standard}' and WareHouseNo='{houseNo}' and AreaNo='{areaNo}'
                                                ) group by Row,AreaNo";
                            var RowList = Db.Ado.SqlQuery<TableMan>(sql).ToList();
                            foreach (var rowItem in RowList)
                            {
                                endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                               && w.WareHouseNo == houseNo && w.AreaNo == areaNo && w.Row == rowItem.Row && w.AreaNo == rowItem.AreaNo && (w.WareHouseNo == "M01" || w.WareHouseNo == "M16"))
                                               .OrderByDescending(o => o.Column).First();
                                if (endLocatInfo.LocatNo != null)
                                {
                                    break;
                                }
                            }
                            //没有找到相同物料同组的空储位
                            if (endLocatInfo.LocatNo == null)
                            {
                                endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                               && w.WareHouseNo == houseNo && w.AreaNo == areaNo)
                                               .OrderByDescending(o => o.Column).OrderBy(o => o.Row).First();
                            }
                        }
                        //没有找到相同物料同组的空储位
                        if (endLocatInfo == null)
                        {
                            endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                           && w.WareHouseNo == houseNo && w.AreaNo == areaNo)
                                           .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First();
                        }
                        break;
                    case "3"://脏桶
                             //查到到脏桶区域编号
                        areaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.Type == "2").Select(s => s.AreaNo).First();
                        //查到到脏桶区域编号,存放顺序,C54 料斗清洗暂存间,C26 3楼中间站脏桶区,C03 4楼中间站脏桶区
                        var ztAreaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Type == "2").Select(w => w.AreaNo).ToList();
                        //查找所有可用脏桶库位
                        var ztLocat = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && ztAreaNo.Contains(w.AreaNo))
                            .OrderBy(o => o.Row).OrderByDescending(o => o.Column).ToList();
                        //areaNo = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.Type == "2").Select(s => s.AreaNo).First();
                        //分配储位
                        endLocatInfo = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                            && w.WareHouseNo == houseNo && w.AreaNo == areaNo)
                                            .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First();
                        //料斗清洗暂存间
                        endLocatInfo = ztLocat.Where(w => w.AreaNo == "C54").FirstOrDefault();
                        if (endLocatInfo == null)
                        {
                            endLocatInfo = ztLocat.Where(w => w.AreaNo == "C26").FirstOrDefault();
                            if (endLocatInfo == null)
                            {
                                endLocatInfo = ztLocat.Where(w => w.AreaNo == "C03").FirstOrDefault();
                                if (endLocatInfo == null)
                                {
                                    throw new Exception("无可用脏桶库位");
                                }
                            }
                        }
                        break;
                }
                return endLocatInfo;