zhaowc
20 小时以前 35e3dae48db445e66c9614ee55dba062659e33d7
Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -1052,7 +1052,7 @@
        /// <param name="taskNo"></param>
        /// <param name="userId"></param>
        /// <exception cref="Exception"></exception>
        public void CancelTask(string taskNo, int userId)
        public void CancelTask(string taskNo, string url, int userId)
        {
            try
            {
@@ -1063,6 +1063,20 @@
                if (task == null)
                {
                    throw new Exception("未查询到任务信息");
                }
                //校验起点是否已经生成任务
                var taskHave = Db.Queryable<LogTask>().First(m => m.EndLocat == task.StartLocat && m.IsDel == "0" && (m.Status == "0"|| m.Status == "1"));
                if (taskHave == null)
                {
                    var locateHave = Db.Queryable<SysStorageLocat>().First(m => m.LocatNo == task.StartLocat);
                    if (locateHave.Status != "3")
                    {
                        throw new Exception("起始储位已有其他料斗存在,无法取消当前任务!");
                    }
                }
                else
                {
                    throw new Exception("起始储位已有任务生成,无法取消当前任务!");
                }
                //if (task.Status != "0")
                //{
@@ -1103,10 +1117,19 @@
                }
                stockDetail.Status = "0";//待分配
                Db.Updateable(stockDetail).ExecuteCommand();
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("库内作业", "库内日志", taskNo, "取消", $"点击取消按钮、取消了任务号为:{taskNo}的任务", userId);
                Db.CommitTran();
                string agvMsg = "";
                bool t = CancleTaskForAgv(taskNo, url, out agvMsg);
                if (t)
                {
                    //添加操作日志记录
                    var k = new OperationCrServer().AddLogOperationCr("库内作业", "库内日志", taskNo, "取消", $"点击取消按钮、取消了任务号为:{taskNo}的任务", userId);
                    Db.CommitTran();
                }
                else
                {
                    throw new Exception("下发取消小车任务失败");
                }
            }
            catch (Exception e)
            {
@@ -1327,6 +1350,43 @@
        }
        /// <summary>
        /// 下发取消任务给AGV
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public bool CancleTaskForAgv(string taskno, string url, out string agvMsg, string priority = null)
        {
            bool result = false;
            #region 呼叫小车代码
            AgvCancelTask cancelTask = new AgvCancelTask();
            cancelTask.robotTaskCode = taskno;
            cancelTask.cancelType = "DROP";
            // 正式运行程序放开
            //AGV任务下发时增加hearder:X-LR-REQUEST-ID,值为随机数
            long ran = DateTime.Now.Ticks;
            Dictionary<string, string> key = new Dictionary<string, string>();
            key.Add("X-LR-REQUEST-ID", ran.ToString());
            var jsonData = JsonConvert.SerializeObject(cancelTask);
            string response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV", key);
            //解析返回数据
            var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
            if (agvModel.Code == "SUCCESS")
            {
                result = true;//给下车下发任务成功
                agvMsg = "";
            }
            else
            {
                var logStr = $@".\log\AGV\AGV取消任务" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                LogFile.SaveLogToFile($"AGV取消任务异常:( {agvModel.Message} ),", logStr);
                agvMsg = agvModel.Message;
            }
            return result;
            #endregion
        }
        /// <summary>
        /// 分配桶后判断该桶外侧储位是否需要移库
        /// </summary>
        /// <param name="palletNo"></param>
@@ -1484,5 +1544,60 @@
                throw new Exception(e.Message);
            }
        }
        public bool DelStockWms(int stockId,string url,int userId,out string errMsg)
        {
            try
            {
                errMsg = "";
                //获取当前库存信息
                var stock = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.Id == stockId);
                if (stock == null)
                {
                    throw new Exception("未在库存中找到当前料桶");
                }
                //获取当前料斗任务信息
                var taskInfo = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == stock.PalletNo && (w.Status == "0" || w.Status == "1"));
                if (taskInfo != null)
                {
                    throw new Exception("当前料桶有等待执行或正在执行的任务");
                }
                //获取当前料斗储位状态
                var locatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == stock.LocatNo && w.Status == "1");
                if (locatInfo == null)
                {
                    throw new Exception("当前料桶储位状态错误");
                }
                var pallnoInfo = Db.Queryable<SysPallets>().First(w => w.IsDel == "0" && w.PalletNo == stock.PalletNo);
                if (pallnoInfo == null)
                {
                    throw new Exception("未找到当前料桶条码");
                }
                Db.BeginTran();
                //下发给AGV解绑信息
                bool t = RcsHelper.UnBindPalletAndSite(stock.PalletNo, stock.LocatNo, url,out errMsg);
                if (t)
                {
                    //删除库存
                    Db.Deleteable(stock).ExecuteCommand();
                    Db.Deleteable(pallnoInfo).ExecuteCommand();
                    locatInfo.Status = "0";
                    Db.Updateable(locatInfo).ExecuteCommand();
                    //添加操作日志记录
                    var k = new OperationCrServer().AddLogOperationCr("统计报表", "桶明细", "", "删除", $"点击删除按钮、删除了桶号:{stock.PalletNo}", userId);
                }
                Db.CommitTran();
                return t;
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
    }
}