activity_voice.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ActivityVoice 活动语音表结构体
  7. type CygxActivityVoice struct {
  8. ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
  9. ActivityId int ` description:"活动ID"`
  10. VoiceUrl string `description:"音频地址"`
  11. VoiceName string `description:"音频名称"`
  12. VoicePlaySeconds string `description:"音频时长"`
  13. CreateTime time.Time `description:"创建时间"`
  14. }
  15. // ActivityVoiceReq 音频数据
  16. type CygxActivityVoiceReq struct {
  17. Url string `description:"音频资源url地址"`
  18. Name string `description:"音频名称"`
  19. PlaySeconds string `description:"音频时长"`
  20. ActivityVoiceId int `description:"活动音频ID"`
  21. }
  22. // 添加
  23. func AddCygxActivityVoice(item *CygxActivityVoice) (newId int64, err error) {
  24. o := orm.NewOrm()
  25. newId, err = o.Insert(item)
  26. return
  27. }
  28. // 修改
  29. func UpdateCygxActivityVoice(item *CygxActivityVoice) (err error) {
  30. to := orm.NewOrm()
  31. updateParams := make(map[string]interface{})
  32. updateParams["VoiceName"] = item.VoiceName
  33. updateParams["VideoDuration"] = item.VoicePlaySeconds
  34. updateParams["VoiceUrl"] = item.VoiceUrl
  35. ptrStructOrTableName := "cygx_activity_voice"
  36. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  37. qs := to.QueryTable(ptrStructOrTableName)
  38. for expr, exprV := range whereParam {
  39. qs = qs.Filter(expr, exprV)
  40. }
  41. _, err = qs.Update(updateParams)
  42. return
  43. }
  44. // 获取数量
  45. func GetCygxActivityVoiceCount(condition string, pars []interface{}) (count int, err error) {
  46. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_voice WHERE 1= 1 `
  47. if condition != "" {
  48. sqlCount += condition
  49. }
  50. o := orm.NewOrm()
  51. err = o.Raw(sqlCount, pars).QueryRow(&count)
  52. return
  53. }
  54. // 列表
  55. func GetCygxActivityVoiceReqList(activityId int) (items []*CygxActivityVoiceReq, err error) {
  56. o := orm.NewOrm()
  57. sql := `SELECT
  58. activity_voice_id,
  59. voice_url AS url,
  60. voice_name AS name,
  61. voice_play_seconds AS play_seconds FROM cygx_activity_voice WHERE activity_id= ? `
  62. _, err = o.Raw(sql, activityId).QueryRows(&items)
  63. return
  64. }
  65. // 列表
  66. func GetActivityVoiceList(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
  67. o := orm.NewOrm()
  68. sql := ` SELECT * FROM cygx_activity_voice WHERE 1=1 `
  69. if condition != "" {
  70. sql += condition
  71. }
  72. _, err = o.Raw(sql, pars).QueryRows(&items)
  73. return
  74. }
  75. func GetCygxActivityVoiceReqDetail(activityId int) (item *CygxActivityVoice, err error) {
  76. o := orm.NewOrm()
  77. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id= ? `
  78. err = o.Raw(sql, activityId).QueryRow(&item)
  79. return
  80. }