chenluhua1980
2026-01-06 0e6f46c82c3f01e4a1b371dbb952f017a7cf42b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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 initSystemLogTable();
 
    // ÖÕÖ¹Êý¾Ý¿âÁ¬½Ó
    void termSystemLogTable();
 
    // Ìí¼ÓÈÕÖ¾
    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