Files
bj_power/bj_power_wms/schema/event_log.go
T

47 lines
1.6 KiB
Go
Raw Normal View History

package schema
import (
"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 操作日志(事件审计)
// 参照 MES 的 event_log 模型落地到 WMS,按 WMS 约定调整:
// - 字段名 snake_casetools/generate.go 统一转 camelCase 输出 JSON
// - 时间字段用 Int64 unix 秒
// - 无 work_order_noWMS 无工单概念),用 entity_type/entity_id 描述业务对象
// 只增不改,不设 updated_at。
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.String("event_type").MaxLen(64).Comment("事件类型,如 user.create / inbound.create / auth.login"),
field.String("operator").Default("").MaxLen(64).Comment("操作人"),
field.String("entity_type").Default("").MaxLen(32).Comment("对象类型,如 user/role/material/inbound/outbound"),
field.String("entity_id").Default("").MaxLen(64).Comment("对象标识:主键ID或业务单号"),
field.Text("description").Default("").Comment("事件描述"),
field.JSON("payload", map[string]any{}).Optional().SchemaType(map[string]string{
dialect.Postgres: "jsonb",
}).Comment("扩展负载"),
field.Int64("created_at").DefaultFunc(nowUnix).Comment("发生时间"),
}
}
func (EventLog) Indexes() []ent.Index {
return []ent.Index{
index.Fields("event_type"),
index.Fields("operator"),
index.Fields("created_at"),
}
}