query.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package yb_activity
  2. import (
  3. "hongze/hongze_yb/global"
  4. "time"
  5. )
  6. type ActivityItem struct {
  7. ActivityID int `json:"activityId"`
  8. FirstActivityTypeID int `json:"firstActivityTypeId"` // 第一级的活动类型ID
  9. FirstActivityTypeName string `json:"firstActivityTypeName"` // 第一级的活动类型名称
  10. ActivityName string `json:"activityName"` // 活动名称
  11. ActivityTypeID int `json:"activityTypeId"` // 活动类型ID
  12. ActivityTypeName string `json:"activityTypeName"` // 活动类型名称
  13. StartTime time.Time `json:"startTime"` // 活动开始时间
  14. EndTime time.Time `json:"endTime"` // 活动结束时间
  15. Speaker string `json:"speaker"` // 主讲人
  16. SpeakerHeadPic string `json:"speakerHeadPic"` // 主讲人头像
  17. SpeakerBackgroundPic string `json:"speakerBackgroundPic"` // 主讲人背景图
  18. City string `json:"city"` // 城市
  19. WeekString string `json:"weekString"` // 周几
  20. HasRemind int `json:"hasRemind"` // 是否已提醒
  21. HasPlayBack int `json:"hasPlayBack"` // 是否有回放
  22. RegisterState int `json:"registerState"` // 报名状态 0-取消报名 1-已报名
  23. ActivityState int `json:"activityState"` // 活动状态 1-本周预告 2-进行中 3-已结束
  24. }
  25. type ActivityDetail struct {
  26. ActivityItem
  27. MainlandTel string `json:"mainlandTel"` // 大陆拨入
  28. HongKongTel string `json:"hongKongTel"` // 香港拨入
  29. TaiwanTel string `json:"taiwanTel"` // 台湾拨入
  30. AmericaTel string `json:"americaTel"` // 美国拨入
  31. SingaporeTel string `json:"singaporeTel"` // 新加坡拨入
  32. ParticipationCode string `json:"participationCode"` // 参会密码
  33. LinkParticipants string `json:"linkParticipants"` // 参会链接
  34. IsLimitPeople int8 `json:"isLimitPeople"` // 是否限制人数 1是,0否
  35. LimitPeopleNum int `json:"limitPeopleNum"` // 限制人数数量
  36. ReportLink string `json:"reportLink"` // 报告链接
  37. ReportName string `json:"reportName"` // 报告名称
  38. Address string `json:"address"` // 活动地址
  39. RegisteredNum int `json:"registeredNum"` // 已报名人数
  40. ReportId int `json:"report_id"` // 报告ID
  41. IsNewReport int `json:"is_new_report"` // 是否关联新报告
  42. }
  43. // GetPageListByWhere 分页获取活动列表
  44. func GetPageListByWhere(condition string, pars []interface{}, page, limit int, order string, userId int) (activities []ActivityItem, err error) {
  45. fields := []string{
  46. "activity_id", "activity_name", "activity_type_id", "activity_type_name", "start_time", "end_time", "speaker",
  47. "city", "speaker_head_pic", "speaker_background_pic", "first_activity_type_id", "first_activity_type_name",
  48. }
  49. queryOrder := "start_time asc"
  50. if order != "" {
  51. queryOrder = order
  52. }
  53. err = global.DEFAULT_MYSQL.Model(YbActivity{}).Select(fields).Where(condition, pars...).Order(queryOrder).Limit(limit).Offset((page - 1) * limit).Scan(&activities).Error
  54. return
  55. }
  56. // GetDetailById 根据主键获取详情
  57. func GetDetailById(activityId int) (activity *ActivityDetail, err error) {
  58. fields := []string{
  59. "activity_id", "activity_name", "activity_type_id", "activity_type_name", "start_time", "end_time", "speaker", "city", "speaker_head_pic", "speaker_background_pic",
  60. "mainland_tel", "hong_kong_tel", "taiwan_tel", "america_tel", "singapore_tel", "participation_code", "report_id", "is_new_report",
  61. "link_participants", "is_limit_people", "limit_people_num", "report_link", "report_name", "address", "first_activity_type_id", "first_activity_type_name",
  62. }
  63. err = global.DEFAULT_MYSQL.Model(YbActivity{}).Select(fields).Where("activity_id", activityId).Scan(&activity).Error
  64. return
  65. }
  66. // GetOneById 根据主键获取活动
  67. func GetOneById(activityId int) (activity *YbActivity, err error) {
  68. err = global.DEFAULT_MYSQL.Where("activity_id = ?", activityId).First(&activity).Error
  69. return
  70. }
  71. // GetActivityByIDsAndDate 根据时间和活动ID筛选出合适的记录
  72. func GetActivityByIDsAndDate(ids []int, publishTime string) (list []*YbActivity, err error) {
  73. err = global.DEFAULT_MYSQL.Model(YbActivity{}).
  74. Select("DISTINCT activity_id").
  75. Where("activity_id in (?) and publish_status = 1 and create_time > ? and is_delete = 0", ids, publishTime).Scan(&list).Error
  76. return
  77. }
  78. // GetLatestByIds 获取最新的活动
  79. func GetLatestByIds(activityids []int) (activity *YbActivity, err error) {
  80. err = global.DEFAULT_MYSQL.Model(YbActivity{}).Where("activity_id in (?) and is_delete = 0 and publish_status = 1", activityids).Order("create_time desc").First(&activity).Error
  81. return
  82. }
  83. // GetListByIds 分页查询活动列表
  84. func GetListByIds(activityids []int, offset, limit int) (activitys []*YbActivity, err error) {
  85. err = global.DEFAULT_MYSQL.Model(YbActivity{}).
  86. Where("activity_id in (?) and is_delete = 0 and publish_status = 1", activityids).
  87. Order("create_time desc").
  88. Offset(offset).
  89. Limit(limit).
  90. Scan(&activitys).Error
  91. return
  92. }
  93. // GetListCountByIds 查询活动列表总数
  94. func GetListCountByIds(activityIds []int) (total int64, err error) {
  95. err = global.DEFAULT_MYSQL.Model(YbActivity{}).
  96. Where("activity_id in (?) and is_delete = 0 and publish_status = 1", activityIds).
  97. Count(&total).Error
  98. return
  99. }
  100. // GetLatestActivity 获取最新的活动
  101. func GetLatestActivity() (activity *YbActivity, err error) {
  102. err = global.DEFAULT_MYSQL.Model(YbActivity{}).Where("is_delete = 0 and publish_status = 1").Order("create_time desc").First(&activity).Error
  103. return
  104. }