yidun送检功能
This commit is contained in:
180
dao/dataengine/tencent_content_check_log_dao.go
Normal file
180
dao/dataengine/tencent_content_check_log_dao.go
Normal file
@@ -0,0 +1,180 @@
|
||||
package dataengine
|
||||
|
||||
import (
|
||||
consts "cid/consts/dataengine"
|
||||
entity "cid/model/entity/dataengine"
|
||||
yidunService "cid/service/yidun"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// TencentContentCheckLogDAO 送检日志数据访问层
|
||||
type TencentContentCheckLogDAO struct{}
|
||||
|
||||
// TencentContentCheckLog 日志DAO单例
|
||||
var TencentContentCheckLog = new(TencentContentCheckLogDAO)
|
||||
|
||||
// Create 创建送检日志
|
||||
func (d *TencentContentCheckLogDAO) Create(ctx context.Context, log *entity.TencentContentCheckLog) (int64, error) {
|
||||
r, err := g.DB("default").Model(consts.TencentContentCheckLogTable).Data(log).Insert()
|
||||
if err != nil {
|
||||
g.Log().Errorf(ctx, "创建送检日志失败: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
id, _ := r.LastInsertId()
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// UpdateStatus 更新送检状态
|
||||
func (d *TencentContentCheckLogDAO) UpdateStatus(ctx context.Context, id int64, status string, responseData string, failReason string) error {
|
||||
_, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data(map[string]interface{}{
|
||||
"status": status,
|
||||
"response_data": responseData,
|
||||
"fail_reason": failReason,
|
||||
}).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateCheckResult 更新检测结果
|
||||
func (d *TencentContentCheckLogDAO) UpdateCheckResult(ctx context.Context, id int64, suggestion, label, resultType int, checkTime int64) error {
|
||||
_, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data(map[string]interface{}{
|
||||
"status": consts.CheckStatusCompleted,
|
||||
"suggestion": suggestion,
|
||||
"label": label,
|
||||
"result_type": resultType,
|
||||
"check_time": checkTime,
|
||||
}).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetByID 根据ID获取日志
|
||||
func (d *TencentContentCheckLogDAO) GetByID(ctx context.Context, id int64) (*entity.TencentContentCheckLog, error) {
|
||||
var result entity.TencentContentCheckLog
|
||||
r, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
if err = r.Struct(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetBySourceID 根据来源ID获取日志
|
||||
func (d *TencentContentCheckLogDAO) GetBySourceID(ctx context.Context, sourceTable string, sourceID int64) ([]entity.TencentContentCheckLog, error) {
|
||||
var result []entity.TencentContentCheckLog
|
||||
r, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("source_table", sourceTable).
|
||||
Where("source_id", sourceID).
|
||||
OrderDesc("created_at").
|
||||
All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = r.Structs(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetByTaskID 根据任务ID获取日志
|
||||
func (d *TencentContentCheckLogDAO) GetByTaskID(ctx context.Context, taskID string) (*entity.TencentContentCheckLog, error) {
|
||||
var result entity.TencentContentCheckLog
|
||||
r, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("task_id", taskID).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
if err = r.Struct(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ListByStatus 根据状态获取日志列表
|
||||
func (d *TencentContentCheckLogDAO) ListByStatus(ctx context.Context, status string, page, pageSize int) ([]entity.TencentContentCheckLog, int, error) {
|
||||
var result []entity.TencentContentCheckLog
|
||||
model := g.DB("default").Model(consts.TencentContentCheckLogTable)
|
||||
|
||||
if status != "" {
|
||||
model = model.Where("status", status)
|
||||
}
|
||||
|
||||
total, err := model.Count()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
r, err := model.
|
||||
OrderDesc("created_at").
|
||||
Page(page, pageSize).
|
||||
All()
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err = r.Structs(&result); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return result, int(total), nil
|
||||
}
|
||||
|
||||
// UpdateDuration 更新耗时
|
||||
func (d *TencentContentCheckLogDAO) UpdateDuration(ctx context.Context, id int64, duration int64) error {
|
||||
_, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data("duration", duration).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateTaskID 更新任务ID
|
||||
func (d *TencentContentCheckLogDAO) UpdateTaskID(ctx context.Context, id int64, taskID string) error {
|
||||
_, err := g.DB("default").Model(consts.TencentContentCheckLogTable).
|
||||
Where("id", id).
|
||||
Data("task_id", taskID).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// GetSubmitResult 获取图片提交结果
|
||||
func (d *TencentContentCheckLogDAO) GetImageSubmitResult(ctx context.Context, id int64) (*yidunService.ImageSubmitResult, error) {
|
||||
log, err := d.GetByID(ctx, id)
|
||||
if err != nil || log == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result yidunService.ImageSubmitResult
|
||||
if err := json.Unmarshal([]byte(log.ResponseData), &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetVideoSubmitResult 获取视频提交结果
|
||||
func (d *TencentContentCheckLogDAO) GetVideoSubmitResult(ctx context.Context, id int64) (*yidunService.VideoSubmitResult, error) {
|
||||
log, err := d.GetByID(ctx, id)
|
||||
if err != nil || log == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result yidunService.VideoSubmitResult
|
||||
if err := json.Unmarshal([]byte(log.ResponseData), &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user