package cygx

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// ActivityVoice 活动语音表结构体
type CygxActivityVoice struct {
	ActivityVoiceId  int       `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
	ActivityId       int       ` description:"活动ID"`
	VoiceUrl         string    `description:"音频地址"`
	VoiceName        string    `description:"音频名称"`
	VoicePlaySeconds string    `description:"音频时长"`
	CreateTime       time.Time `description:"创建时间"`
}

// ActivityVoiceReq 音频数据
type CygxActivityVoiceReq struct {
	Url             string `description:"音频资源url地址"`
	Name            string `description:"音频名称"`
	PlaySeconds     string `description:"音频时长"`
	ActivityVoiceId int    `description:"活动音频ID"`
}

// 列表
func GetCygxActivityVoiceReqList(activityId int) (items []*CygxActivityVoiceReq, err error) {
	o := orm.NewOrm()
	sql := `SELECT 
			activity_voice_id,
			voice_url AS url,
			voice_name AS name,
			voice_play_seconds AS play_seconds  FROM cygx_activity_voice  WHERE activity_id= ? `
	_, err = o.Raw(sql, activityId).QueryRows(&items)
	return
}

// 列表
func GetActivityVoiceList(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
	o := orm.NewOrm()
	sql := ` SELECT  * FROM  cygx_activity_voice  WHERE  1=1  `
	if condition != "" {
		sql += condition
	}
	_, err = o.Raw(sql, pars).QueryRows(&items)
	return
}

func GetCygxActivityVoiceReqDetail(activityId int) (item *CygxActivityVoice, err error) {
	o := orm.NewOrm()
	sql := `SELECT *  FROM cygx_activity_voice  WHERE activity_id= ? `
	err = o.Raw(sql, activityId).QueryRow(&item)
	return
}
