修正数据库错误
This commit is contained in:
parent
3b6280b7c5
commit
6ec26bfeaa
@ -764,7 +764,7 @@ class DatabaseManager:
|
||||
try:
|
||||
offset = (page - 1) * size
|
||||
cursor.execute('''
|
||||
SELECT s.id, s.status, s.start_time, u.name as creator_name
|
||||
SELECT s.id, s.status, s.start_time, u.name as creator_name,s.detection_report as detection_report
|
||||
FROM detection_sessions s
|
||||
LEFT JOIN users u ON s.creator_id = u.id
|
||||
WHERE s.patient_id = ?
|
||||
@ -772,7 +772,27 @@ class DatabaseManager:
|
||||
LIMIT ? OFFSET ?
|
||||
''', (patient_id, size, offset))
|
||||
rows = cursor.fetchall()
|
||||
|
||||
sessions = []
|
||||
for r in rows:
|
||||
try:
|
||||
item = dict(r)
|
||||
except Exception:
|
||||
# 回退:按列序映射
|
||||
item = {
|
||||
'id': r[0],
|
||||
'status': r[1],
|
||||
'start_time': r[2],
|
||||
'creator_name': r[3],
|
||||
'detection_report': r[4],
|
||||
}
|
||||
sessions.append({
|
||||
'id': item.get('id'),
|
||||
'status': item.get('status'),
|
||||
'start_time': item.get('start_time'),
|
||||
'creator_name': item.get('creator_name'),
|
||||
'detection_report': item.get('detection_report'),
|
||||
})
|
||||
return sessions
|
||||
|
||||
except Exception as e:
|
||||
@ -784,8 +804,9 @@ class DatabaseManager:
|
||||
conn = self.get_connection()
|
||||
cursor = conn.cursor()
|
||||
try:
|
||||
icursor.execute('SELECT COUNT(*) FROM detection_sessions WHERE patient_id = ?', (patient_id,))
|
||||
return cursor.fetchone()[0]
|
||||
cursor.execute('SELECT COUNT(*) FROM detection_sessions WHERE patient_id = ?', (patient_id,))
|
||||
row = cursor.fetchone()
|
||||
return int(row[0]) if row else 0
|
||||
except Exception as e:
|
||||
logger.error(f'获取会话总数失败: {e}')
|
||||
return 0
|
||||
@ -1496,9 +1517,9 @@ class DatabaseManager:
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# 检查会话状态和screen_video_path
|
||||
# 检查会话状态
|
||||
cursor.execute('''
|
||||
SELECT status, screen_video_path
|
||||
SELECT status
|
||||
FROM detection_sessions
|
||||
WHERE id = ?
|
||||
''', (session_id,))
|
||||
@ -1510,17 +1531,26 @@ class DatabaseManager:
|
||||
|
||||
session_data = dict(session_row)
|
||||
status = session_data.get('status')
|
||||
screen_video_path = session_data.get('screen_video_path')
|
||||
|
||||
logging.info(f"[is_empty_session] 会话 {session_id} 状态检查: status='{status}', screen_video_path='{screen_video_path}'")
|
||||
logging.info(f"[is_empty_session] 会话 {session_id} 状态检查: status='{status}'")
|
||||
|
||||
# 检查条件1:status是否为created
|
||||
if status != 'checking':
|
||||
logging.info(f"[is_empty_session] 会话 {session_id} 状态不是'checking',当前状态: '{status}' - 不是空白会话")
|
||||
return False
|
||||
|
||||
# 检查条件2:screen_video_path是否为空
|
||||
if screen_video_path and screen_video_path.strip():
|
||||
# 检查条件2:detection_video中是否存在屏幕录制路径
|
||||
cursor.execute('''
|
||||
SELECT screen_video FROM detection_video WHERE session_id = ? ORDER BY timestamp DESC LIMIT 1
|
||||
''', (session_id,))
|
||||
video_row = cursor.fetchone()
|
||||
screen_video_path = None
|
||||
if video_row:
|
||||
try:
|
||||
screen_video_path = (dict(video_row).get('screen_video') or '').strip()
|
||||
except Exception:
|
||||
screen_video_path = (video_row[0] or '').strip()
|
||||
if screen_video_path:
|
||||
logging.info(f"[is_empty_session] 会话 {session_id} 已有录屏路径: '{screen_video_path}' - 不是空白会话")
|
||||
return False
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user