feat(health): BLE 网关后端接入 — 网关管理 + API Key 认证 + 多患者批量上报
Some checks failed
CI / rust-check (push) Has been cancelled
CI / rust-test (push) Has been cancelled
CI / frontend-build (push) Has been cancelled
CI / security-audit (push) Has been cancelled

- 新增 ble_gateways + gateway_patient_bindings 表迁移 (000113)
- 网关 CRUD:注册/编辑/删除/重生成 API Key,含患者绑定管理
- API Key 认证中间件(SHA-256 hash + prefix 快速查找)
- 网关数据上报端点:多患者批量读数,复用 device_reading_service 管道
- 网关心跳端点:固件版本/IP 更新 + last_heartbeat_at
- 10 个管理端路由(JWT)+ 2 个网关端路由(API Key)
- health.ble-gateways.list/manage 权限声明
- 修复 000112 迁移 ForeignKey 借用错误
This commit is contained in:
iven
2026-05-04 20:28:26 +08:00
parent 7b17f94bc0
commit 7e57565ecd
16 changed files with 1379 additions and 4 deletions

View File

@@ -8,7 +8,8 @@ use erp_core::module::{ErpModule, PermissionDescriptor};
use crate::handler::{
action_inbox_handler,
alert_handler, alert_rule_handler,
appointment_handler, article_category_handler, article_handler, article_tag_handler, care_plan_handler, consultation_handler, consent_handler, critical_alert_handler, critical_value_threshold_handler, daily_monitoring_handler, device_handler, device_reading_handler, diagnosis_handler, doctor_handler, follow_up_handler, follow_up_template_handler,
appointment_handler, article_category_handler, article_handler, article_tag_handler,
ble_gateway_handler, care_plan_handler, consultation_handler, consent_handler, critical_alert_handler, critical_value_threshold_handler, daily_monitoring_handler, device_handler, device_reading_handler, diagnosis_handler, doctor_handler, follow_up_handler, follow_up_template_handler,
health_data_handler, medication_record_handler, medication_reminder_handler, patient_handler, points_handler, shift_handler, stats_handler,
vital_signs_daily_handler,
};
@@ -884,6 +885,46 @@ impl HealthModule {
axum::routing::get(shift_handler::list_handoffs)
.post(shift_handler::create_handoff),
)
// BLE 网关管理
.route(
"/health/ble-gateways",
axum::routing::get(ble_gateway_handler::list_gateways)
.post(ble_gateway_handler::create_gateway),
)
.route(
"/health/ble-gateways/{gateway_id}",
axum::routing::get(ble_gateway_handler::get_gateway)
.put(ble_gateway_handler::update_gateway)
.delete(ble_gateway_handler::delete_gateway),
)
.route(
"/health/ble-gateways/{gateway_id}/regenerate-key",
axum::routing::post(ble_gateway_handler::regenerate_api_key),
)
.route(
"/health/ble-gateways/{gateway_id}/bindings",
axum::routing::get(ble_gateway_handler::list_bindings)
.post(ble_gateway_handler::bind_patient),
)
.route(
"/health/ble-gateways/{gateway_id}/bindings/batch",
axum::routing::post(ble_gateway_handler::batch_bind),
)
.route(
"/health/ble-gateways/{gateway_id}/bindings/{binding_id}",
axum::routing::delete(ble_gateway_handler::unbind_patient),
)
}
/// BLE 网关数据接入路由(裸路由,需在 erp-server 层配合 gateway_auth 中间件使用)
pub fn gateway_routes<S>() -> Router<S>
where
crate::state::HealthState: axum::extract::FromRef<S>,
S: Clone + Send + Sync + 'static,
{
Router::new()
.route("/health/gateway/upload", axum::routing::post(ble_gateway_handler::gateway_upload))
.route("/health/gateway/heartbeat", axum::routing::post(ble_gateway_handler::gateway_heartbeat))
}
}
@@ -1330,6 +1371,19 @@ impl ErpModule for HealthModule {
description: "创建/编辑班次、分配患者、创建交接记录".into(),
module: "health".into(),
},
// BLE 网关管理
PermissionDescriptor {
code: "health.ble-gateways.list".into(),
name: "查看 BLE 网关".into(),
description: "查看 BLE 网关列表、绑定患者和状态".into(),
module: "health".into(),
},
PermissionDescriptor {
code: "health.ble-gateways.manage".into(),
name: "管理 BLE 网关".into(),
description: "注册/编辑/删除 BLE 网关、管理患者绑定".into(),
module: "health".into(),
},
]
}