360 lines
11 KiB
Go
360 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bj_power_mes/ent/stationterminalevent"
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
)
|
||
|
|
|
||
|
|
// StationTerminalEventCreate is the builder for creating a StationTerminalEvent entity.
|
||
|
|
type StationTerminalEventCreate struct {
|
||
|
|
config
|
||
|
|
mutation *StationTerminalEventMutation
|
||
|
|
hooks []Hook
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetStationNo sets the "stationNo" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetStationNo(v int) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetStationNo(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetEvent sets the "event" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetEvent(v string) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetEvent(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetLoggedIn sets the "loggedIn" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetLoggedIn(v bool) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetLoggedIn(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableLoggedIn sets the "loggedIn" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalEventCreate) SetNillableLoggedIn(v *bool) *StationTerminalEventCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetLoggedIn(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetPowered sets the "powered" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetPowered(v bool) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetPowered(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillablePowered sets the "powered" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalEventCreate) SetNillablePowered(v *bool) *StationTerminalEventCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetPowered(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetOperator sets the "operator" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetOperator(v string) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalEventCreate) SetNillableOperator(v *string) *StationTerminalEventCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetOperator(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetDetail sets the "detail" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetDetail(v string) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetDetail(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableDetail sets the "detail" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalEventCreate) SetNillableDetail(v *string) *StationTerminalEventCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetDetail(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetCreatedAt sets the "createdAt" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetCreatedAt(v int64) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
||
|
|
func (_c *StationTerminalEventCreate) SetNillableCreatedAt(v *int64) *StationTerminalEventCreate {
|
||
|
|
if v != nil {
|
||
|
|
_c.SetCreatedAt(*v)
|
||
|
|
}
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetID sets the "id" field.
|
||
|
|
func (_c *StationTerminalEventCreate) SetID(v int) *StationTerminalEventCreate {
|
||
|
|
_c.mutation.SetID(v)
|
||
|
|
return _c
|
||
|
|
}
|
||
|
|
|
||
|
|
// Mutation returns the StationTerminalEventMutation object of the builder.
|
||
|
|
func (_c *StationTerminalEventCreate) Mutation() *StationTerminalEventMutation {
|
||
|
|
return _c.mutation
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the StationTerminalEvent in the database.
|
||
|
|
func (_c *StationTerminalEventCreate) Save(ctx context.Context) (*StationTerminalEvent, error) {
|
||
|
|
_c.defaults()
|
||
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveX calls Save and panics if Save returns an error.
|
||
|
|
func (_c *StationTerminalEventCreate) SaveX(ctx context.Context) *StationTerminalEvent {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *StationTerminalEventCreate) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *StationTerminalEventCreate) 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 *StationTerminalEventCreate) defaults() {
|
||
|
|
if _, ok := _c.mutation.LoggedIn(); !ok {
|
||
|
|
v := stationterminalevent.DefaultLoggedIn
|
||
|
|
_c.mutation.SetLoggedIn(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Powered(); !ok {
|
||
|
|
v := stationterminalevent.DefaultPowered
|
||
|
|
_c.mutation.SetPowered(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
v := stationterminalevent.DefaultOperator
|
||
|
|
_c.mutation.SetOperator(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Detail(); !ok {
|
||
|
|
v := stationterminalevent.DefaultDetail
|
||
|
|
_c.mutation.SetDetail(v)
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
v := stationterminalevent.DefaultCreatedAt
|
||
|
|
_c.mutation.SetCreatedAt(v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// check runs all checks and user-defined validators on the builder.
|
||
|
|
func (_c *StationTerminalEventCreate) check() error {
|
||
|
|
if _, ok := _c.mutation.StationNo(); !ok {
|
||
|
|
return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "StationTerminalEvent.stationNo"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Event(); !ok {
|
||
|
|
return &ValidationError{Name: "event", err: errors.New(`ent: missing required field "StationTerminalEvent.event"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Event(); ok {
|
||
|
|
if err := stationterminalevent.EventValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "event", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.event": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.LoggedIn(); !ok {
|
||
|
|
return &ValidationError{Name: "loggedIn", err: errors.New(`ent: missing required field "StationTerminalEvent.loggedIn"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Powered(); !ok {
|
||
|
|
return &ValidationError{Name: "powered", err: errors.New(`ent: missing required field "StationTerminalEvent.powered"`)}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
||
|
|
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "StationTerminalEvent.operator"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Operator(); ok {
|
||
|
|
if err := stationterminalevent.OperatorValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.operator": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.Detail(); !ok {
|
||
|
|
return &ValidationError{Name: "detail", err: errors.New(`ent: missing required field "StationTerminalEvent.detail"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.Detail(); ok {
|
||
|
|
if err := stationterminalevent.DetailValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "detail", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.detail": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||
|
|
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "StationTerminalEvent.createdAt"`)}
|
||
|
|
}
|
||
|
|
if v, ok := _c.mutation.ID(); ok {
|
||
|
|
if err := stationterminalevent.IDValidator(v); err != nil {
|
||
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "StationTerminalEvent.id": %w`, err)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (_c *StationTerminalEventCreate) sqlSave(ctx context.Context) (*StationTerminalEvent, 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 *StationTerminalEventCreate) createSpec() (*StationTerminalEvent, *sqlgraph.CreateSpec) {
|
||
|
|
var (
|
||
|
|
_node = &StationTerminalEvent{config: _c.config}
|
||
|
|
_spec = sqlgraph.NewCreateSpec(stationterminalevent.Table, sqlgraph.NewFieldSpec(stationterminalevent.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(stationterminalevent.FieldStationNo, field.TypeInt, value)
|
||
|
|
_node.StationNo = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Event(); ok {
|
||
|
|
_spec.SetField(stationterminalevent.FieldEvent, field.TypeString, value)
|
||
|
|
_node.Event = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.LoggedIn(); ok {
|
||
|
|
_spec.SetField(stationterminalevent.FieldLoggedIn, field.TypeBool, value)
|
||
|
|
_node.LoggedIn = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Powered(); ok {
|
||
|
|
_spec.SetField(stationterminalevent.FieldPowered, field.TypeBool, value)
|
||
|
|
_node.Powered = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Operator(); ok {
|
||
|
|
_spec.SetField(stationterminalevent.FieldOperator, field.TypeString, value)
|
||
|
|
_node.Operator = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.Detail(); ok {
|
||
|
|
_spec.SetField(stationterminalevent.FieldDetail, field.TypeString, value)
|
||
|
|
_node.Detail = value
|
||
|
|
}
|
||
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
||
|
|
_spec.SetField(stationterminalevent.FieldCreatedAt, field.TypeInt64, value)
|
||
|
|
_node.CreatedAt = value
|
||
|
|
}
|
||
|
|
return _node, _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
// StationTerminalEventCreateBulk is the builder for creating many StationTerminalEvent entities in bulk.
|
||
|
|
type StationTerminalEventCreateBulk struct {
|
||
|
|
config
|
||
|
|
err error
|
||
|
|
builders []*StationTerminalEventCreate
|
||
|
|
}
|
||
|
|
|
||
|
|
// Save creates the StationTerminalEvent entities in the database.
|
||
|
|
func (_c *StationTerminalEventCreateBulk) Save(ctx context.Context) ([]*StationTerminalEvent, error) {
|
||
|
|
if _c.err != nil {
|
||
|
|
return nil, _c.err
|
||
|
|
}
|
||
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||
|
|
nodes := make([]*StationTerminalEvent, 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.(*StationTerminalEventMutation)
|
||
|
|
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 *StationTerminalEventCreateBulk) SaveX(ctx context.Context) []*StationTerminalEvent {
|
||
|
|
v, err := _c.Save(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return v
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exec executes the query.
|
||
|
|
func (_c *StationTerminalEventCreateBulk) Exec(ctx context.Context) error {
|
||
|
|
_, err := _c.Save(ctx)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExecX is like Exec, but panics if an error occurs.
|
||
|
|
func (_c *StationTerminalEventCreateBulk) ExecX(ctx context.Context) {
|
||
|
|
if err := _c.Exec(ctx); err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
}
|