From e178263b3b9e017700aef208ed5ee215d49ec94a Mon Sep 17 00:00:00 2001 From: "2248356998 qq.com" <2248356998@qq.com> Date: Wed, 7 Jun 2023 20:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=BB=98=E8=AE=A4api?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=BAKnife4j?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ThingsGateway.Foundation.Tests.csproj | 2 +- src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs | 9 +++++++-- .../ThingsGateway.Core.csproj | 11 ++++++----- .../Configuration/Swagger.json | 2 +- src/ThingsGateway.Web.Core/Startup.cs | 17 ++++++++++++++++- .../Plugin/DriverBase.cs | 4 ++-- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Plugins/ThingsGateway.Foundation.Tests/ThingsGateway.Foundation.Tests.csproj b/src/Plugins/ThingsGateway.Foundation.Tests/ThingsGateway.Foundation.Tests.csproj index 7bfeb546d..d0814bdb4 100644 --- a/src/Plugins/ThingsGateway.Foundation.Tests/ThingsGateway.Foundation.Tests.csproj +++ b/src/Plugins/ThingsGateway.Foundation.Tests/ThingsGateway.Foundation.Tests.csproj @@ -11,7 +11,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs b/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs index da7665d29..044548448 100644 --- a/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs +++ b/src/ThingsGateway.Core/Sqlsugar/Db/DbContext.cs @@ -68,14 +68,19 @@ namespace ThingsGateway.Core db.Aop.OnLogExecuting = (sql, pars) => { //如果不是开发环境就打印sql - if (App.HostEnvironment.IsDevelopment()) + if (App.HostEnvironment.IsDevelopment()&& !sql.Contains("tg_log_runtime")) { if (sql.StartsWith("SELECT")) { Console.ForegroundColor = ConsoleColor.Green; WriteSqlLog($"查询{config.ConfigId}库操作"); } - if (sql.StartsWith("UPDATE") || sql.StartsWith("INSERT")) + if (sql.StartsWith("UPDATE")) + { + Console.ForegroundColor = ConsoleColor.Yellow; + WriteSqlLog($"修改{config.ConfigId}库操作"); + } + if (sql.StartsWith("INSERT")) { Console.ForegroundColor = ConsoleColor.Blue; WriteSqlLog($"修改{config.ConfigId}库操作"); diff --git a/src/ThingsGateway.Core/ThingsGateway.Core.csproj b/src/ThingsGateway.Core/ThingsGateway.Core.csproj index ee12b6960..1b3c561e7 100644 --- a/src/ThingsGateway.Core/ThingsGateway.Core.csproj +++ b/src/ThingsGateway.Core/ThingsGateway.Core.csproj @@ -6,13 +6,13 @@ 1.5.1 - + - - - + + + - + @@ -21,6 +21,7 @@ + diff --git a/src/ThingsGateway.Web.Core/Configuration/Swagger.json b/src/ThingsGateway.Web.Core/Configuration/Swagger.json index b998ee921..2bd3a0963 100644 --- a/src/ThingsGateway.Web.Core/Configuration/Swagger.json +++ b/src/ThingsGateway.Web.Core/Configuration/Swagger.json @@ -6,7 +6,7 @@ "DocExpansionState": "None", "GroupOpenApiInfos": [ { - "Group": "ThingsGateway", //分组唯一标识,string 类型,必填 + "Group": "ThingsGatewayOpenApi", //分组唯一标识,string 类型,必填 "Order": 99, //分组排序,int 类型,数字越大排前面,默认 0 "Title": "ThingsGateway物联网关接口", //配置分组标题,string 类型 "Description": "物联网关Swagger", diff --git a/src/ThingsGateway.Web.Core/Startup.cs b/src/ThingsGateway.Web.Core/Startup.cs index 4d15567e0..392affb76 100644 --- a/src/ThingsGateway.Web.Core/Startup.cs +++ b/src/ThingsGateway.Web.Core/Startup.cs @@ -10,6 +10,10 @@ //------------------------------------------------------------------------------ #endregion +using Furion.SpecificationDocument; + +using IGeekFan.AspNetCore.Knife4jUI; + using Microsoft.Extensions.Hosting; using Microsoft.Extensions.WebEncoders; @@ -46,7 +50,18 @@ namespace ThingsGateway.Web.Core // 限流服务,自行开启 //app.UseIpRateLimiting(); - app.UseInject("api"); + + // 配置Swagger-Knife4UI(路由前缀一致代表独立,不同则代表共存) + app.UseKnife4UI(options => + { + options.RoutePrefix = "api"; + foreach (var groupInfo in SpecificationDocumentBuilder.GetOpenApiGroups()) + { + options.SwaggerEndpoint("/" + groupInfo.RouteTemplate, groupInfo.Title); + } + }); + + app.UseInject("swagger"); app.UseRouting(); diff --git a/src/ThingsGateway.Web.Foundation/Plugin/DriverBase.cs b/src/ThingsGateway.Web.Foundation/Plugin/DriverBase.cs index 8f488dd05..2fabcf40e 100644 --- a/src/ThingsGateway.Web.Foundation/Plugin/DriverBase.cs +++ b/src/ThingsGateway.Web.Foundation/Plugin/DriverBase.cs @@ -89,11 +89,11 @@ public abstract class DriverBase : DisposableObject /// public void NewMessage(LogType arg1, object arg2, string arg3, Exception arg4) { - if (arg3.StartsWith("报文-") && arg1 == LogType.Trace) + if (arg1 == LogType.Trace && arg3.StartsWith("报文-")) { Messages.Add(new(YitIdHelper.NextId(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff zz") + "-" + arg3)); - if (Messages.Count > 500) + if (Messages.Count > 2500) { Messages.Clear(); }