heshaofeng
7 天以前 375ace27ad6afbc3c83d92add0fb5a0347a6edbf
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs
@@ -5,6 +5,7 @@
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.DB.Models;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
//using WIDESEA_Core.HostedService;
using WIDESEA_Core.Utilities;
@@ -27,30 +28,71 @@
        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;
            try
            {
            ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>().Includes(x=>x.Details);
                if (!string.IsNullOrEmpty(options.Wheres))
                {
                    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_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)
                    {
                    }
                }
                EntityProperties.ValidatePageOptions(options, ref sugarQueryable1);
            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
                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,
@@ -68,11 +110,16 @@
                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, stockViewDTOs);
            return new PageGridData<StockViewDTO>(totalCount, list);
            }
            catch (Exception ex)
            {
            }
            return new PageGridData<StockViewDTO>();
        }
        public virtual object GetDetailPage(PageDataOptions pageData)