362 lines
11 KiB
Go
362 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_mes/ent/stationterminalstate"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StationTerminalStateCreate is the builder for creating a StationTerminalState entity.
|
||
|
|
type StationTerminalStateCreate struct {
|
||
|
|
config
|
||
|
|
mutation *StationTerminalStateMutation
|
||
|
|
hooks []Hook
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetStationNo sets the "stationNo" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetStationNo(v int) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetStationNo(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPowered sets the "powered" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetPowered(v bool) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetPowered(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePowered sets the "powered" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalStateCreate) SetNillablePowered(v *bool) *StationTerminalStateCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetPowered(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLoggedIn sets the "loggedIn" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetLoggedIn(v bool) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetLoggedIn(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLoggedIn sets the "loggedIn" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalStateCreate) SetNillableLoggedIn(v *bool) *StationTerminalStateCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetLoggedIn(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetOperator(v string) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalStateCreate) SetNillableOperator(v *string) *StationTerminalStateCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetOperator(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPaused sets the "paused" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetPaused(v bool) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetPaused(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePaused sets the "paused" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalStateCreate) SetNillablePaused(v *bool) *StationTerminalStateCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetPaused(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLastHeartbeatAt sets the "lastHeartbeatAt" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetLastHeartbeatAt(v int64) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetLastHeartbeatAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLastHeartbeatAt sets the "lastHeartbeatAt" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalStateCreate) SetNillableLastHeartbeatAt(v *int64) *StationTerminalStateCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetLastHeartbeatAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetUpdatedAt(v int64) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetUpdatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalStateCreate) SetNillableUpdatedAt(v *int64) *StationTerminalStateCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetUpdatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetID sets the "id" field.
|
||
|
|
func (_c *StationTerminalStateCreate) SetID(v int) *StationTerminalStateCreate {
|
||
|
|
_c.mutation.SetID(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the StationTerminalStateMutation object of the builder.
|
||
|
|
func (_c *StationTerminalStateCreate) Mutation() *StationTerminalStateMutation {
|
||
|
|
return _c.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the StationTerminalState in the database.
|
||
|
|
func (_c *StationTerminalStateCreate) Save(ctx context.Context) (*StationTerminalState, error) {
|
||
|
|
_c.defaults()
|
||
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
|
func (_c *StationTerminalStateCreate) SaveX(ctx context.Context) *StationTerminalState {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *StationTerminalStateCreate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *StationTerminalStateCreate) 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 *StationTerminalStateCreate) defaults() {
|
||
|
|
if _, ok := _c.mutation.Powered(); !ok {
|
||
|
|
v := stationterminalstate.DefaultPowered
|
||
|
|
_c.mutation.SetPowered(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.LoggedIn(); !ok {
|
||
|
|
v := stationterminalstate.DefaultLoggedIn
|
||
|
|
_c.mutation.SetLoggedIn(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
v := stationterminalstate.DefaultOperator
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Paused(); !ok {
|
||
|
|
v := stationterminalstate.DefaultPaused
|
||
|
|
_c.mutation.SetPaused(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.LastHeartbeatAt(); !ok {
|
||
|
|
v := stationterminalstate.DefaultLastHeartbeatAt
|
||
|
|
_c.mutation.SetLastHeartbeatAt(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||
|
|
v := stationterminalstate.DefaultUpdatedAt
|
||
|
|
_c.mutation.SetUpdatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_c *StationTerminalStateCreate) check() error {
|
||
|
|
if _, ok := _c.mutation.StationNo(); !ok {
|
||
|
|
return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "StationTerminalState.stationNo"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Powered(); !ok {
|
||
|
|
return &ValidationError{Name: "powered", err: errors.New(`ent: missing required field "StationTerminalState.powered"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.LoggedIn(); !ok {
|
||
|
|
return &ValidationError{Name: "loggedIn", err: errors.New(`ent: missing required field "StationTerminalState.loggedIn"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "StationTerminalState.operator"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Operator(); ok {
|
||
|
|
if err := stationterminalstate.OperatorValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationTerminalState.operator": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Paused(); !ok {
|
||
|
|
return &ValidationError{Name: "paused", err: errors.New(`ent: missing required field "StationTerminalState.paused"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.LastHeartbeatAt(); !ok {
|
||
|
|
return &ValidationError{Name: "lastHeartbeatAt", err: errors.New(`ent: missing required field "StationTerminalState.lastHeartbeatAt"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "updatedAt", err: errors.New(`ent: missing required field "StationTerminalState.updatedAt"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.ID(); ok {
|
||
|
|
if err := stationterminalstate.IDValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "StationTerminalState.id": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *StationTerminalStateCreate) sqlSave(ctx context.Context) (*StationTerminalState, 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 *StationTerminalStateCreate) createSpec() (*StationTerminalState, *sqlgraph.CreateSpec) {
|
||
|
|
var (
|
||
|
|
_node = &StationTerminalState{config: _c.config}
|
||
|
|
_spec = sqlgraph.NewCreateSpec(stationterminalstate.Table, sqlgraph.NewFieldSpec(stationterminalstate.FieldID, field.TypeInt))
|
||
|
|
)
|
||
|
|
if id, ok := _c.mutation.ID(); ok {
|
||
|
|
_node.ID = id
|
||
|
|
_spec.ID.Value = id
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.StationNo(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldStationNo, field.TypeInt, value)
|
||
|
|
_node.StationNo = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Powered(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldPowered, field.TypeBool, value)
|
||
|
|
_node.Powered = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.LoggedIn(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldLoggedIn, field.TypeBool, value)
|
||
|
|
_node.LoggedIn = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Operator(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldOperator, field.TypeString, value)
|
||
|
|
_node.Operator = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Paused(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldPaused, field.TypeBool, value)
|
||
|
|
_node.Paused = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.LastHeartbeatAt(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldLastHeartbeatAt, field.TypeInt64, value)
|
||
|
|
_node.LastHeartbeatAt = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||
|
|
_spec.SetField(stationterminalstate.FieldUpdatedAt, field.TypeInt64, value)
|
||
|
|
_node.UpdatedAt = value
|
||
|
|
}
|
||
|
|
return _node, _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
// StationTerminalStateCreateBulk is the builder for creating many StationTerminalState entities in bulk.
|
||
|
|
type StationTerminalStateCreateBulk struct {
|
||
|
|
config
|
||
|
|
err error
|
||
|
|
builders []*StationTerminalStateCreate
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the StationTerminalState entities in the database.
|
||
|
|
func (_c *StationTerminalStateCreateBulk) Save(ctx context.Context) ([]*StationTerminalState, error) {
|
||
|
|
if _c.err != nil {
|
||
|
|
return nil, _c.err
|
||
|
|
}
|
||
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||
|
|
nodes := make([]*StationTerminalState, 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.(*StationTerminalStateMutation)
|
||
|
|
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 *StationTerminalStateCreateBulk) SaveX(ctx context.Context) []*StationTerminalState {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *StationTerminalStateCreateBulk) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *StationTerminalStateCreateBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|