zhaowc
2025-03-27 d07f25c163706ac46a83bd2c63db1e3c52715222
Wms/WMS.BLL/BllPdaServer/PdaSoServer.cs
@@ -20,6 +20,7 @@
using WMS.Entity.LogEntity;
using Model.ModelDto.SysDto;
using Model.ModelDto.BllSoDto;
using System.Security.Policy;
namespace WMS.BLL.BllPdaServer
{
@@ -69,11 +70,11 @@
                {
                    throw new Exception("托盘码为空,请输入托盘码");
                }
                var palletInfo = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                if (!string.IsNullOrEmpty(palletInfo.WareHouseNo) && type != "1")
                {
                    throw new Exception("该托盘还未出库");
                }
                //var palletInfo = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                //if (string.IsNullOrEmpty(palletInfo.WareHouseNo) && type != "1")
                //{
                //    throw new Exception("该托盘还未出库");
                //}
                if (type == "1")//平库出库获取单据
                {
                    var allotList = Db.Queryable<BllExportAllot>().Where(m => m.IsDel == "0" && m.Status == "1" && m.PalletNo == palletNo).Select(m => m.SONo).Distinct().Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
@@ -81,6 +82,11 @@
                }
                //获取状态为待拣货或者部分拣货的出库单
                var allotList2 = Db.Queryable<BllExportAllot>().Where(m => m.IsDel == "0" && (m.Status == "2" || m.Status == "3") && m.PalletNo == palletNo).Select(m => m.SONo).Distinct().Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
                if (allotList2.Count == 0)
                {
                    throw new Exception("此托盘已拣货或无拣货任务");
                }
                //var allotList = Db.Queryable<BllExportAllot>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).Select(m => m.SONo).Distinct().Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
                //获取出库单据不为待拣货 执行完毕 订单关闭 等待执行的单据
@@ -528,6 +534,13 @@
                    {
                        throw new Exception("未在托盘表中查询到托盘信息");
                    }
                    //修改储位状态
                    var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                    if (locate != null)
                    {
                        locate.Status = "0";
                        Db.Updateable(locate).ExecuteCommand();
                    }
                    pallet.Status = "0";
                    Db.Updateable(pallet).ExecuteCommand();
                    //修改出库单明细拣货数量
@@ -756,6 +769,13 @@
                        }
                        pallet.Status = "0";
                        Db.Updateable(pallet).ExecuteCommand();
                        //修改储位状态
                        var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                        if (locate != null)
                        {
                            locate.Status = "0";
                            Db.Updateable(locate).ExecuteCommand();
                        }
                    }
                    //修改出库单明细拣货数量
                    noticeDetail.CompleteQty += pickQty;
@@ -954,12 +974,19 @@
                {
                    throw new Exception("未在托盘表中查询到托盘信息");
                }
                //判断托盘上物料是否拣货完毕
                if (isDel == 0)
                {
                    pallet.Status = "0";
                    Db.Updateable(pallet).ExecuteCommand();
                }
                //修改储位状态
                var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                if (locate != null)
                {
                    locate.Status = "0";
                    Db.Updateable(locate).ExecuteCommand();
                }
                //修改出库单明细拣货数量
@@ -2411,6 +2438,179 @@
        }
        /// <summary>
        /// WMS申请拣货空托
        /// </summary>
        /// <param name="model"> </param>
        /// <param name="userId"> </param>
        /// <param name="url"> </param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public string IssuePlnCehckHouseWcs(CheckModePalletVm model, int userId, string url)
        {
            try
            {
                string StartLocate = "" ,EndLocate = "";
                Db.BeginTran();
                if (model.OutMode == "001") //西侧拣货位叫空托盘
                {
                    var xLocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "1" && (w.LocatNo == "B13010101" || w.LocatNo == "B13020101" || w.LocatNo == "B13030101"));
                    if (xLocate == null)
                    {
                        throw new Exception("没有可用的空托盘");
                    }
                    StartLocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "1" && (w.LocatNo == "B13010101" || w.LocatNo == "B13020101" || w.LocatNo == "B13030101")).LocatNo;
                    //校验是否为第2层拣货托盘位
                    var locate = Db.Queryable<SysStorageLocat>().First(w => w.Row == 2 && w.LocatNo == model.OutCode);
                    if (locate == null)
                    {
                        throw new Exception("请选择正确的拣货位");
                    }
                    //校验目的货位是否可用
                    var isuse = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && w.LocatNo == model.OutCode);
                    if (locate == null)
                    {
                        throw new Exception("此拣货位状态不为空货位");
                    }
                    EndLocate = model.OutCode;
                }
                else//东侧拣货位叫空托盘
                {
                    var dLocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "1" && (w.LocatNo == "B13030101" || w.LocatNo == "B13040101" || w.LocatNo == "B13050101"));
                    if (dLocate == null)
                    {
                        throw new Exception("没有可用的空托盘");
                    }
                    StartLocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "1" && (w.LocatNo == "B13030101" || w.LocatNo == "B13040101" || w.LocatNo == "B13050101")).LocatNo;
                    //校验是否为第2层拣货托盘位
                    var locate = Db.Queryable<SysStorageLocat>().First(w => w.Row == 4 && w.LocatNo == model.OutCode);
                    if (locate == null)
                    {
                        throw new Exception("请选择正确的拣货位");
                    }
                    //校验目的货位是否可用
                    var isuse = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && w.LocatNo == model.OutCode);
                    if (locate == null)
                    {
                        throw new Exception("此拣货位状态不为空货位");
                    }
                    EndLocate = model.OutCode;
                }
                //添加出库任务
                var taskNo = new Common().GetMaxNo("TK");
                var exTask = new LogTask
                {
                    TaskNo = taskNo,
                    Sender = "WMS",
                    Receiver = "AGV",
                    IsSuccess = 0, //是否下发成功 0失败 1成功
                    StartLocat = StartLocate,//起始位置
                    EndLocat = EndLocate,//目标位置
                    PalletNo = "",//托盘码
                    Msg = string.Format("转运任务:{0}=>>{1}", StartLocate, EndLocate),
                    IsSend = 1,//是否可再次下发
                    IsCancel = 1,//是否可取消
                    IsFinish = 1,//是否可完成
                    Type = "2",//任务类型 0 入库任务 1 出库任务  2 移库任务
                    Status = "0",//任务状态0:等待执行1正在执行2执行完成
                    OrderType = "3",//0 入库单 1 出库单  2 盘点单  3 移库单
                    CreateTime = DateTime.Now
                };
                Db.Insertable(exTask).ExecuteCommand();
                var storageLocatEnd = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == EndLocate);
                //修改目标储位地址状态
                if (storageLocatEnd != null)
                {
                    storageLocatEnd.Status = "4";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
                    Db.Updateable(storageLocatEnd).ExecuteCommand();
                }
                #region 呼叫小车代码
                var endlono = EndLocate;
                string tasktype = "D01";
                //点到点指令集合
                object[] position = new object[2];
                position[0] = new
                {
                    positionCode = StartLocate,
                    type = "00"
                };
                position[1] = new
                {
                    positionCode = endlono,
                    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 = "1";
                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
                //添加操作日志记录
                var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", "", "移库", $"PDA呼叫小车拆空托盘拣货", userId);
                Db.CommitTran();
                return "";
            }
            catch (Exception e)
            {
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        public string MoveAddress(string oldAddress, string roadWay, string skuNo,string areaNo="")//01020201  排-列-层-深度
        {
            string nowAddress = "";
@@ -3065,6 +3265,13 @@
                        }
                        pallet.Status = "0";
                        Db.Updateable(pallet).ExecuteCommand();
                        //修改储位状态
                        var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                        if (locate != null)
                        {
                            locate.Status = "0";
                            Db.Updateable(locate).ExecuteCommand();
                        }
                    }
                    //修改出库单明细拣货数量
                    noticeDetail.Qty += pickQty;
@@ -3345,6 +3552,13 @@
                        }
                        pallet.Status = "0";
                        Db.Updateable(pallet).ExecuteCommand();
                        //修改储位状态
                        var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                        if (locate != null)
                        {
                            locate.Status = "0";
                            Db.Updateable(locate).ExecuteCommand();
                        }
                    }
                    //修改出库单明细拣货数量
                    noticeDetail.CompleteQty += pickQty;
@@ -3631,6 +3845,13 @@
                        pallet.Status = "0";
                        Db.Updateable(pallet).ExecuteCommand();
                    }
                    //修改储位状态
                    var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                    if (locate != null)
                    {
                        locate.Status = "0";
                        Db.Updateable(locate).ExecuteCommand();
                    }
                    //修改出库单明细拣货数量
                    noticeDetail.Qty += decimal.Parse(PickQty);
@@ -3814,6 +4035,13 @@
                    {
                        pallet.Status = "0";
                        Db.Updateable(pallet).ExecuteCommand();
                    }
                    //修改储位状态
                    var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                    if (locate != null)
                    {
                        locate.Status = "0";
                        Db.Updateable(locate).ExecuteCommand();
                    }
                    //修改出库单明细拣货数量
@@ -4059,6 +4287,7 @@
                            LotNo = allot.LotNo,
                            LotText = allot.LotText,
                            SupplierLot = allot.SupplierLot,
                            SkuNo = allot.SkuNo,
                            SkuName = allot.SkuName,
                            Standard = allot.Standard,
@@ -4155,10 +4384,10 @@
                            throw new Exception("该托盘与箱码没有绑定关系");
                        }
                        var boxQty = boxInfos.First().Qty;
                        if (boxQty > needQty)
                        {
                            throw new Exception("拣货数量不能大于剩余待拣数量");
                        }
                        //if (boxQty > needQty)
                        //{
                        //    throw new Exception("拣货数量不能大于剩余待拣数量");
                        //}
                        foreach (var item in boxInfos)
                        {
@@ -4181,10 +4410,10 @@
                        {
                            throw new Exception("拣货数量不能大于箱内数量");
                        }
                        if (decimal.Parse(pickQty1) > needQty)
                        {
                            throw new Exception("拣货数量不能大于剩余待拣数量");
                        }
                        //if (decimal.Parse(pickQty1) > needQty)
                        //{
                        //    throw new Exception("拣货数量不能大于剩余待拣数量");
                        //}
                        biaoShi = "2";
                    }
@@ -4199,10 +4428,10 @@
                            throw new Exception("该托盘与箱码没有绑定关系");
                        }
                        var boxQty = boxInfo.GroupBy(m => m.BoxNo).Select(m => SqlFunc.AggregateSum(m.Qty)).ToList();
                        if (boxQty[0] > needQty)
                        {
                            throw new Exception("拣货数量不能大于箱内剩余待拣数量");
                        }
                        //if (boxQty[0] > needQty)
                        //{
                        //    throw new Exception("拣货数量不能大于箱内剩余待拣数量");
                        //}
                        foreach (var item in boxInfos)
                        {
@@ -4300,6 +4529,7 @@
                                        SkuName = item.SkuName,
                                        Standard = item.Standard,
                                        ProductionTime = item.ProductionTime,
                                        ExpirationTime = item.ExpirationTime,
                                        SupplierLot = item.SupplierLot,
                                        InspectMark = item.InspectMark,
                                        BitBoxMark = "1",
@@ -4389,6 +4619,14 @@
                        }
                        pallet.Status = "0";
                        Db.Updateable(pallet).ExecuteCommand();
                        //修改储位状态
                        var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                        if (locate != null)
                        {
                            locate.Status = "0";
                            Db.Updateable(locate).ExecuteCommand();
                        }
                    }
                    //修改出库单明细拣货数量
                    noticeDetail.CompleteQty += pickQty;
@@ -4498,10 +4736,10 @@
                }
                //剩余拣货数量(待拣减去已拣)
                var needQty = allot.Qty - allot.CompleteQty;
                if (decimal.Parse(PickQty) > needQty)
                {
                    throw new Exception("拣货数量不能大于托内剩余待拣数量");
                }
                //if (decimal.Parse(PickQty) > needQty)
                //{
                //    throw new Exception("拣货数量不能大于托内剩余待拣数量");
                //}
                //库存明细
                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.Id == allot.StockId);
@@ -4726,6 +4964,13 @@
                    pallet.Status = "0";
                    Db.Updateable(pallet).ExecuteCommand();
                    //修改储位状态
                    var locate = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == stockDetail.LocatNo);
                    if (locate != null)
                    {
                        locate.Status = "0";
                        Db.Updateable(locate).ExecuteCommand();
                    }
                }
                //修改出库单明细拣货数量