From b690250002ee04f4309e6a90fd16fbfd9bd959e2 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期五, 01 五月 2026 23:11:23 +0800
Subject: [PATCH] feat(router): 添加托盘操作页面路由
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs | 58 ++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs
index d047780..8426635 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/Middlewares/ApiLogMiddleware.cs
@@ -1,14 +1,8 @@
锘縰sing Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
-using Org.BouncyCastle.Asn1.Ocsp;
-using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Net;
using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
using WIDESEA_Core.Helper;
using WIDESEA_Core.LogHelper;
@@ -20,13 +14,34 @@
public class ApiLogMiddleware
{
/// <summary>
- ///
+ /// 涓嶅啓鍏� Sys_Log 琛ㄧ殑鎺ュ彛璺緞锛堝彧鍐欐枃浠舵棩蹇楋級
+ /// </summary>
+ private static readonly string[] _apiLogSkipPaths =
+ {
+ "InOrOutCompleted",
+ "SendLocationStatus",
+ "RequestOutbound",
+ "GetPalletCodeCell",
+ "GetOutBoundTrayTask"
+ };
+
+ /// <summary>
+ ///
/// </summary>
private readonly RequestDelegate _next;
public ApiLogMiddleware(RequestDelegate next, ILogger<ApiLogMiddleware> logger)
{
_next = next;
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇褰撳墠璇锋眰璺緞鏄惁鍦ㄨ烦杩囨暟鎹簱鏃ュ織鍒楄〃涓�
+ /// </summary>
+ private static bool IsApiLogSkipPath(string? path)
+ {
+ if (string.IsNullOrEmpty(path)) return false;
+ return _apiLogSkipPaths.Any(skip => path.Contains(skip));
}
//todo
@@ -51,7 +66,7 @@
var json = new WebResponseContent();
json.Message = HttpStatusCode.InternalServerError.ToString();//閿欒淇℃伅
- json.Code = 500;//500寮傚父
+ json.Code = 500;//500寮傚父
StreamWriter streamWriter = new StreamWriter(context.Response.Body);
await streamWriter.WriteAsync(json.Serialize());
@@ -74,7 +89,7 @@
try
{
// 瀛樺偍璇锋眰鏁版嵁
- requestParam = RequestDataLog(context);
+ requestParam = await RequestDataLogAsync(context);
context.Request.Body.Position = 0;
}
catch { }
@@ -86,14 +101,15 @@
try
{
// 瀛樺偍鍝嶅簲鏁版嵁
- responseParam = ResponseDataLog(context.Response);
+ responseParam = await ResponseDataLogAsync(context.Response);
}
catch { }
ms.Position = 0;
await ms.CopyToAsync(originalBody);
- if (!ignoreUrls.Any(x => context.Request.Path.Value?.Contains(x) ?? false))
+ if (!ignoreUrls.Any(x => context.Request.Path.Value?.Contains(x) ?? false)
+ && !IsApiLogSkipPath(context.Request.Path.Value))
{
Logger.Add(requestParam, responseParam);
}
@@ -101,7 +117,6 @@
catch (Exception ex)
{
// 璁板綍寮傚父
-
}
finally
{
@@ -114,20 +129,23 @@
}
}
- private string RequestDataLog(HttpContext context)
+ private async Task<string> RequestDataLogAsync(HttpContext context)
{
var request = context.Request;
+ //request.EnableBuffering();
+ //request.Body.Position = 0;
- var sr = new StreamReader(request.Body);
+ var sr = new StreamReader(request.Body, Encoding.UTF8);
object obj;
- string bodyData = sr.ReadToEndAsync().Result;
+ string bodyData = await sr.ReadToEndAsync();
if (request.ContentLength <= 100000)
{
obj = new
{
QueryString = request.QueryString.ToString(),
- BodyData = bodyData
+ BodyData = JsonConvert.DeserializeObject(bodyData)
+ //BodyData = bodyData
};
}
else
@@ -145,17 +163,17 @@
return data; ;
}
- private string ResponseDataLog(HttpResponse response)
+ private async Task<string> ResponseDataLogAsync(HttpResponse response)
{
if (response.ContentLength <= 100000)
{
response.Body.Position = 0;
- using StreamReader stream = new StreamReader(response.Body, leaveOpen: true);
- string body = stream.ReadToEnd();
+ using StreamReader stream = new StreamReader(response.Body, Encoding.UTF8, leaveOpen: true);
+ string body = await stream.ReadToEndAsync();
response.Body.Position = 0;
return body;
}
return "";
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3