fix 修复已知问题
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
using System.Net;
|
||||
using Kurisu.RemoteCall.Abstractions;
|
||||
using Polly;
|
||||
using Polly.Extensions.Http;
|
||||
|
||||
namespace Dlhis.Middle.Apis.Handlers;
|
||||
|
||||
@@ -8,16 +11,24 @@ public class HealthzClientHandler : IHttpRemoteCallPolicyHandler
|
||||
public IHttpClientBuilder ConfigureHttpClient(IHttpClientBuilder builder)
|
||||
{
|
||||
builder.ConfigureHttpClient(client => { client.Timeout = TimeSpan.FromSeconds(10); }).ConfigurePrimaryHttpMessageHandler(() =>
|
||||
{
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
||||
};
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
||||
};
|
||||
|
||||
return handler;
|
||||
})
|
||||
//.SetHandlerLifetime(TimeSpan.FromMinutes(5))
|
||||
.AddPolicyHandler(
|
||||
HttpPolicyExtensions
|
||||
.HandleTransientHttpError()
|
||||
.OrResult(x => x.StatusCode != HttpStatusCode.OK)
|
||||
//.OrResult(msg => msg.StatusCode != HttpStatusCode.OK)
|
||||
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
|
||||
);
|
||||
|
||||
return handler;
|
||||
});
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.RemoteCall" Version="0.4.4" />
|
||||
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="8.0.6" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.36" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlcipher" Version="2.1.8" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,136 +1,13 @@
|
||||
using Dlhis.Middle.Entities;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.Entity;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Attributes;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Options;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Middle.Packs;
|
||||
|
||||
public class SqlSugarPack : BaseAppPack
|
||||
{
|
||||
private const string _infoTemplate = "ExecuteCommand[{ms}] Timeout[{timeout}] \r\n {sql}";
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSqlSugar();
|
||||
services.Replace(ServiceDescriptor.Scoped(typeof(ISqlSugarClient), sp =>
|
||||
{
|
||||
var options = sp.GetService<IOptions<SqlSugarOptions>>().Value;
|
||||
var logger = sp.GetService<ILogger<SqlSugarClient>>();
|
||||
var currentUser = sp.GetService<ICurrentUser>();
|
||||
var sugarOptions = sp.GetService<ISqlSugarOptionsService>();
|
||||
|
||||
var configs = new List<ConnectionConfig>
|
||||
{
|
||||
new()
|
||||
{
|
||||
ConfigId = "db-main",
|
||||
|
||||
ConnectionString = options.DefaultConnectionString,
|
||||
DbType = DbType.Sqlite,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
|
||||
MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
DisableNvarchar = true,
|
||||
},
|
||||
ConfigureExternalServices = new ConfigureExternalServices
|
||||
{
|
||||
EntityService = (c, p) =>
|
||||
{
|
||||
if (!p.IsPrimarykey && c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>)
|
||||
|| (!p.IsPrimarykey && p.PropertyInfo.PropertyType == typeof(string)))
|
||||
{
|
||||
p.IsNullable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ISqlSugarClient db = new SqlSugarClient(configs);
|
||||
|
||||
db.Ado.CommandTimeOut = options.Timeout;
|
||||
|
||||
db.Aop.OnLogExecuted = (sql, parameters) =>
|
||||
{
|
||||
var ms = db.Ado.SqlExecutionTime.Milliseconds;
|
||||
|
||||
//警告慢sql
|
||||
if (ms >= options.SlowSqlTime * 1000)
|
||||
logger.LogWarning(message: _infoTemplate, ms, options.Timeout, sql);
|
||||
|
||||
if (options.EnableSqlLog)
|
||||
{
|
||||
sql = UtilMethods.GetSqlString(DbType.MySql, sql, parameters);
|
||||
logger.LogInformation(message: _infoTemplate, ms, options.Timeout, sql);
|
||||
}
|
||||
};
|
||||
|
||||
//软删除
|
||||
db.QueryFilter.AddTableFilter<ISoftDeleted>(x => x.IsDeleted == false);
|
||||
|
||||
|
||||
//增删改
|
||||
db.Aop.DataExecuting = (oldValue, model) =>
|
||||
{
|
||||
if (sugarOptions.IgnoreTenant == false //启用租户
|
||||
&& currentUser != null //用户信息存在
|
||||
&& model.PropertyName == nameof(ITenantId.TenantId) //当前为租户字段
|
||||
&& typeof(ITenantId).IsAssignableFrom(model.EntityValue.GetType())) //继承ITenantId
|
||||
{
|
||||
var tenant = currentUser.GetStringTenantId();
|
||||
model.SetValue(tenant);
|
||||
}
|
||||
|
||||
//处理人员和时间字段
|
||||
switch (model.OperationType)
|
||||
{
|
||||
case DataFilterType.InsertByObject:
|
||||
{
|
||||
if (model.IsAnyAttribute<InsertDateTimeGenerationAttribute>())
|
||||
{
|
||||
model.SetValue(DateTime.Now);
|
||||
}
|
||||
|
||||
if (currentUser != null && model.IsAnyAttribute<InsertUserGenerationAttribute>())
|
||||
{
|
||||
if ((int)model.EntityColumnInfo.PropertyInfo.GetValue(model.EntityValue) == 0)
|
||||
{
|
||||
model.SetValue(currentUser.GetStringSubjectId());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case DataFilterType.UpdateByObject:
|
||||
{
|
||||
if (model.IsAnyAttribute<UpdateDateTimeGenerationAttribute>())
|
||||
{
|
||||
model.SetValue(DateTime.Now);
|
||||
}
|
||||
|
||||
if (currentUser != null && model.IsAnyAttribute<UpdateUserGenerationAttribute>())
|
||||
{
|
||||
if ((int)model.EntityColumnInfo.PropertyInfo.GetValue(model.EntityValue) == 0)
|
||||
{
|
||||
model.SetValue(currentUser.GetStringSubjectId());
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return db;
|
||||
}));
|
||||
services.AddSqlSugar(DbType.Sqlite);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Dlhis.Middle.BackgroundServices;
|
||||
using Dlhis.Middle.Entities;
|
||||
using Dlhis.Middle.Services;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Authentication.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Microsoft.IdentityModel.Logging;
|
||||
@@ -32,6 +33,7 @@ public class Startup : DefaultStartup
|
||||
|
||||
services.AddRemoteCall(App.ActiveTypes);
|
||||
services.AddMemoryCache();
|
||||
services.AddUserInfo();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user