public_meeting.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package roadshow
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. )
  5. //公开会议总览
  6. //公开会议总览
  7. type PublicMeetingView struct {
  8. RsCalendarId int `description:"日历活动id"`
  9. MinTime string `description:"活动最小时间"`
  10. MaxTime string `description:"活动最大时间"`
  11. }
  12. //获取公开会议
  13. func GetPublicMeetingList(endDate string) (list []*PublicMeetingView, err error) {
  14. sql := ` SELECT a.rs_calendar_id,min(DATE_FORMAT(CONCAT(b.start_date," ",b.start_time),'%Y-%m-%d %H:%i:%S')) AS min_time,max(DATE_FORMAT(CONCAT(b.end_date," ",b.end_time),'%Y-%m-%d %H:%i:%S')) AS max_time
  15. FROM rs_calendar AS a
  16. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  17. WHERE a.source=0 AND activity_type='公开会议' AND b.status in (1,2)
  18. AND b.end_date>=?
  19. group by a.rs_calendar_id `
  20. o := orm.NewOrm()
  21. _, err = o.Raw(sql, endDate).QueryRows(&list)
  22. return
  23. }
  24. func ModifyCalendarUnionCode(unionCode string, rsCalendarId int) (err error) {
  25. sql := ` UPDATE rs_calendar SET union_code=? WHERE rs_calendar_id=? `
  26. o := orm.NewOrm()
  27. _, err = o.Raw(sql, unionCode, rsCalendarId).Exec()
  28. if err != nil {
  29. return err
  30. }
  31. sql = ` UPDATE rs_calendar_researcher SET union_code=? WHERE rs_calendar_id=? `
  32. _, err = o.Raw(sql, unionCode, rsCalendarId).Exec()
  33. if err != nil {
  34. return err
  35. }
  36. return
  37. }
  38. func GetCoincideMeeting(startTime, endTime string) (list []*PublicMeetingView, err error) {
  39. sql := ` SELECT * FROM (
  40. SELECT a.rs_calendar_id,MIN(DATE_FORMAT(CONCAT(b.start_date," ",b.start_time),'%Y-%m-%d %H:%i:%S')) AS min_time,MAX(DATE_FORMAT(CONCAT(b.end_date," ",b.end_time),'%Y-%m-%d %H:%i:%S')) AS max_time
  41. FROM rs_calendar AS a
  42. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  43. WHERE a.source=0 AND activity_type='公开会议' AND b.status in (1,2)
  44. GROUP BY a.rs_calendar_id
  45. ) AS t
  46. WHERE (t.min_time<=? AND t.max_time>=?) OR (?>=t.min_time AND ?<=t.max_time) or
  47. (t.min_time >= ? AND t.max_time <=?) `
  48. o := orm.NewOrm()
  49. _, err = o.Raw(sql, startTime, startTime, endTime, endTime, startTime, endTime).QueryRows(&list)
  50. return
  51. }
  52. func GetCoincideMeetingMinAndMaxTime(startTime, endTime string) (min_time, max_time string, err error) {
  53. sql := ` select min(t.min_time) as min_time,max(t.max_time) as max_time from (
  54. SELECT a.rs_calendar_id,MIN(DATE_FORMAT(CONCAT(b.start_date," ",b.start_time),'%Y-%m-%d %H:%i:%S')) AS min_time,MAX(DATE_FORMAT(CONCAT(b.end_date," ",b.end_time),'%Y-%m-%d %H:%i:%S')) AS max_time
  55. FROM rs_calendar AS a
  56. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  57. WHERE a.source=0 AND activity_type='公开会议' AND b.status in (1,2)
  58. GROUP BY a.rs_calendar_id
  59. )as t
  60. where (t.min_time<=? AND t.max_time>=?) OR (?>=t.min_time AND ?<=t.max_time) `
  61. o := orm.NewOrm()
  62. err = o.Raw(sql, startTime, startTime, endTime, endTime).QueryRow(&min_time, &max_time)
  63. return
  64. }
  65. func ClearCalendarUnionCode(nowDate string) (err error) {
  66. o := orm.NewOrm()
  67. var rs_calendar_id string
  68. sql := `SELECT group_concat(distinct a.rs_calendar_id) AS rs_calendar_id FROM rs_calendar AS a
  69. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  70. WHERE a.source=0 AND activity_type='公开会议'
  71. AND b.end_date>=? `
  72. err = o.Raw(sql, nowDate).QueryRow(&rs_calendar_id)
  73. sql = ` UPDATE rs_calendar SET union_code='' WHERE rs_calendar_id IN(` + rs_calendar_id + `) `
  74. _, err = o.Raw(sql).Exec()
  75. if err != nil {
  76. return err
  77. }
  78. sql = ` UPDATE rs_calendar_researcher SET union_code='' WHERE rs_calendar_id IN(` + rs_calendar_id + `) `
  79. _, err = o.Raw(sql).Exec()
  80. if err != nil {
  81. return err
  82. }
  83. return
  84. }
  85. /*
  86. sql := ` SELECT b.* FROM rs_calendar AS a
  87. INNER JOIN rs_calendar_researcher AS b ON a.rs_calendar_id=b.rs_calendar_id
  88. WHERE a.source=0 AND activity_type='公开会议'
  89. AND b.end_date>=?
  90. ORDER BY a.rs_calendar_id ASC `
  91. */
  92. func GetExistMeetingCode(startTime, endTime string) (union_code string, err error) {
  93. sql := ` SELECT union_code FROM rs_calendar_researcher AS a
  94. WHERE DATE_FORMAT(CONCAT(a.start_date," ",a.start_time),'%Y-%m-%d %H:%i:%S')>=?
  95. AND DATE_FORMAT(CONCAT(a.end_date," ",a.end_time),'%Y-%m-%d %H:%i:%S')<=?
  96. group by a.union_code
  97. LIMIT 1 `
  98. o := orm.NewOrm()
  99. err = o.Raw(sql, startTime, endTime).QueryRow(&union_code)
  100. return
  101. }