From 2de09bec5cc05bf875543fa8956167ca7db73021 Mon Sep 17 00:00:00 2001
From: 刘磊 <1161824510@qq.com>
Date: 星期三, 25 六月 2025 11:36:44 +0800
Subject: [PATCH] 合并

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseModels/PageDataOptions.cs |  134 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 1 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseModels/PageDataOptions.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseModels/PageDataOptions.cs"
index bffe798..98959a1 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseModels/PageDataOptions.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseModels/PageDataOptions.cs"
@@ -1,8 +1,14 @@
-锘縰sing System;
+锘縰sing SqlSugar;
+using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Core.Const;
+using WIDESEA_Core.Enums;
+using WIDESEA_Core.Helper;
+using WIDESEA_Core.Utilities;
 
 namespace WIDESEA_Core
 {
@@ -24,6 +30,132 @@
         /// 鏌ヨ鏉′欢
         /// </summary>
         public List<SearchParameters> Filter { get; set; }
+
+        public string ValidatePageOptions(PropertyInfo[] entityProperties)
+        {
+            string where = string.Empty;
+            List<SearchParameters> searchParametersList = new List<SearchParameters>();
+            if (this.Filter != null && this.Filter.Count > 0)
+            {
+                searchParametersList.AddRange(Filter);
+            }
+            else if (!string.IsNullOrEmpty(Wheres))
+            {
+                try
+                {
+                    searchParametersList = Wheres.DeserializeObject<List<SearchParameters>>();
+                    Filter = searchParametersList;
+                }
+                catch { }
+            }
+            for (int i = 0; i < searchParametersList.Count; i++)
+            {
+                if (string.IsNullOrEmpty(searchParametersList[i].Value))
+                {
+                    continue;
+                }
+
+                PropertyInfo? property = entityProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault();
+
+                if (property == null) continue;
+
+                List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList(); 
+                if (results == null || results.Count() == 0)
+                {
+                    continue;
+                }
+                for (int j = 0; j < results.Count(); j++)
+                {
+                    if (j == 0)
+                    {
+                        where += "(";
+                    }
+                    LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
+                    if (expressionType == LinqExpressionType.Equal)
+                    {
+                        where += $"{searchParametersList[i].Name} {HtmlElementType.Equal} '{results[j].Item3}'";
+                    }
+                    else if (expressionType == LinqExpressionType.ThanOrEqual)
+                    {
+                        where += $"{searchParametersList[i].Name} {HtmlElementType.ThanOrEqual} '{searchParametersList[i].Value}'";
+                    }
+                    else if (expressionType == LinqExpressionType.LessThanOrEqual)
+                    {
+                        where += $"{searchParametersList[i].Name} {HtmlElementType.LessOrequal} '{searchParametersList[i].Value}'";
+                    }
+                    else if (expressionType == LinqExpressionType.GreaterThan)
+                    {
+                        where += $"{searchParametersList[i].Name} {HtmlElementType.GT} '{searchParametersList[i].Value}'";
+                    }
+                    else if (expressionType == LinqExpressionType.LessThan)
+                    {
+                        where += $"{searchParametersList[i].Name} {HtmlElementType.LT} '{searchParametersList[i].Value}'";
+                    }
+                    else if (expressionType == LinqExpressionType.Contains)
+                    {
+                        where += $"{searchParametersList[i].Name} {HtmlElementType.like} '%{searchParametersList[i].Value}%'";
+                    }
+                    else
+                    {
+                        where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'";
+                    }
+
+                    if (j == results.Count() - 1)
+                    {
+                        where += ")";
+                    }
+                    else
+                    {
+                        where += " or ";
+                    }
+                }
+                if (i < searchParametersList.Count - 1)
+                    where += " and ";
+            }
+            return where;
+        }
+
+
+        public Dictionary<string, OrderByType> GetPageDataSort(PropertyInfo[] propertyInfo)
+        {
+            try
+            {
+                if (!string.IsNullOrEmpty(Sort))
+                {
+                    if (Sort.Contains(","))
+                    {
+                        List<string> sortArr = Sort.Split(",").Where(x => propertyInfo.Any(p => p.Name == x)).ToList();
+                        Dictionary<string, OrderByType> sortDic = new Dictionary<string, OrderByType>();
+                        foreach (var item in sortArr)
+                        {
+                            sortDic[item] = Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc;
+                        }
+                        return sortDic;
+                    }
+                    else if (propertyInfo.Any(x => x.Name == Sort.FirstLetterToLower() || x.Name == Sort.FirstLetterToUpper()))
+                    {
+                        Dictionary<string, OrderByType> result = new Dictionary<string, OrderByType>();
+
+                        if (Order == "asc")
+                        {
+                            result.Add(Sort, OrderByType.Asc);
+                        }
+                        else
+                        {
+                            result.Add(Sort, OrderByType.Desc);
+                        }
+
+                        return result;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+
+                throw;
+            }
+            return new Dictionary<string, OrderByType> { { "CreateDate", Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc } };
+        }
     }
     public class SearchParameters
     {

--
Gitblit v1.9.3