From 6b7a0433e8501ccde0a7ae6a552833767502b34b Mon Sep 17 00:00:00 2001 From: sunkaixuna <610262374@qq.com> Date: Sun, 9 Jan 2022 18:37:14 +0800 Subject: [PATCH] Update core --- .../Abstract/Reportable/ReportableProvider.cs | 7 ++- .../Abstract/SaveableProvider/Storageable.cs | 1 + .../SqlBuilderProvider/SqlBuilderProvider.cs | 8 +++ .../SqlSugar/Entities/ConditionalModel.cs | 1 + .../SqlSugar/Interface/IStorageable.cs | 19 ++++++- .../SqlSugar/Utilities/UtilMethods.cs | 51 +++++++++++++++++++ 6 files changed, 85 insertions(+), 2 deletions(-) diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs index 6c44f4c6c..c3c3805e5 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/Reportable/ReportableProvider.cs @@ -205,7 +205,12 @@ namespace SqlSugar } else if (type.IsIn(typeof(decimal), typeof(double))) { - return value; + Expression, object>> exp = it => Convert.ToDecimal(it.ColumnName); + var result = queryBuilder.GetExpressionValue(exp, ResolveExpressType.WhereSingle).GetResultString(); + result = Regex.Replace(result, @"\[ColumnName\]", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase); + result = Regex.Replace(result, @"\`ColumnName\`", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase); + result = Regex.Replace(result, @"""ColumnName""", formatBuilder.FormatValue(value) + "", RegexOptions.IgnoreCase); + return result; } else if (type.IsIn(typeof(DateTime))) { diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs index 2d950e6a8..5cc3a0f05 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SaveableProvider/Storageable.cs @@ -221,6 +221,7 @@ namespace SqlSugar { FieldName = item.DbColumnName, ConditionalType = ConditionalType.Equal, + CSharpTypeName=UtilMethods.GetTypeName(value), FieldValue = value + "", FieldValueConvertFunc=this.Context.CurrentConnectionConfig.DbType==DbType.PostgreSQL? UtilMethods.GetTypeConvert(value):null diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs index ef5deb45f..0540d0e2e 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Abstract/SqlBuilderProvider/SqlBuilderProvider.cs @@ -363,9 +363,17 @@ namespace SqlSugar private static object GetFieldValue(ConditionalModel item) { if (item.FieldValueConvertFunc != null) + { return item.FieldValueConvertFunc(item.FieldValue); + } + else if (item.CSharpTypeName.HasValue()) + { + return UtilMethods.ConvertDataByTypeName(item.CSharpTypeName,item.FieldValue); + } else + { return item.FieldValue; + } } #endregion diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConditionalModel.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConditionalModel.cs index 5d7a48187..c7dfbf306 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConditionalModel.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/ConditionalModel.cs @@ -24,6 +24,7 @@ namespace SqlSugar } public string FieldName { get; set; } public string FieldValue { get; set; } + public string CSharpTypeName { get; set; } public ConditionalType ConditionalType { get; set; } [Newtonsoft.Json.JsonIgnoreAttribute] public Func FieldValueConvertFunc { get; set; } diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs index 41439b68a..beb67ce28 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Interface/IStorageable.cs @@ -38,10 +38,27 @@ namespace SqlSugar var list = Database.Where(it=>true); foreach (var pk in PkFields) { - list = list.Where(it => it.GetType().GetProperty(pk).GetValue(it, null).ObjToString() == Item.GetType().GetProperty(pk).GetValue(Item, null).ObjToString()); + list = list.Where(it =>IsEquals(it, pk)); } return list.Any(); } + + private bool IsEquals(T it, string pk) + { + var leftValue = it.GetType().GetProperty(pk).GetValue(it, null); + var rightValue = Item.GetType().GetProperty(pk).GetValue(Item, null); + var left = leftValue.ObjToString(); + var rigth = rightValue.ObjToString(); + if (it.GetType().GetProperty(pk).PropertyType == UtilConstants.DecType) + { + return Convert.ToDecimal(leftValue) == Convert.ToDecimal(rightValue); + } + else + { + return left == rigth; + } + } + public bool NotAny() { return !Any(); diff --git a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs index 26967a1a2..36fc85d9d 100644 --- a/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs +++ b/Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Utilities/UtilMethods.cs @@ -286,6 +286,18 @@ namespace SqlSugar return null; } + internal static string GetTypeName(object value) + { + if (value == null) + { + return null; + } + else + { + return value.GetType().Name; + } + } + internal static string GetParenthesesValue(string dbTypeName) { if (Regex.IsMatch(dbTypeName, @"\(.+\)")) @@ -438,5 +450,44 @@ namespace SqlSugar } return dic; } + public static object ConvertDataByTypeName(string ctypename,string value) + { + var item = new ConditionalModel() { + CSharpTypeName = ctypename, + FieldValue = value + }; + if (item.CSharpTypeName.EqualCase(UtilConstants.DecType.Name)) + { + return Convert.ToDecimal(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase(UtilConstants.DobType.Name)) + { + return Convert.ToDouble(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase(UtilConstants.DateType.Name)) + { + return Convert.ToDateTime(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase(UtilConstants.IntType.Name)) + { + return Convert.ToInt32(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase(UtilConstants.LongType.Name)) + { + return Convert.ToInt64(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase(UtilConstants.ShortType.Name)) + { + return Convert.ToInt16(item.FieldValue); + } + else if (item.CSharpTypeName.EqualCase(UtilConstants.DateTimeOffsetType.Name)) + { + return UtilMethods.GetDateTimeOffsetByDateTime(Convert.ToDateTime(item.FieldValue)); + } + else + { + return item.FieldValue; + } + } } }