qs_event.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // QsEvent 全时会议表
  7. type QsEvent struct {
  8. QsId int `orm:"column(qs_id);pk" description:"自增id"`
  9. YbActivityId int `orm:"column(yb_activity_id)" description:"活动ID"`
  10. QsEventId int `description:"全时会议id"`
  11. Time int `description:"会议时长,单位:分"`
  12. StartTime time.Time `description:"会议开始时间"`
  13. EndTime time.Time `description:"会议结束时间"`
  14. People int `description:"实际入会人数"`
  15. QsStatus int `description:"全时会议状态,0:未开始,1:进行中,2:已完成,3:已取消"`
  16. Status int `description:"状态,0:未同步,1:已创建,2:已取消"`
  17. VideoUrl string `description:"录制的流媒体文件下载地址"`
  18. IsSync int8 `description:"是否已经同步,0:未同步,1:已同步"`
  19. ModifyTime time.Time `description:"修改时间"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ShareSellerId int `description:"分享销售ID"`
  22. }
  23. // TableName 表名变更
  24. func (qsEventInfo *QsEvent) TableName() string {
  25. return "qs_event"
  26. }
  27. // GetLastQsEventByActivityId 根据活动id获取最近的全时会议
  28. func GetLastQsEventByActivityId(activityId int) (item *QsEvent, err error) {
  29. o := orm.NewOrm()
  30. sql := "select * from qs_event where yb_activity_id=? order by qs_id desc "
  31. err = o.Raw(sql, activityId).QueryRow(&item)
  32. return
  33. }
  34. // GetQsEventByActivityId 根据活动id获取已同步的全时会议(已同步)
  35. func GetQsEventByActivityId(activityId int) (item *QsEvent, err error) {
  36. o := orm.NewOrm()
  37. sql := "select * from qs_event where yb_activity_id=? AND status = 1 "
  38. err = o.Raw(sql, activityId).QueryRow(&item)
  39. return
  40. }
  41. // GetQsEventByQsEventId 根据全时会议id获取全时会议(已同步)
  42. func GetQsEventByQsEventId(qsEventId int) (item *QsEvent, err error) {
  43. o := orm.NewOrm()
  44. sql := "select * from qs_event where qs_event_id=? "
  45. err = o.Raw(sql, qsEventId).QueryRow(&item)
  46. return
  47. }
  48. // GetQsEventByQsId 根据qs_id获取全时会议
  49. func GetQsEventByQsId(qsId int) (item *QsEvent, err error) {
  50. o := orm.NewOrm()
  51. sql := "select * from qs_event where qs_id = ? "
  52. err = o.Raw(sql, qsId).QueryRow(&item)
  53. return
  54. }
  55. // Update 更新全时会议
  56. func (qsEventInfo *QsEvent) Update(cols []string) (err error) {
  57. o := orm.NewOrm()
  58. _, err = o.Update(qsEventInfo, cols...)
  59. return
  60. }
  61. // AddQsEvent 新增更新全时会议
  62. func AddQsEvent(qsEvent *QsEvent) (err error) {
  63. o := orm.NewOrm()
  64. id, err := o.Insert(qsEvent)
  65. if err != nil {
  66. return
  67. }
  68. qsEvent.QsId = int(id)
  69. return
  70. }
  71. // GetQsEventListByActivityIds 根据活动id集合获取全时会议列表(已同步)
  72. func GetQsEventListByActivityIds(qsIds string) (list []*QsEvent, err error) {
  73. if qsIds == "" {
  74. return
  75. }
  76. o := orm.NewOrm()
  77. sql := `select * from qs_event where qs_id in (` + qsIds + `) AND status = 1 `
  78. _, err = o.Raw(sql).QueryRows(&list)
  79. return
  80. }
  81. // AddNewQsEvent 添加一个新的活动
  82. func AddNewQsEvent(activity *Activity, activityPosterList []*ActivityPoster, activityPermissionList []*ActivityPermission) (err error) {
  83. o := orm.NewOrm()
  84. to, err := o.Begin()
  85. if err != nil {
  86. return
  87. }
  88. defer func() {
  89. if err != nil {
  90. _ = to.Rollback()
  91. } else {
  92. _ = to.Commit()
  93. }
  94. }()
  95. id, err := to.Insert(activity)
  96. if err != nil {
  97. return
  98. }
  99. activity.ActivityId = int(id)
  100. // 新增海报
  101. if len(activityPosterList) > 0 {
  102. for _, activityPoster := range activityPosterList {
  103. activityPoster.ActivityId = activity.ActivityId
  104. }
  105. _, tmpErr := to.InsertMulti(len(activityPosterList), activityPosterList)
  106. if tmpErr != nil {
  107. err = tmpErr
  108. return
  109. }
  110. }
  111. // 新增权限
  112. if len(activityPermissionList) > 0 {
  113. for _, activityPermission := range activityPermissionList {
  114. activityPermission.ActivityId = activity.ActivityId
  115. }
  116. _, tmpErr := to.InsertMulti(len(activityPermissionList), activityPermissionList)
  117. if tmpErr != nil {
  118. err = tmpErr
  119. return
  120. }
  121. }
  122. return
  123. }
  124. // QsList 到会列表数据结构
  125. type QsList struct {
  126. ActivityName string `description:"活动标题"`
  127. ActivityTypeName string `description:"活动类型名称"`
  128. StartTime time.Time `description:"活动开始时间"`
  129. EndTime time.Time `description:"活动结束时间"`
  130. EventStartTime time.Time `description:"全时会议开始时间"`
  131. EventEndTime time.Time `description:"全时会议结束时间"`
  132. RealTime int64 `description:"会议实际时长"`
  133. QsStatus int8 `description:"全时会议状态,0:未开始,1:进行中,2:已完成,3:已取消"`
  134. People int `description:"实际入会人数"`
  135. ActivityId int `description:"活动ID"`
  136. QsId int `description:"关联ID"`
  137. Speaker string `description:"主讲人"`
  138. ParticipationCode string `description:"参会密码"`
  139. LinkParticipants string `description:"参会链接"`
  140. HostCode string `description:"主持人入会密码"`
  141. ShareSellerId int `description:"分享销售ID"`
  142. ShareSellerName string `description:"分享销售姓名"`
  143. }
  144. // GetQsList 获取到会列表数据
  145. func GetQsList(condition, order string, pars []interface{}, startSize, pageSize int) (total int, list []*QsList, err error) {
  146. o := orm.NewOrm()
  147. sql := "select a.activity_id,b.qs_id,a.activity_name,a.activity_type_name,a.start_time,a.end_time,a.speaker,a.participation_code,a.link_participants,a.host_code,b.start_time event_start_time,b.end_time event_end_time,b.people,b.qs_status,b.time real_time,b.share_seller_id,c.real_name as share_seller_name from yb_activity a " +
  148. "join qs_event b on a.qs_id=b.qs_id left join admin c on b.share_seller_id = c.admin_id where 1=1 AND a.is_delete = 0 and b.status=1 "
  149. sql += condition
  150. sql += ` order by`
  151. if order == "" {
  152. order = " a.end_time DESC "
  153. }
  154. sql += order
  155. totalSql := `select count(1) total from (` + sql + `) z `
  156. err = o.Raw(totalSql, pars).QueryRow(&total)
  157. if err != nil {
  158. return
  159. }
  160. sql += ` LIMIT ?,? `
  161. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  162. return
  163. }