Files
bj_power/bj_power_mes/schema/event_log.go
T

46 lines
1.3 KiB
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// EventLog 操作日志:必须含 workOrderNo(工单号)、operator(操作人)
type EventLog struct {
ent.Schema
}
func (EventLog) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "event_log"}}
}
func (EventLog) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.String("eventType").MaxLen(50).Comment("事件类型,如 work.order.create"),
field.String("workOrderNo").MaxLen(64).Default("").Comment("关联工单号"),
field.String("operator").MaxLen(64).Default("").Comment("操作人"),
field.String("entityType").Default("").MaxLen(30).Comment("实体类型"),
field.String("entityId").Default("").MaxLen(50).Comment("实体标识"),
field.Text("description").Default("").Comment("描述"),
field.JSON("payload", map[string]any{}).Optional().SchemaType(map[string]string{
dialect.Postgres: "jsonb",
}).Comment("载荷"),
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
}
}
func (EventLog) Indexes() []ent.Index {
return []ent.Index{
index.Fields("eventType"),
index.Fields("workOrderNo"),
index.Fields("operator"),
index.Fields("createdAt"),
}
}