zhaowc
2025-05-20 d09a1552e45e6cfc8f83c0249cd296b8706c0dc2
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
            {
@@ -306,7 +306,7 @@
                    {
                        throw new Exception("未找到对应桶信息");
                    }
                    resultYi = YikuTask(palletModel.PalletNo, taskNo, url);
                    resultYi = YikuTask(palletModel.PalletNo, taskNo, url,bindUrl);
                }
                #endregion
                //起始储位地址信息
@@ -358,29 +358,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, url, 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.Insertable(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.Insertable(logTaskEntry).ExecuteCommand();
                        }
                    }
                    else//失败
                    else
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        logTaskEntry.Information = "货架与货位绑定失败,原因:"+agvBindMsg;
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                    }
                }
                //提交事务
                Db.CommitTran();
@@ -405,7 +417,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
            {
@@ -550,29 +562,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.Insertable(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.Insertable(logTaskEntry).ExecuteCommand();
                    }
                }
                else//失败
                else
                {
                    logTaskEntry.IsSuccess = 0;
                    logTaskEntry.Information = agvMsg;
                    logTaskEntry.Information = "货架与货位绑定失败,原因:"+agvBindMsg;
                    Db.Insertable(logTaskEntry).ExecuteCommand();
                }
                //提交事务
                Db.CommitTran();
@@ -720,8 +745,192 @@
            }
        }
        /// <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("非叫料状态");
                }
                //通过设备号查找到所属设备(区域)
                var deviceInfo = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode == deviceID);
                if (deviceInfo == null)
                {
                    throw new Exception("设备信息不存在");
                }
                var houseNo = deviceInfo.WareHouseNo;//叫桶设备所属车间编号
        private bool YikuTask(string palletNo, string taskNo, string url)
                var startLoction = new SysStorageLocat();//起始储位信息
                var endLoction = new SysStorageLocat();//目标储位信息
                var palletModel = new DataStockDetail();//分配桶信息
                //开启事务
                Db.BeginTran();
                //叫料点位
                switch (deviceStation)
                {
                    case "input"://叫脏桶
                        //叫桶设备所在储位信息(目标储位)
                        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");
                        //优先查找脏桶缓存车间
                        palletModel = stockDetail.Where(w => w.AreaNo == "C43").OrderByDescending(o => o.UpdateTime).First();
                        if (palletModel == null)//脏桶缓存车间没有脏桶,再从三楼中间站脏桶区查找
                        {
                            palletModel = stockDetail.Where(w =>w.WareHouseNo=="M16" && w.AreaNo == "C26").OrderByDescending(o => o.UpdateTime).First();
                        }
                        if (palletModel == null)//三楼中间站脏桶区没有脏桶,再从四楼中间站脏桶区查找
                        {
                            palletModel = stockDetail.Where(w => w.WareHouseNo == "M01" && w.AreaNo == "C03").OrderByDescending(o => o.UpdateTime).First();
                        }
                        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}");
                        }
                        break;
                    case "output"://净桶申请储位
                        //叫桶设备所在储位信息(起始储位)
                        startLoction = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.WareHouseNo == houseNo && w.AreaNo == deviceInfo.AreaNo);
                        //桶信息
                        palletModel = Db.Queryable<DataStockDetail>().Where(w => w.WareHouseNo==houseNo && w.AreaNo==deviceInfo.AreaNo && w.LocatNo==startLoction.LocatNo).First();
                        if (palletModel == null)
                        {
                            throw new Exception("未查询到净桶信息");
                        }
                        //分配储位
                        //优先分配四楼中间站净桶区
                        endLoction= Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                            && w.WareHouseNo == "M01" && w.AreaNo == "C01")
                                            .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First();
                        if (endLoction == null)//四楼中间站净桶区没有空储位,再从三楼中间站净桶区查找
                        {
                            endLoction = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                            && w.WareHouseNo == "M16" && w.AreaNo == "C24")
                                            .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First();
                        }
                        if (endLoction == null)//三楼中间站净桶区没有空储位,再从三楼清洗间缓存区查找
                        {
                            endLoction = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0"
                                            && w.WareHouseNo == "M44" && w.AreaNo == "C55")
                                            .OrderBy(o => o.Row).OrderByDescending(o => o.Column).First();
                        }
                        if (endLoction == null)
                        {
                            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 = "",//起始位置
                    EndLocat = endLoction.LocatNo,//目标位置
                    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 = "1",//叫桶
                };
                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.Insertable(logTaskEntry).ExecuteCommand();
                        startLoction.Status = "3";//出库中
                        Db.Updateable(startLoction).ExecuteCommand();
                        endLoction.Status = "2";//入库中
                        Db.Updateable(endLoction).ExecuteCommand();
                    }
                    else//失败
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                    }
                }
                else
                {
                    logTaskEntry.IsSuccess = 0;
                    logTaskEntry.Information = agvBindMsg;
                    Db.Insertable(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
            {
@@ -813,33 +1022,47 @@
                        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.Insertable(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.Insertable(logTaskEntry).ExecuteCommand();
                                throw new Exception($"给小车下发移库任务失败,桶号:{palletInfoYi.PalletNo}");
                            }
                        }
                        else//失败
                        else
                        {
                            logTaskEntry.IsSuccess = 0;
                            logTaskEntry.Information = agvMsg;
                            logTaskEntry.Information = agvBindMsg;
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{palletInfoYi.PalletNo}");
                        }
                    }
                }
                return true;
@@ -855,7 +1078,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
            {
@@ -908,33 +1131,47 @@
                    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.Insertable(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.Insertable(logTaskInfoZ).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{logTaskInfoZ.PalletNo}");
                        }
                    }
                    else//失败
                    else
                    {
                        logTaskInfoZ.IsSuccess = 0;
                        logTaskInfoZ.Information = agvMsg;
                        logTaskInfoZ.Information = agvBindMsg;
                        Db.Insertable(logTaskInfoZ).ExecuteCommand();
                        throw new Exception($"给小车下发移库任务失败,桶号:{logTaskInfoZ.PalletNo}");
                    }
                }
            }
            catch (Exception e)
@@ -950,7 +1187,7 @@
        /// </summary>
        /// <param name="url"></param>
        /// <exception cref="Exception"></exception>
        public void TransferBackTimer(string url)
        public void TransferBackTimer(string url,string bindUrl)
        {
            try
            {
@@ -1025,34 +1262,47 @@
                        string agvMsg = string.Empty;
                        //给下车下发任务
                        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.Insertable(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.Insertable(logTaskEntry).ExecuteCommand();
                                throw new Exception($"给小车下发移库任务失败,桶号:{detailInfo.PalletNo}");
                            }
                        }
                        else//失败
                        else
                        {
                            logTaskEntry.IsSuccess = 0;
                            logTaskEntry.Information = agvMsg;
                            logTaskEntry.Information = agvBindMsg;
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{detailInfo.PalletNo}");
                        }
                    }
                }
                //提交事务