53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
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"
|
||
|
|
)
|
||
|
|
|
||
|
|
// 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").MaxLen(64).Comment("工单号"),
|
||
|
|
field.Int("productTypeId").Comment("产品类型ID"),
|
||
|
|
field.String("productCode").Default("").MaxLen(64).Comment("产品编码"),
|
||
|
|
field.String("productName").Default("").MaxLen(128),
|
||
|
|
field.Int("quantity").Default(1).Comment("工件数量"),
|
||
|
|
field.Int("finishedNum").Default(0).Comment("完成数量"),
|
||
|
|
field.Int("failNum").Default(0).Comment("NG数量"),
|
||
|
|
field.String("processSeq").Default("").MaxLen(64).Comment("工序组合,如 135"),
|
||
|
|
// CREATED / RELEASED / IN_PROGRESS / COMPLETED / CLOSED
|
||
|
|
field.String("status").Default("CREATED").MaxLen(20),
|
||
|
|
field.Time("planStart").Optional().Nillable().Comment("计划开始"),
|
||
|
|
field.Time("planEnd").Optional().Nillable().Comment("计划结束"),
|
||
|
|
field.JSON("context", map[string]any{}).Optional().SchemaType(map[string]string{
|
||
|
|
dialect.Postgres: "jsonb",
|
||
|
|
}).Comment("扩展字段"),
|
||
|
|
field.Time("completedAt").Optional().Nillable(),
|
||
|
|
field.Time("createdAt").Default(time.Now).Immutable(),
|
||
|
|
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable(),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (WorkOrder) Indexes() []ent.Index {
|
||
|
|
return []ent.Index{
|
||
|
|
index.Fields("workOrderNo").Unique(),
|
||
|
|
index.Fields("status"),
|
||
|
|
index.Fields("productTypeId"),
|
||
|
|
}
|
||
|
|
}
|