From 74a20ea351677476cf36f927b5bf2d98dfc2793b Mon Sep 17 00:00:00 2001 From: limengnan <420004014@qq.com> Date: Thu, 11 Dec 2025 13:32:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/config.ini | 6 +++--- backend/database.py | 11 +++++++---- backend/devices/screen_recorder.py | 9 +++++---- backend/main.py | 5 +++-- frontend/src/renderer/main/preload.js | 8 ++------ frontend/src/renderer/src/views/Detection.vue | 4 ++-- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/backend/config.ini b/backend/config.ini index f718726e..f68e42aa 100644 --- a/backend/config.ini +++ b/backend/config.ini @@ -19,7 +19,7 @@ path = D:/BodyCheck/file/ [CAMERA1] enabled = True -device_index = 0 +device_index = 1 width = 1280 height = 720 fps = 30 @@ -50,12 +50,12 @@ synchronized_images_only = False [DEVICES] imu_enabled = True -imu_device_type = mock +imu_device_type = ble imu_port = COM9 imu_mac_address = ef:3c:1a:0a:fe:02 imu_baudrate = 9600 pressure_enabled = True -pressure_device_type = mock +pressure_device_type = real pressure_use_mock = False pressure_port = COM5 pressure_baudrate = 115200 diff --git a/backend/database.py b/backend/database.py index 0e21f5d4..14b07cab 100644 --- a/backend/database.py +++ b/backend/database.py @@ -233,6 +233,7 @@ class DatabaseManager: remark_info TEXT, -- 备注信息 detection_report TEXT, -- 生成检测报告的存储路径 status TEXT DEFAULT 'checking', -- 会话状态(checking/checked/diagnosed/reported) + data_ids TEXT, -- 关联的检测数据ID(逗号分隔) created_at TIMESTAMP, -- 记录创建时间 FOREIGN KEY (patient_id) REFERENCES patients (id), -- 患者表外键约束 FOREIGN KEY (creator_id) REFERENCES users (id) -- 用户表外键约束 @@ -764,7 +765,7 @@ class DatabaseManager: try: offset = (page - 1) * size cursor.execute(''' - SELECT s.id, s.status, s.start_time, u.name as creator_name,s.detection_report as detection_report + SELECT s.id, s.status, s.start_time, u.name as creator_name,s.detection_report as detection_report,s.data_ids as data_ids FROM detection_sessions s LEFT JOIN users u ON s.creator_id = u.id WHERE s.patient_id = ? @@ -785,6 +786,7 @@ class DatabaseManager: 'start_time': r[2], 'creator_name': r[3], 'detection_report': r[4], + 'data_ids': r[5] } sessions.append({ 'id': item.get('id'), @@ -792,6 +794,7 @@ class DatabaseManager: 'start_time': item.get('start_time'), 'creator_name': item.get('creator_name'), 'detection_report': item.get('detection_report'), + 'data_ids': item.get('data_ids') }) return sessions @@ -897,14 +900,14 @@ class DatabaseManager: except Exception as e: logger.error(f'获取会话数据失败: {e}') return None - def update_session_report_path(self, session_id: str, report_path: str) -> bool: + def update_session_report_path(self, session_id: str, report_path: str, data_ids: str) -> bool: """更新检测会话的报告路径并将状态置为 reported""" conn = self.get_connection() cursor = conn.cursor() try: cursor.execute( - 'UPDATE detection_sessions SET detection_report = ?, status = COALESCE(status, "reported") WHERE id = ?', - (report_path, session_id) + 'UPDATE detection_sessions SET detection_report = ?, data_ids = ?, status = COALESCE(status, "reported") WHERE id = ?', + (report_path, data_ids, session_id) ) conn.commit() return cursor.rowcount > 0 diff --git a/backend/devices/screen_recorder.py b/backend/devices/screen_recorder.py index bc7eb6c9..0483a68c 100644 --- a/backend/devices/screen_recorder.py +++ b/backend/devices/screen_recorder.py @@ -881,6 +881,7 @@ class RecordingManager: data = { 'session_id': session_id, 'head_pose': detection_data.get('head_pose'), + 'screen_location': detection_data.get('screen_location'), 'body_pose': None, 'body_image': None, 'foot_data': detection_data.get('foot_data'), @@ -927,7 +928,7 @@ class RecordingManager: except Exception as e: self.logger.error(f'保存{field}失败: {e}') # 屏幕截图 - screen_image = self._capture_screen_image(data_dir,timestamp) + screen_image = self._capture_screen_image(data_dir, data.get('screen_location'), timestamp=timestamp) if screen_image: data['screen_image'] = str(os.path.join( patient_id, session_id, f"image_{timestamp}", screen_image)) @@ -940,7 +941,7 @@ class RecordingManager: - def _capture_screen_image(self, data_dir,timestamp) -> Optional[str]: + def _capture_screen_image(self, data_dir, screen_location, timestamp) -> Optional[str]: """ 采集屏幕截图,根据screen_region 进行截图 @@ -952,9 +953,9 @@ class RecordingManager: """ try: # 截取屏幕 - if self.screen_region: + if screen_location: # 使用指定区域截图 - x, y, width, height = self.screen_region + x, y, width, height = screen_location screenshot = pyautogui.screenshot(region=(x, y, width, height)) else: # 全屏截图 diff --git a/backend/main.py b/backend/main.py index 663d4906..d39ce6e0 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1452,6 +1452,7 @@ class AppServer: if not self.db_manager: return jsonify({'success': False, 'error': '数据库管理器未初始化'}), 500 file = flask_request.files.get('file') + data_ids = flask_request.form.get('data_ids') if not file: return jsonify({'success': False, 'error': '缺少文件'}), 400 # 获取会话信息以得到 patient_id @@ -1484,7 +1485,7 @@ class AppServer: # 生成相对路径存入数据库 rel_path = os.path.join(db_base_path, filename).replace('\\', '/') - self.db_manager.update_session_report_path(session_id, rel_path) + self.db_manager.update_session_report_path(session_id, rel_path,data_ids) return jsonify({'success': True, 'path': rel_path}) except Exception as e: self.logger.error(f'上传报告失败: {e}') @@ -1568,7 +1569,7 @@ class AppServer: # 调用录制管理器保存检测截图到文件 collected_data = self.recording_manager.save_detection_images( session_id=session_id, - patient_id=patient_id, + patient_id=patient_id, detection_data=data ) diff --git a/frontend/src/renderer/main/preload.js b/frontend/src/renderer/main/preload.js index 222465b0..bb9679a1 100644 --- a/frontend/src/renderer/main/preload.js +++ b/frontend/src/renderer/main/preload.js @@ -1,11 +1,7 @@ -const { contextBridge } = require('electron'); +const { contextBridge, ipcRenderer } = require('electron'); contextBridge.exposeInMainWorld('electronAPI', { - generateReportPdf: (payload) => { - try { - return window?.electron?.ipcRenderer?.invoke('generate-report-pdf', payload) - } catch {} - }, + generateReportPdf: (payload) => ipcRenderer.invoke('generate-report-pdf', payload), getBackendUrl: () => process.env.BACKEND_URL || 'http://localhost:5000', getSocketTransports: () => { const allowPolling = process.env.ALLOW_POLLING === '1' diff --git a/frontend/src/renderer/src/views/Detection.vue b/frontend/src/renderer/src/views/Detection.vue index 1ab2c1de..2f8da51d 100644 --- a/frontend/src/renderer/src/views/Detection.vue +++ b/frontend/src/renderer/src/views/Detection.vue @@ -133,7 +133,7 @@ {{ headlist.rotation }}°