activity_voice.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 GetCygxActivityVoiceReqList(activityId int) (items []*CygxActivityVoiceReq, err error) {
  65. o := orm.NewOrmUsingDB("hz_cygx")
  66. sql := `SELECT
  67. background_img,
  68. share_img,
  69. activity_voice_id,
  70. voice_url AS url,
  71. voice_name AS name,
  72. voice_play_seconds AS play_seconds FROM cygx_activity_voice WHERE activity_id= ? `
  73. _, err = o.Raw(sql, activityId).QueryRows(&items)
  74. return
  75. }
  76. // 列表
  77. func GetActivityVoiceList(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
  78. o := orm.NewOrmUsingDB("hz_cygx")
  79. sql := ` SELECT * FROM cygx_activity_voice WHERE 1=1 `
  80. if condition != "" {
  81. sql += condition
  82. }
  83. _, err = o.Raw(sql, pars).QueryRows(&items)
  84. return
  85. }
  86. // 列表
  87. func GetActivityVoiceListNew(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
  88. o := orm.NewOrmUsingDB("hz_cygx")
  89. sql := ` SELECT
  90. v.*
  91. FROM
  92. cygx_activity_voice as v
  93. INNER JOIN cygx_activity as a ON a.activity_id = v.activity_id
  94. WHERE
  95. 1= 1
  96. AND a.activity_time > '2023-09-22'
  97. AND v.voice_name NOT LIKE '%调研反馈%'
  98. AND v.voice_name NOT LIKE '%【%' `
  99. if condition != "" {
  100. sql += condition
  101. }
  102. _, err = o.Raw(sql, pars).QueryRows(&items)
  103. return
  104. }
  105. func GetCygxActivityVoiceReqDetail(activityId int) (item *CygxActivityVoice, err error) {
  106. o := orm.NewOrmUsingDB("hz_cygx")
  107. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id= ? `
  108. err = o.Raw(sql, activityId).QueryRow(&item)
  109. return
  110. }
  111. // 删除数据
  112. func DeleteCygxActivityVoice(activityId int) (err error) {
  113. o := orm.NewOrmUsingDB("hz_cygx")
  114. sql := ` DELETE FROM cygx_activity_voice WHERE activity_id= ? `
  115. _, err = o.Raw(sql, activityId).Exec()
  116. return
  117. }
  118. // 根据音频ID获取详情
  119. func GetCygxActivityVoiceReqDetailByActivityVoiceId(activityVoiceId int) (item *CygxActivityVoice, err error) {
  120. o := orm.NewOrmUsingDB("hz_cygx")
  121. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id= ? `
  122. err = o.Raw(sql, activityVoiceId).QueryRow(&item)
  123. return
  124. }
  125. // 根据活动ID获取详情
  126. func GetCygxActivityVoiceReqDetailByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  127. o := orm.NewOrmUsingDB("hz_cygx")
  128. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id= ? `
  129. err = o.Raw(sql, activityId).QueryRow(&item)
  130. return
  131. }