123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- package services
- import (
- "context"
- "fmt"
- "hongze/hongze_task/models"
- "hongze/hongze_task/models/yb"
- "hongze/hongze_task/services/alarm_msg"
- "hongze/hongze_task/utils"
- "time"
- )
- // YbTelRemind 研报电话会提醒
- func YbTelRemind(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- //fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送消息至同花顺失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("发送电话会提醒失败 ErrMsg:"+err.Error(), 3)
- }
- }()
- condition := ""
- pars := make([]interface{}, 0)
- startTime := time.Now().Add(time.Second * 60 * 15).Format(utils.FormatDateTime) //15分钟后就要开始的会议
- condition += ` and publish_status = 1 and is_send_wx_msg = 0 and is_delete = 0 and start_time <= ? and end_time >= now() `
- pars = append(pars, startTime)
- condition += ` and first_activity_type_id in (1,3) `
- _, list, err := yb.GetList(condition, pars, 0, 1000)
- for _, activityInfo := range list {
- activityInfo.IsSendWxMsg = 1
- activityInfo.Update([]string{"IsSendWxMsg"})
- go sendWxMsg(activityInfo, "会议提醒")
- }
- return
- }
- // YbSalonRemind 研报沙龙提醒
- func YbSalonRemind(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- //fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送消息至同花顺失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("发送研报沙龙提醒失败 ErrMsg:"+err.Error(), 3)
- }
- }()
- condition := ""
- pars := make([]interface{}, 0)
- startTime := time.Now().Add(time.Second * 60 * 60).Format(utils.FormatDateTime) //1小时后就要开始的沙龙
- condition += ` and publish_status = 1 and is_send_salon_wx_msg = 0 and is_delete = 0 and start_time <= ? and end_time >= now() `
- pars = append(pars, startTime)
- condition += ` and first_activity_type_id =3 `
- _, list, err := yb.GetList(condition, pars, 0, 1000)
- for _, activityInfo := range list {
- activityInfo.IsSendSalonWxMsg = 1
- activityInfo.Update([]string{"IsSendSalonWxMsg"})
- go sendWxMsg(activityInfo, "沙龙提醒")
- }
- return
- }
- func sendWxMsg(activityInfo *yb.Activity, remindType string) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error())
- utils.FileLog.Info(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "发送电话会提醒失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- keyword4 := "- -"
- //您有一场【橡胶双周报】将在15分钟后开始
- timeStr := ``
- userIdList := make([]string, 0) //提醒用户列表
- if remindType == "会议提醒" {
- timeStr = `15分钟`
- list, tmpErr := yb.GetAllActivityRemindListByActivityId(activityInfo.ActivityId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range list {
- userIdList = append(userIdList, fmt.Sprint(v.UserId))
- }
- } else {
- timeStr = `1小时`
- list, tmpErr := yb.GetAllActivityRegisterListByActivityId(activityInfo.ActivityId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range list {
- userIdList = append(userIdList, fmt.Sprint(v.UserId))
- }
- keyword4 = activityInfo.Address
- }
- if len(userIdList) <= 0 {
- return
- }
- first := `您有一场【` + activityInfo.ActivityTypeName + `】将在` + timeStr + `后开始`
- keyword1 := activityInfo.ActivityTypeName + "-" + activityInfo.ActivityName
- keyword2 := "将在" + timeStr + "后开始"
- //keyword3 := `2021-10-18 16:30-17:00 星期一`
- keyword3 := formatActivityTimeStr(activityInfo.StartTime, activityInfo.EndTime)
- remark := `点击查看活动详情`
- //获取所有用户的openid列表
- openidList, err := models.GetUserOpenidListByUserIds(userIdList)
- if err != nil {
- return
- }
- //小程序跳转地址
- wxAppPath := `pages-activity/detail?id=` + fmt.Sprint(activityInfo.ActivityId)
- err = SendWxMsgWithActivityAppointmentRemind(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openidList)
- return
- }
- // formatActivityTimeStr 格式化活动的开始结束时间
- func formatActivityTimeStr(startTime, endTime time.Time) string {
- startStr := startTime.Format("2006-01-02 15:04")
- endStr := endTime.Format("15:04")
- weekStr := ``
- weekInt := startTime.Weekday()
- switch weekInt {
- case 0:
- weekStr = `星期日`
- case 1:
- weekStr = `星期一`
- case 2:
- weekStr = `星期二`
- case 3:
- weekStr = `星期三`
- case 4:
- weekStr = `星期四`
- case 5:
- weekStr = `星期五`
- case 6:
- weekStr = `星期六`
- }
- return startStr + `-` + endStr + ` ` + weekStr
- }
|