41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package schema
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"entgo.io/ent"
|
||
|
|
"entgo.io/ent/dialect/entsql"
|
||
|
|
"entgo.io/ent/schema"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
"entgo.io/ent/schema/index"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AlertRule 预警规则:按类型 + 阈值触发,命中后写入 alert 消息表
|
||
|
|
type AlertRule struct {
|
||
|
|
ent.Schema
|
||
|
|
}
|
||
|
|
|
||
|
|
func (AlertRule) Annotations() []schema.Annotation {
|
||
|
|
return []schema.Annotation{entsql.Annotation{Table: "alert_rule"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (AlertRule) Fields() []ent.Field {
|
||
|
|
return []ent.Field{
|
||
|
|
field.Int("id").Positive(),
|
||
|
|
field.String("name").MaxLen(80).Comment("规则名称"),
|
||
|
|
field.String("type").MaxLen(40).Comment("预警类型 torque_ng/inspection_ng/inventory_low/task_overdue"),
|
||
|
|
field.Float("threshold").Default(0).Comment("阈值(不同类含义不同)"),
|
||
|
|
field.String("receiver").Default("").MaxLen(255).Comment("接收人,逗号分隔"),
|
||
|
|
field.Bool("enabled").Default(true).Comment("是否启用"),
|
||
|
|
field.String("createdBy").Default("").MaxLen(64).Comment("创建人"),
|
||
|
|
field.Time("createdAt").Default(time.Now).Immutable(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (AlertRule) Indexes() []ent.Index {
|
||
|
|
return []ent.Index{
|
||
|
|
index.Fields("type"),
|
||
|
|
index.Fields("enabled"),
|
||
|
|
}
|
||
|
|
}
|