2026-09-22 11:32:29 +08:00
|
|
|
package schema
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"entgo.io/ent"
|
|
|
|
|
"entgo.io/ent/dialect/entsql"
|
|
|
|
|
"entgo.io/ent/schema"
|
|
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
|
"entgo.io/ent/schema/index"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// FlowMaterial 工艺物料清单:一道工艺装什么料、单台用多少(备料/齐套校验的唯一源头)。
|
2026-10-10 15:58:59 +08:00
|
|
|
// 约束:物料必须属于产品物料清单子集(写入时校验)。
|
2026-09-22 11:32:29 +08:00
|
|
|
type FlowMaterial struct {
|
|
|
|
|
ent.Schema
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (FlowMaterial) Annotations() []schema.Annotation {
|
2026-10-08 13:09:53 +08:00
|
|
|
return []schema.Annotation{entsql.Annotation{Table: "flow_material"}, entsql.WithComments(true), schema.Comment("FlowMaterial 工艺物料清单:一道工艺装什么料、单台用多少(备料/齐套校验的唯一源头)。")}
|
2026-09-22 11:32:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (FlowMaterial) Fields() []ent.Field {
|
|
|
|
|
return []ent.Field{
|
|
|
|
|
field.Int("id").Positive(),
|
|
|
|
|
field.Int("flowId").Comment("所属工艺ID"),
|
|
|
|
|
field.String("materialCode").MaxLen(64).Comment("物料编码"),
|
|
|
|
|
field.String("materialName").Default("").MaxLen(128),
|
|
|
|
|
field.String("spec").Default("").MaxLen(128),
|
|
|
|
|
field.String("unit").Default("").MaxLen(16),
|
2026-10-10 15:58:59 +08:00
|
|
|
// 是否逐件SN管理(冗余自物料档案 sn_mode,绑定/备料行为唯一依据):1 序列号=是(录SN) / 2 序列号=否
|
2026-09-30 17:33:11 +08:00
|
|
|
field.Int("snMode").Default(2),
|
2026-09-22 11:32:29 +08:00
|
|
|
field.Float("unitQty").Default(0).Comment("单台用量"),
|
2026-11-04 19:06:03 +08:00
|
|
|
field.Float("lossRate").Default(0).Comment("损耗率%(仅展示口径,不参与备料计算——R7 2026-11-03 拍板:备料量=工单需求×单台用量,损耗走补料审批)"),
|
2026-09-22 11:32:29 +08:00
|
|
|
field.Time("createdAt").Default(time.Now).Immutable(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (FlowMaterial) Indexes() []ent.Index {
|
|
|
|
|
return []ent.Index{
|
|
|
|
|
index.Fields("flowId"),
|
|
|
|
|
index.Fields("flowId", "materialCode").Unique(),
|
|
|
|
|
}
|
|
|
|
|
}
|