规则链结构优化

This commit is contained in:
XM-GO
2023-08-25 17:41:59 +08:00
parent fac575ac7b
commit e436f3b7ad
37 changed files with 254 additions and 157 deletions

View File

@@ -29,16 +29,16 @@ func (f createAlarmNodeFactory) Create(id string, meta Metadata) (Node, error) {
return decodePath(meta, node)
}
func (n *createAlarmNode) Handle(msg message.Message) error {
logrus.Infof("%s handle message '%s'", n.Name(), msg.GetType())
func (n *createAlarmNode) Handle(msg *message.Message) error {
logrus.Infof("%s handle message '%s'", n.Name(), msg.MsgType)
created := n.GetLinkedNode("Created")
updated := n.GetLinkedNode("Updated")
failure := n.GetLinkedNode("Failure")
alarm := services.DeviceAlarmModelDao.FindOneByType(msg.GetMetadata().GetKeyValue("deviceId").(string), n.AlarmType, "0")
alarm := services.DeviceAlarmModelDao.FindOneByType(msg.Metadata.GetValue("deviceId").(string), n.AlarmType, "0")
if alarm.DeviceId != "" {
marshal, _ := json.Marshal(msg.GetMsg())
marshal, _ := json.Marshal(msg.Msg)
alarm.Details = string(marshal)
err := services.DeviceAlarmModelDao.Update(*alarm)
if err != nil {
@@ -53,14 +53,14 @@ func (n *createAlarmNode) Handle(msg message.Message) error {
} else {
alarm = &entity.DeviceAlarm{}
alarm.Id = kgo.KStr.Uniqid("a")
alarm.DeviceId = msg.GetMetadata().GetKeyValue("deviceId").(string)
alarm.ProductId = msg.GetMetadata().GetKeyValue("productId").(string)
alarm.Name = msg.GetMetadata().GetKeyValue("deviceName").(string)
alarm.DeviceId = msg.Metadata.GetValue("deviceId").(string)
alarm.ProductId = msg.Metadata.GetValue("productId").(string)
alarm.Name = msg.Metadata.GetValue("deviceName").(string)
alarm.Level = n.AlarmSeverity
alarm.State = global.ALARMING
alarm.Type = n.AlarmType
alarm.Time = time.Now()
marshal, _ := json.Marshal(msg.GetMsg())
marshal, _ := json.Marshal(msg.Msg)
alarm.Details = string(marshal)
err := services.DeviceAlarmModelDao.Insert(*alarm)
if err != nil {