using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using WMS.BZModels; using WMS.Info; using WMS.BZSqlSugar; using wms.sqlsugar.model.cp; using WMS.BZModels.Dto.CP.BoxitemsDtos; namespace WMS.BZServices.CP { public class BoxitemsInfoService { private readonly Repository _boxitemsrepository; public BoxitemsInfoService(Repository boxitemsrepository) { _boxitemsrepository = boxitemsrepository; } public PagedInfo GetPageList(Pagination pagination, BoxitemsQueryDto boxitemsQueryDto) { if (pagination.sord.ToUpper() != "ASC") { pagination.sidx = pagination.sidx + " DESC"; } if (pagination.sidx.IsEmpty()) { pagination.sidx = "AddTime DESC"; } var predicate = Expressionable.Create(); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.KeyWord), m => m.MaterialCode.Contains(boxitemsQueryDto.KeyWord) || m.HuNr.Contains(boxitemsQueryDto.KeyWord) || m.HWBarCode.Contains(boxitemsQueryDto.KeyWord) || m.InDocsNo.Contains(boxitemsQueryDto.KeyWord) || m.OrderNo.Contains(boxitemsQueryDto.KeyWord) || m.Sku.Contains(boxitemsQueryDto.KeyWord) || m.Batch.Contains(boxitemsQueryDto.KeyWord)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.HuNr), m => m.HuNr.Contains(boxitemsQueryDto.HuNr)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.HWBarCode), m => m.HWBarCode.Contains(boxitemsQueryDto.HWBarCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.Sku), m => m.Sku.Contains(boxitemsQueryDto.Sku)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.Batch), m => m.Batch.Contains(boxitemsQueryDto.Batch)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.OrderNo), m => m.OrderNo.Contains(boxitemsQueryDto.OrderNo)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.MaterialCode), m => m.MaterialCode.Contains(boxitemsQueryDto.MaterialCode)); predicate = predicate.AndIF(boxitemsQueryDto != null && boxitemsQueryDto.AddTimeBegin.HasValue, m => m.AddTime >= boxitemsQueryDto.AddTimeBegin); predicate = predicate.AndIF(boxitemsQueryDto != null && boxitemsQueryDto.AddTimeEnd.HasValue, m => m.AddTime <= boxitemsQueryDto.AddTimeEnd); if (!string.IsNullOrEmpty(boxitemsQueryDto?.ExecStateCode)) { var enums = (InvLockState)Enum.ToObject(typeof(InvLockState), Convert.ToInt32(boxitemsQueryDto?.ExecStateCode)); predicate = predicate.AndIF(!string.IsNullOrEmpty(boxitemsQueryDto?.ExecStateCode), m => m.ExecStateCode.Equals(enums.ToString())); } var list = _boxitemsrepository.Queryable().Where(predicate.ToExpression()) //.OrderBy(pagination.sidx) .ToPage(pagination); return list; } } }