Files
bj_power/bj_power_mes/ent/dailyplan_update.go
T
2026-08-28 15:06:01 +08:00

547 lines
16 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/dailyplan"
"bj_power_mes/ent/predicate"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DailyPlanUpdate is the builder for updating DailyPlan entities.
type DailyPlanUpdate struct {
config
hooks []Hook
mutation *DailyPlanMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the DailyPlanUpdate builder.
func (_u *DailyPlanUpdate) Where(ps ...predicate.DailyPlan) *DailyPlanUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetOrderNo sets the "orderNo" field.
func (_u *DailyPlanUpdate) SetOrderNo(v string) *DailyPlanUpdate {
_u.mutation.SetOrderNo(v)
return _u
}
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
func (_u *DailyPlanUpdate) SetNillableOrderNo(v *string) *DailyPlanUpdate {
if v != nil {
_u.SetOrderNo(*v)
}
return _u
}
// SetPlanDate sets the "planDate" field.
func (_u *DailyPlanUpdate) SetPlanDate(v string) *DailyPlanUpdate {
_u.mutation.SetPlanDate(v)
return _u
}
// SetNillablePlanDate sets the "planDate" field if the given value is not nil.
func (_u *DailyPlanUpdate) SetNillablePlanDate(v *string) *DailyPlanUpdate {
if v != nil {
_u.SetPlanDate(*v)
}
return _u
}
// SetPlanQty sets the "planQty" field.
func (_u *DailyPlanUpdate) SetPlanQty(v int) *DailyPlanUpdate {
_u.mutation.ResetPlanQty()
_u.mutation.SetPlanQty(v)
return _u
}
// SetNillablePlanQty sets the "planQty" field if the given value is not nil.
func (_u *DailyPlanUpdate) SetNillablePlanQty(v *int) *DailyPlanUpdate {
if v != nil {
_u.SetPlanQty(*v)
}
return _u
}
// AddPlanQty adds value to the "planQty" field.
func (_u *DailyPlanUpdate) AddPlanQty(v int) *DailyPlanUpdate {
_u.mutation.AddPlanQty(v)
return _u
}
// SetCompletedQty sets the "completedQty" field.
func (_u *DailyPlanUpdate) SetCompletedQty(v int) *DailyPlanUpdate {
_u.mutation.ResetCompletedQty()
_u.mutation.SetCompletedQty(v)
return _u
}
// SetNillableCompletedQty sets the "completedQty" field if the given value is not nil.
func (_u *DailyPlanUpdate) SetNillableCompletedQty(v *int) *DailyPlanUpdate {
if v != nil {
_u.SetCompletedQty(*v)
}
return _u
}
// AddCompletedQty adds value to the "completedQty" field.
func (_u *DailyPlanUpdate) AddCompletedQty(v int) *DailyPlanUpdate {
_u.mutation.AddCompletedQty(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *DailyPlanUpdate) SetStatus(v string) *DailyPlanUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *DailyPlanUpdate) SetNillableStatus(v *string) *DailyPlanUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetOperator sets the "operator" field.
func (_u *DailyPlanUpdate) SetOperator(v string) *DailyPlanUpdate {
_u.mutation.SetOperator(v)
return _u
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_u *DailyPlanUpdate) SetNillableOperator(v *string) *DailyPlanUpdate {
if v != nil {
_u.SetOperator(*v)
}
return _u
}
// SetUpdatedAt sets the "updatedAt" field.
func (_u *DailyPlanUpdate) SetUpdatedAt(v time.Time) *DailyPlanUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (_u *DailyPlanUpdate) ClearUpdatedAt() *DailyPlanUpdate {
_u.mutation.ClearUpdatedAt()
return _u
}
// Mutation returns the DailyPlanMutation object of the builder.
func (_u *DailyPlanUpdate) Mutation() *DailyPlanMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *DailyPlanUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *DailyPlanUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *DailyPlanUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *DailyPlanUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *DailyPlanUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() {
v := dailyplan.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *DailyPlanUpdate) check() error {
if v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *DailyPlanUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *DailyPlanUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *DailyPlanUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(dailyplan.Table, dailyplan.Columns, sqlgraph.NewFieldSpec(dailyplan.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.OrderNo(); ok {
_spec.SetField(dailyplan.FieldOrderNo, field.TypeString, value)
}
if value, ok := _u.mutation.PlanDate(); ok {
_spec.SetField(dailyplan.FieldPlanDate, field.TypeString, value)
}
if value, ok := _u.mutation.PlanQty(); ok {
_spec.SetField(dailyplan.FieldPlanQty, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPlanQty(); ok {
_spec.AddField(dailyplan.FieldPlanQty, field.TypeInt, value)
}
if value, ok := _u.mutation.CompletedQty(); ok {
_spec.SetField(dailyplan.FieldCompletedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCompletedQty(); ok {
_spec.AddField(dailyplan.FieldCompletedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(dailyplan.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Operator(); ok {
_spec.SetField(dailyplan.FieldOperator, field.TypeString, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(dailyplan.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UpdatedAtCleared() {
_spec.ClearField(dailyplan.FieldUpdatedAt, field.TypeTime)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dailyplan.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// DailyPlanUpdateOne is the builder for updating a single DailyPlan entity.
type DailyPlanUpdateOne struct {
config
fields []string
hooks []Hook
mutation *DailyPlanMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetOrderNo sets the "orderNo" field.
func (_u *DailyPlanUpdateOne) SetOrderNo(v string) *DailyPlanUpdateOne {
_u.mutation.SetOrderNo(v)
return _u
}
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
func (_u *DailyPlanUpdateOne) SetNillableOrderNo(v *string) *DailyPlanUpdateOne {
if v != nil {
_u.SetOrderNo(*v)
}
return _u
}
// SetPlanDate sets the "planDate" field.
func (_u *DailyPlanUpdateOne) SetPlanDate(v string) *DailyPlanUpdateOne {
_u.mutation.SetPlanDate(v)
return _u
}
// SetNillablePlanDate sets the "planDate" field if the given value is not nil.
func (_u *DailyPlanUpdateOne) SetNillablePlanDate(v *string) *DailyPlanUpdateOne {
if v != nil {
_u.SetPlanDate(*v)
}
return _u
}
// SetPlanQty sets the "planQty" field.
func (_u *DailyPlanUpdateOne) SetPlanQty(v int) *DailyPlanUpdateOne {
_u.mutation.ResetPlanQty()
_u.mutation.SetPlanQty(v)
return _u
}
// SetNillablePlanQty sets the "planQty" field if the given value is not nil.
func (_u *DailyPlanUpdateOne) SetNillablePlanQty(v *int) *DailyPlanUpdateOne {
if v != nil {
_u.SetPlanQty(*v)
}
return _u
}
// AddPlanQty adds value to the "planQty" field.
func (_u *DailyPlanUpdateOne) AddPlanQty(v int) *DailyPlanUpdateOne {
_u.mutation.AddPlanQty(v)
return _u
}
// SetCompletedQty sets the "completedQty" field.
func (_u *DailyPlanUpdateOne) SetCompletedQty(v int) *DailyPlanUpdateOne {
_u.mutation.ResetCompletedQty()
_u.mutation.SetCompletedQty(v)
return _u
}
// SetNillableCompletedQty sets the "completedQty" field if the given value is not nil.
func (_u *DailyPlanUpdateOne) SetNillableCompletedQty(v *int) *DailyPlanUpdateOne {
if v != nil {
_u.SetCompletedQty(*v)
}
return _u
}
// AddCompletedQty adds value to the "completedQty" field.
func (_u *DailyPlanUpdateOne) AddCompletedQty(v int) *DailyPlanUpdateOne {
_u.mutation.AddCompletedQty(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *DailyPlanUpdateOne) SetStatus(v string) *DailyPlanUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *DailyPlanUpdateOne) SetNillableStatus(v *string) *DailyPlanUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetOperator sets the "operator" field.
func (_u *DailyPlanUpdateOne) SetOperator(v string) *DailyPlanUpdateOne {
_u.mutation.SetOperator(v)
return _u
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_u *DailyPlanUpdateOne) SetNillableOperator(v *string) *DailyPlanUpdateOne {
if v != nil {
_u.SetOperator(*v)
}
return _u
}
// SetUpdatedAt sets the "updatedAt" field.
func (_u *DailyPlanUpdateOne) SetUpdatedAt(v time.Time) *DailyPlanUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (_u *DailyPlanUpdateOne) ClearUpdatedAt() *DailyPlanUpdateOne {
_u.mutation.ClearUpdatedAt()
return _u
}
// Mutation returns the DailyPlanMutation object of the builder.
func (_u *DailyPlanUpdateOne) Mutation() *DailyPlanMutation {
return _u.mutation
}
// Where appends a list predicates to the DailyPlanUpdate builder.
func (_u *DailyPlanUpdateOne) Where(ps ...predicate.DailyPlan) *DailyPlanUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *DailyPlanUpdateOne) Select(field string, fields ...string) *DailyPlanUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated DailyPlan entity.
func (_u *DailyPlanUpdateOne) Save(ctx context.Context) (*DailyPlan, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *DailyPlanUpdateOne) SaveX(ctx context.Context) *DailyPlan {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *DailyPlanUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *DailyPlanUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *DailyPlanUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() {
v := dailyplan.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *DailyPlanUpdateOne) check() error {
if v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *DailyPlanUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *DailyPlanUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *DailyPlanUpdateOne) sqlSave(ctx context.Context) (_node *DailyPlan, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(dailyplan.Table, dailyplan.Columns, sqlgraph.NewFieldSpec(dailyplan.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "DailyPlan.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, dailyplan.FieldID)
for _, f := range fields {
if !dailyplan.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != dailyplan.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.OrderNo(); ok {
_spec.SetField(dailyplan.FieldOrderNo, field.TypeString, value)
}
if value, ok := _u.mutation.PlanDate(); ok {
_spec.SetField(dailyplan.FieldPlanDate, field.TypeString, value)
}
if value, ok := _u.mutation.PlanQty(); ok {
_spec.SetField(dailyplan.FieldPlanQty, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPlanQty(); ok {
_spec.AddField(dailyplan.FieldPlanQty, field.TypeInt, value)
}
if value, ok := _u.mutation.CompletedQty(); ok {
_spec.SetField(dailyplan.FieldCompletedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedCompletedQty(); ok {
_spec.AddField(dailyplan.FieldCompletedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(dailyplan.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.Operator(); ok {
_spec.SetField(dailyplan.FieldOperator, field.TypeString, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(dailyplan.FieldUpdatedAt, field.TypeTime, value)
}
if _u.mutation.UpdatedAtCleared() {
_spec.ClearField(dailyplan.FieldUpdatedAt, field.TypeTime)
}
_spec.AddModifiers(_u.modifiers...)
_node = &DailyPlan{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{dailyplan.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}