group_support.go 1.89 KB
Newer Older
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
package group_ev

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
)

type GroupSupportEvent struct {
	GroupSupportAwardAdmin GroupSupportItem
	GroupCode              string
	GroupSupportAwardMgrs  []GroupSupportItem
}

type GroupSupportItem struct {
	GroupSupportAwardId mysql.ID
	UserId              mysql.ID
	DiamondNum          uint32
}

func InitGroupSupportEvent(size int, groupCode string) *GroupSupportEvent {
	return &GroupSupportEvent{GroupSupportAwardMgrs: make([]GroupSupportItem, 0, size), GroupCode: groupCode}
}

func (groupSupportEvent *GroupSupportEvent) AddAdmin(groupSupportAwardId mysql.ID, userId mysql.ID, diamondNum uint32) *GroupSupportEvent {
	groupSupportEvent.GroupSupportAwardAdmin = GroupSupportItem{
		GroupSupportAwardId: groupSupportAwardId,
		UserId:              userId,
		DiamondNum:          diamondNum,
	}
	return groupSupportEvent
}

func (groupSupportEvent *GroupSupportEvent) AddMgr(groupSupportAwardId mysql.ID, userId mysql.ID, diamondNum uint32) *GroupSupportEvent {
	groupSupportEvent.GroupSupportAwardMgrs = append(groupSupportEvent.GroupSupportAwardMgrs, GroupSupportItem{
		GroupSupportAwardId: groupSupportAwardId,
		UserId:              userId,
		DiamondNum:          diamondNum,
	})
	return groupSupportEvent
}

//注册监听
var groupSupportListen = new(domain.EventBase)

//添加领域事件,在每个领域模型中init中添加,因为这是静态业务,非动态的。
func AddGroupSupportSync(callback func(model *domain.Model, event interface{}) error) {
	domain.AddEventSync(groupSupportListen, callback)
}

//加入到异步操作中
func AddGroupSupportAsync(callback func(model *domain.Model, event interface{}) error) {
	domain.AddEventAsync(groupSupportListen, callback)
}

//领域事件发布
func PublishGroupSupport(model *domain.Model, event interface{}) error {
	return domain.PublishEvent(groupSupportListen, model, event)
}