208 lines
5.4 KiB
Go
208 lines
5.4 KiB
Go
package radio
|
|
|
|
import (
|
|
"sundynix-go/global"
|
|
common "sundynix-go/model/commom/request"
|
|
"sundynix-go/model/commom/response"
|
|
"sundynix-go/model/radio/request"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type VoiceApi struct{}
|
|
|
|
// GetVoiceList 获取音色列表
|
|
// @Tags 音色管理
|
|
// @Summary 获取音色列表
|
|
// @Produce application/json
|
|
// @Param data body request.GetVoiceList true "分页查询"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/list [post]
|
|
func (a *VoiceApi) GetVoiceList(c *gin.Context) {
|
|
var req request.GetVoiceList
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
|
|
list, total, err := voiceService.GetVoiceList(req)
|
|
if err != nil {
|
|
global.Logger.Error("获取音色列表失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithData(response.PageResult{
|
|
List: list,
|
|
Total: total,
|
|
Page: req.Current,
|
|
PageSize: req.PageSize,
|
|
}, c)
|
|
}
|
|
|
|
// GetVoiceDetail 获取音色详情
|
|
// @Tags 音色管理
|
|
// @Summary 获取音色详情
|
|
// @Produce application/json
|
|
// @Param id query string true "音色ID"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/detail [get]
|
|
func (a *VoiceApi) GetVoiceDetail(c *gin.Context) {
|
|
id := c.Query("id")
|
|
if id == "" {
|
|
response.FailWithMsg("参数错误: id不能为空", c)
|
|
return
|
|
}
|
|
|
|
voice, err := voiceService.GetVoiceById(id)
|
|
if err != nil {
|
|
global.Logger.Error("获取音色详情失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithData(voice, c)
|
|
}
|
|
|
|
// GetVoiceOptions 获取音色选项列表(前端下拉选择用)
|
|
// @Tags 音色管理
|
|
// @Summary 获取音色选项列表
|
|
// @Produce application/json
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/options [get]
|
|
func (a *VoiceApi) GetVoiceOptions(c *gin.Context) {
|
|
list, err := voiceService.GetAllEnabledVoice()
|
|
if err != nil {
|
|
global.Logger.Error("获取音色列表失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithData(response.ListResult{
|
|
List: list,
|
|
}, c)
|
|
}
|
|
|
|
// SaveVoice 保存音色
|
|
// @Tags 音色管理
|
|
// @Summary 保存音色
|
|
// @Accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.SaveVoice true "音色信息"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/save [post]
|
|
func (a *VoiceApi) SaveVoice(c *gin.Context) {
|
|
var req request.SaveVoice
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
if err := voiceService.SaveVoice(req); err != nil {
|
|
global.Logger.Error("保存音色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("保存成功", c)
|
|
}
|
|
|
|
// UpdateVoice 更新音色
|
|
// @Tags 音色管理
|
|
// @Summary 更新音色
|
|
// @Accept application/json
|
|
// @Produce application/json
|
|
// @Param data body request.UpdateVoice true "音色信息"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/update [post]
|
|
func (a *VoiceApi) UpdateVoice(c *gin.Context) {
|
|
var req request.UpdateVoice
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: "+err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 如果修改了speakerId,检查是否与其他音色冲突
|
|
if req.SpeakerId != "" {
|
|
existing, _ := voiceService.GetVoiceBySpeakerId(req.SpeakerId)
|
|
if existing != nil && existing.Id != req.Id {
|
|
response.FailWithMsg("该音色ID已被其他音色使用", c)
|
|
return
|
|
}
|
|
}
|
|
|
|
if err := voiceService.UpdateVoice(req); err != nil {
|
|
global.Logger.Error("更新音色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("更新成功", c)
|
|
}
|
|
|
|
// DeleteVoice 删除音色
|
|
// @Tags 音色管理
|
|
// @Summary 删除音色
|
|
// @Produce json
|
|
// @Param data body common.IdsReq true "音色ID列表"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/delete [post]
|
|
func (a *VoiceApi) DeleteVoice(c *gin.Context) {
|
|
var req common.IdsReq
|
|
err := c.ShouldBindJSON(&req)
|
|
if err != nil {
|
|
response.FailWithMsg("参数错误: id不能为空", c)
|
|
return
|
|
}
|
|
|
|
if err := voiceService.DeleteVoice(req.Ids); err != nil {
|
|
global.Logger.Error("删除音色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("删除成功", c)
|
|
}
|
|
|
|
// GetDefaultVoice 获取默认音色
|
|
// @Tags 音色管理
|
|
// @Summary 获取默认音色
|
|
// @Produce application/json
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/default [get]
|
|
func (a *VoiceApi) GetDefaultVoice(c *gin.Context) {
|
|
voice, err := voiceService.GetDefaultVoice()
|
|
if err != nil {
|
|
global.Logger.Error("获取默认音色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithData(voice, c)
|
|
}
|
|
|
|
// SetDefaultVoice 设置默认音色
|
|
// @Tags 音色管理
|
|
// @Summary 设置默认音色
|
|
// @Produce json
|
|
// @Param id query string true "音色ID"
|
|
// @Success 200 {object} response.Response
|
|
// @Router /radio/voice/set-default [post]
|
|
func (a *VoiceApi) SetDefaultVoice(c *gin.Context) {
|
|
id := c.Query("id")
|
|
if id == "" {
|
|
response.FailWithMsg("参数错误: id不能为空", c)
|
|
return
|
|
}
|
|
|
|
if err := voiceService.SetDefaultVoice(id); err != nil {
|
|
global.Logger.Error("设置默认音色失败!", zap.Error(err))
|
|
response.FailWithMsg(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
response.OkWithMsg("设置成功", c)
|
|
}
|