From 1318cc77e20a82b3328aa82ea6b8d8ca600de44f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 10 六月 2025 15:51:55 +0800
Subject: [PATCH] 1. 拆分数据库,每一个管理类是单独的数据库文件 2. 修复复制产生的ID错误

---
 SourceCode/Bond/Servo/SystemLogManager.h |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/SystemLogManager.h b/SourceCode/Bond/Servo/SystemLogManager.h
new file mode 100644
index 0000000..5ae9ab0
--- /dev/null
+++ b/SourceCode/Bond/Servo/SystemLogManager.h
@@ -0,0 +1,73 @@
+#ifndef SYSTEM_LOG_MANAGER_H
+#define SYSTEM_LOG_MANAGER_H
+
+#include <string>
+#include <vector>
+#include <mutex>
+#include "Database.h"
+
+// 系统日志管理类
+class SystemLogManager {
+public:
+    // 日志类型定义
+    enum class LogType {
+        Info,
+        Error,
+        Operation,
+        Unknown
+    };
+
+    // 获取单例实例
+    static SystemLogManager& getInstance();
+
+    // 初始化日志表
+    bool initializeLogTable();
+
+    // 添加日志
+    bool log(LogType logType, const std::string& event);
+    bool log(LogType logType, const std::string& event, const std::string& username);
+
+    // 获取日志内容
+    std::vector<std::vector<std::string>> getLogs(int startPosition = -1, int count = -1);
+
+    // 获取筛选后的日志数据
+    std::vector<std::vector<std::string>> getFilteredLogs(
+        const std::string& logType,
+        const std::string& username,
+        const std::string& description,
+        const std::string& startTime,
+        const std::string& endTime,
+        int pageNumber,
+        int pageSize);
+
+    // 获取符合条件的日志总数
+    int getTotalLogCount(
+        const std::string& logType,
+        const std::string& username,
+        const std::string& description,
+        const std::string& startTime,
+        const std::string& endTime);
+
+    // 清理超过指定天数的旧日志
+    void cleanOldLogs(int daysToKeep = 30);
+
+    // 转换日志类型为字符串
+    static std::string logTypeToString(LogType logType);
+
+private:
+    // 构造函数和析构函数
+    SystemLogManager();
+    ~SystemLogManager();
+
+    // 禁止拷贝和赋值
+    SystemLogManager(const SystemLogManager&) = delete;
+    SystemLogManager& operator=(const SystemLogManager&) = delete;
+
+    // 数据库连接
+    BL::Database* m_pDB = nullptr;
+
+    // 线程安全锁
+    static std::mutex m_mutex;
+};
+
+#endif // SYSTEM_LOG_MANAGER_H
\ No newline at end of file

--
Gitblit v1.9.3