package schema import ( "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" ) // RecipeStep 工序定义 // 第一阶段:以 stepId 为业务步骤标识,stepIndex 仅保留为排序字段。 type RecipeStep struct { ent.Schema } func (RecipeStep) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.Annotation{Table: "recipe_step"}, } } func (RecipeStep) Fields() []ent.Field { return []ent.Field{ field.Int("id").Positive(), field.Int("recipeId").Comment("工艺路线ID"), field.String("stepId").MaxLen(20).Default("").Comment("业务步骤ID"), field.String("stepName").MaxLen(50).Comment("工序名称"), field.Int("stepIndex").Comment("工序序号(排序字段)"), field.Enum("stepType"). GoType(constants.StepType("")). Comment("工序类型"), field.String("resourceType").Default("").Comment("工站设备类型(手持操作可为空)"), field.String("toolType").Default("").Comment("手持工具类型:SCANNER, LASER"), field.JSON("allowedResources", []string{}).Optional().SchemaType(map[string]string{ dialect.Postgres: "jsonb", }).Comment("允许的设备ID列表"), field.JSON("processingParams", map[string]any{}).Optional().SchemaType(map[string]string{ dialect.Postgres: "jsonb", }).Comment("加工参数"), field.String("nextStepDefault").Default("").Comment("默认下一步 stepId"), field.JSON("nextStepBranches", map[string]any{}).Optional().SchemaType(map[string]string{ dialect.Postgres: "jsonb", }).Comment("条件分支:条件→stepId"), field.Int("stepTimeout").Default(0).Comment("工序超时秒数"), field.Int("restoreStep").Default(-1).Comment("恢复时回退步数(-1=不回退)"), field.String("desc").Default("").Comment("描述"), } } func (RecipeStep) Edges() []ent.Edge { return []ent.Edge{ edge.From("recipe", Recipe.Type).Ref("steps").Field("recipeId").Unique().Required(), } } func (RecipeStep) Indexes() []ent.Index { return []ent.Index{ index.Fields("recipeId", "stepIndex").Unique(), index.Fields("recipeId", "stepId").Unique(), } }