44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
|
|
from common.msg_db_helper import DBHelper
|
|||
|
|
from PySide6.QtCore import QMutex
|
|||
|
|
|
|||
|
|
"""
|
|||
|
|
消息管理器: 系统状态消息 和 预警消息
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
class MessageRecorder:
|
|||
|
|
_instance = None # 单例模式
|
|||
|
|
_mutex = QMutex()
|
|||
|
|
|
|||
|
|
def __new__(cls):
|
|||
|
|
cls._mutex.lock()
|
|||
|
|
try:
|
|||
|
|
if not cls._instance:
|
|||
|
|
cls._instance = super().__new__(cls)
|
|||
|
|
cls._instance.db = DBHelper()
|
|||
|
|
finally:
|
|||
|
|
cls._mutex.unlock()
|
|||
|
|
return cls._instance
|
|||
|
|
|
|||
|
|
def normal_record(self, content, is_processed=0):
|
|||
|
|
"""记录系统状态消息"""
|
|||
|
|
self.db.insert_message(content, message_type=1, is_processed=is_processed)
|
|||
|
|
|
|||
|
|
def warning_record(self, content, is_processed=0):
|
|||
|
|
"""记录预警消息"""
|
|||
|
|
self.db.insert_message(content, message_type=2, is_processed=is_processed)
|
|||
|
|
|
|||
|
|
def update_warning_status(self, content, is_processed=1):
|
|||
|
|
"""更新预警消息的处理状态: is_processed为1表示已经处理, 字体变为灰色"""
|
|||
|
|
self.db.update_processed_status(content, message_type=2, is_processed=is_processed)
|
|||
|
|
|
|||
|
|
def update_normal_status(self, content, is_processed=1):
|
|||
|
|
"""更新系统消息的处理状态: is_processed为1表示已经处理, 字体变为灰色"""
|
|||
|
|
self.db.update_processed_status(content, message_type=1, is_processed=is_processed)
|
|||
|
|
|
|||
|
|
def get_latest_normal_messages(self, limit=16):
|
|||
|
|
"""获取最新的系统状态消息(message_type=1), limit为获取的消息的条数, 默认16条"""
|
|||
|
|
return self.db.get_latest_messages(message_type=1, limit=limit)
|
|||
|
|
|
|||
|
|
def get_latest_warning_messages(self, limit=16):
|
|||
|
|
"""获取最新的预警消息(message_type=2), limit为获取的消息的条数, 默认16条"""
|
|||
|
|
return self.db.get_latest_messages(message_type=2, limit=limit)
|