feat(health): 实现媒体库 service — CRUD + 缩略图 + 裁剪
This commit is contained in:
@@ -135,6 +135,9 @@ mod m20260508_000130_fix_operator_permissions_and_nurse_devices;
|
||||
mod m20260508_000131_fix_all_role_permissions;
|
||||
mod m20260508_000132_fix_doctor_permissions_restore;
|
||||
mod m20260510_000133_create_patient_role;
|
||||
mod m20260510_000134_create_media_folder;
|
||||
mod m20260510_000135_create_media_item;
|
||||
mod m20260510_000136_create_banner;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -277,6 +280,9 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260508_000131_fix_all_role_permissions::Migration),
|
||||
Box::new(m20260508_000132_fix_doctor_permissions_restore::Migration),
|
||||
Box::new(m20260510_000133_create_patient_role::Migration),
|
||||
Box::new(m20260510_000134_create_media_folder::Migration),
|
||||
Box::new(m20260510_000135_create_media_item::Migration),
|
||||
Box::new(m20260510_000136_create_banner::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
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
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(MediaFolder::Table)
|
||||
.col(
|
||||
ColumnDef::new(MediaFolder::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(MediaFolder::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(MediaFolder::Name).string_len(100).not_null())
|
||||
.col(ColumnDef::new(MediaFolder::ParentId).uuid().null())
|
||||
.col(
|
||||
ColumnDef::new(MediaFolder::SortOrder)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaFolder::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaFolder::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(MediaFolder::CreatedBy).uuid().null())
|
||||
.col(ColumnDef::new(MediaFolder::UpdatedBy).uuid().null())
|
||||
.col(
|
||||
ColumnDef::new(MediaFolder::DeletedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaFolder::Version)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_media_folder_parent")
|
||||
.from(MediaFolder::Table, MediaFolder::ParentId)
|
||||
.to(MediaFolder::Table, MediaFolder::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_media_folder_tenant_parent")
|
||||
.table(MediaFolder::Table)
|
||||
.col(MediaFolder::TenantId)
|
||||
.col(MediaFolder::ParentId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(MediaFolder::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum MediaFolder {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
Name,
|
||||
ParentId,
|
||||
SortOrder,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
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
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(MediaItem::Table)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::Id)
|
||||
.uuid()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(MediaItem::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(MediaItem::FolderId).uuid().null())
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::Filename)
|
||||
.string_len(255)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::StoragePath)
|
||||
.string_len(500)
|
||||
.not_null()
|
||||
.unique_key(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::ThumbnailPath)
|
||||
.string_len(500)
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::ContentType)
|
||||
.string_len(100)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(MediaItem::FileSize).big_integer().not_null())
|
||||
.col(ColumnDef::new(MediaItem::Width).integer().null())
|
||||
.col(ColumnDef::new(MediaItem::Height).integer().null())
|
||||
.col(ColumnDef::new(MediaItem::AltText).string_len(255).null())
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::IsPublic)
|
||||
.boolean()
|
||||
.not_null()
|
||||
.default(false),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(MediaItem::CreatedBy).uuid().null())
|
||||
.col(ColumnDef::new(MediaItem::UpdatedBy).uuid().null())
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::DeletedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(MediaItem::Version)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_media_item_folder")
|
||||
.from(MediaItem::Table, MediaItem::FolderId)
|
||||
.to(MediaFolderRef::Table, MediaFolderRef::Id)
|
||||
.on_delete(ForeignKeyAction::SetNull),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_media_item_tenant_folder")
|
||||
.table(MediaItem::Table)
|
||||
.col(MediaItem::TenantId)
|
||||
.col(MediaItem::FolderId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_media_item_tenant_public")
|
||||
.table(MediaItem::Table)
|
||||
.col(MediaItem::TenantId)
|
||||
.col(MediaItem::IsPublic)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(MediaItem::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum MediaItem {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
FolderId,
|
||||
Filename,
|
||||
StoragePath,
|
||||
ThumbnailPath,
|
||||
ContentType,
|
||||
FileSize,
|
||||
Width,
|
||||
Height,
|
||||
AltText,
|
||||
IsPublic,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
|
||||
/// 外键引用 media_folder 表
|
||||
#[derive(DeriveIden)]
|
||||
enum MediaFolderRef {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
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
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Banner::Table)
|
||||
.col(ColumnDef::new(Banner::Id).uuid().not_null().primary_key())
|
||||
.col(ColumnDef::new(Banner::TenantId).uuid().not_null())
|
||||
.col(ColumnDef::new(Banner::MediaItemId).uuid().not_null())
|
||||
.col(ColumnDef::new(Banner::Title).string_len(100).null())
|
||||
.col(ColumnDef::new(Banner::Subtitle).string_len(255).null())
|
||||
.col(ColumnDef::new(Banner::LinkType).string_len(20).null())
|
||||
.col(ColumnDef::new(Banner::LinkTarget).string_len(500).null())
|
||||
.col(
|
||||
ColumnDef::new(Banner::SortOrder)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(0),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Banner::Status)
|
||||
.string_len(20)
|
||||
.not_null()
|
||||
.default("active"),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Banner::StartTime)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Banner::EndTime)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Banner::CreatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Banner::UpdatedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null()
|
||||
.default(Expr::current_timestamp()),
|
||||
)
|
||||
.col(ColumnDef::new(Banner::CreatedBy).uuid().null())
|
||||
.col(ColumnDef::new(Banner::UpdatedBy).uuid().null())
|
||||
.col(
|
||||
ColumnDef::new(Banner::DeletedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Banner::Version)
|
||||
.integer()
|
||||
.not_null()
|
||||
.default(1),
|
||||
)
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_banner_media_item")
|
||||
.from(Banner::Table, Banner::MediaItemId)
|
||||
.to(MediaItemRef::Table, MediaItemRef::Id)
|
||||
.on_delete(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_banner_tenant_status")
|
||||
.table(Banner::Table)
|
||||
.col(Banner::TenantId)
|
||||
.col(Banner::Status)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_banner_sort")
|
||||
.table(Banner::Table)
|
||||
.col(Banner::SortOrder)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Banner::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Banner {
|
||||
Table,
|
||||
Id,
|
||||
TenantId,
|
||||
MediaItemId,
|
||||
Title,
|
||||
Subtitle,
|
||||
LinkType,
|
||||
LinkTarget,
|
||||
SortOrder,
|
||||
Status,
|
||||
StartTime,
|
||||
EndTime,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
CreatedBy,
|
||||
UpdatedBy,
|
||||
DeletedAt,
|
||||
Version,
|
||||
}
|
||||
|
||||
/// 外键引用 media_item 表
|
||||
#[derive(DeriveIden)]
|
||||
enum MediaItemRef {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
Reference in New Issue
Block a user