IPC-610
2024-12-03 2f0120d0c10ac24603936911ee5812d4e71d2740
Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -18,6 +18,13 @@
using Dm;
using Model.InterFaceModel;
using WMS.Entity.BllQualityEntity;
using Newtonsoft.Json;
using Utility.Tools;
using System.Reflection;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Net.WebSockets;
using WMS.BLL.SysServer;
namespace WMS.BLL.BllPdaServer
{
@@ -25,17 +32,117 @@
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        #region 修改托盘绑定时入库单去除变为物料+数量
        /// <summary>
        /// 获取单据明细显示的物料
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<ArrivalNoticeDetailDto> GetArrivalNoticesInfo(ArrivalNoticeVm model)
        {
            try
            {
                //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<ArrivalNoticeDetailDto>();
                if (model.Type.Contains("0"))//0贴标
                {
                    list = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && data.Contains(m.ASNNo) && !string.IsNullOrWhiteSpace(m.PackagNo)).Select(m => new ArrivalNoticeDetailDto()).ToList();
                }
                else if (model.Type.Contains("1"))//1不贴标
                {
                    list = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && data.Contains(m.ASNNo) && string.IsNullOrWhiteSpace(m.PackagNo)).Select(m=>new ArrivalNoticeDetailDto()).ToList();
                }
                else
                {
                    throw new Exception("页签类型参数错误");
                }
                List<ArrivalNoticeDetailDto> noticeList = new List<ArrivalNoticeDetailDto>();
                foreach (var item in list)
                {
                    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 noticeList;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
        // 获取单据列表
        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);
                return modelList;
                //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.Contains("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.Contains("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)
            {
@@ -103,6 +210,8 @@
                if (modelList.Count > 0)
                {
                    var notice = Db.Queryable<BllArrivalNotice>().First(m=>m.IsDel == "0" && m.ASNNo == modelList[0].ASNNo);
                    modelList[0].UDF5 = notice.Demo;
                    return modelList[0];
                }
@@ -225,6 +334,7 @@
        public string BindNullPallet(PalletBindVm model)
        {
            string strMsg = "";
            string type = model.BindType == "0" ? "PDA" : "叠托机";
            try
            {
                var datetime = Db.GetDate();
@@ -332,7 +442,7 @@
                    LotText = "",
                    SupplierLot = "",
                    InspectStatus = "1",
                    Origin = "PDA",
                    Origin = type,
                    BoxNo = "",
                    BoxNo2 = "",
                    BoxNo3 = "",
@@ -353,6 +463,120 @@
                // 插入操作日志
                new OperationASNServer().AddLogOperationAsn("PDA模块", "空托入库", model.PalletNo, "添加", $"在PDA上添加了空托盘跺", (int)model.CreateUser);
                return strMsg;
            }
            catch (Exception ex)
            {
                Db.Ado.RollbackTran();
                throw ex;
            }
        }
        // 叠托机绑定空托盘
        public string BindNullPallets(PalletsBind model)
        {
            string strMsg = "";
            string type = model.BindType == "0" ? "PDA" : "叠托机";
            try
            {
                var datetime = Db.GetDate();
                //获取托盘绑定信息
                string str = "select * from BllPalletBind where IsDel = '0' and PalletNo = @palletno and Status = '0' ";
                List<PalletBindVm> list = Db.Ado.SqlQuery<PalletBindVm>(str, new
                {
                    palletno = model.PalletNo //托盘号
                });
                //判断是否已绑定该托盘
                if (list.Count > 0)
                {
                    strMsg = "-1:该托盘已被绑定!";
                    return strMsg;
                }
                if (string.IsNullOrEmpty(model.PalletNo))
                {
                    strMsg = "-1:托盘号不可为空!";
                    return strMsg;
                }
                if (model.Qty == null || model.Qty == 0)
                {
                    strMsg = "-1:空托盘数量不可为空!";
                    return strMsg;
                }
                //获取托盘信息
                var pallet = Db.Queryable<SysPallets>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    strMsg = "-1:托盘信息为空!";
                    return strMsg;
                }
                if (pallet.Status != "0")
                {
                    strMsg = "-1:该托盘正在使用!";
                    return strMsg;
                }
                Db.BeginTran();
                // 插入托盘绑定表
                var modelpb = new BllPalletBind
                {
                    ASNNo = "",
                    ASNDetailNo = 0,
                    TaskNo = "", //任务号
                    PalletNo = model.PalletNo,
                    Qty = (int)model.Qty,
                    Status = "0", //等待执行
                    Type = "1", //0 物料托 1 空托
                    LotNo = "",
                    LotText = "",
                    SupplierLot = "",
                    InspectMark = "0", //0 否 1 是
                    BitPalletMark = "0",
                    IsBale = "0",
                    IsBelt = "0",
                    CreateTime = Db.GetDate()
                };
                var id = Db.Insertable(modelpb).ExecuteReturnIdentity();
                var modelbb = new BllBoxInfo
                {
                    ASNNo = "",
                    ASNDetailNo = null,
                    BindNo = id,
                    PalletNo = model.PalletNo,
                    Status = "1",
                    CompleteTime = DateTime.Now,
                    Qty = (int)model.Qty,
                    FullQty = null,
                    SkuNo = "100099",
                    SkuName = "托盘",
                    LotNo = "",
                    LotText = "",
                    SupplierLot = "",
                    InspectStatus = "1",
                    Origin = type,
                    BoxNo = "",
                    BoxNo2 = "",
                    BoxNo3 = "",
                    InspectMark = "",
                    BitBoxMark = "0",
                    CreateTime = datetime
                };
                Db.Insertable(modelbb).ExecuteCommand();
                // 更改托盘使用状态
                string sqlStr = string.Empty;
                sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
                Db.Ado.ExecuteCommand(sqlStr);
                Db.CommitTran();
                // 插入操作日志
                new OperationASNServer().AddLogOperationAsn("PDA模块", "空托入库", model.PalletNo, "添加", $"在PDA上添加了空托盘跺", 1);
                return strMsg;
            }
@@ -415,7 +639,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,
@@ -801,7 +1025,7 @@
                            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)
                        {
@@ -1402,7 +1626,7 @@
                {
                    throw new Exception("-1:箱码信息不存在,请核查!");
                }
                var bNum = 0;//数量
                decimal bNum = 0;//数量
                //验证箱码是否已绑定托盘
                foreach (var item in boxinfo)
                {
@@ -1685,18 +1909,198 @@
        }
        #region 产品组托
        public void GetBoxInfoByFuMa(string boxNo,string url,string fuMaTokenUrl,string levelType)
        {
            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 token = new Token().GetFuMaToken(fuMaTokenUrl);
                var getParentVal = levelType == "1" ? "true" : "false";
                var getChildrenVal = levelType == "3" ? "true" : "false";
                Dictionary<string, string> paramDic = new Dictionary<string, string>
                {
                    { "Token", token }, //分配的令牌(变量)
                    { "Barcode", boxNo },//要查询的条码
                    { "getParent", getParentVal },//是否查询父码
                    { "getChildren", getChildrenVal } //是否查询子码
                };
                //程序正式发布后放开
                var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
                var response = HttpHelper.DoGet(url, "赋码", "获取箱码信息", paramDic);
                var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
                //解析返回数据
                var fuMaModel = JsonConvert.DeserializeObject<FuMaGetBoxModel>(response);
                if (fuMaModel.IsSuccess)
                {
                    //赋码返回信息成功状态
                    if (fuMaModel.Product == null || fuMaModel.Barcodes.Count == 0)
                    {
                        throw new Exception("产品信息或箱支信息为空");
                    }
                    foreach (var item in fuMaModel.Barcodes)
                    {
                        if (item.Barcode != boxNo)
                        {
                            throw new Exception("获取信息不一致");
                        }
                        var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == fuMaModel.Product.ProductCode);
                        if (sku == null)
                        {
                            throw new Exception("未查询到箱码中的物料信息");
                        }
                        var boxInfo = new BllBoxInfo()
                        {
                            ASNNo = "",
                            //ASNDetailNo = 0,
                            OrderCode = "",
                            //BindNo = 0,
                            BoxNo = item.Barcode,
                            BoxNo2 = item.Barcode,
                            BoxNo3 = item.Barcode,
                            PalletNo = "",
                            Qty = item.BoxItemQty,
                            FullQty = fuMaModel.BoxItemQty,
                            Status = "0",
                            SkuNo = sku.SkuNo,
                            SkuName = sku.SkuName,
                            LotNo = item.BatchNo,
                            //LotText = "",
                            //SupplierLot = item.SupplierLot,
                            ProductionTime = DateTime.Parse(item.ProductionDate),
                            ExpirationTime = DateTime.Parse(item.ExpirationDate),
                            //CompleteTime = comTime,
                            InspectMark = "0",
                            BitBoxMark = item.Status == "零箱"? "1":"0",
                            InspectStatus = "0",
                            Origin = "赋码",
                            Standard = fuMaModel.Product.Spec,
                            PackageStandard = fuMaModel.Product.PackageSpec,
                            //StoreTime = item.StoreTime,
                            //QtyOrd = item.QtyOrd,
                            //QtyCount = item.QtyCount,
                            CreateUser = 0,
                            CreateTime = comTime,
                        };
                        list.Add(boxInfo);
                    }
                    Db.Insertable(list).ExecuteCommand();
                }
                else
                {
                    //赋码返回信息失败状态
                    throw new Exception($"赋码系统返回状态异常:{fuMaModel.Message}");
                }
                #endregion
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// 根据箱码获取标签箱码信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<BoxInfoDto> GetBindBoxInfos(BoxInfoVm model)
        public List<BoxInfoDto> GetBindBoxInfos(BoxInfoVm model, string url, string fuMaTokenUrl)
        {
            try
            {
                if (string.IsNullOrEmpty(model.BoxNo))
                {
                    throw new Exception("请扫描外箱条码!");
                }
                if (!string.IsNullOrWhiteSpace(model.ASNNo))
                {
                    var detailId = model.ASNNo.Split("-")[0];
                    var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m=>m.IsDel =="0" && m.Id == int.Parse(detailId));
                    if (detail != null)
                    {
                        var asnData = Db.Queryable<BllArrivalNotice>().First(m => m.IsDel == "0" && m.ASNNo == detail.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, url, fuMaTokenUrl,"1"); //从赋码系统获取箱码信息
                            }
                        }
                    }
                }
                string sqlString = $@"SELECT 
                                        ASNNo,
@@ -1711,7 +2115,7 @@
                                        AND BoxNo = '{model.BoxNo}'
                                      GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo; ";
                var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                if (models == null)
                if (models.Count == 0)
                {
                    throw new Exception("箱码信息不存在!");
                }
@@ -1722,6 +2126,111 @@
                throw ex;
            }
        }
        /// <summary>
        /// 根据箱码获取标签最小追溯码信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<BoxInfoDto> GetBindBoxInfo2s(BoxInfoVm model, string url, string fuMaTokenUrl)
        {
            try
            {
                if (string.IsNullOrEmpty(model.BoxNo3))
                {
                    throw new Exception("请扫描最小追溯条码!");
                }
                if (!string.IsNullOrWhiteSpace(model.ASNNo))
                {
                    var detailId = model.ASNNo.Split("-")[0];
                    var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == int.Parse(detailId));
                    if (detail != null)
                    {
                        var asnData = Db.Queryable<BllArrivalNotice>().First(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo);
                        if (asnData != null)
                        {
                            if (asnData.Type != "3")
                            {
                                throw new Exception("单据请选择退货入库单!");
                            }
                            var count = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.Status == "0" && m.BoxNo3 == model.BoxNo3);
                            if (count == 0)
                            {
                                //优先WMS查找
                                var comDetail = Db.Queryable<BllBoxInfo>().First(m=>m.BoxNo3 == model.BoxNo3 && m.IsDel =="0" && m.Status =="2");
                                if (comDetail!= null)
                                {
                                    var boxInfo = new BllBoxInfo()
                                    {
                                        ASNNo = "",
                                        //ASNDetailNo = 0,
                                        OrderCode = "",
                                        //BindNo = 0,
                                        BoxNo = comDetail.BoxNo,
                                        BoxNo2 = comDetail.BoxNo2,
                                        BoxNo3 = comDetail.BoxNo3,
                                        PalletNo = "",
                                        Qty = comDetail.Qty,
                                        FullQty = comDetail.FullQty,
                                        Status = "0",
                                        SkuNo = comDetail.SkuNo,
                                        SkuName = comDetail.SkuName,
                                        LotNo = comDetail.LotNo,
                                        LotText = comDetail.LotText,
                                        SupplierLot = comDetail.SupplierLot,
                                        ProductionTime = comDetail.ProductionTime,
                                        ExpirationTime = comDetail.ExpirationTime,
                                        //CompleteTime = comTime,
                                        InspectMark = comDetail.InspectMark,
                                        BitBoxMark = "1",
                                        InspectStatus = comDetail.InspectStatus,
                                        Origin = "赋码",
                                        Standard = comDetail.Standard,
                                        PackageStandard = comDetail.PackageStandard,
                                        StoreTime = comDetail.StoreTime,
                                        QtyOrd = comDetail.QtyOrd,
                                        QtyCount = comDetail.QtyCount,
                                        CreateUser = 0,
                                        CreateTime = DateTime.Now,
                                    };
                                    Db.Insertable(boxInfo).ExecuteCommand();
                                }
                                else
                                {
                                    GetBoxInfoByFuMa(model.BoxNo3, url, fuMaTokenUrl,"3"); //从赋码系统获取箱码信息
                                }
                            }
                        }
                    }
                }
                string sqlString = $@"SELECT
                                        ASNNo,
                                        BoxNo,
                                        SkuNo,
                                        SkuName,
                                        LotNo,
                                        SUM(Qty) as Qty
                                      FROM BllBoxInfo
                                      WHERE IsDel = '0'
                                        AND Status='0'
                                        AND BoxNo3 = '{model.BoxNo3}'
                                      GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo; ";
                var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
                if (models.Count == 0)
                {
                    throw new Exception("最小追溯码信息不存在!");
                }
                return models;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // 根据单据号获取单据明细列表
        public List<ArrivalNoticeDetailDto> GetBindArrivalNoticeDetails(ArrivalNoticeVm model)
        {
@@ -1823,18 +2332,27 @@
                if (string.IsNullOrEmpty(model.AsnNo))
                {
                    throw new Exception("-1:单据号不可为空!");
                    throw new Exception("-1:物料明细不可为空!");
                }
                if (model.AsnDetailId == null || model.AsnDetailId == 0)
                {
                    throw new Exception("-1:物料不可为空!");
                }
                //if (model.AsnDetailId == null || model.AsnDetailId == 0)
                //{
                //    throw new Exception("-1:物料明细不可为空!");
                //}
                if (string.IsNullOrEmpty(model.PalletNo))
                {
                    throw new Exception("-1:托盘号不可为空!");
                }
                var detailId = model.AsnNo.Split("-");
                model.AsnDetailId = int.Parse(detailId[0]);
                // 验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId);
                if (detail == null)
                {
                    throw new Exception("-1:当前物料未查询到单据,请核实!");
                }
                model.AsnNo = detail.ASNNo;
                //根据单据号获取入库单总单
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo);
                if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
                {
                    throw new Exception("-1:该单据已关单!");
@@ -1851,10 +2369,11 @@
                else
                {
                    //从物料名称-批次中取出批次
                    int indexOfDash = model.LotNo.IndexOf("-");
                    if (indexOfDash != -1)
                    var indexOfDash = model.LotNo.Split("-");
                    var len = indexOfDash.Length;
                    if (len == 3)
                    {
                        model.LotNo = model.LotNo.Substring(indexOfDash + 1);
                        model.LotNo =indexOfDash[len-1];
                    }
                    else
                    {
@@ -1864,19 +2383,35 @@
                //判断物料数量是否为0 为0判断箱码信息 不为0继续
                if (model.TableType == 0)
                {
                    if (string.IsNullOrEmpty(model.BoxNo))
                    if (notice.Type != "3")
                    {
                        throw new Exception("-1:箱码信息不可为空!");
                    }
                    if (model.IsContinue == "1")
                    {
                        if (string.IsNullOrWhiteSpace(model.TailBoxNo))
                        if (string.IsNullOrEmpty(model.BoxNo))
                        {
                            throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!");
                            throw new Exception("-1:箱码信息不可为空!");
                        }
                        if (model.IsContinue == "1")
                        {
                            if (string.IsNullOrWhiteSpace(model.TailBoxNo))
                            {
                                throw new Exception("-1:开启连续组托时,尾箱码信息不可为空!");
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(model.BoxNo01))
                        {
                            throw new Exception("-1:追溯码信息不可为空!");
                        }
                        if (model.IsContinue == "1")
                        {
                            throw new Exception("-1:追溯码不可连续组托!");
                        }
                    }
                }
                int isTextTable = model.TableType;
                int isDeposit = 0;
@@ -1941,12 +2476,7 @@
                {
                    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);
@@ -2013,6 +2543,21 @@
                var bindId = 0;
                if (bind == null)
                {
                    DateTime proTime;
                    DateTime expTime;
                    var bl1 = DateTime.TryParse(detail.Lot1, out proTime);
                    var bl2 = DateTime.TryParse(detail.Lot2, out expTime);
                    if (!bl1 && !string.IsNullOrWhiteSpace(detail.Lot1))
                    {
                        throw new Exception("生产日期转换失败");
                    }
                    if (!bl2 && !string.IsNullOrWhiteSpace(detail.Lot2))
                    {
                        throw new Exception("有效期转换失败");
                    }
                    bind = new BllPalletBind
                    {
                        ASNNo = model.AsnNo,
@@ -2035,6 +2580,15 @@
                        Demo = model.Demo,
                    };
                    if (bl1)
                    {
                        bind.ProductionTime = proTime;
                    }
                    if (bl2)
                    {
                        bind.ExpirationTime = expTime;
                    }
                    //if (model.TableType == 0 && isDeposit == 0 && isTextTable == 0)   不太理解这段代码的含义
                    //{
                    //    throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
@@ -2057,27 +2611,40 @@
                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)
                    if (notice.Type == "3")
                    {
                        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)
                        //首箱
                        var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo3 == model.BoxNo01 && m.Status == "0").ToList();
                        if (boxInfo.Count == 0)
                        {
                            throw new Exception("-1:尾箱码信息不存在!");
                            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}";
                        boxInfoList.AddRange(boxInfo);
                    }
                    else
                    {
                        //首箱
                        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
@@ -2090,7 +2657,7 @@
                    var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                    foreach (var g in boxGroup)
                    {
                        var boxFullQty = 0;//箱内总数量
                        decimal boxFullQty = 0;//箱内总数量
                        foreach (var box in g)
                        {
                            if (box.BindNo != null && box.BindNo != 0)
@@ -2115,29 +2682,29 @@
                            factQty += box.Qty;
                            boxFullQty += box.Qty;
                        }
                        if (boxFullQty > bNum)
                        {
                            throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                        }
                        //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("托盘绑定数量已超出该物料包装数量");
                }
                //if (bind.FullQty < bind.Qty && isDeposit == 0 && isTextTable == 0)
                //{
                //    throw new Exception("托盘绑定数量已超出该物料包装数量");
                //}
                if (bind.FullQty == bind.Qty)
                if (bind.FullQty <= bind.Qty)
                {
                    bind.BitPalletMark = "0";
                }
                if (bind.Qty > pNum && isDeposit == 0 && isTextTable == 0)
                {
                    throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                }
                //if (bind.Qty > pNum && isDeposit == 0 && isTextTable == 0)
                //{
                //    throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                //}
                Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                // 更改入库单明细已组数量
@@ -2404,7 +2971,7 @@
                            PackagNo = sku.PackagNo,
                            IsBale = bindInfo.IsBale,
                            IsBelt = bindInfo.IsBelt,
                            Demo = bindInfo.Demo,
                            CreateUser = (int)model.CreateUser,
                            CreateTime = serverTime
                        };
@@ -2420,8 +2987,13 @@
                            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 (notice.Type == "3")
                        {
                            quality = Db.Queryable<BllQualityInspect>().Where(a => a.LotNo == noticeDetail.LotNo && a.ASNNo == notice.ASNNo && a.IsDel == "0").OrderByDescending(a => a.CreateTime).First();
                        }
                        if (quality != null)
                        {
                            //修改合格不合格数量
@@ -2466,7 +3038,7 @@
                        SendDate = serverTime,  //发送时间
                        BackDate = serverTime,  //返回时间
                        StartLocat = "",//起始位置
                        EndLocat = "力诺平库",//目标位置
                        EndLocat = model.LocatNo,//目标位置
                        PalletNo = bindInfo.PalletNo,//托盘码
                        IsSend = 0,//是否可再次下发
                        IsCancel = 0,//是否可取消
@@ -2513,11 +3085,13 @@
                            SkuName = item.SkuName,
                            Standard = sku.Standard,
                            ProductionTime = item.ProductionTime,
                            ExpirationTime = item.ExpirationTime,
                            SupplierLot = item.SupplierLot,
                            InspectMark = item.InspectMark,
                            BitBoxMark = item.BitBoxMark,
                            InspectStatus = item.InspectStatus,
                            //InspectTime = item.,
                            UDF1 = item.StoreTime == null? "":((DateTime)item.StoreTime).ToString("yyyy-MM-dd"),
                            //InspectTime = item.StoreTime,
                            IsDel = "0",
                            CreateUser = 0,
@@ -2584,7 +3158,7 @@
                        SendDate = DateTime.Now,  //发送时间
                        BackDate = DateTime.Now,  //返回时间
                        StartLocat = "",//起始位置
                        EndLocat = "力诺平库",//目标位置
                        EndLocat = model.LocatNo,//目标位置
                        PalletNo = model.PalletNo,//托盘码
                        IsSend = 0,//是否可再次下发
                        IsCancel = 0,//是否可取消