2025-12-20 21:42:58 +08:00
|
|
|
|
package dao
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// RecognitionLogProvider 第三方服务提供商
|
|
|
|
|
|
type RecognitionLogProvider string
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
ProviderMathpix RecognitionLogProvider = "mathpix"
|
|
|
|
|
|
ProviderSiliconflow RecognitionLogProvider = "siliconflow"
|
|
|
|
|
|
ProviderTexpixel RecognitionLogProvider = "texpixel"
|
2025-12-25 14:02:06 +08:00
|
|
|
|
ProviderBaiduOCR RecognitionLogProvider = "baidu_ocr"
|
2025-12-20 21:42:58 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// RecognitionLog 识别调用日志表,记录第三方API调用请求和响应
|
|
|
|
|
|
type RecognitionLog struct {
|
|
|
|
|
|
BaseModel
|
|
|
|
|
|
TaskID int64 `gorm:"column:task_id;bigint;not null;default:0;index;comment:关联任务ID" json:"task_id"`
|
|
|
|
|
|
Provider RecognitionLogProvider `gorm:"column:provider;varchar(32);not null;comment:服务提供商" json:"provider"`
|
|
|
|
|
|
RequestBody string `gorm:"column:request_body;type:longtext;comment:请求体" json:"request_body"`
|
|
|
|
|
|
ResponseBody string `gorm:"column:response_body;type:longtext;comment:响应体" json:"response_body"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (RecognitionLog) TableName() string {
|
|
|
|
|
|
return "recognition_log"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type RecognitionLogDao struct{}
|
|
|
|
|
|
|
|
|
|
|
|
func NewRecognitionLogDao() *RecognitionLogDao {
|
|
|
|
|
|
return &RecognitionLogDao{}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create 创建日志记录
|
|
|
|
|
|
func (d *RecognitionLogDao) Create(tx *gorm.DB, log *RecognitionLog) error {
|
|
|
|
|
|
return tx.Create(log).Error
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetByTaskID 根据任务ID获取日志
|
|
|
|
|
|
func (d *RecognitionLogDao) GetByTaskID(tx *gorm.DB, taskID int64) ([]*RecognitionLog, error) {
|
|
|
|
|
|
var logs []*RecognitionLog
|
|
|
|
|
|
err := tx.Where("task_id = ?", taskID).Order("created_at DESC").Find(&logs).Error
|
|
|
|
|
|
return logs, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetByProvider 根据提供商获取日志
|
|
|
|
|
|
func (d *RecognitionLogDao) GetByProvider(tx *gorm.DB, provider RecognitionLogProvider, limit int) ([]*RecognitionLog, error) {
|
|
|
|
|
|
var logs []*RecognitionLog
|
|
|
|
|
|
err := tx.Where("provider = ?", provider).Order("created_at DESC").Limit(limit).Find(&logs).Error
|
|
|
|
|
|
return logs, err
|
|
|
|
|
|
}
|