using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using wms.sqlsugar.model.pt; using WMS.BZModels; using WMS.BZModels.Dto.PT.BarcodeDtos; using WMS.Info; using WMS.BZSqlSugar; namespace WMS.BZServices.PT { public class barCodeInfoService { private readonly Repository _invinit; public barCodeInfoService(Repository invinit) { _invinit = invinit; } public PagedInfo GetPageList(Pagination pagination, BarcodeQueryDto barcodeQuery) { if (pagination.sord.ToUpper() != "ASC") { pagination.sidx = pagination.sidx.IsEmpty() ? "AddTime DESC" : pagination.sidx + " DESC"; } if (pagination.sidx.IsEmpty()) { pagination.sidx = "AddTime DESC"; } var predicate = Expressionable.Create(); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.KeyWord), m => m.ContGrpBarCode.Contains(barcodeQuery.KeyWord) || m.InDocsNo.Contains(barcodeQuery.KeyWord) || m.MatCode.Contains(barcodeQuery.KeyWord) || m.SuppCode.Contains(barcodeQuery.KeyWord) || m.BoilerNo.Contains(barcodeQuery.KeyWord) || m.PackNo.Contains(barcodeQuery.KeyWord) || m.RodBarCode.Contains(barcodeQuery.KeyWord)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.ContGrpBarCode), m => m.ContGrpBarCode.ToString().Contains(barcodeQuery.ContGrpBarCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.RodBarCode), m => m.RodBarCode.Contains(barcodeQuery.RodBarCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.MatCode), m => m.MatCode.Contains(barcodeQuery.MatCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.SuppCode), m => m.SuppCode.Contains(barcodeQuery.SuppCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.InDocsNo), m => m.InDocsNo.Contains(barcodeQuery.InDocsNo)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.BoilerNo), m => m.BoilerNo.Contains(barcodeQuery.BoilerNo)); predicate = predicate.AndIF(!string.IsNullOrEmpty(barcodeQuery?.PackNo), m => m.PackNo.Contains(barcodeQuery.PackNo)); predicate = predicate.AndIF(barcodeQuery != null && barcodeQuery.AddTimeFrom.HasValue, (m) => m.AddTime >= barcodeQuery.AddTimeFrom); predicate = predicate.AndIF(barcodeQuery != null && barcodeQuery.AddTimeTo.HasValue, (m) => m.AddTime <= barcodeQuery.AddTimeTo); predicate = predicate.AndIF(barcodeQuery != null && barcodeQuery.EndTimeBegin.HasValue, (m) => m.EditTime >= barcodeQuery.EndTimeBegin); predicate = predicate.AndIF(barcodeQuery != null && barcodeQuery.EndTimeEnd.HasValue, (m) => m.EditTime <= barcodeQuery.EndTimeEnd); var list = _invinit.Queryable().Where(predicate.ToExpression()) .ToPage(pagination); return list; } } }