on_mic.go 1.11 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
package mic_cron

import (
	"git.hilo.cn/hilo-common/domain"
	"github.com/robfig/cron"
	"hilo-group/domain/model/group_m"
	"hilo-group/domain/service/group_mic_s"
)

func OnMicCheck() {
	c := cron.New()
	//一分钟执行一次
	spec := "0 */1 * * * ?"
	_ = c.AddFunc(spec, func() {
		//获取麦上的所有人
		var model = domain.CreateModelNil()
		groupIds, err := group_m.GetMicHasInGroups()
		if err != nil {
			model.Log.Errorf("cron micIn GetMicHasInGroups err:%v", err)
			return
		}
		for _, groupId := range groupIds {
			//遍历每个麦位
			for i := 1; i <= 30; i++ {
				micUser, err := group_m.GetMicUser(model, groupId, i)
				if err != nil {
					model.Log.Errorf("cron micIn group_m.GetMicUser err:%v", err)
				}
				if micUser != nil {
					if err := group_mic_s.NewGroupPowerService(model.MyContext).GroupPowerOnMicExp(groupId, micUser.UserId, micUser.Timestamp); err != nil {
						model.Log.Errorf("cron micIn GroupPowerOnMicExp err:%v", err)
					} else {
						model.Log.Infof("cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v", groupId, micUser.UserId)
					}
				}
			}
		}
	})
hujiebin's avatar
hujiebin committed
39
	c.Start()
hujiebin's avatar
hujiebin committed
40
}