123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package roadshow
- import (
- "context"
- "fmt"
- "hongze/hongze_task/models/roadshow"
- "hongze/hongze_task/utils"
- "strconv"
- "time"
- )
- //
- //func SetPublicMeetingUnionCode(cont context.Context) (err error) {
- // now := time.Now().Format(utils.FormatDate)
- // list, err := roadshow.GetPublicMeetingList(now)
- // if err != nil {
- // return
- // }
- //
- // for _, v := range list {
- // calendarResearchItem, err := roadshow.GetRsCalendarResearcherById(v.RsCalendarResearcherId)
- // if err != nil {
- // fmt.Println("GetRsCalendarById Err:" + err.Error())
- // return
- // }
- // if calendarResearchItem == nil {
- // continue
- // }
- // var unionCode string
- // if calendarResearchItem.UnionCode != "" {
- // unionCode = calendarResearchItem.UnionCode
- // } else {
- // //生成当前公开会议联合编码
- // unionCodeStr := strconv.Itoa(v.RsCalendarId) + "_" + strconv.Itoa(int(time.Now().Unix()))
- // unionCode = utils.MD5(unionCodeStr)
- // }
- //
- // err = roadshow.ModifyCalendarUnionCode(unionCode, v.RsCalendarId)
- // if err != nil {
- // fmt.Println("ModifyCalendarUnionCode Err:" + err.Error())
- // return
- // }
- // startDateTime := v.StartDate + " " + v.StartTime
- // endDateTime := v.EndDate + " " + v.EndTime
- // coincideList, err := roadshow.GetCoincideMeeting(startDateTime, endDateTime)
- // if err != nil {
- // return
- // }
- // for _, cv := range coincideList {
- // if cv.UnionCode != unionCode {
- // err = roadshow.ModifyCalendarUnionCode(unionCode, cv.RsCalendarId)
- // if err != nil {
- // fmt.Println("ModifyCalendarUnionCode Err:" + err.Error())
- // return
- // }
- // }
- // }
- // }
- // return
- //}
- func SetPublicMeetingUnionCode(cont context.Context) (err error) {
- fmt.Println("start SetPublicMeetingUnionCode" + time.Now().Format(utils.FormatDateTime))
- now := time.Now().AddDate(-1, 0, 0).Format(utils.FormatDate)
- //清空现有分组
- err = roadshow.ClearCalendarUnionCode(now)
- if err != nil {
- return
- }
- list, err := roadshow.GetPublicMeetingList(now)
- if err != nil {
- return
- }
- for _, v := range list {
- calendarResearchItem, err := roadshow.GetRsCalendarById(v.RsCalendarId)
- if err != nil {
- fmt.Println("GetRsCalendarById Err:" + err.Error())
- return err
- }
- if calendarResearchItem == nil {
- continue
- }
- if calendarResearchItem.UnionCode != "" {
- continue
- }
- startDateTime := v.MinTime
- endDateTime := v.MaxTime
- var unionCode string
- unionCodeStr := strconv.Itoa(v.RsCalendarId) + "_" + strconv.Itoa(int(time.Now().Unix()))
- unionCode = utils.MD5(unionCodeStr)
- err = roadshow.ModifyCalendarUnionCode(unionCode, v.RsCalendarId)
- if err != nil {
- fmt.Println("ModifyCalendarUnionCode Err:" + err.Error())
- return err
- }
- fmt.Println("SetCoincideMeeting:", startDateTime, endDateTime)
- SetCoincideMeeting(startDateTime, endDateTime, unionCode)
- }
- fmt.Println("end SetPublicMeetingUnionCode" + time.Now().Format(utils.FormatDateTime))
- return
- }
- func SetCoincideMeeting(startDateTime, endDateTime, unionCode string) (err error) {
- coincideList, err := roadshow.GetCoincideMeeting(startDateTime, endDateTime)
- if err != nil {
- return err
- }
- for _, cv := range coincideList {
- calendarResearchItem, err := roadshow.GetRsCalendarById(cv.RsCalendarId)
- if err != nil {
- fmt.Println("GetRsCalendarById Err:" + err.Error())
- return err
- }
- if calendarResearchItem == nil {
- continue
- }
- if calendarResearchItem.UnionCode != "" {
- continue
- }
- fmt.Println("RsCalendarId:", cv.RsCalendarId)
- err = roadshow.ModifyCalendarUnionCode(unionCode, cv.RsCalendarId)
- if err != nil {
- fmt.Println("ModifyCalendarUnionCode Err:" + err.Error())
- return err
- }
- }
- minTime, maxTime, err := roadshow.GetCoincideMeetingMinAndMaxTime(startDateTime, endDateTime)
- if minTime == startDateTime && maxTime == endDateTime {
- return err
- } else {
- startDateTime = minTime
- endDateTime = maxTime
- SetCoincideMeeting(startDateTime, endDateTime, unionCode)
- }
- fmt.Println("结束循环")
- fmt.Println(startDateTime, endDateTime, minTime, maxTime)
- return err
- }
|