zhaowc
2025-04-07 b9f7560cbe0e562a40e9515a0559a3e951f0fee6
Wms/WMS.BLL/BllQualityServer/QualityInspectServer.cs
@@ -1,14 +1,18 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Model.ModelDto.BllQualityDto;
using Model.ModelVm;
using SqlSugar;
using Utility.Tools;
using WMS.DAL;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.BllQualityEntity;
using WMS.Entity.Context;
using WMS.Entity.DataEntity;
using WMS.Entity.SysEntity;
using WMS.IBLL.IBllQualityServer;
namespace WMS.BLL.BllQualityServer
@@ -29,7 +33,7 @@
        /// <returns></returns>
        public List<BllQualityInspectDto> GetBllQualityList(BllQualityInspect model)
        {
            string str = "select q.Id Id,q.InspectNo InspectNo,q.ASNNo ASNNo,q.LotNo LotNo,q.SupplierLot SupplierLot,q.SkuNo SkuNo,q.SkuName SkuName,q.Standard Standard,q.PassQty PassQty,q.FailQty FailQty,q.Origin Origin,q.InspectTime InspectTime,q.IsOut IsOut,q.IsQualified IsQualified,q.IsDel IsDel,q.CreateTime CreateTime,u.RealName CreateUserName,q.UpdateTime UpdateTime,q.UpdateUser UpdateUserName from BllQualityInspect q left join SysUserInfor u on q.CreateUser = u.id where q.IsDel = @isdel";
            string str = "select q.Id Id,q.InspectNo InspectNo,q.ASNNo ASNNo,q.Status Status,q.LotNo LotNo,q.SupplierLot SupplierLot,q.SkuNo SkuNo,q.SkuName SkuName,q.Standard Standard,q.PassQty PassQty,q.FailQty FailQty,q.Origin Origin,q.InspectTime InspectTime,q.IsOut IsOut,q.IsQualified IsQualified,q.IsDel IsDel,q.CreateTime CreateTime,u.RealName CreateUserName,q.UpdateTime UpdateTime,q.UpdateUser UpdateUserName from BllQualityInspect q left join SysUserInfor u on q.CreateUser = u.id where q.IsDel = @isdel";
            ////判断入库单号是否为空
            //if (!string.IsNullOrEmpty(model.ASNNo))
@@ -87,47 +91,183 @@
            {
                throw new Exception("质检号不可为空,请核查!");
            }
            //验证入库单号是否为空
            if (string.IsNullOrEmpty(model.ASNNo))
            {
                throw new Exception("入库单号不可为空,请核查!");
            }
            //验证物料号是否为空
            if (string.IsNullOrEmpty(model.SkuNo))
            {
                throw new Exception("物料号不可为空,请核查!");
            }
            //获取物料信息
            var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == model.SkuNo);
            if (sku == null)
            {
                throw new Exception("物料信息为空,请核查!");
            }
            //验证批次号是否为空
            if (string.IsNullOrEmpty(model.LotNo))
            {
                throw new Exception("批次号不可为空,请核查!");
            }
            //查找质检信息中是否存在同批次质检录入记录
            BllQualityInspect quality = Db.Queryable<BllQualityInspect>().First(m => m.IsDel == "0" && m.ASNNo == model.ASNNo && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo);
            if (quality != null)
            //验证批次号是否为当前库存中已有批次
            var lot = Db.Queryable<DataStock>().Where(w => w.LotNo == model.LotNo).ToList();
            if (lot.Count == 0)
            {
                throw new Exception("当前批次已进行质检,请核查!");
                throw new Exception("当前库存中无此批号,请核查!");
            }
            int isTui = 0;
            //验证入库单号是否为空
            if (!string.IsNullOrEmpty(model.ASNNo))
            {
                //查询是否为退货入库单据
                var Arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && (a.Type == "3" || a.Type == "4"));
                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;
            }
            //查找同批次 同单据 入库单信息、
            BllArrivalNoticeDetail arrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.ASNNo == model.ASNNo && m.LotNo == model.LotNo);
            //查找质检信息中是否存在同批次质检录入记录
            //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("当前退货入库单已创建质检信息,请勿重复创建!");
            //    }
            //}
            //    throw new Exception("当前物料和批次已进行质检,请核查!");
            //}
            ////查找同批次 同单据 入库单信息、
            //BllArrivalNoticeDetail arrivalDetail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.ASNNo == model.ASNNo && m.LotNo == model.LotNo);
            model.Status = "0";//审核状态
            model.Origin = "WMS"; //来源
            model.CreateTime = Db.GetDate(); //创建日期
            model.SkuNo = arrivalDetail.SkuNo; //物料号
            model.SkuName = arrivalDetail.SkuName; //物料名称
            model.PassQty = 0; //合格数量
            model.FailQty = 0; //不合格数量
            model.Standard = arrivalDetail.Standard; //规格
            model.SupplierLot = arrivalDetail.SupplierLot; //供货批次
            model.SkuNo = sku.SkuNo; //物料号
            model.SkuName = sku.SkuName; //物料名称
            //model.PassQty = 0; //合格数量
            //model.FailQty = 0; //不合格数量
            model.Standard = sku.Standard; //规格
            //model.SupplierLot = arrivalDetail.SupplierLot; //供货批次
            //查找库存明细信息
            List<DataStockDetail> detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.ASNNo == model.ASNNo && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo).ToList();
            //List<DataStockDetail> detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo).ToList();
            //if (isTui == 1)
            //{
            //    detail = detail.Where(m=> m.ASNNo == model.ASNNo).ToList();
            //}
            //foreach (var item in detail)
            //{
            //    List<DataBoxInfo> box = Db.Queryable<DataBoxInfo>().Where(a => a.IsDel == "0" && a.StockDetailId == item.Id && a.SkuNo == model.SkuNo && a.LotNo == model.LotNo).ToList();
            //    //判断合格状态是否合格
            //    if (model.IsQualified == "1")
            //    {
            //        //合格 相同批次库存信息全部改为合格状态 且合格数量增加为同批次同单号该物料全部数量之和
            //        model.PassQty += item.Qty;
            //        //修改库存明细合格状态
            //        item.InspectStatus = "1"; //1合格
            //        foreach (var b1 in box)
            //        {
            //            b1.InspectStatus = "1"; //1合格
            //        }
            //    }
            //    else //不合格
            //    {
            //        //不合格 相同批次、入库单库存信息全部改为不合格物料 且不合格数量增加为同批次同单号该物料全部数量之和
            //        model.FailQty += item.Qty;
            //        item.InspectStatus = "2"; //2不合格
            //        foreach (var b1 in box)
            //        {
            //            b1.InspectStatus = "2"; //2不合格
            //        }
            //    }
            //    Db.Updateable(box).ExecuteCommand();
            //    Db.Updateable(item).ExecuteCommand();
            //}
            var isquality = Db.Insertable(model).ExecuteCommand();
            return isquality;
        }
        /// <summary>
        /// 质检复核信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userNo"></param>
        /// <param name="password"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public int FinshQuality(int id,string userNo, string password, int userId)
        {
            var loginPwd = Md5Tools.CalcMd5(password);
            var date = Db.Queryable<SysUserInfor>().First(m => m.IsDel == "0" && m.UserName == userNo && m.PassWord == loginPwd);
            if (date == null) //账号密码是否正确
            {
                throw new Exception("账号密码不正确或没有此账号");
            }
            if (date.Status != "0") //当前账号是否正常启用
            {
                throw new Exception("当前账号非启用状态");
            }
            var model = Db.Queryable<BllQualityInspect>().First(m=>m.IsDel == "0" && m.Id == id);
            if (model == null)
            {
                throw new Exception("未查询到质检信息");
            }
            if (date.Id == model.CreateUser)
            {
                throw new Exception("复核失败,复核人员和创建质检单据人员不能相同!");
            }
            int isTui = 0;
            //验证入库单号是否为空
            if (!string.IsNullOrEmpty(model.ASNNo))
            {
                //查询是否为退货入库单据
                var Arrival = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && (a.Type == "3" || a.Type == "4"));
                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;
            }
            model.Status = "1"; //规格
            model.UpdateTime = DateTime.Now;
            model.UpdateUser = userId;
            //model.SupplierLot = arrivalDetail.SupplierLot; //供货批次
            //查找库存明细信息
            List<DataStockDetail> detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.SkuNo == model.SkuNo && m.LotNo == model.LotNo).ToList();
            if (isTui == 1)
            {
                detail = detail.Where(m => m.ASNNo == model.ASNNo).ToList();
            }
            foreach (var item in detail)
            {
                List<BllBoxInfo> box = Db.Queryable<BllBoxInfo>().Where(a => a.IsDel == "0" && a.ASNNo == model.ASNNo && a.SkuNo == model.SkuNo && a.LotNo == model.LotNo).ToList();
                List<DataBoxInfo> box = Db.Queryable<DataBoxInfo>().Where(a => a.IsDel == "0" && a.StockDetailId == item.Id && a.SkuNo == model.SkuNo && a.LotNo == model.LotNo).ToList();
                //判断合格状态是否合格
                if (model.IsQualified == "1")
                {
@@ -137,7 +277,7 @@
                    item.InspectStatus = "1"; //1合格
                    foreach (var b1 in box)
                    {
                        b1.InspectMark = "1"; //1合格
                        b1.InspectStatus = "1"; //1合格
                    }
                }
                else //不合格
@@ -147,13 +287,13 @@
                    item.InspectStatus = "2"; //2不合格
                    foreach (var b1 in box)
                    {
                        b1.InspectMark = "2"; //2不合格
                        b1.InspectStatus = "2"; //2不合格
                    }
                }
                Db.Updateable(box).ExecuteCommand();
                Db.Updateable(item).ExecuteCommand();
            }
            var isquality = Db.Insertable(model).ExecuteCommand();
            var isquality = Db.Updateable(model).ExecuteCommand();
            return isquality;
        }