activity_meeting_reminder.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package cygx
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type CygxActivityMeetingReminder struct {
  8. Id int `orm:"column(id);pk"`
  9. ActivityId int `description:"活动ID"`
  10. UserId int `description:"用户ID"`
  11. CreateTime time.Time `description:"创建时间"`
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. Source int `description:"来源,1小程序,2后台添加"`
  17. }
  18. // 记录日志
  19. type CygxActivityMeetingReminderLog struct {
  20. Id int `orm:"column(id);pk"`
  21. ActivityId int `description:"活动ID"`
  22. UserId int `description:"用户ID"`
  23. CreateTime time.Time `description:"创建时间"`
  24. Mobile string `description:"手机号"`
  25. Email string `description:"邮箱"`
  26. CompanyId int `description:"公司id"`
  27. CompanyName string `description:"公司名称"`
  28. Type int `description:"操作方式,1报名,2取消报名"`
  29. }
  30. type AddMeetingReminderReq struct {
  31. List []*AddUserList
  32. ActivityIds string `description:"活动ID,多个用,隔开"`
  33. }
  34. type AddUserList struct {
  35. UserId int `description:"用户ID"`
  36. IsAppointment int `description:"是否预约纪要,1:是,0:否"`
  37. SignupType int `description:"报名方式,1预约外呼,2自主拨入,3我要报名"`
  38. }
  39. // 取消会议提醒
  40. func CancelActivityMeetingReminder(item *CygxActivityMeetingReminder) (lastId int64, err error) {
  41. o, err := orm.NewOrmUsingDB("hz_cygx").Begin()
  42. if err != nil {
  43. return
  44. }
  45. defer func() {
  46. fmt.Println(err)
  47. if err == nil {
  48. o.Commit()
  49. } else {
  50. o.Rollback()
  51. }
  52. }()
  53. //判断是否删除我的日程
  54. var countSignup int
  55. var countAppointment int
  56. sql := `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE is_cancel = 0 AND user_id=? AND activity_id=? `
  57. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countSignup)
  58. sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  59. err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countAppointment)
  60. if err != nil {
  61. return
  62. }
  63. if countSignup == 0 && countAppointment == 0 {
  64. sql = `DELETE FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  65. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  66. if err != nil {
  67. return
  68. }
  69. }
  70. sql = `DELETE FROM cygx_activity_meeting_reminder WHERE user_id=? AND activity_id=? `
  71. _, err = o.Raw(sql, item.UserId, item.ActivityId).Exec()
  72. return
  73. }
  74. // 会议提醒的人数列表
  75. func GetCygxActivityMeetingReminderList(activityId int, sqlStr string) (item []*CygxAppointmentList, err error) {
  76. o := orm.NewOrmUsingDB("hz_cygx")
  77. sql := `SELECT s.*,a.activity_time
  78. FROM
  79. cygx_activity_meeting_reminder AS s
  80. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  81. WHERE a.activity_id = ? ` + sqlStr + ` GROUP BY s.user_id ORDER BY s.create_time DESC `
  82. _, err = o.Raw(sql, activityId).QueryRows(&item)
  83. return
  84. }
  85. // 会议提醒的人数数量
  86. func GetCygxActivityMeetingReminderCount(activityId int, sqlStr string) (count int, err error) {
  87. o := orm.NewOrmUsingDB("hz_cygx")
  88. sql := `SELECT COUNT(*) FROM
  89. cygx_activity_meeting_reminder AS s
  90. LEFT JOIN cygx_activity AS a ON a.activity_id = s.activity_id
  91. WHERE
  92. s.activity_id = ? ` + sqlStr + `
  93. GROUP BY s.user_id)`
  94. sql = `SELECT COUNT(*) as count FROM (` + sql + ` a`
  95. err = o.Raw(sql, activityId).QueryRow(&count)
  96. return
  97. }
  98. // 通过ID获取会议提醒详情
  99. func GetCygxActivityMeetingReminderInfoById(id int) (item *CygxActivityMeetingReminder, err error) {
  100. o := orm.NewOrmUsingDB("hz_cygx")
  101. sql := `SELECT * FROM cygx_activity_meeting_reminder WHERE id=?`
  102. err = o.Raw(sql, id).QueryRow(&item)
  103. return
  104. }
  105. // 添加会议提醒
  106. func AddActivityMeetingReminderUser(items []*CygxActivityAppointment, itemsReminder []*CygxActivityMeetingReminder) (err error) {
  107. o := orm.NewOrmUsingDB("hz_cygx")
  108. to, err := o.Begin()
  109. if err != nil {
  110. return
  111. }
  112. defer func() {
  113. if err != nil {
  114. _ = to.Rollback()
  115. } else {
  116. _ = to.Commit()
  117. }
  118. }()
  119. //添加预约纪要部分
  120. if len(items) > 0 {
  121. for _, item := range items {
  122. var count int
  123. sql := `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  124. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  125. if err != nil {
  126. return
  127. }
  128. if count == 0 {
  129. _, err = to.Insert(item)
  130. if err != nil {
  131. return
  132. }
  133. }
  134. }
  135. }
  136. //添加会议提醒
  137. for _, item := range itemsReminder {
  138. var count int
  139. sql := `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
  140. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  141. if err != nil {
  142. return
  143. }
  144. if count == 0 {
  145. itemMy := new(CygxMySchedule)
  146. itemMy.UserId = item.UserId
  147. itemMy.ActivityId = item.ActivityId
  148. itemMy.CreateTime = time.Now()
  149. itemMy.Mobile = item.Mobile
  150. itemMy.Email = item.Email
  151. itemMy.CompanyId = item.CompanyId
  152. itemMy.CompanyName = item.CompanyName
  153. _, err = to.Insert(itemMy)
  154. if err != nil {
  155. return
  156. }
  157. }
  158. sql = `SELECT COUNT(1) AS count FROM cygx_activity_appointment WHERE user_id=? AND activity_id=? `
  159. err = to.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
  160. if err != nil {
  161. return
  162. }
  163. if count == 0 {
  164. _, err = to.Insert(item)
  165. if err != nil {
  166. return
  167. }
  168. }
  169. }
  170. return
  171. }