Files
bj_power/bj_power_mes/schema/job.go
T

94 lines
3.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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"
)
// Job 工件
// currentStepId/positionType/positionRefId/version/lastEventId
type Job struct {
ent.Schema
}
func (Job) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "job"},
}
}
func (Job) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.Int("workOrderId").Comment("工单ID"),
field.Int("palletId").Optional().Nillable().Comment("所属托盘ID"),
field.Int("productTypeId").Comment("产品类型ID"),
field.Int("recipeId").Comment("工艺路线ID"),
field.String("currentStepId").MaxLen(20).Default("").Comment("当前步骤业务IDOP10-OP120"),
field.Enum("status").
GoType(constants.JobStatus("")).
Default(string(constants.JobStatus_Created)).
Comment("工件状态"),
field.String("positionType").
GoType(constants.PositionType("")).
Default(string(constants.PositionType_OnDock)).
Comment("位置类型(主字段)"),
field.String("positionRefId").Default("").Comment("位置引用ID(主字段)"),
field.Int("tempSlotNo").Optional().Nillable().Comment("暂存台槽位号(兼容字段)"),
field.String("workpieceNo").Default("").Comment("工件编号(扫码结果/打标文本)"),
field.Int("dockNo").Optional().Nillable().Comment("接驳台编号(兼容字段)"),
field.Int("dockSlotNo").Optional().Nillable().Comment("接驳台槽位编号(兼容字段)"),
field.JSON("context", map[string]any{}).Optional().SchemaType(map[string]string{
dialect.Postgres: "jsonb",
}).Comment("运行时上下文"),
field.Int("priority").Default(2).Comment("优先级"),
field.String("suspendedReason").Default("").Comment("挂起原因"),
field.Int("version").Default(0).Comment("事件版本号"),
field.String("lastEventId").Default("").Comment("最后处理事件ID"),
field.Time("completedAt").Optional().Comment("完成时间"),
field.Time("cncStartedAt").Optional().Comment("CNC加工开始时间"),
field.Time("cncCompletedAt").Optional().Comment("CNC加工完成时间"),
field.Enum("inspectionResult").
GoType(constants.QCResult("")).
Optional().
Comment("内窥镜检测结果(PASS/FAILNULL=未检测)"),
field.Enum("samplingResult").
GoType(constants.QCResult("")).
Optional().
Comment("抽检检测结果(PASS/FAILNULL=未检测)"),
field.Time("createdAt").Default(time.Now).Immutable().Comment("创建时间"),
field.Time("updatedAt").Default(time.Now).UpdateDefault(time.Now).Optional().Nillable().Comment("最后更新时间"),
}
}
func (Job) Edges() []ent.Edge {
return []ent.Edge{
edge.From("workOrder", WorkOrder.Type).Ref("jobs").Field("workOrderId").Unique().Required(),
edge.From("productType", ProductType.Type).Ref("jobs").Field("productTypeId").Unique().Required(),
edge.From("recipe", Recipe.Type).Ref("jobs").Field("recipeId").Unique().Required(),
edge.To("taskLogs", TaskLog.Type).Comment("任务日志"),
edge.To("tasks", Task.Type).Comment("领域任务"),
edge.To("stepInstances", JobStepInstance.Type).Comment("步骤执行实例"),
edge.From("pallet", Pallet.Type).Ref("jobs").Field("palletId").Unique(),
}
}
func (Job) Indexes() []ent.Index {
return []ent.Index{
index.Fields("workOrderId"),
index.Fields("status"),
index.Fields("positionType"),
index.Fields("version"),
index.Fields("palletId"),
}
}