Files
bj_power/bj_power_mes/ent/semiflow_create.go
T
2026-08-28 15:06:01 +08:00

368 lines
10 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/semiflow"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// SemiFlowCreate is the builder for creating a SemiFlow entity.
type SemiFlowCreate struct {
config
mutation *SemiFlowMutation
hooks []Hook
}
// SetSn sets the "sn" field.
func (_c *SemiFlowCreate) SetSn(v string) *SemiFlowCreate {
_c.mutation.SetSn(v)
return _c
}
// SetOrderNo sets the "orderNo" field.
func (_c *SemiFlowCreate) SetOrderNo(v string) *SemiFlowCreate {
_c.mutation.SetOrderNo(v)
return _c
}
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
func (_c *SemiFlowCreate) SetNillableOrderNo(v *string) *SemiFlowCreate {
if v != nil {
_c.SetOrderNo(*v)
}
return _c
}
// SetDoneProcessCodes sets the "doneProcessCodes" field.
func (_c *SemiFlowCreate) SetDoneProcessCodes(v []int) *SemiFlowCreate {
_c.mutation.SetDoneProcessCodes(v)
return _c
}
// SetAction sets the "action" field.
func (_c *SemiFlowCreate) SetAction(v string) *SemiFlowCreate {
_c.mutation.SetAction(v)
return _c
}
// SetNillableAction sets the "action" field if the given value is not nil.
func (_c *SemiFlowCreate) SetNillableAction(v *string) *SemiFlowCreate {
if v != nil {
_c.SetAction(*v)
}
return _c
}
// SetTargetDock sets the "targetDock" field.
func (_c *SemiFlowCreate) SetTargetDock(v string) *SemiFlowCreate {
_c.mutation.SetTargetDock(v)
return _c
}
// SetNillableTargetDock sets the "targetDock" field if the given value is not nil.
func (_c *SemiFlowCreate) SetNillableTargetDock(v *string) *SemiFlowCreate {
if v != nil {
_c.SetTargetDock(*v)
}
return _c
}
// SetOperator sets the "operator" field.
func (_c *SemiFlowCreate) SetOperator(v string) *SemiFlowCreate {
_c.mutation.SetOperator(v)
return _c
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_c *SemiFlowCreate) SetNillableOperator(v *string) *SemiFlowCreate {
if v != nil {
_c.SetOperator(*v)
}
return _c
}
// SetCreatedAt sets the "createdAt" field.
func (_c *SemiFlowCreate) SetCreatedAt(v time.Time) *SemiFlowCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (_c *SemiFlowCreate) SetNillableCreatedAt(v *time.Time) *SemiFlowCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *SemiFlowCreate) SetID(v int) *SemiFlowCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the SemiFlowMutation object of the builder.
func (_c *SemiFlowCreate) Mutation() *SemiFlowMutation {
return _c.mutation
}
// Save creates the SemiFlow in the database.
func (_c *SemiFlowCreate) Save(ctx context.Context) (*SemiFlow, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *SemiFlowCreate) SaveX(ctx context.Context) *SemiFlow {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SemiFlowCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SemiFlowCreate) 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 *SemiFlowCreate) defaults() {
if _, ok := _c.mutation.OrderNo(); !ok {
v := semiflow.DefaultOrderNo
_c.mutation.SetOrderNo(v)
}
if _, ok := _c.mutation.Action(); !ok {
v := semiflow.DefaultAction
_c.mutation.SetAction(v)
}
if _, ok := _c.mutation.TargetDock(); !ok {
v := semiflow.DefaultTargetDock
_c.mutation.SetTargetDock(v)
}
if _, ok := _c.mutation.Operator(); !ok {
v := semiflow.DefaultOperator
_c.mutation.SetOperator(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := semiflow.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *SemiFlowCreate) check() error {
if _, ok := _c.mutation.Sn(); !ok {
return &ValidationError{Name: "sn", err: errors.New(`ent: missing required field "SemiFlow.sn"`)}
}
if v, ok := _c.mutation.Sn(); ok {
if err := semiflow.SnValidator(v); err != nil {
return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.sn": %w`, err)}
}
}
if _, ok := _c.mutation.OrderNo(); !ok {
return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "SemiFlow.orderNo"`)}
}
if v, ok := _c.mutation.OrderNo(); ok {
if err := semiflow.OrderNoValidator(v); err != nil {
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.orderNo": %w`, err)}
}
}
if _, ok := _c.mutation.Action(); !ok {
return &ValidationError{Name: "action", err: errors.New(`ent: missing required field "SemiFlow.action"`)}
}
if v, ok := _c.mutation.Action(); ok {
if err := semiflow.ActionValidator(v); err != nil {
return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.action": %w`, err)}
}
}
if _, ok := _c.mutation.TargetDock(); !ok {
return &ValidationError{Name: "targetDock", err: errors.New(`ent: missing required field "SemiFlow.targetDock"`)}
}
if v, ok := _c.mutation.TargetDock(); ok {
if err := semiflow.TargetDockValidator(v); err != nil {
return &ValidationError{Name: "targetDock", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.targetDock": %w`, err)}
}
}
if _, ok := _c.mutation.Operator(); !ok {
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "SemiFlow.operator"`)}
}
if v, ok := _c.mutation.Operator(); ok {
if err := semiflow.OperatorValidator(v); err != nil {
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.operator": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "SemiFlow.createdAt"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := semiflow.IDValidator(v); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "SemiFlow.id": %w`, err)}
}
}
return nil
}
func (_c *SemiFlowCreate) sqlSave(ctx context.Context) (*SemiFlow, 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 *SemiFlowCreate) createSpec() (*SemiFlow, *sqlgraph.CreateSpec) {
var (
_node = &SemiFlow{config: _c.config}
_spec = sqlgraph.NewCreateSpec(semiflow.Table, sqlgraph.NewFieldSpec(semiflow.FieldID, field.TypeInt))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.Sn(); ok {
_spec.SetField(semiflow.FieldSn, field.TypeString, value)
_node.Sn = value
}
if value, ok := _c.mutation.OrderNo(); ok {
_spec.SetField(semiflow.FieldOrderNo, field.TypeString, value)
_node.OrderNo = value
}
if value, ok := _c.mutation.DoneProcessCodes(); ok {
_spec.SetField(semiflow.FieldDoneProcessCodes, field.TypeJSON, value)
_node.DoneProcessCodes = value
}
if value, ok := _c.mutation.Action(); ok {
_spec.SetField(semiflow.FieldAction, field.TypeString, value)
_node.Action = value
}
if value, ok := _c.mutation.TargetDock(); ok {
_spec.SetField(semiflow.FieldTargetDock, field.TypeString, value)
_node.TargetDock = value
}
if value, ok := _c.mutation.Operator(); ok {
_spec.SetField(semiflow.FieldOperator, field.TypeString, value)
_node.Operator = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(semiflow.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
return _node, _spec
}
// SemiFlowCreateBulk is the builder for creating many SemiFlow entities in bulk.
type SemiFlowCreateBulk struct {
config
err error
builders []*SemiFlowCreate
}
// Save creates the SemiFlow entities in the database.
func (_c *SemiFlowCreateBulk) Save(ctx context.Context) ([]*SemiFlow, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*SemiFlow, 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.(*SemiFlowMutation)
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 *SemiFlowCreateBulk) SaveX(ctx context.Context) []*SemiFlow {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SemiFlowCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SemiFlowCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}