chengsc
2024-10-14 b31f32fbfb25c77567e3853e05ca114dd2a00fbe
Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -15,6 +15,13 @@
using WMS.Entity.BllSoEntity;
using Model.ModelVm.PdaVm;
using Model.ModelDto.PdaDto;
using Dm;
using Model.InterFaceModel;
using WMS.Entity.BllQualityEntity;
using Newtonsoft.Json;
using Utility.Tools;
using System.Reflection;
using System.IO;
namespace WMS.BLL.BllPdaServer
{
@@ -23,14 +30,48 @@
        private static readonly SqlSugarScope Db = DataContext.Db;
        // 获取单据列表
        public List<ArrivalNoticeDto> GetArrivalNotices(ArrivalNoticeVm model)
        public List<string> GetArrivalNotices(ArrivalNoticeVm model)
        {
            string sqlString = string.Empty;
            try
            {
                // 未关单的单据
                sqlString = $"select * from BllArrivalNotice where Type in ({model.Type}) and Status != '3' and Status != '4'  and IsDel='0' order by CreateTime;";
                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDto>(sqlString);
                //sqlString = $"select * from BllArrivalNotice where Type in ({model.Type}) and Status != '3' and Status != '4'  and IsDel='0' order by CreateTime;";
                //var modelList = Db.Ado.SqlQuery<ArrivalNoticeDto>(sqlString);
                //model.Type:单据类型 在这里代表前端页签类型:即标签页签:贴标物料; 数量页签:不贴表物料,原因:懒得加参数
                var data = Db.Queryable<BllArrivalNotice>().Where(m => m.IsDel == "0" && m.Status != "3" && m.Status != "4").Select(m=>m.ASNNo).ToList();
                var list = new List<string>();
                if (model.Type == "0")//0贴标
                {
                    list = Db.Queryable<BllArrivalNoticeDetail>().Where(m =>m.IsDel == "0" && data.Contains(m.ASNNo) && !string.IsNullOrWhiteSpace(m.PackagNo)).Select(m => m.ASNNo).Distinct().ToList();
                }
                else if(model.Type == "1")//1不贴标
                {
                    list = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && data.Contains(m.ASNNo) && string.IsNullOrWhiteSpace(m.PackagNo)).Select(m=>m.ASNNo).Distinct().ToList();
                }
                else
                {
                    throw new Exception("页签类型参数错误");
                }
                return list;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //根据入库单号获取入库总单信息
        public List<BllArrivalNotice> GetArrivalNotice(ArrivalNoticeVm model)
        {
            string sqlString = string.Empty;
            try
            {
                sqlString = $"select * from BllArrivalNotice where ASNNo = '{model.ASNNo}' and isdel='0'  ";
                var modelList = Db.Ado.SqlQuery<BllArrivalNotice>(sqlString);
                return modelList;
            }
@@ -49,7 +90,17 @@
                sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
                return modelList;
                List<ArrivalNoticeDetailDto> list = new List<ArrivalNoticeDetailDto>();
                foreach (var item in modelList)
                {
                    string str = BySkuNoGetPackInfo(item.SkuNo);
                    if (str == "不存在")
                    {
                        list.Add(item);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
@@ -132,7 +183,7 @@
        public List<BoxInfoDto> GetBoxInfos(BoxInfoVm model)
        {
            try
            {
            {
                string sqlString = string.Empty;
                if (model.IsHuiKu == 0)
                {
@@ -157,6 +208,31 @@
                    sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; ";
                }
                var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                return models;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // 根据托盘号或箱码获取托盘信息   liudl
        public List<PalletBindDto> GetPalletBindInfo(BllPalletBind model)
        {
            try
            {
                string sqlString = string.Empty;
                sqlString = "select b.SkuNo,b.SkuName,a.LotNo,a.Qty,a.PalletNo,a.Id from BllPalletBind a left join BllArrivalNoticeDetail b on a.ASNDetailNo = b.Id where a.IsDel = '0' and b.IsDel = '0' ";
                if (!string.IsNullOrEmpty(model.PalletNo))
                {
                    sqlString += $"and PalletNo = '{model.PalletNo}' and a.Status = '0' ";
                }
                else
                {
                    throw new Exception("托盘号异常!");
                }
                var models = Db.Ado.SqlQuery<PalletBindDto>(sqlString);
                return models;
            }
@@ -322,12 +398,12 @@
            {
                //获取任务信息
                var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && a.Status == "1");
                if (logtask == null)
                if (logtask != null)
                {
                    strMsg = "该托盘任务已完成 或未成功创建任务 请核实!";
                    return strMsg;
                }
                string bindstr = "select * from BllPalletBind Where IsDel = @isdel and PalletNo = @palletno and ASNDetailNo = 0 and ASNNo = ''";
                string bindstr = "select * from BllPalletBind Where IsDel = @isdel and PalletNo = @palletno and ASNDetailNo = 0 and ASNNo = '' ";
                //获取绑定托盘表信息
                List<PalletBindVm> bindVms = Db.Ado.SqlQuery<PalletBindVm>(bindstr, new
                {
@@ -343,10 +419,13 @@
                    return strMsg;
                }
                //删除绑定托盘表信息
                string delstr = "delete from BllPalletBind Where PalletNo = @palletno";
                string delstr = "update BllPalletBind set IsDel = 1,UpdateUser = @UpdateUser,UpdateTime = @UpdateTime Where PalletNo = @palletno and Id =@Id ";
                int i = Db.Ado.ExecuteCommand(delstr, new
                {
                    palletno = upBindPalletNo
                    UpdateUser = createUser,
                    UpdateTime = DateTime.Now,
                    palletno = upBindPalletNo,
                    Id = bindVms[0].Id
                });
                //修改托盘状态
                Db.BeginTran();
@@ -357,7 +436,7 @@
                    UpbindPalletNo = upBindPalletNo,
                    PalletNo2 = bindVms[0].PalletNo2,
                    PalletNo3 = bindVms[0].PalletNo3,
                    Qty = (int)bindVms[0].Qty,
                    Qty = bindVms[0].Qty,
                    LotNo = bindVms[0].LotNo,
                    LotText = bindVms[0].LotText,
                    SupplierLot = bindVms[0].SupplierLot,
@@ -373,12 +452,12 @@
                box.IsDel = "1";
                Db.Updateable(box).ExecuteCommand();
                //修改任务状态
                logtask.IsDel = "1";
                logtask.Status = "4"; //3 已取消
                logtask.UpdateUser = createUser; //取消人
                logtask.UpdateTime = DateTime.Now; //取消时间
                Db.Updateable(logtask).ExecuteCommand();
                ////修改任务状态
                //logtask.IsDel = "1";
                //logtask.Status = "4"; //3 已取消
                //logtask.UpdateUser = createUser; //取消人
                //logtask.UpdateTime = DateTime.Now; //取消时间
                //Db.Updateable(logtask).ExecuteCommand();
                //更改库存数量
                //string str = $"update DataStock set Qty = Qty - {(int)bindVms[0].Qty} Where SkuNo = '100099'";
                // 更改托盘使用状态
@@ -485,6 +564,121 @@
            }
        }
        // 删除已组信息
        public string DelPalletBind(BllPalletBind model)
        {
            string strMsg = "";
            string sqlString = string.Empty;
            try
            {
                if (model.Id == 0)
                {
                    throw new Exception("-1:托盘ID不可为0!");
                }
                //获取托盘绑定信息
                var bind = Db.Queryable<BllPalletBind>().First(a => a.IsDel == "0" && a.Status == "0" && a.Id == model.Id);
                //验证托盘绑定信息是否为空
                if (bind == null)
                {
                    throw new Exception("-1:未获取到对应托盘信息,请核实!");
                }
                //判断托盘绑定信息是否不是等待执行
                if (bind.Status != "0")
                {
                    throw new Exception("-1:该托盘已正在入库,请核实!");
                }
                //获取是否有指定库位
                SysStorageLocat locat = new SysStorageLocat();
                int isNullLocat = 0;
                //判断储位是否为空
                if (!string.IsNullOrWhiteSpace(bind.LocatNo))
                {
                    isNullLocat = 1;
                    locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == bind.WareHouseNo && a.RoadwayNo == bind.RoadwayNo && a.LocatNo == bind.LocatNo);
                    //判断储位地址是否为正在入库
                    if (locat.Status != "2")
                    {
                        throw new Exception("-1:当前托盘绑定的储位地址不是正在入库,请核实!");
                    }
                }
                //获取托盘信息
                var pallet = Db.Queryable<SysPallets>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo);
                //判断托盘信息是否为空
                if (pallet == null)
                {
                    throw new Exception("-1:未获取到对应托盘信息,请核实!");
                }
                //获取对应入库单据总单
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == bind.ASNNo);
                //验证入库单总单信息
                if (notice == null)
                {
                    throw new Exception("-1:未获取到对应入库单总单信息,请核实!");
                }
                //获取对应入库单据明细
                var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.Id == bind.ASNDetailNo);
                //验证入库单单据明细
                if (noticeDetail == null)
                {
                    throw new Exception("-1:未获取到对应入库单单据明细信息,请核实!");
                }
                Db.BeginTran();
                //减少入库单明细数量 判断已组数量是否为0 再判断完成数量是否为0
                noticeDetail.FactQty -= bind.Qty;
                //判断已组数量是否为0
                if (noticeDetail.FactQty == 0)
                {
                    //判断是否有完成数量
                    if (noticeDetail.CompleteQty == 0)
                    {
                        noticeDetail.Status = "0"; //入库单明细状态
                        notice.Status = "0"; //入库单总单状态
                    }
                }
                Db.Updateable(noticeDetail).ExecuteCommand();
                Db.Updateable(notice).ExecuteCommand();
                // 清除托盘绑定上信息
                //ASNNo,ASNDetailNo,Qty,FullQty,LotNo,LotText,SupplierLot,IsDel,UpdateTime,UpdateUser
                bind.ASNNo = ""; //入库单号
                bind.ASNDetailNo = 0; //入库单明细id
                bind.Qty = 0; //数量
                bind.FullQty = 0; //整托数量
                bind.LotNo = ""; //批次
                bind.LotText = ""; //批次描述
                bind.SupplierLot = ""; //供货批次
                bind.IsDel = "1"; //是否删除
                bind.UpdateTime = Db.GetDate(); //修改时间
                bind.UpdateUser = model.CreateUser; //修改人
                if (isNullLocat == 1)
                {
                    bind.LocatNo = ""; //储位地址
                    bind.RoadwayNo = ""; //所属巷道
                    bind.WareHouseNo = ""; //所属仓库
                    //修改储位信息状态
                    locat.Status = "0"; //储位状态 0:空储位
                    Db.Updateable(locat).ExecuteCommand();
                }
                Db.Updateable(bind).ExecuteCommand();
                //修改托盘信息状态
                pallet.Status = "0"; //0:未使用
                Db.Updateable(pallet).ExecuteCommand();
                Db.CommitTran();
                return strMsg;
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw ex;
            }
        }
        // 平库完成入库操作
        public string CompleteInStock(PalletBindVm model)
        {
@@ -517,7 +711,7 @@
                #region 是否回流入库
                int iscount = 0;
                //库存明细信息
                var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList();
                var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList();
                //验证库存是否拥有该托信息
                if (stockDetail != null && stockDetail.Count > 0)
                {
@@ -534,7 +728,7 @@
                #endregion
                #region 地码信息(储位信息)
                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0");
                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02");
                if (storageLocat == null)
                {
                    strMsg = "-1:储位信息不存在或非空闲状态,请核查!";
@@ -628,14 +822,14 @@
                            return strMsg;
                        }
                        #endregion
                        var pallQty = 0;//托盘上数量
                        decimal pallQty = 0;//托盘上数量
                        var boxinfo2 = boxinfo.Where(w => w.SkuNo == noticeItem.SkuNo && w.LotNo == noticeItem.LotNo && w.PalletNo == model.PalletNo).ToList();
                        if (boxinfo2.Count <= 0)
                        {
                            strMsg = "-1:箱码信息不存在,请核查!";
                            return strMsg;
                        }
                        else
                        else
                        {
                            // 改变箱支关系表状态:已入库
                            sqlString = $"Update BllBoxInfo set Status = '2' where PalletNo = '{model.PalletNo}' and ASNNo = '{model.ASNNo}' and Status = '1'";
@@ -644,7 +838,7 @@
                            pallQty = boxinfo2.Sum(w => w.Qty);
                            //入库单明细完成数量增加
                            noticeItem.CompleteQty += pallQty;
                        }
                        }
                        //判断入库数量增加后是否大于等于单据数量
                        if (noticeItem.CompleteQty >= noticeItem.Qty)
                        {
@@ -703,7 +897,7 @@
                            sqlString = "select sum(qty) from BllBoxInfo where isdel = 0 and ";
                            sqlString += $"BindNo = '{palletbindInfo.Id}'";
                            int inspectQty = Db.Ado.GetInt(sqlString);
                            // 添加库存明细表
                            detailModel = new DataStockDetail()
                            {
@@ -780,6 +974,8 @@
                        //修改组托状态
                        palletbindInfo.Status = "2"; //2 入库完成
                        palletbindInfo.WareHouseNo = "W02";//所属仓库
                        palletbindInfo.LocatNo = model.LocatNo;//储位地址
                        palletbindInfo.UpdateTime = serverTime;
                        palletbindInfo.UpdateUser = model.CreateUser;
                        palletbindInfo.CompleteTime = serverTime; //完成时间
@@ -946,6 +1142,11 @@
                    #endregion
                }
                storageLocat.Status = "1";
                storageLocat.UpdateTime = serverTime; //修改时间
                storageLocat.UpdateUser = model.CreateUser; //修改人
                //修改储位状态
                Db.Updateable(storageLocat).ExecuteCommand();
                new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成", $"在PDA上完成单据号为:{model.ASNNo}的托盘码为:{model.PalletNo}的平库入库操作", (int)model.CreateUser);
@@ -1109,7 +1310,7 @@
            try
            {
                //入库中
                var aSNNoList= Db.Ado.SqlQuery<string>($"SELECT DISTINCT ASNNo from BllPalletBind where IsDel=0 and Status=0 and PalletNo='{palletNo}' ").ToList();
                var aSNNoList = Db.Ado.SqlQuery<string>($"SELECT DISTINCT ASNNo from BllPalletBind where IsDel=0 and Status=0 and PalletNo='{palletNo}' ").ToList();
                if (aSNNoList.Count <= 0)
                {
                    //库外托盘或平库托盘
@@ -1125,6 +1326,30 @@
                    throw new Exception("同一个托盘号存在多个入库单,请检查!");
                }
                return aSNNoList[0];
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 验证储位地址(地码)是否可用
        /// </summary>
        /// <param name="locatNo">储位编码</param>
        /// <returns></returns>
        public string CheckLocatNo(string locatNo)
        {
            try
            {
                string strMsg = "";
                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == locatNo && w.Status == "0" && w.WareHouseNo == "W02");
                if (storageLocat == null)
                {
                    throw new Exception("-1:地码(储位信息)不存在或非空闲状态,请核查!");
                }
                return strMsg;
            }
            catch (Exception ex)
            {
@@ -1166,7 +1391,7 @@
        //拼托入库
        public void CompleteInStockLing(PdaLingAsnVm model, int userId)
        {
            try
            try
            {
                if (string.IsNullOrWhiteSpace(model.AsnNo))
                {
@@ -1198,15 +1423,15 @@
                {
                    throw new Exception("-1:箱码信息不存在,请核查!");
                }
                var bNum = 0;//数量
                decimal bNum = 0;//数量
                //验证箱码是否已绑定托盘
                foreach (var item in boxinfo)
                {
                    if (!string.IsNullOrEmpty(item.PalletNo))
                    {
                    {
                        throw new Exception("-1:该箱码已绑定其他托盘,请先解绑托盘!");
                    }
                    bNum += item.Qty;
                    bNum += item.Qty;
                }
                if (bNum == boxinfo[0].FullQty)
                {
@@ -1267,7 +1492,7 @@
                    //修改入库单总单信息
                    arrival.Status = "2";
                    arrival.CompleteTime = serverTime;
                    arrival.UpdateUser =userId;
                    arrival.UpdateUser = userId;
                    arrival.UpdateTime = serverTime;
                    Db.Updateable(arrival).ExecuteCommand();
                }
@@ -1373,7 +1598,7 @@
                #region 库存明细表
                var boxinfoItem = boxinfo.First();
                var detailModel = Db.Queryable<DataStockDetail>() .First(it => it.PalletNo == model.PalletNo && it.LotNo == arrivalnotice.LotNo
                var detailModel = Db.Queryable<DataStockDetail>().First(it => it.PalletNo == model.PalletNo && it.LotNo == arrivalnotice.LotNo
                     && it.SkuNo == arrivalnotice.SkuNo && it.Standard == arrivalnotice.Standard && it.IsDel == "0");
                var stId = 0;
                if (detailModel == null || detailModel.Id == 0)
@@ -1481,6 +1706,104 @@
        }
        #region 产品组托
        public void GetBoxInfoByFuMa(string boxNo,string url)
        {
            try
            {
                var list = new List<BllBoxInfo>();
                var data = new { BoxNo = boxNo };
                var jsonData = JsonConvert.SerializeObject(data);
                #region 测试版本
                //读取json文件,添加数据
                var ss = AppDomain.CurrentDomain.BaseDirectory;
                string filePath = Path.Combine(ss, "CreateBoxInfo.json");
                string json = File.ReadAllText(filePath);
                var person = JsonConvert.DeserializeObject<List<BllBoxInfo>>(json);
                var comTime = DateTime.Now;
                //添加箱码信息表中  //暂时这些写--添加数据,后续需要和赋码系统对接后 根据明确返回的数据格式更改
                foreach (var item in person)
                {
                    if (item.BoxNo!= boxNo)
                    {
                        continue;
                    }
                    var sku = Db.Queryable<SysMaterials>().First(m=>m.IsDel =="0" && m.SkuNo == item.SkuNo);
                    if (sku == null)
                    {
                        continue;
                    }
                    var boxInfo = new BllBoxInfo()
                    {
                        ASNNo = "",
                        //ASNDetailNo = 0,
                        OrderCode = "",
                        //BindNo = 0,
                        BoxNo = item.BoxNo,
                        BoxNo2 = item.BoxNo2,
                        BoxNo3 = item.BoxNo3,
                        PalletNo = "",
                        Qty = item.Qty,
                        FullQty = item.FullQty,
                        Status = "0",
                        SkuNo = item.SkuNo,
                        SkuName = sku.SkuName,
                        LotNo = item.LotNo,
                        LotText = item.LotText,
                        SupplierLot = item.SupplierLot,
                        ProductionTime = item.ProductionTime,
                        ExpirationTime = item.ExpirationTime,
                        //CompleteTime = comTime,
                        InspectMark = item.InspectMark,
                        BitBoxMark = item.BitBoxMark,
                        InspectStatus = item.InspectStatus,
                        Origin = "赋码",
                        Standard = item.Standard,
                        PackageStandard = item.PackageStandard,
                        StoreTime = item.StoreTime,
                        QtyOrd = item.QtyOrd,
                        QtyCount = item.QtyCount,
                        CreateUser = 0,
                        CreateTime = comTime,
                    };
                    list.Add(boxInfo);
                }
                Db.Insertable(list).ExecuteCommand();
                #endregion
                #region 正式版本
                ////程序正式发布后放开
                //var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
                //var response = HttpHelper.DoPost(url, jsonData, "获取箱码信息", "赋码");
                //var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
                ////解析返回数据
                //var fuMaModel = JsonConvert.DeserializeObject<FuMaModel>(response);
                //if (fuMaModel.Success == 0)
                //{
                //}
                //if (fuMaModel.Success == -1)
                //{
                //    throw new Exception($"赋码系统返回状态异常:{fuMaModel.Message}");
                //}
                #endregion
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 根据箱码获取标签箱码信息
        /// </summary>
@@ -1494,19 +1817,33 @@
                {
                    throw new Exception("请扫描外箱条码!");
                }
                string sqlString = string.Empty;
                sqlString = "select ASNNo,BoxNo, SkuNo,SkuName, LotNo, Qty from BLLLabelBoxNo where IsDel = '0' ";
                sqlString += $"and BoxNo = '{model.BoxNo}' ";
                var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                if (models == null || models.Count <= 0)
                if (!string.IsNullOrWhiteSpace(model.ASNNo))
                {
                    sqlString = "select BoxNo, SkuNo,SkuName, LotNo, SUM(Qty) as Qty from BllBoxInfo where IsDel = '0' ";
                    sqlString += $"and BoxNo = '{model.BoxNo}' and Status='0' ";
                    sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; ";
                    models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                }
                if (models == null)
                    var asnData = Db.Queryable<BllArrivalNotice>().First(m => m.IsDel == "0" && m.ASNNo == model.ASNNo);
                    if (asnData != null && (asnData.Type == "0" || asnData.Type == "3"))
                    {
                        var count = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.Status == "0" && m.BoxNo == model.BoxNo);
                        if (count == 0)
                        {
                            GetBoxInfoByFuMa(model.BoxNo, ""); //从赋码系统获取箱码信息
                        }
                    }
                }
                string sqlString = $@"SELECT
                                        ASNNo,
                                        BoxNo,
                                        SkuNo,
                                        SkuName,
                                        LotNo,
                                        SUM(Qty) as Qty
                                      FROM BllBoxInfo
                                      WHERE IsDel = '0'
                                        AND Status='0'
                                        AND BoxNo = '{model.BoxNo}'
                                      GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo; ";
                var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                if (models.Count == 0)
                {
                    throw new Exception("箱码信息不存在!");
                }
@@ -1517,13 +1854,104 @@
                throw ex;
            }
        }
        // 根据单据号获取单据明细列表
        public List<ArrivalNoticeDetailDto> GetBindArrivalNoticeDetails(ArrivalNoticeVm model)
        {
            string sqlString = string.Empty;
            try
            {
                sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
                List<ArrivalNoticeDetailDto> noticeList = new List<ArrivalNoticeDetailDto>();
                foreach (var item in modelList)
                {
                    if (string.IsNullOrEmpty(item.LotNo))
                    {
                        noticeList.Add(item);
                    }
                    else
                    {
                        string[] LotNoList = item.LotNo.Split(';');
                        foreach (var item2 in LotNoList)
                        {
                            ArrivalNoticeDetailDto entry = new ArrivalNoticeDetailDto()
                            {
                                Id = item.Id,
                                ASNNo = item.ASNNo,
                                CompleteQty = item.CompleteQty,
                                CompleteTime = item.CompleteTime,
                                CreateTime = item.CreateTime,
                                Qty = item.Qty,
                                FactQty = item.FactQty,
                                LotNo = item2,
                                Money = item.Money,
                                PackagNo = item.PackagNo,
                                PackagName = item.PackagName,
                                Status = item.Status,
                                SkuNo = item.SkuNo,
                                SkuName = item.SkuName,
                            };
                            noticeList.Add(entry);
                        }
                    }
                }
                List<ArrivalNoticeDetailDto> list = new List<ArrivalNoticeDetailDto>();
                foreach (var item in noticeList)
                {
                    string str = BySkuNoGetPackInfo(item.SkuNo);
                    if (str == "存在")
                    {
                        list.Add(item);
                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //根据物料获取是否存在包装信息
        public string BySkuNoGetPackInfo(string skuNo)
        {
            try
            {
                //获取物料信息
                var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == skuNo);
                //判断物料信息是否为空
                if (!string.IsNullOrWhiteSpace(sku.PackagNo))
                {
                    return "存在";
                }
                else
                {
                    return "不存在";
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        /// <summary>
        /// 绑定托盘
        /// </summary>
        /// <param name="model"></param>
        /// <param name="userId"></param>
        /// <param name="origin"></param>
        public void BindPallet(PdaPalletBindVm model, int userId, string origin)
        {
            try
            {
                #region 判断
                //0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库 7:寄存入库
                var TypeLot = "1, 2, 5, 6, 7";
                if (string.IsNullOrEmpty(model.AsnNo))
                {
@@ -1537,489 +1965,299 @@
                {
                    throw new Exception("-1:托盘号不可为空!");
                }
                if (string.IsNullOrEmpty(model.BoxNo))
                //根据单据号获取入库单总单
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
                if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
                {
                    throw new Exception("-1:箱码信息不可为空!");
                    throw new Exception("-1:该单据已关单!");
                }
                if (model.IsContinue == "1")
                if (string.IsNullOrEmpty(model.LotNo))
                {
                    if (string.IsNullOrWhiteSpace(model.TailBoxNo))
                    //判断是否为不限制批次单据
                    if (!TypeLot.Contains(notice.Type))
                    {
                        throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!");
                        throw new Exception("-1:物料批次不可为空!");
                    }
                }
                #endregion
                // 验证入库单总表
                var notice = Db.Queryable<BllArrivalNotice>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo);
                if (notice == null)
                {
                    throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
                }
                //入库单类型,0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库
                if (notice.Type == "0" || notice.Type == "3" || notice.Type == "5" || notice.Type == "6")
                {
                    BindPalletForBox(model,userId,origin);
                }
                else
                {
                    BindPalletForLabelBox(model,userId);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // 绑定物料托盘
        private void BindPalletForBox(PdaPalletBindVm model, int userId, string origin)
        {
            try
            {
                Db.BeginTran();
                //托盘是否存在
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息,请核实!");
                }
                // 验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo);
                if (detail == null)
                {
                    throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
                }
                #region 包装
                var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
                if (pack == null)
                {
                    throw new Exception("-1:获取物料包装失败,请核实!");
                }
                var pNum = 0;//托盘物品数量
                var bNum = 0;//箱码物品数量
                if (pack.L5Num.HasValue)
                {
                    pNum = (int)pack.L5Num;
                    bNum = (int)pack.L4Num;
                }
                else if (pack.L4Num.HasValue)
                {
                    pNum = (int)pack.L4Num;
                    bNum = (int)pack.L3Num;
                }
                else if (pack.L3Num.HasValue)
                {
                    pNum = (int)pack.L3Num;
                    bNum = (int)pack.L2Num;
                }
                else if (pack.L2Num.HasValue)
                {
                    pNum = (int)pack.L2Num;
                    bNum = (int)pack.L1Num;
                }
                else if (pack.L1Num.HasValue)
                {
                    pNum = (int)pack.L1Num;
                    bNum = (int)pack.L1Num;
                }
                if (pNum == 0 || bNum == 0)
                {
                    throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                }
                #endregion
                #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
                var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
                if (palletBind != null)
                {
                    var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
                    if (box != null && (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo))
                    //从物料名称-批次中取出批次
                    int indexOfDash = model.LotNo.IndexOf("-");
                    if (indexOfDash != -1)
                    {
                        var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
                        if (funSetting == null || funSetting.IsEnable == "OFF")
                        {
                            throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
                        }
                    }
                }
                #endregion
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                var bindId = 0;
                if (bind == null)
                {
                    bind = new BllPalletBind
                    {
                        ASNNo = model.AsnNo,
                        ASNDetailNo = (int)model.AsnDetailId,
                        PalletNo = model.PalletNo,
                        PalletNo2 = "",
                        PalletNo3 = "",
                        Qty = 0,
                        FullQty = pNum,
                        Status = "0",
                        Type = "0",
                        LotNo = detail.LotNo,
                        LotText = detail.LotText,
                        SupplierLot = "",
                        InspectMark = "0",
                        BitPalletMark = "1",
                        IsBale = "0",
                        IsBelt = "0",
                        CreateUser = userId
                    };
                    // 插入托盘绑定表
                    bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                }
                else
                {
                    if (bind.Status != "0")
                    {
                        throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
                    }
                    bindId = bind.Id;
                }
                #region 箱码信息
                var msgStr = $"箱号为{model.BoxNo}";
                var boxInfoList = new List<BllBoxInfo>();
                //首箱
                var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList();
                if (boxInfo.Count == 0)
                {
                    throw new Exception("-1:箱码信息不存在!");
                }
                boxInfoList.AddRange(boxInfo);
                //是否连续组托
                if (model.IsContinue == "1")
                {
                    //尾箱
                    var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList();
                    if (boxInfo2.Count == 0)
                    {
                        throw new Exception("-1:尾箱码信息不存在!");
                    }
                    boxInfoList.AddRange(boxInfo2);
                    var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
                    var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
                    boxInfoList.AddRange(list);
                    msgStr += $"尾箱号为{model.TailBoxNo}";
                }
                #endregion
                // 更改箱支关系表
                var factQty = 0;//托盘总数量
                var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                foreach (var g in boxGroup)
                {
                    var boxFullQty = 0;//箱内总数量
                    foreach (var box in g)
                    {
                        if (box.BindNo != null && box.BindNo != 0)
                        {
                            continue;
                        }
                        //箱内物料批次与单据明细不符合
                        if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo)
                        {
                            throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                        }
                        box.ASNNo = model.AsnNo;
                        box.ASNDetailNo = model.AsnDetailId;
                        box.BindNo = bindId;
                        box.PalletNo = model.PalletNo;
                        box.Status = "1";
                        box.CompleteTime = DateTime.Now;
                        box.UpdateTime = DateTime.Now;
                        box.UpdateUser = userId;
                        factQty += box.Qty;
                        boxFullQty += box.Qty;
                    }
                    if (boxFullQty > bNum)
                    {
                        throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                    }
                }
                Db.Updateable(boxInfoList).ExecuteCommand();
                // 更新托盘绑定表
                bind.Qty += factQty;
                if (bind.FullQty < bind.Qty)
                {
                    throw new Exception("托盘绑定数量已超出该物料包装数量");
                }
                if (bind.FullQty == bind.Qty)
                {
                    bind.BitPalletMark = "0";
                }
                Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                // 更改入库单明细已组数量
                var sqlString = string.Empty;
                sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';";
                Db.Ado.ExecuteCommand(sqlString);
                // 更改入库单及入库明细状态
                if (detail.Status == "0")
                {
                    var sqlString2 = string.Empty;
                    sqlString2 += $"update BllArrivalNotice set Status = '1',CompleteTime= getDate() where ASNNo = '{model.AsnNo}' and Status ='0';";
                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',CompleteTime= getDate() where id = '{model.AsnDetailId}' and Status ='0';";
                    Db.Ado.ExecuteCommand(sqlString2);
                }
                // 更改托盘使用状态
                var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
                //添加托盘记录表数据
                sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
                Db.Ado.ExecuteCommand(sqlStr);
                new OperationASNServer().AddLogOperationAsn("PDA模块", "产品组托", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
                Db.CommitTran();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                throw ex;
            }
        }
        // 绑定物料托盘
        public void BindPalletForLabelBox(PdaPalletBindVm model, int userId)
        {
            try
            {
                Db.BeginTran();
                //托盘是否存在
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息,请核实!");
                }
                // 验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo);
                if (detail == null)
                {
                    throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
                }
                #region 包装
                var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
                if (pack == null)
                {
                    throw new Exception("-1:获取物料包装失败,请核实!");
                }
                var pNum = 0;//托盘物品数量
                var bNum = 0;//箱码物品数量
                if (pack.L5Num.HasValue)
                {
                    pNum = (int)pack.L5Num;
                    bNum = (int)pack.L4Num;
                }
                else if (pack.L4Num.HasValue)
                {
                    pNum = (int)pack.L4Num;
                    bNum = (int)pack.L3Num;
                }
                else if (pack.L3Num.HasValue)
                {
                    pNum = (int)pack.L3Num;
                    bNum = (int)pack.L2Num;
                }
                else if (pack.L2Num.HasValue)
                {
                    pNum = (int)pack.L2Num;
                    bNum = (int)pack.L1Num;
                }
                else if (pack.L1Num.HasValue)
                {
                    pNum = (int)pack.L1Num;
                    bNum = (int)pack.L1Num;
                }
                if (pNum == 0 || bNum == 0)
                {
                    throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                }
                #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
                var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
                if (palletBind != null)
                {
                    var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
                    if (box != null && (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo))
                    {
                        var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
                        if (funSetting == null || funSetting.IsEnable == "OFF")
                        {
                            throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
                        }
                    }
                }
                #endregion
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                var bindId = 0;
                if (bind == null)
                {
                    bind = new BllPalletBind
                    {
                        ASNNo = model.AsnNo,
                        ASNDetailNo = (int)model.AsnDetailId,
                        PalletNo = model.PalletNo,
                        PalletNo2 = "",
                        PalletNo3 = "",
                        Qty = 0,
                        FullQty = pNum,
                        Status = "0",
                        Type = "0",
                        LotNo = detail.LotNo,
                        LotText = detail.LotText,
                        SupplierLot = "",
                        InspectMark = "0",
                        BitPalletMark = "1",
                        IsBale = "0",
                        IsBelt = "0",
                        CreateUser = userId
                    };
                    // 插入托盘绑定表
                    bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                }
                else
                {
                    if (bind.Status != "0")
                    {
                        throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
                    }
                    bindId = bind.Id;
                }
                #region 箱码信息
                var msgStr = $"箱号为{model.BoxNo}";
                var boxInfoList = new List<BllLabelBoxNo>();
                //首箱
                var boxInfo = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Level == "1").ToList();
                if (boxInfo.Count == 0)
                {
                    throw new Exception("-1:箱码信息不存在!");
                }
                //是否连续组托
                if (model.IsContinue == "1")
                {
                    boxInfoList.AddRange(boxInfo);
                    //尾箱
                    var boxInfo2 = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Level == "1").ToList();
                    if (boxInfo2.Count == 0)
                    {
                        throw new Exception("-1:尾箱码信息不存在!");
                    }
                    boxInfoList.AddRange(boxInfo2);
                    var sql = $"select * from BllLabelBoxNo where IsDel = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}' and Level='1'; ";
                    var list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql);
                    boxInfoList.AddRange(list);
                    //找到相关的二级码
                    foreach (var item in boxInfoList)
                    {
                        sql = $"select * from BllLabelBoxNo  where IsDel = '0' and IsUse = '0' and ParentBoxNo='{item.BoxNo}' and Level = '2' ";
                        list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql);
                        boxInfoList.AddRange(list);
                    }
                    msgStr += $"尾箱号为{model.TailBoxNo}";
                }
                else
                {
                    var boxInfoList2 = new List<BllLabelBoxNo>();//所有二级码
                    decimal boxQty = 0.00m;//箱内二级码数量
                    if (!string.IsNullOrEmpty(model.BoxNo01))
                    {
                        //二级码首码
                        var box01Info = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo01 && m.IsUse == "0" && m.Level == "2" && (string.IsNullOrEmpty(m.ParentBoxNo) || m.ParentBoxNo == model.BoxNo)).ToList();
                        if (box01Info.Count == 0)
                        {
                            throw new Exception("-1:二级码首码信息不存在!");
                        }
                        boxInfoList2.AddRange(box01Info);
                        if (model.IsContinue2 == "1")
                        {
                            //二级码尾码
                            var box01Info2 = Db.Queryable<BllLabelBoxNo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo01 && m.IsUse == "0" && m.Level == "2" && (string.IsNullOrEmpty(m.ParentBoxNo) || m.ParentBoxNo == model.BoxNo)).ToList();
                            if (box01Info2.Count == 0)
                            {
                                throw new Exception("-1:二级码尾码信息不存在!");
                            }
                            boxInfoList2.AddRange(box01Info2);
                            //中间码
                            var sql = $"select * from BllLabelBoxNo where IsDel = '0' and IsUse = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}' and Level='2' and (ParentBoxNo='' || ParentBoxNo='{model.BoxNo}'); ";
                            var list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql);
                            boxInfoList2.AddRange(list);
                        }
                        foreach (var item in boxInfoList2)
                        {
                            item.ParentBoxNo = model.BoxNo;
                            boxQty += item.Qty;
                        }
                        boxInfoList.AddRange(boxInfoList2);
                        foreach (var item in boxInfo)
                        {
                            item.Qty += boxQty;
                        }
                        model.LotNo = model.LotNo.Substring(indexOfDash + 1);
                    }
                    else
                    {
                        //找到相关的二级码
                        foreach (var item in boxInfo)
                        model.LotNo = "";
                    }
                }
                //判断物料数量是否为0 为0判断箱码信息 不为0继续
                if (model.TableType == 0)
                {
                    if (string.IsNullOrEmpty(model.BoxNo))
                    {
                        throw new Exception("-1:箱码信息不可为空!");
                    }
                    if (model.IsContinue == "1")
                    {
                        if (string.IsNullOrWhiteSpace(model.TailBoxNo))
                        {
                            string sql = $"select * from BllLabelBoxNo  where IsDel = '0' and IsUse = '0' and ParentBoxNo='{item.BoxNo}' and Level = '2' ";
                            var list = Db.Ado.SqlQuery<BllLabelBoxNo>(sql);
                            boxInfoList.AddRange(list);
                            throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!");
                        }
                    }
                }
                int isTextTable = model.TableType;
                int isDeposit = 0;
                //判断总单单据是否为寄存单据
                if (notice.Type == "7")
                {
                    isDeposit = 1;
                }
                if (isDeposit == 1)
                {
                    //判断总单备注是否为空
                    if (!string.IsNullOrWhiteSpace(notice.Demo))
                    {
                        //分割总单备注及托盘备注
                        var noticeDemo = notice.Demo.Split('、'); //总单备注
                        var palletDemo = model.Demo.Split('、'); //托盘备注
                        //循环托盘备注
                        foreach (var itemPallet in palletDemo)
                        {
                            int isDemo = 0;
                            //循环总单备注
                            foreach (var itemNotice in noticeDemo)
                            {
                                //判断是否有相同备注
                                if (itemPallet == itemNotice)
                                {
                                    isDemo = 1;
                                    break;
                                }
                            }
                            if (isDemo == 0)
                            {
                                throw new Exception("-1:总单备注与托盘备注不符,请核实后重新绑定!");
                            }
                        }
                    }
                    boxInfoList.AddRange(boxInfo);
                    else if (string.IsNullOrWhiteSpace(notice.Demo))
                    {
                        //判断托盘备注是否为空
                        if (!string.IsNullOrWhiteSpace(model.Demo))
                        {
                            throw new Exception("-1:请添加总单备注后输入托盘备注!");
                        }
                    }
                }
                #endregion
                Db.BeginTran();
                //托盘是否存在
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息,请核实!");
                }
                //判断托盘是否在库外
                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (stockDetail != null)// && !string.IsNullOrEmpty(stockDetail.WareHouseNo)
                {
                    throw new Exception("该托盘在库存已有信息,请核实!");
                }
                // 验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo));
                if (detail == null)
                {
                    throw new Exception("-1:当前物料及批次与单据无关联,请核实!");
                }
                #region 包装
                var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
                var pNum = 0;//托盘物品数量
                var bNum = 0;//箱码物品数量
                //判断是否为寄存物料
                if (isDeposit == 0 && isTextTable == 0)
                {
                    if (pack == null)
                    {
                        throw new Exception("-1:获取物料包装失败,请核实!");
                    }
                    if (pack.L5Num.HasValue)
                    {
                        pNum = (int)pack.L5Num;
                        bNum = (int)pack.L4Num;
                    }
                    else if (pack.L4Num.HasValue)
                    {
                        pNum = (int)pack.L4Num;
                        bNum = (int)pack.L3Num;
                    }
                    else if (pack.L3Num.HasValue)
                    {
                        pNum = (int)pack.L3Num;
                        bNum = (int)pack.L2Num;
                    }
                    else if (pack.L2Num.HasValue)
                    {
                        pNum = (int)pack.L2Num;
                        bNum = (int)pack.L1Num;
                    }
                    else if (pack.L1Num.HasValue)
                    {
                        pNum = (int)pack.L1Num;
                        bNum = (int)pack.L1Num;
                    }
                    if (pNum == 0 || bNum == 0)
                    {
                        throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                    }
                }
                #endregion
                #endregion
                // 更改箱支关系表
                decimal factQty = 0.00m;//托盘总数量
                foreach (var box in boxInfoList)
                #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
                var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
                if (palletBind != null)
                {
                    //箱内物料批次与单据明细不符合
                    if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo)
                    var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
                    if (box != null && (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo))
                    {
                        throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                    }
                    if (box.IsUse != "0")
                    {
                        continue;
                    }
                    if (box.Level == "1")
                    {
                        if (box.Qty > bNum)
                        var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
                        if (funSetting == null || funSetting.IsEnable == "OFF")
                        {
                            throw new Exception($"绑定失败,{box.BoxNo}箱码绑定数量大于该物品包装数量!");
                            throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
                        }
                        factQty += box.Qty;
                    }
                    //box.ASNNo = model.AsnNo;
                    //box.ASNDetailNo = model.AsnDetailId;
                    box.IsUse = "1";
                    box.CompleteTime = DateTime.Now;
                    box.UpdateTime = DateTime.Now;
                    box.UpdateUser = userId;
                }
                Db.Updateable(boxInfoList).ExecuteCommand();
                }
                #endregion
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo && m.Status != "2");
                var bindId = 0;
                if (bind == null)
                {
                    bind = new BllPalletBind
                    {
                        ASNNo = model.AsnNo,
                        ASNDetailNo = (int)model.AsnDetailId,
                        PalletNo = model.PalletNo,
                        PalletNo2 = "",
                        PalletNo3 = "",
                        Qty = model.SkuQty,
                        FullQty = pNum,
                        Status = "0",
                        Type = "0",
                        LotNo = model.LotNo,
                        LotText = detail.LotText,
                        SupplierLot = detail.SupplierLot,
                        InspectMark = "0",
                        BitPalletMark = "1",
                        IsBale = "0",
                        IsBelt = "0",
                        CreateUser = userId,
                        Demo = model.Demo,
                // 更新托盘绑定表
                bind.Qty += factQty;
                if (bind.FullQty < bind.Qty)
                    };
                    //if (model.TableType == 0 && isDeposit == 0 && isTextTable == 0)   不太理解这段代码的含义
                    //{
                    //    throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                    //}
                    // 插入托盘绑定表
                    bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                }
                else
                {
                    if (bind.Status != "0")
                    {
                        throw new Exception("-1:当前托盘正在执行中,绑定失败,请核实!");
                    }
                    bindId = bind.Id;
                    bind.Qty += model.SkuQty;
                }
                #region 箱码信息
                var msgStr = $"箱号为{model.BoxNo}";
                var boxInfoList = new List<BllBoxInfo>();
                if (model.SkuQty == 0)
                {
                    //首箱
                    var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList();
                    if (boxInfo.Count == 0)
                    {
                        throw new Exception("-1:箱码信息不存在!");
                    }
                    boxInfoList.AddRange(boxInfo);
                    //是否连续组托
                    if (model.IsContinue == "1")
                    {
                        //尾箱
                        var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList();
                        if (boxInfo2.Count == 0)
                        {
                            throw new Exception("-1:尾箱码信息不存在!");
                        }
                        boxInfoList.AddRange(boxInfo2);
                        var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
                        var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
                        boxInfoList.AddRange(list);
                        msgStr += $"尾箱号为{model.TailBoxNo}";
                    }
                }
                #endregion
                // 更改箱支关系表
                decimal factQty = 0.00m;//托盘总数量
                //成品组托
                if (isTextTable == 0)
                {
                    var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                    foreach (var g in boxGroup)
                    {
                        decimal boxFullQty = 0;//箱内总数量
                        foreach (var box in g)
                        {
                            if (box.BindNo != null && box.BindNo != 0)
                            {
                                continue;
                            }
                            //箱内物料批次与单据明细不符合
                            if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
                            {
                                throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                            }
                            box.ASNNo = model.AsnNo;
                            box.ASNDetailNo = model.AsnDetailId;
                            box.BindNo = bindId;
                            box.PalletNo = model.PalletNo;
                            box.Status = "1";
                            box.CompleteTime = DateTime.Now;
                            box.UpdateTime = DateTime.Now;
                            box.UpdateUser = userId;
                            factQty += box.Qty;
                            boxFullQty += box.Qty;
                        }
                        if (boxFullQty > bNum)
                        {
                            throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                        }
                    }
                    Db.Updateable(boxInfoList).ExecuteCommand();
                    // 更新托盘绑定表
                    bind.Qty += factQty;
                }
                if (bind.FullQty < bind.Qty && isDeposit == 0 && isTextTable == 0)
                {
                    throw new Exception("托盘绑定数量已超出该物料包装数量");
                }
@@ -2028,19 +2266,38 @@
                {
                    bind.BitPalletMark = "0";
                }
                if (bind.Qty > pNum && isDeposit == 0 && isTextTable == 0)
                {
                    throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                }
                Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                // 更改入库单明细已组数量
                var sqlString = string.Empty;
                sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';";
                if (factQty == 0)
                {
                    sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{model.SkuQty}' where id = '{model.AsnDetailId}';";
                }
                else
                {
                    sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';";
                }
                Db.Ado.ExecuteCommand(sqlString);
                // 更改入库单及入库明细状态
                if (detail.Status == "0")
                {
                    var sqlString2 = string.Empty;
                    sqlString2 += $"update BllArrivalNotice set Status = '1',CompleteTime= getDate() where ASNNo = '{model.AsnNo}' and Status ='0';";
                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',CompleteTime= getDate() where id = '{model.AsnDetailId}' and Status ='0';";
                    sqlString2 += $"update BllArrivalNotice set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='0';";
                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='0';";
                    Db.Ado.ExecuteCommand(sqlString2);
                }
                else if (detail.Status == "1")
                {
                    var sqlString2 = string.Empty;
                    sqlString2 += $"update BllArrivalNotice set UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='1';";
                    sqlString2 += $"update BllArrivalNoticeDetail set UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='1';";
                    Db.Ado.ExecuteCommand(sqlString2);
                }
@@ -2049,14 +2306,448 @@
                //添加托盘记录表数据
                sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
                Db.Ado.ExecuteCommand(sqlStr);
                new OperationASNServer().AddLogOperationAsn("PDA模块", "产品组托", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
                new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
                Db.CommitTran();
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                Db.RollbackTran();
                throw ex;
            }
        }
        #endregion
        #region 平库入库
        /// <summary>
        /// 平库确认入库
        /// </summary>
        /// <param name="model"></param>
        public void ConfirmInStock(PalletBindVm model)
        {
            try
            {
                #region 验证信息
                //if (string.IsNullOrEmpty(model.ASNNo))
                //{
                //    throw new Exception("入库单不能为空!");
                //}
                if (string.IsNullOrEmpty(model.PalletNo))
                {
                    throw new Exception("托盘条码不能为空!");
                }
                if (string.IsNullOrEmpty(model.LocatNo))
                {
                    throw new Exception("储位地址不能为空!");
                }
                #endregion
                //获取当前时间
                DateTime serverTime = Db.Ado.GetDateTime("select GETDATE();");
                #region 是否回流入库
                int iscount = 0;
                //库存明细信息
                var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList();
                //验证库存是否拥有该托信息
                if (stockDetail != null && stockDetail.Count > 0)
                {
                    foreach (var item in stockDetail)
                    {
                        if (!string.IsNullOrEmpty(item.WareHouseNo))
                        {
                            throw new Exception("该托盘未在库外,请核查!");
                        }
                    }
                    iscount = 1; //回流入库
                }
                #endregion
                #region 托盘绑定信息
                var bindInfo = Db.Queryable<BllPalletBind>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo && w.Status != "2");
                if (iscount == 0)
                {
                    if (bindInfo == null)
                    {
                        throw new Exception("托盘绑定信息不存在,请核查!");
                    }
                    if (!string.IsNullOrEmpty(bindInfo.WareHouseNo))
                    {
                        throw new Exception("该托盘未在库外,请核查!");
                    }
                }
                #endregion
                #region 地码信息(储位信息)
                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02");
                if (storageLocat == null)
                {
                    throw new Exception("储位信息不存在或非空闲状态,请核查!");
                }
                #endregion
                Db.BeginTran();//开启事务
                if (iscount == 0)//正常入库
                {
                    #region 入库总单信息
                    var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.Status != "3" && a.ASNNo == model.ASNNo);
                    //验证入库单总单是否关闭
                    if (notice == null)
                    {
                        throw new Exception("入库单总单信息不存在,请核查!");
                    }
                    //判断入库单总单是否为已关闭
                    if (notice.Status == "3")
                    {
                        throw new Exception("入库单总单已关闭,请核查!");
                    }
                    #endregion
                    #region 箱码信息
                    var boxInfoList = Db.Queryable<BllBoxInfo>().Where(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo).ToList();
                    // type 0:成品入库 1:采购入库 2:中间品入库 3:退货入库 4:车间余料退回入库 5:其它入库 6:代储入库 7:寄存入库
                    if (notice.Type == "2" || notice.Type == "6" || notice.Type == "7")
                    {
                        // 不贴码物料 无需验证箱码信息
                    }
                    else
                    {
                        //验证箱码信息是否存在
                        if (boxInfoList.Count <= 0)
                        {
                            throw new Exception("箱码信息不存在,请核查!");
                        }
                        foreach (var item in boxInfoList)
                        {
                            item.Status = "2"; // 改变箱支关系表状态:已入库
                            item.UpdateTime = serverTime;
                            item.UpdateUser = model.CreateUser;
                        }
                        Db.Updateable(boxInfoList).ExecuteCommand();
                    }
                    #endregion
                    bool isFinsh = true;//是否全部入库完成
                    #region 入库单明细
                    var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.Id == bindInfo.ASNDetailNo);
                    if (noticeDetail == null)
                    {
                        throw new Exception("入库单明细信息不存在,请核查!");
                    }
                    noticeDetail.CompleteQty += bindInfo.Qty;//增加入库数量
                    //判断入库数量增加后是否大于等于单据数量
                    if (noticeDetail.CompleteQty >= noticeDetail.Qty)
                    {
                        noticeDetail.Status = "2";//执行完成
                        noticeDetail.CompleteTime = serverTime;
                    }
                    else
                    {
                        noticeDetail.Status = "1";//正在执行
                        isFinsh = false;
                    }
                    noticeDetail.UpdateUser = model.CreateUser;
                    noticeDetail.UpdateTime = serverTime;
                    Db.Updateable(noticeDetail).ExecuteCommand();
                    #endregion
                    #region 物料信息
                    var sku = Db.Queryable<SysMaterials>().First(s => s.SkuNo == noticeDetail.SkuNo && s.IsDel == "0" && s.SkuName == noticeDetail.SkuName);
                    //判断物料信息是否为空
                    if (sku == null)
                    {
                        throw new Exception("物料信息不存在,请核查!");
                    }
                    #endregion
                    #region 库存总表
                    // 判断当前物料库存表是否已存在
                    var stockModel = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == noticeDetail.SkuNo && w.LotNo == bindInfo.LotNo && w.Standard == noticeDetail.Standard);
                    if (stockModel == null || stockModel.Id == 0)
                    {
                        stockModel = new DataStock
                        {
                            LotNo = bindInfo.LotNo,
                            LotText = bindInfo.LotText,
                            SupplierLot = bindInfo.SupplierLot,
                            SkuNo = noticeDetail.SkuNo,
                            SkuName = noticeDetail.SkuName,
                            Qty = bindInfo.Qty,
                            Standard = noticeDetail.Standard,
                            CreateUser = (int)model.CreateUser,
                            CreateTime = serverTime
                        };
                        //维护库存货主信息
                        if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                        {
                            stockModel.OwnerNo = notice.CustomerNo;//货主编码
                            stockModel.OwnerName = notice.CustomerName;//货主名称
                        }
                        //新增库存总信息
                        Db.Insertable<DataStock>(stockModel).ExecuteCommand();
                    }
                    else
                    {
                        stockModel.Qty += bindInfo.Qty;
                        stockModel.UpdateUser = (int)model.CreateUser;
                        stockModel.UpdateTime = serverTime;
                        //修改库存总信息
                        Db.Updateable(stockModel).ExecuteCommand();
                    }
                    #endregion
                    #region 库存明细表
                    // 判断当前托盘是否已存在(拣货回库托盘)
                    var detailModel = Db.Queryable<DataStockDetail>().First(it => it.PalletNo == bindInfo.PalletNo && it.LotNo == bindInfo.LotNo && it.SkuNo == noticeDetail.SkuNo
                        && it.Standard == noticeDetail.Standard && it.IsDel == "0");
                    var stId = 0;
                    if (detailModel == null || detailModel.Id == 0)
                    {
                        // 添加库存明细表
                        detailModel = new DataStockDetail()
                        {
                            LotNo = bindInfo.LotNo,
                            LotText = bindInfo.LotText,
                            SupplierLot = noticeDetail.SupplierLot,
                            SkuNo = noticeDetail.SkuNo,
                            SkuName = noticeDetail.SkuName,
                            Standard = noticeDetail.Standard,
                            Qty = bindInfo.Qty,
                            LockQty = 0,
                            FrozenQty = 0,
                            InspectQty = bindInfo.Qty,
                            ASNNo = noticeDetail.ASNNo,
                            ASNDetailNo = (int)bindInfo.ASNDetailNo,
                            WareHouseNo = "W02",
                            RoadwayNo = "",
                            AreaNo = storageLocat.AreaNo,
                            LocatNo = model.LocatNo,
                            PalletNo = model.PalletNo,
                            PalletNo2 = bindInfo.PalletNo2,
                            PalletNo3 = bindInfo.PalletNo3,
                            CompleteTime = serverTime,
                            ProductionTime = bindInfo.ProductionTime,
                            ExpirationTime = bindInfo.ExpirationTime,
                            Status = "0",
                            InspectMark = bindInfo.InspectMark,
                            BitPalletMark = bindInfo.BitPalletMark,
                            InspectStatus = sku.IsInspect,// 组盘的时候就要默认设定好是否合格
                            PackagNo = sku.PackagNo,
                            IsBale = bindInfo.IsBale,
                            IsBelt = bindInfo.IsBelt,
                            Demo = bindInfo.Demo,
                            CreateUser = (int)model.CreateUser,
                            CreateTime = serverTime
                        };
                        //维护库存明细货主/供应商信息
                        if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                        {
                            detailModel.OwnerNo = notice.CustomerNo;//货主编码
                            detailModel.OwnerName = notice.CustomerName;//货主名称
                        }
                        else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
                        {
                            detailModel.SupplierNo = notice.CustomerNo;//供应商编码
                            detailModel.SupplierName = notice.CustomerName;//供应商名称
                        }
                        #region  维护质检结果
                        //获取该批次最终质检结果
                        var quality = Db.Queryable<BllQualityInspect>().Where(a => a.LotNo == noticeDetail.LotNo && a.IsDel == "0").OrderByDescending(a => a.CreateTime).First();
                        if (quality != null)
                        {
                            //修改合格不合格数量
                            if (quality.IsQualified == "1") //合格
                            {
                                //增加合格数量
                                quality.PassQty += detailModel.Qty;
                                detailModel.InspectStatus = "1";
                            }
                            else if (quality.IsQualified == "0") //不合格
                            {
                                //增加不合格数量
                                quality.FailQty += detailModel.Qty;
                                detailModel.InspectStatus = "2";
                            }
                            Db.Updateable(quality).ExecuteCommand(); //修改质检信息
                        }
                        #endregion
                        stId = Db.Insertable<DataStockDetail>(detailModel).ExecuteReturnIdentity();
                    }
                    else
                    {
                        stId = detailModel.Id;
                        detailModel.LocatNo = model.LocatNo;
                        detailModel.AreaNo = storageLocat.AreaNo;
                        detailModel.UpdateTime = serverTime;
                        detailModel.UpdateUser = (int)model.CreateUser;
                        // 变更储位地址
                        Db.Updateable<DataStockDetail>(detailModel).UpdateColumns(it => new { it.LocatNo, it.UpdateTime, it.UpdateUser }).ExecuteCommand();
                    }
                    #endregion
                    #region 任务及组托信息
                    //创建任务信息
                    var taskNo = new Common().GetMaxNo("TK");
                    var exTask = new LogTask    //入库任务
                    {
                        TaskNo = taskNo,
                        Sender = "WMS",
                        Receiver = "PDA",
                        IsSuccess = 1, //是否下发成功 0失败 1成功
                        SendDate = serverTime,  //发送时间
                        BackDate = serverTime,  //返回时间
                        StartLocat = "",//起始位置
                        EndLocat = model.LocatNo,//目标位置
                        PalletNo = bindInfo.PalletNo,//托盘码
                        IsSend = 0,//是否可再次下发
                        IsCancel = 0,//是否可取消
                        IsFinish = 0,//是否可完成
                        Type = "0",//任务类型 0 入库任务 1 出库任务  2 移库任务
                        Status = "2",//任务状态0:等待执行1正在执行2执行完成
                        OrderType = "0",//0 入库单 1 出库单  2 盘点单  3 移库单
                        Msg = "力诺平库的入库任务",
                    };
                    Db.Insertable(exTask).ExecuteCommand();
                    //修改组托状态
                    bindInfo.Status = "2"; //2 入库完成
                    bindInfo.WareHouseNo = "W02";//所属仓库
                    bindInfo.LocatNo = model.LocatNo;//储位地址
                    bindInfo.UpdateTime = serverTime;
                    bindInfo.UpdateUser = model.CreateUser;
                    bindInfo.CompleteTime = serverTime; //完成时间
                    bindInfo.TaskNo = taskNo; //任务号
                    Db.Updateable(bindInfo).ExecuteCommand();
                    #endregion
                    #region 库存箱支明细表
                    // 插入新组的箱支信息
                    var comTime = DateTime.Now;
                    foreach (var item in boxInfoList)
                    {
                        var info = new DataBoxInfo()
                        {
                            StockDetailId = stId,
                            BindNo = bindInfo.Id,
                            BoxNo = item.BoxNo,
                            BoxNo2 = item.BoxNo2,
                            BoxNo3 = item.BoxNo3,
                            PalletNo = item.PalletNo,
                            PalletNo2 = item.PalletNo2,
                            PalletNo3 = item.PalletNo3,
                            Qty = item.Qty,
                            FullQty = item.FullQty,
                            Status = "2",
                            LotNo = item.LotNo,
                            LotText = item.LotText,
                            SkuNo = item.SkuNo,
                            SkuName = item.SkuName,
                            Standard = sku.Standard,
                            ProductionTime = item.ProductionTime,
                            SupplierLot = item.SupplierLot,
                            InspectMark = item.InspectMark,
                            BitBoxMark = item.BitBoxMark,
                            InspectStatus = item.InspectStatus,
                            //InspectTime = item.,
                            IsDel = "0",
                            CreateUser = 0,
                            CreateTime = comTime
                        };
                        Db.Insertable(info).ExecuteCommand();
                    }
                    #endregion
                    var entryList = Db.Queryable<BllArrivalNoticeDetail>().Where(w => w.IsDel == "0" && w.ASNNo == notice.ASNNo && w.Id != noticeDetail.Id && w.Status != "2").ToList();
                    if (isFinsh && entryList.Count <= 0)//入库单明细全部完成
                    {
                        //修改入库单总单信息
                        notice.Status = "2";
                        notice.UpdateUser = model.CreateUser;
                        notice.UpdateTime = serverTime;
                        Db.Updateable(notice).ExecuteCommand();
                    }
                    else
                    {
                        //判断总单状态是否为正在执行
                        if (notice.Status == "0")
                        {
                            //修改入库单总单信息
                            notice.Status = "1";
                            notice.UpdateUser = model.CreateUser;
                            notice.UpdateTime = serverTime;
                            Db.Updateable(notice).ExecuteCommand();
                        }
                    }
                }
                else
                {
                    //修改库存明细信息
                    foreach (var item in stockDetail)
                    {
                        item.Status = "0"; //状态更改为待分配
                        item.WareHouseNo = "W02"; //所属仓库
                        item.LocatNo = model.LocatNo;//储位地址
                        item.UpdateTime = serverTime; //修改时间
                        item.UpdateUser = model.CreateUser; //修改人
                        //修改库存明细信息
                        Db.Updateable(item).ExecuteCommand();
                    }
                    //获取拣货信息
                    var alotr = Db.Queryable<BllExportAllot>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo && a.Status == "4");
                    if (alotr != null)
                    {
                        alotr.Status = "5"; //5 已完成
                        alotr.UpdateUser = model.CreateUser; //修改人
                        alotr.UpdateTime = serverTime; //修改时间
                        //修改拣货信息
                        Db.Updateable(alotr).ExecuteCommand();
                    }
                    #region 任务及组托信息
                    //创建任务信息
                    var taskNo = new Common().GetMaxNo("TK");
                    var exTask = new LogTask    //入库任务
                    {
                        TaskNo = taskNo,
                        Sender = "WMS",
                        Receiver = "PDA",
                        IsSuccess = 1, //是否下发成功 0失败 1成功
                        SendDate = DateTime.Now,  //发送时间
                        BackDate = DateTime.Now,  //返回时间
                        StartLocat = "",//起始位置
                        EndLocat = model.LocatNo,//目标位置
                        PalletNo = model.PalletNo,//托盘码
                        IsSend = 0,//是否可再次下发
                        IsCancel = 0,//是否可取消
                        IsFinish = 0,//是否可完成
                        Type = "0",//任务类型 0 入库任务 1 出库任务  2 移库任务
                        Status = "2",//任务状态0:等待执行1正在执行2执行完成
                        OrderType = "3",//0 入库单 1 出库单  2 盘点单  3 移库单
                        Msg = "力诺平库的回库任务",
                    };
                    Db.Insertable(exTask).ExecuteCommand();
                    #endregion
                }
                storageLocat.Status = "1";//状态已使用
                storageLocat.UpdateTime = serverTime; //修改时间
                storageLocat.UpdateUser = model.CreateUser; //修改人
                //修改储位信息
                Db.Updateable(storageLocat).ExecuteCommand();
                if (iscount == 1)
                {
                    new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成", $"在PDA上完成托盘码为:{model.PalletNo}的平库回流入库操作", (int)model.CreateUser);
                }
                else
                {
                    new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成", $"在PDA上完成单据号为:{model.ASNNo}的托盘码为:{model.PalletNo}的平库入库操作", (int)model.CreateUser);
                }
                Db.CommitTran();
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw ex;
            }
        }