Files
SunYF 5e2640c13a feat: AGV点位锁与缓存迁移 + 工位终端去离线队列 + WMS出入库增强
【MES】
- AGV点位/线路点位/AGV任务/工单 ent schema 重构(全量重生成 ent 代码)
- 新增派车锁 agv_point_lock.go:目标点位占用即拒车,JBT21 库房接驳台卸货后保持锁定待库管手动解锁
- 新增进程内 TTL 缓存 cache.go,由 Redis 看板缓存迁移至内存(singleflight 防击穿,去除外部依赖)
- AGV 三段链安全机制、车辆状态/接驳台左右互换、补料损耗闭环完善
- 来料检/工序卡/工单/质检/日排产/AGV 前端与帮助文档更新
- 新增 migrations/、sql/ 目录

【WMS】
- 出库、Excel 导出、物料、路由处理增强
- 配置与 DB 初始化调整;基础数据/成品入库/入库前端调整

【工位终端】
- 移除离线同步队列(syncer 包、sync.go、SyncQueueDialog.vue),改为实时直连上报 MES(断网即失败报错),以本人身份操作
- 本地 SQLite 仅保留操作日志 + 内置账号 + 登录态;保留空闲自动登出

【文档】
- 删除 AGV海康litev1.5.md;案例.md 更新
2026-11-07 15:06:00 +08:00

706 lines
21 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/agvtask"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// AgvTaskCreate is the builder for creating a AgvTask entity.
type AgvTaskCreate struct {
config
mutation *AgvTaskMutation
hooks []Hook
}
// SetTaskNo sets the "task_no" field.
func (_c *AgvTaskCreate) SetTaskNo(v string) *AgvTaskCreate {
_c.mutation.SetTaskNo(v)
return _c
}
// SetSourceDock sets the "source_dock" field.
func (_c *AgvTaskCreate) SetSourceDock(v string) *AgvTaskCreate {
_c.mutation.SetSourceDock(v)
return _c
}
// SetNillableSourceDock sets the "source_dock" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableSourceDock(v *string) *AgvTaskCreate {
if v != nil {
_c.SetSourceDock(*v)
}
return _c
}
// SetTargetDock sets the "target_dock" field.
func (_c *AgvTaskCreate) SetTargetDock(v string) *AgvTaskCreate {
_c.mutation.SetTargetDock(v)
return _c
}
// SetNillableTargetDock sets the "target_dock" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableTargetDock(v *string) *AgvTaskCreate {
if v != nil {
_c.SetTargetDock(*v)
}
return _c
}
// SetMaterialsJSON sets the "materials_json" field.
func (_c *AgvTaskCreate) SetMaterialsJSON(v string) *AgvTaskCreate {
_c.mutation.SetMaterialsJSON(v)
return _c
}
// SetNillableMaterialsJSON sets the "materials_json" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableMaterialsJSON(v *string) *AgvTaskCreate {
if v != nil {
_c.SetMaterialsJSON(*v)
}
return _c
}
// SetRelatedRequestNo sets the "related_request_no" field.
func (_c *AgvTaskCreate) SetRelatedRequestNo(v string) *AgvTaskCreate {
_c.mutation.SetRelatedRequestNo(v)
return _c
}
// SetNillableRelatedRequestNo sets the "related_request_no" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableRelatedRequestNo(v *string) *AgvTaskCreate {
if v != nil {
_c.SetRelatedRequestNo(*v)
}
return _c
}
// SetRelatedOutboundNo sets the "related_outbound_no" field.
func (_c *AgvTaskCreate) SetRelatedOutboundNo(v string) *AgvTaskCreate {
_c.mutation.SetRelatedOutboundNo(v)
return _c
}
// SetNillableRelatedOutboundNo sets the "related_outbound_no" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableRelatedOutboundNo(v *string) *AgvTaskCreate {
if v != nil {
_c.SetRelatedOutboundNo(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *AgvTaskCreate) SetStatus(v string) *AgvTaskCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableStatus(v *string) *AgvTaskCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetKind sets the "kind" field.
func (_c *AgvTaskCreate) SetKind(v string) *AgvTaskCreate {
_c.mutation.SetKind(v)
return _c
}
// SetNillableKind sets the "kind" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableKind(v *string) *AgvTaskCreate {
if v != nil {
_c.SetKind(*v)
}
return _c
}
// SetBizType sets the "biz_type" field.
func (_c *AgvTaskCreate) SetBizType(v string) *AgvTaskCreate {
_c.mutation.SetBizType(v)
return _c
}
// SetNillableBizType sets the "biz_type" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableBizType(v *string) *AgvTaskCreate {
if v != nil {
_c.SetBizType(*v)
}
return _c
}
// SetBizNo sets the "biz_no" field.
func (_c *AgvTaskCreate) SetBizNo(v string) *AgvTaskCreate {
_c.mutation.SetBizNo(v)
return _c
}
// SetNillableBizNo sets the "biz_no" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableBizNo(v *string) *AgvTaskCreate {
if v != nil {
_c.SetBizNo(*v)
}
return _c
}
// SetTemplateType sets the "template_type" field.
func (_c *AgvTaskCreate) SetTemplateType(v string) *AgvTaskCreate {
_c.mutation.SetTemplateType(v)
return _c
}
// SetNillableTemplateType sets the "template_type" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableTemplateType(v *string) *AgvTaskCreate {
if v != nil {
_c.SetTemplateType(*v)
}
return _c
}
// SetChainNo sets the "chain_no" field.
func (_c *AgvTaskCreate) SetChainNo(v string) *AgvTaskCreate {
_c.mutation.SetChainNo(v)
return _c
}
// SetNillableChainNo sets the "chain_no" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableChainNo(v *string) *AgvTaskCreate {
if v != nil {
_c.SetChainNo(*v)
}
return _c
}
// SetAutoEnd sets the "auto_end" field.
func (_c *AgvTaskCreate) SetAutoEnd(v bool) *AgvTaskCreate {
_c.mutation.SetAutoEnd(v)
return _c
}
// SetNillableAutoEnd sets the "auto_end" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableAutoEnd(v *bool) *AgvTaskCreate {
if v != nil {
_c.SetAutoEnd(*v)
}
return _c
}
// SetAgvCode sets the "agv_code" field.
func (_c *AgvTaskCreate) SetAgvCode(v string) *AgvTaskCreate {
_c.mutation.SetAgvCode(v)
return _c
}
// SetNillableAgvCode sets the "agv_code" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableAgvCode(v *string) *AgvTaskCreate {
if v != nil {
_c.SetAgvCode(*v)
}
return _c
}
// SetOperator sets the "operator" field.
func (_c *AgvTaskCreate) SetOperator(v string) *AgvTaskCreate {
_c.mutation.SetOperator(v)
return _c
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableOperator(v *string) *AgvTaskCreate {
if v != nil {
_c.SetOperator(*v)
}
return _c
}
// SetDispatchedAt sets the "dispatched_at" field.
func (_c *AgvTaskCreate) SetDispatchedAt(v int64) *AgvTaskCreate {
_c.mutation.SetDispatchedAt(v)
return _c
}
// SetNillableDispatchedAt sets the "dispatched_at" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableDispatchedAt(v *int64) *AgvTaskCreate {
if v != nil {
_c.SetDispatchedAt(*v)
}
return _c
}
// SetArrivedAt sets the "arrived_at" field.
func (_c *AgvTaskCreate) SetArrivedAt(v int64) *AgvTaskCreate {
_c.mutation.SetArrivedAt(v)
return _c
}
// SetNillableArrivedAt sets the "arrived_at" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableArrivedAt(v *int64) *AgvTaskCreate {
if v != nil {
_c.SetArrivedAt(*v)
}
return _c
}
// SetRemark sets the "remark" field.
func (_c *AgvTaskCreate) SetRemark(v string) *AgvTaskCreate {
_c.mutation.SetRemark(v)
return _c
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableRemark(v *string) *AgvTaskCreate {
if v != nil {
_c.SetRemark(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *AgvTaskCreate) SetCreatedAt(v int64) *AgvTaskCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *AgvTaskCreate) SetNillableCreatedAt(v *int64) *AgvTaskCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// Mutation returns the AgvTaskMutation object of the builder.
func (_c *AgvTaskCreate) Mutation() *AgvTaskMutation {
return _c.mutation
}
// Save creates the AgvTask in the database.
func (_c *AgvTaskCreate) Save(ctx context.Context) (*AgvTask, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *AgvTaskCreate) SaveX(ctx context.Context) *AgvTask {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AgvTaskCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AgvTaskCreate) 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 *AgvTaskCreate) defaults() {
if _, ok := _c.mutation.SourceDock(); !ok {
v := agvtask.DefaultSourceDock
_c.mutation.SetSourceDock(v)
}
if _, ok := _c.mutation.TargetDock(); !ok {
v := agvtask.DefaultTargetDock
_c.mutation.SetTargetDock(v)
}
if _, ok := _c.mutation.MaterialsJSON(); !ok {
v := agvtask.DefaultMaterialsJSON
_c.mutation.SetMaterialsJSON(v)
}
if _, ok := _c.mutation.RelatedRequestNo(); !ok {
v := agvtask.DefaultRelatedRequestNo
_c.mutation.SetRelatedRequestNo(v)
}
if _, ok := _c.mutation.RelatedOutboundNo(); !ok {
v := agvtask.DefaultRelatedOutboundNo
_c.mutation.SetRelatedOutboundNo(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := agvtask.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.Kind(); !ok {
v := agvtask.DefaultKind
_c.mutation.SetKind(v)
}
if _, ok := _c.mutation.BizType(); !ok {
v := agvtask.DefaultBizType
_c.mutation.SetBizType(v)
}
if _, ok := _c.mutation.BizNo(); !ok {
v := agvtask.DefaultBizNo
_c.mutation.SetBizNo(v)
}
if _, ok := _c.mutation.TemplateType(); !ok {
v := agvtask.DefaultTemplateType
_c.mutation.SetTemplateType(v)
}
if _, ok := _c.mutation.ChainNo(); !ok {
v := agvtask.DefaultChainNo
_c.mutation.SetChainNo(v)
}
if _, ok := _c.mutation.AutoEnd(); !ok {
v := agvtask.DefaultAutoEnd
_c.mutation.SetAutoEnd(v)
}
if _, ok := _c.mutation.AgvCode(); !ok {
v := agvtask.DefaultAgvCode
_c.mutation.SetAgvCode(v)
}
if _, ok := _c.mutation.Operator(); !ok {
v := agvtask.DefaultOperator
_c.mutation.SetOperator(v)
}
if _, ok := _c.mutation.DispatchedAt(); !ok {
v := agvtask.DefaultDispatchedAt
_c.mutation.SetDispatchedAt(v)
}
if _, ok := _c.mutation.ArrivedAt(); !ok {
v := agvtask.DefaultArrivedAt
_c.mutation.SetArrivedAt(v)
}
if _, ok := _c.mutation.Remark(); !ok {
v := agvtask.DefaultRemark
_c.mutation.SetRemark(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := agvtask.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *AgvTaskCreate) check() error {
if _, ok := _c.mutation.TaskNo(); !ok {
return &ValidationError{Name: "task_no", err: errors.New(`ent: missing required field "AgvTask.task_no"`)}
}
if v, ok := _c.mutation.TaskNo(); ok {
if err := agvtask.TaskNoValidator(v); err != nil {
return &ValidationError{Name: "task_no", err: fmt.Errorf(`ent: validator failed for field "AgvTask.task_no": %w`, err)}
}
}
if _, ok := _c.mutation.SourceDock(); !ok {
return &ValidationError{Name: "source_dock", err: errors.New(`ent: missing required field "AgvTask.source_dock"`)}
}
if v, ok := _c.mutation.SourceDock(); ok {
if err := agvtask.SourceDockValidator(v); err != nil {
return &ValidationError{Name: "source_dock", err: fmt.Errorf(`ent: validator failed for field "AgvTask.source_dock": %w`, err)}
}
}
if _, ok := _c.mutation.TargetDock(); !ok {
return &ValidationError{Name: "target_dock", err: errors.New(`ent: missing required field "AgvTask.target_dock"`)}
}
if v, ok := _c.mutation.TargetDock(); ok {
if err := agvtask.TargetDockValidator(v); err != nil {
return &ValidationError{Name: "target_dock", err: fmt.Errorf(`ent: validator failed for field "AgvTask.target_dock": %w`, err)}
}
}
if _, ok := _c.mutation.MaterialsJSON(); !ok {
return &ValidationError{Name: "materials_json", err: errors.New(`ent: missing required field "AgvTask.materials_json"`)}
}
if v, ok := _c.mutation.MaterialsJSON(); ok {
if err := agvtask.MaterialsJSONValidator(v); err != nil {
return &ValidationError{Name: "materials_json", err: fmt.Errorf(`ent: validator failed for field "AgvTask.materials_json": %w`, err)}
}
}
if v, ok := _c.mutation.RelatedRequestNo(); ok {
if err := agvtask.RelatedRequestNoValidator(v); err != nil {
return &ValidationError{Name: "related_request_no", err: fmt.Errorf(`ent: validator failed for field "AgvTask.related_request_no": %w`, err)}
}
}
if v, ok := _c.mutation.RelatedOutboundNo(); ok {
if err := agvtask.RelatedOutboundNoValidator(v); err != nil {
return &ValidationError{Name: "related_outbound_no", err: fmt.Errorf(`ent: validator failed for field "AgvTask.related_outbound_no": %w`, err)}
}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "AgvTask.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := agvtask.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "AgvTask.status": %w`, err)}
}
}
if _, ok := _c.mutation.Kind(); !ok {
return &ValidationError{Name: "kind", err: errors.New(`ent: missing required field "AgvTask.kind"`)}
}
if v, ok := _c.mutation.Kind(); ok {
if err := agvtask.KindValidator(v); err != nil {
return &ValidationError{Name: "kind", err: fmt.Errorf(`ent: validator failed for field "AgvTask.kind": %w`, err)}
}
}
if _, ok := _c.mutation.BizType(); !ok {
return &ValidationError{Name: "biz_type", err: errors.New(`ent: missing required field "AgvTask.biz_type"`)}
}
if v, ok := _c.mutation.BizType(); ok {
if err := agvtask.BizTypeValidator(v); err != nil {
return &ValidationError{Name: "biz_type", err: fmt.Errorf(`ent: validator failed for field "AgvTask.biz_type": %w`, err)}
}
}
if _, ok := _c.mutation.BizNo(); !ok {
return &ValidationError{Name: "biz_no", err: errors.New(`ent: missing required field "AgvTask.biz_no"`)}
}
if v, ok := _c.mutation.BizNo(); ok {
if err := agvtask.BizNoValidator(v); err != nil {
return &ValidationError{Name: "biz_no", err: fmt.Errorf(`ent: validator failed for field "AgvTask.biz_no": %w`, err)}
}
}
if _, ok := _c.mutation.TemplateType(); !ok {
return &ValidationError{Name: "template_type", err: errors.New(`ent: missing required field "AgvTask.template_type"`)}
}
if v, ok := _c.mutation.TemplateType(); ok {
if err := agvtask.TemplateTypeValidator(v); err != nil {
return &ValidationError{Name: "template_type", err: fmt.Errorf(`ent: validator failed for field "AgvTask.template_type": %w`, err)}
}
}
if _, ok := _c.mutation.ChainNo(); !ok {
return &ValidationError{Name: "chain_no", err: errors.New(`ent: missing required field "AgvTask.chain_no"`)}
}
if v, ok := _c.mutation.ChainNo(); ok {
if err := agvtask.ChainNoValidator(v); err != nil {
return &ValidationError{Name: "chain_no", err: fmt.Errorf(`ent: validator failed for field "AgvTask.chain_no": %w`, err)}
}
}
if _, ok := _c.mutation.AutoEnd(); !ok {
return &ValidationError{Name: "auto_end", err: errors.New(`ent: missing required field "AgvTask.auto_end"`)}
}
if _, ok := _c.mutation.AgvCode(); !ok {
return &ValidationError{Name: "agv_code", err: errors.New(`ent: missing required field "AgvTask.agv_code"`)}
}
if v, ok := _c.mutation.AgvCode(); ok {
if err := agvtask.AgvCodeValidator(v); err != nil {
return &ValidationError{Name: "agv_code", err: fmt.Errorf(`ent: validator failed for field "AgvTask.agv_code": %w`, err)}
}
}
if _, ok := _c.mutation.Operator(); !ok {
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "AgvTask.operator"`)}
}
if v, ok := _c.mutation.Operator(); ok {
if err := agvtask.OperatorValidator(v); err != nil {
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "AgvTask.operator": %w`, err)}
}
}
if _, ok := _c.mutation.DispatchedAt(); !ok {
return &ValidationError{Name: "dispatched_at", err: errors.New(`ent: missing required field "AgvTask.dispatched_at"`)}
}
if _, ok := _c.mutation.ArrivedAt(); !ok {
return &ValidationError{Name: "arrived_at", err: errors.New(`ent: missing required field "AgvTask.arrived_at"`)}
}
if v, ok := _c.mutation.Remark(); ok {
if err := agvtask.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "AgvTask.remark": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AgvTask.created_at"`)}
}
return nil
}
func (_c *AgvTaskCreate) sqlSave(ctx context.Context) (*AgvTask, 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 *AgvTaskCreate) createSpec() (*AgvTask, *sqlgraph.CreateSpec) {
var (
_node = &AgvTask{config: _c.config}
_spec = sqlgraph.NewCreateSpec(agvtask.Table, sqlgraph.NewFieldSpec(agvtask.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.TaskNo(); ok {
_spec.SetField(agvtask.FieldTaskNo, field.TypeString, value)
_node.TaskNo = value
}
if value, ok := _c.mutation.SourceDock(); ok {
_spec.SetField(agvtask.FieldSourceDock, field.TypeString, value)
_node.SourceDock = value
}
if value, ok := _c.mutation.TargetDock(); ok {
_spec.SetField(agvtask.FieldTargetDock, field.TypeString, value)
_node.TargetDock = value
}
if value, ok := _c.mutation.MaterialsJSON(); ok {
_spec.SetField(agvtask.FieldMaterialsJSON, field.TypeString, value)
_node.MaterialsJSON = value
}
if value, ok := _c.mutation.RelatedRequestNo(); ok {
_spec.SetField(agvtask.FieldRelatedRequestNo, field.TypeString, value)
_node.RelatedRequestNo = value
}
if value, ok := _c.mutation.RelatedOutboundNo(); ok {
_spec.SetField(agvtask.FieldRelatedOutboundNo, field.TypeString, value)
_node.RelatedOutboundNo = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(agvtask.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.Kind(); ok {
_spec.SetField(agvtask.FieldKind, field.TypeString, value)
_node.Kind = value
}
if value, ok := _c.mutation.BizType(); ok {
_spec.SetField(agvtask.FieldBizType, field.TypeString, value)
_node.BizType = value
}
if value, ok := _c.mutation.BizNo(); ok {
_spec.SetField(agvtask.FieldBizNo, field.TypeString, value)
_node.BizNo = value
}
if value, ok := _c.mutation.TemplateType(); ok {
_spec.SetField(agvtask.FieldTemplateType, field.TypeString, value)
_node.TemplateType = value
}
if value, ok := _c.mutation.ChainNo(); ok {
_spec.SetField(agvtask.FieldChainNo, field.TypeString, value)
_node.ChainNo = value
}
if value, ok := _c.mutation.AutoEnd(); ok {
_spec.SetField(agvtask.FieldAutoEnd, field.TypeBool, value)
_node.AutoEnd = value
}
if value, ok := _c.mutation.AgvCode(); ok {
_spec.SetField(agvtask.FieldAgvCode, field.TypeString, value)
_node.AgvCode = value
}
if value, ok := _c.mutation.Operator(); ok {
_spec.SetField(agvtask.FieldOperator, field.TypeString, value)
_node.Operator = value
}
if value, ok := _c.mutation.DispatchedAt(); ok {
_spec.SetField(agvtask.FieldDispatchedAt, field.TypeInt64, value)
_node.DispatchedAt = value
}
if value, ok := _c.mutation.ArrivedAt(); ok {
_spec.SetField(agvtask.FieldArrivedAt, field.TypeInt64, value)
_node.ArrivedAt = value
}
if value, ok := _c.mutation.Remark(); ok {
_spec.SetField(agvtask.FieldRemark, field.TypeString, value)
_node.Remark = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(agvtask.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
return _node, _spec
}
// AgvTaskCreateBulk is the builder for creating many AgvTask entities in bulk.
type AgvTaskCreateBulk struct {
config
err error
builders []*AgvTaskCreate
}
// Save creates the AgvTask entities in the database.
func (_c *AgvTaskCreateBulk) Save(ctx context.Context) ([]*AgvTask, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*AgvTask, 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.(*AgvTaskMutation)
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 *AgvTaskCreateBulk) SaveX(ctx context.Context) []*AgvTask {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AgvTaskCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AgvTaskCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}