权限认证

This commit is contained in:
橙子
2022-04-06 22:22:45 +08:00
parent 5fcf5bd583
commit a6a2025972
13 changed files with 202 additions and 108 deletions

View File

@@ -12,7 +12,7 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static class CAPExtend
{
public static IServiceCollection AddCAPService<T>(this IServiceCollection services)
public static IServiceCollection AddCAPService(this IServiceCollection services)
{
if (Appsettings.appBool("CAP_Enabled"))
{
@@ -31,9 +31,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
x.FailedRetryInterval = 60;//second
x.FailedThresholdCallback = failed =>
{
var logger = failed.ServiceProvider.GetService<ILogger<T>>();
logger.LogError($@"MessageType {failed.MessageType} 失败了, 重试了 {x.FailedRetryCount} 次,
消息名称: {failed.Message.GetName()}");//do anything
//var logger = failed.ServiceProvider.GetService<ILogger<T>>();
//logger.LogError($@"MessageType {failed.MessageType} 失败了, 重试了 {x.FailedRetryCount} 次,
//消息名称: {failed.Message.GetName()}");//do anything
};
if (Appsettings.appBool("CAPDashboard_Enabled"))
{

View File

@@ -1,11 +1,13 @@
using log4net;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Core;
namespace Yi.Framework.WebCore.MiddlewareExtend
@@ -13,12 +15,12 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
public static class RedisInitExtend
{
private static readonly ILog log = LogManager.GetLogger(typeof(RedisInitExtend));
public static void UseRedisSeedInitService(this IApplicationBuilder app, CacheClientDB _cacheClientDB)
public static void UseRedisSeedInitService(this IApplicationBuilder app )
{
if (Appsettings.appBool("RedisSeed_Enabled"))
{
if (app == null) throw new ArgumentNullException(nameof(app));
var _cacheClientDB = ServiceLocator.Instance.GetService<CacheClientDB>();
try
{

View File

@@ -0,0 +1,72 @@
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static class SqlsugarExtension
{
public static void AddSqlsugarServer(this IServiceCollection services)
{
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
{
DbType = SqlSugar.DbType.MySql,
ConnectionString = Appsettings.app("DbConn", "WriteUrl"),
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);
};
});
services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton
}
}
}