From f29f358f589f5b1c2589c07b65845650be7aafef Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期一, 08 十二月 2025 21:21:08 +0800
Subject: [PATCH] 代码优化

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs |  133 ++++++++++++++++++++++++++++++--------------
 1 files changed, 90 insertions(+), 43 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs"
index e6aadcc..98cd527 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_StockService/StockViewService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/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,52 +28,98 @@
 
         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>().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
+            try
             {
-                LocationCode = b.LocationCode,
-                Column = a.Column,
-                CreateDate = b.CreateDate,
-                Creater = b.Creater,
-                Depth = a.Depth,
-                EnalbeStatus = a.EnableStatus,
-                Layer = a.Layer,
-                LocationName = a.LocationName,
-                LocationStatus = a.LocationStatus,
-                LocationType = a.LocationType,
-                Modifier = b.Modifier,
-                ModifyDate = b.ModifyDate,
-                PalletCode = b.PalletCode,
-                StockRemark = b.Remark,
-                RoadwayNo = a.RoadwayNo,
-                Row = a.Row,
-                StockId = b.Id,
-                StockStatus = b.StockStatus,
-                Details = b.Details,
-            }).ToPageList(options.Page, options.Rows, ref totalCount);
+                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<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,
+                    Layer = a.Layer,
+                    LocationName = a.LocationName,
+                    LocationStatus = a.LocationStatus,
+                    LocationType = a.LocationType,
+                    Modifier = b.Modifier,
+                    ModifyDate = b.ModifyDate,
+                    PalletCode = b.PalletCode,
+                    StockRemark = b.Remark,
+                    RoadwayNo = a.RoadwayNo,
+                    Row = a.Row,
+                    StockId = b.Id,
+                    StockStatus = b.StockStatus,
+                    Details = b.Details,
+                });
+                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)

--
Gitblit v1.9.3