using Infrastructure.Attribute; using SqlSugar; using System; using System.Linq; using ZR.Model; using ZR.Model.MES.pro; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; using ZR.Repository; using ZR.Service.mes.wms.IService; namespace ZR.Service.mes.wms { /// /// 成品入库检验Service业务层处理 /// [AppService(ServiceType = typeof(IWmFgentryInspectService), ServiceLifetime = LifeTime.Transient)] public class WmFgentryInspectService : BaseService, IWmFgentryInspectService { /// /// 把包装数据转换为检验数据 /// /// /// public int TransformData(string workorder) { int sum = 0; var inpects = Context.Queryable() .Where(it => it.WorkOrderNum == workorder) .GroupBy(it => it.PackingCode) .Select(it => new WmFgentryInspect() { Workorder = SqlFunc.AggregateMax(it.WorkOrderNum), Packcode = it.PackingCode, Machine = SqlFunc.AggregateMax(it.Machine), ProductionNum = SqlFunc.AggregateCount(it), Partnumber = SqlFunc.AggregateMax(it.PartNum), Bfilled = SqlFunc.ToInt32(SqlFunc.AggregateMax(it.BFilled)), Result = 0, Bitwm = 0, CreatedBy = " ", CreatedTime = DateTime.Now, }).ToList(); var x = Context.Storageable(inpects) .WhereColumns(it => new { it.Packcode, it.Workorder }) .ToStorage(); sum = x.AsInsertable.ExecuteCommand();//不存在插入 x.AsUpdateable.ExecuteCommand();//存在更新 return sum; } /// /// 查询成品入库检验列表 /// /// /// public PagedInfo GetList(WmFgentryInspectQueryDto parm) { var predicate = Expressionable.Create(); var response = Queryable() .Where(predicate.ToExpression()) .ToPage(parm); return response; } /// /// 查询成品入库检验列表 /// /// /// public PagedInfo GetList_first(WmFgentryInspectQueryDto parm) { bool useTime = false; if (string.IsNullOrEmpty(parm.Workorder) && string.IsNullOrEmpty(parm.Packcode) && string.IsNullOrEmpty(parm.Partnumber)) { useTime = true; } var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.Workorder), it => it.Workorder.Contains(parm.Workorder)) .AndIF(!string.IsNullOrEmpty(parm.Packcode), it => it.Packcode.Contains(parm.Packcode)) .AndIF(!string.IsNullOrEmpty(parm.Partnumber), it => it.Partnumber.Contains(parm.Partnumber)) // XXX 调整搜索逻辑,当搜索工单号零件号或标签时,屏蔽时间的判定 .AndIF(useTime && parm.starttime > new DateTime(1999, 1, 1), it => it.CreatedTime > parm.starttime) .AndIF(useTime && parm.endtime > new DateTime(1999, 1, 1), it => it.CreatedTime < parm.endtime) ; List inspects = Queryable() .Where(predicate.ToExpression()) .Where(it => it.Bitwm == 0) .GroupBy(it => it.Workorder) .Select(it => new WmFgentryInspect_parentDto() { Workorder = it.Workorder, ProductionNum = SqlFunc.AggregateSum(it.ProductionNum ?? 0), Packnum = SqlFunc.AggregateCount(it.Workorder), Partnumber = SqlFunc.AggregateMax(it.Partnumber), CreatedTime = SqlFunc.AggregateMax(it.CreatedTime), }) .LeftJoin((s, w) => s.Workorder == w.ClientWorkorder) .Select((s, w) => new WmFgentryInspect_parentDto { Workorder = s.Workorder, ProductionNum = s.ProductionNum, Partnumber = s.Partnumber, CreatedTime = s.CreatedTime, Packnum = s.Packnum, ProductDescription = w.ProductDescription, Specifications = w.Specifications, PreviousNumber = w.PreviousNumber, Colour = w.Colour, Status = w.Status }) .ToList(); foreach (var inspect in inspects) { inspect.Result_good = Queryable().Where(it => it.Workorder == inspect.Workorder).Where(it => it.Result == 1).Count(); inspect.Result_bad = Queryable().Where(it => it.Workorder == inspect.Workorder).Where(it => it.Result == 2).Count(); inspect.Result_null = Queryable().Where(it => it.Workorder == inspect.Workorder).Where(it => it.Result == 0 || it.Result == null).Count(); // 描述来源调整为物料清单 WmMaterial material = Context.Queryable() .Where(it => it.Partnumber == inspect.Partnumber) .First(); if (material == null) { inspect.ProductDescription = "此零件号不在物料清单内!"; } else { inspect.ProductDescription = !string.IsNullOrEmpty(material.Description) ? material.Description : material.ProductName; } } //int totalPages = (int)Math.Ceiling((double)inspects.Count / parm.PageSize); var pageProducts = inspects.Skip((parm.PageNum - 1) * parm.PageSize).Take(parm.PageSize).ToList(); PagedInfo response = new PagedInfo() { PageSize = parm.PageSize, PageIndex = parm.PageNum, TotalNum = inspects.Count, Result = pageProducts }; return response; } /// /// 获取二级菜单 /// /// /// public PagedInfo GetList_second(WmFgentryInspectQueryDto parm) { var predicate = Expressionable.Create() .AndIF(!string.IsNullOrEmpty(parm.Workorder), s => s.Workorder.Contains(parm.Workorder)) .AndIF(!string.IsNullOrEmpty(parm.Packcode), s => s.Packcode.Contains(parm.Packcode)) .AndIF(!string.IsNullOrEmpty(parm.Partnumber), s => s.Partnumber.Contains(parm.Partnumber)) .AndIF(parm.starttime != null && parm.starttime > new DateTime(1999, 1, 1), s => s.CreatedTime > parm.starttime) .AndIF(parm.endtime != null && parm.endtime > new DateTime(1999, 1, 1), s => s.CreatedTime < parm.endtime) ; var response = Queryable() .LeftJoin((s, w) => s.Workorder == w.ClientWorkorder) .Where(s => s.Bitwm == 0) .Where(predicate.ToExpression()) .Select((s, w) => new WmFgentryInspectDto { Workorder = s.Workorder, ProductionNum = s.ProductionNum, Packcode = s.Packcode, Machine = s.Machine, Bfilled = s.Bfilled, Partnumber = s.Partnumber, Result = s.Result, CreatedBy = s.CreatedBy, CreatedTime = s.CreatedTime, ProductDescription = w.ProductDescription, Specifications = w.Specifications, Colour = w.Colour }) .ToPage(parm); return response; } /// /// 获取详情 /// /// /// public WmFgentryInspect GetInfo(int Id) { var response = Queryable() .Where(x => x.Id == Id) .First(); return response; } /// /// 添加成品入库检验 /// /// /// public WmFgentryInspect AddWmFgentryInspect(WmFgentryInspect model) { return Context.Insertable(model).ExecuteReturnEntity(); } /// /// 修改成品入库检验 /// /// /// public int UpdateWmFgentryInspect(WmFgentryInspect model) { //var response = Update(w => w.Id == model.Id, it => new WmFgentryInspect() //{ // Workorder = model.Workorder, // Machine = model.Machine, // ProductionNum = model.ProductionNum, // Partnumber = model.Partnumber, // Bfilled = model.Bfilled, // Result = model.Result, // CreatedBy = model.CreatedBy, // CreatedTime = model.CreatedTime, // UpdatedBy = model.UpdatedBy, // UpdatedTime = model.UpdatedTime, //}); //return response; return Update(model, true); } /// /// 批量修改合格 /// /// /// public int BatchQualified(string[] packcode_select, string updateby) { int sum = 0; foreach (string packcode in packcode_select) { sum = sum + Context.Updateable() .Where(it => it.Packcode == packcode) .SetColumns(it => it.Result == 1) .ExecuteCommand(); } return sum; } /// /// 设置全部批量合格 /// /// /// /// public int SetAllQualified(string workorder_selected, string updateby) { return Context.Updateable() .SetColumns(it => it.Result == 1) .Where(it => it.Workorder == workorder_selected) .ExecuteCommand(); } /// /// 设置全部批量不合格 /// /// /// /// public int SetAllUnQualified(string workorder_selected, string updateby) { return Context.Updateable() .SetColumns(it => it.Result == 2) .Where(it => it.Workorder == workorder_selected) .ExecuteCommand(); } /// /// 批量修改合格 /// /// /// public int BatchUnQualified(string[] packcode_select, string updateby) { int sum = 0; foreach (string packcode in packcode_select) { sum = sum + Context.Updateable() .Where(it => it.Packcode == packcode) .SetColumns(it => it.Result == 2) .ExecuteCommand(); } return sum; } } }