chengsc
2024-10-18 1e26a7575d9969e728b0aa01466f490409cb173c
Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -29,6 +29,89 @@
    {
        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<string> GetArrivalNotices(ArrivalNoticeVm model)
        {
@@ -42,11 +125,11 @@
                //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贴标
                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 == "1")//1不贴标
                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();
                }
@@ -1817,12 +1900,19 @@
                {
                    throw new Exception("请扫描外箱条码!");
                }
                var count = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.Status == "0" && m.BoxNo == model.BoxNo);
                if (count == 0)
                if (!string.IsNullOrWhiteSpace(model.ASNNo))
                {
                    GetBoxInfoByFuMa(model.BoxNo, ""); //从赋码系统获取箱码信息
                    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, 
@@ -1836,7 +1926,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("箱码信息不存在!");
                }
@@ -1948,18 +2038,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:该单据已关单!");
@@ -1976,10 +2075,11 @@
                else
                {
                    //从物料名称-批次中取出批次
                    int indexOfDash = model.LotNo.IndexOf("-");
                    if (indexOfDash != -1)
                    var indexOfDash = model.LotNo.Split("-");
                    var len = indexOfDash.Length;
                    if (len >= 1)
                    {
                        model.LotNo = model.LotNo.Substring(indexOfDash + 1);
                        model.LotNo =indexOfDash[len-1];
                    }
                    else
                    {
@@ -2066,12 +2166,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);
@@ -2240,29 +2335,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();
                // 更改入库单明细已组数量
@@ -2529,7 +2624,7 @@
                            PackagNo = sku.PackagNo,
                            IsBale = bindInfo.IsBale,
                            IsBelt = bindInfo.IsBelt,
                            Demo = bindInfo.Demo,
                            CreateUser = (int)model.CreateUser,
                            CreateTime = serverTime
                        };
@@ -2545,8 +2640,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)
                        {
                            //修改合格不合格数量
@@ -2638,6 +2738,7 @@
                            SkuName = item.SkuName,
                            Standard = sku.Standard,
                            ProductionTime = item.ProductionTime,
                            ExpirationTime = item.ExpirationTime,
                            SupplierLot = item.SupplierLot,
                            InspectMark = item.InspectMark,
                            BitBoxMark = item.BitBoxMark,