|
@@ -5,15 +5,17 @@ using XF.Domain.Repository;
|
|
|
|
|
|
namespace Hotline.Repository.SqlSugar
|
|
|
{
|
|
|
- public abstract class BaseRepository<TEntity> : IRepository<TEntity> where TEntity : class, IEntity<string>, IHasCreationTime, new()
|
|
|
+ public abstract class BaseRepository<TEntity> : IRepository<TEntity> where TEntity : class, IEntity<string>, IHasCreationTime, IDataPermission, new()
|
|
|
{
|
|
|
+ private readonly IDataPermissionFilterBuilder _dataPermissionFilterBuilder;
|
|
|
protected ISugarUnitOfWork<HotlineDbContext> Uow { get; }
|
|
|
protected ISqlSugarClient Db { get; }
|
|
|
|
|
|
- public BaseRepository(ISugarUnitOfWork<HotlineDbContext> uow)
|
|
|
+ public BaseRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder)
|
|
|
{
|
|
|
Uow = uow;
|
|
|
Db = uow.Db;
|
|
|
+ _dataPermissionFilterBuilder = dataPermissionFilterBuilder;
|
|
|
}
|
|
|
|
|
|
public async Task<string> AddAsync(TEntity entity, CancellationToken cancellationToken = default)
|
|
@@ -129,16 +131,21 @@ namespace Hotline.Repository.SqlSugar
|
|
|
/// <param name="orderByCreator"></param>
|
|
|
/// <param name="pageIndex"></param>
|
|
|
/// <param name="pageSize"></param>
|
|
|
+ /// <param name="permissionVerify"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<(int Total, List<TEntity> Items)> QueryPagedAsync(
|
|
|
Expression<Func<TEntity, bool>> predicate,
|
|
|
Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> orderByCreator,
|
|
|
int pageIndex,
|
|
|
int pageSize,
|
|
|
+ bool permissionVerify = false,
|
|
|
params (bool isWhere, Expression<Func<TEntity, bool>> expression)[] whereIfs)
|
|
|
{
|
|
|
RefAsync<int> total = 0;
|
|
|
var query = Db.Queryable<TEntity>().Where(predicate);
|
|
|
+ if (permissionVerify)
|
|
|
+ query = query.DataPermissionFiltering(_dataPermissionFilterBuilder);
|
|
|
+
|
|
|
if (whereIfs.Any())
|
|
|
{
|
|
|
foreach (var whereIf in whereIfs)
|
|
@@ -151,16 +158,20 @@ namespace Hotline.Repository.SqlSugar
|
|
|
}
|
|
|
|
|
|
public async Task<List<TEntity>> QueryExtAsync(
|
|
|
- Expression<Func<TEntity, bool>> predicate,
|
|
|
- Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>>? includes = null,
|
|
|
+ Expression<Func<TEntity, bool>> predicate,
|
|
|
+ Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>>? includes = null,
|
|
|
Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>>? orderByCreator = null,
|
|
|
+ bool permissionVerify = false,
|
|
|
params (bool isWhere, Expression<Func<TEntity, bool>> expression)[] whereIfs)
|
|
|
{
|
|
|
var query = Db.Queryable<TEntity>().Where(predicate);
|
|
|
+ if (permissionVerify)
|
|
|
+ query = query.DataPermissionFiltering(_dataPermissionFilterBuilder);
|
|
|
+
|
|
|
if (includes is not null)
|
|
|
query = includes(query);
|
|
|
-
|
|
|
- if(whereIfs.Any())
|
|
|
+
|
|
|
+ if (whereIfs.Any())
|
|
|
{
|
|
|
foreach (var whereIf in whereIfs)
|
|
|
{
|
|
@@ -174,23 +185,35 @@ namespace Hotline.Repository.SqlSugar
|
|
|
return await query.ToListAsync();
|
|
|
}
|
|
|
|
|
|
- public async Task<List<TEntity>> QueryExtAsync(Expression<Func<TEntity, bool>> predicate, Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> includes)
|
|
|
+ public async Task<List<TEntity>> QueryExtAsync(
|
|
|
+ Expression<Func<TEntity, bool>> predicate,
|
|
|
+ Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> includes,
|
|
|
+ bool permissionVerify = false)
|
|
|
{
|
|
|
var query = Db.Queryable<TEntity>().Where(predicate);
|
|
|
+ if (permissionVerify)
|
|
|
+ query = query.DataPermissionFiltering(_dataPermissionFilterBuilder);
|
|
|
query = includes(query);
|
|
|
return await query.ToListAsync();
|
|
|
}
|
|
|
|
|
|
- public async Task<TEntity> GetExtAsync(Expression<Func<TEntity, bool>> predicate, Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> includes)
|
|
|
+ public async Task<TEntity> GetExtAsync(
|
|
|
+ Expression<Func<TEntity, bool>> predicate,
|
|
|
+ Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> includes,
|
|
|
+ bool permissionVerify = false)
|
|
|
{
|
|
|
var query = Db.Queryable<TEntity>();
|
|
|
+ if (permissionVerify)
|
|
|
+ query = query.DataPermissionFiltering(_dataPermissionFilterBuilder);
|
|
|
query = includes(query);
|
|
|
return await query.FirstAsync(predicate);
|
|
|
}
|
|
|
|
|
|
- public async Task<TEntity> GetExtAsync(string id, Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> includes)
|
|
|
+ public async Task<TEntity> GetExtAsync(string id, Func<ISugarQueryable<TEntity>, ISugarQueryable<TEntity>> includes, bool permissionVerify = false)
|
|
|
{
|
|
|
var query = Db.Queryable<TEntity>();
|
|
|
+ if (permissionVerify)
|
|
|
+ query = query.DataPermissionFiltering(_dataPermissionFilterBuilder);
|
|
|
query = includes(query);
|
|
|
return await query.FirstAsync(d => d.Id == id);
|
|
|
}
|