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