activity_voice.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. BackgroundImg string `description:"封面图片"`
  14. ShareImg string `description:"分享图片"`
  15. IsByHand int `description:"是否手动修改过"`
  16. FileType int `description:"文件类型,1:路演回放,2:调研反馈"`
  17. CreateTime time.Time `description:"创建时间"`
  18. }
  19. // ActivityVoiceReq 音频数据
  20. type CygxActivityVoiceReq struct {
  21. Url string `description:"音频资源url地址"`
  22. Name string `description:"音频名称"`
  23. PlaySeconds string `description:"音频时长"`
  24. ActivityVoiceId int `description:"活动音频ID"`
  25. BackgroundImg string `description:"封面图片"`
  26. ShareImg string `description:"分享图片"`
  27. }
  28. // 添加
  29. func AddCygxActivityVoice(item *CygxActivityVoice) (newId int64, err error) {
  30. o := orm.NewOrmUsingDB("hz_cygx")
  31. newId, err = o.Insert(item)
  32. return
  33. }
  34. // 修改
  35. func UpdateCygxActivityVoice(item *CygxActivityVoice) (err error) {
  36. to := orm.NewOrmUsingDB("hz_cygx")
  37. updateParams := make(map[string]interface{})
  38. updateParams["VoiceName"] = item.VoiceName
  39. updateParams["VoicePlaySeconds"] = item.VoicePlaySeconds
  40. updateParams["VoiceUrl"] = item.VoiceUrl
  41. updateParams["BackgroundImg"] = item.BackgroundImg
  42. updateParams["ShareImg"] = item.ShareImg
  43. updateParams["FileType"] = item.FileType
  44. ptrStructOrTableName := "cygx_activity_voice"
  45. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  46. qs := to.QueryTable(ptrStructOrTableName)
  47. for expr, exprV := range whereParam {
  48. qs = qs.Filter(expr, exprV)
  49. }
  50. _, err = qs.Update(updateParams)
  51. return
  52. }
  53. // 获取数量
  54. func GetCygxActivityVoiceCount(condition string, pars []interface{}) (count int, err error) {
  55. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_voice WHERE 1= 1 `
  56. if condition != "" {
  57. sqlCount += condition
  58. }
  59. o := orm.NewOrmUsingDB("hz_cygx")
  60. err = o.Raw(sqlCount, pars).QueryRow(&count)
  61. return
  62. }
  63. // 获取数量
  64. func GetCygxActivityVoiceCountByActivityId(activityId int) (count int, err error) {
  65. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_voice WHERE activity_id= ? `
  66. o := orm.NewOrmUsingDB("hz_cygx")
  67. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  68. return
  69. }
  70. // 列表
  71. func GetCygxActivityVoiceReqList(activityId int) (items []*CygxActivityVoiceReq, err error) {
  72. o := orm.NewOrmUsingDB("hz_cygx")
  73. sql := `SELECT
  74. background_img,
  75. share_img,
  76. activity_voice_id,
  77. voice_url AS url,
  78. voice_name AS name,
  79. voice_play_seconds AS play_seconds FROM cygx_activity_voice WHERE activity_id= ? `
  80. _, err = o.Raw(sql, activityId).QueryRows(&items)
  81. return
  82. }
  83. // 列表
  84. func GetActivityVoiceList(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
  85. o := orm.NewOrmUsingDB("hz_cygx")
  86. sql := ` SELECT * FROM cygx_activity_voice WHERE 1=1 `
  87. if condition != "" {
  88. sql += condition
  89. }
  90. _, err = o.Raw(sql, pars).QueryRows(&items)
  91. return
  92. }
  93. // 列表
  94. func GetActivityVoiceListNew(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
  95. o := orm.NewOrmUsingDB("hz_cygx")
  96. sql := ` SELECT
  97. v.*
  98. FROM
  99. cygx_activity_voice as v
  100. INNER JOIN cygx_activity as a ON a.activity_id = v.activity_id
  101. WHERE
  102. 1= 1
  103. AND a.activity_time > '2023-09-22'
  104. AND v.voice_name NOT LIKE '%调研反馈%'
  105. AND v.voice_name NOT LIKE '%【%' `
  106. if condition != "" {
  107. sql += condition
  108. }
  109. _, err = o.Raw(sql, pars).QueryRows(&items)
  110. return
  111. }
  112. func GetCygxActivityVoiceReqDetail(activityId int) (item *CygxActivityVoice, err error) {
  113. o := orm.NewOrmUsingDB("hz_cygx")
  114. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id= ? `
  115. err = o.Raw(sql, activityId).QueryRow(&item)
  116. return
  117. }
  118. // 删除数据
  119. func DeleteCygxActivityVoice(activityId int) (err error) {
  120. o := orm.NewOrmUsingDB("hz_cygx")
  121. sql := ` DELETE FROM cygx_activity_voice WHERE activity_id= ? `
  122. _, err = o.Raw(sql, activityId).Exec()
  123. return
  124. }
  125. // 根据音频ID获取详情
  126. func GetCygxActivityVoiceReqDetailByActivityVoiceId(activityVoiceId int) (item *CygxActivityVoice, err error) {
  127. o := orm.NewOrmUsingDB("hz_cygx")
  128. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id= ? `
  129. err = o.Raw(sql, activityVoiceId).QueryRow(&item)
  130. return
  131. }
  132. // 根据活动ID获取详情
  133. func GetCygxActivityVoiceReqDetailByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  134. o := orm.NewOrmUsingDB("hz_cygx")
  135. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id= ? `
  136. err = o.Raw(sql, activityId).QueryRow(&item)
  137. return
  138. }