- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页) - WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报 - AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典 - 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列 - 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等) - 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
426 lines
13 KiB
Go
426 lines
13 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/productbom"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ProductBOMCreate is the builder for creating a ProductBOM entity.
|
|
type ProductBOMCreate struct {
|
|
config
|
|
mutation *ProductBOMMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetProductCode sets the "productCode" field.
|
|
func (_c *ProductBOMCreate) SetProductCode(v string) *ProductBOMCreate {
|
|
_c.mutation.SetProductCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_c *ProductBOMCreate) SetMaterialCode(v string) *ProductBOMCreate {
|
|
_c.mutation.SetMaterialCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_c *ProductBOMCreate) SetMaterialName(v string) *ProductBOMCreate {
|
|
_c.mutation.SetMaterialName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableMaterialName(v *string) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetMaterialName(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_c *ProductBOMCreate) SetSpec(v string) *ProductBOMCreate {
|
|
_c.mutation.SetSpec(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableSpec(v *string) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetSpec(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_c *ProductBOMCreate) SetUnit(v string) *ProductBOMCreate {
|
|
_c.mutation.SetUnit(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableUnit(v *string) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetUnit(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUnitQty sets the "unitQty" field.
|
|
func (_c *ProductBOMCreate) SetUnitQty(v float64) *ProductBOMCreate {
|
|
_c.mutation.SetUnitQty(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUnitQty sets the "unitQty" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableUnitQty(v *float64) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetUnitQty(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetLossRate sets the "lossRate" field.
|
|
func (_c *ProductBOMCreate) SetLossRate(v float64) *ProductBOMCreate {
|
|
_c.mutation.SetLossRate(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableLossRate sets the "lossRate" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableLossRate(v *float64) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetLossRate(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_c *ProductBOMCreate) SetRemark(v string) *ProductBOMCreate {
|
|
_c.mutation.SetRemark(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableRemark(v *string) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetRemark(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "createdAt" field.
|
|
func (_c *ProductBOMCreate) SetCreatedAt(v time.Time) *ProductBOMCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
|
func (_c *ProductBOMCreate) SetNillableCreatedAt(v *time.Time) *ProductBOMCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ProductBOMCreate) SetID(v int) *ProductBOMCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the ProductBOMMutation object of the builder.
|
|
func (_c *ProductBOMCreate) Mutation() *ProductBOMMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the ProductBOM in the database.
|
|
func (_c *ProductBOMCreate) Save(ctx context.Context) (*ProductBOM, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ProductBOMCreate) SaveX(ctx context.Context) *ProductBOM {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProductBOMCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProductBOMCreate) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// defaults sets the default values of the builder before save.
|
|
func (_c *ProductBOMCreate) defaults() {
|
|
if _, ok := _c.mutation.MaterialName(); !ok {
|
|
v := productbom.DefaultMaterialName
|
|
_c.mutation.SetMaterialName(v)
|
|
}
|
|
if _, ok := _c.mutation.Spec(); !ok {
|
|
v := productbom.DefaultSpec
|
|
_c.mutation.SetSpec(v)
|
|
}
|
|
if _, ok := _c.mutation.Unit(); !ok {
|
|
v := productbom.DefaultUnit
|
|
_c.mutation.SetUnit(v)
|
|
}
|
|
if _, ok := _c.mutation.UnitQty(); !ok {
|
|
v := productbom.DefaultUnitQty
|
|
_c.mutation.SetUnitQty(v)
|
|
}
|
|
if _, ok := _c.mutation.LossRate(); !ok {
|
|
v := productbom.DefaultLossRate
|
|
_c.mutation.SetLossRate(v)
|
|
}
|
|
if _, ok := _c.mutation.Remark(); !ok {
|
|
v := productbom.DefaultRemark
|
|
_c.mutation.SetRemark(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := productbom.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ProductBOMCreate) check() error {
|
|
if _, ok := _c.mutation.ProductCode(); !ok {
|
|
return &ValidationError{Name: "productCode", err: errors.New(`ent: missing required field "ProductBOM.productCode"`)}
|
|
}
|
|
if v, ok := _c.mutation.ProductCode(); ok {
|
|
if err := productbom.ProductCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "productCode", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.productCode": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.MaterialCode(); !ok {
|
|
return &ValidationError{Name: "materialCode", err: errors.New(`ent: missing required field "ProductBOM.materialCode"`)}
|
|
}
|
|
if v, ok := _c.mutation.MaterialCode(); ok {
|
|
if err := productbom.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.MaterialName(); !ok {
|
|
return &ValidationError{Name: "materialName", err: errors.New(`ent: missing required field "ProductBOM.materialName"`)}
|
|
}
|
|
if v, ok := _c.mutation.MaterialName(); ok {
|
|
if err := productbom.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Spec(); !ok {
|
|
return &ValidationError{Name: "spec", err: errors.New(`ent: missing required field "ProductBOM.spec"`)}
|
|
}
|
|
if v, ok := _c.mutation.Spec(); ok {
|
|
if err := productbom.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.spec": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Unit(); !ok {
|
|
return &ValidationError{Name: "unit", err: errors.New(`ent: missing required field "ProductBOM.unit"`)}
|
|
}
|
|
if v, ok := _c.mutation.Unit(); ok {
|
|
if err := productbom.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.unit": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.UnitQty(); !ok {
|
|
return &ValidationError{Name: "unitQty", err: errors.New(`ent: missing required field "ProductBOM.unitQty"`)}
|
|
}
|
|
if _, ok := _c.mutation.LossRate(); !ok {
|
|
return &ValidationError{Name: "lossRate", err: errors.New(`ent: missing required field "ProductBOM.lossRate"`)}
|
|
}
|
|
if _, ok := _c.mutation.Remark(); !ok {
|
|
return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "ProductBOM.remark"`)}
|
|
}
|
|
if v, ok := _c.mutation.Remark(); ok {
|
|
if err := productbom.RemarkValidator(v); err != nil {
|
|
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.remark": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "ProductBOM.createdAt"`)}
|
|
}
|
|
if v, ok := _c.mutation.ID(); ok {
|
|
if err := productbom.IDValidator(v); err != nil {
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "ProductBOM.id": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ProductBOMCreate) sqlSave(ctx context.Context) (*ProductBOM, error) {
|
|
if err := _c.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
_node, _spec := _c.createSpec()
|
|
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
if _spec.ID.Value != _node.ID {
|
|
id := _spec.ID.Value.(int64)
|
|
_node.ID = int(id)
|
|
}
|
|
_c.mutation.id = &_node.ID
|
|
_c.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
func (_c *ProductBOMCreate) createSpec() (*ProductBOM, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &ProductBOM{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(productbom.Table, sqlgraph.NewFieldSpec(productbom.FieldID, field.TypeInt))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.ProductCode(); ok {
|
|
_spec.SetField(productbom.FieldProductCode, field.TypeString, value)
|
|
_node.ProductCode = value
|
|
}
|
|
if value, ok := _c.mutation.MaterialCode(); ok {
|
|
_spec.SetField(productbom.FieldMaterialCode, field.TypeString, value)
|
|
_node.MaterialCode = value
|
|
}
|
|
if value, ok := _c.mutation.MaterialName(); ok {
|
|
_spec.SetField(productbom.FieldMaterialName, field.TypeString, value)
|
|
_node.MaterialName = value
|
|
}
|
|
if value, ok := _c.mutation.Spec(); ok {
|
|
_spec.SetField(productbom.FieldSpec, field.TypeString, value)
|
|
_node.Spec = value
|
|
}
|
|
if value, ok := _c.mutation.Unit(); ok {
|
|
_spec.SetField(productbom.FieldUnit, field.TypeString, value)
|
|
_node.Unit = value
|
|
}
|
|
if value, ok := _c.mutation.UnitQty(); ok {
|
|
_spec.SetField(productbom.FieldUnitQty, field.TypeFloat64, value)
|
|
_node.UnitQty = value
|
|
}
|
|
if value, ok := _c.mutation.LossRate(); ok {
|
|
_spec.SetField(productbom.FieldLossRate, field.TypeFloat64, value)
|
|
_node.LossRate = value
|
|
}
|
|
if value, ok := _c.mutation.Remark(); ok {
|
|
_spec.SetField(productbom.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(productbom.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// ProductBOMCreateBulk is the builder for creating many ProductBOM entities in bulk.
|
|
type ProductBOMCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ProductBOMCreate
|
|
}
|
|
|
|
// Save creates the ProductBOM entities in the database.
|
|
func (_c *ProductBOMCreateBulk) Save(ctx context.Context) ([]*ProductBOM, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*ProductBOM, len(_c.builders))
|
|
mutators := make([]Mutator, len(_c.builders))
|
|
for i := range _c.builders {
|
|
func(i int, root context.Context) {
|
|
builder := _c.builders[i]
|
|
builder.defaults()
|
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
|
mutation, ok := m.(*ProductBOMMutation)
|
|
if !ok {
|
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
|
}
|
|
if err := builder.check(); err != nil {
|
|
return nil, err
|
|
}
|
|
builder.mutation = mutation
|
|
var err error
|
|
nodes[i], specs[i] = builder.createSpec()
|
|
if i < len(mutators)-1 {
|
|
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
|
} else {
|
|
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
|
// Invoke the actual operation on the latest mutation in the chain.
|
|
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
|
if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
}
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
mutation.id = &nodes[i].ID
|
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
|
id := specs[i].ID.Value.(int64)
|
|
nodes[i].ID = int(id)
|
|
}
|
|
mutation.done = true
|
|
return nodes[i], nil
|
|
})
|
|
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
|
mut = builder.hooks[i](mut)
|
|
}
|
|
mutators[i] = mut
|
|
}(i, ctx)
|
|
}
|
|
if len(mutators) > 0 {
|
|
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
return nodes, nil
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_c *ProductBOMCreateBulk) SaveX(ctx context.Context) []*ProductBOM {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProductBOMCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProductBOMCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|