From bcf9bb239b20aad23a0f4dfe8074b6fdf69f0a37 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 16 四月 2025 09:29:27 +0800
Subject: [PATCH] 123

---
 项目资料/项目图纸/前段线体点位图/08三楼输送布局点位图1107.DWG.lck                                     |    0 
 项目资料/项目图纸/前段线体点位图/08三楼输送布局点位图1107.dwg.bak                                     |    0 
 CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs |   37 ++++++++++++++++++++++++++++++++-----
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
index 5033cc1..ed6b061 100644
--- a/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
+++ b/CodeManagement/WMS/WIDESEA_WMSServer/WIDESEA_Common/HttpClient/HttpsClient.cs
@@ -5,11 +5,24 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Timers;
+using Timer = System.Timers.Timer;
 
 namespace WIDESEA_Common;
 
 public class HttpsClient
 {
+    private static readonly Timer cleanupTimer;
+
+    static HttpsClient()
+    {
+        // 璁剧疆瀹氭椂鍣紝姣�10鍒嗛挓娓呯悊涓�娆equestTracker鐨勬暟鎹�
+        cleanupTimer = new Timer(10 * 60 * 1000);
+        cleanupTimer.Elapsed += CleanupRequestTracker;
+        cleanupTimer.AutoReset = true;
+        cleanupTimer.Enabled = true;
+    }
+
     private static readonly LogFactory LogFactory = new LogFactory();
 
     // 灏佽涓�涓敤HttpClient鍙戦�丟ET璇锋眰鐨勬柟娉曟湁鍙傛暟
@@ -44,23 +57,24 @@
 
     // 鐢ㄤ簬杩借釜姣忎釜璇锋眰鐨勮皟鐢ㄦ鏁板拰鏈�鍚庤姹傛椂闂淬��
     private static readonly Dictionary<string, (int Count, DateTime LastRequestTime)> requestTracker = new();
+
     // 灏佽涓�涓敤HttpClient鍙戦�丳ost璇锋眰鐨勬柟娉曟湁鍙傛暟
     public static async Task<string> PostAsync(string url, Dictionary<string, object> parameters)
     {
         // 鍒涘缓涓�涓柊鐨勫瓧鍏革紝鎺掗櫎 RequestTime 鍜� SessionId
-        var filteredParameters = parameters.Where(p => p.Key != "RequestTime"&& p.Key != "SessionId").ToDictionary(p => p.Key, p => p.Value);
+        var filteredParameters = parameters.Where(p => p.Key != "RequestTime" && p.Key != "SessionId").ToDictionary(p => p.Key, p => p.Value);
 
         string requestKey = $"{url}:{JsonConvert.SerializeObject(filteredParameters)}";
-        // 妫�鏌ヨ姹傛鏁板拰鏃堕棿闄愬埗 
+        // 妫�鏌ヨ姹傛鏁板拰鏃堕棿闄愬埗
         if (requestTracker.TryGetValue(requestKey, out var requestInfo))
         {
-            if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(10))
+            if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(5))
             {
                 // 濡傛灉璇锋眰娆℃暟瓒呰繃闄愬埗涓旀湭瓒呰繃10鍒嗛挓锛屾姏鍑哄紓甯�
                 Console.WriteLine("璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��");
                 Console.WriteLine($"鎺ュ彛鍦板潃锛歿url}");
                 Console.WriteLine($"璇锋眰鏁版嵁锛歿JsonConvert.SerializeObject(filteredParameters, Formatting.Indented)}");
-                throw new Exception($"鎺ュ彛鍦板潃锛歿url}---璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��"); 
+                throw new Exception($"鎺ュ彛鍦板潃锛歿url}---璇锋眰娆℃暟宸茶揪鍒伴檺鍒讹紝璇风◢鍚庡啀璇曘��");
             }
         }
 
@@ -73,7 +87,6 @@
         {
             requestTracker[requestKey] = (1, DateTime.Now);
         }
-
 
         // 璁板綍璇锋眰鍙傛暟
         LogRequestParameters(parameters, url);
@@ -137,4 +150,18 @@
         }
     }
 
+    // 娓呯悊requestTracker鐨勬柟娉�
+    private static void CleanupRequestTracker(object sender, ElapsedEventArgs e)
+    {
+        // 鑾峰彇褰撳墠鏃堕棿
+        DateTime now = DateTime.Now;
+
+        // 閬嶅巻骞舵竻鐞唕equestTracker涓秴杩�10鍒嗛挓鐨勮褰�
+        var keysToRemove = requestTracker.Keys.Where(key => now > requestTracker[key].LastRequestTime.AddMinutes(10)).ToList();
+
+        foreach (var key in keysToRemove)
+        {
+            requestTracker.Remove(key);
+        }
+    }
 }
\ No newline at end of file
diff --git "a/\351\241\271\347\233\256\350\265\204\346\226\231/\351\241\271\347\233\256\345\233\276\347\272\270/\345\211\215\346\256\265\347\272\277\344\275\223\347\202\271\344\275\215\345\233\276/08\344\270\211\346\245\274\350\276\223\351\200\201\345\270\203\345\261\200\347\202\271\344\275\215\345\233\2761107.DWG.lck" "b/\351\241\271\347\233\256\350\265\204\346\226\231/\351\241\271\347\233\256\345\233\276\347\272\270/\345\211\215\346\256\265\347\272\277\344\275\223\347\202\271\344\275\215\345\233\276/08\344\270\211\346\245\274\350\276\223\351\200\201\345\270\203\345\261\200\347\202\271\344\275\215\345\233\2761107.DWG.lck"
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ "b/\351\241\271\347\233\256\350\265\204\346\226\231/\351\241\271\347\233\256\345\233\276\347\272\270/\345\211\215\346\256\265\347\272\277\344\275\223\347\202\271\344\275\215\345\233\276/08\344\270\211\346\245\274\350\276\223\351\200\201\345\270\203\345\261\200\347\202\271\344\275\215\345\233\2761107.DWG.lck"
diff --git "a/\351\241\271\347\233\256\350\265\204\346\226\231/\351\241\271\347\233\256\345\233\276\347\272\270/\345\211\215\346\256\265\347\272\277\344\275\223\347\202\271\344\275\215\345\233\276/08\344\270\211\346\245\274\350\276\223\351\200\201\345\270\203\345\261\200\347\202\271\344\275\215\345\233\2761107.dwg.bak" "b/\351\241\271\347\233\256\350\265\204\346\226\231/\351\241\271\347\233\256\345\233\276\347\272\270/\345\211\215\346\256\265\347\272\277\344\275\223\347\202\271\344\275\215\345\233\276/08\344\270\211\346\245\274\350\276\223\351\200\201\345\270\203\345\261\200\347\202\271\344\275\215\345\233\2761107.dwg.bak"
new file mode 100644
index 0000000..c15b6a8
--- /dev/null
+++ "b/\351\241\271\347\233\256\350\265\204\346\226\231/\351\241\271\347\233\256\345\233\276\347\272\270/\345\211\215\346\256\265\347\272\277\344\275\223\347\202\271\344\275\215\345\233\276/08\344\270\211\346\245\274\350\276\223\351\200\201\345\270\203\345\261\200\347\202\271\344\275\215\345\233\2761107.dwg.bak"
Binary files differ

--
Gitblit v1.9.3