Files
bj_power/bj_power_mes/schema/bom_item.go
T

49 lines
1.5 KiB
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
2026-08-29 15:30:25 +08:00
// BomItem 产品 BOM 明细(按产品编码维护,同一型号多个工单共用)
2026-08-28 15:06:01 +08:00
type BomItem struct {
ent.Schema
}
func (BomItem) Annotations() []schema.Annotation {
return []schema.Annotation{entsql.Annotation{Table: "work_order_bom"}}
}
func (BomItem) Fields() []ent.Field {
return []ent.Field{
field.Int("id").Positive(),
2026-08-29 15:30:25 +08:00
field.String("productCode").Default("").MaxLen(64).Comment("产品编码"),
2026-08-28 15:06:01 +08:00
field.String("materialCode").MaxLen(64).Comment("物料编码"),
field.String("materialName").Default("").MaxLen(128),
field.String("spec").Default("").MaxLen(128),
field.String("unit").Default("").MaxLen(16),
// 1 批次(结构件) / 2 序列号(精密件)
field.String("manageMode").Default("2").MaxLen(10),
field.Float("unitQty").Default(0).Comment("单台用量"),
field.Float("lossRate").Default(0).Comment("损耗率%"),
field.Float("requiredQty").Default(0).Comment("需求总量=总台数*单台*(1+损耗)"),
field.JSON("serialSns", []string{}).Optional().SchemaType(map[string]string{
dialect.Postgres: "jsonb",
}).Comment("精密件SN下发列表(可选)"),
field.Time("createdAt").Default(time.Now).Immutable(),
}
}
func (BomItem) Indexes() []ent.Index {
return []ent.Index{
2026-08-29 15:30:25 +08:00
index.Fields("productCode"),
index.Fields("productCode", "materialCode").Unique(),
2026-08-28 15:06:01 +08:00
}
2026-08-29 15:30:25 +08:00
}