From 7ff298c6834275b63b612af49651673689a39660 Mon Sep 17 00:00:00 2001 From: hutongqing <hutongqing@hnkhzn.com> Date: 星期三, 27 十一月 2024 11:33:18 +0800 Subject: [PATCH] 更新 --- WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs | 122 +++++++++++++++++++++------------------- 1 files changed, 65 insertions(+), 57 deletions(-) diff --git a/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs b/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs index d72dc1e..8a630f0 100644 --- a/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs +++ b/WIDESEAWCS_Server/WIDESEAWCS_Core/BaseServices/ServiceBase.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.Extensions.Options; +using Newtonsoft.Json; using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using SqlSugar; using System.Drawing.Drawing2D; @@ -11,10 +12,10 @@ using System.Linq.Expressions; using System.Reflection; using WIDESEAWCS_Core.BaseRepository; +using WIDESEAWCS_Core.Const; using WIDESEAWCS_Core.Enums; using WIDESEAWCS_Core.Helper; using WIDESEAWCS_Core.Utilities; -using static OfficeOpenXml.ExcelErrorValue; namespace WIDESEAWCS_Core.BaseServices { @@ -53,42 +54,10 @@ Dictionary<string, OrderByType> orderbyDic = GetPageDataSort(options, TProperties); PageGridData<TEntity> pageGridData = new PageGridData<TEntity>(); - //if (QueryRelativeExpression != null) - //{ - // queryable = QueryRelativeExpression.Invoke(queryable); - //} - //if (options.Export) - //{ - // queryable = queryable.GetIQueryableOrderBy(orderbyDic); - // if (Limit > 0) - // { - // queryable = queryable.Take(Limit); - // } - // pageGridData.rows = queryable.ToList(); - //} - //else - //{ - // pageGridData.rows = repository.IQueryablePage(queryable, - // options.Page, - // options.Rows, - // out int rowCount, - // orderbyDic).ToList(); - // pageGridData.total = rowCount; - // //鏌ヨ鐣岄潰缁熻姹傜瓑瀛楁 - // if (SummaryExpress != null) - // { - // pageGridData.summary = SummaryExpress.Invoke(queryable); - // //Func<T, T> groupExpress = x =>x; - // //pageGridData.summary = queryable.GroupBy(groupExpress).Select(SummaryExpress).FirstOrDefault(); - // } - //} - //GetPageDataOnExecuted?.Invoke(pageGridData); - pageGridData = BaseDal.QueryPage(wheres, options.Page, options.Rows, orderbyDic); return pageGridData; } - protected string ValidatePageOptions(PageDataOptions options) { @@ -135,7 +104,27 @@ LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition(); if (expressionType == LinqExpressionType.Equal) { - where += $"{searchParametersList[i].Name} = '{results[j].Item3}'"; + 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 { @@ -163,7 +152,7 @@ /// <param name="pageData"></param> /// <param name="propertyInfo"></param> /// <returns></returns> - private Dictionary<string, OrderByType> GetPageDataSort(PageDataOptions pageData, PropertyInfo[] propertyInfo) + protected Dictionary<string, OrderByType> GetPageDataSort(PageDataOptions pageData, PropertyInfo[] propertyInfo) { if (!string.IsNullOrEmpty(pageData.Sort)) { @@ -181,7 +170,7 @@ { return new Dictionary<string, OrderByType> { { - pageData.Sort,pageData.Order?.ToLower() == OrderByType.Asc.ToString() ? OrderByType.Asc : OrderByType.Desc + pageData.Sort,pageData.Order?.ToLower() == OrderByType.Asc.ToString().ToLower() ? OrderByType.Asc : OrderByType.Desc } }; } } @@ -281,7 +270,7 @@ } } TEntity entity = saveModel.MainData.DicToModel<TEntity>(); - if (saveModel.DetailData == null && saveModel.DetailData.Count == 0) + if (saveModel.DetailData == null || saveModel.DetailData.Count == 0) { BaseDal.AddData(entity); return WebResponseContent.Instance.OK(); @@ -293,7 +282,7 @@ } Type detailType = typeof(TEntity).GetDetailType(); - MethodInfo? methodInfo = GetType().GetMethod("AddDataIncludesDetail"); + MethodInfo? methodInfo = GetType().GetMethod(nameof(AddDataIncludesDetail)); methodInfo = methodInfo?.MakeGenericMethod(new Type[] { detailType }); object? obj = methodInfo?.Invoke(this, new object[] { entity, detailType, saveModel.DetailData }); return obj as WebResponseContent; @@ -403,27 +392,27 @@ TEntity entity = saveModel.MainData.DicToModel<TEntity>(); - List<string> listCol = new List<string>(); - foreach (var item in saveModel.MainData) - { - PropertyInfo propertyInfo = typeof(TEntity).GetProperty(item.Key); - if (propertyInfo == null) - { - propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToLower()); - if (propertyInfo == null) - { - propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToUpper()); - } - } + //List<string> listCol = new List<string>(); + //foreach (var item in saveModel.MainData) + //{ + // PropertyInfo propertyInfo = typeof(TEntity).GetProperty(item.Key); + // if (propertyInfo == null) + // { + // propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToLower()); + // if (propertyInfo == null) + // { + // propertyInfo = typeof(TEntity).GetProperty(item.Key.FirstLetterToUpper()); + // } + // } - listCol.Add(propertyInfo?.Name); - } + // listCol.Add(propertyInfo?.Name); + //} - if (saveModel.DetailData == null && saveModel.DetailData.Count == 0) + if (saveModel.DetailData == null || saveModel.DetailData.Count == 0) { - if (list != null) - listCol = listCol.Where(x => !list.Contains(x)).ToList(); - bool result = BaseDal.UpdateData(entity, listCol, list); + //if (list != null) + // listCol = listCol.Where(x => !list.Contains(x)).ToList(); + bool result = BaseDal.UpdateData(entity); return WebResponseContent.Instance.OK(); } @@ -433,7 +422,7 @@ } Type detailType = typeof(TEntity).GetDetailType(); - MethodInfo? methodInfo = GetType().GetMethod("UpdateDataInculdesDetail"); + MethodInfo? methodInfo = GetType().GetMethod(nameof(UpdateDataInculdesDetail)); methodInfo = methodInfo?.MakeGenericMethod(new Type[] { detailType }); object? obj = methodInfo?.Invoke(this, new object[] { entity, detailType, saveModel.DetailData, saveModel.DelKeys }); return obj as WebResponseContent; @@ -735,5 +724,24 @@ content = WebResponseContent.Instance.OK(data: savePath + "\\" + fileName); return content; } + + public WebResponseContent ExportSeedData() + { + WebResponseContent content = new WebResponseContent(); + try + { + string seedDataFolder = $"WIDESEAWCS_DB.DBSeed.Json/{typeof(TEntity).Name}.tsv"; + 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); + content = WebResponseContent.Instance.OK(); + } + catch (Exception ex) + { + content = WebResponseContent.Instance.Error(ex.Message); + } + return content; + } } } -- Gitblit v1.9.3