Demo
2024-03-22 a9522f978edf6dee98949f9ed715fc36f999ed4f
Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -17,6 +17,7 @@
using Model.ModelDto.PdaDto;
using Dm;
using Model.InterFaceModel;
using WMS.Entity.BllQualityEntity;
namespace WMS.BLL.BllPdaServer
{
@@ -42,6 +43,23 @@
            }
        }
        //根据入库单号获取入库总单信息
        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;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        // 根据单据号获取单据明细列表
        public List<ArrivalNoticeDetailDto> GetArrivalNoticeDetails(ArrivalNoticeVm model)
        {
@@ -51,7 +69,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)
            {
@@ -349,12 +377,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
                {
@@ -370,10 +398,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();
@@ -400,12 +431,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'";
                // 更改托盘使用状态
@@ -1286,7 +1317,7 @@
        /// </summary>
        /// <param name="locatNo">储位编码</param>
        /// <returns></returns>
        public string CheckLocatNo(string locatNo)
        public string CheckLocatNo(string locatNo)
        {
            try
            {
@@ -1734,11 +1765,44 @@
                        }
                    }
                }
                return noticeList;
                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;
            }
        }
@@ -1771,9 +1835,9 @@
                }
                //根据单据号获取入库单总单
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
                if (notice.Status != "0" && notice.Status != "1")
                if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
                {
                    throw new Exception("-1:入库单状态不是等待执行或执行完成!");
                    throw new Exception("-1:该单据已关单!");
                }
                if (string.IsNullOrEmpty(model.LotNo))
                {
@@ -1792,9 +1856,13 @@
                    {
                        model.LotNo = model.LotNo.Substring(indexOfDash + 1);
                    }
                    else
                    {
                        model.LotNo = "";
                    }
                }
                //判断物料数量是否为0 为0判断箱码信息 不为0继续
                if (model.SkuQty == 0)
                if (model.TableType == 0)
                {
                    if (string.IsNullOrEmpty(model.BoxNo))
                    {
@@ -1810,6 +1878,53 @@
                    }
                }
                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:总单备注与托盘备注不符,请核实后重新绑定!");
                            }
                        }
                    }
                    else if (string.IsNullOrWhiteSpace(notice.Demo))
                    {
                        //判断托盘备注是否为空
                        if (!string.IsNullOrWhiteSpace(model.Demo))
                        {
                            throw new Exception("-1:请添加总单备注后输入托盘备注!");
                        }
                    }
                }
                #endregion
                Db.BeginTran();
@@ -1822,9 +1937,9 @@
                }
                //判断托盘是否在库外
                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo))
                if (stockDetail != null)// && !string.IsNullOrEmpty(stockDetail.WareHouseNo)
                {
                    throw new Exception("该托盘未在库外,请核实!");
                    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));
@@ -1836,40 +1951,46 @@
                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)
                //判断是否为寄存物料
                if (isDeposit == 0 && isTextTable == 0)
                {
                    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}物品包装未找到!");
                    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
@@ -1888,7 +2009,7 @@
                    }
                }
                #endregion
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                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)
                {
@@ -1905,17 +2026,19 @@
                        Type = "0",
                        LotNo = model.LotNo,
                        LotText = detail.LotText,
                        SupplierLot = "",
                        SupplierLot = detail.SupplierLot,
                        InspectMark = "0",
                        BitPalletMark = "1",
                        IsBale = "0",
                        IsBelt = "0",
                        CreateUser = userId
                        CreateUser = userId,
                        Demo = model.Demo,
                    };
                    if (model.SkuQty > pNum)
                    {
                        throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                    }
                    //if (model.TableType == 0 && isDeposit == 0 && isTextTable == 0)   不太理解这段代码的含义
                    //{
                    //    throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                    //}
                    // 插入托盘绑定表
                    bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                }
@@ -1962,7 +2085,7 @@
                // 更改箱支关系表
                decimal factQty = 0.00m;//托盘总数量
                //成品组托
                if (model.SkuQty == 0)
                if (isTextTable == 0)
                {
                    var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                    foreach (var g in boxGroup)
@@ -2002,7 +2125,7 @@
                    // 更新托盘绑定表
                    bind.Qty += factQty;
                }
                if (bind.FullQty < bind.Qty)
                if (bind.FullQty < bind.Qty && isDeposit == 0 && isTextTable == 0)
                {
                    throw new Exception("托盘绑定数量已超出该物料包装数量");
                }
@@ -2011,7 +2134,7 @@
                {
                    bind.BitPalletMark = "0";
                }
                if (bind.Qty > pNum)
                if (bind.Qty > pNum && isDeposit == 0 && isTextTable == 0)
                {
                    throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                }
@@ -2034,8 +2157,15 @@
                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);
                }
@@ -2142,13 +2272,13 @@
                    #endregion
                    #region 箱码信息
                    var boxInfoList = Db.Queryable<BllBoxInfo>().Where(w => w.IsDel == "0" && w.ASNNo == model.ASNNo).ToList();
                    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
                    else
                    {
                        //验证箱码信息是否存在
                        if (boxInfoList.Count <= 0)
@@ -2216,6 +2346,12 @@
                            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();
                    }
@@ -2268,11 +2404,43 @@
                            PackagNo = sku.PackagNo,
                            IsBale = bindInfo.IsBale,
                            IsBelt = bindInfo.IsBelt,
                            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
                    {