44 lines
1.2 KiB
Go
44 lines
1.2 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"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// Alert 预警消息:规则命中或手动触发后写入,供前端预警中心收件箱展示
|
|||
|
|
type Alert struct {
|
|||
|
|
ent.Schema
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Alert) Annotations() []schema.Annotation {
|
|||
|
|
return []schema.Annotation{entsql.Annotation{Table: "alert"}}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Alert) Fields() []ent.Field {
|
|||
|
|
return []ent.Field{
|
|||
|
|
field.Int("id").Positive(),
|
|||
|
|
field.Int("ruleId").Default(0).Comment("关联规则ID,0=手动触发"),
|
|||
|
|
field.String("type").MaxLen(40).Comment("预警类型"),
|
|||
|
|
field.String("title").MaxLen(120).Comment("标题"),
|
|||
|
|
field.String("content").Default("").MaxLen(500).Comment("内容"),
|
|||
|
|
field.String("refType").Default("").MaxLen(40).Comment("关联业务类型"),
|
|||
|
|
field.String("refId").Default("").MaxLen(64).Comment("关联业务ID"),
|
|||
|
|
field.String("status").Default("UNREAD").MaxLen(10).Comment("UNREAD/READ"),
|
|||
|
|
field.String("receiver").Default("").MaxLen(255).Comment("接收人"),
|
|||
|
|
field.Time("createdAt").Default(time.Now).Immutable(),
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (Alert) Indexes() []ent.Index {
|
|||
|
|
return []ent.Index{
|
|||
|
|
index.Fields("status"),
|
|||
|
|
index.Fields("type"),
|
|||
|
|
index.Fields("createdAt"),
|
|||
|
|
}
|
|||
|
|
}
|