49 lines
2.7 KiB
Go
49 lines
2.7 KiB
Go
// Package model 提供 transcribe 模块的数据库模型
|
||
package model
|
||
|
||
import "time"
|
||
|
||
// Transcript 会议录制语音转写结果,对应 meeting_transcripts 表
|
||
//
|
||
// 一对一关联 meeting_recordings.id(unique 索引),同一段录制只保留最新一份转写结果,
|
||
// 重新触发转写会就地更新(保持状态机:pending → running → ready/failed)。
|
||
//
|
||
// 字段设计:
|
||
// - Text:拼接后的全文,便于列表/搜索
|
||
// - Segments:JSONB 数组 [{start,end,text}],便于按时间轴渲染字幕
|
||
// - Provider/ModelCode:本次实际使用的 LLM 配置快照,调试/审计用
|
||
// - ErrorMsg:失败原因(HTTP 错误 / Key 不可用 / 文件下载失败等)
|
||
//
|
||
// PostgreSQL JSONB 字段在 GORM 里用 string 承载,由 service 层 json.Marshal/Unmarshal。
|
||
type Transcript struct {
|
||
ID int64 `json:"id" gorm:"primaryKey;autoIncrement"`
|
||
RecordingID int64 `json:"recording_id" gorm:"not null;uniqueIndex:uk_transcripts_recording"` // 唯一关联录制
|
||
RoomID int64 `json:"room_id" gorm:"not null;index:idx_transcripts_room"` // 冗余 room_id 便于按会议批量查
|
||
Status string `json:"status" gorm:"size:16;not null;default:pending"` // pending / running / ready / failed
|
||
Text string `json:"text" gorm:"type:text;not null;default:''"`
|
||
Segments string `json:"segments" gorm:"type:jsonb;not null;default:'[]'"` // JSON 数组字符串
|
||
Language string `json:"language" gorm:"size:16;not null;default:''"`
|
||
DurationSec int `json:"duration_sec" gorm:"not null;default:0"`
|
||
ProviderCode string `json:"provider_code" gorm:"size:32;not null;default:''"` // 来自 t_llm_provider.provider_code
|
||
ModelCode string `json:"model_code" gorm:"size:64;not null;default:''"` // 来自 t_llm_model.model_code
|
||
KeyID int64 `json:"key_id" gorm:"not null;default:0"` // 来自 t_llm_key.id,便于追踪 key 用量
|
||
ErrorMsg string `json:"error_msg" gorm:"size:512;not null;default:''"`
|
||
StartedAt *time.Time `json:"started_at" gorm:"type:timestamp(0)"`
|
||
FinishedAt *time.Time `json:"finished_at" gorm:"type:timestamp(0)"`
|
||
CreatedAt time.Time `json:"created_at" gorm:"not null;autoCreateTime;type:timestamp(0)"`
|
||
UpdatedAt time.Time `json:"updated_at" gorm:"not null;autoUpdateTime;type:timestamp(0)"`
|
||
}
|
||
|
||
// TableName 指定数据库表名
|
||
func (Transcript) TableName() string {
|
||
return "meeting_transcripts"
|
||
}
|
||
|
||
// 状态常量
|
||
const (
|
||
TranscriptStatusPending = "pending"
|
||
TranscriptStatusRunning = "running"
|
||
TranscriptStatusReady = "ready"
|
||
TranscriptStatusFailed = "failed"
|
||
)
|