feat: 新增 AgvPoint 点位表及客户端,支持点位编码与接驳台绑定
This commit is contained in:
@@ -0,0 +1,318 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"bj_power_mes/ent/agvpoint"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// AgvPointCreate is the builder for creating a AgvPoint entity.
|
||||
type AgvPointCreate struct {
|
||||
config
|
||||
mutation *AgvPointMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetPositionCode sets the "position_code" field.
|
||||
func (_c *AgvPointCreate) SetPositionCode(v string) *AgvPointCreate {
|
||||
_c.mutation.SetPositionCode(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *AgvPointCreate) SetName(v string) *AgvPointCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *AgvPointCreate) SetNillableName(v *string) *AgvPointCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetIsDock sets the "is_dock" field.
|
||||
func (_c *AgvPointCreate) SetIsDock(v bool) *AgvPointCreate {
|
||||
_c.mutation.SetIsDock(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableIsDock sets the "is_dock" field if the given value is not nil.
|
||||
func (_c *AgvPointCreate) SetNillableIsDock(v *bool) *AgvPointCreate {
|
||||
if v != nil {
|
||||
_c.SetIsDock(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDockID sets the "dock_id" field.
|
||||
func (_c *AgvPointCreate) SetDockID(v int) *AgvPointCreate {
|
||||
_c.mutation.SetDockID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDockID sets the "dock_id" field if the given value is not nil.
|
||||
func (_c *AgvPointCreate) SetNillableDockID(v *int) *AgvPointCreate {
|
||||
if v != nil {
|
||||
_c.SetDockID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetEnabled sets the "enabled" field.
|
||||
func (_c *AgvPointCreate) SetEnabled(v bool) *AgvPointCreate {
|
||||
_c.mutation.SetEnabled(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableEnabled sets the "enabled" field if the given value is not nil.
|
||||
func (_c *AgvPointCreate) SetNillableEnabled(v *bool) *AgvPointCreate {
|
||||
if v != nil {
|
||||
_c.SetEnabled(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *AgvPointCreate) SetCreatedAt(v time.Time) *AgvPointCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *AgvPointCreate) SetNillableCreatedAt(v *time.Time) *AgvPointCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the AgvPointMutation object of the builder.
|
||||
func (_c *AgvPointCreate) Mutation() *AgvPointMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the AgvPoint in the database.
|
||||
func (_c *AgvPointCreate) Save(ctx context.Context) (*AgvPoint, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *AgvPointCreate) SaveX(ctx context.Context) *AgvPoint {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *AgvPointCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *AgvPointCreate) 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 *AgvPointCreate) defaults() {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
v := agvpoint.DefaultName
|
||||
_c.mutation.SetName(v)
|
||||
}
|
||||
if _, ok := _c.mutation.IsDock(); !ok {
|
||||
v := agvpoint.DefaultIsDock
|
||||
_c.mutation.SetIsDock(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Enabled(); !ok {
|
||||
v := agvpoint.DefaultEnabled
|
||||
_c.mutation.SetEnabled(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := agvpoint.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *AgvPointCreate) check() error {
|
||||
if _, ok := _c.mutation.PositionCode(); !ok {
|
||||
return &ValidationError{Name: "position_code", err: errors.New(`ent: missing required field "AgvPoint.position_code"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.PositionCode(); ok {
|
||||
if err := agvpoint.PositionCodeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "position_code", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.position_code": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "AgvPoint.name"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Name(); ok {
|
||||
if err := agvpoint.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.IsDock(); !ok {
|
||||
return &ValidationError{Name: "is_dock", err: errors.New(`ent: missing required field "AgvPoint.is_dock"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Enabled(); !ok {
|
||||
return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "AgvPoint.enabled"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AgvPoint.created_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *AgvPointCreate) sqlSave(ctx context.Context) (*AgvPoint, 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
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *AgvPointCreate) createSpec() (*AgvPoint, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &AgvPoint{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(agvpoint.Table, sqlgraph.NewFieldSpec(agvpoint.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.PositionCode(); ok {
|
||||
_spec.SetField(agvpoint.FieldPositionCode, field.TypeString, value)
|
||||
_node.PositionCode = value
|
||||
}
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(agvpoint.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.IsDock(); ok {
|
||||
_spec.SetField(agvpoint.FieldIsDock, field.TypeBool, value)
|
||||
_node.IsDock = value
|
||||
}
|
||||
if value, ok := _c.mutation.DockID(); ok {
|
||||
_spec.SetField(agvpoint.FieldDockID, field.TypeInt, value)
|
||||
_node.DockID = &value
|
||||
}
|
||||
if value, ok := _c.mutation.Enabled(); ok {
|
||||
_spec.SetField(agvpoint.FieldEnabled, field.TypeBool, value)
|
||||
_node.Enabled = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(agvpoint.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// AgvPointCreateBulk is the builder for creating many AgvPoint entities in bulk.
|
||||
type AgvPointCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*AgvPointCreate
|
||||
}
|
||||
|
||||
// Save creates the AgvPoint entities in the database.
|
||||
func (_c *AgvPointCreateBulk) Save(ctx context.Context) ([]*AgvPoint, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*AgvPoint, 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.(*AgvPointMutation)
|
||||
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 {
|
||||
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 *AgvPointCreateBulk) SaveX(ctx context.Context) []*AgvPoint {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *AgvPointCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *AgvPointCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user