From 8f10146d39cf95dac9b68c83c4474d11d453530c Mon Sep 17 00:00:00 2001 From: GitHubList Date: Wed, 28 Aug 2024 00:03:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCPU=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=8E=87=E3=80=81=E5=BD=93=E5=89=8D=E7=A9=BA?= =?UTF-8?q?=E9=97=B2=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/Yi.Framework.Core/Helper/ComputerHelper.cs | 4 ++-- Yi.RuoYi.Vue3/src/views/monitor/server/index.vue | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Yi.Abp.Net8/framework/Yi.Framework.Core/Helper/ComputerHelper.cs b/Yi.Abp.Net8/framework/Yi.Framework.Core/Helper/ComputerHelper.cs index 2c0acec4..c1f68058 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.Core/Helper/ComputerHelper.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.Core/Helper/ComputerHelper.cs @@ -94,7 +94,7 @@ namespace Yi.Framework.Core.Helper memoryMetrics.UsedRam = Math.Round(memoryMetrics.Used / 1024, 2) + "GB"; memoryMetrics.TotalRAM = Math.Round(memoryMetrics.Total / 1024, 2) + "GB"; memoryMetrics.RAMRate = Math.Ceiling(100 * memoryMetrics.Used / memoryMetrics.Total).ToString() + "%"; - memoryMetrics.CPURate = Math.Ceiling(ParseToDouble(GetCPURate())) + "%"; + memoryMetrics.CPURate = Math.Ceiling(ParseToDouble(GetCPURate())); return memoryMetrics; } catch (Exception ex) @@ -239,7 +239,7 @@ namespace Yi.Framework.Core.Helper /// /// CPU使用率% /// - public string CPURate { get; set; } + public double CPURate { get; set; } /// /// 总内存 GB /// diff --git a/Yi.RuoYi.Vue3/src/views/monitor/server/index.vue b/Yi.RuoYi.Vue3/src/views/monitor/server/index.vue index 91ccfc85..cd046d78 100644 --- a/Yi.RuoYi.Vue3/src/views/monitor/server/index.vue +++ b/Yi.RuoYi.Vue3/src/views/monitor/server/index.vue @@ -23,11 +23,11 @@
系统使用率
-
{{ Math.floor((server.cpu.used/server.cpu.total)*100)}}%
+
{{ server.cpu.cpuRate}}%
当前空闲率
-
{{ Math.floor((server.cpu.free/server.cpu.total)*100) }}%
+
{{ 100-server.cpu.cpuRate}}%
From bfe0f346c828588244152fd832d0bf923af27d39 Mon Sep 17 00:00:00 2001 From: chenchun Date: Thu, 29 Aug 2024 10:26:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E8=BD=AF=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/SqlSugarRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs index 6e47740f..38cf18d3 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs @@ -243,7 +243,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { - return await (await GetDbSimpleClientAsync()).AsUpdateable().SetColumns(nameof(ISoftDelete), true).Where(whereExpression).ExecuteCommandAsync() > 0; + return await (await GetDbSimpleClientAsync()).AsUpdateable().SetColumns(nameof(ISoftDelete.IsDeleted), true).Where(whereExpression).ExecuteCommandAsync() > 0; } else { From e3aada0fff566377c772c67c6ec0def859b2e505 Mon Sep 17 00:00:00 2001 From: bi8bo <2738644273@qq.com> Date: Fri, 30 Aug 2024 14:41:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=BF=E6=8D=A2Sqlsugar=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=BA=8F=E5=88=97=E5=8C=96=E5=99=A8=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3.Select()=E6=98=A0=E5=B0=84=E5=B5=8C=E5=A5=97/?= =?UTF-8?q?=E5=8C=BF=E5=90=8D=E7=B1=BB=E6=97=B6=EF=BC=8C=E5=AE=9E=E4=BD=93?= =?UTF-8?q?=E7=9A=84=E9=9D=9E=E5=85=AC=E6=9C=89=E8=AE=BF=E9=97=AE=E5=99=A8?= =?UTF-8?q?=20=E5=80=BC=E6=97=A0=E6=B3=95=E7=BB=91=E5=AE=9A,=E5=A6=82Id(pr?= =?UTF-8?q?otect=E5=B1=9E=E6=80=A7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SqlSugarDbContext.cs | 5 ++ .../SqlSugarNonPublicSerializer.cs | 76 +++++++++++++++++++ .../YiFrameworkSqlSugarCoreModule.cs | 4 +- 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarNonPublicSerializer.cs diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs index 0712e96d..09543005 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs @@ -40,6 +40,9 @@ namespace Yi.Framework.SqlSugarCore public IEntityChangeEventHelper EntityChangeEventHelper => LazyServiceProvider.LazyGetService(NullEntityChangeEventHelper.Instance); public DbConnOptions Options => LazyServiceProvider.LazyGetRequiredService>().Value; public AbpDbConnectionOptions ConnectionOptions => LazyServiceProvider.LazyGetRequiredService>().Value; + + public ISerializeService SerializeService=> LazyServiceProvider.LazyGetRequiredService(); + private ISqlSugarDbConnectionCreator _dbConnectionCreator; public void SetSqlSugarClient(ISqlSugarClient sqlSugarClient) @@ -63,6 +66,8 @@ namespace Yi.Framework.SqlSugarCore options.DbType = GetCurrentDbType(); })); connectionCreator.SetDbAop(SqlSugarClient); + //替换默认序列化器 + SqlSugarClient.CurrentConnectionConfig.ConfigureExternalServices.SerializeService = SerializeService; } /// diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarNonPublicSerializer.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarNonPublicSerializer.cs new file mode 100644 index 00000000..74a1bee5 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarNonPublicSerializer.cs @@ -0,0 +1,76 @@ +using System.Reflection; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using SqlSugar; + +namespace Yi.Framework.SqlSugarCore; + +public class NonPublicPropertiesResolver : DefaultContractResolver +{ + /// + /// 重写获取属性,存在get set方法就可以写入 + /// + /// + /// + /// + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + var prop = base.CreateProperty(member, memberSerialization); + if (member is PropertyInfo pi) + { + prop.Readable = (pi.GetMethod != null); + prop.Writable = (pi.SetMethod != null); + } + + return prop; + } +} + +public class SqlSugarNonPublicSerializer : ISerializeService +{ + /// + /// 默认的序列化服务 + /// + private readonly ISerializeService _serializeService = DefaultServices.Serialize; + + public string SerializeObject(object value) + { + //保留原有实现 + return _serializeService.SerializeObject(value); + } + + public string SugarSerializeObject(object value) + { //保留原有实现 + return _serializeService.SugarSerializeObject(value); + } + + /// + /// 重写对象反序列化支持NoPublic访问器 + /// + /// + /// + /// + public T DeserializeObject(string value) + { + if (typeof(T).FullName.StartsWith("System.Text.Json.")) + { + // 动态创建一个 JsonSerializer 实例 + Type serializerType =typeof(T).Assembly.GetType("System.Text.Json.JsonSerializer"); + + var methods = serializerType + .GetMethods().Where(it=>it.Name== "Deserialize") + .Where(it=>it.GetParameters().Any(z=>z.ParameterType==typeof(string))).First(); + + // 调用 SerializeObject 方法序列化对象 + T json = (T)methods.MakeGenericMethod(typeof(T)) + .Invoke(null, new object[] { value, null }); + return json; + } + var jSetting = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore, + ContractResolver =new NonPublicPropertiesResolver() //替换默认解析器使能支持protect + }; + return JsonConvert.DeserializeObject(value, jSetting); + } +} \ No newline at end of file diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs index 9718f18b..9f8aa952 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs @@ -39,8 +39,8 @@ namespace Yi.Framework.SqlSugarCore service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>)); service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlsugarDbContextProvider<>)); - - + //替换Sqlsugar默认序列化器,用来解决.Select()不支持嵌套对象/匿名对象的非公有访问器 值无法绑定,如Id属性 + context.Services.AddSingleton (); return Task.CompletedTask; }