From d0ded5cd9bf5070a120bad58b5be21fe2ac6a4ff Mon Sep 17 00:00:00 2001
From: C3032 <C3032@BC3032>
Date: 星期六, 20 十二月 2025 16:41:09 +0800
Subject: [PATCH] test

---
 IDViewer_2D/OperateLog/OperateLogService.cs |   69 ++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/IDViewer_2D/OperateLog/OperateLogService.cs b/IDViewer_2D/OperateLog/OperateLogService.cs
new file mode 100644
index 0000000..d72e749
--- /dev/null
+++ b/IDViewer_2D/OperateLog/OperateLogService.cs
@@ -0,0 +1,69 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SmartScanner.OperateLog
+{
+    public static class OperateLogService
+    {
+        private static readonly string logDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
+        private static readonly string logFileName = $"OperationLog_{DateTime.Now:yyyyMMdd}.txt";
+
+        static OperateLogService()
+        {
+            // 纭繚鏃ュ織鐩綍瀛樺湪
+            if (!Directory.Exists(logDirectory))
+            {
+                Directory.CreateDirectory(logDirectory);
+            }
+        }
+
+        public static void LogOperation(string operationType, string operationDetails, string targetDevice = null)
+        {
+            if (UserManager.CurrentUser == null) return;
+
+            try
+            {
+                var logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} | " +
+                              $"鎿嶄綔浜哄憳: {UserManager.CurrentUser.Username} | " +
+                              $"鎿嶄綔绫诲瀷: {operationType} | " +
+                              $"鐩爣璁惧: {targetDevice ?? "N/A"} | " +
+                              $"鎿嶄綔璇︽儏: {operationDetails}";
+
+                var logPath = Path.Combine(logDirectory, logFileName);
+                File.AppendAllText(logPath, logEntry + Environment.NewLine);
+            }
+            catch (Exception ex)
+            {
+                // 绠�鍗曞鐞嗘棩蹇楀啓鍏ラ敊璇�
+                Console.WriteLine($"鏃ュ織璁板綍澶辫触: {ex.Message}");
+            }
+        }
+
+        public static string[] GetRecentLogs(int days = 7)
+        {
+            try
+            {
+                var logFiles = Directory.GetFiles(logDirectory, "OperationLog_*.txt")
+                                      .OrderByDescending(f => f)
+                                      .Take(days)
+                                      .ToList();
+
+                var allLogs = new List<string>();
+                foreach (var file in logFiles)
+                {
+                    allLogs.AddRange(File.ReadAllLines(file));
+                }
+
+                return allLogs.ToArray();
+            }
+            catch
+            {
+                return new string[0];
+            }
+        }
+    }
+}

--
Gitblit v1.9.3