wxw
2 天以前 950fac9fd7b9477fc2bbe3253d217f62ac7608e5
Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs
@@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using Model.InterFaceModel;
using Model.ModelDto.BllQualityDto;
using Model.ModelVm;
using SqlSugar;
@@ -112,51 +114,59 @@
                throw new Exception("物料信息为空,请核查!");
            }
            //验证批次号是否为空
            if (string.IsNullOrEmpty(model.LotNo))
            if (string.IsNullOrEmpty(model.LotNo) && string.IsNullOrEmpty(model.ASNNo))
            {
                throw new Exception("批次号不可为空,请核查!");
                throw new Exception("请输入批次号或入库单号!");
            }
            //验证入库单号是否为空
            if (string.IsNullOrEmpty(model.ASNNo))
            {
                throw new Exception("入库单号不可为空!");
            //if (string.IsNullOrEmpty(model.ASNNo))
            //{
            //    throw new Exception("入库单号不可为空!");
                //查询是否为退货入库单据
                //var Arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.Type == "3");
                //if (Arrival == null)
                //{
                //    throw new Exception("只有入库单据为退货入库单可输入 入库单号,请核查!");
                //}
            //查询是否为退货入库单据
            //var Arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.Type == "3");
            //if (Arrival == null)
            //{
            //    throw new Exception("只有入库单据为退货入库单可输入 入库单号,请核查!");
            //}
                ////获取入库单明细
                //var ArrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.LotNo.Contains(model.LotNo) && a.SkuNo == model.SkuNo);
                //if (ArrivalDetail == null)
                //{
                //    throw new Exception("输入的批次或物料信息与入库单据不符,请核查!");
                //}
                //isTui = 1;
            }
            ////获取入库单明细
            //var ArrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.LotNo.Contains(model.LotNo) && a.SkuNo == model.SkuNo);
            //if (ArrivalDetail == null)
            //{
            //    throw new Exception("输入的批次或物料信息与入库单据不符,请核查!");
            //}
            //isTui = 1;
            //}
            //查找质检信息中是否存在同批次质检录入记录
            //BllQualityInspect quality = Db.Queryable<BllQualityInspect>().First(m => m.IsDel == "0" && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo);
            //if (quality != null)
            //{
                ////判断是否为退货入库单
                //if (isTui == 1)
                //{
                //    if (quality.ASNNo == model.ASNNo)
                //    {
                //        throw new Exception("当前退货入库单已创建质检信息,请勿重复创建!");
                //    }
                //}
            ////判断是否为退货入库单
            //if (isTui == 1)
            //{
            //    if (quality.ASNNo == model.ASNNo)
            //    {
            //        throw new Exception("当前退货入库单已创建质检信息,请勿重复创建!");
            //    }
            //}
            //    throw new Exception("当前物料和批次已进行质检,请核查!");
            //}
            ////查找同批次 同单据 入库单信息、
            BllArrivalNoticeDetail arrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0"
            && m.ASNNo == model.ASNNo && m.LotNo == model.LotNo && m.SkuNo == model.SkuNo);
            string sqlStr = $@"select * from BllArrivalNoticeDetail where IsDel='0' and SkuNo='{model.SkuNo}' ";
            if (!string.IsNullOrEmpty(model.ASNNo))
            {
                sqlStr += $" and ASNNo='{model.ASNNo}' ";
            }
            if (!string.IsNullOrEmpty(model.LotNo))
            {
                sqlStr += $" and LotNo='{model.LotNo}' ";
            }
            BllArrivalNoticeDetail arrivalDetail = Db.SqlQueryable<BllArrivalNoticeDetail>(sqlStr).First();
            if (arrivalDetail == null)
            {
                throw new Exception("未找到入库单信息!");
@@ -170,10 +180,19 @@
            model.PassQty = 0; //合格数量
            model.FailQty = 0; //不合格数量
            model.Standard = sku.Standard; //规格
            //model.SupplierLot = arrivalDetail.SupplierLot; //供货批次
                                           //model.SupplierLot = arrivalDetail.SupplierLot; //供货批次
            //查找库存明细信息
            List<DataStockDetail> detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo).ToList();
            string sqlStr2 = $@"select * from DataStockDetail where IsDel='0' and SkuNo='{model.SkuNo}' ";
            if (!string.IsNullOrEmpty(model.ASNNo))
            {
                sqlStr2 += $" and ASNNo='{model.ASNNo}' ";
            }
            if (!string.IsNullOrEmpty(model.LotNo))
            {
                sqlStr2 += $" and LotNo='{model.LotNo}' ";
            }
            List<DataStockDetail> detail = Db.SqlQueryable<DataStockDetail>(sqlStr2).ToList();
            foreach (var item in detail)
            {
                List<BllBoxInfo> box = Db.Queryable<BllBoxInfo>().Where(a => a.IsDel == "0" && a.SkuNo == model.SkuNo && a.LotNo == model.LotNo).ToList();
@@ -201,7 +220,128 @@
            return isquality;
        }
        /// <summary>
        /// SAP下发库存调整单
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public string InsertQualitySap(SendQualityVm model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.orderNo) || model.adjustmentDList.Count <= 0)
                {
                    throw new Exception("参数错误");
                }
                var asnInfo = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.OrderCode == model.orderNo);
                if (asnInfo == null)
                {
                    throw new Exception($"未查询到{model.orderNo}对应的入库单信息");
                }
                //开启事务
                Db.BeginTran();
                foreach (var item in model.adjustmentDList)
                {
                    var asnDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.ASNNo == asnInfo.ASNNo && w.OrderDetailCode == item.lineNo && w.SkuNo == item.skuNo && w.LotNo == item.lotNo);
                    if (asnDetail == null)
                    {
                        throw new Exception($"未查询到{item.lineNo}对应的入库单明细信息");
                    }
                    asnDetail.InspectStatus = item.IsQualified;
                    //更新入库单明细质检状态
                    Db.Updateable(asnDetail).ExecuteCommand();
                    //获取物料信息
                    var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == item.skuNo);
                    if (sku == null)
                    {
                        throw new Exception($"物料编码为{item.skuNo}的物料信息不存在,请核查!");
                    }
                    string toDayTime = DateTime.Now.ToString("yyyyMMdd");
                    var maxInspectNo = Db.Queryable<BllQualityInspect>().Where(m => m.IsDel == "0" && m.InspectNo.Contains("SAP")).Max(m => m.InspectNo);
                    if (string.IsNullOrWhiteSpace(maxInspectNo))
                    {
                        maxInspectNo = "SAP" + toDayTime + "0001";
                    }
                    else
                    {
                        var lotStr = maxInspectNo.Substring(3, 8);
                        if (lotStr == toDayTime)
                        {
                            maxInspectNo = "SAP" + toDayTime + (int.Parse(maxInspectNo.Replace("SAP","").Substring(8, 4)) + 1).ToString().PadLeft(4, '0');
                        }
                        else
                        {
                            maxInspectNo = "SAP" + toDayTime + "0001";
                        }
                    }
                    var qualityModel = new BllQualityInspect
                    {
                        ASNNo = asnDetail.ASNNo,
                        InspectNo = maxInspectNo,
                        SkuNo = item.skuNo,
                        SkuName = item.skuName,
                        Standard = sku.Standard,
                        LotNo = item.lotNo,
                        IsQualified = item.IsQualified,
                        Origin = "SAP",
                        FailQty = 0,
                        PassQty = 0
                    };
                    //查找库存信息
                    var stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == item.skuNo && w.LotNo == item.lotNo).ToList();
                    foreach(var datailItem in stockDetailList)
                    {
                        List<DataBoxInfo> boxList = Db.Queryable<DataBoxInfo>().Where(a => a.IsDel == "0" && a.SkuNo == item.skuNo && a.LotNo == item.lotNo && a.PalletNo == datailItem.PalletNo).ToList();
                        foreach (var boxItem in boxList)
                        {
                            if (item.IsQualified == "0")//不合格
                            {
                                boxItem.InspectStatus = "2";
                            }
                            else//合格
                            {
                                boxItem.InspectStatus = "1";
                            }
                        }
                        //更新箱码明细质检状态
                        Db.Updateable(boxList).ExecuteCommand();
                        if (item.IsQualified == "0")//不合格
                        {
                            datailItem.InspectStatus = "2";
                            //不合格数量
                            qualityModel.FailQty += datailItem.Qty;
                        }
                        else//合格
                        {
                            datailItem.InspectStatus = "1";
                            //合格数量
                            qualityModel.PassQty += datailItem.Qty;
                        }
                        //更新库存明细质检状态
                        Db.Updateable(datailItem).ExecuteCommand();
                    }
                    //添加质检变更记录
                    Db.Insertable(qualityModel).ExecuteCommand();
                }
                //提交事务
                Db.CommitTran();
                return "0";
            }
            catch (Exception ex)
            {
                //回滚事务
                Db.RollbackTran();
                //抛出异常
                throw new Exception("接收SAP下发库存调整单异常:", ex);
            }
        }
        #endregion
    }