// Code generated by ent, DO NOT EDIT. package ent import ( "bj_power_mes/ent/dailyplan" "context" "errors" "fmt" "time" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" ) // DailyPlanCreate is the builder for creating a DailyPlan entity. type DailyPlanCreate struct { config mutation *DailyPlanMutation hooks []Hook } // SetOrderNo sets the "orderNo" field. func (_c *DailyPlanCreate) SetOrderNo(v string) *DailyPlanCreate { _c.mutation.SetOrderNo(v) return _c } // SetPlanDate sets the "planDate" field. func (_c *DailyPlanCreate) SetPlanDate(v string) *DailyPlanCreate { _c.mutation.SetPlanDate(v) return _c } // SetPlanQty sets the "planQty" field. func (_c *DailyPlanCreate) SetPlanQty(v int) *DailyPlanCreate { _c.mutation.SetPlanQty(v) return _c } // SetNillablePlanQty sets the "planQty" field if the given value is not nil. func (_c *DailyPlanCreate) SetNillablePlanQty(v *int) *DailyPlanCreate { if v != nil { _c.SetPlanQty(*v) } return _c } // SetCompletedQty sets the "completedQty" field. func (_c *DailyPlanCreate) SetCompletedQty(v int) *DailyPlanCreate { _c.mutation.SetCompletedQty(v) return _c } // SetNillableCompletedQty sets the "completedQty" field if the given value is not nil. func (_c *DailyPlanCreate) SetNillableCompletedQty(v *int) *DailyPlanCreate { if v != nil { _c.SetCompletedQty(*v) } return _c } // SetDockCodes sets the "dockCodes" field. func (_c *DailyPlanCreate) SetDockCodes(v []string) *DailyPlanCreate { _c.mutation.SetDockCodes(v) return _c } // SetStatus sets the "status" field. func (_c *DailyPlanCreate) SetStatus(v string) *DailyPlanCreate { _c.mutation.SetStatus(v) return _c } // SetNillableStatus sets the "status" field if the given value is not nil. func (_c *DailyPlanCreate) SetNillableStatus(v *string) *DailyPlanCreate { if v != nil { _c.SetStatus(*v) } return _c } // SetOperator sets the "operator" field. func (_c *DailyPlanCreate) SetOperator(v string) *DailyPlanCreate { _c.mutation.SetOperator(v) return _c } // SetNillableOperator sets the "operator" field if the given value is not nil. func (_c *DailyPlanCreate) SetNillableOperator(v *string) *DailyPlanCreate { if v != nil { _c.SetOperator(*v) } return _c } // SetCreatedAt sets the "createdAt" field. func (_c *DailyPlanCreate) SetCreatedAt(v time.Time) *DailyPlanCreate { _c.mutation.SetCreatedAt(v) return _c } // SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. func (_c *DailyPlanCreate) SetNillableCreatedAt(v *time.Time) *DailyPlanCreate { if v != nil { _c.SetCreatedAt(*v) } return _c } // SetUpdatedAt sets the "updatedAt" field. func (_c *DailyPlanCreate) SetUpdatedAt(v time.Time) *DailyPlanCreate { _c.mutation.SetUpdatedAt(v) return _c } // SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil. func (_c *DailyPlanCreate) SetNillableUpdatedAt(v *time.Time) *DailyPlanCreate { if v != nil { _c.SetUpdatedAt(*v) } return _c } // SetID sets the "id" field. func (_c *DailyPlanCreate) SetID(v int) *DailyPlanCreate { _c.mutation.SetID(v) return _c } // Mutation returns the DailyPlanMutation object of the builder. func (_c *DailyPlanCreate) Mutation() *DailyPlanMutation { return _c.mutation } // Save creates the DailyPlan in the database. func (_c *DailyPlanCreate) Save(ctx context.Context) (*DailyPlan, error) { _c.defaults() return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) } // SaveX calls Save and panics if Save returns an error. func (_c *DailyPlanCreate) SaveX(ctx context.Context) *DailyPlan { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *DailyPlanCreate) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *DailyPlanCreate) 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 *DailyPlanCreate) defaults() { if _, ok := _c.mutation.PlanQty(); !ok { v := dailyplan.DefaultPlanQty _c.mutation.SetPlanQty(v) } if _, ok := _c.mutation.CompletedQty(); !ok { v := dailyplan.DefaultCompletedQty _c.mutation.SetCompletedQty(v) } if _, ok := _c.mutation.Status(); !ok { v := dailyplan.DefaultStatus _c.mutation.SetStatus(v) } if _, ok := _c.mutation.Operator(); !ok { v := dailyplan.DefaultOperator _c.mutation.SetOperator(v) } if _, ok := _c.mutation.CreatedAt(); !ok { v := dailyplan.DefaultCreatedAt() _c.mutation.SetCreatedAt(v) } if _, ok := _c.mutation.UpdatedAt(); !ok { v := dailyplan.DefaultUpdatedAt() _c.mutation.SetUpdatedAt(v) } } // check runs all checks and user-defined validators on the builder. func (_c *DailyPlanCreate) check() error { if _, ok := _c.mutation.OrderNo(); !ok { return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "DailyPlan.orderNo"`)} } if v, ok := _c.mutation.OrderNo(); ok { if err := dailyplan.OrderNoValidator(v); err != nil { return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "DailyPlan.orderNo": %w`, err)} } } if _, ok := _c.mutation.PlanDate(); !ok { return &ValidationError{Name: "planDate", err: errors.New(`ent: missing required field "DailyPlan.planDate"`)} } if v, ok := _c.mutation.PlanDate(); ok { if err := dailyplan.PlanDateValidator(v); err != nil { return &ValidationError{Name: "planDate", err: fmt.Errorf(`ent: validator failed for field "DailyPlan.planDate": %w`, err)} } } if _, ok := _c.mutation.PlanQty(); !ok { return &ValidationError{Name: "planQty", err: errors.New(`ent: missing required field "DailyPlan.planQty"`)} } if _, ok := _c.mutation.CompletedQty(); !ok { return &ValidationError{Name: "completedQty", err: errors.New(`ent: missing required field "DailyPlan.completedQty"`)} } if _, ok := _c.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "DailyPlan.status"`)} } if v, ok := _c.mutation.Status(); ok { if err := dailyplan.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "DailyPlan.status": %w`, err)} } } if _, ok := _c.mutation.Operator(); !ok { return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "DailyPlan.operator"`)} } if v, ok := _c.mutation.Operator(); ok { if err := dailyplan.OperatorValidator(v); err != nil { return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "DailyPlan.operator": %w`, err)} } } if _, ok := _c.mutation.CreatedAt(); !ok { return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "DailyPlan.createdAt"`)} } if v, ok := _c.mutation.ID(); ok { if err := dailyplan.IDValidator(v); err != nil { return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "DailyPlan.id": %w`, err)} } } return nil } func (_c *DailyPlanCreate) sqlSave(ctx context.Context) (*DailyPlan, 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 *DailyPlanCreate) createSpec() (*DailyPlan, *sqlgraph.CreateSpec) { var ( _node = &DailyPlan{config: _c.config} _spec = sqlgraph.NewCreateSpec(dailyplan.Table, sqlgraph.NewFieldSpec(dailyplan.FieldID, field.TypeInt)) ) if id, ok := _c.mutation.ID(); ok { _node.ID = id _spec.ID.Value = id } if value, ok := _c.mutation.OrderNo(); ok { _spec.SetField(dailyplan.FieldOrderNo, field.TypeString, value) _node.OrderNo = value } if value, ok := _c.mutation.PlanDate(); ok { _spec.SetField(dailyplan.FieldPlanDate, field.TypeString, value) _node.PlanDate = value } if value, ok := _c.mutation.PlanQty(); ok { _spec.SetField(dailyplan.FieldPlanQty, field.TypeInt, value) _node.PlanQty = value } if value, ok := _c.mutation.CompletedQty(); ok { _spec.SetField(dailyplan.FieldCompletedQty, field.TypeInt, value) _node.CompletedQty = value } if value, ok := _c.mutation.DockCodes(); ok { _spec.SetField(dailyplan.FieldDockCodes, field.TypeJSON, value) _node.DockCodes = value } if value, ok := _c.mutation.Status(); ok { _spec.SetField(dailyplan.FieldStatus, field.TypeString, value) _node.Status = value } if value, ok := _c.mutation.Operator(); ok { _spec.SetField(dailyplan.FieldOperator, field.TypeString, value) _node.Operator = value } if value, ok := _c.mutation.CreatedAt(); ok { _spec.SetField(dailyplan.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := _c.mutation.UpdatedAt(); ok { _spec.SetField(dailyplan.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = &value } return _node, _spec } // DailyPlanCreateBulk is the builder for creating many DailyPlan entities in bulk. type DailyPlanCreateBulk struct { config err error builders []*DailyPlanCreate } // Save creates the DailyPlan entities in the database. func (_c *DailyPlanCreateBulk) Save(ctx context.Context) ([]*DailyPlan, error) { if _c.err != nil { return nil, _c.err } specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) nodes := make([]*DailyPlan, 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.(*DailyPlanMutation) 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 *DailyPlanCreateBulk) SaveX(ctx context.Context) []*DailyPlan { v, err := _c.Save(ctx) if err != nil { panic(err) } return v } // Exec executes the query. func (_c *DailyPlanCreateBulk) Exec(ctx context.Context) error { _, err := _c.Save(ctx) return err } // ExecX is like Exec, but panics if an error occurs. func (_c *DailyPlanCreateBulk) ExecX(ctx context.Context) { if err := _c.Exec(ctx); err != nil { panic(err) } }