From cebd0800e9b5e1a1055a48d5e52f3f8a85e8d82c Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期一, 13 一月 2025 20:59:26 +0800 Subject: [PATCH] 1 --- 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 47 insertions(+), 2 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs" index c351b8b..a57e31b 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs" @@ -5,10 +5,12 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading.Tasks; using WIDESEA_Core.Const; +using WIDESEA_Core.Enums; using WIDESEA_Core.Helper; namespace WIDESEA_Core.Utilities @@ -87,7 +89,7 @@ { int length = sugarColumn.Length; - if (length == 0) { return (true, null, null); } + if (length == 0) { return (true, null, value); } //鍒ゆ柇鍙屽瓧鑺備笌鍗曞瓧娈� else if (length < 8000 && ((dbType.Substring(0, 1) != "n" @@ -184,7 +186,7 @@ continue; //涓嶅湪缂栬緫涓殑鍒楋紝鏄惁涔熻蹇呭~ - if (!dic.ContainsKey(property.Name.FirstLetterToLower()) /*&& !dic.ContainsKey(property.Name.FirstLetterToUpper())*/) + if (!dic.ContainsKey(property.Name.FirstLetterToLower())) { if (!sugarColumn.IsNullable) { @@ -318,5 +320,48 @@ } return null; } + + public static void ValidatePageOptions<TEntity>(PageDataOptions options, ref ISugarQueryable<TEntity> sugarQueryable) + { + string where = string.Empty; + PropertyInfo[] entityProperties = typeof(TEntity).GetProperties(); + 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 { } + } + 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++) + { + LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); + Expression<Func<TEntity, bool>> expression = property.GetWhereExpression<TEntity>(results[j].Item3, null, expressionType); + sugarQueryable = sugarQueryable.Where(expression); + } + } + } } } -- Gitblit v1.9.3