package schema import ( "bj_power_mes/constants" "entgo.io/ent" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" ) // RecipeStep 工序定义,工艺路线中的单个加工步骤? // // 设计原则:步骤的走向?Scheduler 层实时决策,不通过 JSON 字段配置分支逻辑? // nextStepDefault 提供默认下一跳,Scheduler ?Generator/Filter 可在运行时根据系统状态覆盖? type RecipeStep struct { ent.Schema } func (RecipeStep) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.Annotation{ Table: "recipe_step", Options: "COMMENT='工序定义表,工艺路线中的单个加工步骤'", }, entsql.WithComments(true), } } func (RecipeStep) Fields() []ent.Field { return []ent.Field{ field.Int("id").Positive().Comment("主键ID"), field.Int("recipeId").Comment("所属工艺路线ID"), field.String("stepId").MaxLen(20).Default("").Comment("业务步骤ID,如 OP10/OP20"), field.String("stepName").MaxLen(50).Comment("工序名称"), field.Int("stepIndex").Comment("工序序号"), field.Enum("stepType"). GoType(constants.StepType("")). Comment("工序类型:OPERATION/BUFFER_STAGE/AIR_BLOW/LOAD_DOCK/UNLOAD_DOCK"), field.String("resourceType").Default("").Comment("目标设备类型编码,如 GRINDER/FULL_CHECK,手持操作时可为?), field.String("nextStepDefault").Default("").Comment("默认下一步stepId,正常流转时的目标步?), field.Int("priority").Default(2).Comment("调度优先级,数值越小越优先(磨床取料等高优先),trySchedule 按当前步骤优先级排序"), field.Int("timeoutSeconds").Default(-1).Comment("超时秒数?1=一致监?轮询兜底(不超时),0=不超时,>0=超时秒数"), field.Bool("holdUntilHandover").Default(false).Comment("本步骤完成后是否挂起等待交接(换料场景:磨完的工件等下一件来换料交接,状态进?holding,不自动推进?), field.String("fallbackNextStep").MaxLen(20).Default("").Comment("holding 挂起时若无后继工件交接,走此步骤收尾(如最后一件自行取料)"), field.String("desc").Default("").Comment("工序描述"), } } func (RecipeStep) Edges() []ent.Edge { return []ent.Edge{ edge.From("recipe", Recipe.Type).Ref("steps").Field("recipeId").Unique().Required().Comment("所属工艺路?), } } func (RecipeStep) Indexes() []ent.Index { return []ent.Index{ index.Fields("recipeId", "stepIndex").Unique(), index.Fields("recipeId", "stepId").Unique(), } }