处理异常信息展示功能
This commit is contained in:
@@ -320,25 +320,39 @@ class StatsDBOperator(BaseDBOperator):
|
||||
"""
|
||||
return self.execute_query(sql, (days, limit)) or []
|
||||
|
||||
def get_error_logs(self, days: int = 7, limit: int = 100) -> List[Dict]:
|
||||
def get_error_logs(self, days: int = 7, page: int = 1, limit: int = 20) -> Tuple[List[Dict], int]:
|
||||
"""获取错误日志
|
||||
|
||||
Args:
|
||||
days: 统计天数
|
||||
limit: 返回记录数量限制
|
||||
page: 页码
|
||||
limit: 每页数量
|
||||
|
||||
Returns:
|
||||
错误日志列表
|
||||
(日志列表, 总数)
|
||||
"""
|
||||
# 1. 获取总数
|
||||
count_sql = """
|
||||
SELECT COUNT(*) as total
|
||||
FROM t_error_logs
|
||||
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL %s DAY)
|
||||
"""
|
||||
count_result = self.execute_query(count_sql, (days,), fetch_one=True)
|
||||
total = count_result['total'] if count_result else 0
|
||||
|
||||
# 2. 获取分页数据
|
||||
offset = (page - 1) * limit
|
||||
sql = """
|
||||
SELECT id, plugin_name, command, user_id, group_id,
|
||||
error_message, stack_trace, created_at
|
||||
FROM t_error_logs
|
||||
WHERE created_at >= DATE_SUB(CURDATE(), INTERVAL %s DAY)
|
||||
ORDER BY created_at DESC
|
||||
LIMIT %s
|
||||
LIMIT %s OFFSET %s
|
||||
"""
|
||||
return self.execute_query(sql, (days, limit)) or []
|
||||
logs = self.execute_query(sql, (days, limit, offset)) or []
|
||||
|
||||
return logs, total
|
||||
|
||||
def get_error_detail(self, error_id: int) -> Optional[Dict]:
|
||||
"""获取错误详情
|
||||
|
||||
Reference in New Issue
Block a user