From 8f872af917daaf693368b166a6985410976ca30a Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <1247017146@qq.com>
Date: 星期一, 07 四月 2025 14:23:43 +0800
Subject: [PATCH] 优化底层查询添加

---
 Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs |  121 +++++++++++++++++++++++++++++++++-------
 1 files changed, 99 insertions(+), 22 deletions(-)

diff --git a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs
index 7b5b5b2..71e0481 100644
--- a/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs
+++ b/Code Management/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs
@@ -60,6 +60,73 @@
         }
 
 
+        //protected string ValidatePageOptions(PageDataOptions options)
+        //{
+        //    options = options ?? new PageDataOptions();
+        //    string where = "";
+        //    List<SearchParameters> searchParametersList = new List<SearchParameters>();
+        //    if (options.Filter != null && options.Filter.Count > 0)
+        //    {
+        //        searchParametersList.AddRange(options.Filter);
+        //    }
+        //    else if (!string.IsNullOrEmpty(options.Wheres))
+        //    {
+        //        try
+        //        {
+        //            searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+        //            options.Filter = searchParametersList;
+        //        }
+        //        catch { }
+        //    }
+        //    QueryRelativeList?.Invoke(searchParametersList);
+
+        //    for (int i = 0; i < searchParametersList.Count; i++)
+        //    {
+        //        if (string.IsNullOrEmpty(searchParametersList[i].Value))
+        //        {
+        //            continue;
+        //        }
+
+        //        PropertyInfo property = TProperties.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} like '%{results[j].Item3}%'";
+        //            }
+        //            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;
+        //}
+
         protected string ValidatePageOptions(PageDataOptions options)
         {
             options = options ?? new PageDataOptions();
@@ -91,38 +158,48 @@
 
                 if (property == null) continue;
 
-                List<(bool, string, object)> results = property.ValidationValueForDbType(searchParametersList[i].Value.Split(',')).ToList();
-                if (results == null || results.Count() == 0)
+                (bool, string, object) result = property.ValidationVal(searchParametersList[i].Value);
+                if (!result.Item1)
                 {
                     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} like '%{results[j].Item3}%'";
-                    }
-                    else
-                    {
-                        where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{results[j].Item3}'";
-                    }
 
-                    if (j == results.Count() - 1)
+                LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
+                if (expressionType == LinqExpressionType.Equal)
+                {
+                    if (string.IsNullOrEmpty(where))
                     {
-                        where += ")";
+                        // 閽堝瀛楃涓茬被鍨嬬殑瀛楁浣跨敤妯$硦鏌ヨ
+                        //where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
+                        if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false")
+                        {
+                            where += $" {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'";
+                        }
+                        else
+                        {
+                            where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
+                        }
                     }
                     else
                     {
-                        where += " or ";
+                        // 閽堝甯冨皵绫诲瀷瀛楁杩涜绮剧‘鏌ヨ
+                        if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false")
+                        {
+                            where += $" and {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'";
+                        }
+                        else
+                        {
+                            where += $" and {searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
+                        }
                     }
                 }
-                if (i < searchParametersList.Count - 1)
-                    where += " and ";
+                else
+                {
+                    if (string.IsNullOrEmpty(where))
+                        where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'";
+                    else
+                        where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'";
+                }
             }
             return where;
         }

--
Gitblit v1.9.3