数字人项目迁移
This commit is contained in:
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
|
||||
}
|
||||
Reference in New Issue
Block a user