From ef8dc261257cb00a8a3ddceb084dd0e9edbd7b8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Sat, 9 Apr 2022 16:16:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebFirst/database/sqlite.db | Bin 135168 -> 139264 bytes .../Config/SwaggerDoc.xml | 22 ++++++- .../BaseController/BaseCrudController.cs | 9 +-- .../Controllers/TenantController.cs | 26 -------- .../Controllers/TestController.cs | 61 ++++++++++++++++++ .../Yi.Framework.ApiMicroservice/Program.cs | 1 - .../appsettings.Production.json | 1 + .../appsettings.json | 9 +-- .../yi-sqlsugar-dev.db | Bin 20480 -> 12288 bytes ...{MySqlConnOptions.cs => SqlConnOptions.cs} | 2 +- .../IOCOptions/SqliteOptions.cs | 14 ---- .../Yi.Framework.Core/JwtInvoker.cs | 9 ++- .../IServiceTemplate/ITenantService.cs | 9 --- ...Yi - Backup (2).Framework.Interface.csproj | 25 +++++++ .../Yi.Framework.Interface.csproj | 13 +++- .../Models/BaseModel/BaseModelEntity.cs | 7 +- .../Yi.Framework.Model/Models/TenantEntity.cs | 19 ------ .../Yi.Framework.Model/Models/UserEntity.cs | 16 ++--- .../Yi - Backup (3).Framework.Model.csproj | 44 +++++++++++++ .../Yi.Framework.Model.csproj | 22 +++---- .../Yi.Framework.Repository/IRepository.cs | 2 +- .../Yi.Framework.Repository/Repository.cs | 3 +- .../Yi.Framework.Repository.csproj | 1 + .../ServiceTemplate/TenantService.cs | 14 ---- .../Yi - Backup (2).Framework.Service.csproj | 27 ++++++++ .../Yi.Framework.Service.csproj | 13 +++- .../AttributeExtend/PermissionAttribute.cs | 22 ++++--- .../CustomAuthorizationHandler.cs | 47 ++++---------- .../AuthorizationPolicy/PolicyEnum.cs | 2 +- .../Yi.Framework.WebCore/CommonExtend.cs | 5 +- .../AuthorizationExtension.cs | 16 ++--- .../MiddlewareExtend/IocExtension.cs | 6 ++ .../MiddlewareExtend/JwtExtension.cs | 4 +- .../MiddlewareExtend/SqlsugarExtension.cs | 30 ++++++++- 34 files changed, 314 insertions(+), 187 deletions(-) delete mode 100644 Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TenantController.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs rename Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/{MySqlConnOptions.cs => SqlConnOptions.cs} (86%) delete mode 100644 Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqliteOptions.cs delete mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/IServiceTemplate/ITenantService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Interface/Yi - Backup (2).Framework.Interface.csproj delete mode 100644 Yi.Framework.Net6/Yi.Framework.Model/Models/TenantEntity.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Model/Yi - Backup (3).Framework.Model.csproj delete mode 100644 Yi.Framework.Net6/Yi.Framework.Service/ServiceTemplate/TenantService.cs create mode 100644 Yi.Framework.Net6/Yi.Framework.Service/Yi - Backup (2).Framework.Service.csproj diff --git a/WebFirst/database/sqlite.db b/WebFirst/database/sqlite.db index 28007ec7249a5ba6fcbce7f842ecb236957d27cf..12daf48c1b0da0953074569248f14d51c3c5886e 100644 GIT binary patch delta 2495 zcmeHJeQXnD7{B-K+WYGDI<_)CR@RkutBkF8*LL(v!Zrw*#sT3|3F5Jyqsi8mwquNs zFv89d5P_UfO_qp39QX$)3zWnNBtVoz4UqVSK?o>{VgMb6Kn%Wbw{~0bU;p#c_xe8H z&-*;T=WToT(>-VC-IK=QAq>MDaOIzu_e__KkXtwR&_|JRZV=YH+&0j!?{&*y>cD4i zm&GF02PIF?Bi6}*fEbYc$7TULXP$=PgcmbZ6W)Oai;G~kCU6d00A5?Fi|S;(CH5WH zsHD_|YI1F~Rn?_|D{X6lNsV$)b3yr(ZBNj}0_Q|6-T3;6)77`6cPtZsUCX8lltI zL&P;>8_d{^lLilVPVc_q8V4hKgWf>UCvfOT1j!@$Iee1pfs z(BvXDro_@iZ&{S(TG3l8<}#M#pzMLM{F3NH<^zG7j{wdJ1HPYRAT162Ns?SI`Mo(8r*1jv@h=RSVxBRkP#zeN?_Rb{poL4QnGWHx@IbgL z+!k&MSA}ncOUKK=alr&76}_GCZSVDGuL_{rVllGYG2ys*Jg;#x*_-TkSdF!;v~;Qw z3t2nyIqTADEESE%R?h8=MpmK}MXxxc4HC;YI9ikr)e&@bLQ3B==&W8*ZF$jw47*1e zHg>1gg5fGiEZ4Jx-Z0edon1j;4U@MujMAR1wnjUY_JToVh#m>{YI|JK*F2GoXp{EC zxNbTcOG9KS?T8@TQ)(O9P#sFE5{V>p%!HC&jW&29t``l;R3hHq-4>4_mL(GJT-C1H z6G<2f9W`f=RCDf}^)SyZW;+EBwM7|~XJb4*lH@8#jAV!?=dkDq<|xS3H#UFaKo8G^CKL322i_D;)`YS2Vraj!66Zcq}L63c~by zq&&Gm=al1}>9P97IqRqVI0=|z_P85-H3j%GJ6eFl!O)DYh^Ct(&5<8Zeti4QBh9mA zUk$}!<>fR@JE16}^nodv-&;Ty+8mq*UIM-o^8vY^Xe4K5sC(c%35qdy=Hfk21ILzV z$|wV%*x-ZPnr!KP@T++<1mm;hCX6~wZKIY^6~=qUZ;gkHYm5y>)^Npez>qWq$S34E zaxb|_xG20WL!e=V>0jmWeAnelY99B^Q3&m#^ z{0vG<^6d>*YUKq9*b7Q6?eSO})Spt|N{~BR-&T;Uxd2Kx=k%>w8HW`YBmcz!YiLv9 z2M$8GOqqXvFC-7@de44lZ7fZYe9leR)%s3m1rgZl42;^hvR*KL@Jpu ziI)@B-sdu4A1Hy)`}`hoXN&KHS|WRc!cQ5qN6q*Gu$mWkVIp-06I|v&^EvZQ^9pkn z{}+Fne}ix3eZ0-|&~(N0fhlEbGMTvVxevLwxYeA*K4LGheQbbUe9D7NNHCWaka#nUDG zA0qjY_zxhGg%F8>QmY34h~(fd48vW@0qC#+cM~oR%OqI5I$LkV+W;Z;c4gkdagp>} zd)MZWMfz*Cs?7cKz?GZ1P?_dLvxPbgr(~hhoZIWv13HK~_GmV~+p8o~pnrYj|;O9NSn zFH+-HO$_03fRSVk^?~3eq0q@PBqoFgL>@G3ObqydA(U20w8caogcoPmc#`kseE;`f zzHjQXJT)U9UegKxAcXn?{QtHe8Kh$Hn;I;gAL~qm!}h1+z}WFLg&yyEdLSA#49B({ zJD0L@7PYB8Hw+0i&|@Kqgrv6Kdm*auil)Od+5#VKW=1*2Mk?#rxyc?jGu_2@)*`H< z8edEK-OOw7sRZT3Y=2zVhB`fZvXNx%7$8mY1IME-m%TtJ>t|a-}*E;P*rI#e>J& zBwhI_+AWcrE$jQpWAc!!ko#nT+$J}*UmH(BgM@WmmgPvmCu*Dg+XRwP5l91(hSyR0 zhWL#%{M-Z7{d5G@t_>>V9kN^;D~{c}`0f2;XNxaWxUBqUtsuzy?mQZF1oRbV0_y%Htu<{9 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 bd195d633e56899cde53c14e85e81b91a46f42aa..ba7873c48127d72436c06b4c70510f06da8384c6 100644 GIT binary patch delta 321 zcmZozz}S#5L0XWBfq{V;h+%+nqK+|8P|tk@FaHk)CO#(yJ}3V3n*|jv@p3hDF|vz` ziZZsAPnO}+WXZ|TOP{RED>XTv&lO zvsus}h`+v3k&%xLDCW$-z`-EcXlX0*&-8F!6u)e2bv2k8iV5V-7hgrH?SWtymWQe!6 mlV_e`p;1V3a9}`Cpsg(z*wJ4Y_`d)h{feK5o0*Lh=1u@+|5M-q delta 757 zcmZojXjs5FL0XWDfq{V)h+%+fqK>gB7lWSlM_&FP3@kiP82E(v&+|OteY&x*fTzB( zj+tFtQj)Pbyd*IxCp9EBFEOtKLb5mqxjKfpDug&X`M4@5K?IdFc)653Q&;uRlFgDW^J}&WEU3|Wo!$d?8B!ifbPi2m3*O?f|vNrFa>$|eK7@N`DK}m%_i6I zxAO5aFfeleVBr42%K(HM3tw{AH?cDEg)%UNI)^fF@Cr6s+L~J$CmNd=BRK2Zm?x!}7$v8rnG>VN$iT=**T6*Az*51$z{MHvb;SCvMbWVjgkYj z6M2ggle4k|&C6|V85o#17XD=t03}97{u>PZH~3>gaI>I706$~(#KLktb>>h`V*Cya UX9flVpvK4i6C1?YKqex%0N3c;1^@s6 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()));