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" ) // WorkpieceLifecycleLog 工件生命周期状态流水(问题.md 三 / P2 定稿)。 // 与 semiflow(业务流水:含库位、数量) 并存、同事务写: // - semiflow = 业务流水(谁写不变),不再作计数源 // - workpiece_lifecycle_log = 状态流水(from/to status),所有 status 变更点同事务写 // // action 值域:NEW / ONLINE / REPORT / SEMI_IN / SEMI_OUT / DONE / SCRAPPED // 入库次数统一 count(action='SEMI_IN'),原 CountSemiStored 已删除(semi.go)。 type WorkpieceLifecycleLog struct { ent.Schema } func (WorkpieceLifecycleLog) Annotations() []schema.Annotation { return []schema.Annotation{entsql.Annotation{Table: "workpiece_lifecycle_log"}, entsql.WithComments(true), schema.Comment("工件生命周期状态流水:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED,所有状态变更点同事务写")} } func (WorkpieceLifecycleLog) Fields() []ent.Field { return []ent.Field{ field.Int("id").Positive(), field.String("sn").MaxLen(64).Comment("工件SN"), field.String("workOrderNo").Default("").MaxLen(64).Comment("所属工单"), field.String("action").MaxLen(20).Comment("状态动作:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED"), field.String("fromStatus").Default("").MaxLen(20).Comment("变更前状态"), field.String("toStatus").Default("").MaxLen(20).Comment("变更后状态"), field.Int("stationNo").Optional().Comment("关联工位号"), field.Int("flowSeq").Optional().Comment("工艺序号(工序顺序)"), field.String("operator").Default("").MaxLen(64).Comment("操作人"), field.String("source").Default("").MaxLen(32).Comment("来源:workstation/mes/admin/reconcile"), field.String("remark").Default("").MaxLen(255).Comment("备注"), field.Time("createdAt").Default(time.Now).Immutable(), } } func (WorkpieceLifecycleLog) Indexes() []ent.Index { return []ent.Index{ index.Fields("sn", "createdAt"), index.Fields("workOrderNo", "createdAt"), index.Fields("action", "createdAt"), } }