diff --git a/Src/Dlhis.Entity/Dlhis.Entity.csproj b/Src/Dlhis.Entity/Dlhis.Entity.csproj index 3193b66c..7d5d683b 100644 --- a/Src/Dlhis.Entity/Dlhis.Entity.csproj +++ b/Src/Dlhis.Entity/Dlhis.Entity.csproj @@ -11,7 +11,7 @@ - + diff --git a/Src/Dlhis.Middle/BackgroundServices/BalanceRecordUploadBackgroundService.cs b/Src/Dlhis.Middle/BackgroundServices/BalanceRecordUploadBackgroundService.cs index 9984ac59..470a15ce 100644 --- a/Src/Dlhis.Middle/BackgroundServices/BalanceRecordUploadBackgroundService.cs +++ b/Src/Dlhis.Middle/BackgroundServices/BalanceRecordUploadBackgroundService.cs @@ -10,7 +10,6 @@ public class BalanceRecordUploadBackgroundService : BackgroundService { private readonly IServiceProvider _serviceProvider; private readonly ILogger _logger; - private readonly IWebHostEnvironment _environment; private readonly ISettingService _settingService; private readonly ICanteenApi _canteenApi; @@ -18,14 +17,12 @@ public class BalanceRecordUploadBackgroundService : BackgroundService public BalanceRecordUploadBackgroundService(IServiceProvider serviceProvider, ILogger logger, - IWebHostEnvironment environment, ISettingService settingService, ICanteenApi canteenApi, IHealthCheckService healthCheckService) { _serviceProvider = serviceProvider; _logger = logger; - _environment = environment; _settingService = settingService; _canteenApi = canteenApi; _healthCheckService = healthCheckService; @@ -33,7 +30,7 @@ public class BalanceRecordUploadBackgroundService : BackgroundService protected override async Task ExecuteAsync(CancellationToken stoppingToken) { - while (!stoppingToken.IsCancellationRequested && _environment.IsProduction()) + while (!stoppingToken.IsCancellationRequested) { if (!_healthCheckService.GetIsOffline()) { @@ -48,7 +45,10 @@ public class BalanceRecordUploadBackgroundService : BackgroundService { try { - var balanceRecords = await db.Queryable().Where(x => x.TenantId == factory).Where(x => !x.IsSync).ToListAsync(stoppingToken); + var balanceRecords = await db.Queryable() + .Where(x => x.TenantId == factory) + .Where(x => !x.IsSync).ToListAsync(stoppingToken); + if (balanceRecords.Any()) { _logger.LogInformation("上传离线订单"); @@ -87,9 +87,13 @@ public class BalanceRecordUploadBackgroundService : BackgroundService balanceRecords = await db.Queryable().Where(x => x.TenantId == factory).Where(x => !x.IsSync).ToListAsync(stoppingToken); if (!balanceRecords.Any()) { - _logger.LogInformation("上传离线订单完成"); + _logger.LogInformation("{factory}上传离线订单完成", factory); } } + else + { + _logger.LogInformation("{factory}无离线订单", factory); + } } catch (Exception e) { @@ -125,7 +129,7 @@ public class BalanceRecordUploadBackgroundService : BackgroundService } } - await Task.Delay(60 * 1000, stoppingToken); + await Task.Delay(30 * 1000, stoppingToken); } } } \ No newline at end of file diff --git a/Src/Dlhis.Middle/Packs/SqlSugarPack.cs b/Src/Dlhis.Middle/Packs/SqlSugarPack.cs index 347518f5..06656513 100644 --- a/Src/Dlhis.Middle/Packs/SqlSugarPack.cs +++ b/Src/Dlhis.Middle/Packs/SqlSugarPack.cs @@ -1,132 +1,13 @@ -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(DbType.Sqlite); - services.Replace(ServiceDescriptor.Scoped(typeof(ISqlSugarClient), sp => - { - var options = sp.GetService>().Value; - var logger = sp.GetService>(); - var currentUser = sp.GetService(); - var sugarOptions = sp.GetService(); - - var configs = new List - { - 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(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()) - { - model.SetValue(DateTime.Now); - } - - if (currentUser != null && model.IsAnyAttribute()) - { - if ((int)model.EntityColumnInfo.PropertyInfo.GetValue(model.EntityValue) == 0) - { - model.SetValue(currentUser.GetStringSubjectId()); - } - } - - break; - } - case DataFilterType.UpdateByObject: - { - if (model.IsAnyAttribute()) - { - model.SetValue(DateTime.Now); - } - - if (currentUser != null && model.IsAnyAttribute()) - { - model.SetValue(currentUser.GetStringSubjectId()); - } - - break; - } - } - }; - - return db; - })); } } \ No newline at end of file diff --git a/Src/Dlhis.Middle/Program.cs b/Src/Dlhis.Middle/Program.cs index 8d787f49..b07548a2 100644 --- a/Src/Dlhis.Middle/Program.cs +++ b/Src/Dlhis.Middle/Program.cs @@ -2,7 +2,6 @@ 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; @@ -33,7 +32,6 @@ public class Startup : DefaultStartup services.AddRemoteCall(App.ActiveTypes); services.AddMemoryCache(); - services.AddUserInfo(); } ///