From 6fd9b2118ad62fb05b38b20c9276cf17f9de1238 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Wed, 17 Apr 2024 16:58:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=93=8D=E5=BA=94=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/OrderController.cs | 9 ++- EntrustSettle.Api/appsettings.json | 5 +- .../Middlewares/RequRespLogMiddleware.cs | 81 +++++++------------ EntrustSettle.Model/Dtos/Order/OrderDto.cs | 2 +- .../QuartzNet/Jobs/JobHydStatusQuartz.cs | 2 +- 5 files changed, 43 insertions(+), 56 deletions(-) diff --git a/EntrustSettle.Api/Controllers/OrderController.cs b/EntrustSettle.Api/Controllers/OrderController.cs index b3009a8..e11760b 100644 --- a/EntrustSettle.Api/Controllers/OrderController.cs +++ b/EntrustSettle.Api/Controllers/OrderController.cs @@ -100,6 +100,13 @@ namespace EntrustSettle.Api.Controllers order.IsHasInvoiceAnnex = true; } } + result.data.ForEach(x => + { + if (!string.IsNullOrWhiteSpace(x.MailBillNo)) + { + x.IsHasInvoiceAnnex = true; + } + }); } return SuccessPage(result); @@ -427,7 +434,7 @@ namespace EntrustSettle.Api.Controllers var sumAllAmount = await orderFeeService.AsQueryable() .Where(x => x.OrderId == changeStatusDto.Id) .SumAsync(x => x.Amount); - //order.Amount = sumAllAmount; + order.Amount = sumAllAmount; } await orderService.Update(order, x => new { x.Status, x.Amount }); diff --git a/EntrustSettle.Api/appsettings.json b/EntrustSettle.Api/appsettings.json index 281da89..09ecf68 100644 --- a/EntrustSettle.Api/appsettings.json +++ b/EntrustSettle.Api/appsettings.json @@ -47,7 +47,8 @@ "Middleware": { "RequestResponseLog": { "Enabled": true, - "IgnoreApis": "/api/Annex/Upload,/api/Annex/DownloadFile,/api/Annex/Download", + "IgnoreRequestApis": "/api/Annex/Upload,/api/Open/AnnexUpload", + "IgnoreResponseApis": "/api/Annex/DownloadFile,/api/Open/AnnexDownload", "LogToFile": { "Enabled": true }, @@ -63,7 +64,7 @@ "LogToDB": { "Enabled": false }, - "IgnoreApis": "/api/Annex/Upload,/api/Annex/DownloadFile,/api/Annex/Download" + "IgnoreApis": "/api/Annex/Upload,/api/Open/AnnexUpload,/api/Annex/DownloadFile,/api/Open/AnnexDownload" }, "SignalR": { "Enabled": false diff --git a/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs b/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs index 22f87b3..286a98e 100644 --- a/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs +++ b/EntrustSettle.Extensions/Middlewares/RequRespLogMiddleware.cs @@ -1,16 +1,11 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using EntrustSettle.Common; +using EntrustSettle.Common; using EntrustSettle.Common.Extensions; using EntrustSettle.Common.LogHelper; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Org.BouncyCastle.Asn1.Ocsp; -using Polly; +using System.IO; +using System.Linq; +using System.Threading.Tasks; namespace EntrustSettle.Extensions.Middlewares { @@ -43,33 +38,36 @@ namespace EntrustSettle.Extensions.Middlewares return; } - // 判断如果请求或响应中含有文件上传,不记录日志 - if (context.Request.HasFormContentType && context.Request.Form.Files.Count > 0) + var path = context.Request.Path.ToString(); + if (path.Contains("index.html") || path.Contains("swagger.json")) { await _next(context); return; } + // 判断如果请求或响应中含有文件上传,不记录日志 + //if (context.Request.HasFormContentType && context.Request.Form.Files.Count > 0) + //{ + // await _next(context); + // return; + //} + // 过滤,只有接口 - var ignoreApis = AppSettings.app("Middleware", "RequestResponseLog", "IgnoreApis"); - var api = context.Request.Path.ObjToString().TrimEnd('/'); - if (!api.Contains("api", StringComparison.OrdinalIgnoreCase) || ignoreApis.Contains(api, StringComparison.OrdinalIgnoreCase)) - { - await _next(context); - return; - } + var ignoreRequestApis = AppSettings.app("Middleware", "RequestResponseLog", "IgnoreRequestApis").Split(',').ToList(); + var ignoreResponseApis = AppSettings.app("Middleware", "RequestResponseLog", "IgnoreResponseApis").Split(',').ToList(); + context.Request.EnableBuffering(); // 存储请求数据 - await RequestDataLog(context); + await RequestDataLog(context, ignoreRequestApis.Contains(path)); await _next(context); // 存储响应数据 - ResponseDataLog(context.Response); + ResponseDataLog(context, ignoreResponseApis.Contains(path)); } - private async Task RequestDataLog(HttpContext context) + private async Task RequestDataLog(HttpContext context, bool isIgnore) { var request = context.Request; var sr = new StreamReader(request.Body); @@ -77,10 +75,10 @@ namespace EntrustSettle.Extensions.Middlewares var logContent = new string[] { - $"●请求", + $"● 请求", $"[Path]:{request.Path}", - $"[QueryString]:{request.QueryString}", - $"[Body]:{bodyData}" + $"[QueryString]:{(isIgnore ? "略" : request.QueryString)}", + $"[Body]:{(isIgnore ? "略" : bodyData)}" }; Parallel.For(0, 1, e => { @@ -92,50 +90,31 @@ namespace EntrustSettle.Extensions.Middlewares request.Body.Position = 0; } - private void ResponseDataLog(HttpResponse response) + private void ResponseDataLog(HttpContext context, bool isIgnore) { - var responseBody = response.GetResponseBody(); + var responseBody = context.Response.GetResponseBody(); // 去除 Html //var reg = "<[^>]+>"; - if (!string.IsNullOrEmpty(responseBody)) + //if (!string.IsNullOrEmpty(responseBody)) { //var isHtml = Regex.IsMatch(responseBody, reg); var logContent = new string[] { - $"●响应", - $"[StatusCode]:{response.StatusCode}", - $"[Body]:{responseBody}", + $"● 响应", + $"[Path]:{context.Request.Path}", + $"[StatusCode]:{context.Response.StatusCode}", + $"[Body]:{(isIgnore? "略" : responseBody )}", }; Parallel.For(0, 1, e => { LogLock.OutLogAOP("RequestResponseLog", - response.HttpContext.TraceIdentifier, + context.TraceIdentifier, logContent); }); } } - - private void ResponseDataLog(HttpResponse response, MemoryStream ms) - { - ms.Position = 0; - var responseBody = new StreamReader(ms).ReadToEnd(); - - // 去除 Html - var reg = "<[^>]+>"; - var isHtml = Regex.IsMatch(responseBody, reg); - - if (!string.IsNullOrEmpty(responseBody)) - { - Parallel.For(0, 1, e => - { - //LogLock.OutSql2Log("RequestResponseLog", new string[] { "Response Data:", ResponseBody }); - LogLock.OutLogAOP("RequestResponseLog", response.HttpContext.TraceIdentifier, - new string[] { "Response Data - ResponseJsonDataType:" + responseBody.GetType().ToString(), responseBody }); - }); - } - } } } \ No newline at end of file diff --git a/EntrustSettle.Model/Dtos/Order/OrderDto.cs b/EntrustSettle.Model/Dtos/Order/OrderDto.cs index b2ff21b..d636092 100644 --- a/EntrustSettle.Model/Dtos/Order/OrderDto.cs +++ b/EntrustSettle.Model/Dtos/Order/OrderDto.cs @@ -67,7 +67,7 @@ namespace EntrustSettle.Model.Dtos /// public bool IsHasBillAnnex { get; set; } /// - /// 是否有发票附件 + /// 是否有发票附件或快递单号 /// public bool IsHasInvoiceAnnex { get; set; } } diff --git a/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs b/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs index c41e54f..f5dffa7 100644 --- a/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs +++ b/EntrustSettle.Tasks/QuartzNet/Jobs/JobHydStatusQuartz.cs @@ -100,7 +100,7 @@ namespace EntrustSettle.Tasks Status = item.status, StatusTime = DateTime.Now, CreateBy = "系统", - Remark = "(由后台任务自动设置)" + Remark = "(后台任务自动设置)" }); // 将更新后的状态及费用推送到消息队列