- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页) - WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报 - AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典 - 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列 - 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等) - 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
374 lines
12 KiB
Go
374 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/productprocessmaterial"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// ProductProcessMaterialCreate is the builder for creating a ProductProcessMaterial entity.
|
|
type ProductProcessMaterialCreate struct {
|
|
config
|
|
mutation *ProductProcessMaterialMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetProductProcessId sets the "productProcessId" field.
|
|
func (_c *ProductProcessMaterialCreate) SetProductProcessId(v int) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetProductProcessId(v)
|
|
return _c
|
|
}
|
|
|
|
// SetSeq sets the "seq" field.
|
|
func (_c *ProductProcessMaterialCreate) SetSeq(v int) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetSeq(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableSeq sets the "seq" field if the given value is not nil.
|
|
func (_c *ProductProcessMaterialCreate) SetNillableSeq(v *int) *ProductProcessMaterialCreate {
|
|
if v != nil {
|
|
_c.SetSeq(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetFlowId sets the "flowId" field.
|
|
func (_c *ProductProcessMaterialCreate) SetFlowId(v int) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetFlowId(v)
|
|
return _c
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_c *ProductProcessMaterialCreate) SetMaterialCode(v string) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetMaterialCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_c *ProductProcessMaterialCreate) SetMaterialName(v string) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetMaterialName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_c *ProductProcessMaterialCreate) SetNillableMaterialName(v *string) *ProductProcessMaterialCreate {
|
|
if v != nil {
|
|
_c.SetMaterialName(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_c *ProductProcessMaterialCreate) SetUnit(v string) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetUnit(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_c *ProductProcessMaterialCreate) SetNillableUnit(v *string) *ProductProcessMaterialCreate {
|
|
if v != nil {
|
|
_c.SetUnit(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUnitQty sets the "unitQty" field.
|
|
func (_c *ProductProcessMaterialCreate) SetUnitQty(v float64) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetUnitQty(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUnitQty sets the "unitQty" field if the given value is not nil.
|
|
func (_c *ProductProcessMaterialCreate) SetNillableUnitQty(v *float64) *ProductProcessMaterialCreate {
|
|
if v != nil {
|
|
_c.SetUnitQty(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "createdAt" field.
|
|
func (_c *ProductProcessMaterialCreate) SetCreatedAt(v time.Time) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
|
func (_c *ProductProcessMaterialCreate) SetNillableCreatedAt(v *time.Time) *ProductProcessMaterialCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *ProductProcessMaterialCreate) SetID(v int) *ProductProcessMaterialCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the ProductProcessMaterialMutation object of the builder.
|
|
func (_c *ProductProcessMaterialCreate) Mutation() *ProductProcessMaterialMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the ProductProcessMaterial in the database.
|
|
func (_c *ProductProcessMaterialCreate) Save(ctx context.Context) (*ProductProcessMaterial, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *ProductProcessMaterialCreate) SaveX(ctx context.Context) *ProductProcessMaterial {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProductProcessMaterialCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProductProcessMaterialCreate) 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 *ProductProcessMaterialCreate) defaults() {
|
|
if _, ok := _c.mutation.Seq(); !ok {
|
|
v := productprocessmaterial.DefaultSeq
|
|
_c.mutation.SetSeq(v)
|
|
}
|
|
if _, ok := _c.mutation.MaterialName(); !ok {
|
|
v := productprocessmaterial.DefaultMaterialName
|
|
_c.mutation.SetMaterialName(v)
|
|
}
|
|
if _, ok := _c.mutation.Unit(); !ok {
|
|
v := productprocessmaterial.DefaultUnit
|
|
_c.mutation.SetUnit(v)
|
|
}
|
|
if _, ok := _c.mutation.UnitQty(); !ok {
|
|
v := productprocessmaterial.DefaultUnitQty
|
|
_c.mutation.SetUnitQty(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := productprocessmaterial.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *ProductProcessMaterialCreate) check() error {
|
|
if _, ok := _c.mutation.ProductProcessId(); !ok {
|
|
return &ValidationError{Name: "productProcessId", err: errors.New(`ent: missing required field "ProductProcessMaterial.productProcessId"`)}
|
|
}
|
|
if _, ok := _c.mutation.Seq(); !ok {
|
|
return &ValidationError{Name: "seq", err: errors.New(`ent: missing required field "ProductProcessMaterial.seq"`)}
|
|
}
|
|
if _, ok := _c.mutation.FlowId(); !ok {
|
|
return &ValidationError{Name: "flowId", err: errors.New(`ent: missing required field "ProductProcessMaterial.flowId"`)}
|
|
}
|
|
if _, ok := _c.mutation.MaterialCode(); !ok {
|
|
return &ValidationError{Name: "materialCode", err: errors.New(`ent: missing required field "ProductProcessMaterial.materialCode"`)}
|
|
}
|
|
if v, ok := _c.mutation.MaterialCode(); ok {
|
|
if err := productprocessmaterial.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "ProductProcessMaterial.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.MaterialName(); !ok {
|
|
return &ValidationError{Name: "materialName", err: errors.New(`ent: missing required field "ProductProcessMaterial.materialName"`)}
|
|
}
|
|
if v, ok := _c.mutation.MaterialName(); ok {
|
|
if err := productprocessmaterial.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "ProductProcessMaterial.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Unit(); !ok {
|
|
return &ValidationError{Name: "unit", err: errors.New(`ent: missing required field "ProductProcessMaterial.unit"`)}
|
|
}
|
|
if v, ok := _c.mutation.Unit(); ok {
|
|
if err := productprocessmaterial.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "ProductProcessMaterial.unit": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.UnitQty(); !ok {
|
|
return &ValidationError{Name: "unitQty", err: errors.New(`ent: missing required field "ProductProcessMaterial.unitQty"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "ProductProcessMaterial.createdAt"`)}
|
|
}
|
|
if v, ok := _c.mutation.ID(); ok {
|
|
if err := productprocessmaterial.IDValidator(v); err != nil {
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "ProductProcessMaterial.id": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *ProductProcessMaterialCreate) sqlSave(ctx context.Context) (*ProductProcessMaterial, 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 *ProductProcessMaterialCreate) createSpec() (*ProductProcessMaterial, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &ProductProcessMaterial{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(productprocessmaterial.Table, sqlgraph.NewFieldSpec(productprocessmaterial.FieldID, field.TypeInt))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.ProductProcessId(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldProductProcessId, field.TypeInt, value)
|
|
_node.ProductProcessId = value
|
|
}
|
|
if value, ok := _c.mutation.Seq(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldSeq, field.TypeInt, value)
|
|
_node.Seq = value
|
|
}
|
|
if value, ok := _c.mutation.FlowId(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldFlowId, field.TypeInt, value)
|
|
_node.FlowId = value
|
|
}
|
|
if value, ok := _c.mutation.MaterialCode(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldMaterialCode, field.TypeString, value)
|
|
_node.MaterialCode = value
|
|
}
|
|
if value, ok := _c.mutation.MaterialName(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldMaterialName, field.TypeString, value)
|
|
_node.MaterialName = value
|
|
}
|
|
if value, ok := _c.mutation.Unit(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldUnit, field.TypeString, value)
|
|
_node.Unit = value
|
|
}
|
|
if value, ok := _c.mutation.UnitQty(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldUnitQty, field.TypeFloat64, value)
|
|
_node.UnitQty = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(productprocessmaterial.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// ProductProcessMaterialCreateBulk is the builder for creating many ProductProcessMaterial entities in bulk.
|
|
type ProductProcessMaterialCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*ProductProcessMaterialCreate
|
|
}
|
|
|
|
// Save creates the ProductProcessMaterial entities in the database.
|
|
func (_c *ProductProcessMaterialCreateBulk) Save(ctx context.Context) ([]*ProductProcessMaterial, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*ProductProcessMaterial, 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.(*ProductProcessMaterialMutation)
|
|
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 *ProductProcessMaterialCreateBulk) SaveX(ctx context.Context) []*ProductProcessMaterial {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *ProductProcessMaterialCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *ProductProcessMaterialCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|