zhaowc
2025-02-28 157abc191c34e57c1b958ae74fc3de6518ca8a30
Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -890,7 +890,7 @@
        /// <param name="palletNo"></param>
        /// <param name="areaNo"></param>
        /// <param name="ruku"></param>
        public void AgvTransport(string palletNo, string areaNo, string ruku, int userId, string url)
        public void AgvTransport(string palletNo, string areaNo, string ruku, int userId, string url, string wcsurl)
        {
            if (string.IsNullOrEmpty(palletNo))
            {
@@ -907,7 +907,7 @@
            try
            {
                string EndLocat = string.Empty,OrderTy = "";//目标位置
                var tasktype = "D00";  //小车任务类型,默认为点到点任务
                var log = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1"));
                if (log != null)
@@ -969,6 +969,33 @@
                //开启事务
                Db.BeginTran();
                //请求WCS入库口放货确认
                if (!string.IsNullOrEmpty(ruku))
                {
                    try
                    {
                        var port = new
                        {
                            Port = EndLocat
                        };
                        var json = JsonConvert.SerializeObject(port);
                        var res = HttpHelper.DoPost(wcsurl, json, "请求WCS入库口是否可放货", "WCS");
                        //////解析返回数据
                        var ret = JsonConvert.DeserializeObject<WcsModel>(res);
                        if (ret.StatusCode == -1)
                        {
                            throw new Exception(EndLocat + "号入库口已有其他任务占用,请选择其他入库口");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
                //添加出库任务
                var taskNo = new Common().GetMaxNo("TK");
                var exTask = new LogTask
@@ -1017,34 +1044,19 @@
                #region 呼叫小车代码
                var endlono = EndLocat;
                var tasktype = "D00";  //默认为点到点任务
                //根据目的地址库区获取小车任务类型
                switch (storageLocatEnd.AreaNo)
                if (OrderTy == "0")
                {
                    case "B13" :
                        tasktype = "D02";  // 叠托任务(目的地址为空托盘收集区)
                        break;
                    case "B15":
                        tasktype = "D01";  // 拆托任务(目的地址为拣货区)
                        break;
                    tasktype = "RK0"; //入库任务
                }
                //缓存库位转换     3楼原辅料Y003_001,Y003_002,Y003_003  1楼Y138_001到Y138_021外包缓存区   1楼Y128_001到Y128_015内包缓存区
                //缓存库位转换     3楼接驳位Y003_001,Y003_002,Y003_003
                if (storageLocatEnd.AreaNo == "B12")
                {
                    switch (EndLocat.ToString().Substring(4, 1))
                    {
                        case "1":
                            endlono = "Y003_00" + EndLocat.ToString().Substring(6, 1);
                            endlono = "Y003_0" + EndLocat.ToString().Substring(5, 2);
                            tasktype = "D00";     //点到点任务
                            break;
                        case "2":
                            endlono = "Y138_0" + EndLocat.ToString().Substring(5, 2);
                            tasktype = "F20";    //电梯任务
                            break;
                        case "3":
                            endlono = "Y128_0" + EndLocat.ToString().Substring(5, 2);
                            tasktype = "F20";     //电梯任务
                            break;
                        default:
                            break;
@@ -1270,21 +1282,13 @@
                            break;
                    }
                    //缓存库位转换     3楼原辅料Y003_001到Y003_009  1楼Y138_001到Y138_021外包缓存区   1楼Y128_001到Y128_015内包缓存区
                    //缓存库位转换     3楼原辅料Y003_001到Y003_011
                    if (storageLocatEnd.AreaNo == "B12")
                    {
                        switch (EndLocat.ToString().Substring(4, 1))
                        {
                            case "1":
                                endlono = "Y003_00" + EndLocat.ToString().Substring(6, 1);
                                break;
                            case "2":
                                endlono = "Y138_0" + EndLocat.ToString().Substring(5, 2);
                                tasktype = "F20";    //电梯任务
                                break;
                            case "3":
                                endlono = "Y128_0" + EndLocat.ToString().Substring(5, 2);
                                tasktype = "F20";     //电梯任务
                                endlono = "Y003_0" + EndLocat.ToString().Substring(5, 2);
                                break;
                            default:
                                break;
@@ -1400,8 +1404,203 @@
            }
        }
        /// <summary>
        /// 空托盘入库呼叫小车
        /// </summary>
        /// <param name="palletNo"></param>
        /// <param name="areaNo"></param>
        /// <param name="ruku"></param>
        public void AgvTransport3(string palletNo, string LocatNo, string ruku, int userId, string url, string wcsurl)
        {
            if (string.IsNullOrEmpty(palletNo))
            {
                throw new Exception("请扫描托盘条码!");
            }
            if (string.IsNullOrEmpty(ruku))
            {
                throw new Exception("请选择入库口!");
            }
            try
            {
                if (ruku == "001")
                {
                    var xlocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13010101" || w.LocatNo == "B13020101" || w.LocatNo == "B13030101"));
                    if (xlocate == null)
                    {
                        throw new Exception("空托盘收集器已满");
                    }
                    ruku = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13010101" || w.LocatNo == "B13020101" || w.LocatNo == "B13030101")).LocatNo;
                }
                if (ruku == "002")
                {
                    var dlocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13040101" || w.LocatNo == "B13050101" || w.LocatNo == "B13060101"));
                    if (dlocate == null)
                    {
                        throw new Exception("空托盘收集器已满");
                    }
                    ruku = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13040101" || w.LocatNo == "B13050101" || w.LocatNo == "B13060101")).LocatNo;
                }
                if (ruku == null)
                {
                    throw new Exception("当前托盘收集器工位无空余,请将空托盘垛入立体库");
                }
                string EndLocat = ruku;//目标位置
                string OrderTy = ruku.Length ==3 ? "0":"2";
                var tasktype = "RK0"; //入库任务
                int palnoqty = 1;
                var log = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1"));
                if (log != null)
                {
                    throw new Exception("该托盘已有小车等待执行或正在执行的任务!");
                }
                //起始储位信息
                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == LocatNo);
                if (storageLocat == null)
                {
                    throw new Exception("储位信息不存在,请检查!");
                }
                //开启事务
                Db.BeginTran();
                if (EndLocat.Length == 3)
                {
                    //请求WCS入库口放货确认
                    try
                    {
                        var port = new
                        {
                            Port = EndLocat
                        };
                        var json = JsonConvert.SerializeObject(port);
                        var res = HttpHelper.DoPost(wcsurl, json, "请求WCS入库口是否可放货", "WCS");
                        //////解析返回数据
                        var ret = JsonConvert.DeserializeObject<WcsModel>(res);
                        if (ret.StatusCode == -1)
                        {
                            throw new Exception(EndLocat + "号入库口已有其他任务占用,请选择其他入库口");
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
                else
                {
                    tasktype = "D02";
                    palnoqty = (int)Db.Queryable<BllPalletBind>().First(w => w.PalletNo == palletNo && w.Status == "1" && w.IsDel == "0").Qty;
                }
                //添加入库任务
                var taskNo = new Common().GetMaxNo("TK");
                var exTask = new LogTask
                {
                    TaskNo = taskNo,
                    Sender = "WMS",
                    Receiver = "AGV",
                    IsSuccess = 0, //是否下发成功 0失败 1成功
                    StartLocat = LocatNo,//起始位置
                    EndLocat = EndLocat,//目标位置
                    PalletNo = palletNo,//托盘码
                    Msg = string.Format("转运任务:{0}=>>{1}", LocatNo, EndLocat),
                    IsSend = 0,//是否可再次下发
                    IsCancel = 0,//是否可取消
                    IsFinish = 0,//是否可完成
                    Type = OrderTy,//任务类型 0 入库任务 1 出库任务  2 移库任务
                    Status = "0",//任务状态0:等待执行1正在执行2执行完成
                    OrderType = OrderTy,//0 入库单 1 出库单  2 盘点单  3 移库单
                    CreateTime = DateTime.Now
                };
                Db.Insertable(exTask).ExecuteCommand();
                //修改起始储位地址状态
                storageLocat.Status = "5";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                Db.Updateable(storageLocat).ExecuteCommand();
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("PDA模块", "空托入库", palletNo, OrderTy == "0" ? "入库" : "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
                #region 呼叫小车代码
                //点到点指令集合
                object[] position = new object[2];
                position[0] = new
                {
                    positionCode = LocatNo,
                    type = "00"
                };
                position[1] = new
                {
                    positionCode = EndLocat,
                    type = "00"
                };
                List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
                AgvSchedulingTask agvTask = new AgvSchedulingTask();
                Random r = new Random();
                long ran = DateTime.Now.Ticks;
                agvTask.ReqCode = ran.ToString();
                agvTask.TaskCode = taskNo;
                agvTask.TaskTyp = tasktype;
                agvTask.PositionCodePath = position;
                agvTask.CtnrTyp = palnoqty.ToString();
                agvTaskList.Add(agvTask);
                // 正式运行程序放开
                string str = "";
                var list2 = agvTaskList.Select(m => m.TaskCode).ToList();
                var jsonData = JsonConvert.SerializeObject(agvTaskList);
                jsonData = jsonData.Substring(1, jsonData.Length - 1);
                jsonData = jsonData.Substring(0, jsonData.Length - 1);
                string response = "";
                try
                {
                    var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
                    response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV");
                    var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
                    //////解析返回数据
                    var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
                    if (agvModel.Code == "0")
                    {
                        //更改任务的发送返回时间//
                        new TaskServer().EditTaskIssueOk(list2, time1, time2);
                        str += "下发成功";
                    }
                    if (agvModel.Code == "1")
                    {
                        new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
                        throw new Exception(agvModel.Message);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                #endregion
                //提交事务
                Db.CommitTran();
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw new Exception(ex.Message);
            }
        }
        #region
        /// <summary>
        /// agv调度任务下发
        /// </summary>
@@ -1431,21 +1630,13 @@
                    break;
            }
            // MES申请备料,备料区库位需要转换     车间备料缓存位名称:3楼原辅料Y003_001-->Y003_003  1楼外包缓存区Y138_001-->Y138_021   1楼内包缓存区Y128_001-->Y128_015
            // MES申请备料,备料区库位需要转换     车间备料缓存位名称:Y003_001-->Y003_011
            if (storageLocatEnd.AreaNo == "B12")
            {
                switch (endlono.ToString().Substring(4, 1))
                {
                    case "1":
                        endlono = "Y003_00" + endlono.Substring(6, 1);
                        break;
                    case "2":
                        endlono = "Y138_0" + endlono.Substring(5, 2);
                        tasktype = "F20";    //电梯任务
                        break;
                    case "3":
                        endlono = "Y128_0" + endlono.Substring(5, 2);
                        tasktype = "F20";     //电梯任务
                        endlono = "Y003_0" + endlono.Substring(5, 2);
                        break;
                    default:
                        break;
@@ -1591,7 +1782,43 @@
                        endLocat = locatInfo3.LocatNo;
                    }
                }
                return endLocat;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 下发AGV任务继续执行
        /// </summary>
        /// <param name="taskno"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public void AgvContinue(string taskno,string url)
        {
            Random r = new Random();
            long ran = DateTime.Now.Ticks;
            var ReqCode = ran.ToString();
            var data = new
            {
                reqCode = ReqCode,
                taskCode = taskno
            };
            var jsonData = JsonConvert.SerializeObject(data);
            try
            {
                var response = HttpHelper.DoPost(url, jsonData, "下发给AGV继续执行命令", "AGV");
                //////解析返回数据
                var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
                if (agvModel.Code == "1")
                {
                    throw new Exception(agvModel.Message);
                }
            }
            catch (Exception ex)
            {
@@ -1691,15 +1918,19 @@
                        //var boxno = boxInfo.GroupBy(w => w.BoxNo).ToList();
                        var boxno = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.StockDetailId == item.Id).GroupBy(m => new
                        {
                            m.BoxNo
                            m.BoxNo,
                            m.ProductionTime,
                            m.ExpirationTime,
                        }).Select(it => new DataBoxInfo()
                        {
                            BoxNo = it.BoxNo
                            BoxNo = it.BoxNo,
                            ProductionTime = it.ProductionTime,
                            ExpirationTime = it.ExpirationTime,
                        }).ToList();
                        //记录托盘上信息给MES
                        foreach (var item2 in boxno) {
                            var a = item.ProductionTime.ToString();
                            //var a = item.ProductionTime.ToString();
                            data.Add(new RequertBeiliaoInfoModel()
                            {
                                no = item2.BoxNo,
@@ -1707,8 +1938,8 @@
                                materiel_name = item.SkuName,
                                qty = item.Qty,
                                batch = item.LotNo,
                                producttime = item.ProductionTime.ToString().Substring(0,10),
                                expiry = item.ExpirationTime.ToString().Substring(0, 10)
                                producttime = item2.ProductionTime.ToString().Substring(0,10),
                                expiry = item2.ExpirationTime.ToString().Substring(0, 10)
                            });
                        }
@@ -1746,13 +1977,7 @@
                    switch (EndLocat.LocatNo.ToString().Substring(4, 1))
                    {
                        case "1":
                            endlono = "Y003_00" + EndLocat.LocatNo.ToString().Substring(6, 1);
                            break;
                        case "2":
                            endlono = "Y138_0" + EndLocat.LocatNo.ToString().Substring(5, 2);
                            break;
                        case"3":
                            endlono = "Y128_0" + EndLocat.LocatNo.ToString().Substring(5, 2);
                            endlono = "Y003_0" + EndLocat.LocatNo.ToString().Substring(5, 2);
                            break;
                        default:
                            break;