public_meeting.go 4.2 KB

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