feat(health): BLE 网关后端接入 — 网关管理 + API Key 认证 + 多患者批量上报
- 新增 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:
39
crates/erp-health/src/entity/ble_gateway.rs
Normal file
39
crates/erp-health/src/entity/ble_gateway.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "ble_gateways")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub gateway_id: String,
|
||||
pub name: String,
|
||||
pub api_key_hash: String,
|
||||
pub api_key_prefix: String,
|
||||
pub status: String,
|
||||
pub firmware_version: Option<String>,
|
||||
pub ip_address: Option<String>,
|
||||
pub last_heartbeat_at: Option<DateTimeUtc>,
|
||||
pub metadata: Option<serde_json::Value>,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::gateway_patient_binding::Entity")]
|
||||
GatewayPatientBinding,
|
||||
}
|
||||
|
||||
impl Related<super::gateway_patient_binding::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::GatewayPatientBinding.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
51
crates/erp-health/src/entity/gateway_patient_binding.rs
Normal file
51
crates/erp-health/src/entity/gateway_patient_binding.rs
Normal file
@@ -0,0 +1,51 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "gateway_patient_bindings")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub tenant_id: Uuid,
|
||||
pub gateway_id_fk: Uuid,
|
||||
pub patient_id: Uuid,
|
||||
pub peripheral_mac: Option<String>,
|
||||
pub device_type: Option<String>,
|
||||
pub status: String,
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub created_by: Option<Uuid>,
|
||||
pub updated_by: Option<Uuid>,
|
||||
pub deleted_at: Option<DateTimeUtc>,
|
||||
pub version: i32,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::ble_gateway::Entity",
|
||||
from = "Column::GatewayIdFk",
|
||||
to = "super::ble_gateway::Column::Id"
|
||||
)]
|
||||
BleGateway,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::patient::Entity",
|
||||
from = "Column::PatientId",
|
||||
to = "super::patient::Column::Id"
|
||||
)]
|
||||
Patient,
|
||||
}
|
||||
|
||||
impl Related<super::ble_gateway::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::BleGateway.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::patient::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Patient.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod alert_rules;
|
||||
pub mod ble_gateway;
|
||||
pub mod api_client;
|
||||
pub mod alerts;
|
||||
pub mod appointment;
|
||||
@@ -23,6 +24,7 @@ pub mod follow_up_record;
|
||||
pub mod follow_up_task;
|
||||
pub mod follow_up_template;
|
||||
pub mod follow_up_template_field;
|
||||
pub mod gateway_patient_binding;
|
||||
pub mod health_record;
|
||||
pub mod health_trend;
|
||||
pub mod lab_report;
|
||||
|
||||
Reference in New Issue
Block a user