数字人项目迁移
This commit is contained in:
69
digitalhuman/dao/async_task_ref_dao.go
Normal file
69
digitalhuman/dao/async_task_ref_dao.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"digital-human/consts/public"
|
||||
"digital-human/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
)
|
||||
|
||||
var AsyncTaskRef = &asyncTaskRefDao{}
|
||||
|
||||
type asyncTaskRefDao struct{}
|
||||
|
||||
func (d *asyncTaskRefDao) Insert(ctx context.Context, ref *entity.AsyncTaskRef) (id int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).Data(ref).Insert()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// ListPending 列出待处理任务绑定(state=0/1)
|
||||
func (d *asyncTaskRefDao) ListPending(ctx context.Context, limit int) (list []*entity.AsyncTaskRef, err error) {
|
||||
if limit <= 0 {
|
||||
limit = 200
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).
|
||||
Where("deleted_at IS NULL").
|
||||
// 业务侧只维护三态:生成中/成功/失败;绑定表仅用于“待同步列表”
|
||||
WhereIn(entity.AsyncTaskRefCol.State, []int{0, 1}).
|
||||
OrderAsc(entity.AsyncTaskRefCol.UpdatedAt).
|
||||
Limit(limit).
|
||||
All()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = r.Structs(&list)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *asyncTaskRefDao) UpdateByTaskID(ctx context.Context, taskID string, data gdb.Map) (rows int64, err error) {
|
||||
// 触发 gfdb 的 updateHook 自动填充 updater,需要显式带 updater 字段
|
||||
data[entity.AsyncTaskRefCol.Updater] = ""
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).
|
||||
Where(entity.AsyncTaskRefCol.TaskID, taskID).
|
||||
Data(data).
|
||||
Update()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
func (d *asyncTaskRefDao) GetByTaskID(ctx context.Context, taskID string) (ref *entity.AsyncTaskRef, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAsyncTaskRef).
|
||||
Where(entity.AsyncTaskRefCol.TaskID, taskID).
|
||||
One()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.IsEmpty() {
|
||||
return nil, nil
|
||||
}
|
||||
err = r.Struct(&ref)
|
||||
return
|
||||
}
|
||||
128
digitalhuman/dao/audio_dao.go
Normal file
128
digitalhuman/dao/audio_dao.go
Normal file
@@ -0,0 +1,128 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"digital-human/consts"
|
||||
"digital-human/consts/public"
|
||||
"digital-human/model/dto"
|
||||
"digital-human/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var Audio = &audio{}
|
||||
|
||||
type audio struct{}
|
||||
|
||||
// Insert 插入音频
|
||||
func (d *audio) Insert(ctx context.Context, req *dto.CreateAudioReq) (id int64, err error) {
|
||||
var res *entity.Audio
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAudio).Data(&res).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
// Update 更新音频
|
||||
func (d *audio) Update(ctx context.Context, id int64, updateData *entity.Audio) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAudio).Where(entity.AudioCol.Id, id).Data(&updateData).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// UpdateStatus 更新音频状态
|
||||
func (d *audio) UpdateStatus(ctx context.Context, id int64, status consts.AudioStatus, errorMsg string, audioURL string, duration int, externalID string) (rows int64, err error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameAudio).Where(entity.AudioCol.Id, id)
|
||||
|
||||
updateData := gdb.Map{
|
||||
entity.AudioCol.Status: int(status),
|
||||
}
|
||||
if errorMsg != "" {
|
||||
updateData[entity.AudioCol.ErrorMsg] = errorMsg
|
||||
}
|
||||
if audioURL != "" {
|
||||
updateData[entity.AudioCol.AudioURL] = audioURL
|
||||
}
|
||||
if duration > 0 {
|
||||
updateData[entity.AudioCol.Duration] = duration
|
||||
}
|
||||
if externalID != "" {
|
||||
updateData[entity.AudioCol.ExternalID] = externalID
|
||||
}
|
||||
|
||||
r, err := model.Data(&updateData).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除音频
|
||||
func (d *audio) Delete(ctx context.Context, id int64) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAudio).Where(entity.AudioCol.Id, id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个音频
|
||||
func (d *audio) GetOne(ctx context.Context, id int64) (audio *entity.Audio, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameAudio).Where(entity.AudioCol.Id, id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&audio)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取音频列表
|
||||
func (d *audio) List(ctx context.Context, req *dto.ListAudioReq) (res []*entity.Audio, total int, err error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameAudio).OmitEmpty()
|
||||
|
||||
// 构建查询过滤条件
|
||||
if req.Status != consts.AudioStatusGenerating && req.Status != consts.AudioStatusSuccess && req.Status != consts.AudioStatusFailed {
|
||||
// 不添加状态过滤
|
||||
} else {
|
||||
model = model.Where(entity.AudioCol.Status+" = ?", req.Status)
|
||||
}
|
||||
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
like := "%" + req.Keyword + "%"
|
||||
model = model.Where(
|
||||
"("+entity.AudioCol.Name+
|
||||
" LIKE ? OR "+entity.AudioCol.Description+
|
||||
" LIKE ? OR "+entity.AudioCol.ScriptText+
|
||||
" LIKE ?)",
|
||||
like, like, like,
|
||||
)
|
||||
}
|
||||
|
||||
model = model.OrderDesc(entity.AudioCol.CreatedAt)
|
||||
|
||||
if req.Page != nil {
|
||||
if req.Page.PageNum <= 0 {
|
||||
req.Page.PageNum = 1
|
||||
}
|
||||
if req.Page.PageSize <= 0 {
|
||||
req.Page.PageSize = 10
|
||||
}
|
||||
model = model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
|
||||
r, total, err := model.AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
135
digitalhuman/dao/custom_voice_dao.go
Normal file
135
digitalhuman/dao/custom_voice_dao.go
Normal file
@@ -0,0 +1,135 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"digital-human/consts/public"
|
||||
"digital-human/model/dto"
|
||||
"digital-human/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/beans"
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// CustomVoice 自定义音色数据访问层
|
||||
var CustomVoice = &customVoice{}
|
||||
|
||||
type customVoice struct{}
|
||||
|
||||
// Insert 插入自定义音色
|
||||
func (d *customVoice) Insert(ctx context.Context, req *dto.CreateCustomVoiceReq) (id int64, err error) {
|
||||
var result *entity.CustomVoice
|
||||
if err = gconv.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
// 初始状态:生成中
|
||||
result.Status = 0
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice).Data(&result).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
func (d *customVoice) UpdateReferenceAudio(ctx context.Context, id int64, referenceAudio []byte) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice).
|
||||
Where(entity.CustomVoiceCol.Id, id).
|
||||
Data(gdb.Map{
|
||||
entity.CustomVoiceCol.ReferenceAudio: referenceAudio,
|
||||
}).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
func (d *customVoice) UpdateDescription(ctx context.Context, id int64, description string) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice).
|
||||
Where(entity.CustomVoiceCol.Id, id).
|
||||
Data(gdb.Map{
|
||||
entity.CustomVoiceCol.Description: description,
|
||||
}).
|
||||
Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// UpdateStatus 更新自定义音色状态/结果
|
||||
func (d *customVoice) UpdateStatus(ctx context.Context, id int64, status int, errorMsg string, ossFile string) (rows int64, err error) {
|
||||
data := gdb.Map{
|
||||
entity.CustomVoiceCol.Status: status,
|
||||
}
|
||||
if errorMsg != "" {
|
||||
data[entity.CustomVoiceCol.ErrorMsg] = errorMsg
|
||||
}
|
||||
if ossFile != "" {
|
||||
data[entity.CustomVoiceCol.OssFile] = ossFile
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice).
|
||||
Where(entity.CustomVoiceCol.Id, id).
|
||||
Data(data).
|
||||
Update()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除自定义音色
|
||||
func (d *customVoice) Delete(ctx context.Context, id int64) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice).Where(entity.CustomVoiceCol.Id, id).Delete()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// GetOne 获取单个自定义音色
|
||||
func (d *customVoice) GetOne(ctx context.Context, id int64) (customVoice *entity.CustomVoice, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice).Where(entity.CustomVoiceCol.Id, id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&customVoice)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取自定义音色列表
|
||||
func (d *customVoice) List(ctx context.Context, req *dto.ListCustomVoiceReq) (res []*entity.CustomVoice, total int, err error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameCustomVoice)
|
||||
|
||||
// 处理分页
|
||||
if req.Page == nil {
|
||||
req.Page = &beans.Page{PageNum: 1, PageSize: 20}
|
||||
}
|
||||
|
||||
r, total, err := model.OrderDesc(entity.CustomVoiceCol.CreatedAt).Page(int(req.Page.PageNum), int(req.Page.PageSize)).AllAndCount(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// GetCustomVoiceItem 转换为 DTO 列表项
|
||||
func (d *customVoice) GetCustomVoiceItem(entity *entity.CustomVoice) *dto.CustomVoiceItem {
|
||||
item := &dto.CustomVoiceItem{
|
||||
ID: gconv.String(entity.Id),
|
||||
Name: entity.Name,
|
||||
Description: entity.Description,
|
||||
Status: entity.Status,
|
||||
ErrorMsg: entity.ErrorMsg,
|
||||
OssFile: entity.OssFile,
|
||||
}
|
||||
if entity.CreatedAt != nil {
|
||||
item.CreatedAt = entity.CreatedAt
|
||||
}
|
||||
if entity.UpdatedAt != nil {
|
||||
item.UpdatedAt = entity.UpdatedAt
|
||||
}
|
||||
return item
|
||||
}
|
||||
125
digitalhuman/dao/digitalhuman_dao.go
Normal file
125
digitalhuman/dao/digitalhuman_dao.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"digital-human/consts"
|
||||
"digital-human/consts/public"
|
||||
"digital-human/model/dto"
|
||||
"digital-human/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// DigitalHuman 数字人形象数据
|
||||
var DigitalHuman = &digitalHuman{}
|
||||
|
||||
type digitalHuman struct{}
|
||||
|
||||
// Insert 插入数字人形象
|
||||
func (d *digitalHuman) Insert(ctx context.Context, req *dto.CreateDigitalHumanReq) (ids []any, err error) {
|
||||
var result entity.DigitalHuman
|
||||
if err = gconv.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).Data(&result).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
lastInsertId, err := r.LastInsertId()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ids = []any{lastInsertId}
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新数字人形象
|
||||
func (d *digitalHuman) Update(ctx context.Context, id int64, updateData *entity.DigitalHuman) (err error) {
|
||||
_, err = gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).Data(updateData).Where("id = ?", id).Update()
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新数字人形象状态
|
||||
func (d *digitalHuman) UpdateStatus(ctx context.Context, id int64, status consts.DigitalHumanStatus) (rows int64, err error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).Where("id = ?", id)
|
||||
r, err := model.Data(g.Map{"status": status}).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
// Delete 删除数字人形象
|
||||
func (d *digitalHuman) Delete(ctx context.Context, id int64) (err error) {
|
||||
_, err = gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).Where("id = ?", id).Delete()
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个数字人形象
|
||||
func (d *digitalHuman) GetOne(ctx context.Context, id int64) (digitalHuman *entity.DigitalHuman, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).Where("id = ?", id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&digitalHuman)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取数字人形象列表
|
||||
func (d *digitalHuman) List(ctx context.Context, req *dto.ListDigitalHumanReq) (res []entity.DigitalHuman, total int64, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
|
||||
var totalCount int
|
||||
totalCount, err = model.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
total = gconv.Int64(totalCount)
|
||||
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
|
||||
r, err := model.OrderDesc("id").All()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *digitalHuman) buildListFilter(ctx context.Context, req *dto.ListDigitalHumanReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).OmitEmpty()
|
||||
// 状态字段允许查询所有状态值,包括0(停用),所以需要特别处理
|
||||
if req.Status != consts.DigitalHumanStatusInactive && req.Status != consts.DigitalHumanStatusActive {
|
||||
// 如果状态不是有效值之一,则不添加状态过滤条件
|
||||
} else {
|
||||
model = model.Where("status = ?", req.Status)
|
||||
}
|
||||
if !g.IsEmpty(req.Gender) {
|
||||
model = model.Where("gender = ?", req.Gender)
|
||||
}
|
||||
if !g.IsEmpty(req.Style) {
|
||||
model = model.Where("style = ?", req.Style)
|
||||
}
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model = model.Where("name LIKE ? OR description LIKE ?", "%"+req.Keyword+"%", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
return model
|
||||
}
|
||||
|
||||
// Count 计数
|
||||
func (d *digitalHuman) Count(ctx context.Context, req *dto.CreateDigitalHumanReq) (count int64, err error) {
|
||||
var totalCount int
|
||||
totalCount, err = gfdb.DB(ctx).Model(ctx, public.TableNameDigitalHuman).Where("name = ?", req.Name).Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = gconv.Int64(totalCount)
|
||||
return
|
||||
}
|
||||
131
digitalhuman/dao/video_dao.go
Normal file
131
digitalhuman/dao/video_dao.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
"digital-human/consts"
|
||||
"digital-human/consts/public"
|
||||
"digital-human/model/dto"
|
||||
"digital-human/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
// Video 视频数据
|
||||
var Video = &video{}
|
||||
|
||||
type video struct{}
|
||||
|
||||
// Insert 插入视频
|
||||
func (d *video) Insert(ctx context.Context, req *dto.CreateVideoReq) (ids []any, err error) {
|
||||
var result entity.Video
|
||||
if err = gconv.Struct(req, &result); err != nil {
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameVideo).Data(&result).Insert()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
lastInsertId, err := r.LastInsertId()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ids = []any{lastInsertId}
|
||||
return
|
||||
}
|
||||
|
||||
// Update 更新视频
|
||||
func (d *video) Update(ctx context.Context, id int64, updateData *entity.Video) (err error) {
|
||||
_, err = gfdb.DB(ctx).Model(ctx, public.TableNameVideo).Data(updateData).Where("id = ?", id).Update()
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除视频
|
||||
func (d *video) Delete(ctx context.Context, id int64) (err error) {
|
||||
_, err = gfdb.DB(ctx).Model(ctx, public.TableNameVideo).Where("id = ?", id).Delete()
|
||||
return
|
||||
}
|
||||
|
||||
// GetOne 获取单个视频
|
||||
func (d *video) GetOne(ctx context.Context, id int64) (video *entity.Video, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameVideo).Where("id = ?", id).One()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Struct(&video)
|
||||
return
|
||||
}
|
||||
|
||||
// List 获取视频列表
|
||||
func (d *video) List(ctx context.Context, req *dto.ListVideoReq) (res []entity.Video, total int64, err error) {
|
||||
model := d.buildListFilter(ctx, req)
|
||||
|
||||
var totalCount int
|
||||
totalCount, err = model.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
total = gconv.Int64(totalCount)
|
||||
|
||||
if req.Page != nil {
|
||||
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
||||
}
|
||||
|
||||
r, err := model.OrderDesc("id").All()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = r.Structs(&res)
|
||||
return
|
||||
}
|
||||
|
||||
// buildListFilter 构建列表查询的过滤条件
|
||||
func (d *video) buildListFilter(ctx context.Context, req *dto.ListVideoReq) *gdb.Model {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameVideo).OmitEmpty()
|
||||
// 状态字段允许查询所有状态值,包括0(生成中),所以需要特别处理
|
||||
if req.Status != consts.VideoStatusGenerating && req.Status != consts.VideoStatusSuccess && req.Status != consts.VideoStatusFailed {
|
||||
// 如果状态不是有效值之一,则不添加状态过滤条件
|
||||
} else {
|
||||
model = model.Where("status = ?", req.Status)
|
||||
}
|
||||
if !g.IsEmpty(req.DigitalHumanID) {
|
||||
model = model.Where("digitalHumanId = ?", req.DigitalHumanID)
|
||||
}
|
||||
if !g.IsEmpty(req.Keyword) {
|
||||
model = model.Where("name LIKE ? OR description LIKE ?", "%"+req.Keyword+"%", "%"+req.Keyword+"%")
|
||||
}
|
||||
|
||||
return model
|
||||
}
|
||||
|
||||
// UpdateStatus 更新视频状态
|
||||
func (d *video) UpdateStatus(ctx context.Context, id int64, status consts.VideoStatus, errorMsg string, videoURL string, duration int, thumbnailURL string, externalTaskID string) (rows int64, err error) {
|
||||
model := gfdb.DB(ctx).Model(ctx, public.TableNameVideo).Where("id = ?", id)
|
||||
|
||||
updateData := gdb.Map{
|
||||
"status": status,
|
||||
}
|
||||
if errorMsg != "" {
|
||||
updateData["errorMsg"] = errorMsg
|
||||
}
|
||||
if videoURL != "" {
|
||||
updateData["videoUrl"] = videoURL
|
||||
}
|
||||
if duration > 0 {
|
||||
updateData["duration"] = duration
|
||||
}
|
||||
if thumbnailURL != "" {
|
||||
updateData["thumbnailUrl"] = thumbnailURL
|
||||
}
|
||||
if externalTaskID != "" {
|
||||
updateData["externalTaskId"] = externalTaskID
|
||||
}
|
||||
|
||||
r, err := model.Data(updateData).Update()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
Reference in New Issue
Block a user