权限认证
This commit is contained in:
@@ -5,68 +5,11 @@ namespace Yi.Framework.Repository
|
||||
{
|
||||
public class DataContext<T> : SimpleClient<T> where T : class, new()
|
||||
{
|
||||
public DataContext(ISqlSugarClient context = null!) : base(context)
|
||||
public DataContext(ISqlSugarClient context) : base(context)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
base.Context = Db;
|
||||
}
|
||||
Db =base.Context;
|
||||
}
|
||||
/// <summary>
|
||||
/// SqlSugarScope操作数据库是线程安的可以单例
|
||||
/// </summary>
|
||||
public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig()
|
||||
{
|
||||
DbType = SqlSugar.DbType.MySql,
|
||||
//ConnectionString = Appsettings.app("ConnectionStrings", "mysqlConnection"),
|
||||
ConnectionString= "server=119.91.207.67;port=3306;database=yi-sqlsugar-dev;user id=root;password=Qz52013142020.",
|
||||
IsAutoCloseConnection = true
|
||||
},
|
||||
db =>
|
||||
{
|
||||
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
//var httpcontext = ServiceLocator.Instance.GetService<IHttpContextAccessor>().HttpContext;
|
||||
switch (entityInfo.OperationType)
|
||||
{
|
||||
case DataFilterType.InsertByObject:
|
||||
if (entityInfo.PropertyName == "CreateUser")
|
||||
{
|
||||
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["Id"].ToString()));
|
||||
}
|
||||
|
||||
if (entityInfo.PropertyName == "TenantId")
|
||||
{
|
||||
//现在不能直接给了,要根据判断一下租户等级,如果租户等级是1,不给,需要自己去赋值,如果租户等级是0,就执行下面的。
|
||||
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["TenantId"].ToString()));
|
||||
//查询的时候,也需要判断一下,如果是租户等级,不要租户条件,如果是超级租户,就返回所有
|
||||
}
|
||||
break;
|
||||
case DataFilterType.UpdateByObject:
|
||||
if (entityInfo.PropertyName == "ModifyTime")
|
||||
{
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
if (entityInfo.PropertyName == "ModifyUser")
|
||||
{
|
||||
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["Id"].ToString()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
//inset生效
|
||||
|
||||
};
|
||||
//如果用单例配置要统一写在这儿
|
||||
db.Aop.OnLogExecuting = (s, p) =>
|
||||
{
|
||||
|
||||
Console.WriteLine("_______________________________________________");
|
||||
Console.WriteLine(s);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
public ISqlSugarClient Db;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
|
||||
namespace Yi.Framework.Repository
|
||||
@@ -13,6 +14,6 @@ namespace Yi.Framework.Repository
|
||||
{
|
||||
public Task<T> InsertReturnEntityAsync(T entity);
|
||||
public Task<List<S>> StoreAsync<S>(string storeName, object para);
|
||||
public object CommonPage(QueryCondition queryCondition);
|
||||
public Task<PageModel<List<T>>> CommonPage(QueryCondition pars);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using SqlSugar;
|
||||
using System.Data;
|
||||
using System.Linq.Expressions;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
|
||||
/***这里面写的代码不会给覆盖,如果要重新生成请删除 Repository.cs ***/
|
||||
@@ -17,12 +18,8 @@ namespace Yi.Framework.Repository
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
|
||||
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
base.Context = Db;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +49,9 @@ namespace Yi.Framework.Repository
|
||||
/// 仓储扩展方法:单表查询通用分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object CommonPage(QueryCondition pars)
|
||||
public async Task<PageModel<List<T>>> CommonPage(QueryCondition pars)
|
||||
{
|
||||
int tolCount = 0;
|
||||
RefAsync<int> tolCount = 0;
|
||||
var sugarParamters = pars.Parameters.Select(it => (IConditionalModel)new ConditionalModel()
|
||||
{
|
||||
ConditionalType = it.ConditionalType,
|
||||
@@ -66,14 +63,15 @@ namespace Yi.Framework.Repository
|
||||
{
|
||||
foreach (var item in pars.OrderBys)
|
||||
{
|
||||
query.OrderBy(item.ToSqlFilter());//格式 id asc或者 id desc
|
||||
query.OrderBy(item.ToSqlFilter());
|
||||
}
|
||||
}
|
||||
var result = query.Where(sugarParamters).ToPageList(pars.Index, pars.Size, ref tolCount);
|
||||
return new
|
||||
var result =await query.Where(sugarParamters).ToPageListAsync(pars.Index, pars.Size, tolCount);
|
||||
|
||||
return new PageModel<List<T>>
|
||||
{
|
||||
count = tolCount,
|
||||
data = result
|
||||
Total = tolCount.Value,
|
||||
Data = result
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user