348 lines
11 KiB
Go
348 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_mes/ent/associationtrace"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AssociationTraceCreate is the builder for creating a AssociationTrace entity.
|
||
|
|
type AssociationTraceCreate struct {
|
||
|
|
config
|
||
|
|
mutation *AssociationTraceMutation
|
||
|
|
hooks []Hook
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetFinishedSn sets the "finishedSn" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetFinishedSn(v string) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetFinishedSn(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOrderNo sets the "orderNo" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetOrderNo(v string) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetOrderNo(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
|
||
|
|
func (_c *AssociationTraceCreate) SetNillableOrderNo(v *string) *AssociationTraceCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetOrderNo(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetProcessCode sets the "processCode" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetProcessCode(v string) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetProcessCode(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableProcessCode sets the "processCode" field if the given value is not nil.
|
||
|
|
func (_c *AssociationTraceCreate) SetNillableProcessCode(v *string) *AssociationTraceCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetProcessCode(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetBatchItems sets the "batchItems" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetBatchItems(v []string) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetBatchItems(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetSerialItems sets the "serialItems" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetSerialItems(v []string) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetSerialItems(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetOperator(v string) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
||
|
|
func (_c *AssociationTraceCreate) SetNillableOperator(v *string) *AssociationTraceCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetOperator(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "createdAt" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetCreatedAt(v time.Time) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
||
|
|
func (_c *AssociationTraceCreate) SetNillableCreatedAt(v *time.Time) *AssociationTraceCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetCreatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetID sets the "id" field.
|
||
|
|
func (_c *AssociationTraceCreate) SetID(v int) *AssociationTraceCreate {
|
||
|
|
_c.mutation.SetID(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the AssociationTraceMutation object of the builder.
|
||
|
|
func (_c *AssociationTraceCreate) Mutation() *AssociationTraceMutation {
|
||
|
|
return _c.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the AssociationTrace in the database.
|
||
|
|
func (_c *AssociationTraceCreate) Save(ctx context.Context) (*AssociationTrace, error) {
|
||
|
|
_c.defaults()
|
||
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
|
func (_c *AssociationTraceCreate) SaveX(ctx context.Context) *AssociationTrace {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *AssociationTraceCreate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *AssociationTraceCreate) 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 *AssociationTraceCreate) defaults() {
|
||
|
|
if _, ok := _c.mutation.OrderNo(); !ok {
|
||
|
|
v := associationtrace.DefaultOrderNo
|
||
|
|
_c.mutation.SetOrderNo(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.ProcessCode(); !ok {
|
||
|
|
v := associationtrace.DefaultProcessCode
|
||
|
|
_c.mutation.SetProcessCode(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
v := associationtrace.DefaultOperator
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
v := associationtrace.DefaultCreatedAt()
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_c *AssociationTraceCreate) check() error {
|
||
|
|
if _, ok := _c.mutation.FinishedSn(); !ok {
|
||
|
|
return &ValidationError{Name: "finishedSn", err: errors.New(`ent: missing required field "AssociationTrace.finishedSn"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.FinishedSn(); ok {
|
||
|
|
if err := associationtrace.FinishedSnValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "finishedSn", err: fmt.Errorf(`ent: validator failed for field "AssociationTrace.finishedSn": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.OrderNo(); !ok {
|
||
|
|
return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "AssociationTrace.orderNo"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.OrderNo(); ok {
|
||
|
|
if err := associationtrace.OrderNoValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "AssociationTrace.orderNo": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.ProcessCode(); !ok {
|
||
|
|
return &ValidationError{Name: "processCode", err: errors.New(`ent: missing required field "AssociationTrace.processCode"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.ProcessCode(); ok {
|
||
|
|
if err := associationtrace.ProcessCodeValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "processCode", err: fmt.Errorf(`ent: validator failed for field "AssociationTrace.processCode": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "AssociationTrace.operator"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Operator(); ok {
|
||
|
|
if err := associationtrace.OperatorValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "AssociationTrace.operator": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "AssociationTrace.createdAt"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.ID(); ok {
|
||
|
|
if err := associationtrace.IDValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "AssociationTrace.id": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *AssociationTraceCreate) sqlSave(ctx context.Context) (*AssociationTrace, 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 *AssociationTraceCreate) createSpec() (*AssociationTrace, *sqlgraph.CreateSpec) {
|
||
|
|
var (
|
||
|
|
_node = &AssociationTrace{config: _c.config}
|
||
|
|
_spec = sqlgraph.NewCreateSpec(associationtrace.Table, sqlgraph.NewFieldSpec(associationtrace.FieldID, field.TypeInt))
|
||
|
|
)
|
||
|
|
if id, ok := _c.mutation.ID(); ok {
|
||
|
|
_node.ID = id
|
||
|
|
_spec.ID.Value = id
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.FinishedSn(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldFinishedSn, field.TypeString, value)
|
||
|
|
_node.FinishedSn = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.OrderNo(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldOrderNo, field.TypeString, value)
|
||
|
|
_node.OrderNo = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.ProcessCode(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldProcessCode, field.TypeString, value)
|
||
|
|
_node.ProcessCode = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.BatchItems(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldBatchItems, field.TypeJSON, value)
|
||
|
|
_node.BatchItems = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.SerialItems(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldSerialItems, field.TypeJSON, value)
|
||
|
|
_node.SerialItems = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Operator(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldOperator, field.TypeString, value)
|
||
|
|
_node.Operator = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||
|
|
_spec.SetField(associationtrace.FieldCreatedAt, field.TypeTime, value)
|
||
|
|
_node.CreatedAt = value
|
||
|
|
}
|
||
|
|
return _node, _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
// AssociationTraceCreateBulk is the builder for creating many AssociationTrace entities in bulk.
|
||
|
|
type AssociationTraceCreateBulk struct {
|
||
|
|
config
|
||
|
|
err error
|
||
|
|
builders []*AssociationTraceCreate
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the AssociationTrace entities in the database.
|
||
|
|
func (_c *AssociationTraceCreateBulk) Save(ctx context.Context) ([]*AssociationTrace, error) {
|
||
|
|
if _c.err != nil {
|
||
|
|
return nil, _c.err
|
||
|
|
}
|
||
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||
|
|
nodes := make([]*AssociationTrace, 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.(*AssociationTraceMutation)
|
||
|
|
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 *AssociationTraceCreateBulk) SaveX(ctx context.Context) []*AssociationTrace {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *AssociationTraceCreateBulk) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *AssociationTraceCreateBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|