// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "mingyang-admin-pay/rpc/ent/app" "mingyang-admin-pay/rpc/ent/paynotifylog" "mingyang-admin-pay/rpc/ent/paynotifytask" "mingyang-admin-pay/rpc/ent/payorder" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // PayNotifyTaskCreate is the builder for creating a PayNotifyTask entity. type PayNotifyTaskCreate struct { config mutation *PayNotifyTaskMutation hooks []Hook } // SetCreatedAt sets the "created_at" field. func (_c *PayNotifyTaskCreate) SetCreatedAt(v time.Time) *PayNotifyTaskCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "created_at" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableCreatedAt(v *time.Time) *PayNotifyTaskCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updated_at" field. func (_c *PayNotifyTaskCreate) SetUpdatedAt(v time.Time) *PayNotifyTaskCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableUpdatedAt(v *time.Time) *PayNotifyTaskCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetStatus sets the "status" field. func (_c *PayNotifyTaskCreate) SetStatus(v uint8) *PayNotifyTaskCreate { _c.mutation.SetStatus(v) return _c } // SetNillableStatus sets the "status" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableStatus(v *uint8) *PayNotifyTaskCreate { if v != nil { _c.SetStatus(*v) } return _c } // SetTenantID sets the "tenant_id" field. func (_c *PayNotifyTaskCreate) SetTenantID(v uint64) *PayNotifyTaskCreate { _c.mutation.SetTenantID(v) return _c } // SetNillableTenantID sets the "tenant_id" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableTenantID(v *uint64) *PayNotifyTaskCreate { if v != nil { _c.SetTenantID(*v) } return _c } // SetDeletedAt sets the "deleted_at" field. func (_c *PayNotifyTaskCreate) SetDeletedAt(v time.Time) *PayNotifyTaskCreate { _c.mutation.SetDeletedAt(v) return _c } // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableDeletedAt(v *time.Time) *PayNotifyTaskCreate { if v != nil { _c.SetDeletedAt(*v) } return _c } // SetType sets the "type" field. func (_c *PayNotifyTaskCreate) SetType(v uint8) *PayNotifyTaskCreate { _c.mutation.SetType(v) return _c } // SetNillableType sets the "type" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableType(v *uint8) *PayNotifyTaskCreate { if v != nil { _c.SetType(*v) } return _c } // SetDataID sets the "data_id" field. func (_c *PayNotifyTaskCreate) SetDataID(v uint64) *PayNotifyTaskCreate { _c.mutation.SetDataID(v) return _c } // SetOrderID sets the "order_id" field. func (_c *PayNotifyTaskCreate) SetOrderID(v uint64) *PayNotifyTaskCreate { _c.mutation.SetOrderID(v) return _c } // SetAppID sets the "app_id" field. func (_c *PayNotifyTaskCreate) SetAppID(v uint64) *PayNotifyTaskCreate { _c.mutation.SetAppID(v) return _c } // SetNotifyStatus sets the "notify_status" field. func (_c *PayNotifyTaskCreate) SetNotifyStatus(v uint8) *PayNotifyTaskCreate { _c.mutation.SetNotifyStatus(v) return _c } // SetNextNotifyTime sets the "next_notify_time" field. func (_c *PayNotifyTaskCreate) SetNextNotifyTime(v time.Time) *PayNotifyTaskCreate { _c.mutation.SetNextNotifyTime(v) return _c } // SetNillableNextNotifyTime sets the "next_notify_time" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableNextNotifyTime(v *time.Time) *PayNotifyTaskCreate { if v != nil { _c.SetNextNotifyTime(*v) } return _c } // SetLastExecuteTime sets the "last_execute_time" field. func (_c *PayNotifyTaskCreate) SetLastExecuteTime(v time.Time) *PayNotifyTaskCreate { _c.mutation.SetLastExecuteTime(v) return _c } // SetNillableLastExecuteTime sets the "last_execute_time" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableLastExecuteTime(v *time.Time) *PayNotifyTaskCreate { if v != nil { _c.SetLastExecuteTime(*v) } return _c } // SetRetryCount sets the "retry_count" field. func (_c *PayNotifyTaskCreate) SetRetryCount(v uint32) *PayNotifyTaskCreate { _c.mutation.SetRetryCount(v) return _c } // SetNillableRetryCount sets the "retry_count" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableRetryCount(v *uint32) *PayNotifyTaskCreate { if v != nil { _c.SetRetryCount(*v) } return _c } // SetMaxRetryCount sets the "max_retry_count" field. func (_c *PayNotifyTaskCreate) SetMaxRetryCount(v uint32) *PayNotifyTaskCreate { _c.mutation.SetMaxRetryCount(v) return _c } // SetNillableMaxRetryCount sets the "max_retry_count" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableMaxRetryCount(v *uint32) *PayNotifyTaskCreate { if v != nil { _c.SetMaxRetryCount(*v) } return _c } // SetNotifyURL sets the "notify_url" field. func (_c *PayNotifyTaskCreate) SetNotifyURL(v string) *PayNotifyTaskCreate { _c.mutation.SetNotifyURL(v) return _c } // SetNillableNotifyURL sets the "notify_url" field if the given value is not nil. func (_c *PayNotifyTaskCreate) SetNillableNotifyURL(v *string) *PayNotifyTaskCreate { if v != nil { _c.SetNotifyURL(*v) } return _c } // SetID sets the "id" field. func (_c *PayNotifyTaskCreate) SetID(v uint64) *PayNotifyTaskCreate { _c.mutation.SetID(v) return _c } // SetApp sets the "app" edge to the App entity. func (_c *PayNotifyTaskCreate) SetApp(v *App) *PayNotifyTaskCreate { return _c.SetAppID(v.ID) } // SetOrder sets the "order" edge to the PayOrder entity. func (_c *PayNotifyTaskCreate) SetOrder(v *PayOrder) *PayNotifyTaskCreate { return _c.SetOrderID(v.ID) } // AddNotifyLogIDs adds the "notify_log" edge to the PayNotifyLog entity by IDs. func (_c *PayNotifyTaskCreate) AddNotifyLogIDs(ids ...uint64) *PayNotifyTaskCreate { _c.mutation.AddNotifyLogIDs(ids...) return _c } // AddNotifyLog adds the "notify_log" edges to the PayNotifyLog entity. func (_c *PayNotifyTaskCreate) AddNotifyLog(v ...*PayNotifyLog) *PayNotifyTaskCreate { ids := make([]uint64, len(v)) for i := range v { ids[i] = v[i].ID } return _c.AddNotifyLogIDs(ids...) } // Mutation returns the PayNotifyTaskMutation object of the builder. func (_c *PayNotifyTaskCreate) Mutation() *PayNotifyTaskMutation { return _c.mutation } // Save creates the PayNotifyTask in the database. func (_c *PayNotifyTaskCreate) Save(ctx context.Context) (*PayNotifyTask, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *PayNotifyTaskCreate) SaveX(ctx context.Context) *PayNotifyTask { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *PayNotifyTaskCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *PayNotifyTaskCreate) 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 *PayNotifyTaskCreate) defaults() { if _, ok := _c.mutation.CreatedAt(); !ok { v := paynotifytask.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := paynotifytask.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } if _, ok := _c.mutation.Status(); !ok { v := paynotifytask.DefaultStatus _c.mutation.SetStatus(v) } if _, ok := _c.mutation.TenantID(); !ok { v := paynotifytask.DefaultTenantID _c.mutation.SetTenantID(v) } if _, ok := _c.mutation.GetType(); !ok { v := paynotifytask.DefaultType _c.mutation.SetType(v) } } // check runs all checks and user-defined validators on the builder. func (_c *PayNotifyTaskCreate) check() error { if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "PayNotifyTask.created_at"`)} } if _, ok := _c.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "PayNotifyTask.updated_at"`)} } if _, ok := _c.mutation.TenantID(); !ok { return &ValidationError{Name: "tenant_id", err: errors.New(`ent: missing required field "PayNotifyTask.tenant_id"`)} } if _, ok := _c.mutation.GetType(); !ok { return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "PayNotifyTask.type"`)} } if _, ok := _c.mutation.DataID(); !ok { return &ValidationError{Name: "data_id", err: errors.New(`ent: missing required field "PayNotifyTask.data_id"`)} } if _, ok := _c.mutation.OrderID(); !ok { return &ValidationError{Name: "order_id", err: errors.New(`ent: missing required field "PayNotifyTask.order_id"`)} } if _, ok := _c.mutation.AppID(); !ok { return &ValidationError{Name: "app_id", err: errors.New(`ent: missing required field "PayNotifyTask.app_id"`)} } if _, ok := _c.mutation.NotifyStatus(); !ok { return &ValidationError{Name: "notify_status", err: errors.New(`ent: missing required field "PayNotifyTask.notify_status"`)} } if len(_c.mutation.AppIDs()) == 0 { return &ValidationError{Name: "app", err: errors.New(`ent: missing required edge "PayNotifyTask.app"`)} } if len(_c.mutation.OrderIDs()) == 0 { return &ValidationError{Name: "order", err: errors.New(`ent: missing required edge "PayNotifyTask.order"`)} } return nil } func (_c *PayNotifyTaskCreate) sqlSave(ctx context.Context) (*PayNotifyTask, 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 = uint64(id) } _c.mutation.id = &_node.ID _c.mutation.done = true return _node, nil } func (_c *PayNotifyTaskCreate) createSpec() (*PayNotifyTask, *sqlgraph.CreateSpec) { var ( _node = &PayNotifyTask{config: _c.config} _spec = sqlgraph.NewCreateSpec(paynotifytask.Table, sqlgraph.NewFieldSpec(paynotifytask.FieldID, field.TypeUint64)) ) if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(paynotifytask.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(paynotifytask.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := _c.mutation.Status(); ok { _spec.SetField(paynotifytask.FieldStatus, field.TypeUint8, value) _node.Status = value } if value, ok := _c.mutation.TenantID(); ok { _spec.SetField(paynotifytask.FieldTenantID, field.TypeUint64, value) _node.TenantID = value } if value, ok := _c.mutation.DeletedAt(); ok { _spec.SetField(paynotifytask.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = value } if value, ok := _c.mutation.GetType(); ok { _spec.SetField(paynotifytask.FieldType, field.TypeUint8, value) _node.Type = value } if value, ok := _c.mutation.DataID(); ok { _spec.SetField(paynotifytask.FieldDataID, field.TypeUint64, value) _node.DataID = value } if value, ok := _c.mutation.NotifyStatus(); ok { _spec.SetField(paynotifytask.FieldNotifyStatus, field.TypeUint8, value) _node.NotifyStatus = value } if value, ok := _c.mutation.NextNotifyTime(); ok { _spec.SetField(paynotifytask.FieldNextNotifyTime, field.TypeTime, value) _node.NextNotifyTime = value } if value, ok := _c.mutation.LastExecuteTime(); ok { _spec.SetField(paynotifytask.FieldLastExecuteTime, field.TypeTime, value) _node.LastExecuteTime = value } if value, ok := _c.mutation.RetryCount(); ok { _spec.SetField(paynotifytask.FieldRetryCount, field.TypeUint32, value) _node.RetryCount = value } if value, ok := _c.mutation.MaxRetryCount(); ok { _spec.SetField(paynotifytask.FieldMaxRetryCount, field.TypeUint32, value) _node.MaxRetryCount = value } if value, ok := _c.mutation.NotifyURL(); ok { _spec.SetField(paynotifytask.FieldNotifyURL, field.TypeString, value) _node.NotifyURL = value } if nodes := _c.mutation.AppIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paynotifytask.AppTable, Columns: []string{paynotifytask.AppColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(app.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.AppID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.OrderIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: false, Table: paynotifytask.OrderTable, Columns: []string{paynotifytask.OrderColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(payorder.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.OrderID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } if nodes := _c.mutation.NotifyLogIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.O2M, Inverse: true, Table: paynotifytask.NotifyLogTable, Columns: []string{paynotifytask.NotifyLogColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(paynotifylog.FieldID, field.TypeUint64), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _spec.Edges = append(_spec.Edges, edge) } return _node, _spec } // PayNotifyTaskCreateBulk is the builder for creating many PayNotifyTask entities in bulk. type PayNotifyTaskCreateBulk struct { config err error builders []*PayNotifyTaskCreate } // Save creates the PayNotifyTask entities in the database. func (_c *PayNotifyTaskCreateBulk) Save(ctx context.Context) ([]*PayNotifyTask, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*PayNotifyTask, 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.(*PayNotifyTaskMutation) 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 = uint64(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 *PayNotifyTaskCreateBulk) SaveX(ctx context.Context) []*PayNotifyTask { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *PayNotifyTaskCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *PayNotifyTaskCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } }