Merge branch 'refs/heads/abp' into pure

This commit is contained in:
橙子
2024-08-31 19:08:38 +08:00
6 changed files with 88 additions and 7 deletions

View File

@@ -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
/// <summary>
/// CPU使用率%
/// </summary>
public string CPURate { get; set; }
public double CPURate { get; set; }
/// <summary>
/// 总内存 GB
/// </summary>

View File

@@ -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
{

View File

@@ -40,6 +40,9 @@ namespace Yi.Framework.SqlSugarCore
public IEntityChangeEventHelper EntityChangeEventHelper => LazyServiceProvider.LazyGetService<IEntityChangeEventHelper>(NullEntityChangeEventHelper.Instance);
public DbConnOptions Options => LazyServiceProvider.LazyGetRequiredService<IOptions<DbConnOptions>>().Value;
public AbpDbConnectionOptions ConnectionOptions => LazyServiceProvider.LazyGetRequiredService<IOptions<AbpDbConnectionOptions>>().Value;
public ISerializeService SerializeService=> LazyServiceProvider.LazyGetRequiredService<ISerializeService>();
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;
}
/// <summary>

View File

@@ -0,0 +1,76 @@
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using SqlSugar;
namespace Yi.Framework.SqlSugarCore;
public class NonPublicPropertiesResolver : DefaultContractResolver
{
/// <summary>
/// 重写获取属性存在get set方法就可以写入
/// </summary>
/// <param name="member"></param>
/// <param name="memberSerialization"></param>
/// <returns></returns>
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
{
/// <summary>
/// 默认的序列化服务
/// </summary>
private readonly ISerializeService _serializeService = DefaultServices.Serialize;
public string SerializeObject(object value)
{
//保留原有实现
return _serializeService.SerializeObject(value);
}
public string SugarSerializeObject(object value)
{ //保留原有实现
return _serializeService.SugarSerializeObject(value);
}
/// <summary>
/// 重写对象反序列化支持NoPublic访问器
/// </summary>
/// <param name="value"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T DeserializeObject<T>(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<T>(value, jSetting);
}
}

View File

@@ -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<ISerializeService,SqlSugarNonPublicSerializer> ();
return Task.CompletedTask;
}

View File

@@ -23,11 +23,11 @@
</tr>
<tr>
<td class="el-table__cell is-leaf"><div class="cell">系统使用率</div></td>
<td class="el-table__cell is-leaf"><div class="cell" v-if="server.cpu">{{ Math.floor((server.cpu.used/server.cpu.total)*100)}}%</div></td>
<td class="el-table__cell is-leaf"><div class="cell" v-if="server.cpu">{{ server.cpu.cpuRate}}%</div></td>
</tr>
<tr>
<td class="el-table__cell is-leaf"><div class="cell">当前空闲率</div></td>
<td class="el-table__cell is-leaf"><div class="cell" v-if="server.cpu">{{ Math.floor((server.cpu.free/server.cpu.total)*100) }}%</div></td>
<td class="el-table__cell is-leaf"><div class="cell" v-if="server.cpu">{{ 100-server.cpu.cpuRate}}%</div></td>
</tr>
</tbody>
</table>