From 1e12c140c041c0cb52306a0db9ff0ba18354d0d8 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 03 四月 2025 18:01:52 +0800
Subject: [PATCH] 优化WMS前端首页,货位查询column数据库关键字处理
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 163 insertions(+), 12 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs"
index ab489a0..84bc1c5 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Utilities/EntityProperties.cs"
@@ -1,13 +1,16 @@
锘縰sing SqlSugar;
using System;
+using System.Collections;
using System.Collections.Generic;
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
@@ -17,7 +20,6 @@
/// <summary>
/// 楠岃瘉鏁版嵁搴撳瓧娈电被鍨嬩笌鍊兼槸鍚︽纭紝
/// </summary>
- /// <param name="dbType">鏁版嵁搴撳瓧娈电被鍨�(濡倂archar,nvarchar,decimal,涓嶈甯﹀悗闈㈤暱搴﹀:varchar(50))</param>
/// <param name="value">鍊�</param>
/// <param name="propertyInfo">瑕侀獙璇佺殑绫荤殑灞炴�э紝鑻ヤ笉涓簄ull锛屽垯浼氬垽鏂瓧绗︿覆鐨勯暱搴︽槸鍚︽纭�</param>
/// <returns>(bool, string, object)bool鎴愬惁鏍¢獙鎴愬姛,string鏍¢獙澶辫触淇℃伅,object,褰撳墠鏍¢獙鐨勫��</returns>
@@ -28,7 +30,7 @@
if (propertyInfo != null)
{
sugarColumn = propertyInfo.GetCustomAttribute<SugarColumn>();
- dbType = propertyInfo != null ? propertyInfo.GetProperWithDbType() : SqlDbTypeName.NVarChar;
+ dbType = propertyInfo.PropertyType != null ? propertyInfo.GetProperWithDbType() : SqlDbTypeName.NVarChar;
}
dbType = dbType.ToLower();
string val = value?.ToString();
@@ -106,6 +108,16 @@
return (reslutMsg == "" ? true : false, reslutMsg, value);
}
+ public static List<(bool, string, object)> ValidationValueForDbType(this PropertyInfo propertyInfo, params object[] values)
+ {
+ List<(bool, string, object)> result = new List<(bool, string, object)>();
+ foreach (object value in values)
+ {
+ result.Add(propertyInfo.ValidationVal(value));
+ }
+ return result;
+ }
+
private static readonly Dictionary<Type, string> ProperWithDbType = new Dictionary<Type, string>() {
{ typeof(string),SqlDbTypeName.NVarChar },
{ typeof(DateTime),SqlDbTypeName.DateTime},
@@ -117,6 +129,7 @@
{ typeof(byte),SqlDbTypeName.Int },//绫诲瀷寰呭畬
{ typeof(Guid),SqlDbTypeName.UniqueIdentifier}
};
+
public static string GetProperWithDbType(this PropertyInfo propertyInfo)
{
bool result = ProperWithDbType.TryGetValue(propertyInfo.PropertyType, out string value);
@@ -135,7 +148,7 @@
/// <param name="removeNotContains">绉婚櫎涓嶅瓨鍦ㄥ瓧娈�</param>
/// <param name="removerKey">绉婚櫎涓婚敭</param>
/// <returns></returns>
- public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[] ignoreFields = null)
+ public static string ValidateDicInEntity(this Type typeinfo, Dictionary<string, object> dic, bool removerKey, PropertyInfo[] propertyInfo, string[]? ignoreFields = null)
{
if (dic == null || dic.Count == 0) { return "鍙傛暟鏃犳晥"; }
@@ -157,15 +170,23 @@
foreach (PropertyInfo property in propertyInfo)
{
- SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>();
+ SugarColumn? sugarColumn = property.GetCustomAttribute<SugarColumn>();
if (sugarColumn == null)
+ {
+ Navigate? navigate = property.GetCustomAttribute<Navigate>();
+ if(navigate != null)
+ {
+ continue;
+ }
return "璇烽厤缃甋ugarColumn灞炴��";
+ }
+
//蹇界暐涓庝富閿殑瀛楁涓嶅仛楠岃瘉
if (property.Name == keyName.FirstLetterToUpper() || (ignoreFields != null && ignoreFields.Contains(property.Name)) || sugarColumn.IsOnlyIgnoreInsert || sugarColumn.IsOnlyIgnoreUpdate || sugarColumn.IsIgnore)
continue;
//涓嶅湪缂栬緫涓殑鍒楋紝鏄惁涔熻蹇呭~
- if (!dic.ContainsKey(property.Name.FirstLetterToLower()))
+ if (!dic.ContainsKey(property.Name.FirstLetterToLower()) /*&& !dic.ContainsKey(property.Name.FirstLetterToUpper())*/)
{
if (!sugarColumn.IsNullable)
{
@@ -175,12 +196,29 @@
}
continue;
}
- string str = dic[property.Name.FirstLetterToLower()].ToString();
- //灏嗘墍鏈夌┖鍊艰缃负null
- if (dic[property.Name.FirstLetterToLower()] != null && str == string.Empty)
- dic[property.Name.FirstLetterToLower()] = null;
+ if(dic[property.Name.FirstLetterToLower()] != null)
+ {
+ string str = dic[property.Name.FirstLetterToLower()].ToString();
+ //灏嗘墍鏈夌┖鍊艰缃负null
+ if (str == string.Empty)
+ dic[property.Name.FirstLetterToLower()] = null;
+ }
+
}
return string.Empty;
+ }
+
+ public static string ValidateDicInEntity(this Type typeinfo, List<Dictionary<string, object>> dicList, bool removerKey, string[] ignoreFields = null)
+ {
+ PropertyInfo[] propertyInfo = typeinfo.GetProperties();
+ string reslutMsg = string.Empty;
+ foreach (Dictionary<string, object> dic in dicList)
+ {
+ reslutMsg = typeinfo.ValidateDicInEntity(dic, removerKey, propertyInfo, ignoreFields);
+ if (!string.IsNullOrEmpty(reslutMsg))
+ return reslutMsg;
+ }
+ return reslutMsg;
}
public static string GetKeyName(this Type typeinfo)
@@ -192,9 +230,12 @@
{
foreach (PropertyInfo property in properties)
{
- SugarColumn sugarColumn = property.GetCustomAttribute<SugarColumn>();
- if (sugarColumn.IsPrimaryKey)
- return property.Name;
+ SugarColumn? sugarColumn = property.GetCustomAttribute<SugarColumn>();
+ if (sugarColumn != null)
+ {
+ if (sugarColumn.IsPrimaryKey)
+ return property.Name;
+ }
}
return null;
}
@@ -212,5 +253,115 @@
}
return null;
}
+
+ public static Type GetDetailType(this Type typeinfo)
+ {
+ PropertyInfo[] properties = typeinfo.GetProperties();
+ foreach (PropertyInfo property in properties)
+ {
+ Navigate? navigate = property.GetCustomAttribute<Navigate>();
+ if (navigate is not null)
+ {
+ if (navigate.GetNavigateType() == NavigateType.OneToOne)
+ return property.PropertyType;
+ else
+ return property.PropertyType.GenericTypeArguments[0];
+ }
+ }
+ return null;
+ }
+
+ public static string GetMainIdByDetail(this Type typeinfo)
+ {
+ PropertyInfo[] properties = typeinfo.GetProperties();
+ foreach (PropertyInfo property in properties)
+ {
+ Navigate? navigate = property.GetCustomAttribute<Navigate>();
+ if (navigate is not null)
+ {
+ return navigate.GetName();
+ }
+ }
+ return null;
+ }
+
+ public static void SetDetailId<T>(this Type typeinfo, T enetiy, object id, string name)
+ {
+ PropertyInfo property = typeinfo.GetProperty(name);
+ if (property != null)
+ {
+ property.SetValue(enetiy, id);
+ }
+ }
+
+ public static PropertyInfo? GetNavigatePro(this Type typeinfo)
+ {
+ PropertyInfo[] properties = typeinfo.GetProperties();
+ foreach (PropertyInfo property in properties)
+ {
+ Navigate? navigate = property.GetCustomAttribute<Navigate>();
+ if (navigate is not null)
+ {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ public static object GetPropertyValue<T>(this Type typeinfo, T data, string propertyName)
+ {
+ if (typeinfo != typeof(T))
+ return null;
+
+ PropertyInfo? property = typeinfo.GetProperty(propertyName);
+ if (property != null)
+ {
+ return property.GetValue(data);
+ }
+ 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