feat:全基础流程跑通
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Data.Filters
|
||||
{
|
||||
public class DefaultDataFilter : IDataFilter
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public DefaultDataFilter(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IDisposable Disable<TFilter>() where TFilter : class
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public IDisposable Enable<TFilter>() where TFilter : class
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public bool IsEnabled<TFilter>() where TFilter : class
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveFilter<TFilter>() where TFilter : class
|
||||
{
|
||||
}
|
||||
public void RemoveAndBackup<TFilter>() where TFilter : class
|
||||
{
|
||||
}
|
||||
|
||||
public void AddFilter<TFilter>(Expression<Func<TFilter, bool>> expression) where TFilter : class
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Data.Filters
|
||||
{
|
||||
public interface IDataFilter : IDisposable
|
||||
{
|
||||
IDisposable Enable<TFilter>() where TFilter : class;
|
||||
|
||||
IDisposable Disable<TFilter>() where TFilter : class;
|
||||
|
||||
bool IsEnabled<TFilter>() where TFilter : class;
|
||||
|
||||
void AddFilter<TFilter>(Expression<Func<TFilter, bool>> expression) where TFilter : class;
|
||||
|
||||
void RemoveFilter<TFilter>() where TFilter : class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -77,6 +77,7 @@ where TEntityDto : IEntityDto<TKey>
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[Route("")]
|
||||
public virtual async Task<PagedResultDto<TGetListOutputDto>> GetListAsync([FromQuery]TGetListInput input)
|
||||
{
|
||||
var totalCount = -1;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Linq.Expressions;
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Infrastructure.Data.Filters;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Sqlsugar.Filters
|
||||
{
|
||||
public class SqlsugarDataFilter : IDataFilter
|
||||
{
|
||||
private ISqlSugarClient _Db { get; set; }
|
||||
public SqlsugarDataFilter(ISqlSugarClient sqlSugarClient)
|
||||
{
|
||||
_Db = sqlSugarClient;
|
||||
}
|
||||
public void AddFilter<TFilter>(Expression<Func<TFilter, bool>> expression) where TFilter : class
|
||||
{
|
||||
_Db.QueryFilter.AddTableFilter(expression);
|
||||
}
|
||||
|
||||
public IDisposable Disable<TFilter>() where TFilter : class
|
||||
{
|
||||
_Db.QueryFilter.ClearAndBackup<TFilter>();
|
||||
return this;
|
||||
}
|
||||
|
||||
public IDisposable Enable<TFilter>() where TFilter : class
|
||||
{
|
||||
throw new NotImplementedException("暂时没有单独还原过滤器的方式");
|
||||
}
|
||||
|
||||
public bool IsEnabled<TFilter>() where TFilter : class
|
||||
{
|
||||
throw new NotImplementedException("暂时没有判断过滤器的方式");
|
||||
}
|
||||
|
||||
public void RemoveFilter<TFilter>() where TFilter : class
|
||||
{
|
||||
_Db.QueryFilter.Clear<TFilter>();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_Db.QueryFilter.Restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Infrastructure.CurrentUsers;
|
||||
using Yi.Framework.Infrastructure.Data.Auditing;
|
||||
using Yi.Framework.Infrastructure.Data.Entities;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Sqlsugar
|
||||
{
|
||||
@@ -83,45 +85,45 @@ namespace Yi.Framework.Infrastructure.Sqlsugar
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
|
||||
//switch (entityInfo.OperationType)
|
||||
//{
|
||||
// case DataFilterType.UpdateByObject:
|
||||
switch (entityInfo.OperationType)
|
||||
{
|
||||
case DataFilterType.UpdateByObject:
|
||||
|
||||
// if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime)))
|
||||
// {
|
||||
// entityInfo.SetValue(DateTime.Now);
|
||||
// }
|
||||
// if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModifierId)))
|
||||
// {
|
||||
// if (_currentUser != null)
|
||||
// {
|
||||
// entityInfo.SetValue(_currentUser.Id);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case DataFilterType.InsertByObject:
|
||||
// if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreationTime)))
|
||||
// {
|
||||
// entityInfo.SetValue(DateTime.Now);
|
||||
// }
|
||||
// if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreatorId)))
|
||||
// {
|
||||
// if (_currentUser != null)
|
||||
// {
|
||||
// entityInfo.SetValue(_currentUser.Id);
|
||||
// }
|
||||
// }
|
||||
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime)))
|
||||
{
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModifierId)))
|
||||
{
|
||||
if (_currentUser != null)
|
||||
{
|
||||
entityInfo.SetValue(_currentUser.Id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DataFilterType.InsertByObject:
|
||||
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreationTime)))
|
||||
{
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreatorId)))
|
||||
{
|
||||
if (_currentUser != null)
|
||||
{
|
||||
entityInfo.SetValue(_currentUser.Id);
|
||||
}
|
||||
}
|
||||
|
||||
// //插入时,需要租户id,先预留
|
||||
// if (entityInfo.PropertyName.Equals(nameof(IMultiTenant.TenantId)))
|
||||
// {
|
||||
// //if (this.CurrentTenant is not null)
|
||||
// //{
|
||||
// // entityInfo.SetValue(this.CurrentTenant.Id);
|
||||
// //}
|
||||
// }
|
||||
// break;
|
||||
//}
|
||||
//插入时,需要租户id,先预留
|
||||
if (entityInfo.PropertyName.Equals(nameof(IMultiTenant.TenantId)))
|
||||
{
|
||||
//if (this.CurrentTenant is not null)
|
||||
//{
|
||||
// entityInfo.SetValue(this.CurrentTenant.Id);
|
||||
//}
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
db.Aop.OnLogExecuting = (s, p) =>
|
||||
{
|
||||
|
||||
@@ -3,8 +3,11 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using StackExchange.Profiling.SqlFormatters;
|
||||
using Yi.Framework.Infrastructure.AspNetCore;
|
||||
using Yi.Framework.Infrastructure.Data.Filters;
|
||||
using Yi.Framework.Infrastructure.Sqlsugar;
|
||||
using Yi.Framework.Infrastructure.Sqlsugar.Filters;
|
||||
using Yi.Framework.Infrastructure.Sqlsugar.Uow;
|
||||
|
||||
namespace Yi.Framework.Infrastructure;
|
||||
@@ -20,6 +23,8 @@ public class Startup : AppStartup
|
||||
services.AddDbSqlsugarContextServer();
|
||||
|
||||
services.AddUnitOfWork<SqlsugarUnitOfWork>();
|
||||
|
||||
services.AddTransient<IDataFilter, SqlsugarDataFilter>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
|
||||
Reference in New Issue
Block a user