package models import ( "errors" "github.com/jinzhu/gorm" ) // AlarmRule 报警规则 // 为某个产品增加一个告警规则,平台可以根据设备的实时数据产生一个告警信息,并推送给用户 // 用来监控设备的状态异常等 type AlarmRule struct { gorm.Model AlertName string `gorm:"size:30;not null"` //规则名称 ProtocalID int //所属数据点ID ProtocalName string //协议名称 AlertCondition int //对应触发条件的属性编号 // |1|小于| // |2|等于| // |3|大于| // |4|小于等于| // |5|大于等于| // |6|不等于| AlertValue int //触发对比数值 AlertContent string `gorm:"size:500;not null"` // 告警内容 AlertType int // 告警类型:1:设备异常 2:设备警告 NoticeType int // 通知类型:1:通知型
2:告警型 NoticeWay int //通知方式 1:短信通知
2:极光推送
3:微信通知
ProductID int //关联的产品ID VendorID uint //关联厂商ID } // Validate 验证 func (a *AlarmRule) Validate() error { if a.AlertName == "" || a.AlertCondition == 0 || a.AlertValue == 0 || a.AlertContent == "" || a.AlertType == 0 || a.NoticeType == 0 || a.ProductID == 0 { return errors.New("非法参数") } return nil }