1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- package services
- import (
- "context"
- "errors"
- "fmt"
- "hongze/hongze_task/models/yb"
- "hongze/hongze_task/services/alarm_msg"
- "time"
- )
- // PublishVoiceBroadcast 定时发布语音播报-每分钟
- func PublishVoiceBroadcast(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("PublishVoiceBroadcast-定时发布语音播报失败, ErrMsg:\n"+err.Error(), 3)
- }
- }()
- // 获取所有未发布的语音播报
- list, e := yb.GetUnpublishedVoiceBroadcastList()
- if e != nil {
- return
- }
- listLen := len(list)
- if listLen == 0 {
- return
- }
- // 比对时间(分钟),时间相等则发布并推送
- format := "200601021504"
- nowTime := time.Now().Local().Format(format)
- for i := 0; i < listLen; i++ {
- item := list[i]
- t := item.PrePublishTime.Format(format)
- if t == nowTime && item.MsgState == 0 {
- if e := VoiceBroadcastUpdateAndPush(item); e != nil {
- err = e
- return
- }
- }
- }
- return
- }
- // VoiceBroadcastUpdateAndPush 更新发布语音播报
- func VoiceBroadcastUpdateAndPush(item *yb.VoiceBroadcast) (err error) {
- if item == nil {
- return
- }
- if e := yb.PublishVoiceBroadcast(item.BroadcastId); e != nil {
- err = errors.New(fmt.Sprintf("Id: %d, 更新发布状态失败, Err: %s", item.BroadcastId, e.Error()))
- return
- }
- go func() {
- fmt.Println("开始发送模板消息")
- _ = SendYbVoiceBroadcastWxMsg(item.BroadcastId, item.SectionName, item.BroadcastName)
- }()
- go func() {
- fmt.Println("开始发送客群消息")
- _ = SendYbVoiceBroadcastToThs(item.BroadcastId)
- }()
- return
- }
|