Files
bj_power/bj_power_mes/schema/product_bom.go
T

50 lines
1.9 KiB
Go
Raw Normal View History

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"
)
// ProductBOM 成品 BOM 总账(2026-11-13 拍板「总分制」):
// 挂在【成品】下,一台成品需要哪些物料、各用多少,只在这里维护一次。
// 彻底废除旧的「分总公用」思路——flow_material 不再是可被多个成品随意借用的公共清单,
// 而是由「产品工艺」把本表物料分配到各工序后生成的执行口径(见 ProductProcessMaterial)。
// 总账不直接参与备料计算;下游 10+ 消费方仍读 flow_material,避免一次改全链路。
type ProductBOM struct {
ent.Schema
}
func (ProductBOM) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{Table: "product_bom"}, entsql.WithComments(true),
schema.Comment("ProductBOM 成品BOM总账:某成品整机需要的物料及单台用量(总分制的总账)。"),
}
}
func (ProductBOM) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
field.String("productCode").MaxLen(64).Comment("成品编码(成品档案 code,即图号唯一码)"),
field.String("materialCode").MaxLen(64).Comment("物料编码"),
field.String("materialName").Default("").MaxLen(128),
field.String("spec").Default("").MaxLen(128),
field.String("unit").Default("").MaxLen(16),
field.Float("unitQty").Default(0).Comment("单台用量(总账量,必须等于各工序分账量之和)"),
field.Float("lossRate").Default(0).Comment("损耗率%(展示口径,不参与备料计算)"),
field.String("remark").Default("").MaxLen(255),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}
func (ProductBOM) Indexes() []ent.Index {
return []ent.Index{
index.Fields("productCode"),
index.Fields("productCode", "materialCode").Unique(),
}
}