using System; using System.Collections.Generic; using System.Text; using Model.ModelDto.BllQualityDto; using Model.ModelVm; using SqlSugar; using WMS.DAL; using WMS.Entity.BllAsnEntity; using WMS.Entity.BllQualityEntity; using WMS.Entity.Context; using WMS.Entity.DataEntity; using WMS.IBLL.IBllQualityServer; namespace WMS.BLL.BllQualityServer { public class QualityInspectServer : DbHelper, IQualityInspectServer { private static readonly SqlSugarScope Db = DataContext.Db; public QualityInspectServer() : base(Db) { } #region 质检信息录入 /// /// 获取质检物料信息 /// /// 质检信息实体模型 /// public List 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"; ////判断入库单号是否为空 //if (!string.IsNullOrEmpty(model.ASNNo)) //{ // str += " and q.ASNNo = @asnno"; //} //判断物料号是否为空 if (!string.IsNullOrEmpty(model.SkuNo)) { str += " and q.SkuNo like @skuno"; } //判断物料名称是否为空 if (!string.IsNullOrEmpty(model.SkuName)) { str += " and q.SkuName like @skuname"; } //判断批次号是否为空 if (!string.IsNullOrEmpty(model.LotNo)) { str += " and q.LotNo = @lotno"; } //判断是否合格状态是否为空 if (!string.IsNullOrEmpty(model.IsQualified)) { str += " and q.IsQualified = @isqualified"; } str += " order by q.CreateTime desc"; List qualityList = Db.Ado.SqlQuery(str, new { isdel = "0", //是否删除 asnno = model.ASNNo, //入库单号 skuno = "%" + model.SkuNo+ "%", //物料号 skuname = "%" + model.SkuName + "%", //物料名称 lotno = model.LotNo, //批次号 isqualified = model.IsQualified //是否合格 }); return qualityList; } /// /// 添加物料质检信息 /// /// 质检信息实体模型 /// public int InsertQuality(BllQualityInspect model) { //string str = "insert into BllQualityInspect values(@inspectno,@asnno,@lotno,@supplierlot,@skuno,@skuname,,@standard,@passqty,@failqty,@origin,@inspecttime,@isout,@isqualified,@isdel,@createtime,@createuser,@updatetime,@updateuser);"; //查找质检信息中是否存在同批次质检录入记录 //BllQualityInspect quality = Db.Queryable().First(m => m.LotNo == model.LotNo && m.IsDel == "0"); //if (quality != null) //{ // throw new Exception("当前批次已进行质检,请核查!"); //} //查找同批次 同单据 入库单信息、 BllArrivalNoticeDetail arrival = Db.Queryable().First(m => m.LotNo == model.LotNo && m.IsDel == "0"); model.Origin = "WMS"; //来源 model.CreateTime = Db.GetDate(); //创建日期 model.SkuNo = arrival.SkuNo; //物料号 model.SkuName = arrival.SkuName; //物料名称 //model.ASNNo = arrival.ASNNo; //入库单号 model.PassQty = 0; //合格数量 model.FailQty = 0; //不合格数量 model.Standard = arrival.Standard; //规格 model.SupplierLot = arrival.SupplierLot; //供货批次 //查找库存明细信息 List detail = Db.Queryable().Where(m => m.SkuNo == model.SkuNo && m.LotNo == model.LotNo && m.IsDel == "0").ToList(); foreach (var item in detail) { List box = Db.Queryable().Where(a => a.SkuNo == model.SkuNo && a.LotNo == model.LotNo && a.IsDel == "0").ToList(); //判断合格状态是否合格 if (model.IsQualified == "1") { //合格 相同批次库存信息全部改为合格状态 且合格数量增加为同批次同单号该物料全部数量之和 //不合格数量为0 model.FailQty = 0; model.PassQty += item.Qty; //修改库存明细合格状态 item.InspectStatus = "1"; //1合格 foreach (var b1 in box) { b1.InspectMark = "1"; //1合格 } } else //不合格 { //不合格 相同批次、入库单库存信息全部改为不合格物料 且不合格数量增加为同批次同单号该物料全部数量之和 //合格数量为0 model.PassQty = 0; model.FailQty += item.Qty; item.InspectStatus = "2"; //2不合格 foreach (var b1 in box) { b1.InspectMark = "2"; //2不合格 } } Db.Updateable(box).ExecuteCommand(); Db.Updateable(item).ExecuteCommand(); } var isquality = Db.Insertable(model).ExecuteCommand(); return isquality; } #endregion } }