using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using wms.sqlsugar.model.sx; using WMS.BZModels; using WMS.BZModels.Dto.SX.BillInvflowHistoryDtos; using WMS.BZSqlSugar; using WMS.Info; namespace WMS.BZServices.SX { public class BillInvflowHistoryService { private readonly Repository _billInvflowHistoryRepository; public BillInvflowHistoryService(Repository billInvflowHistoryRepository) { _billInvflowHistoryRepository = billInvflowHistoryRepository; } public PagedInfo GetPageList(Pagination pagination, BillInvflowHistoryQueryDto billInvflowHistoryQueryDto) { ISugarQueryable sugarQueryable = GetQueryable(billInvflowHistoryQueryDto); var list = sugarQueryable.ToPage(pagination); return list; } public IList GetList(BillInvflowHistoryQueryDto billInvflowHistoryQueryDto) { ISugarQueryable sugarQueryable = GetQueryable(billInvflowHistoryQueryDto); var list = sugarQueryable.ToList(); return list; } private ISugarQueryable GetQueryable(BillInvflowHistoryQueryDto billInvflowHistoryQueryDto) { var predicate = Expressionable.Create(); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.KeyWord), (billInvflowHistory, warehouse) => billInvflowHistory.RFIDBarCode.Contains(billInvflowHistoryQueryDto.KeyWord) || billInvflowHistory.ContGrpBarCode.Contains(billInvflowHistoryQueryDto.KeyWord) || billInvflowHistory.MatCode.Contains(billInvflowHistoryQueryDto.KeyWord) || billInvflowHistory.MatName.Contains(billInvflowHistoryQueryDto.KeyWord) || billInvflowHistory.InvBarCode.Contains(billInvflowHistoryQueryDto.KeyWord)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.Id), (billInvflowHistory, warehouse) => billInvflowHistory.Id.ToString().Contains(billInvflowHistoryQueryDto.Id)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.WarehouseId), (billInvflowHistory, warehouse) => billInvflowHistory.WarehouseId.ToString().Contains(billInvflowHistoryQueryDto.WarehouseId)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.ContGrpId), (billInvflowHistory, warehouse) => billInvflowHistory.ContGrpId.ToString().Contains(billInvflowHistoryQueryDto.ContGrpId)); //predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.EquContGrpId), (billInvflowHistory, warehouse) => billInvflowHistory.ContGrpId.ToString().Equals(billInvflowHistoryQueryDto.EquContGrpId)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.MatCode), (billInvflowHistory, warehouse) => billInvflowHistory.MatCode.Contains(billInvflowHistoryQueryDto.MatCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.MatName), (billInvflowHistory, warehouse) => billInvflowHistory.MatName.Contains(billInvflowHistoryQueryDto.MatName)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.RFIDBarCode), (billInvflowHistory, warehouse) => billInvflowHistory.RFIDBarCode.Contains(billInvflowHistoryQueryDto.RFIDBarCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.InvBarCode), (billInvflowHistory, warehouse) => billInvflowHistory.InvBarCode.Contains(billInvflowHistoryQueryDto.InvBarCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.PutRow), (billInvflowHistory, warehouse) => billInvflowHistory.PutRow.Equals(billInvflowHistoryQueryDto.PutRow)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.PutCol), (billInvflowHistory, warehouse) => billInvflowHistory.PutCol.Equals(billInvflowHistoryQueryDto.PutCol)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.PutLayer), (billInvflowHistory, warehouse) => billInvflowHistory.PutLayer.Equals(billInvflowHistoryQueryDto.PutLayer)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.Grade), (billInvflowHistory, warehouse) => billInvflowHistory.Grade.Contains(billInvflowHistoryQueryDto.Grade)); predicate = predicate.AndIF(billInvflowHistoryQueryDto != null && billInvflowHistoryQueryDto.OneInTimeBegin.HasValue, (billInvflowHistory, warehouse) => billInvflowHistory.OneInTime >= billInvflowHistoryQueryDto.OneInTimeBegin); predicate = predicate.AndIF(billInvflowHistoryQueryDto != null && billInvflowHistoryQueryDto.OneInTimeEnd.HasValue, (billInvflowHistory, warehouse) => billInvflowHistory.OneInTime <= billInvflowHistoryQueryDto.OneInTimeEnd); predicate = predicate.AndIF(billInvflowHistoryQueryDto != null && billInvflowHistoryQueryDto.ProductTimeBegin.HasValue, (billInvflowHistory, warehouse) => billInvflowHistory.ProductTime >= billInvflowHistoryQueryDto.ProductTimeBegin); predicate = predicate.AndIF(billInvflowHistoryQueryDto != null && billInvflowHistoryQueryDto.ProductTimeEnd.HasValue, (billInvflowHistory, warehouse) => billInvflowHistory.ProductTime <= billInvflowHistoryQueryDto.ProductTimeEnd); //predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.Tunnel), (billInvflowHistory, warehouse) => warecell.Tunnel.Equals(billInvflowHistoryQueryDto.Tunnel)); //predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.Code), (billInvflowHistory, warehouse) => warecell.Code.Contains(billInvflowHistoryQueryDto.Code)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsSurplus), (billInvflowHistory, warehouse) => billInvflowHistory.IsSurplus.Equals(billInvflowHistoryQueryDto.IsSurplus)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsRework), (billInvflowHistory, warehouse) => billInvflowHistory.IsRework.Equals(billInvflowHistoryQueryDto.IsRework)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsFail), (billInvflowHistory, warehouse) => billInvflowHistory.IsFail.Equals(billInvflowHistoryQueryDto.IsFail)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsFast), (billInvflowHistory, warehouse) => billInvflowHistory.IsFast.Equals(billInvflowHistoryQueryDto.IsFast)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsBack), (billInvflowHistory, warehouse) => billInvflowHistory.IsBack.Equals(billInvflowHistoryQueryDto.IsBack)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsBlack), (billInvflowHistory, warehouse) => billInvflowHistory.IsBlack.Equals(billInvflowHistoryQueryDto.IsBlack)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsControlpanel), (billInvflowHistory, warehouse) => billInvflowHistory.IsControlpanel.Equals(billInvflowHistoryQueryDto.IsControlpanel)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsTorsChk), (billInvflowHistory, warehouse) => billInvflowHistory.IsTorsChk.Equals(billInvflowHistoryQueryDto.IsTorsChk)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsCore), (billInvflowHistory, warehouse) => billInvflowHistory.IsCore.Equals(billInvflowHistoryQueryDto.IsCore)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.WbGroupCode), (billInvflowHistory, warehouse) => billInvflowHistory.WbGroupCode.Contains(billInvflowHistoryQueryDto.WbGroupCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.SolderCount), (billInvflowHistory, warehouse) => billInvflowHistory.SolderCount.ToString().Contains(billInvflowHistoryQueryDto.SolderCount)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.HoldTime), (billInvflowHistory, warehouse) => billInvflowHistory.HoldTime.ToString().Contains(billInvflowHistoryQueryDto.HoldTime)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.Wind), (billInvflowHistory, warehouse) => billInvflowHistory.Wind.ToString().Contains(billInvflowHistoryQueryDto.Wind)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.TorsChkQty), (billInvflowHistory, warehouse) => billInvflowHistory.TorsChkQty.Equals(billInvflowHistoryQueryDto.TorsChkQty)); //if (!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsTimeOut) && billInvflowHistoryQueryDto?.IsTimeOut == "1") //{ // predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.IsTimeOut), (billInvflowHistory, warehouse) => (DateTime.Now - billInvflowHistory.ProductTime).TotalHours >= 72 && !billInvflowHistory.InDocsNo.ToLower().Contains("cha")); //} predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.ExecStateCode), (billInvflowHistory, warehouse) => billInvflowHistory.ExecStateCode.Equals(billInvflowHistoryQueryDto.ExecStateCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.ContGrpType), (billInvflowHistory, warehouse) => billInvflowHistory.ContGrpType.Equals(billInvflowHistoryQueryDto.ContGrpType)); if (!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.InvStateCode)) { var enums = (InvState)Enum.ToObject(typeof(InvState), Convert.ToInt32(billInvflowHistoryQueryDto?.InvStateCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(billInvflowHistoryQueryDto?.InvStateCode), (billInvflowHistory, warehouse) => billInvflowHistory.InvStateCode.Equals(enums.ToString())); } var sugarQueryable = _billInvflowHistoryRepository.Context.Queryable((billInvflowHistory, warehouse) => new object[] { JoinType.Left, billInvflowHistory.WarehouseId==warehouse.Id}).Where(predicate.ToExpression()) .Select((billInvflowHistory, warehouse) => new BillInvflowHistoryDto { Id = billInvflowHistory.Id.ToString(), WarehouseId = billInvflowHistory.WarehouseId.ToString(), WarehouseName = warehouse.Name, ContGrpId = billInvflowHistory.ContGrpId.ToString(), ContGrpBarCode = billInvflowHistory.ContGrpBarCode, ContGrpType = (int)billInvflowHistory.ContGrpType, BoxBarCode = billInvflowHistory.BoxBarCode, BomDocsNo = billInvflowHistory.BomDocsNo, BomMatId = billInvflowHistory.BomMatId.ToString(), BomMatCode = billInvflowHistory.BomMatCode, BomMatName = billInvflowHistory.BomMatName, BomSetId = billInvflowHistory.BomSetId.ToString(), ExecStateCode = billInvflowHistory.ExecStateCode, InvStateCode = billInvflowHistory.InvStateCode, ExecDocsNo = billInvflowHistory.ExecDocsNo, ExecDocsRowNo = billInvflowHistory.ExecDocsRowNo, ExecDocsTypeCode = billInvflowHistory.ExecDocsTypeCode, InvInOut = (int)billInvflowHistory.InvInOut, ExecWho = billInvflowHistory.ExecWho, ExecTime = billInvflowHistory.ExecTime, PutRow = billInvflowHistory.PutRow, PutCol = billInvflowHistory.PutCol, PutLayer = billInvflowHistory.PutLayer, InvBarCode = billInvflowHistory.InvBarCode, InDocsNo = billInvflowHistory.InDocsNo, InDocsRowNo = billInvflowHistory.InDocsRowNo, SuppCode = billInvflowHistory.SuppCode, SuppName = billInvflowHistory.SuppName, CustCode = billInvflowHistory.CustCode, CustName = billInvflowHistory.CustName, MatId = billInvflowHistory.MatId.ToString(), MatCode = billInvflowHistory.MatCode, MatName = billInvflowHistory.MatName, TolWQty = billInvflowHistory.TolWQty, NetWQty = billInvflowHistory.NetWQty, TareWQty = billInvflowHistory.TareWQty, LengthQty = billInvflowHistory.LengthQty, CaQty = billInvflowHistory.CaQty, SolderQty = billInvflowHistory.SolderQty, ContUsageQty = billInvflowHistory.ContUsageQty, BatchNo = billInvflowHistory.BatchNo, ProductTime = billInvflowHistory.ProductTime, OneInTime = billInvflowHistory.OneInTime, RodBarCode = billInvflowHistory.RodBarCode, HWBarCode = billInvflowHistory.HWBarCode, RFIDBarCode = billInvflowHistory.RFIDBarCode, CLBarCode = billInvflowHistory.CLBarCode, HWTypeCode = billInvflowHistory.HWTypeCode, BoilerNo = billInvflowHistory.BoilerNo, PackNo = billInvflowHistory.PackNo, BrandNo = billInvflowHistory.BrandNo, ExecStd = billInvflowHistory.ExecStd, LicenceCode = billInvflowHistory.LicenceCode, IsSurplus = billInvflowHistory.IsSurplus, IsRework = billInvflowHistory.IsRework, IsBlack = billInvflowHistory.IsBlack, IsCore = billInvflowHistory.IsCore, IsFast = billInvflowHistory.IsFast, IsFail = billInvflowHistory.IsFail, FailReason = billInvflowHistory.FailReason, SilkTypeCode = billInvflowHistory.SilkTypeCode, Grade = billInvflowHistory.Grade, IsBack = billInvflowHistory.IsBack, BackReason = billInvflowHistory.BackReason, IsTorsChk = billInvflowHistory.IsTorsChk, TorsChkQty = billInvflowHistory.TorsChkQty, TorsChkTime = billInvflowHistory.TorsChkTime, TorsChkValue = billInvflowHistory.TorsChkValue, TorsChkMachCode = billInvflowHistory.TorsChkMachCode, ProcessDocsCode = billInvflowHistory.ProcessDocsCode, ProductMachCode = billInvflowHistory.ProductMachCode, ProductLineNo = billInvflowHistory.ProductLineNo, Wind = billInvflowHistory.Wind, AddWho = billInvflowHistory.AddWho, AddTime = billInvflowHistory.AddTime, EditWho = billInvflowHistory.EditWho, EditTime = billInvflowHistory.EditTime, Size = billInvflowHistory.Size, Memo = billInvflowHistory.Memo, PreStock = billInvflowHistory.PreStock, TorsChkChord = billInvflowHistory.TorsChkChord, TorsChkChordIsGood=billInvflowHistory.TorsChkChordIsGood, TorsChkFlatness = billInvflowHistory.TorsChkFlatness, TorsChkFlatnessIsGood=billInvflowHistory.TorsChkFlatnessIsGood, TorsChkStation=billInvflowHistory.TorsChkStation, TorsChkValueIsGood=billInvflowHistory.TorsChkValueIsGood, //Tunnel = warecell.Tunnel, //Code = warecell.Code, //CellState = warecell.IsStop, SolderCount = billInvflowHistory.SolderCount, HoldTime = billInvflowHistory.HoldTime, IsControlpanel = billInvflowHistory.IsControlpanel, WbGroupCode = billInvflowHistory.WbGroupCode, SkuCode = billInvflowHistory.SkuCode, }).MergeTable(); return sugarQueryable; } } }