From f3382f9c8e4008afe50a070b918df871cd4a57b4 Mon Sep 17 00:00:00 2001
From: NoahLan <6995syu@163.com>
Date: Thu, 9 May 2024 22:30:33 +0800
Subject: [PATCH] =?UTF-8?q?wip:=20=E8=A7=A3=E5=86=B3=E9=85=8D=E7=BD=AE?=
=?UTF-8?q?=E7=AE=A1=E7=90=86+=E7=9F=AD=E4=BF=A1=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E3=80=82=E4=BC=98=E5=8C=96=E5=A4=A7=E9=83=A8=E5=88=86=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=90=AF=E5=8A=A8bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Abp/NPinHttpExceptionStatusCodeFinder.cs | 28 +
.../NPinFrameworkAspNetCoreModule.cs | 24 +-
.../DbConnOptions.cs | 208 ++---
.../NPinFrameworkSqlSugarCoreModule.cs | 218 +++--
.../Repositories/SqlSugarRepository.cs | 859 +++++++++---------
.../SqlSugarDbConnectionCreator.cs | 239 ++---
.../SqlSugarDbContext.cs | 573 ++++++------
.../UnitOfWorkSqlSugarDbContextProvider.cs | 273 +++---
.../AuditLogInfoToAuditLogConverter.cs | 175 ++--
.../AuditingStore.cs | 119 +--
.../Entities/AuditLogActionEntity.cs | 100 +-
.../Entities/AuditLogAggregateRoot.cs | 220 ++---
.../Entities/EntityChangeEntity.cs | 124 +--
.../Entities/EntityPropertyChangeEntity.cs | 98 +-
.../Entities/SettingEntity.cs | 39 +-
....Framework.SettingManagement.Domain.csproj | 4 +
.../SettingManager.cs | 21 +-
.../Store/SettingManagementStore.cs | 7 +-
.../TenantService.cs | 293 +++---
.../TenantAggregateRoot.cs | 98 +-
.../Consts/ConfigConst.cs | 29 +-
.../Enums/SmsEnum.cs | 42 +-
.../Model/AliyunConfigModel.cs | 24 -
.../Model/SmsConfigModel.cs | 180 ++--
.../Model/TencentConfigModel.cs | 31 -
.../Authorization/SocialAggregateRoot.cs | 90 +-
.../Entities/AnnouncementEntity.cs | 62 +-
.../Entities/ConfigEntity.cs | 66 +-
.../Entities/FileAggregateRoot.cs | 80 +-
.../Entities/LoginLogEntity.cs | 161 ++--
.../Entities/OrganizationEntity.cs | 90 +-
.../Entities/PostEntity.cs | 58 +-
.../Entities/RoleEntity.cs | 82 +-
.../Entities/RoleOrganizationEntity.cs | 30 +-
.../Entities/UserEntity.cs | 3 +-
.../Entities/UserMetaEntity.cs | 46 +-
.../Entities/UserOrganizationEntity.cs | 30 +-
.../Entities/UserPostEntity.cs | 32 +-
.../Entities/UserRoleEntity.cs | 32 +-
.../Managers/SmsManager.cs | 205 ++---
.../NPin.Framework.Upms.Domain.csproj | 1 +
.../NPinFrameworkUpmsDomainModule.cs | 70 +-
.../OperLog/OperationLogEntity.cs | 168 ++--
.../Settings/UpmsSettingManagementProvider.cs | 17 +
.../Settings/UpmsSettingManagerExtensions.cs | 23 +
.../Settings/UpmsStaticSettingProvider.cs | 20 +
.../Sms/Handler/AliyunSmsHandler.cs | 54 ++
.../Sms/Handler/TencentSmsHandler.cs | 64 ++
.../NPin.Framework.Upms.Domain/Sms/ISms.cs | 26 +-
.../DataSeeds/SmsConfigDataSeed.cs | 46 +
.../NPin.Framework.Upms.SqlSugarCore.csproj | 21 +-
.../NPinFrameworkUpmsSqlSugarCoreModule.cs | 39 +-
.../NPinUpmsDbContext.cs | 96 +-
.../{ => Repositories}/ConfigRepository.cs | 58 +-
src/NPin.SqlSugarCore/NPinDbContext.cs | 20 +-
.../NPinSqlSugarCoreModule.cs | 56 +-
src/NPin.Web/NPinWebModule.cs | 2 +-
src/NPin.Web/Program.cs | 2 +-
src/NPin.Web/Properties/launchSettings.json | 39 +-
src/NPin.Web/appsettings.json | 4 +-
60 files changed, 3141 insertions(+), 2778 deletions(-)
create mode 100644 framework/NPin.Framework.AspNetCore/Abp/NPinHttpExceptionStatusCodeFinder.cs
delete mode 100644 module/upms/NPin.Framework.Upms.Domain.Shared/Model/AliyunConfigModel.cs
delete mode 100644 module/upms/NPin.Framework.Upms.Domain.Shared/Model/TencentConfigModel.cs
create mode 100644 module/upms/NPin.Framework.Upms.Domain/Settings/UpmsSettingManagementProvider.cs
create mode 100644 module/upms/NPin.Framework.Upms.Domain/Settings/UpmsSettingManagerExtensions.cs
create mode 100644 module/upms/NPin.Framework.Upms.Domain/Settings/UpmsStaticSettingProvider.cs
create mode 100644 module/upms/NPin.Framework.Upms.Domain/Sms/Handler/AliyunSmsHandler.cs
create mode 100644 module/upms/NPin.Framework.Upms.Domain/Sms/Handler/TencentSmsHandler.cs
create mode 100644 module/upms/NPin.Framework.Upms.SqlSugarCore/DataSeeds/SmsConfigDataSeed.cs
rename module/upms/NPin.Framework.Upms.SqlSugarCore/{ => Repositories}/ConfigRepository.cs (91%)
diff --git a/framework/NPin.Framework.AspNetCore/Abp/NPinHttpExceptionStatusCodeFinder.cs b/framework/NPin.Framework.AspNetCore/Abp/NPinHttpExceptionStatusCodeFinder.cs
new file mode 100644
index 0000000..4ba372a
--- /dev/null
+++ b/framework/NPin.Framework.AspNetCore/Abp/NPinHttpExceptionStatusCodeFinder.cs
@@ -0,0 +1,28 @@
+using System.Net;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Options;
+using Volo.Abp.AspNetCore.ExceptionHandling;
+
+namespace NPin.Framework.AspNetCore.Abp;
+
+///
+/// NPin框架自定义 HttpStatusCode 处理器
+/// 将 IBusinessException 与 IUserFriendlyException 默认返回403改为500
+///
+public class NPinHttpExceptionStatusCodeFinder : DefaultHttpExceptionStatusCodeFinder
+{
+ public NPinHttpExceptionStatusCodeFinder(IOptions options) : base(options)
+ {
+ }
+
+ public override HttpStatusCode GetStatusCode(HttpContext httpContext, Exception exception)
+ {
+ switch (exception)
+ {
+ case IBusinessException _:
+ return HttpStatusCode.InternalServerError;
+ default:
+ return base.GetStatusCode(httpContext, exception);
+ }
+ }
+}
\ No newline at end of file
diff --git a/framework/NPin.Framework.AspNetCore/NPinFrameworkAspNetCoreModule.cs b/framework/NPin.Framework.AspNetCore/NPinFrameworkAspNetCoreModule.cs
index f2a55f6..a2839fb 100644
--- a/framework/NPin.Framework.AspNetCore/NPinFrameworkAspNetCoreModule.cs
+++ b/framework/NPin.Framework.AspNetCore/NPinFrameworkAspNetCoreModule.cs
@@ -1,9 +1,17 @@
-using NPin.Framework.Core;
-using Volo.Abp.Modularity;
-
-namespace NPin.Framework.AspNetCore;
-
-[DependsOn(typeof(NPinFrameworkCoreModule))]
-public class NPinFrameworkAspNetCoreModule : AbpModule
-{
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using NPin.Framework.AspNetCore.Abp;
+using NPin.Framework.Core;
+using Volo.Abp.AspNetCore.ExceptionHandling;
+
+namespace NPin.Framework.AspNetCore;
+
+[DependsOn(typeof(NPinFrameworkCoreModule))]
+public class NPinFrameworkAspNetCoreModule : AbpModule
+{
+ public override void ConfigureServices(ServiceConfigurationContext context)
+ {
+ context.Services.Replace(new ServiceDescriptor(typeof(IHttpExceptionStatusCodeFinder),
+ typeof(NPinHttpExceptionStatusCodeFinder), ServiceLifetime.Transient));
+ }
}
\ No newline at end of file
diff --git a/framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs b/framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
index a7eb463..330f426 100644
--- a/framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
+++ b/framework/NPin.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
@@ -1,105 +1,105 @@
-using SqlSugar;
-
-namespace NPin.Framework.SqlSugarCore.Abstractions;
-
-public class DbConnOptions
-{
- ///
- /// 连接字符串 必填
- ///
- public string? Url { get; set; }
-
- ///
- /// 数据库类型
- ///
- public DbType? DbType { get; set; }
-
- ///
- /// 开启种子数据
- ///
- public bool EnabledDbSeed { get; set; } = false;
-
- ///
- /// 开启 CodeFirst 自动化表结构
- ///
- public bool EnabledCodeFirst { get; set; } = false;
-
- ///
- /// 开启sql日志
- ///
- public bool EnabledSqlLog { get; set; } = true;
-
- ///
- /// 实体程序集
- ///
- public List? EntityAssembly { get; set; }
-
- ///
- /// 开启读写分离
- ///
- public bool EnabledReadWrite { get; set; } = false;
-
- ///
- /// 读写分离
- ///
- public List? ReadUrl { get; set; }
-
- ///
- /// 开启Saas多租户
- ///
- public bool EnabledSaasMultiTenancy { get; set; } = false;
-
-
- ///
- /// 默认租户库连接,如果不填,那就是默认库的地址
- ///
- public string? MasterSaasMultiTenancyUrl { get; set; }
-
-
- ///
- /// Saas租户连接
- ///
- public List? SaasMultiTenancy { get; set; }
-
- public static string MasterTenantName = "Master";
- public static string DefaultTenantName = "Default";
-
- public SaasMultiTenancyOptions GetDefaultSaasMultiTenancy()
- {
- return new SaasMultiTenancyOptions { Name = DefaultTenantName, Url = Url };
- }
-
- public SaasMultiTenancyOptions? GetDefaultMasterSaasMultiTenancy()
- {
- if (EnabledSaasMultiTenancy == false)
- {
- return null;
- }
-
- if (string.IsNullOrEmpty(MasterSaasMultiTenancyUrl))
- {
- return new SaasMultiTenancyOptions { Name = MasterTenantName, Url = Url };
- }
- else
- {
- return new SaasMultiTenancyOptions()
- {
- Name = MasterTenantName,
- Url = MasterSaasMultiTenancyUrl
- };
- }
- }
-}
-
-public class SaasMultiTenancyOptions
-{
- ///
- /// 租户名称标识
- ///
- public string Name { get; set; }
-
- ///
- /// 连接Url
- ///
- public string Url { get; set; }
+using SqlSugar;
+
+namespace NPin.Framework.SqlSugarCore.Abstractions;
+
+public class DbConnOptions
+{
+ ///
+ /// 连接字符串 必填
+ ///
+ public string? Url { get; set; }
+
+ ///
+ /// 数据库类型
+ ///
+ public DbType? DbType { get; set; }
+
+ ///
+ /// 开启种子数据
+ ///
+ public bool EnabledDbSeed { get; set; } = false;
+
+ ///
+ /// 开启 CodeFirst 自动化表结构
+ ///
+ public bool EnabledCodeFirst { get; set; } = false;
+
+ ///
+ /// 开启sql日志
+ ///
+ public bool EnabledSqlLog { get; set; } = true;
+
+ ///
+ /// 实体程序集
+ ///
+ public List? EntityAssembly { get; set; }
+
+ ///
+ /// 开启读写分离
+ ///
+ public bool EnabledReadWrite { get; set; } = false;
+
+ ///
+ /// 读写分离
+ ///
+ public List? ReadUrl { get; set; }
+
+ ///
+ /// 开启Saas多租户
+ ///
+ public bool EnabledSaasMultiTenancy { get; set; } = false;
+
+
+ ///
+ /// 默认租户库连接,如果不填,那就是默认库的地址
+ ///
+ public string? MasterSaasMultiTenancyUrl { get; set; }
+
+
+ ///
+ /// Saas租户连接
+ ///
+ public List? SaasMultiTenancy { get; set; }
+
+ public static string MasterTenantName = "Master";
+ public static string DefaultTenantName = "Default";
+
+ public SaasMultiTenancyOptions GetDefaultSaasMultiTenancy()
+ {
+ return new SaasMultiTenancyOptions { Name = DefaultTenantName, Url = Url };
+ }
+
+ public SaasMultiTenancyOptions? GetMasterSaasMultiTenancy()
+ {
+ if (EnabledSaasMultiTenancy == false)
+ {
+ return null;
+ }
+
+ if (string.IsNullOrEmpty(MasterSaasMultiTenancyUrl))
+ {
+ return new SaasMultiTenancyOptions { Name = MasterTenantName, Url = Url };
+ }
+ else
+ {
+ return new SaasMultiTenancyOptions()
+ {
+ Name = MasterTenantName,
+ Url = MasterSaasMultiTenancyUrl
+ };
+ }
+ }
+}
+
+public class SaasMultiTenancyOptions
+{
+ ///
+ /// 租户名称标识
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// 连接Url
+ ///
+ public string Url { get; set; }
}
\ No newline at end of file
diff --git a/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs b/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs
index affb446..585f2f7 100644
--- a/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs
+++ b/framework/NPin.Framework.SqlSugarCore/NPinFrameworkSqlSugarCoreModule.cs
@@ -1,94 +1,126 @@
-using System.Reflection;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.DependencyInjection.Extensions;
-using Microsoft.Extensions.Options;
-using NPin.Framework.SqlSugarCore.Abstractions;
-using NPin.Framework.SqlSugarCore.Repositories;
-using NPin.Framework.SqlSugarCore.Uow;
-using SqlSugar;
-using Volo.Abp;
-using Volo.Abp.Data;
-using Volo.Abp.Domain;
-using Volo.Abp.Domain.Repositories;
-using Volo.Abp.Modularity;
-
-namespace NPin.Framework.SqlSugarCore;
-
-[DependsOn(typeof(AbpDddDomainModule))]
-public class NPinFrameworkSqlSugarCoreModule : AbpModule
-{
- public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
- {
- var service = context.Services;
- var configuration = service.GetConfiguration();
- Configure(configuration.GetSection("DbConnOptions"));
-
- // 开放 sqlSugarClient
- service.TryAddScoped();
- // 不开放 sqlSugarClient
- //service.AddTransient(x => x.GetRequiredService().SqlSugarClient);
-
- service.AddTransient(typeof(IRepository<>), typeof(SqlSugarRepository<>));
- service.AddTransient(typeof(IRepository<,>), typeof(SqlSugarRepository<,>));
- service.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>));
- service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>));
-
- service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlSugarDbContextProvider<>));
-
- return Task.CompletedTask;
- }
-
- public override async Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context)
- {
- // CodeFirst & DataSeed
- var service = context.ServiceProvider;
- var options = service.GetRequiredService>().Value;
-
- if (options.EnabledCodeFirst)
- {
- CodeFirst(service);
- }
-
- if (options.EnabledDbSeed)
- {
- await DataSeedAsync(service);
- }
- }
-
- ///
- /// CodeFirst 建库建表
- ///
- ///
- private void CodeFirst(IServiceProvider service)
- {
- var moduleContainer = service.GetRequiredService();
- var db = service.GetRequiredService().SqlSugarClient;
-
- // 尝试创建数据库
- db.DbMaintenance.CreateDatabase();
-
- var types = new List();
- foreach (var module in moduleContainer.Modules)
- {
- types.AddRange(module.Assembly.GetTypes()
- .Where(x => x.GetCustomAttribute() == null)
- .Where(x => x.GetCustomAttribute() != null)
- .Where(x => x.GetCustomAttribute() is null));
- }
-
- if (types.Count > 0)
- {
- db.CopyNew().CodeFirst.InitTables(types.ToArray());
- }
- }
-
- ///
- /// 同步种子数据
- ///
- ///
- private async Task DataSeedAsync(IServiceProvider service)
- {
- var dataSeeder = service.GetRequiredService();
- await dataSeeder.SeedAsync();
- }
+using System.Reflection;
+using System.Text;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using NPin.Framework.SqlSugarCore.Abstractions;
+using NPin.Framework.SqlSugarCore.Repositories;
+using NPin.Framework.SqlSugarCore.Uow;
+using SqlSugar;
+using Volo.Abp.Data;
+using Volo.Abp.Domain;
+using Volo.Abp.Domain.Repositories;
+using Volo.Abp.Guids;
+
+namespace NPin.Framework.SqlSugarCore;
+
+[DependsOn(typeof(AbpDddDomainModule))]
+public class NPinFrameworkSqlSugarCoreModule : AbpModule
+{
+ public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
+ {
+ var service = context.Services;
+ var configuration = service.GetConfiguration();
+ Configure(configuration.GetSection("DbConnOptions"));
+
+ // 开放 sqlSugarClient
+ service.TryAddScoped();
+ // 不开放 sqlSugarClient
+ //service.AddTransient(x => x.GetRequiredService().SqlSugarClient);
+
+ service.AddTransient(typeof(IRepository<>), typeof(SqlSugarRepository<>));
+ service.AddTransient(typeof(IRepository<,>), typeof(SqlSugarRepository<,>));
+ service.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>));
+ service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>));
+
+ service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlSugarDbContextProvider<>));
+
+ return Task.CompletedTask;
+ }
+
+ public override async Task OnPreApplicationInitializationAsync(ApplicationInitializationContext context)
+ {
+ // CodeFirst & DataSeed
+ var service = context.ServiceProvider;
+ var options = service.GetRequiredService>().Value;
+
+ Configure(opt =>
+ {
+ switch (options.DbType)
+ {
+ case DbType.PostgreSQL:
+ case DbType.MySql:
+ opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAsString;
+ break;
+ case DbType.Oracle:
+ opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAsBinary;
+ break;
+ default:
+ opt.DefaultSequentialGuidType = SequentialGuidType.SequentialAtEnd;
+ break;
+ }
+ });
+
+ var logger = service.GetRequiredService>();
+
+ StringBuilder sb = new StringBuilder();
+ sb.AppendLine();
+ sb.AppendLine("==========NPin-SQL配置:==========");
+ sb.AppendLine($"数据库连接字符串:{options.Url}");
+ sb.AppendLine($"数据库类型:{options.DbType.ToString()}");
+ sb.AppendLine($"是否开启种子数据:{options.EnabledDbSeed}");
+ sb.AppendLine($"是否开启CodeFirst:{options.EnabledCodeFirst}");
+ sb.AppendLine($"是否开启Saas多租户:{options.EnabledSaasMultiTenancy}");
+ sb.AppendLine("===============================");
+
+ logger.LogInformation(sb.ToString());
+
+ if (options.EnabledCodeFirst)
+ {
+ CodeFirst(service);
+ }
+
+ if (options.EnabledDbSeed)
+ {
+ await DataSeedAsync(service);
+ }
+ }
+
+ ///
+ /// CodeFirst 建库建表
+ ///
+ ///
+ private void CodeFirst(IServiceProvider service)
+ {
+ var moduleContainer = service.GetRequiredService();
+ var db = service.GetRequiredService().SqlSugarClient;
+
+ // 尝试创建数据库
+ db.DbMaintenance.CreateDatabase();
+
+ var types = new List();
+ foreach (var module in moduleContainer.Modules)
+ {
+ types.AddRange(module.Assembly.GetTypes()
+ .Where(x => x.GetCustomAttribute() == null)
+ .Where(x => x.GetCustomAttribute() != null)
+ .Where(x => x.GetCustomAttribute() is null));
+ }
+
+ if (types.Count > 0)
+ {
+ db.CopyNew().CodeFirst.InitTables(types.ToArray());
+ }
+ }
+
+ ///
+ /// 同步种子数据
+ ///
+ ///
+ private async Task DataSeedAsync(IServiceProvider service)
+ {
+ var dataSeeder = service.GetRequiredService();
+ await dataSeeder.SeedAsync();
+ }
}
\ No newline at end of file
diff --git a/framework/NPin.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs b/framework/NPin.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
index 8255279..4f451d6 100644
--- a/framework/NPin.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
+++ b/framework/NPin.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
@@ -1,430 +1,431 @@
-using System.Linq.Expressions;
-using NPin.Framework.Core.Helper;
-using NPin.Framework.SqlSugarCore.Abstractions;
-using SqlSugar;
-using Volo.Abp;
-using Volo.Abp.Domain.Entities;
-using Volo.Abp.Domain.Repositories;
-using Volo.Abp.Linq;
-
-namespace NPin.Framework.SqlSugarCore.Repositories;
-
-public class SqlSugarRepository : ISqlSugarRepository, IRepository
- where TEntity : class, IEntity, new()
-{
- public ISqlSugarClient Db => GetDbContextAsync().Result;
-
- public ISugarQueryable DbQueryable => GetDbContextAsync().Result.Queryable();
-
- private ISugarDbContextProvider _sugarDbContextProvider;
- public IAsyncQueryableExecuter AsyncExecuter { get; }
-
- public bool? IsChangeTrackingEnabled => false;
-
- public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider)
- {
- _sugarDbContextProvider = sugarDbContextProvider;
- }
-
- public virtual async Task GetDbContextAsync()
- {
- var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
- return db;
- }
-
- public virtual async Task> GetDbSimpleClientAsync()
- {
- var db = await GetDbContextAsync();
- return new SimpleClient(db);
- }
-
- #region Abp模块
-
- public virtual async Task FindAsync(Expression> predicate, bool includeDetails = true,
- CancellationToken cancellationToken = default)
- {
- return await GetFirstAsync(predicate);
- }
-
- public virtual async Task GetAsync(Expression> predicate, bool includeDetails = true,
- CancellationToken cancellationToken = default)
- {
- return await GetFirstAsync(predicate);
- }
-
- public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await this.DeleteAsync(predicate);
- }
-
- public virtual async Task DeleteDirectAsync(Expression> predicate,
- CancellationToken cancellationToken = default)
- {
- await this.DeleteAsync(predicate);
- }
-
- public IQueryable WithDetails()
- {
- throw new NotImplementedException();
- }
-
- public IQueryable WithDetails(params Expression>[] propertySelectors)
- {
- throw new NotImplementedException();
- }
-
- public Task> WithDetailsAsync()
- {
- throw new NotImplementedException();
- }
-
- public Task> WithDetailsAsync(params Expression>[] propertySelectors)
- {
- throw new NotImplementedException();
- }
-
- public Task> GetQueryableAsync()
- {
- throw new NotImplementedException();
- }
-
- public virtual async Task> GetListAsync(Expression> predicate,
- bool includeDetails = false, CancellationToken cancellationToken = default)
- {
- return await GetListAsync(predicate);
- }
-
- public virtual async Task InsertAsync(TEntity entity, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- return await InsertReturnEntityAsync(entity);
- }
-
- public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await InsertRangeAsync(entities.ToList());
- }
-
- public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await UpdateAsync(entity);
- return entity;
- }
-
- public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await UpdateRangeAsync(entities.ToList());
- }
-
- public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await DeleteAsync(entity);
- }
-
- public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await DeleteAsync(entities.ToList());
- }
-
- public virtual async Task> GetListAsync(bool includeDetails = false,
- CancellationToken cancellationToken = default)
- {
- return await GetListAsync();
- }
-
- public virtual async Task GetCountAsync(CancellationToken cancellationToken = default)
- {
- return await this.CountAsync();
- }
-
- public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting,
- bool includeDetails = false, CancellationToken cancellationToken = default)
- {
- return await GetPageListAsync(_ => true, skipCount, maxResultCount);
- }
-
- #endregion
-
- #region 内置DB快捷操作
-
- public virtual async Task> AsDeleteable()
- {
- return (await GetDbSimpleClientAsync()).AsDeleteable();
- }
-
- public virtual async Task> AsInsertable(List insertObjs)
- {
- return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
- }
-
- public virtual async Task> AsInsertable(TEntity insertObj)
- {
- return (await GetDbSimpleClientAsync()).AsInsertable(insertObj);
- }
-
- public virtual async Task> AsInsertable(TEntity[] insertObjs)
- {
- return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
- }
-
- public virtual async Task> AsQueryable()
- {
- return (await GetDbSimpleClientAsync()).AsQueryable();
- }
-
- public virtual async Task AsSugarClient()
- {
- return (await GetDbSimpleClientAsync()).AsSugarClient();
- }
-
- public virtual async Task AsTenant()
- {
- return (await GetDbSimpleClientAsync()).AsTenant();
- }
-
- public virtual async Task> AsUpdateable(List updateObjs)
- {
- return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
- }
-
- public virtual async Task> AsUpdateable(TEntity updateObj)
- {
- return (await GetDbSimpleClientAsync()).AsUpdateable(updateObj);
- }
-
- public virtual async Task> AsUpdateable()
- {
- return (await GetDbSimpleClientAsync()).AsUpdateable();
- }
-
- public virtual async Task> AsUpdateable(TEntity[] updateObjs)
- {
- return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
- }
-
- #endregion
-
- #region SimpleClient模块
-
- public virtual async Task CountAsync(Expression> whereExpression)
- {
- return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression);
- }
-
- public virtual async Task DeleteAsync(TEntity deleteObj)
- {
- if (deleteObj is ISoftDelete)
- {
- ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, deleteObj);
- return await (await GetDbSimpleClientAsync()).UpdateAsync(deleteObj);
- }
- else
- {
- return await (await GetDbSimpleClientAsync()).DeleteAsync(deleteObj);
- }
- }
-
- public virtual async Task DeleteAsync(List deleteObjs)
- {
- if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
- {
- deleteObjs.ForEach(e => ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
- return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(deleteObjs);
- }
- else
- {
- return await (await GetDbSimpleClientAsync()).DeleteAsync(deleteObjs);
- }
- }
-
- public virtual async Task DeleteAsync(Expression> whereExpression)
- {
- if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
- {
- return await (await GetDbSimpleClientAsync()).AsUpdateable().SetColumns(nameof(ISoftDelete), true)
- .Where(whereExpression).ExecuteCommandAsync() > 0;
- }
- else
- {
- return await (await GetDbSimpleClientAsync()).DeleteAsync(whereExpression);
- }
- }
-
- public virtual async Task DeleteByIdAsync(dynamic id)
- {
- if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
- {
- var entity = await GetByIdAsync(id);
- //反射赋值
- ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, entity);
- return await UpdateAsync(entity);
- }
- else
- {
- return await (await GetDbSimpleClientAsync()).DeleteByIdAsync(id);
- }
- }
-
- public virtual async Task DeleteByIdsAsync(dynamic[] ids)
- {
- if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
- {
- var simpleClient = (await GetDbSimpleClientAsync());
- var entities = await simpleClient.AsQueryable().In(ids).ToListAsync();
- if (entities.Count == 0)
- {
- return false;
- }
-
- // 反射赋值
- entities.ForEach(e => ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
- return await UpdateRangeAsync(entities);
- }
- else
- {
- return await (await GetDbSimpleClientAsync()).DeleteByIdAsync(ids);
- }
- }
-
- public virtual async Task GetByIdAsync(dynamic id)
- {
- return await (await GetDbSimpleClientAsync()).GetByIdAsync(id);
- }
-
-
- public virtual async Task GetFirstAsync(Expression> whereExpression)
- {
- return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression);
- }
-
- public virtual async Task> GetListAsync()
- {
- return await (await GetDbSimpleClientAsync()).GetListAsync();
- }
-
- public virtual async Task> GetListAsync(Expression> whereExpression)
- {
- return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression);
- }
-
- public virtual async Task> GetPageListAsync(Expression> whereExpression,
- int pageNum, int pageSize)
- {
- return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression,
- new PageModel() { PageIndex = pageNum, PageSize = pageSize });
- }
-
- public virtual async Task> GetPageListAsync(Expression> whereExpression,
- int pageNum, int pageSize,
- Expression>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
- {
- return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression,
- new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType);
- }
-
- public virtual async Task GetSingleAsync(Expression> whereExpression)
- {
- return await (await GetDbSimpleClientAsync()).GetSingleAsync(whereExpression);
- }
-
- public virtual async Task InsertAsync(TEntity insertObj)
- {
- return await (await GetDbSimpleClientAsync()).InsertAsync(insertObj);
- }
-
- public virtual async Task InsertOrUpdateAsync(TEntity data)
- {
- return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(data);
- }
-
- public virtual async Task InsertOrUpdateAsync(List datas)
- {
- return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(datas);
- }
-
- public virtual async Task InsertRangeAsync(List insertObjs)
- {
- return await (await GetDbSimpleClientAsync()).InsertRangeAsync(insertObjs);
- }
-
- public virtual async Task InsertReturnBigIdentityAsync(TEntity insertObj)
- {
- return await (await GetDbSimpleClientAsync()).InsertReturnBigIdentityAsync(insertObj);
- }
-
- public virtual async Task InsertReturnEntityAsync(TEntity insertObj)
- {
- return await (await GetDbSimpleClientAsync()).InsertReturnEntityAsync(insertObj);
- }
-
- public virtual async Task InsertReturnIdentityAsync(TEntity insertObj)
- {
- return await (await GetDbSimpleClientAsync()).InsertReturnIdentityAsync(insertObj);
- }
-
- public virtual async Task InsertReturnSnowflakeIdAsync(TEntity insertObj)
- {
- return await (await GetDbSimpleClientAsync()).InsertReturnSnowflakeIdAsync(insertObj);
- }
-
- public virtual async Task IsAnyAsync(Expression> whereExpression)
- {
- return await (await GetDbSimpleClientAsync()).IsAnyAsync(whereExpression);
- }
-
- public virtual async Task UpdateAsync(TEntity updateObj)
- {
- return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj);
- }
-
- public virtual async Task UpdateAsync(Expression> columns,
- Expression> whereExpression)
- {
- return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression);
- }
-
- public virtual async Task UpdateRangeAsync(List updateObjs)
- {
- return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(updateObjs);
- }
-
- #endregion
-}
-
-public class SqlSugarRepository : SqlSugarRepository, ISqlSugarRepository,
- IRepository where TEntity : class, IEntity, new()
-{
- public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider) : base(
- sugarDbContextProvider)
- {
- }
-
- public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
- {
- await DeleteByIdAsync(id);
- }
-
- public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false,
- CancellationToken cancellationToken = default)
- {
- await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray());
- }
-
- public virtual async Task FindAsync(TKey id, bool includeDetails = true,
- CancellationToken cancellationToken = default)
- {
- return await GetByIdAsync(id);
- }
-
- public virtual async Task GetAsync(TKey id, bool includeDetails = true,
- CancellationToken cancellationToken = default)
- {
- return await GetByIdAsync(id);
- }
+using System.Linq.Expressions;
+using NPin.Framework.Core.Helper;
+using NPin.Framework.SqlSugarCore.Abstractions;
+using SqlSugar;
+using Volo.Abp;
+using Volo.Abp.Domain.Entities;
+using Volo.Abp.Domain.Repositories;
+using Volo.Abp.Linq;
+
+namespace NPin.Framework.SqlSugarCore.Repositories;
+
+public class SqlSugarRepository : ISqlSugarRepository, IRepository
+ where TEntity : class, IEntity, new()
+{
+ public ISqlSugarClient Db => GetDbContextAsync().Result;
+
+ public ISugarQueryable DbQueryable => GetDbContextAsync().Result.Queryable();
+
+ private ISugarDbContextProvider _sugarDbContextProvider;
+ public IAsyncQueryableExecuter AsyncExecuter { get; }
+
+ public bool? IsChangeTrackingEnabled => false;
+
+ public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider)
+ {
+ _sugarDbContextProvider = sugarDbContextProvider;
+ }
+
+ public virtual async Task GetDbContextAsync()
+ {
+ var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
+ // await Console.Out.WriteLineAsync("获取的id:" + db.ContextID);
+ return db;
+ }
+
+ public virtual async Task> GetDbSimpleClientAsync()
+ {
+ var db = await GetDbContextAsync();
+ return new SimpleClient(db);
+ }
+
+ #region Abp模块
+
+ public virtual async Task FindAsync(Expression> predicate, bool includeDetails = true,
+ CancellationToken cancellationToken = default)
+ {
+ return await GetFirstAsync(predicate);
+ }
+
+ public virtual async Task GetAsync(Expression> predicate, bool includeDetails = true,
+ CancellationToken cancellationToken = default)
+ {
+ return await GetFirstAsync(predicate);
+ }
+
+ public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await this.DeleteAsync(predicate);
+ }
+
+ public virtual async Task DeleteDirectAsync(Expression> predicate,
+ CancellationToken cancellationToken = default)
+ {
+ await this.DeleteAsync(predicate);
+ }
+
+ public IQueryable WithDetails()
+ {
+ throw new NotImplementedException();
+ }
+
+ public IQueryable WithDetails(params Expression>[] propertySelectors)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task> WithDetailsAsync()
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task> WithDetailsAsync(params Expression>[] propertySelectors)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Task> GetQueryableAsync()
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual async Task> GetListAsync(Expression> predicate,
+ bool includeDetails = false, CancellationToken cancellationToken = default)
+ {
+ return await GetListAsync(predicate);
+ }
+
+ public virtual async Task InsertAsync(TEntity entity, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ return await InsertReturnEntityAsync(entity);
+ }
+
+ public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await InsertRangeAsync(entities.ToList());
+ }
+
+ public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await UpdateAsync(entity);
+ return entity;
+ }
+
+ public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await UpdateRangeAsync(entities.ToList());
+ }
+
+ public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await DeleteAsync(entity);
+ }
+
+ public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await DeleteAsync(entities.ToList());
+ }
+
+ public virtual async Task> GetListAsync(bool includeDetails = false,
+ CancellationToken cancellationToken = default)
+ {
+ return await GetListAsync();
+ }
+
+ public virtual async Task GetCountAsync(CancellationToken cancellationToken = default)
+ {
+ return await this.CountAsync();
+ }
+
+ public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting,
+ bool includeDetails = false, CancellationToken cancellationToken = default)
+ {
+ return await GetPageListAsync(_ => true, skipCount, maxResultCount);
+ }
+
+ #endregion
+
+ #region 内置DB快捷操作
+
+ public virtual async Task> AsDeleteable()
+ {
+ return (await GetDbSimpleClientAsync()).AsDeleteable();
+ }
+
+ public virtual async Task> AsInsertable(List insertObjs)
+ {
+ return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
+ }
+
+ public virtual async Task> AsInsertable(TEntity insertObj)
+ {
+ return (await GetDbSimpleClientAsync()).AsInsertable(insertObj);
+ }
+
+ public virtual async Task> AsInsertable(TEntity[] insertObjs)
+ {
+ return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
+ }
+
+ public virtual async Task> AsQueryable()
+ {
+ return (await GetDbSimpleClientAsync()).AsQueryable();
+ }
+
+ public virtual async Task AsSugarClient()
+ {
+ return (await GetDbSimpleClientAsync()).AsSugarClient();
+ }
+
+ public virtual async Task AsTenant()
+ {
+ return (await GetDbSimpleClientAsync()).AsTenant();
+ }
+
+ public virtual async Task> AsUpdateable(List updateObjs)
+ {
+ return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
+ }
+
+ public virtual async Task> AsUpdateable(TEntity updateObj)
+ {
+ return (await GetDbSimpleClientAsync()).AsUpdateable(updateObj);
+ }
+
+ public virtual async Task> AsUpdateable()
+ {
+ return (await GetDbSimpleClientAsync()).AsUpdateable();
+ }
+
+ public virtual async Task> AsUpdateable(TEntity[] updateObjs)
+ {
+ return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
+ }
+
+ #endregion
+
+ #region SimpleClient模块
+
+ public virtual async Task CountAsync(Expression> whereExpression)
+ {
+ return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression);
+ }
+
+ public virtual async Task DeleteAsync(TEntity deleteObj)
+ {
+ if (deleteObj is ISoftDelete)
+ {
+ ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, deleteObj);
+ return await (await GetDbSimpleClientAsync()).UpdateAsync(deleteObj);
+ }
+ else
+ {
+ return await (await GetDbSimpleClientAsync()).DeleteAsync(deleteObj);
+ }
+ }
+
+ public virtual async Task DeleteAsync(List deleteObjs)
+ {
+ if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
+ {
+ deleteObjs.ForEach(e => ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
+ return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(deleteObjs);
+ }
+ else
+ {
+ return await (await GetDbSimpleClientAsync()).DeleteAsync(deleteObjs);
+ }
+ }
+
+ public virtual async Task DeleteAsync(Expression> whereExpression)
+ {
+ if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
+ {
+ return await (await GetDbSimpleClientAsync()).AsUpdateable().SetColumns(nameof(ISoftDelete), true)
+ .Where(whereExpression).ExecuteCommandAsync() > 0;
+ }
+ else
+ {
+ return await (await GetDbSimpleClientAsync()).DeleteAsync(whereExpression);
+ }
+ }
+
+ public virtual async Task DeleteByIdAsync(dynamic id)
+ {
+ if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
+ {
+ var entity = await GetByIdAsync(id);
+ //反射赋值
+ ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, entity);
+ return await UpdateAsync(entity);
+ }
+ else
+ {
+ return await (await GetDbSimpleClientAsync()).DeleteByIdAsync(id);
+ }
+ }
+
+ public virtual async Task DeleteByIdsAsync(dynamic[] ids)
+ {
+ if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
+ {
+ var simpleClient = (await GetDbSimpleClientAsync());
+ var entities = await simpleClient.AsQueryable().In(ids).ToListAsync();
+ if (entities.Count == 0)
+ {
+ return false;
+ }
+
+ // 反射赋值
+ entities.ForEach(e => ReflectHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
+ return await UpdateRangeAsync(entities);
+ }
+ else
+ {
+ return await (await GetDbSimpleClientAsync()).DeleteByIdAsync(ids);
+ }
+ }
+
+ public virtual async Task GetByIdAsync(dynamic id)
+ {
+ return await (await GetDbSimpleClientAsync()).GetByIdAsync(id);
+ }
+
+
+ public virtual async Task GetFirstAsync(Expression> whereExpression)
+ {
+ return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression);
+ }
+
+ public virtual async Task> GetListAsync()
+ {
+ return await (await GetDbSimpleClientAsync()).GetListAsync();
+ }
+
+ public virtual async Task> GetListAsync(Expression> whereExpression)
+ {
+ return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression);
+ }
+
+ public virtual async Task> GetPageListAsync(Expression> whereExpression,
+ int pageNum, int pageSize)
+ {
+ return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression,
+ new PageModel() { PageIndex = pageNum, PageSize = pageSize });
+ }
+
+ public virtual async Task> GetPageListAsync(Expression> whereExpression,
+ int pageNum, int pageSize,
+ Expression>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
+ {
+ return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression,
+ new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType);
+ }
+
+ public virtual async Task GetSingleAsync(Expression> whereExpression)
+ {
+ return await (await GetDbSimpleClientAsync()).GetSingleAsync(whereExpression);
+ }
+
+ public virtual async Task InsertAsync(TEntity insertObj)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertAsync(insertObj);
+ }
+
+ public virtual async Task InsertOrUpdateAsync(TEntity data)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(data);
+ }
+
+ public virtual async Task InsertOrUpdateAsync(List datas)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(datas);
+ }
+
+ public virtual async Task InsertRangeAsync(List insertObjs)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertRangeAsync(insertObjs);
+ }
+
+ public virtual async Task InsertReturnBigIdentityAsync(TEntity insertObj)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertReturnBigIdentityAsync(insertObj);
+ }
+
+ public virtual async Task InsertReturnEntityAsync(TEntity insertObj)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertReturnEntityAsync(insertObj);
+ }
+
+ public virtual async Task InsertReturnIdentityAsync(TEntity insertObj)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertReturnIdentityAsync(insertObj);
+ }
+
+ public virtual async Task InsertReturnSnowflakeIdAsync(TEntity insertObj)
+ {
+ return await (await GetDbSimpleClientAsync()).InsertReturnSnowflakeIdAsync(insertObj);
+ }
+
+ public virtual async Task IsAnyAsync(Expression> whereExpression)
+ {
+ return await (await GetDbSimpleClientAsync()).IsAnyAsync(whereExpression);
+ }
+
+ public virtual async Task UpdateAsync(TEntity updateObj)
+ {
+ return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj);
+ }
+
+ public virtual async Task UpdateAsync(Expression> columns,
+ Expression> whereExpression)
+ {
+ return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression);
+ }
+
+ public virtual async Task UpdateRangeAsync(List updateObjs)
+ {
+ return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(updateObjs);
+ }
+
+ #endregion
+}
+
+public class SqlSugarRepository : SqlSugarRepository, ISqlSugarRepository,
+ IRepository where TEntity : class, IEntity, new()
+{
+ public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider) : base(
+ sugarDbContextProvider)
+ {
+ }
+
+ public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
+ {
+ await DeleteByIdAsync(id);
+ }
+
+ public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false,
+ CancellationToken cancellationToken = default)
+ {
+ await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray());
+ }
+
+ public virtual async Task FindAsync(TKey id, bool includeDetails = true,
+ CancellationToken cancellationToken = default)
+ {
+ return await GetByIdAsync(id);
+ }
+
+ public virtual async Task GetAsync(TKey id, bool includeDetails = true,
+ CancellationToken cancellationToken = default)
+ {
+ return await GetByIdAsync(id);
+ }
}
\ No newline at end of file
diff --git a/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs b/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs
index a88b6a5..2a95709 100644
--- a/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs
+++ b/framework/NPin.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs
@@ -1,117 +1,124 @@
-using System.Reflection;
-using Microsoft.Extensions.Options;
-using NPin.Framework.SqlSugarCore.Abstractions;
-using SqlSugar;
-using Volo.Abp.Data;
-using Volo.Abp.DependencyInjection;
-
-namespace NPin.Framework.SqlSugarCore;
-
-public class SqlSugarDbConnectionCreator : ISqlSugarDbConnectionCreator, ITransientDependency
-{
- [DisablePropertyInjection] public Action OnSqlSugarClientConfig { get; set; }
-
- [DisablePropertyInjection] public Action