diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs new file mode 100644 index 00000000..dc5c06f1 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/ISqlSugarDbConnectionCreator.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; + +namespace Yi.Framework.SqlSugarCore.Abstractions +{ + public interface ISqlSugarDbConnectionCreator + { + DbConnOptions Options { get; } + Action OnSqlSugarClientConfig { get; set; } + Action DataExecuted { get; set; } + Action DataExecuting { get; set; } + Action OnLogExecuting { get; set; } + Action OnLogExecuted { get; set; } + Action EntityService { get; set; } + + ConnectionConfig Build(Action? action = null); + void SetDbAop(ISqlSugarClient currentDb); + } +} diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs new file mode 100644 index 00000000..d9b6be45 --- /dev/null +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbConnectionCreator.cs @@ -0,0 +1,110 @@ +using System.Reflection; +using Microsoft.Extensions.Options; +using SqlSugar; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Yi.Framework.SqlSugarCore.Abstractions; + +namespace Yi.Framework.SqlSugarCore +{ + + public class SqlSugarDbConnectionCreator: ISqlSugarDbConnectionCreator,ITransientDependency + { + public SqlSugarDbConnectionCreator(IOptions options) + { + Options = options.Value; + } + public DbConnOptions Options { get; } + + public void SetDbAop(ISqlSugarClient currentDb) + { + currentDb.Aop.OnLogExecuting = this.OnLogExecuting; + currentDb.Aop.OnLogExecuted = this.OnLogExecuted; + currentDb.Aop.DataExecuting = this.DataExecuting; + currentDb.Aop.DataExecuted = this.DataExecuted; + } + public ConnectionConfig Build(Action? action=null) + { + var dbConnOptions = Options; + #region 组装options + if (dbConnOptions.DbType is null) + { + throw new ArgumentException("DbType配置为空"); + } + var slavaConFig = new List(); + if (dbConnOptions.EnabledReadWrite) + { + if (dbConnOptions.ReadUrl is null) + { + throw new ArgumentException("读写分离为空"); + } + + var readCon = dbConnOptions.ReadUrl; + + readCon.ForEach(s => + { + //如果是动态saas分库,这里的连接串都不能写死,需要动态添加,这里只配置共享库的连接 + slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s }); + }); + } + #endregion + + #region 组装连接config + var connectionConfig = new ConnectionConfig() + { + ConfigId= ConnectionStrings.DefaultConnectionStringName, + DbType = dbConnOptions.DbType ?? DbType.Sqlite, + ConnectionString = dbConnOptions.Url, + IsAutoCloseConnection = true, + SlaveConnectionConfigs = slavaConFig, + //设置codefirst非空值判断 + ConfigureExternalServices = new ConfigureExternalServices + { + EntityService = (c, p) => + { + if (new NullabilityInfoContext() + .Create(c).WriteState is NullabilityState.Nullable) + { + p.IsNullable = true; + } + + EntityService(c, p); + } + }, + //这里多租户有个坑,无效的 + AopEvents = new AopEvents + { + DataExecuted = DataExecuted, + DataExecuting = DataExecuting, + OnLogExecuted = OnLogExecuted, + OnLogExecuting = OnLogExecuting + } + + }; + + if (action is not null) + { + action.Invoke(connectionConfig); + } + #endregion + return connectionConfig; + } + [DisablePropertyInjection] + public Action OnSqlSugarClientConfig { get; set; } + + [DisablePropertyInjection] + public Action DataExecuted { get; set; } + + [DisablePropertyInjection] + public Action DataExecuting { get; set; } + + [DisablePropertyInjection] + public Action OnLogExecuting { get; set; } + + [DisablePropertyInjection] + public Action OnLogExecuted { get; set; } + + [DisablePropertyInjection] + public Action EntityService { get; set; } + } +} diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs index 292c8662..435ba474 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs @@ -41,66 +41,20 @@ namespace Yi.Framework.SqlSugarCore public void SetSqlSugarClient(ISqlSugarClient sqlSugarClient) { - SqlSugarClient=sqlSugarClient; + SqlSugarClient = sqlSugarClient; } public SqlSugarDbContext(IAbpLazyServiceProvider lazyServiceProvider) { LazyServiceProvider = lazyServiceProvider; - var dbConnOptions = Options; - #region 组装options - if (dbConnOptions.DbType is null) - { - throw new ArgumentException("DbType配置为空"); - } - var slavaConFig = new List(); - if (dbConnOptions.EnabledReadWrite) - { - if (dbConnOptions.ReadUrl is null) - { - throw new ArgumentException("读写分离为空"); - } - - var readCon = dbConnOptions.ReadUrl; - - readCon.ForEach(s => - { - //如果是动态saas分库,这里的连接串都不能写死,需要动态添加,这里只配置共享库的连接 - slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s }); - }); - } - #endregion - SqlSugarClient = new SqlSugarClient(new ConnectionConfig() - { - //准备添加分表分库 - DbType = dbConnOptions.DbType ?? DbType.Sqlite, - ConnectionString = dbConnOptions.Url, - IsAutoCloseConnection = true, - SlaveConnectionConfigs = slavaConFig, - //设置codefirst非空值判断 - ConfigureExternalServices = new ConfigureExternalServices - { - EntityService = (c, p) => - { - if (new NullabilityInfoContext() - .Create(c).WriteState is NullabilityState.Nullable) - { - p.IsNullable = true; - } - - EntityService(c,p); - } - } - }, - db => - { - - db.Aop.DataExecuting = DataExecuting; - db.Aop.DataExecuted = DataExecuted; - db.Aop.OnLogExecuting = OnLogExecuting; - db.Aop.OnLogExecuted = OnLogExecuted; - //扩展 - OnSqlSugarClientConfig(db); - }); + var connectionCreator = LazyServiceProvider.LazyGetRequiredService(); + connectionCreator.OnSqlSugarClientConfig = OnSqlSugarClientConfig; + connectionCreator.EntityService = EntityService; + connectionCreator.DataExecuting = DataExecuting; + connectionCreator.DataExecuted = DataExecuted; + connectionCreator.OnLogExecuting = OnLogExecuting; + connectionCreator.OnLogExecuted = OnLogExecuted; + SqlSugarClient = new SqlSugarClient(connectionCreator.Build()); + connectionCreator.SetDbAop(SqlSugarClient); } /// @@ -248,14 +202,14 @@ namespace Yi.Framework.SqlSugarCore /// /// protected virtual void EntityService(PropertyInfo property, EntityColumnInfo column) - { - + { + } public void BackupDataBase() { string directoryName = "database_backup"; - string fileName = DateTime.Now.ToString($"yyyyMMdd_HHmmss")+ $"_{SqlSugarClient.Ado.Connection.Database}"; + string fileName = DateTime.Now.ToString($"yyyyMMdd_HHmmss") + $"_{SqlSugarClient.Ado.Connection.Database}"; if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); @@ -264,7 +218,7 @@ namespace Yi.Framework.SqlSugarCore { case DbType.MySql: //MySql - SqlSugarClient.DbMaintenance.BackupDataBase(SqlSugarClient.Ado.Connection.Database, $"{Path.Combine(directoryName, fileName) }.sql");//mysql 只支持.net core + SqlSugarClient.DbMaintenance.BackupDataBase(SqlSugarClient.Ado.Connection.Database, $"{Path.Combine(directoryName, fileName)}.sql");//mysql 只支持.net core break; diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlsugarCoreExtensions.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlsugarCoreExtensions.cs index 70fe0dd4..8facee27 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlsugarCoreExtensions.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlsugarCoreExtensions.cs @@ -16,6 +16,12 @@ namespace Yi.Framework.SqlSugarCore service.Replace(new ServiceDescriptor(typeof(ISqlSugarDbContext), typeof(DbContext), ServiceLifetime.Scoped)); return service; } + public static IServiceCollection TryAddYiDbContext(this IServiceCollection service) where DbContext : class, ISqlSugarDbContext + { + service.TryAdd(new ServiceDescriptor(typeof(ISqlSugarDbContext), typeof(DbContext), ServiceLifetime.Scoped)); + return service; + } + public static IServiceCollection AddYiDbContext(this IServiceCollection service,Action options) where DbContext : class, ISqlSugarDbContext { diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Uow/UnitOfWorkSqlsugarDbContextProvider.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Uow/UnitOfWorkSqlsugarDbContextProvider.cs index af319ea8..3b600607 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Uow/UnitOfWorkSqlsugarDbContextProvider.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Uow/UnitOfWorkSqlsugarDbContextProvider.cs @@ -18,6 +18,7 @@ namespace Yi.Framework.SqlSugarCore.Uow { public class UnitOfWorkSqlsugarDbContextProvider : ISugarDbContextProvider where TDbContext : ISqlSugarDbContext { + private readonly ISqlSugarDbConnectionCreator _dbConnectionCreator; private readonly string MasterTenantDbDefaultName = DbConnOptions.MasterTenantDbDefaultName; public ILogger> Logger { get; set; } @@ -30,7 +31,8 @@ namespace Yi.Framework.SqlSugarCore.Uow IUnitOfWorkManager unitOfWorkManager, IConnectionStringResolver connectionStringResolver, ICancellationTokenProvider cancellationTokenProvider, - ICurrentTenant currentTenant + ICurrentTenant currentTenant, + ISqlSugarDbConnectionCreator dbConnectionCreator ) { UnitOfWorkManager = unitOfWorkManager; @@ -38,6 +40,7 @@ namespace Yi.Framework.SqlSugarCore.Uow CancellationTokenProvider = cancellationTokenProvider; CurrentTenant = currentTenant; Logger = NullLogger>.Instance; + _dbConnectionCreator = dbConnectionCreator; } public virtual async Task GetDbContextAsync() @@ -72,7 +75,7 @@ namespace Yi.Framework.SqlSugarCore.Uow protected virtual async Task CreateDbContextAsync(IUnitOfWork unitOfWork, string connectionStringName, string connectionString) { - + var dbContext = await CreateDbContextAsync(unitOfWork); //没有检测到使用多租户功能,默认使用默认库即可 @@ -98,25 +101,36 @@ namespace Yi.Framework.SqlSugarCore.Uow { //直接切换 configId = MasterTenantDbDefaultName; - var conStrOrNull= dbOption.GetDefaultMasterSaasMultiTenancy(); - Volo.Abp.Check.NotNull(conStrOrNull,"租户主库未找到"); + var conStrOrNull = dbOption.GetDefaultMasterSaasMultiTenancy(); + Volo.Abp.Check.NotNull(conStrOrNull, "租户主库未找到"); connectionString = conStrOrNull.Url; } //租户Db的动态切换 //二级缓存 + var changed = false; if (!db.IsAnyConnection(configId)) { - //添加一个db到当前上下文 (Add部分不线上下文不会共享) - db.AddConnection(new ConnectionConfig() + var config = _dbConnectionCreator.Build(options => { - DbType = dbOption.DbType!.Value, - ConfigId = configId,//设置库的唯一标识 - IsAutoCloseConnection = true, - ConnectionString = connectionString + options.DbType = dbOption.DbType!.Value; + options.ConfigId = configId;//设置库的唯一标识 + options.IsAutoCloseConnection = true; + options.ConnectionString = connectionString; }); + //添加一个db到当前上下文 (Add部分不线上下文不会共享) + db.AddConnection(config); + changed = true; } var currentDb = db.GetConnection(configId) as ISqlSugarClient; + + //设置Aop + if (changed) + { + _dbConnectionCreator.SetDbAop(currentDb); + } + + dbContext.SetSqlSugarClient(currentDb); return dbContext; } diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs index 78201f19..7fc06665 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs @@ -13,7 +13,7 @@ namespace Yi.AuditLogging.SqlSugarCore public override void ConfigureServices(ServiceConfigurationContext context) { context.Services.Replace(new ServiceDescriptor(typeof(IAuditLogRepository), typeof(SqlSugarCoreAuditLogRepository), lifetime: ServiceLifetime.Transient)); - context.Services.AddYiDbContext(); + context.Services.TryAddYiDbContext(); } } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/BbsUserAnalyseService.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/BbsUserAnalyseService.cs index 1e453071..6f589811 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/BbsUserAnalyseService.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Services/Analyses/BbsUserAnalyseService.cs @@ -7,6 +7,7 @@ using Yi.Framework.Bbs.Application.Contracts.Dtos.BbsUser; using Yi.Framework.Bbs.Domain.Entities; using Yi.Framework.Bbs.Domain.Managers; using Yi.Framework.Rbac.Application.Contracts.IServices; +using Yi.Framework.Rbac.Domain.Authorization; using Yi.Framework.Rbac.Domain.Shared.Consts; using Yi.Framework.Rbac.Domain.Shared.Model; @@ -29,13 +30,16 @@ namespace Yi.Framework.Bbs.Application.Services.Analyses [HttpGet("analyse/bbs-user/random")] public async Task> GetRandomUserAsync([FromQuery] PagedResultRequestDto input) { - var randUserIds = await _bbsUserManager._userRepository._DbQueryable - //.Where(x => x.UserName != UserConst.Admin) + // using (DataFilter.DisablePermissionHandler()) + { + var randUserIds = await _bbsUserManager._userRepository._DbQueryable + //.Where(x => x.UserName != UserConst.Admin) .OrderBy(x => SqlFunc.GetRandom()) .Select(x => x.Id). ToPageListAsync(input.SkipCount, input.MaxResultCount); - var output = await _bbsUserManager.GetBbsUserInfoAsync(randUserIds); - return output.Adapt>(); + var output = await _bbsUserManager.GetBbsUserInfoAsync(randUserIds); + return output.Adapt>(); + } } /// @@ -45,14 +49,17 @@ namespace Yi.Framework.Bbs.Application.Services.Analyses [HttpGet("analyse/bbs-user/integral-top")] public async Task> GetIntegralTopUserAsync([FromQuery] PagedResultRequestDto input) { - var randUserIds = await _bbsUserManager._userRepository._DbQueryable - // .Where(user => user.UserName != UserConst.Admin) - .LeftJoin((user, info) => user.Id==info.UserId) - .OrderByDescending((user, info)=>info.Money) + // using (DataFilter.DisablePermissionHandler()) + { + var randUserIds = await _bbsUserManager._userRepository._DbQueryable + // .Where(user => user.UserName != UserConst.Admin) + .LeftJoin((user, info) => user.Id == info.UserId) + .OrderByDescending((user, info) => info.Money) .Select((user, info) => user.Id). ToPageListAsync(input.SkipCount, input.MaxResultCount); - var output = await _bbsUserManager.GetBbsUserInfoAsync(randUserIds); - return output.OrderByDescending(x=>x.Money).ToList().Adapt>(); + var output = await _bbsUserManager.GetBbsUserInfoAsync(randUserIds); + return output.OrderByDescending(x => x.Money).ToList().Adapt>(); + } } /// @@ -62,22 +69,24 @@ namespace Yi.Framework.Bbs.Application.Services.Analyses [HttpGet("analyse/bbs-user")] public async Task GetUserAnalyseAsync() { - - var registerUser = await _bbsUserManager._userRepository._DbQueryable.CountAsync(); + // using (DataFilter.DisablePermissionHandler()) + { + var registerUser = await _bbsUserManager._userRepository._DbQueryable.CountAsync(); - DateTime now = DateTime.Now; - DateTime yesterday = now.AddDays(-1); - DateTime startTime = new DateTime(yesterday.Year, yesterday.Month, yesterday.Day, 0, 0, 0); - DateTime endTime = startTime.AddHours(24); - var yesterdayNewUser = await _bbsUserManager._userRepository._DbQueryable - .Where(x => x.CreationTime >= startTime && x.CreationTime <= endTime).CountAsync(); + DateTime now = DateTime.Now; + DateTime yesterday = now.AddDays(-1); + DateTime startTime = new DateTime(yesterday.Year, yesterday.Month, yesterday.Day, 0, 0, 0); + DateTime endTime = startTime.AddHours(24); + var yesterdayNewUser = await _bbsUserManager._userRepository._DbQueryable + .Where(x => x.CreationTime >= startTime && x.CreationTime <= endTime).CountAsync(); - var userOnline = (await _onlineService.GetListAsync(new OnlineUserModel { })).TotalCount; + var userOnline = (await _onlineService.GetListAsync(new OnlineUserModel { })).TotalCount; - var output = new BbsUserAnalyseGetOutput() { OnlineNumber = userOnline, RegisterNumber = registerUser, YesterdayNewUser = yesterdayNewUser }; + var output = new BbsUserAnalyseGetOutput() { OnlineNumber = userOnline, RegisterNumber = registerUser, YesterdayNewUser = yesterdayNewUser }; - return output; + return output; + } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/LoginInputVo.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/LoginInputVo.cs index 2675531c..f412c342 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/LoginInputVo.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application.Contracts/Dtos/Account/LoginInputVo.cs @@ -5,8 +5,8 @@ public string UserName { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; - public string Uuid { get; set; } + public string? Uuid { get; set; } - public string Code { get; set; } + public string? Code { get; set; } } } diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Authorization/DataPermissionExtensions.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Authorization/DataPermissionExtensions.cs new file mode 100644 index 00000000..f8d6a6e7 --- /dev/null +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Authorization/DataPermissionExtensions.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Data; + +namespace Yi.Framework.Rbac.Domain.Authorization +{ + public static class DataPermissionExtensions + { + /// + /// 关闭数据权限 + /// + /// + /// + public static IDisposable DisablePermissionHandler(this IDataFilter dataFilter) + { + return dataFilter.Disable(); + } + } +} diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Authorization/IDataPermission.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Authorization/IDataPermission.cs new file mode 100644 index 00000000..cc01c66e --- /dev/null +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Authorization/IDataPermission.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Yi.Framework.Rbac.Domain.Authorization +{ + /// + /// 数据权限过滤接口 + /// + public interface IDataPermission + { + } +} diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiFrameworkRbacSqlSugarCoreModule.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiFrameworkRbacSqlSugarCoreModule.cs index 1c85803d..32936300 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiFrameworkRbacSqlSugarCoreModule.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiFrameworkRbacSqlSugarCoreModule.cs @@ -15,7 +15,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore { public override void ConfigureServices(ServiceConfigurationContext context) { - context.Services.AddYiDbContext(); + context.Services.TryAddYiDbContext(); } } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiRbacDbContext.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiRbacDbContext.cs index 6bd77d52..26465c0b 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiRbacDbContext.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.SqlSugarCore/YiRbacDbContext.cs @@ -1,5 +1,6 @@ using SqlSugar; using Volo.Abp.DependencyInjection; +using Yi.Framework.Rbac.Domain.Authorization; using Yi.Framework.Rbac.Domain.Entities; using Yi.Framework.Rbac.Domain.Extensions; using Yi.Framework.Rbac.Domain.Shared.Consts; @@ -16,8 +17,11 @@ namespace Yi.Framework.Rbac.SqlSugarCore protected override void CustomDataFilter(ISqlSugarClient sqlSugarClient) { - - DataPermissionFilter(sqlSugarClient); + if (DataFilter.IsEnabled()) + { + DataPermissionFilter(sqlSugarClient); + } + base.CustomDataFilter(sqlSugarClient); } @@ -42,7 +46,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore if (/*CurrentUser.GetDeptId() is null ||*/ roleInfo is null) { expUser.Or(it => it.Id == CurrentUser.Id); - expRole.Or(it => roleInfo.Select(x=>x.Id).Contains(it.Id)); + expRole.Or(it => roleInfo.Select(x => x.Id).Contains(it.Id)); } else { @@ -68,7 +72,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore //SQl OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) ) var allChildDepts = sqlSugarClient.Queryable().ToChildList(it => it.ParentId, CurrentUser.GetDeptId()); - expUser.Or(it => allChildDepts.Select(f => f.Id).ToList().Contains(it.DeptId??Guid.Empty)); + expUser.Or(it => allChildDepts.Select(f => f.Id).ToList().Contains(it.DeptId ?? Guid.Empty)); } else if (DataScopeEnum.USER.Equals(dataScope))//仅本人数据 { @@ -85,30 +89,5 @@ namespace Yi.Framework.Rbac.SqlSugarCore sqlSugarClient.QueryFilter.AddTableFilter(expUser.ToExpression()); sqlSugarClient.QueryFilter.AddTableFilter(expRole.ToExpression()); } - - protected override void DataExecuted(object oldValue, DataAfterModel entityInfo) - { - base.DataExecuted(oldValue, entityInfo); - } - - protected override void DataExecuting(object oldValue, DataFilterModel entityInfo) - { - base.DataExecuting(oldValue, entityInfo); - } - - protected override void OnLogExecuting(string sql, SugarParameter[] pars) - { - base.OnLogExecuting(sql, pars); - } - - protected override void OnLogExecuted(string sql, SugarParameter[] pars) - { - base.OnLogExecuted(sql, pars); - } - - protected override void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient) - { - base.OnSqlSugarClientConfig(sqlSugarClient); - } } } diff --git a/Yi.Abp.Net8/sample/Acme.BookStore.SqlSugarCore/YiDbContext.cs b/Yi.Abp.Net8/sample/Acme.BookStore.SqlSugarCore/YiDbContext.cs index e9c0dd7b..c119ddec 100644 --- a/Yi.Abp.Net8/sample/Acme.BookStore.SqlSugarCore/YiDbContext.cs +++ b/Yi.Abp.Net8/sample/Acme.BookStore.SqlSugarCore/YiDbContext.cs @@ -10,36 +10,5 @@ namespace Acme.BookStore.SqlSugarCore public YiDbContext(IAbpLazyServiceProvider lazyServiceProvider) : base(lazyServiceProvider) { } - - protected override void CustomDataFilter(ISqlSugarClient sqlSugarClient) - { - base.CustomDataFilter(sqlSugarClient); - } - - - protected override void DataExecuted(object oldValue, DataAfterModel entityInfo) - { - base.DataExecuted(oldValue, entityInfo); - } - - protected override void DataExecuting(object oldValue, DataFilterModel entityInfo) - { - base.DataExecuting(oldValue, entityInfo); - } - - protected override void OnLogExecuting(string sql, SugarParameter[] pars) - { - base.OnLogExecuting(sql, pars); - } - - protected override void OnLogExecuted(string sql, SugarParameter[] pars) - { - base.OnLogExecuted(sql, pars); - } - - protected override void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient) - { - base.OnSqlSugarClientConfig(sqlSugarClient); - } } } diff --git a/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiDbContext.cs b/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiDbContext.cs index b732354c..0e8404b5 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiDbContext.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiDbContext.cs @@ -9,36 +9,5 @@ namespace Yi.Abp.SqlSugarCore public YiDbContext(IAbpLazyServiceProvider lazyServiceProvider) : base(lazyServiceProvider) { } - - protected override void CustomDataFilter(ISqlSugarClient sqlSugarClient) - { - base.CustomDataFilter(sqlSugarClient); - } - - - protected override void DataExecuted(object oldValue, DataAfterModel entityInfo) - { - base.DataExecuted(oldValue, entityInfo); - } - - protected override void DataExecuting(object oldValue, DataFilterModel entityInfo) - { - base.DataExecuting(oldValue, entityInfo); - } - - protected override void OnLogExecuting(string sql, SugarParameter[] pars) - { - base.OnLogExecuting(sql, pars); - } - - protected override void OnLogExecuted(string sql, SugarParameter[] pars) - { - base.OnLogExecuted(sql, pars); - } - - protected override void OnSqlSugarClientConfig(ISqlSugarClient sqlSugarClient) - { - base.OnSqlSugarClientConfig(sqlSugarClient); - } } } diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs index 48832fce..0feeab19 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/Program.cs @@ -11,7 +11,7 @@ Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Async(c => c.File("logs/all/log-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Debug)) .WriteTo.Async(c => c.File("logs/error/errorlog-.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error)) -.WriteTo.Async(c => c.Console(restrictedToMinimumLevel: LogEventLevel.Information)) +.WriteTo.Async(c => c.Console()) .CreateLogger(); try