activity.go 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // Activity 活动表
  7. type Activity struct {
  8. ActivityId int `orm:"column(activity_id);pk" description:"活动ID"`
  9. FirstActivityTypeId int `description:"第一级的活动类型ID"`
  10. FirstActivityTypeName string `description:"第一级的活动类型名称"`
  11. ActivityTypeId int `description:"活动类型ID"`
  12. ActivityTypeName string `description:"活动类型名称"`
  13. ActivityName string `description:"活动标题"`
  14. StartTime time.Time `description:"活动开始时间"`
  15. EndTime time.Time `description:"活动结束时间"`
  16. Speaker string `description:"主讲人"`
  17. SpeakerHeadPic string `description:"主讲人头像"`
  18. SpeakerBackgroundPic string `description:"主讲人背景图"`
  19. MainlandTel string `description:"大陆拨入"`
  20. HongKongTel string `description:"香港拨入"`
  21. TaiwanTel string `description:"台湾拨入"`
  22. AmericaTel string `description:"美国拨入"`
  23. SingaporeTel string `description:"新加坡拨入"`
  24. ParticipationCode string `description:"参会密码"`
  25. LinkParticipants string `description:"参会链接"`
  26. IsLimitPeople int8 `description:"是否限制人数 1是,0否"`
  27. LimitPeopleNum int `description:"限制人数数量"`
  28. ReportId int `description:"报告链接所关联的文章ID"`
  29. ReportLink string `description:"报告链接"`
  30. ReportName string `description:"报告标题"`
  31. City string `description:"城市"`
  32. Address string `description:"活动地址"`
  33. Remarks string `description:"备注"`
  34. UserId int `description:"创建者id"`
  35. PublishStatus int8 `description:"发布状态,0未发布,1已发布"`
  36. IsSendWxMsg int8 `description:"是否推送过会议提醒微信消息,未推送:0,已推送:1"`
  37. IsSendSalonWxMsg int8 `description:"是否推送过沙龙提醒微信消息,未推送:0,已推送:1"`
  38. IsDelete int8 `description:"是否删除,0:未删除,1:已删除"`
  39. ModifyTime time.Time `description:"修改时间"`
  40. CreateTime time.Time `description:"创建时间"`
  41. QsId int `description:"全时会议关系id"`
  42. HostCode string `description:"主持人入会密码"`
  43. IsNewReport int `description:"是否关联新报告 0-否 1-是"`
  44. }
  45. // TableName 表名变更
  46. func (activityInfo *Activity) TableName() string {
  47. return "yb_activity"
  48. }
  49. // GetById 根据id获取活动详情
  50. func GetById(activityId int) (item *Activity, err error) {
  51. o := orm.NewOrm()
  52. sql := "select * from yb_activity where activity_id=? AND is_delete = 0 "
  53. err = o.Raw(sql, activityId).QueryRow(&item)
  54. return
  55. }
  56. type ActivityList struct {
  57. ActivityId int `orm:"column(activity_id);pk" description:"活动ID"`
  58. FirstActivityTypeId int `description:"第一级的活动类型ID"`
  59. FirstActivityTypeName string `description:"第一级的活动类型名称"`
  60. ActivityTypeId int `description:"活动类型ID"`
  61. ActivityTypeName string `description:"活动类型名称"`
  62. ActivityName string `description:"活动标题"`
  63. StartTime time.Time `description:"活动开始时间"`
  64. EndTime time.Time `description:"活动结束时间"`
  65. Speaker string `description:"主讲人"`
  66. MainlandTel string `description:"大陆拨入"`
  67. HongKongTel string `description:"香港拨入"`
  68. TaiwanTel string `description:"台湾拨入"`
  69. AmericaTel string `description:"美国拨入"`
  70. SingaporeTel string `description:"新加坡拨入"`
  71. ParticipationCode string `description:"参会密码"`
  72. LinkParticipants string `description:"参会链接"`
  73. IsLimitPeople int8 `description:"是否限制人数 1是,0否"`
  74. LimitPeopleNum int `description:"限制人数数量"`
  75. ReportId int `description:"报告链接所关联的文章ID"`
  76. ReportLink string `description:"报告链接"`
  77. ReportName string `description:"报告标题"`
  78. City string `description:"城市"`
  79. Address string `description:"活动地址"`
  80. Remarks string `description:"备注"`
  81. UserId int `description:"创建者id"`
  82. PublishStatus int8 `description:"发布状态,0未发布,1已发布"`
  83. IsSendWxMsg int8 `description:"是否推送过会议提醒微信消息,未推送:0,已推送:1"`
  84. IsSendSalonWxMsg int8 `description:"是否推送过沙龙提醒微信消息,未推送:0,已推送:1"`
  85. ModifyTime time.Time `description:"修改时间"`
  86. CreateTime time.Time `description:"创建时间"`
  87. VoiceList []*ActivityVoice `description:"音频文件列表"`
  88. PosterList []*ActivityPoster `description:"海报文件列表"`
  89. PermissionList []*ActivityPermission `description:"权限列表"`
  90. QsId int `description:"全时关联会议id"`
  91. HostCode string `description:"主持人入会密码"`
  92. IsNewReport int `description:"是否关联新报告 0-否 1-是"`
  93. }
  94. // GetList 获取活动列表数据
  95. func GetList(condition, order string, pars []interface{}, startSize, pageSize int) (total int, list []*ActivityList, err error) {
  96. o := orm.NewOrm()
  97. sql := "select * from yb_activity where 1=1 AND is_delete = 0 "
  98. sql += condition
  99. sql += ` order by`
  100. if order == "" {
  101. order = " start_time ASC"
  102. }
  103. sql += order
  104. totalSql := `select count(1) total from (` + sql + `) z `
  105. err = o.Raw(totalSql, pars).QueryRow(&total)
  106. if err != nil {
  107. return
  108. }
  109. sql += ` LIMIT ?,? `
  110. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  111. return
  112. }
  113. // Update 更新活动
  114. func (activityInfo *Activity) Update(cols []string) (err error) {
  115. o := orm.NewOrm()
  116. _, err = o.Update(activityInfo, cols...)
  117. return
  118. }
  119. // AddActivity 新增活动
  120. func AddActivity(activity *Activity) (err error) {
  121. o := orm.NewOrm()
  122. id, err := o.Insert(activity)
  123. if err != nil {
  124. return
  125. }
  126. activity.ActivityId = int(id)
  127. return
  128. }
  129. // AddNewActivity 添加一个新的活动
  130. func AddNewActivity(activity *Activity, activityPosterList []*ActivityPoster, activityPermissionList []*ActivityPermission) (err error) {
  131. o := orm.NewOrm()
  132. to, err := o.Begin()
  133. if err != nil {
  134. return
  135. }
  136. defer func() {
  137. if err != nil {
  138. _ = to.Rollback()
  139. } else {
  140. _ = to.Commit()
  141. }
  142. }()
  143. id, err := to.Insert(activity)
  144. if err != nil {
  145. return
  146. }
  147. activity.ActivityId = int(id)
  148. // 新增海报
  149. if len(activityPosterList) > 0 {
  150. for _, activityPoster := range activityPosterList {
  151. activityPoster.ActivityId = activity.ActivityId
  152. }
  153. _, tmpErr := to.InsertMulti(len(activityPosterList), activityPosterList)
  154. if tmpErr != nil {
  155. err = tmpErr
  156. return
  157. }
  158. }
  159. // 新增权限
  160. if len(activityPermissionList) > 0 {
  161. for _, activityPermission := range activityPermissionList {
  162. activityPermission.ActivityId = activity.ActivityId
  163. }
  164. _, tmpErr := to.InsertMulti(len(activityPermissionList), activityPermissionList)
  165. if tmpErr != nil {
  166. err = tmpErr
  167. return
  168. }
  169. }
  170. return
  171. }
  172. // UpdateActivity 更新活动
  173. func (activityInfo *Activity) UpdateActivity(cols []string, activityPosterList []*ActivityPoster, activityVoiceList []*ActivityVoice, activityPermissionList []*ActivityPermission) (err error) {
  174. o := orm.NewOrm()
  175. to, err := o.Begin()
  176. if err != nil {
  177. return
  178. }
  179. defer func() {
  180. if err != nil {
  181. _ = to.Rollback()
  182. } else {
  183. _ = to.Commit()
  184. }
  185. }()
  186. _, err = to.Update(activityInfo, cols...)
  187. if err != nil {
  188. return
  189. }
  190. //海报处理
  191. //删除旧的海报
  192. sql := "delete from yb_activity_poster where activity_id=?"
  193. _, err = to.Raw(sql, activityInfo.ActivityId).Exec()
  194. if err != nil {
  195. return
  196. }
  197. //插入新的海报
  198. if len(activityPosterList) > 0 {
  199. _, tmpErr := to.InsertMulti(len(activityPosterList), activityPosterList)
  200. if tmpErr != nil {
  201. err = tmpErr
  202. return
  203. }
  204. }
  205. //权限处理
  206. //删除旧的权限
  207. sql = "delete from yb_activity_permission where activity_id=?"
  208. _, err = to.Raw(sql, activityInfo.ActivityId).Exec()
  209. //插入新的权限
  210. if len(activityPermissionList) > 0 {
  211. _, tmpErr := to.InsertMulti(len(activityPermissionList), activityPermissionList)
  212. if tmpErr != nil {
  213. err = tmpErr
  214. return
  215. }
  216. }
  217. //音频处理
  218. //删除旧的音频
  219. sql = "delete from yb_activity_voice where activity_id=?"
  220. _, err = to.Raw(sql, activityInfo.ActivityId).Exec()
  221. //插入新的音频
  222. if len(activityVoiceList) > 0 {
  223. _, tmpErr := to.InsertMulti(len(activityVoiceList), activityVoiceList)
  224. if tmpErr != nil {
  225. err = tmpErr
  226. return
  227. }
  228. }
  229. return
  230. }
  231. // GetCountBySpeaker 获取主讲人活动次数
  232. func GetCountBySpeaker(speakerName string) (total int, err error) {
  233. o := orm.NewOrm()
  234. sql := `SELECT COUNT(1) FROM yb_activity WHERE speaker = ? AND is_delete = 0 `
  235. err = o.Raw(sql, speakerName).QueryRow(&total)
  236. return
  237. }
  238. // UpdateActivitySpeaker 更新主讲人冗余字段
  239. func UpdateActivitySpeaker(name, headPic, originName string) (err error) {
  240. o := orm.NewOrm()
  241. sql := `UPDATE yb_activity SET speaker = ?, speaker_head_pic = ? WHERE speaker = ? `
  242. _, err = o.Raw(sql, name, headPic, originName).Exec()
  243. return
  244. }