public_meeting.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package roadshow
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/roadshow"
  5. "hongze/hz_crm_api/utils"
  6. "strconv"
  7. "time"
  8. )
  9. func SetPublicMeetingUnionCode() (err error) {
  10. fmt.Println("start SetPublicMeetingUnionCode" + time.Now().Format(utils.FormatDateTime))
  11. now := time.Now().AddDate(-1, 0, 0).Format(utils.FormatDate)
  12. //清空现有分组
  13. err = roadshow.ClearCalendarUnionCode(now)
  14. if err != nil {
  15. return
  16. }
  17. list, err := roadshow.GetPublicMeetingList(now)
  18. if err != nil {
  19. return
  20. }
  21. for _, v := range list {
  22. calendarResearchItem, err := roadshow.GetRsCalendarById(v.RsCalendarId)
  23. if err != nil {
  24. fmt.Println("GetRsCalendarById Err:" + err.Error())
  25. return err
  26. }
  27. if calendarResearchItem == nil {
  28. continue
  29. }
  30. if calendarResearchItem.UnionCode != "" {
  31. continue
  32. }
  33. startDateTime := v.MinTime
  34. endDateTime := v.MaxTime
  35. var unionCode string
  36. unionCodeStr := strconv.Itoa(v.RsCalendarId) + "_" + strconv.Itoa(int(time.Now().Unix()))
  37. unionCode = utils.MD5(unionCodeStr)
  38. err = roadshow.ModifyCalendarUnionCode(unionCode, v.RsCalendarId)
  39. if err != nil {
  40. fmt.Println("ModifyCalendarUnionCode Err:" + err.Error())
  41. return err
  42. }
  43. fmt.Println("SetCoincideMeeting:", startDateTime, endDateTime)
  44. SetCoincideMeeting(startDateTime, endDateTime, unionCode)
  45. }
  46. fmt.Println("end SetPublicMeetingUnionCode" + time.Now().Format(utils.FormatDateTime))
  47. return
  48. }
  49. func SetCoincideMeeting(startDateTime, endDateTime, unionCode string) (err error) {
  50. coincideList, err := roadshow.GetCoincideMeeting(startDateTime, endDateTime)
  51. if err != nil {
  52. return err
  53. }
  54. for _, cv := range coincideList {
  55. calendarResearchItem, err := roadshow.GetRsCalendarById(cv.RsCalendarId)
  56. if err != nil {
  57. fmt.Println("GetRsCalendarById Err:" + err.Error())
  58. return err
  59. }
  60. if calendarResearchItem == nil {
  61. continue
  62. }
  63. if calendarResearchItem.UnionCode != "" {
  64. continue
  65. }
  66. fmt.Println("RsCalendarId:", cv.RsCalendarId)
  67. err = roadshow.ModifyCalendarUnionCode(unionCode, cv.RsCalendarId)
  68. if err != nil {
  69. fmt.Println("ModifyCalendarUnionCode Err:" + err.Error())
  70. return err
  71. }
  72. }
  73. minTime, maxTime, err := roadshow.GetCoincideMeetingMinAndMaxTime(startDateTime, endDateTime)
  74. if minTime == startDateTime && maxTime == endDateTime {
  75. return err
  76. } else {
  77. startDateTime = minTime
  78. endDateTime = maxTime
  79. SetCoincideMeeting(startDateTime, endDateTime, unionCode)
  80. }
  81. fmt.Println("结束循环")
  82. fmt.Println(startDateTime, endDateTime, minTime, maxTime)
  83. return err
  84. }