Commit 4bddac36 authored by hujiebin's avatar hujiebin

feat:上麦调成发事件

parent 363408c8
...@@ -3,8 +3,8 @@ package mic_cron ...@@ -3,8 +3,8 @@ package mic_cron
import ( import (
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron" "github.com/robfig/cron"
"hilo-group/domain/event/mic_ev"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_mic_s"
) )
func OnMicCheck() { func OnMicCheck() {
...@@ -27,11 +27,21 @@ func OnMicCheck() { ...@@ -27,11 +27,21 @@ func OnMicCheck() {
model.Log.Errorf("cron micIn group_m.GetMicUser err:%v", err) model.Log.Errorf("cron micIn group_m.GetMicUser err:%v", err)
} }
if micUser != nil { if micUser != nil {
if err := group_mic_s.NewGroupPowerService(model.MyContext).GroupPowerOnMicExp(groupId, micUser.UserId, micUser.Timestamp); err != nil { if err := mic_ev.PublishOnMicEvent(model, &mic_ev.OnMicEvent{
model.Log.Errorf("cron micIn GroupPowerOnMicExp err:%v", err) GroupUuid: micUser.GroupUuid,
} else { I: micUser.I,
model.Log.Infof("cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v", groupId, micUser.UserId) ExternalId: micUser.ExternalId,
UserId: micUser.UserId,
Forbid: micUser.Forbid,
Timestamp: micUser.Timestamp,
}); err != nil {
model.Log.Errorf("PublishOnMicEvent fail:%v", err)
} }
//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)
//}
} }
} }
} }
......
package mic_ev
import (
"git.hilo.cn/hilo-common/domain"
)
var onMicListen = new(domain.EventBase)
// 在麦上事件
type OnMicEvent struct {
GroupUuid string // 群组uuid
I int // 麦位
ExternalId string // 麦中的人
UserId uint64 // 麦中的人
Forbid bool // 静音 true:静音,false:没有静音
Timestamp int64 // 上麦的的时间戳
}
func AddOnMicEventSync(callback func(model *domain.Model, event interface{}) error) {
domain.AddEventSync(onMicListen, callback)
}
func AddOnMicEventAsync(callback func(model *domain.Model, event interface{}) error) {
domain.AddEventAsync(onMicListen, callback)
}
func PublishOnMicEvent(model *domain.Model, event interface{}) error {
return domain.PublishEvent(onMicListen, model, event)
}
...@@ -13,12 +13,14 @@ import ( ...@@ -13,12 +13,14 @@ import (
"hilo-group/domain/event/gift_ev" "hilo-group/domain/event/gift_ev"
"hilo-group/domain/event/group_ev" "hilo-group/domain/event/group_ev"
"hilo-group/domain/event/group_power_ev" "hilo-group/domain/event/group_power_ev"
"hilo-group/domain/event/mic_ev"
"hilo-group/domain/model/diamond_m" "hilo-group/domain/model/diamond_m"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
"hilo-group/domain/model/msg_m" "hilo-group/domain/model/msg_m"
"hilo-group/domain/model/task_m" "hilo-group/domain/model/task_m"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_mic_s"
"hilo-group/myerr" "hilo-group/myerr"
"strconv" "strconv"
"time" "time"
...@@ -30,7 +32,8 @@ func EventInit() { ...@@ -30,7 +32,8 @@ func EventInit() {
GroupEvents() GroupEvents()
GroupImMass() GroupImMass()
GroupTheme() GroupTheme()
SendGift() SendGift() // 送礼事件
OnMic() // 在麦上事件
} }
func GroupSupportEvents() { func GroupSupportEvents() {
...@@ -451,3 +454,19 @@ func SendGift() { ...@@ -451,3 +454,19 @@ func SendGift() {
return nil return nil
}) })
} }
func OnMic() {
mic_ev.AddOnMicEventSync(func(model *domain.Model, e interface{}) error {
event, ok := e.(*mic_ev.OnMicEvent)
if !ok {
model.Log.Errorf("AddOnMicEventSync event type err")
return nil
}
if err := group_mic_s.NewGroupPowerService(model.MyContext).GroupPowerOnMicExp(event.GroupUuid, event.UserId, event.Timestamp); err != nil {
model.Log.Errorf("cron micIn GroupPowerOnMicExp err:%v", err)
} else {
model.Log.Infof("cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v", event.GroupUuid, event.UserId)
}
return nil
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment