Files
PandaX/pkg/initialize/event.go
2023-09-28 10:38:02 +08:00

25 lines
587 B
Go

package initialize
import (
"pandax/apps/device/entity"
"pandax/apps/device/services"
"pandax/pkg/events"
"pandax/pkg/global"
)
// 初始化事件监听
func InitEvents() {
// 监听规则链改变 更新所有绑定改规则链的产品
global.EventEmitter.On(events.ProductChainRuleEvent, func(ruleId, codeData string) {
global.Log.Infof("规则链%s变更", ruleId)
list := services.ProductModelDao.FindList(entity.Product{
RuleChainId: ruleId,
})
if list != nil {
for _, product := range *list {
global.ProductCache.Put(product.Id, codeData)
}
}
})
}