Files
bj_power/bj_power_wms/schema/alert_rule.go
T

41 lines
1.7 KiB
Go
Raw Normal View History

package schema
import (
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
)
// AlertRule 预警规则:控制各类预警是否启用与阈值。
// 五种固定规则由扫描器启动时确保存在(缺则插入,已存在不覆盖用户修改):
// - inventory_low 库存阈值/缺货(阈值未用,缺货判定走 materials.safety_stock)
// - inspection_overdue 来料检超期未检(阈值=超期小时,默认 48)
// - backup_overdue 备份超期(阈值未用,超期判定走 backup_record 最近成功+提醒周期)
// - sync_failed 物料同步失败(阈值未用,判定走 materials.sync_pending)
// - inventory_age 库龄超档(阈值=超期天,默认 180)
type AlertRule struct {
ent.Schema
}
func (AlertRule) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "alert_rules"},
entsql.WithComments(true),
schema.Comment("AlertRule 预警规则:控制各类预警是否启用与阈值"),
}
}
func (AlertRule) Fields() []ent.Field {
return []ent.Field{
field.String("code").Unique().Comment("规则编码(唯一,固定五类)"),
field.String("name").Comment("规则名称"),
field.Bool("enabled").Default(true).Comment("是否启用"),
// 阈值含义随规则:inspection_overdue=超期小时;inventory_age=超期天;其余未使用(0)。
field.Int("threshold").Default(0).Comment("阈值(含义随规则:超期小时/库龄天;0=按默认)"),
field.String("remark").Optional().Comment("备注"),
field.Int64("created_at").DefaultFunc(nowUnix).Comment("创建时间"),
field.Int64("updated_at").DefaultFunc(nowUnix).Comment("更新时间"),
}
}