- 在main.go中添加定时任务每10分钟同步可生产数量到WMS系统 - 为BomItem实体添加relatedStandard字段及相关CRUD方法 - 为InspectionRecord实体添加reportNo、materialCode、materialName等字段 - 更新ent schema确保新字段的验证和默认值设置 - 添加必要的数据库迁移和字段映射逻辑
53 lines
2.0 KiB
Go
53 lines
2.0 KiB
Go
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"
|
||
)
|
||
|
||
// BomItem 产品 BOM 明细(一个产品型号可并存多份 BOM:不同厂家供货/含半成品等不同料单结构,工单建单时选定一份)
|
||
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(),
|
||
field.String("productCode").Default("").MaxLen(64).Comment("产品编码"),
|
||
field.String("bomName").Default("默认").MaxLen(64).Comment("BOM名称:同一型号多份并存(如 厂家A/厂家B/含半成品),工单按名选用"),
|
||
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),
|
||
// 装配工序 1..12:该料在第几道工序被装配(装机绑定/齐套校验按此过滤);0=未指定,不参与工位绑定校验
|
||
field.Int("processCode").Default(0).Comment("装配工序 1~12,0=不参与工位绑定"),
|
||
field.Float("unitQty").Default(0).Comment("单台用量"),
|
||
field.Float("lossRate").Default(0).Comment("损耗率%"),
|
||
field.String("relatedStandard").Default("").MaxLen(255).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{
|
||
index.Fields("productCode"),
|
||
index.Fields("productCode", "bomName", "materialCode").Unique(),
|
||
}
|
||
}
|