zhaowc
10 小时以前 71d1dcdf796f08fa01cbc2d3faab86eea28b295b
Wms/WMS.BLL/BllTransServer/RcsServer.cs
@@ -7,6 +7,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
@@ -336,7 +338,7 @@
                                        //logTaskEntry2.IsCancel = 0;
                                        logTaskEntry2.BackDate = DateTime.Now;
                                        logTaskEntry2.Status = "1";
                                        Db.Insertable(logTaskEntry2).ExecuteCommand();
                                        Db.Updateable(logTaskEntry2).ExecuteCommand();
                                        startLoction2.Status = "3";//出库中
                                        Db.Updateable(startLoction2).ExecuteCommand();
@@ -348,7 +350,7 @@
                                    {
                                        logTaskEntry2.IsSuccess = 0;
                                        logTaskEntry2.Information = agvMsg;
                                        Db.Insertable(logTaskEntry2).ExecuteCommand();
                                        Db.Updateable(logTaskEntry2).ExecuteCommand();
                                    }
                                    //提交事务
@@ -412,7 +414,7 @@
                        //logTaskEntry.IsCancel = 0;
                        logTaskEntry.BackDate = DateTime.Now;
                        logTaskEntry.Status = "1";//正在执行
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                        startLoction.Status = "3";//出库中
                        Db.Updateable(startLoction).ExecuteCommand();
@@ -424,7 +426,7 @@
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    }
                    //提交事务
@@ -704,7 +706,7 @@
                        //logTaskEntry.IsCancel = 0;
                        logTaskEntry.BackDate = DateTime.Now;
                        logTaskEntry.Status = "1";//正在执行
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                        deviceLocatInfo.Status = "3";//出库中
                        Db.Updateable(deviceLocatInfo).ExecuteCommand();
@@ -716,7 +718,7 @@
                    {
                        logTaskEntry.IsSuccess = 0;
                        logTaskEntry.Information = agvMsg;
                        Db.Insertable(logTaskEntry).ExecuteCommand();
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    }
                    //提交事务
                    Db.CommitTran();
@@ -941,17 +943,12 @@
                    stockDetail.PalletStatus = "0";
                    stockDetail.Status = "0";//待分配
                }
                else if (endAreaInfo.Type == "1")//预混区
                {
                    stockDetail.PalletStatus = "1";
                    stockDetail.Status = "0";//待分配
                }
                else if (endAreaInfo.Type == "2")//半成品区
                else if (endAreaInfo.Type == "1")//满桶
                {
                    stockDetail.PalletStatus = "2";
                    stockDetail.Status = "0";//待分配
                }
                else if (endAreaInfo.Type == "3")//脏桶区
                else if (endAreaInfo.Type == "2")//脏桶区
                {
                    stockDetail.PalletStatus = "3";
                    stockDetail.LotNo = "";//批次
@@ -1055,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
            {
@@ -1066,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")
                //{
@@ -1097,21 +1108,28 @@
                }
                locatEnd.Status = "0"; //空储位
                Db.Updateable(locatEnd).ExecuteCommand();
                if (task.Type == "1")//出库任务
                //修改库存明细
                var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == task.PalletNo);
                if (stockDetail == null)
                {
                    //修改库存明细
                    var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == task.PalletNo && w.Status == "2");
                    if (stockDetail == null)
                    {
                        throw new Exception("未查询到该桶库存信息,请检查!");
                    }
                    stockDetail.Status = "0";//待分配
                    Db.Updateable(stockDetail).ExecuteCommand();
                    throw new Exception("未查询到该桶库存信息,请检查!");
                }
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("库内作业", "库内日志", taskNo, "取消", $"点击取消按钮、取消了任务号为:{taskNo}的任务", userId);
                Db.CommitTran();
                stockDetail.Status = "0";//待分配
                Db.Updateable(stockDetail).ExecuteCommand();
                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)
            {
@@ -1125,7 +1143,7 @@
        /// <param name="taskNo"></param>
        /// <param name="userId"></param>
        /// <exception cref="Exception"></exception>
        public void DownTask(string taskNo, int userId,string url)
        public void DownTask(string taskNo, int userId,string url,string bindUrl)
        {
            try
            {
@@ -1142,7 +1160,7 @@
                    throw new Exception("只有等待执行的任务才可手动下发");
                }
                //查找该桶有没有正在执行的任务
                var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1" && w.PalletNo == logTaskEntry.PalletNo);
                var tasking = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.Status == "1"  && w.PalletNo == logTaskEntry.PalletNo);
                if (tasking != null)
                {
                    throw new Exception($"该桶有正在执行的任务");
@@ -1153,20 +1171,20 @@
                {
                    throw new Exception($"未查询到起始储位信息");
                }
                if (startLocatInfo.Status != "1")
                {
                    throw new Exception($"起始储位状态异常");
                }
                //if (startLocatInfo.Status != "1")
                //{
                //    throw new Exception($"起始储位状态异常");
                //}
                //目标储位信息
                var endLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == logTaskEntry.EndLocat);
                if (endLocatInfo == null)
                {
                    throw new Exception($"未查询到目标储位信息");
                }
                if (endLocatInfo.Status != "0")
                {
                    throw new Exception($"目标储位状态异常");
                }
                //if (endLocatInfo.Status != "0")
                //{
                //    throw new Exception($"目标储位状态异常");
                //}
                //组织给小车下发任务信息
                var task = new TaskDetial
                {
@@ -1179,30 +1197,33 @@
                string agvMsg = string.Empty;
                //给下车下发任务
                logTaskEntry.SendDate = DateTime.Now;//发送时间
                var agvResult = CreateTaskForAgv(task, url, out agvMsg);
                if (agvResult)//成功
                //先给货位绑定载具
                var bind = RcsHelper.BindPalletAndSite(logTaskEntry.PalletNo, logTaskEntry.StartLocat, 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 = CreateTaskForAgv(task, url, out agvMsg);
                    if (agvResult)//成功
                    {
                        //请求成功修改任务表相应字段状态
                        logTaskEntry.IsSuccess = 1;
                        logTaskEntry.IsSend = 1;
                        logTaskEntry.IsCancel = 1;
                        logTaskEntry.BackDate = DateTime.Now;
                        Db.Updateable(logTaskEntry).ExecuteCommand();
                    startLocatInfo.Status = "3";//出库中
                    Db.Updateable(startLocatInfo).ExecuteCommand();
                        startLocatInfo.Status = "3";//出库中
                        Db.Updateable(startLocatInfo).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//失败
                {
                    logTaskEntry.IsSuccess = 0;
                    logTaskEntry.Information = agvMsg;
                    Db.Insertable(logTaskEntry).ExecuteCommand();
                }
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("库内作业", "库内日志", taskNo, "下发", $"点击下发按钮、任务号为:{taskNo}的任务", userId);
                Db.CommitTran();
@@ -1322,6 +1343,43 @@
                var logStr = $@".\log\AGV\AGV{logMsg}" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                LogFile.SaveLogToFile($"AGV{logMsg}异常:( {agvModel.Message} ),", logStr);
                agvMsg = agvModel.Message;
            }
            return result;
            #endregion
        }
        /// <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;
@@ -1460,7 +1518,7 @@
                            //logTaskEntry.IsCancel = 0;
                            logTaskEntry.BackDate = DateTime.Now;
                            logTaskEntry.Status = "1";//正在执行
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            Db.Updateable(logTaskEntry).ExecuteCommand();
                            locatInfo.Status = "5";//移出中
@@ -1473,7 +1531,7 @@
                        {
                            logTaskEntry.IsSuccess = 0;
                            logTaskEntry.Information = agvMsg;
                            Db.Insertable(logTaskEntry).ExecuteCommand();
                            Db.Updateable(logTaskEntry).ExecuteCommand();
                            throw new Exception($"给小车下发移库任务失败,桶号:{palletInfoYi.PalletNo}");
                        }
@@ -1486,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);
            }
        }
    }
}