topfans/backend/pkg/models/material.go
2026-05-16 02:42:32 +08:00

63 lines
2.5 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
// Material 素材表模型
type Material struct {
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
OssKey string `gorm:"type:varchar(255);not null;uniqueIndex;column:oss_key"`
OriginalName string `gorm:"type:varchar(255);not null;column:original_name"`
FileSize int64 `gorm:"not null;column:file_size"`
MimeType string `gorm:"type:varchar(100);not null;column:mime_type"`
Width *int `gorm:"column:width"`
Height *int `gorm:"column:height"`
Hash string `gorm:"type:varchar(64);not null;index;column:hash"`
CreatedBy int64 `gorm:"not null;index;column:created_by"`
StarID int64 `gorm:"not null;index;column:star_id"`
CreatedAt int64 `gorm:"not null;column:created_at"`
UpdatedAt int64 `gorm:"not null;column:updated_at"`
DeletedAt *int64 `gorm:"index;column:deleted_at"`
}
func (Material) TableName() string { return "materials" }
func (m *Material) BeforeCreate(tx *gorm.DB) error {
now := time.Now().UnixMilli()
m.CreatedAt = now
m.UpdatedAt = now
return nil
}
func (m *Material) BeforeUpdate(tx *gorm.DB) error {
m.UpdatedAt = time.Now().UnixMilli()
return nil
}
// AssetMaterialRelation 资产-素材关联表模型
type AssetMaterialRelation struct {
ID int64 `gorm:"primaryKey;autoIncrement;column:id"`
AssetID int64 `gorm:"not null;index:idx_amr_asset_id;column:asset_id"`
MaterialID int64 `gorm:"not null;index:idx_amr_material_id;column:material_id"`
MaterialType string `gorm:"type:varchar(50);not null;column:material_type"`
LayerOrder int `gorm:"not null;default:0;column:layer_order"`
PosX *float64 `gorm:"column:pos_x"`
PosY *float64 `gorm:"column:pos_y"`
Opacity *float64 `gorm:"default:1.0;column:opacity"`
Rotation *float64 `gorm:"default:0;column:rotation"`
ScaleX *float64 `gorm:"default:1.0;column:scale_x"`
ScaleY *float64 `gorm:"default:1.0;column:scale_y"`
Version int `gorm:"not null;default:1;column:version"`
CreatedAt int64 `gorm:"not null;column:created_at"`
UpdatedAt int64 `gorm:"not null;column:updated_at"`
DeletedAt *int64 `gorm:"index;column:deleted_at"`
Asset Asset `gorm:"foreignKey:AssetID;references:ID;constraint:OnDelete:CASCADE"`
Material Material `gorm:"foreignKey:MaterialID;references:ID;constraint:OnDelete:RESTRICT"`
}
func (AssetMaterialRelation) TableName() string { return "asset_material_relations" }