431 lines
12 KiB
Go
431 lines
12 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"mingyang-admin-pay/rpc/ent/app"
|
|
"mingyang-admin-pay/rpc/ent/paychannel"
|
|
"mingyang-admin-pay/rpc/ent/paynotifytask"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// AppCreate is the builder for creating a App entity.
|
|
type AppCreate struct {
|
|
config
|
|
mutation *AppMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_c *AppCreate) SetCreatedAt(v time.Time) *AppCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableCreatedAt(v *time.Time) *AppCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_c *AppCreate) SetUpdatedAt(v time.Time) *AppCreate {
|
|
_c.mutation.SetUpdatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableUpdatedAt(v *time.Time) *AppCreate {
|
|
if v != nil {
|
|
_c.SetUpdatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *AppCreate) SetStatus(v uint8) *AppCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableStatus(v *uint8) *AppCreate {
|
|
if v != nil {
|
|
_c.SetStatus(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetTenantID sets the "tenant_id" field.
|
|
func (_c *AppCreate) SetTenantID(v uint64) *AppCreate {
|
|
_c.mutation.SetTenantID(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableTenantID sets the "tenant_id" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableTenantID(v *uint64) *AppCreate {
|
|
if v != nil {
|
|
_c.SetTenantID(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetDeletedAt sets the "deleted_at" field.
|
|
func (_c *AppCreate) SetDeletedAt(v time.Time) *AppCreate {
|
|
_c.mutation.SetDeletedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableDeletedAt(v *time.Time) *AppCreate {
|
|
if v != nil {
|
|
_c.SetDeletedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetAppKey sets the "app_key" field.
|
|
func (_c *AppCreate) SetAppKey(v string) *AppCreate {
|
|
_c.mutation.SetAppKey(v)
|
|
return _c
|
|
}
|
|
|
|
// SetAppName sets the "app_name" field.
|
|
func (_c *AppCreate) SetAppName(v string) *AppCreate {
|
|
_c.mutation.SetAppName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetOrderNotifyURL sets the "order_notify_url" field.
|
|
func (_c *AppCreate) SetOrderNotifyURL(v string) *AppCreate {
|
|
_c.mutation.SetOrderNotifyURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOrderNotifyURL sets the "order_notify_url" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableOrderNotifyURL(v *string) *AppCreate {
|
|
if v != nil {
|
|
_c.SetOrderNotifyURL(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRefundNotifyURL sets the "refund_notify_url" field.
|
|
func (_c *AppCreate) SetRefundNotifyURL(v string) *AppCreate {
|
|
_c.mutation.SetRefundNotifyURL(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRefundNotifyURL sets the "refund_notify_url" field if the given value is not nil.
|
|
func (_c *AppCreate) SetNillableRefundNotifyURL(v *string) *AppCreate {
|
|
if v != nil {
|
|
_c.SetRefundNotifyURL(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *AppCreate) SetID(v uint64) *AppCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// AddChannelIDs adds the "channel" edge to the PayChannel entity by IDs.
|
|
func (_c *AppCreate) AddChannelIDs(ids ...uint64) *AppCreate {
|
|
_c.mutation.AddChannelIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddChannel adds the "channel" edges to the PayChannel entity.
|
|
func (_c *AppCreate) AddChannel(v ...*PayChannel) *AppCreate {
|
|
ids := make([]uint64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddChannelIDs(ids...)
|
|
}
|
|
|
|
// AddNotifyTaskIDs adds the "notify_task" edge to the PayNotifyTask entity by IDs.
|
|
func (_c *AppCreate) AddNotifyTaskIDs(ids ...uint64) *AppCreate {
|
|
_c.mutation.AddNotifyTaskIDs(ids...)
|
|
return _c
|
|
}
|
|
|
|
// AddNotifyTask adds the "notify_task" edges to the PayNotifyTask entity.
|
|
func (_c *AppCreate) AddNotifyTask(v ...*PayNotifyTask) *AppCreate {
|
|
ids := make([]uint64, len(v))
|
|
for i := range v {
|
|
ids[i] = v[i].ID
|
|
}
|
|
return _c.AddNotifyTaskIDs(ids...)
|
|
}
|
|
|
|
// Mutation returns the AppMutation object of the builder.
|
|
func (_c *AppCreate) Mutation() *AppMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the App in the database.
|
|
func (_c *AppCreate) Save(ctx context.Context) (*App, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *AppCreate) SaveX(ctx context.Context) *App {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AppCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AppCreate) 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 *AppCreate) defaults() {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := app.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
v := app.DefaultUpdatedAt()
|
|
_c.mutation.SetUpdatedAt(v)
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
v := app.DefaultStatus
|
|
_c.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := _c.mutation.TenantID(); !ok {
|
|
v := app.DefaultTenantID
|
|
_c.mutation.SetTenantID(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *AppCreate) check() error {
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "App.created_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
|
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "App.updated_at"`)}
|
|
}
|
|
if _, ok := _c.mutation.TenantID(); !ok {
|
|
return &ValidationError{Name: "tenant_id", err: errors.New(`ent: missing required field "App.tenant_id"`)}
|
|
}
|
|
if _, ok := _c.mutation.AppKey(); !ok {
|
|
return &ValidationError{Name: "app_key", err: errors.New(`ent: missing required field "App.app_key"`)}
|
|
}
|
|
if _, ok := _c.mutation.AppName(); !ok {
|
|
return &ValidationError{Name: "app_name", err: errors.New(`ent: missing required field "App.app_name"`)}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *AppCreate) sqlSave(ctx context.Context) (*App, 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 *AppCreate) createSpec() (*App, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &App{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(app.Table, sqlgraph.NewFieldSpec(app.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(app.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(app.FieldUpdatedAt, field.TypeTime, value)
|
|
_node.UpdatedAt = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(app.FieldStatus, field.TypeUint8, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.TenantID(); ok {
|
|
_spec.SetField(app.FieldTenantID, field.TypeUint64, value)
|
|
_node.TenantID = value
|
|
}
|
|
if value, ok := _c.mutation.DeletedAt(); ok {
|
|
_spec.SetField(app.FieldDeletedAt, field.TypeTime, value)
|
|
_node.DeletedAt = value
|
|
}
|
|
if value, ok := _c.mutation.AppKey(); ok {
|
|
_spec.SetField(app.FieldAppKey, field.TypeString, value)
|
|
_node.AppKey = value
|
|
}
|
|
if value, ok := _c.mutation.AppName(); ok {
|
|
_spec.SetField(app.FieldAppName, field.TypeString, value)
|
|
_node.AppName = value
|
|
}
|
|
if value, ok := _c.mutation.OrderNotifyURL(); ok {
|
|
_spec.SetField(app.FieldOrderNotifyURL, field.TypeString, value)
|
|
_node.OrderNotifyURL = value
|
|
}
|
|
if value, ok := _c.mutation.RefundNotifyURL(); ok {
|
|
_spec.SetField(app.FieldRefundNotifyURL, field.TypeString, value)
|
|
_node.RefundNotifyURL = value
|
|
}
|
|
if nodes := _c.mutation.ChannelIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: app.ChannelTable,
|
|
Columns: []string{app.ChannelColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(paychannel.FieldID, field.TypeUint64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
if nodes := _c.mutation.NotifyTaskIDs(); len(nodes) > 0 {
|
|
edge := &sqlgraph.EdgeSpec{
|
|
Rel: sqlgraph.O2M,
|
|
Inverse: true,
|
|
Table: app.NotifyTaskTable,
|
|
Columns: []string{app.NotifyTaskColumn},
|
|
Bidi: false,
|
|
Target: &sqlgraph.EdgeTarget{
|
|
IDSpec: sqlgraph.NewFieldSpec(paynotifytask.FieldID, field.TypeUint64),
|
|
},
|
|
}
|
|
for _, k := range nodes {
|
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
|
}
|
|
_spec.Edges = append(_spec.Edges, edge)
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// AppCreateBulk is the builder for creating many App entities in bulk.
|
|
type AppCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*AppCreate
|
|
}
|
|
|
|
// Save creates the App entities in the database.
|
|
func (_c *AppCreateBulk) Save(ctx context.Context) ([]*App, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*App, 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.(*AppMutation)
|
|
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 *AppCreateBulk) SaveX(ctx context.Context) []*App {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *AppCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *AppCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|