69 lines
2.1 KiB
Go
69 lines
2.1 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"bj_power_mes/constants"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// WorkOrder 工单
|
|
type WorkOrder struct {
|
|
ent.Schema
|
|
}
|
|
|
|
func (WorkOrder) Annotations() []schema.Annotation {
|
|
return []schema.Annotation{
|
|
entsql.Annotation{Table: "work_order"},
|
|
}
|
|
}
|
|
|
|
func (WorkOrder) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Int("id").Positive(),
|
|
field.String("workOrderNo").Default("").Comment("工单号"),
|
|
field.Int("productTypeId").Comment("产品类型ID"),
|
|
field.Int("quantity").Default(1).Comment("工件数量"),
|
|
field.Int("finishedNum").Default(0).Comment("完成数量"),
|
|
field.Int("failNum").Default(0).Comment("检测NG数量"),
|
|
field.Enum("status").
|
|
GoType(constants.WorkOrderStatus("")).
|
|
Default(string(constants.WorkOrderStatus_Created)).
|
|
Comment("工单状态"),
|
|
field.JSON("context", map[string]any{}).Optional().SchemaType(map[string]string{
|
|
dialect.Postgres: "jsonb",
|
|
}).Comment("运行时的上下文"),
|
|
field.Enum("source").
|
|
GoType(constants.WorkOrderSource("")).
|
|
Default(string(constants.WorkOrderSource_SYSTEM)).
|
|
Comment("工单来源"),
|
|
field.String("productCode").Default("").Comment("MOM 下发的产品编码(保持下发时一致,用于报工回传)"),
|
|
field.Time("completedAt").Optional().Nillable().Comment("完成时间"),
|
|
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
|
|
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable().Comment("更新时间"),
|
|
}
|
|
}
|
|
|
|
func (WorkOrder) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("productType", ProductType.Type).Ref("workOrders").Field("productTypeId").Unique().Required(),
|
|
edge.To("jobs", Job.Type).Comment("工件"),
|
|
edge.To("pallets", Pallet.Type).Comment("托盘"),
|
|
edge.To("partRef", WorkOrderPart.Type).Unique().Comment("工单零件号(一个工单只选一个零件号)"),
|
|
}
|
|
}
|
|
|
|
func (WorkOrder) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("status"),
|
|
index.Fields("productTypeId"),
|
|
}
|
|
}
|