darker
2025-02-18 1f5df45b8e213de70e91a7ca54d6e2219cd967ca
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef ALARM_MANAGER_H
#define ALARM_MANAGER_H
 
#include <string>
#include <vector>
#include <mutex>
#include "Database.h"
 
class AlarmManager {
public:
    /**
     * »ñÈ¡µ¥ÀýʵÀý
     * @return AlarmManagerʵÀýµÄÒýÓÃ
     */
    static AlarmManager& getInstance();
 
    /**
     * ÉèÖÃÊý¾Ý¿âÁ¬½Ó
     * @param db Êý¾Ý¿âÁ¬½ÓµÄÖ¸Õë
     */
    void setDatabase(BL::Database* db);
 
    /**
     * ³õʼ»¯±¨¾¯±í
     * @return ³É¹¦·µ»Øtrue£¬Ê§°Ü·µ»Øfalse
     */
    bool initAlarmTable();
 
    /**
     * Ïú»Ù±¨¾¯±í
     */
    void termAlarmTable();
 
    /**
     * Ïú»Ù±¨¾¯±í
     * @return ³É¹¦·µ»Øtrue£¬Ê§°Ü·µ»Øfalse
     */
    bool destroyAlarmTable();
 
    /**
     * Ìí¼Ó±¨¾¯
     * @param id ±¨¾¯ID
     * @param deviceName É豸Ãû³Æ
     * @param description ±¨¾¯ÃèÊö
     * @param startTime ±¨¾¯¿ªÊ¼Ê±¼ä
     * @param endTime ±¨¾¯½áÊøÊ±¼ä
     * @return ³É¹¦·µ»Øtrue£¬Ê§°Ü·µ»Øfalse
     */
    bool addAlarm(const std::string& id, const std::string& deviceName, const std::string& description, const std::string& startTime, const std::string& endTime);
 
    /**
     * ²éѯËùÓб¨¾¯Êý¾Ý
     * @return °üº¬ËùÓб¨¾¯Êý¾ÝµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getAllAlarms();
 
    /**
     * ¸ù¾Ý±¨¾¯ID²éѯ±¨¾¯
     * @param id ±¨¾¯ID
     * @return °üº¬É¸Ñ¡ºó±¨¾¯Êý¾ÝµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getAlarmsById(const std::string& id);
 
    /**
     * ¸ù¾ÝÃèÊö²éѯ±¨¾¯
     * @param description ±¨¾¯ÃèÊöµÄɸѡÌõ¼þ
     * @return °üº¬É¸Ñ¡ºó±¨¾¯Êý¾ÝµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getAlarmsByDescription(const std::string& description);
 
    /**
     * ¸ù¾Ýʱ¼ä·¶Î§²éѯ±¨¾¯
     * @param startTime Æðʼʱ¼ä
     * @param endTime ½áÊøÊ±¼ä
     * @return °üº¬²éѯ½á¹ûµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getAlarmsByTimeRange(
        const std::string& startTime, const std::string& endTime);
 
    /**
    * ¸ù¾ÝIDºÍʱ¼ä·¶Î§²éѯ±¨¾¯
     * @param id ±¨¾¯ID
     * @param startTime Æðʼʱ¼ä
     * @param endTime ½áÊøÊ±¼ä
     * @return °üº¬²éѯ½á¹ûµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getAlarmsByIdAndTimeRange(
        const std::string& id, const std::string& startTime, const std::string& endTime);
 
    /**
     * »ñÈ¡±¨¾¯Êý¾Ý
     * @param startPosition ÆðʼλÖÃ
     * @param count »ñÈ¡µÄ¼Ç¼ÊýÁ¿
     * @return °üº¬±¨¾¯Êý¾ÝµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getAlarms(int startPosition, int count);
 
    /**
     * »ñȡɸѡºóµÄ±¨¾¯Êý¾Ý
     * @param id ±¨¾¯IDµÄɸѡÌõ¼þ
     * @param deviceName É豸Ãû³ÆµÄɸѡÌõ¼þ
     * @param description ±¨¾¯ÃèÊöµÄɸѡÌõ¼þ
     * @param startTime Æðʼʱ¼äɸѡÌõ¼þ
     * @param endTime ½áÊøÊ±¼äɸѡÌõ¼þ
     * @param pageNumber Ò³Âë
     * @param pageSize Ã¿Ò³µÄ¼Ç¼Êý
     * @return °üº¬É¸Ñ¡ºó±¨¾¯Êý¾ÝµÄ¶þά×Ö·û´®ÏòÁ¿
     */
    std::vector<std::vector<std::string>> getFilteredAlarms(
        const std::string& id,
        const std::string& deviceName,
        const std::string& description,
        const std::string& startTime,
        const std::string& endTime,
        int pageNumber,
        int pageSize);
 
    /**
     * »ñÈ¡·ûºÏÌõ¼þµÄ±¨¾¯×ÜÊý
     * @param id ±¨¾¯IDµÄɸѡÌõ¼þ
     * @param deviceName É豸Ãû³ÆµÄɸѡÌõ¼þ
     * @param description ±¨¾¯ÃèÊöµÄɸѡÌõ¼þ
     * @param startTime Æðʼʱ¼äɸѡÌõ¼þ
     * @param endTime ½áÊøÊ±¼äɸѡÌõ¼þ
     * @return ·ûºÏÌõ¼þµÄ±¨¾¯×ÜÊý
     */
    int getTotalAlarmCount(
        const std::string& id,
        const std::string& deviceName,
        const std::string& description,
        const std::string& startTime,
        const std::string& endTime);
 
    /**
     * ¸üб¨¾¯½áÊøÊ±¼ä
     * @param id ±¨¾¯ID
     * @param description ±¨¾¯ÃèÊö
     * @param startTime ±¨¾¯¿ªÊ¼Ê±¼ä
     * @param newEndTime Ðµı¨¾¯½áÊøÊ±¼ä
     * @return ³É¹¦·µ»Øtrue£¬Ê§°Ü·µ»Øfalse
     */
    bool updateAlarmEndTime(const std::string& id, const std::string& deviceName, const std::string& description, const std::string& startTime, const std::string& newEndTime);
 
    /**
     * ÇåÀí¾É±¨¾¯
     * @param daysToKeep ±£ÁôµÄÌìÊý
     * @param deviceName É豸Ãû³Æ
     */
    void cleanOldAlarms(int daysToKeep = 30, const std::string& deviceName = "");
 
private:
    AlarmManager();
    ~AlarmManager();
 
    // ½ûÖ¹¿½±´ºÍ¸³Öµ
    AlarmManager(const AlarmManager&) = delete;
    AlarmManager& operator=(const AlarmManager&) = delete;
 
    BL::Database* m_pDB;
    static std::mutex m_mutex;
};
 
#endif // ALARM_MANAGER_H