feat: 音色管理
This commit is contained in:
@@ -13,7 +13,7 @@ type CategoryService struct{}
|
||||
|
||||
// GetCategoryList 获取分类列表
|
||||
func (s *CategoryService) GetCategoryList(info radioReq.GetCategoryList) ([]radio.RadioCategory, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioCategory{})
|
||||
db := global.DB.Model(&radio.RadioCategory{}).Where("status = ?", 1)
|
||||
var list []radio.RadioCategory
|
||||
var total int64
|
||||
|
||||
@@ -50,7 +50,7 @@ func (s *CategoryService) GetCategoryTree() ([]radio.RadioCategory, error) {
|
||||
|
||||
func (s *CategoryService) GetAllCategory() ([]radio.RadioCategory, error) {
|
||||
var res []radio.RadioCategory
|
||||
err := global.DB.Find(&res).Error
|
||||
err := global.DB.Where("status = ?", 1).Find(&res).Error
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
type ChannelService struct{}
|
||||
|
||||
func (s *ChannelService) GetFreeChannelList(req common.PageInfo) ([]radio.RadioChannel, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioChannel{}).Where("is_free = 1")
|
||||
db := global.DB.Model(&radio.RadioChannel{}).Where("is_free = 1").Where("status = ?", 1)
|
||||
var list []radio.RadioChannel
|
||||
var total int64
|
||||
err := db.Count(&total).Error
|
||||
@@ -33,7 +33,7 @@ func (s *ChannelService) GetFreeChannelList(req common.PageInfo) ([]radio.RadioC
|
||||
|
||||
// GetChannelList 获取频道列表
|
||||
func (s *ChannelService) GetChannelList(userId string, info radioReq.GetChannelList) ([]radio.RadioChannel, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioChannel{})
|
||||
db := global.DB.Model(&radio.RadioChannel{}).Where("status = ?", 1)
|
||||
var list []radio.RadioChannel
|
||||
var total int64
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ type ProgramService struct{}
|
||||
|
||||
// GetProgramList 获取节目列表
|
||||
func (s *ProgramService) GetProgramList(info radioReq.GetProgramList) ([]radio.RadioProgram, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioProgram{}).Preload("Audio")
|
||||
db := global.DB.Model(&radio.RadioProgram{}).Where("status = ?", 1).Preload("Audio")
|
||||
var list []radio.RadioProgram
|
||||
var total int64
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/radio"
|
||||
radioReq "sundynix-go/model/radio/request"
|
||||
radioRes "sundynix-go/model/radio/response"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -12,8 +11,8 @@ import (
|
||||
type VoiceService struct{}
|
||||
|
||||
// GetVoiceList 获取音色列表
|
||||
func (s *VoiceService) GetVoiceList(req radioReq.GetVoiceList) ([]radioRes.VoiceResponse, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioVoice{})
|
||||
func (s *VoiceService) GetVoiceList(req radioReq.GetVoiceList) ([]radio.RadioVoice, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioVoice{}).Preload("Audio")
|
||||
var list []radio.RadioVoice
|
||||
var total int64
|
||||
|
||||
@@ -34,51 +33,14 @@ func (s *VoiceService) GetVoiceList(req radioReq.GetVoiceList) ([]radioRes.Voice
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 转换为响应结构
|
||||
var resp []radioRes.VoiceResponse
|
||||
for _, v := range list {
|
||||
resp = append(resp, radioRes.VoiceResponse{
|
||||
Id: v.Id,
|
||||
SpeakerId: v.SpeakerId,
|
||||
Name: v.Name,
|
||||
Description: v.Description,
|
||||
Gender: v.Gender,
|
||||
Icon: v.Icon,
|
||||
AudioId: v.AudioId,
|
||||
Sort: v.Sort,
|
||||
Status: v.Status,
|
||||
IsDefault: v.IsDefault,
|
||||
UseCount: v.UseCount,
|
||||
})
|
||||
}
|
||||
return resp, total, nil
|
||||
return list, total, nil
|
||||
}
|
||||
|
||||
// GetVoiceById 获取音色详情
|
||||
func (s *VoiceService) GetVoiceById(id string) (*radioRes.VoiceDetailResponse, error) {
|
||||
func (s *VoiceService) GetVoiceById(id string) (*radio.RadioVoice, error) {
|
||||
var voice radio.RadioVoice
|
||||
err := global.DB.Preload("Audio").Where("id = ?", id).First(&voice).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &radioRes.VoiceDetailResponse{
|
||||
Id: voice.Id,
|
||||
SpeakerId: voice.SpeakerId,
|
||||
Name: voice.Name,
|
||||
Description: voice.Description,
|
||||
Gender: voice.Gender,
|
||||
Icon: voice.Icon,
|
||||
AudioId: voice.AudioId,
|
||||
Audio: voice.Audio,
|
||||
Sort: voice.Sort,
|
||||
Status: voice.Status,
|
||||
IsDefault: voice.IsDefault,
|
||||
UseCount: voice.UseCount,
|
||||
CreateTime: voice.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdateTime: voice.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
}, nil
|
||||
return &voice, err
|
||||
}
|
||||
|
||||
// GetVoiceBySpeakerId 根据SpeakerId获取音色
|
||||
@@ -100,30 +62,19 @@ func (s *VoiceService) GetDefaultVoice() (*radio.RadioVoice, error) {
|
||||
}
|
||||
|
||||
// GetAllEnabledVoice 获取所有启用的音色(前端选择用)
|
||||
func (s *VoiceService) GetAllEnabledVoice() ([]radioRes.VoiceResponse, error) {
|
||||
func (s *VoiceService) GetAllEnabledVoice() ([]radio.RadioVoice, error) {
|
||||
var list []radio.RadioVoice
|
||||
err := global.DB.Where("status = ?", 1).Order("sort ASC").Find(&list).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []radioRes.VoiceResponse
|
||||
for _, v := range list {
|
||||
resp = append(resp, radioRes.VoiceResponse{
|
||||
Id: v.Id,
|
||||
SpeakerId: v.SpeakerId,
|
||||
Name: v.Name,
|
||||
Gender: v.Gender,
|
||||
Icon: v.Icon,
|
||||
IsDefault: v.IsDefault,
|
||||
})
|
||||
}
|
||||
return resp, nil
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// SaveVoice 保存音色
|
||||
func (s *VoiceService) SaveVoice(req radioReq.SaveVoice) error {
|
||||
return global.DB.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
// 如果设置为默认音色,先取消其他默认
|
||||
if req.IsDefault == 1 {
|
||||
if err := tx.Model(&radio.RadioVoice{}).Where("is_default = ?", 1).Update("is_default", 0).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user