45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type RecognitionResult struct {
|
|
BaseModel
|
|
TaskID int64 `gorm:"column:task_id;bigint;not null;default:0;comment:任务ID" json:"task_id"`
|
|
TaskType TaskType `gorm:"column:task_type;varchar(16);not null;comment:任务类型;default:''" json:"task_type"`
|
|
Latex string `json:"latex" gorm:"column:latex;type:text;not null;default:''"`
|
|
Markdown string `json:"markdown" gorm:"column:markdown;type:text;not null;default:''"` // Mathpix Markdown 格式
|
|
MathML string `json:"mathml" gorm:"column:mathml;type:text;not null;default:''"` // MathML 格式
|
|
}
|
|
|
|
type RecognitionResultDao struct {
|
|
}
|
|
|
|
func NewRecognitionResultDao() *RecognitionResultDao {
|
|
return &RecognitionResultDao{}
|
|
}
|
|
|
|
// 模型方法
|
|
func (dao *RecognitionResultDao) Create(tx *gorm.DB, data RecognitionResult) error {
|
|
return tx.Create(&data).Error
|
|
}
|
|
|
|
func (dao *RecognitionResultDao) GetByTaskID(tx *gorm.DB, taskID int64) (result *RecognitionResult, err error) {
|
|
result = &RecognitionResult{}
|
|
err = tx.Where("task_id = ?", taskID).First(result).Error
|
|
if err != nil && err == gorm.ErrRecordNotFound {
|
|
return nil, nil
|
|
}
|
|
return
|
|
}
|
|
|
|
func (dao *RecognitionResultDao) GetByTaskIDs(tx *gorm.DB, taskIDs []int64) (results []*RecognitionResult, err error) {
|
|
err = tx.Where("task_id IN (?)", taskIDs).Find(&results).Error
|
|
return
|
|
}
|
|
|
|
func (dao *RecognitionResultDao) Update(tx *gorm.DB, id int64, updates map[string]interface{}) error {
|
|
return tx.Model(&RecognitionResult{}).Where("id = ?", id).Updates(updates).Error
|
|
}
|