using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using ZR.Model; using ZR.Model.Dto; using ZR.Repository; using System.Linq; using ZR.Service.mes.wms.IService; using ZR.Model.MES.wms; using ZR.Model.MES.wms.Dto; using Mapster; using System.Reflection.PortableExecutable; using Microsoft.AspNetCore.Http.HttpResults; 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) { 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)) .AndIF(parm.starttime != null && parm.starttime > new DateTime(1999, 1, 1), it => it.CreatedTime > parm.starttime) .AndIF(parm.endtime != null && 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), // Result= SqlFunc.AggregateSum(it.Result??0), Partnumber = SqlFunc.AggregateMax(it.Partnumber) }).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(); } 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, TotalPage = totalPages, Result = pageProducts }; return response; } /// /// 获取二级菜单 /// /// /// public PagedInfo GetList_second(WmFgentryInspectQueryDto parm) { 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)) .AndIF(parm.starttime != null && parm.starttime > new DateTime(1999, 1, 1), it => it.CreatedTime > parm.starttime) .AndIF(parm.endtime != null && parm.endtime > new DateTime(1999, 1, 1), it => it.CreatedTime < parm.endtime) ; var response = Queryable() .Where(it => it.Bitwm == 0) .Where(predicate.ToExpression()) .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 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; } } }