| | |
| | | |
| | | public virtual PageGridData<StockViewDTO> GetPageData(PageDataOptions options) |
| | | { |
| | | string where = options.ValidatePageOptions(typeof(StockViewDTO).GetProperties()); |
| | | //获取排序字段 |
| | | //Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(typeof(StockViewDTO).GetProperties()); |
| | | //List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | //foreach (var item in orderbyDic) |
| | | //{ |
| | | // OrderByModel orderByModel = new OrderByModel() |
| | | // { |
| | | // FieldName = item.Key, |
| | | // OrderByType = item.Value |
| | | // }; |
| | | // orderByModels.Add(orderByModel); |
| | | //} |
| | | int totalCount = 0; |
| | | |
| | | ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>(); |
| | | try |
| | | { |
| | | ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>().Includes(x => x.Details); |
| | | ISugarQueryable<Dt_LocationInfo> sugarQueryable = _dbBase.Queryable<Dt_LocationInfo>(); |
| | | ISugarQueryable<Dt_StockInfoDetail> sugarQueryable2 = _dbBase.Queryable<Dt_StockInfoDetail>(); |
| | | |
| | | |
| | | List<StockViewDTO> list = sugarQueryable1.InnerJoin(sugarQueryable, (b, a) => a.LocationCode == b.LocationCode).WhereIF(!string.IsNullOrEmpty(where), where).Select((b, a) => new StockViewDTO |
| | | if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | AreaId = a.AreaId, |
| | | try |
| | | { |
| | | |
| | | List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | if (searchParametersList?.Any() == true) |
| | | { |
| | | foreach (var param in searchParametersList) |
| | | { |
| | | switch (param.Name) |
| | | { |
| | | case var name when name == nameof(Dt_StockInfoDetail.MaterielCode).FirstLetterToLower(): |
| | | if (!string.IsNullOrEmpty(param.Value?.ToString())) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1 |
| | | .Where(x => x.Details.Any(v => v.MaterielCode.Contains(param.Value.ToString()))); |
| | | } |
| | | break; |
| | | case var name when name == nameof(Dt_StockInfoDetail.BatchNo).FirstLetterToLower(): |
| | | if (!string.IsNullOrEmpty(param.Value?.ToString())) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1 |
| | | .Where(x => x.Details.Any(v => v.BatchNo.Contains(param.Value.ToString()))); |
| | | } |
| | | break; |
| | | |
| | | case var name when name == nameof(Dt_StockInfo.LocationCode).FirstLetterToLower(): |
| | | if (!string.IsNullOrEmpty(param.Value?.ToString())) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1 |
| | | .Where(x => x.LocationCode == param.Value.ToString()); |
| | | } |
| | | break; |
| | | case var name when name == nameof(Dt_LocationInfo.LocationStatus).FirstLetterToLower(): |
| | | if (!string.IsNullOrEmpty(param.Value?.ToString())) |
| | | { |
| | | sugarQueryable = sugarQueryable |
| | | .Where(x => x.LocationStatus == param.Value.ObjToInt()); |
| | | } |
| | | break; |
| | | case var name when name == nameof(Dt_StockInfo.StockStatus).FirstLetterToLower(): |
| | | if (!string.IsNullOrEmpty(param.Value?.ToString())) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1 |
| | | .Where(x => x.StockStatus == param.Value.ObjToInt()); |
| | | } |
| | | break; |
| | | case var name when name == nameof(Dt_StockInfo.WarehouseId).FirstLetterToLower(): |
| | | if (!string.IsNullOrEmpty(param.Value?.ToString())) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1 |
| | | .Where(x => x.WarehouseId == param.Value.ObjToInt()); |
| | | } |
| | | break; |
| | | case var name when name == nameof(Dt_StockInfo.CreateDate).FirstLetterToLower(): |
| | | if (DateTime.TryParse(param.Value?.ToString(), out DateTime minDate)) |
| | | { |
| | | LinqExpressionType expressionType = param.DisplayType.GetLinqCondition(); |
| | | if (expressionType == LinqExpressionType.ThanOrEqual) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1.Where(x => x.CreateDate >= minDate); |
| | | } |
| | | else if (expressionType == LinqExpressionType.LessThanOrEqual) |
| | | { |
| | | sugarQueryable1 = sugarQueryable1.Where(x => x.CreateDate <= minDate); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | } |
| | | |
| | | |
| | | ISugarQueryable<StockViewDTO> list = sugarQueryable1 |
| | | .InnerJoin(sugarQueryable, (b, a) => a.LocationCode == b.LocationCode) |
| | | .Select((b, a) => new StockViewDTO |
| | | { |
| | | LocationCode = b.LocationCode, |
| | | Column = a.Column, |
| | | WarehouseId = b.WarehouseId, |
| | | CreateDate = b.CreateDate, |
| | | Creater = b.Creater, |
| | | Depth = a.Depth, |
| | | EnalbeStatus = a.EnableStatus, |
| | | IsFull = b.IsFull, |
| | | Layer = a.Layer, |
| | | LocationName = a.LocationName, |
| | | LocationStatus = a.LocationStatus, |
| | |
| | | StockId = b.Id, |
| | | StockStatus = b.StockStatus, |
| | | Details = b.Details, |
| | | }).ToPageList(options.Page, options.Rows, ref totalCount); |
| | | }); |
| | | |
| | | int totalCount = 0; |
| | | var stockViewDTOs = list.ToPageList(options.Page, options.Rows, ref totalCount); |
| | | |
| | | return new PageGridData<StockViewDTO>(totalCount, list); |
| | | stockViewDTOs.ForEach(x => |
| | | { |
| | | x.MaterielCode = string.Join(",", x.Details.Select(d => d.MaterielCode).Distinct()); |
| | | x.BatchNo = string.Join(",", x.Details.Select(d => d.BatchNo).Distinct()); |
| | | x.MaterielSpec = x.Details.FirstOrDefault()?.MaterieSpec ?? ""; |
| | | x.MaterielName = x.Details.FirstOrDefault()?.MaterielName ?? ""; |
| | | }); |
| | | |
| | | return new PageGridData<StockViewDTO>(totalCount, stockViewDTOs); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | } |
| | | return new PageGridData<StockViewDTO>(); |
| | | } |
| | | |
| | | public virtual object GetDetailPage(PageDataOptions pageData) |