通过分镜json剪辑视频
This commit is contained in:
111
dao/video/cut_task_dao.go
Normal file
111
dao/video/cut_task_dao.go
Normal file
@@ -0,0 +1,111 @@
|
||||
package video
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
dto "media/model/dto/video"
|
||||
entity "media/model/entity/video"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var CutTask = new(cutTaskDao)
|
||||
|
||||
type cutTaskDao struct{}
|
||||
|
||||
const cutTaskTable = "cut_task"
|
||||
|
||||
// Insert 创建任务(排除 id 字段,让数据库自增)
|
||||
func (d *cutTaskDao) Insert(ctx context.Context, data *entity.CutTask) (id int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, cutTaskTable).
|
||||
Data(data).
|
||||
FieldsEx(entity.CutTaskCols.Id).
|
||||
Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// GetByTaskID 根据taskId查询任务
|
||||
func (d *cutTaskDao) GetByTaskID(ctx context.Context, taskID string) (res *entity.CutTask, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, cutTaskTable).
|
||||
Where(entity.CutTaskCols.TaskID, taskID).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r == nil {
|
||||
return nil, nil
|
||||
}
|
||||
err = r.Struct(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateRunning 更新为运行中
|
||||
func (d *cutTaskDao) UpdateRunning(ctx context.Context, taskID string) error {
|
||||
_, err := gfdb.DB(ctx).Model(ctx, cutTaskTable).
|
||||
Data(g.Map{
|
||||
entity.CutTaskCols.Status: "running",
|
||||
}).
|
||||
Where(entity.CutTaskCols.TaskID, taskID).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateSuccess 更新为成功
|
||||
func (d *cutTaskDao) UpdateSuccess(ctx context.Context, taskID string, fileURL string, fileSize int64, fileName, fileFormat, fileAddrPrefix, durationStr string) error {
|
||||
_, err := gfdb.DB(ctx).Model(ctx, cutTaskTable).
|
||||
Data(g.Map{
|
||||
entity.CutTaskCols.Status: "success",
|
||||
entity.CutTaskCols.FileURL: fileURL,
|
||||
entity.CutTaskCols.FileSize: fileSize,
|
||||
entity.CutTaskCols.FileName: fileName,
|
||||
entity.CutTaskCols.FileFormat: fileFormat,
|
||||
entity.CutTaskCols.FileAddressPrefix: fileAddrPrefix,
|
||||
entity.CutTaskCols.DurationStr: durationStr,
|
||||
entity.CutTaskCols.ErrorMessage: "",
|
||||
}).
|
||||
Where(entity.CutTaskCols.TaskID, taskID).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateError 更新为失败
|
||||
func (d *cutTaskDao) UpdateError(ctx context.Context, taskID string, errMsg string) error {
|
||||
_, err := gfdb.DB(ctx).Model(ctx, cutTaskTable).
|
||||
Data(g.Map{
|
||||
entity.CutTaskCols.Status: "failed",
|
||||
entity.CutTaskCols.ErrorMessage: errMsg,
|
||||
}).
|
||||
Where(entity.CutTaskCols.TaskID, taskID).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// EntityToTaskRes 实体转DTO
|
||||
func CutEntityToTaskRes(e *entity.CutTask) *dto.GetCutTaskRes {
|
||||
res := &dto.GetCutTaskRes{
|
||||
TaskID: e.TaskID,
|
||||
Status: e.Status,
|
||||
CreatedAt: gconv.Int64(e.CreatedAt.Timestamp()),
|
||||
}
|
||||
if e.CreatedAt == nil {
|
||||
res.CreatedAt = time.Now().UnixMilli()
|
||||
}
|
||||
if e.Status == "success" {
|
||||
res.FileURL = e.FileURL
|
||||
res.FileSize = e.FileSize
|
||||
res.FileName = e.FileName
|
||||
res.FileFormat = e.FileFormat
|
||||
res.FileAddressPrefix = e.FileAddressPrefix
|
||||
res.DurationStr = e.DurationStr
|
||||
}
|
||||
if e.Status == "failed" {
|
||||
res.ErrorMessage = e.ErrorMessage
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user