From 86568968476684b61521ff392a7a902196f71a97 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 4 May 2026 02:32:19 +0800 Subject: [PATCH] =?UTF-8?q?feat(health):=20patient=5Fdevices=20=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA=20=E2=80=94=20status/firmware/manufacturer/connection?= =?UTF-8?q?=5Ftype/metadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增迁移:添加 status/firmware_version/manufacturer/connection_type/metadata 列 - 更新 Entity:新增对应字段(含默认值) - 修复 device_reading_service 自动绑定设备时填充新字段 --- .../erp-health/src/entity/patient_devices.rs | 8 ++++ .../src/service/device_reading_service.rs | 5 ++ crates/erp-server/migration/src/lib.rs | 4 ++ ...000105_alter_patient_devices_add_status.rs | 47 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 crates/erp-server/migration/src/m20260504_000105_alter_patient_devices_add_status.rs diff --git a/crates/erp-health/src/entity/patient_devices.rs b/crates/erp-health/src/entity/patient_devices.rs index 0998dc2..331454c 100644 --- a/crates/erp-health/src/entity/patient_devices.rs +++ b/crates/erp-health/src/entity/patient_devices.rs @@ -26,6 +26,14 @@ pub struct Model { #[sea_orm(skip_serializing_if = "Option::is_none")] pub deleted_at: Option, pub version: i32, + pub status: String, + #[sea_orm(skip_serializing_if = "Option::is_none")] + pub firmware_version: Option, + #[sea_orm(skip_serializing_if = "Option::is_none")] + pub manufacturer: Option, + pub connection_type: String, + #[sea_orm(skip_serializing_if = "Option::is_none")] + pub metadata: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/crates/erp-health/src/service/device_reading_service.rs b/crates/erp-health/src/service/device_reading_service.rs index 2a9b17e..e42f02b 100644 --- a/crates/erp-health/src/service/device_reading_service.rs +++ b/crates/erp-health/src/service/device_reading_service.rs @@ -187,6 +187,11 @@ async fn ensure_device_binding( updated_by: Set(None), deleted_at: Set(None), version: Set(1), + status: Set("active".to_string()), + firmware_version: Set(None), + manufacturer: Set(None), + connection_type: Set("ble".to_string()), + metadata: Set(None), }; binding.insert(db).await?; } else if let Some(existing) = existing { diff --git a/crates/erp-server/migration/src/lib.rs b/crates/erp-server/migration/src/lib.rs index 326aa80..7600831 100644 --- a/crates/erp-server/migration/src/lib.rs +++ b/crates/erp-server/migration/src/lib.rs @@ -104,6 +104,8 @@ mod m20260502_000101_seed_health_dictionaries; mod m20260502_000102_seed_warning_thresholds; mod m20260502_000103_seed_follow_up_template_menu; mod m20260504_000104_create_vital_signs_daily; +mod m20260504_000105_alter_patient_devices_add_status; +mod m20260504_000106_create_api_clients; pub struct Migrator; @@ -215,6 +217,8 @@ impl MigratorTrait for Migrator { Box::new(m20260502_000102_seed_warning_thresholds::Migration), Box::new(m20260502_000103_seed_follow_up_template_menu::Migration), Box::new(m20260504_000104_create_vital_signs_daily::Migration), + Box::new(m20260504_000105_alter_patient_devices_add_status::Migration), + Box::new(m20260504_000106_create_api_clients::Migration), ] } } diff --git a/crates/erp-server/migration/src/m20260504_000105_alter_patient_devices_add_status.rs b/crates/erp-server/migration/src/m20260504_000105_alter_patient_devices_add_status.rs new file mode 100644 index 0000000..57c5f49 --- /dev/null +++ b/crates/erp-server/migration/src/m20260504_000105_alter_patient_devices_add_status.rs @@ -0,0 +1,47 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Alias::new("patient_devices")) + .add_column( + ColumnDef::new(Alias::new("status")) + .string() + .not_null() + .default("active"), + ) + .add_column(ColumnDef::new(Alias::new("firmware_version")).string()) + .add_column(ColumnDef::new(Alias::new("manufacturer")).string()) + .add_column( + ColumnDef::new(Alias::new("connection_type")) + .string() + .not_null() + .default("ble"), + ) + .add_column(ColumnDef::new(Alias::new("metadata")).json_binary()) + .to_owned(), + ) + .await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Alias::new("patient_devices")) + .drop_column(Alias::new("status")) + .drop_column(Alias::new("firmware_version")) + .drop_column(Alias::new("manufacturer")) + .drop_column(Alias::new("connection_type")) + .drop_column(Alias::new("metadata")) + .to_owned(), + ) + .await + } +}