From f82511343cf2c8ecf3981954e7eb92172d72a905 Mon Sep 17 00:00:00 2001
From: Huangxiaoqiang-03 <1247017146@qq.com>
Date: 星期二, 05 十一月 2024 17:26:08 +0800
Subject: [PATCH] 1
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs | 119 +++++------------------------------------------------------
1 files changed, 10 insertions(+), 109 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs"
index 707c213..b0f77a5 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs"
@@ -34,7 +34,7 @@
public ISqlSugarClient Db => BaseDal.Db;
private PropertyInfo[] _propertyInfo { get; set; } = null;
- private PropertyInfo[] TProperties
+ public PropertyInfo[] TProperties
{
get
{
@@ -49,113 +49,14 @@
public virtual PageGridData<TEntity> GetPageData(PageDataOptions options)
{
- string wheres = ValidatePageOptions(options);
+ string wheres = options.ValidatePageOptions(TProperties);
//鑾峰彇鎺掑簭瀛楁
- Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
+ Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(TProperties);
PageGridData<TEntity> pageGridData = new PageGridData<TEntity>();
pageGridData = BaseDal.QueryPage(wheres, options.Page, options.Rows, orderbyDic);
return pageGridData;
- }
-
-
- 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} = '{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;
- }
-
- /// <summary>
- /// 鑾峰彇鎺掑簭瀛楁
- /// </summary>
- /// <param name="pageData"></param>
- /// <param name="propertyInfo"></param>
- /// <returns></returns>
- private Dictionary<string, OrderByType> GetPageDataSort(PageDataOptions pageData, PropertyInfo[] propertyInfo)
- {
- if (!string.IsNullOrEmpty(pageData.Sort))
- {
- if (pageData.Sort.Contains(","))
- {
- List<string> sortArr = pageData.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] = pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc;
- }
- return sortDic;
- }
- else if (propertyInfo.Any(x => x.Name == pageData.Sort.FirstLetterToLower() || x.Name == pageData.Sort.FirstLetterToUpper()))
- {
- return new Dictionary<string, OrderByType> {
- {
- pageData.Sort,pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc
- } };
- }
- }
- return new Dictionary<string, OrderByType> { { "CreateDate", pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc } };
}
public virtual object GetDetailPage(PageDataOptions pageData)
@@ -243,8 +144,8 @@
}
else if (keyPro.PropertyType == typeof(int) || keyPro.PropertyType == typeof(long))
{
- SugarColumn sugarColumn = keyPro.GetCustomAttribute<SugarColumn>();
- if (sugarColumn.IsIdentity)
+ SugarColumn? sugarColumn = keyPro.GetCustomAttribute<SugarColumn>();
+ if (sugarColumn?.IsIdentity ?? true)
{
saveModel.MainData.Remove(keyPro.Name.FirstLetterToUpper());
saveModel.MainData.Remove(keyPro.Name.FirstLetterToLower());
@@ -358,7 +259,7 @@
{
return WebResponseContent.Instance.Error("浼犲弬閿欒,鍙傛暟涓嶈兘涓虹┖");
}
- string validResult = typeof(TEntity).ValidateDicInEntity(saveModel.MainData, false, TProperties, list?.ToArray());
+ string validResult = typeof(TEntity).ValidateDicInEntity(saveModel.MainData, false, TProperties, list?.ToArray() ?? null);
if (!string.IsNullOrEmpty(validResult))
{
@@ -376,7 +277,7 @@
List<string> listCol = new List<string>();
foreach (var item in saveModel.MainData)
{
- PropertyInfo propertyInfo = typeof(TEntity).GetProperty(item.Key);
+ PropertyInfo? propertyInfo = typeof(TEntity).GetProperty(item.Key);
if (propertyInfo == null)
{
propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToLower());
@@ -604,9 +505,9 @@
string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelExport";
IExporter exporter = new ExcelExporter();
- string wheres = ValidatePageOptions(options);
+ string wheres = options.ValidatePageOptions(TProperties);
//鑾峰彇鎺掑簭瀛楁
- Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
+ Dictionary<string, OrderByType> orderbyDic = options.GetPageDataSort(TProperties);
List<TEntity> entities = BaseDal.QueryData(wheres, orderbyDic);
@@ -715,7 +616,7 @@
List<TEntity> deviceInfos = BaseDal.QueryData();
string str = JsonConvert.SerializeObject(deviceInfos, Formatting.Indented);
List<Dictionary<string, object>> keyValuePairs = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(str);
- FileHelper.WriteFileAndDelOldFile($"{AppDomain.CurrentDomain.BaseDirectory}wwwroot/{seedDataFolder}", str);
+ FileHelper.WriteFileAndDelOldFile($"wwwroot/{seedDataFolder}", str);
content = WebResponseContent.Instance.OK();
}
catch (Exception ex)
--
Gitblit v1.9.3