From 9888fe5d6611690994259d8b47a7c945854f726a Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Thu, 7 Nov 2024 11:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=85=E9=80=89=E4=BF=AE=E8=A7=84=E5=88=99?= =?UTF-8?q?=E6=A0=8F=E4=BD=8D=E6=98=BE=E7=A4=BA=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dswagger=E6=8E=A5=E5=8F=A3=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=AE=BF=E9=97=AE=EF=BC=88?= =?UTF-8?q?api=E5=90=88=E5=B9=B6=E9=83=A8=E7=BD=B2=E5=BC=95=E8=B5=B7?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Model/Tiobon.Web.pdm | 16 ++-- Tiobon.Core.Api/Program.cs | 2 +- Tiobon.Core.Api/Tiobon.Core.Model.xml | 6 +- .../Swagger/SwaggerContextExtension.cs | 81 ++++++++++--------- .../Middlewares/SwaggerAuthMiddleware.cs | 8 +- .../ServiceExtensions/SwaggerSetup.cs | 8 +- .../Base/Ghre/Ghre_StudyRule.Dto.Base.cs | 8 +- .../Models/Ghre/Ghre_StudyRule.cs | 6 +- Tiobon.Core.sln | 7 ++ Tiobon.Core/Tiobon.Core.Model.xml | 6 +- 10 files changed, 83 insertions(+), 65 deletions(-) diff --git a/Model/Tiobon.Web.pdm b/Model/Tiobon.Web.pdm index edf88824..9ad5e2eb 100644 --- a/Model/Tiobon.Web.pdm +++ b/Model/Tiobon.Web.pdm @@ -1,5 +1,5 @@ - + @@ -26483,7 +26483,7 @@ LABL 0 Arial Unicode MS,8,N Ghre_StudyRule 1721267637 Administrator -1726122724 +1730947770 Administrator 必选修规则 @@ -26729,13 +26729,13 @@ LABL 0 Arial Unicode MS,8,N 11CD542D-061E-4B85-A96B-7A0543F3C4AE -职称 +岗位ID1 TitleId 1721353940 Administrator -1723284422 +1730947751 Administrator -职称 +岗位ID nvarchar(2000) 2000 @@ -26753,13 +26753,13 @@ LABL 0 Arial Unicode MS,8,N AF5F0E34-DA3F-4286-A4EC-88F51CDA9EF5 -岗位 +职称 JobId 1721354134 Administrator -1723284422 +1730947770 Administrator -岗位 +职称 nvarchar(2000) 2000 diff --git a/Tiobon.Core.Api/Program.cs b/Tiobon.Core.Api/Program.cs index 516b90a4..39025c2d 100644 --- a/Tiobon.Core.Api/Program.cs +++ b/Tiobon.Core.Api/Program.cs @@ -149,7 +149,7 @@ app.UseAllServicesMiddle(builder.Services); app.UseSession(); app.UseSwaggerAuthorized(); -app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("Tiobon.Core.Api.index.html")); +app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("Tiobon.Core.Api.index.html"), app.Environment.IsDevelopment()); app.UseCors(AppSettings.app(new string[] { "Startup", "Cors", "PolicyName" })); DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions(); diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index 96352cad..1524eed7 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -4957,7 +4957,7 @@ - 职称 + 岗位 @@ -4967,7 +4967,7 @@ - 岗位 + 职称 @@ -14778,7 +14778,7 @@ - 职称 + 岗位 diff --git a/Tiobon.Core.Common/Swagger/SwaggerContextExtension.cs b/Tiobon.Core.Common/Swagger/SwaggerContextExtension.cs index e3ae00c0..cab576bb 100644 --- a/Tiobon.Core.Common/Swagger/SwaggerContextExtension.cs +++ b/Tiobon.Core.Common/Swagger/SwaggerContextExtension.cs @@ -6,43 +6,46 @@ namespace Tiobon.Core.Common.Swagger; public static class SwaggerContextExtension { - public const string SwaggerCodeKey = "swagger-code"; - public const string SwaggerJwt = "swagger-jwt"; - - public static bool IsSuccessSwagger() - { - return App.HttpContext?.GetSession()?.GetString(SwaggerCodeKey) == "success"; - } - - public static bool IsSuccessSwagger(this HttpContext context) - { - return context.GetSession()?.GetString(SwaggerCodeKey) == "success"; - } - - public static void SuccessSwagger() - { - App.HttpContext?.GetSession()?.SetString(SwaggerCodeKey, "success"); - } - - public static void SuccessSwagger(this HttpContext context) - { - context.GetSession()?.SetString(SwaggerCodeKey, "success"); - } - - public static void SuccessSwaggerJwt(this HttpContext context, string token) - { - context.GetSession()?.SetString(SwaggerJwt, token); - } - - public static string GetSuccessSwaggerJwt(this HttpContext context) - { - return context.GetSession()?.GetString(SwaggerJwt); - } - - - public static void RedirectSwaggerLogin(this HttpContext context) - { - var returnUrl = context.Request.GetDisplayUrl(); //获取当前url地址 - context.Response.Redirect("/swg-login.html?returnUrl=" + returnUrl); - } + public const string SwaggerCodeKey = "swagger-code"; + public const string SwaggerJwt = "swagger-jwt"; + + public static bool IsSuccessSwagger() + { + return App.HttpContext?.GetSession()?.GetString(SwaggerCodeKey) == "success"; + } + + public static bool IsSuccessSwagger(this HttpContext context) + { + return context.GetSession()?.GetString(SwaggerCodeKey) == "success"; + } + + public static void SuccessSwagger() + { + App.HttpContext?.GetSession()?.SetString(SwaggerCodeKey, "success"); + } + + public static void SuccessSwagger(this HttpContext context) + { + context.GetSession()?.SetString(SwaggerCodeKey, "success"); + } + + public static void SuccessSwaggerJwt(this HttpContext context, string token) + { + context.GetSession()?.SetString(SwaggerJwt, token); + } + + public static string GetSuccessSwaggerJwt(this HttpContext context) + { + return context.GetSession()?.GetString(SwaggerJwt); + } + + + public static void RedirectSwaggerLogin(this HttpContext context, bool IsDevelopment) + { + var returnUrl = context.Request.GetDisplayUrl(); //获取当前url地址 + if (IsDevelopment) + context.Response.Redirect("/swg-login.html?returnUrl=" + returnUrl); + else + context.Response.Redirect("/Advanced/swg-login.html?returnUrl=" + returnUrl); + } } \ No newline at end of file diff --git a/Tiobon.Core.Extensions/Middlewares/SwaggerAuthMiddleware.cs b/Tiobon.Core.Extensions/Middlewares/SwaggerAuthMiddleware.cs index 21c76f51..1e384711 100644 --- a/Tiobon.Core.Extensions/Middlewares/SwaggerAuthMiddleware.cs +++ b/Tiobon.Core.Extensions/Middlewares/SwaggerAuthMiddleware.cs @@ -3,6 +3,8 @@ using System.Threading.Tasks; using Tiobon.Core.Common.Swagger; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; namespace Tiobon.Core.Extensions.Middlewares { @@ -10,10 +12,12 @@ namespace Tiobon.Core.Extensions.Middlewares { private readonly RequestDelegate next; + private readonly IWebHostEnvironment Env; - public SwaggerAuthMiddleware(RequestDelegate next) + public SwaggerAuthMiddleware(RequestDelegate next, IWebHostEnvironment env) { this.next = next; + Env = env; } public async Task InvokeAsync(HttpContext context) @@ -29,7 +33,7 @@ namespace Tiobon.Core.Extensions.Middlewares } // 无权限,跳转swagger登录页 - context.RedirectSwaggerLogin(); + context.RedirectSwaggerLogin(Env.IsDevelopment()); } else { diff --git a/Tiobon.Core.Extensions/ServiceExtensions/SwaggerSetup.cs b/Tiobon.Core.Extensions/ServiceExtensions/SwaggerSetup.cs index 49c5d604..08ba1e4c 100644 --- a/Tiobon.Core.Extensions/ServiceExtensions/SwaggerSetup.cs +++ b/Tiobon.Core.Extensions/ServiceExtensions/SwaggerSetup.cs @@ -111,7 +111,7 @@ namespace Tiobon.Core.Extensions services.AddSwaggerGenNewtonsoftSupport(); } - public static void UseSwaggerMiddle(this IApplicationBuilder app, Func streamHtml) + public static void UseSwaggerMiddle(this IApplicationBuilder app, Func streamHtml, bool IsDevelopment) { if (app == null) throw new ArgumentNullException(nameof(app)); @@ -121,7 +121,11 @@ namespace Tiobon.Core.Extensions // 遍历分组信息,生成Json ApiInfos.ForEach(x => { - options.SwaggerEndpoint($"/swagger/{x.UrlPrefix}/swagger.json", x.Name); + if (IsDevelopment) + options.SwaggerEndpoint($"/swagger/{x.UrlPrefix}/swagger.json", x.Name); + else + options.SwaggerEndpoint($"/Advanced/swagger/{x.UrlPrefix}/swagger.json", x.Name); + }); // 模型的默认扩展深度,设置为 -1 完全隐藏模型 options.DefaultModelsExpandDepth(-1); diff --git a/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRule.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRule.Dto.Base.cs index afd191b3..959fb848 100644 --- a/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRule.Dto.Base.cs +++ b/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRule.Dto.Base.cs @@ -61,9 +61,9 @@ namespace Tiobon.Core.Model.Models public string DeptId { get; set; } /// - /// 职称 + /// 岗位 /// - [Display(Name = "TitleId"), Description("职称"), MaxLength(2000, ErrorMessage = "职称 不能超过 2000 个字符")] + [Display(Name = "TitleId"), Description("岗位"), MaxLength(2000, ErrorMessage = "岗位 不能超过 2000 个字符")] public string TitleId { get; set; } /// @@ -73,9 +73,9 @@ namespace Tiobon.Core.Model.Models public string GradeId { get; set; } /// - /// 岗位 + /// 职称 /// - [Display(Name = "JobId"), Description("岗位"), MaxLength(2000, ErrorMessage = "岗位 不能超过 2000 个字符")] + [Display(Name = "JobId"), Description("职称"), MaxLength(2000, ErrorMessage = "职称 不能超过 2000 个字符")] public string JobId { get; set; } /// diff --git a/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRule.cs b/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRule.cs index 58249963..9f201593 100644 --- a/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRule.cs +++ b/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRule.cs @@ -63,9 +63,9 @@ namespace Tiobon.Core.Model.Models public string DeptId { get; set; } /// - /// 职称 + /// 岗位 /// - [Display(Name = "TitleId"), Description("职称"), MaxLength(2000, ErrorMessage = "职称 不能超过 2000 个字符")] + [Display(Name = "TitleId"), Description("岗位"), MaxLength(2000, ErrorMessage = "岗位 不能超过 2000 个字符")] public string TitleId { get; set; } /// @@ -77,7 +77,7 @@ namespace Tiobon.Core.Model.Models /// /// 岗位 /// - [Display(Name = "JobId"), Description("岗位"), MaxLength(2000, ErrorMessage = "岗位 不能超过 2000 个字符")] + [Display(Name = "JobId"), Description("职称"), MaxLength(2000, ErrorMessage = "职称 不能超过 2000 个字符")] public string JobId { get; set; } /// diff --git a/Tiobon.Core.sln b/Tiobon.Core.sln index d1a6e68d..4f24c8e4 100644 --- a/Tiobon.Core.sln +++ b/Tiobon.Core.sln @@ -68,6 +68,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tiobon.Core.PublishHelper", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tiobon.Core.Jobs", "Tiobon.Core.Jobs\Tiobon.Core.Jobs.csproj", "{CF66C4DE-8E0C-4FAD-901A-2B7E1E485ABA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tiobon.Core.OPS.Tool", "Tiobon.Core.OPS.Tool\Tiobon.Core.OPS.Tool.csproj", "{1C0E27D6-B516-4D30-B559-C9097476DEEC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -150,6 +152,10 @@ Global {CF66C4DE-8E0C-4FAD-901A-2B7E1E485ABA}.Debug|Any CPU.Build.0 = Debug|Any CPU {CF66C4DE-8E0C-4FAD-901A-2B7E1E485ABA}.Release|Any CPU.ActiveCfg = Release|Any CPU {CF66C4DE-8E0C-4FAD-901A-2B7E1E485ABA}.Release|Any CPU.Build.0 = Release|Any CPU + {1C0E27D6-B516-4D30-B559-C9097476DEEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C0E27D6-B516-4D30-B559-C9097476DEEC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C0E27D6-B516-4D30-B559-C9097476DEEC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C0E27D6-B516-4D30-B559-C9097476DEEC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -162,6 +168,7 @@ Global {1CD6CC3C-D58C-47D1-9F9A-671BB9261A46} = {EDA8901E-541E-4ADC-B71E-59697D5F9549} {BA7081E8-08F2-4CC2-ACD9-E878C0CDE313} = {047A9723-9AAC-42E3-8C69-B3835F15FF96} {9B5E9966-1B4E-427E-838F-4AF0B742BE6C} = {047A9723-9AAC-42E3-8C69-B3835F15FF96} + {1C0E27D6-B516-4D30-B559-C9097476DEEC} = {047A9723-9AAC-42E3-8C69-B3835F15FF96} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AB40D0C5-E3EA-4A9B-86C2-38F0BB33FC04} diff --git a/Tiobon.Core/Tiobon.Core.Model.xml b/Tiobon.Core/Tiobon.Core.Model.xml index 96352cad..1524eed7 100644 --- a/Tiobon.Core/Tiobon.Core.Model.xml +++ b/Tiobon.Core/Tiobon.Core.Model.xml @@ -4957,7 +4957,7 @@ - 职称 + 岗位 @@ -4967,7 +4967,7 @@ - 岗位 + 职称 @@ -14778,7 +14778,7 @@ - 职称 + 岗位