46 lines
1.4 KiB
Go
46 lines
1.4 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"
|
|
)
|
|
|
|
// Workpiece 工件(SN):序列号管理的成品/主件
|
|
type Workpiece struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (Workpiece) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{entsql.Annotation{Table: "workpiece"}}
|
|
}
|
|
|
|
func (Workpiece) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int("id").Positive(),
|
|
field.String("sn").Unique().MaxLen(64).Comment("工件唯一SN"),
|
|
field.String("orderNo").Default("").MaxLen(64).Comment("所属工单"),
|
|
field.Int("workOrderId").Optional().Comment("工单ID"),
|
|
field.String("processSeq").Default("").MaxLen(64).Comment("工序组合,如 135"),
|
|
field.Int("currentProcess").Optional().Comment("当前进行到的工序码"),
|
|
// ONLINE(已进线) / PROCESSING(在工位) / DONE(完工) / REPAIR / SCRAPPED
|
|
field.String("status").Default("ONLINE").MaxLen(20),
|
|
field.Time("onlineAt").Optional().Nillable().Comment("进线时间"),
|
|
field.Time("doneAt").Optional().Nillable().Comment("完工时间"),
|
|
field.Time("createdAt").Default(time.Now).Immutable(),
|
|
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
|
}
|
|
}
|
|
|
|
func (Workpiece) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("sn").Unique(),
|
|
index.Fields("orderNo"),
|
|
index.Fields("status"),
|
|
}
|
|
}
|