42 lines
1.5 KiB
Go
42 lines
1.5 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"}, entsql.WithComments(true), schema.Comment("AlertRule 预警规则:按类型 + 阈值触发,命中后写入 alert 消息表")}
|
|
}
|
|
|
|
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.Bool("enabled").Default(true).Comment("是否启用"),
|
|
// 通知渠道(遗留5 第一阶段占位):逗号分隔(如 site,sms),空=仅落预警中心收件箱、不外发;暂不实现发送
|
|
field.String("notifyChannels").Default("").MaxLen(255).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"),
|
|
}
|
|
}
|