diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db
index 28007ec7..12daf48c 100644
Binary files a/WebFirst/database/sqlite.db and b/WebFirst/database/sqlite.db differ
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
index dce031be..1eb4c3c8 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
@@ -10,7 +10,7 @@
-
+
主键查询
@@ -44,12 +44,30 @@
-
+
列表删除
+
+
+ 国际化测试
+
+
+
+
+
+ 权限测试
+
+
+
+
+
+ 策略授权测试
+
+
+
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs
index d48ebbdf..b0cc7363 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/BaseController/BaseCrudController.cs
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Localization;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
+using Yi.Framework.Language;
using Yi.Framework.Model.Models;
using Yi.Framework.Model.Query;
using Yi.Framework.Repository;
@@ -19,7 +21,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public readonly ILogger _logger;
public IBaseService _baseService;
public IRepository _repository;
-
public BaseCrudController(ILogger logger, IBaseService iBaseService)
{
_logger = logger;
@@ -34,7 +35,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
///
[Permission($"{nameof(T)}:get:one")]
[HttpGet]
- public async Task Get(object id)
+ public async Task Get(long id)
{
return Result.Success().SetData(await _repository.GetByIdAsync(id));
}
@@ -71,7 +72,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
[HttpPost]
public async Task Add(T entity)
{
- return Result.Success().SetData(await _repository.InsertReturnEntityAsync(entity));
+ return Result.Success().SetData(await _repository.InsertReturnSnowflakeIdAsync(entity));
}
///
@@ -93,7 +94,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
///
[Permission($"{nameof(T)}:delete:list")]
[HttpDelete]
- public async Task DeleteList(List ids)
+ public async Task DeleteList(List ids)
{
return Result.Success().SetStatus(await _repository.DeleteByLogic(ids));
}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TenantController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TenantController.cs
deleted file mode 100644
index cd3b179e..00000000
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TenantController.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Yi.Framework.Common.Models;
-using Yi.Framework.Interface;
-using Yi.Framework.Model.Models;
-using Yi.Framework.Repository;
-using Yi.Framework.WebCore;
-using Yi.Framework.WebCore.AttributeExtend;
-using Yi.Framework.WebCore.AuthorizationPolicy;
-
-namespace Yi.Framework.ApiMicroservice.Controllers
-{
- [ApiController]
- [Route("api/[controller]/[action]")]
- public class TenantController : BaseCrudController
- {
- public TenantController(ILogger logger, ITenantService iTenantService) : base(logger, iTenantService)
- {
- }
- }
-}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
new file mode 100644
index 00000000..1443b95c
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
@@ -0,0 +1,61 @@
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Localization;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Yi.Framework.Common.Models;
+using Yi.Framework.Interface;
+using Yi.Framework.Language;
+using Yi.Framework.Model.Models;
+using Yi.Framework.Repository;
+using Yi.Framework.WebCore;
+using Yi.Framework.WebCore.AttributeExtend;
+using Yi.Framework.WebCore.AuthorizationPolicy;
+
+namespace Yi.Framework.ApiMicroservice.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]/[action]")]
+ public class TestController : ControllerBase
+ {
+ private IStringLocalizer _local;
+ public TestController(ILogger logger, IUserService iUserService, IStringLocalizer local)
+ {
+ _local = local;
+ }
+ ///
+ /// 国际化测试
+ ///
+ ///
+ [HttpGet]
+ public Result LocalTest()
+ {
+ return Result.Success().SetData(_local["succeed"]);
+ }
+
+ ///
+ /// 权限测试
+ ///
+ ///
+ [HttpGet]
+ [Permission("user:get:test")]
+ public Result PermissionTest()
+ {
+ return Result.Success();
+ }
+
+ ///
+ /// 策略授权测试
+ ///
+ ///
+ [HttpGet]
+ [Authorize(PolicyName.Sid)]
+ public Result AutnTest()
+ {
+ return Result.Success();
+ }
+ }
+}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs
index 3a2c3c7f..87abaf09 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs
@@ -108,7 +108,6 @@ builder.Services.AddCAPService();
builder.Services.AddLocalizerService();
//-----------------------------------------------------------------------------------------------------------
var app = builder.Build();
-
#region
//
#endregion
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.Production.json b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.Production.json
index 3898cb29..cd9cd1cd 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.Production.json
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.Production.json
@@ -31,6 +31,7 @@
},
"DbConn": {
+ //"WriteUrl": "DataSource=yi-sqlsugar-dev.db",
"WriteUrl": "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"ReadUrl": [
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json
index 24a90649..d7e71ae1 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/appsettings.json
@@ -25,13 +25,10 @@
"Cors_Enabled": true,
"DbList": [ "Sqlite", "Mysql", "Sqlserver", "Oracle" ],
- "DbSelect": "Mysql",
- "Pan": {
- "ZipPath": "D:/AppWeb/test/zip"
- },
-
+ "DbSelect": "Sqlite",
"DbConn": {
- "WriteUrl": "server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
+ "WriteUrl": "DataSource=yi-sqlsugar-dev.db",
+ //"WriteUrl": "[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"ReadUrl": [
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
"server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]",
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db
index bd195d63..ba7873c4 100644
Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/MySqlConnOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqlConnOptions.cs
similarity index 86%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/MySqlConnOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqlConnOptions.cs
index c5ae46b1..5e177b00 100644
--- a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/MySqlConnOptions.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqlConnOptions.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Yi.Framework.Common.IOCOptions
{
- public class DbConnOptions
+ public class SqlConnOptions
{
public string WriteUrl { get; set; }
public List ReadUrl { get; set; }
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqliteOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqliteOptions.cs
deleted file mode 100644
index bd2caf1e..00000000
--- a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqliteOptions.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Yi.Framework.Common.IOCOptions
-{
- public class SqliteOptions
- {
- public string WriteUrl { get; set; }
- public List ReadUrl { get; set; }
- }
-}
diff --git a/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs b/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
index 3e71a3af..e599ff74 100644
--- a/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
@@ -37,11 +37,10 @@ namespace Yi.Framework.Core
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(minutes)).ToUnixTimeSeconds()}"));
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
- //claims.Add(new Claim("TenantId", userRoleMenuEntity.user.TenantId.ToString()));
- //claims.Add(new Claim("TenantName", userRoleMenuEntity.tenant.TenantName.ToString()));
- //claims.Add(new Claim("Id", userRoleMenuEntity.user.Id.ToString()));
- //claims.Add(new Claim("Name", userRoleMenuEntity.user.Name));
- //claims.Add(new Claim("TenantLevel", userRoleMenuEntity.tenant.TenantLevel.ToString()));
+
+ //-----------------------------以下从user的权限表中添加权限-----------------------例如:
+ claims.Add(new Claim("permission", "userentity:get:list"));
+ claims.Add(new Claim("permission", "userentity:get:one"));
if (isRefresh)
{
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs
deleted file mode 100644
index 31f8a4a9..00000000
--- a/Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using Yi.Framework.Model.Models;
-using Yi.Framework.Repository;
-
-namespace Yi.Framework.Interface
-{
- public partial interface ITenantService:IBaseService
- {
- }
-}
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/Yi - Backup (2).Framework.Interface.csproj b/Yi.Framework.Net6/Yi.Framework.Interface/Yi - Backup (2).Framework.Interface.csproj
new file mode 100644
index 00000000..4748d76c
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/Yi - Backup (2).Framework.Interface.csproj
@@ -0,0 +1,25 @@
+
+
+
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/Yi.Framework.Interface.csproj b/Yi.Framework.Net6/Yi.Framework.Interface/Yi.Framework.Interface.csproj
index 4748d76c..a98e0345 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/Yi.Framework.Interface.csproj
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/Yi.Framework.Interface.csproj
@@ -14,12 +14,23 @@
+
+
+ T4Iservice.cs
+ TextTemplatingFileGenerator
+
+
+
-
+
+ True
+ True
+ T4IService.tt
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs
index eb7b55db..d02df0a0 100644
--- a/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/BaseModel/BaseModelEntity.cs
@@ -11,7 +11,6 @@ namespace Yi.Framework.Model.Models
{
public BaseModelEntity()
{
- this.Id = Guid.NewGuid();
this.IsDeleted = false;
this.CreateTime = DateTime.Now;
}
@@ -19,17 +18,17 @@ namespace Yi.Framework.Model.Models
/// 1
///
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
- public Guid Id { get; set; }
+ public long Id { get; set; }
///
/// 创建者
///
[SugarColumn(ColumnName = "CreateUser")]
- public Guid? CreateUser { get; set; }
+ public long? CreateUser { get; set; }
///
/// 修改者
///
[SugarColumn(ColumnName = "ModifyUser")]
- public Guid? ModifyUser { get; set; }
+ public long? ModifyUser { get; set; }
///
/// 创建时间
///
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs
deleted file mode 100644
index 8da9ff39..00000000
--- a/Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using SqlSugar;
-namespace Yi.Framework.Model.Models
-{
- ///
- /// 租户表
- ///
- [SugarTable("Tenant")]
- public partial class TenantEntity:BaseModelEntity
- {
- ///
- /// 租户名
- ///
- [SugarColumn(ColumnName="TenantName" )]
- public string TenantName { get; set; }
- }
-}
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs
index f79d8aea..35b9b147 100644
--- a/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Model/Models/UserEntity.cs
@@ -5,38 +5,38 @@ using SqlSugar;
namespace Yi.Framework.Model.Models
{
///
- /// 用户表
+ ///
///
[SugarTable("User")]
public partial class UserEntity:BaseModelEntity
{
///
- /// 姓名
+ ///
///
[SugarColumn(ColumnName="Name" )]
public string Name { get; set; }
///
- /// 年龄
+ ///
///
[SugarColumn(ColumnName="Age" )]
public int? Age { get; set; }
///
- /// 租户Id
+ ///
///
[SugarColumn(ColumnName="TenantId" )]
- public Guid? TenantId { get; set; }
+ public long? TenantId { get; set; }
///
- /// 账户
+ ///
///
[SugarColumn(ColumnName="UserName" )]
public string UserName { get; set; }
///
- /// 密码
+ ///
///
[SugarColumn(ColumnName="Password" )]
public string Password { get; set; }
///
- /// 加密盐值
+ ///
///
[SugarColumn(ColumnName="Salt" )]
public string Salt { get; set; }
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Yi - Backup (3).Framework.Model.csproj b/Yi.Framework.Net6/Yi.Framework.Model/Yi - Backup (3).Framework.Model.csproj
new file mode 100644
index 00000000..b9873517
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.Model/Yi - Backup (3).Framework.Model.csproj
@@ -0,0 +1,44 @@
+
+
+
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ TextTemplatingFileGenerator
+ T4DaraContext.cs
+
+
+
+
+
+
+
+
+
+ True
+ True
+ T4DaraContext.tt
+
+
+
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj b/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj
index b9873517..50f4b52a 100644
--- a/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj
+++ b/Yi.Framework.Net6/Yi.Framework.Model/Yi.Framework.Model.csproj
@@ -1,21 +1,12 @@
-
+
net6.0
-
-
-
-
-
-
-
-
-
-
+
@@ -27,6 +18,10 @@
TextTemplatingFileGenerator
T4DaraContext.cs
+
+ TextTemplatingFileGenerator
+ T4DataContext.cs
+
@@ -39,6 +34,11 @@
True
T4DaraContext.tt
+
+ True
+ True
+ T4DataContext.tt
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
index 273954e9..020d997b 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/IRepository.cs
@@ -17,6 +17,6 @@ namespace Yi.Framework.Repository
public Task> StoreAsync(string storeName, object para);
public Task>> CommonPage(QueryPageCondition pars);
public Task> GetListAsync(QueryCondition pars);
- public Task DeleteByLogic(List ids);
+ public Task DeleteByLogic(List ids);
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
index b9846506..4669e256 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
@@ -31,6 +31,7 @@ namespace Yi.Framework.Repository
///
public async Task InsertReturnEntityAsync(T entity)
{
+ entity.Id =SnowFlakeSingle.instance.getID();
return await Db.Insertable(entity).ExecuteReturnEntityAsync();
}
@@ -38,7 +39,7 @@ namespace Yi.Framework.Repository
/// 逻辑多删除
///
///
- public async Task DeleteByLogic(List ids)
+ public async Task DeleteByLogic(List ids)
{
var entitys = await Db.Queryable().Where(u => ids.Contains(u.Id)).ToListAsync();
entitys.ForEach(u=>u.IsDeleted=true);
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Yi.Framework.Repository.csproj b/Yi.Framework.Net6/Yi.Framework.Repository/Yi.Framework.Repository.csproj
index 239ac7ef..9eb1d78e 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/Yi.Framework.Repository.csproj
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/Yi.Framework.Repository.csproj
@@ -11,6 +11,7 @@
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs
deleted file mode 100644
index 6093f532..00000000
--- a/Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using SqlSugar;
-using Yi.Framework.Interface;
-using Yi.Framework.Model.Models;
-using Yi.Framework.Repository;
-
-namespace Yi.Framework.Service
-{
- public partial class TenantService : BaseService, ITenantService
- {
- public TenantService(IRepository repository) : base(repository)
- {
- }
- }
-}
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Yi - Backup (2).Framework.Service.csproj b/Yi.Framework.Net6/Yi.Framework.Service/Yi - Backup (2).Framework.Service.csproj
new file mode 100644
index 00000000..e8861d67
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Yi - Backup (2).Framework.Service.csproj
@@ -0,0 +1,27 @@
+
+
+
+ net6.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Yi.Framework.Service.csproj b/Yi.Framework.Net6/Yi.Framework.Service/Yi.Framework.Service.csproj
index e8861d67..9f989a4a 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/Yi.Framework.Service.csproj
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Yi.Framework.Service.csproj
@@ -16,12 +16,23 @@
+
+
+ T4Service.cs
+ TextTemplatingFileGenerator
+
+
+
-
+
+ True
+ True
+ T4Service.tt
+
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs
index e2a053ec..78f8655b 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AttributeExtend/PermissionAttribute.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc.Filters;
+using Microsoft.IdentityModel.JsonWebTokens;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -29,16 +30,21 @@ namespace Yi.Framework.WebCore.AttributeExtend
{
throw new Exception("权限不能为空!");
}
-
- //可以从Redis得到用户菜单列表,或者直接从jwt中获取
-
var result = false;
- //判断权限是否存在Redis中
- if (permission.Length>0)
- {
- result = true;
- }
+
+ //可以从Redis得到用户菜单列表,或者直接从jwt中获取
+ var sid = context.HttpContext.User.Claims.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Sid);
+
+ //jwt存在的权限列表
+ var perList = context.HttpContext.User.Claims.Where(u => u.Type == "permission").Select(u=> u.Value.ToString().ToLower()). ToList();
+ //判断权限是否存在Redis中,或者jwt中
+
+ //if (perList.Contains(permission.ToLower()))
+ //{
+ // result = true;
+ //}
+ result = true;
if (!result)
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/CustomAuthorizationHandler.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/CustomAuthorizationHandler.cs
index 14e166ba..b3360551 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/CustomAuthorizationHandler.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/CustomAuthorizationHandler.cs
@@ -1,5 +1,7 @@
-using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
+using Microsoft.IdentityModel.JsonWebTokens;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,51 +17,30 @@ namespace Yi.Framework.WebCore.AuthorizationPolicy
public class CustomAuthorizationHandler : AuthorizationHandler
{
- private CacheClientDB _cacheClientDB;
+ //private CacheClientDB _cacheClientDB;
///
/// 构造函数
///
- public CustomAuthorizationHandler(CacheClientDB cacheClientDB)
+ public CustomAuthorizationHandler()
{
- _cacheClientDB= cacheClientDB;
}
//验证的方法就在这里
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, CustomAuthorizationRequirement requirement)
{
- var currentClaim = context.User.Claims.FirstOrDefault(u => u.Type == ClaimTypes.Sid);
-
- if (currentClaim==null) //说明没有写入Sid 没有登录
- {
- return Task.CompletedTask; //验证不同过
- }
-
- int currentUserId = 0;
- if (!string.IsNullOrWhiteSpace(currentClaim.Value))
- {
- currentUserId = Convert.ToInt32(currentClaim.Value);
- }
- DefaultHttpContext httpcontext = (DefaultHttpContext)context.Resource;
- Dictionary dicMenueDictionary = new Dictionary();
- //现在只需要登录的时候把用户的api路径添加到redis去
- //每次访问的时候进行redis判断一下即可
- //注意一下,redis不能一直保存,和jwt一样搞一个期限
- //var menuList=_cacheClientDB.Get>(RedisConst.userMenusApi+":"+currentUserId);
- //foreach (var k in menuList)
- //{
- // if (k.mould != null)
- // {
- // dicMenueDictionary.Add(k.mould?.id.ToString(), "/api"+ k.mould?.url);
- // }
-
- //}
-
- if (dicMenueDictionary.ContainsValue(httpcontext.Request.Path))
+ var currentClaim = context.User.Claims.FirstOrDefault(u => u.Type == JwtRegisteredClaimNames.Sid);
+ //DefaultHttpContext httpcontext = (DefaultHttpContext)context.AuthenticateAsync();
+ if (currentClaim!=null) //说明没有写入Sid 没有登录
{
context.Succeed(requirement); //验证通过了
}
+ //string currentUserId = "";
+ //if (!string.IsNullOrWhiteSpace(currentClaim.Value))
+ //{
+ // currentUserId = currentClaim.Value;
+ //}
+ //DefaultHttpContext httpcontext = (DefaultHttpContext)context.Resource;
return Task.CompletedTask; //验证不同过
-
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/PolicyEnum.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/PolicyEnum.cs
index ad8ac425..ccc5a2c2 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/PolicyEnum.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AuthorizationPolicy/PolicyEnum.cs
@@ -15,6 +15,6 @@ namespace Yi.Framework.WebCore.AuthorizationPolicy
}
public static class PolicyName
{
- public const string Menu = "Menu";
+ public const string Sid = "Sid";
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs
index cc87f21b..794371bf 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/CommonExtend.cs
@@ -33,9 +33,8 @@ namespace Yi.Framework.WebCore
public static UserEntity GetCurrentUserEntityInfo(this HttpContext httpContext, out List menuIds)
{
IEnumerable claimlist = httpContext.AuthenticateAsync().Result.Principal.Claims;
-
- var resId= new Guid (claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value);
-
+
+ long.TryParse(claimlist.FirstOrDefault(u => u.Type == ClaimTypes.Sid).Value,out var resId) ;
menuIds = claimlist.Where(u => u.Type == "menuIds").ToList().Select(u => new Guid(u.Value)).ToList();
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/AuthorizationExtension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/AuthorizationExtension.cs
index cbe1a4df..0fed6dd8 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/AuthorizationExtension.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/AuthorizationExtension.cs
@@ -13,15 +13,15 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static IServiceCollection AddAuthorizationService(this IServiceCollection services)
{
- //services.AddAuthorization(options =>
- //{
- // options.AddPolicy(PolicyName.Menu, polic =>
- // {
- // polic.AddRequirements(new CustomAuthorizationRequirement(PolicyEnum.MenuPermissions));
- // });
- //});
+ services.AddAuthorization(options =>
+ {
+ options.AddPolicy(PolicyName.Sid, polic =>
+ {
+ polic.AddRequirements(new CustomAuthorizationRequirement(PolicyEnum.MenuPermissions));
+ });
+ });
- //services.AddSingleton();
+ services.AddSingleton();
return services;
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs
index 665e61a2..d7b5301f 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/IocExtension.cs
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
+using Yi.Framework.Common.IOCOptions;
using Yi.Framework.Model;
namespace Yi.Framework.WebCore.MiddlewareExtend
@@ -20,6 +21,11 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
#endregion
services.AddSingleton(new Appsettings(configuration));
+ #region
+ //数据库连接字符串
+ #endregion
+ services.Configure(Appsettings.appConfiguration("DbConn"));
+
return services;
}
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs
index a09163d1..451b3496 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/JwtExtension.cs
@@ -27,11 +27,9 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
options.TokenValidationParameters = new TokenValidationParameters
{
- ValidateIssuer = true,//是否验证Issuer
+ ValidateIssuer = true,//是否验证Issuer
ValidateAudience = true,//是否验证Audience
ValidateLifetime = true,//是否验证失效时间
-
-
ValidateIssuerSigningKey = true,//是否验证SecurityKey
ValidAudience = jwtOptions.Audience,//Audience
ValidIssuer = jwtOptions.Issuer,//Issuer,这两项和前面签发jwt的设置一致
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/SqlsugarExtension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/SqlsugarExtension.cs
index ed3dabb9..61a75658 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/SqlsugarExtension.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/SqlsugarExtension.cs
@@ -12,11 +12,36 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static void AddSqlsugarServer(this IServiceCollection services)
{
+ DbType dbType;
+ var slavaConFig = new List();
+ if (Appsettings.appBool("MutiDB_Enabled"))
+ {
+ var readCon = Appsettings.app>("DbConn", "ReadUrl");
+
+ readCon.ForEach(s => {
+ slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s });
+ });
+ }
+
+ switch (Appsettings.app("DbSelect"))
+ {
+ case "Mysql": dbType = DbType.MySql; break;
+ case "Sqlite": dbType = DbType.Sqlite; break;
+ case "Sqlserver": dbType = DbType.SqlServer; break;
+ case "Oracle": dbType = DbType.Oracle; break;
+ default:throw new Exception("DbSelect配置写的TM是个什么东西?");
+ }
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
{
- DbType = SqlSugar.DbType.MySql,
+ DbType = dbType,
ConnectionString = Appsettings.app("DbConn", "WriteUrl"),
- IsAutoCloseConnection = true
+ IsAutoCloseConnection = true,
+ MoreSettings = new ConnMoreSettings()
+ {
+ DisableNvarchar = true
+ },
+ SlaveConnectionConfigs = slavaConFig,
+
},
db =>
{
@@ -31,7 +56,6 @@ namespace Yi.Framework.WebCore.MiddlewareExtend
{
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["Id"].ToString()));
}
-
if (entityInfo.PropertyName == "TenantId")
{
//entityInfo.SetValue(new Guid(httpcontext.Request.Headers["TenantId"].ToString()));