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

526 lines
15 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/packagebox"
"bj_power_wms/ent/predicate"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// PackageBoxUpdate is the builder for updating PackageBox entities.
type PackageBoxUpdate struct {
config
hooks []Hook
mutation *PackageBoxMutation
}
// Where appends a list predicates to the PackageBoxUpdate builder.
func (_u *PackageBoxUpdate) Where(ps ...predicate.PackageBox) *PackageBoxUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetBoxNo sets the "box_no" field.
func (_u *PackageBoxUpdate) SetBoxNo(v string) *PackageBoxUpdate {
_u.mutation.SetBoxNo(v)
return _u
}
// SetNillableBoxNo sets the "box_no" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableBoxNo(v *string) *PackageBoxUpdate {
if v != nil {
_u.SetBoxNo(*v)
}
return _u
}
// SetSnList sets the "sn_list" field.
func (_u *PackageBoxUpdate) SetSnList(v string) *PackageBoxUpdate {
_u.mutation.SetSnList(v)
return _u
}
// SetNillableSnList sets the "sn_list" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableSnList(v *string) *PackageBoxUpdate {
if v != nil {
_u.SetSnList(*v)
}
return _u
}
// ClearSnList clears the value of the "sn_list" field.
func (_u *PackageBoxUpdate) ClearSnList() *PackageBoxUpdate {
_u.mutation.ClearSnList()
return _u
}
// SetMaterialCode sets the "material_code" field.
func (_u *PackageBoxUpdate) SetMaterialCode(v string) *PackageBoxUpdate {
_u.mutation.SetMaterialCode(v)
return _u
}
// SetNillableMaterialCode sets the "material_code" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableMaterialCode(v *string) *PackageBoxUpdate {
if v != nil {
_u.SetMaterialCode(*v)
}
return _u
}
// ClearMaterialCode clears the value of the "material_code" field.
func (_u *PackageBoxUpdate) ClearMaterialCode() *PackageBoxUpdate {
_u.mutation.ClearMaterialCode()
return _u
}
// SetQuantity sets the "quantity" field.
func (_u *PackageBoxUpdate) SetQuantity(v int) *PackageBoxUpdate {
_u.mutation.ResetQuantity()
_u.mutation.SetQuantity(v)
return _u
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableQuantity(v *int) *PackageBoxUpdate {
if v != nil {
_u.SetQuantity(*v)
}
return _u
}
// AddQuantity adds value to the "quantity" field.
func (_u *PackageBoxUpdate) AddQuantity(v int) *PackageBoxUpdate {
_u.mutation.AddQuantity(v)
return _u
}
// SetOperator sets the "operator" field.
func (_u *PackageBoxUpdate) SetOperator(v string) *PackageBoxUpdate {
_u.mutation.SetOperator(v)
return _u
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableOperator(v *string) *PackageBoxUpdate {
if v != nil {
_u.SetOperator(*v)
}
return _u
}
// ClearOperator clears the value of the "operator" field.
func (_u *PackageBoxUpdate) ClearOperator() *PackageBoxUpdate {
_u.mutation.ClearOperator()
return _u
}
// SetRemark sets the "remark" field.
func (_u *PackageBoxUpdate) SetRemark(v string) *PackageBoxUpdate {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableRemark(v *string) *PackageBoxUpdate {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// ClearRemark clears the value of the "remark" field.
func (_u *PackageBoxUpdate) ClearRemark() *PackageBoxUpdate {
_u.mutation.ClearRemark()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *PackageBoxUpdate) SetCreatedAt(v int64) *PackageBoxUpdate {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *PackageBoxUpdate) SetNillableCreatedAt(v *int64) *PackageBoxUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *PackageBoxUpdate) AddCreatedAt(v int64) *PackageBoxUpdate {
_u.mutation.AddCreatedAt(v)
return _u
}
// Mutation returns the PackageBoxMutation object of the builder.
func (_u *PackageBoxUpdate) Mutation() *PackageBoxMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *PackageBoxUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *PackageBoxUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *PackageBoxUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *PackageBoxUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *PackageBoxUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(packagebox.Table, packagebox.Columns, sqlgraph.NewFieldSpec(packagebox.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.BoxNo(); ok {
_spec.SetField(packagebox.FieldBoxNo, field.TypeString, value)
}
if value, ok := _u.mutation.SnList(); ok {
_spec.SetField(packagebox.FieldSnList, field.TypeString, value)
}
if _u.mutation.SnListCleared() {
_spec.ClearField(packagebox.FieldSnList, field.TypeString)
}
if value, ok := _u.mutation.MaterialCode(); ok {
_spec.SetField(packagebox.FieldMaterialCode, field.TypeString, value)
}
if _u.mutation.MaterialCodeCleared() {
_spec.ClearField(packagebox.FieldMaterialCode, field.TypeString)
}
if value, ok := _u.mutation.Quantity(); ok {
_spec.SetField(packagebox.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedQuantity(); ok {
_spec.AddField(packagebox.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.Operator(); ok {
_spec.SetField(packagebox.FieldOperator, field.TypeString, value)
}
if _u.mutation.OperatorCleared() {
_spec.ClearField(packagebox.FieldOperator, field.TypeString)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(packagebox.FieldRemark, field.TypeString, value)
}
if _u.mutation.RemarkCleared() {
_spec.ClearField(packagebox.FieldRemark, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(packagebox.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(packagebox.FieldCreatedAt, field.TypeInt64, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{packagebox.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// PackageBoxUpdateOne is the builder for updating a single PackageBox entity.
type PackageBoxUpdateOne struct {
config
fields []string
hooks []Hook
mutation *PackageBoxMutation
}
// SetBoxNo sets the "box_no" field.
func (_u *PackageBoxUpdateOne) SetBoxNo(v string) *PackageBoxUpdateOne {
_u.mutation.SetBoxNo(v)
return _u
}
// SetNillableBoxNo sets the "box_no" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableBoxNo(v *string) *PackageBoxUpdateOne {
if v != nil {
_u.SetBoxNo(*v)
}
return _u
}
// SetSnList sets the "sn_list" field.
func (_u *PackageBoxUpdateOne) SetSnList(v string) *PackageBoxUpdateOne {
_u.mutation.SetSnList(v)
return _u
}
// SetNillableSnList sets the "sn_list" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableSnList(v *string) *PackageBoxUpdateOne {
if v != nil {
_u.SetSnList(*v)
}
return _u
}
// ClearSnList clears the value of the "sn_list" field.
func (_u *PackageBoxUpdateOne) ClearSnList() *PackageBoxUpdateOne {
_u.mutation.ClearSnList()
return _u
}
// SetMaterialCode sets the "material_code" field.
func (_u *PackageBoxUpdateOne) SetMaterialCode(v string) *PackageBoxUpdateOne {
_u.mutation.SetMaterialCode(v)
return _u
}
// SetNillableMaterialCode sets the "material_code" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableMaterialCode(v *string) *PackageBoxUpdateOne {
if v != nil {
_u.SetMaterialCode(*v)
}
return _u
}
// ClearMaterialCode clears the value of the "material_code" field.
func (_u *PackageBoxUpdateOne) ClearMaterialCode() *PackageBoxUpdateOne {
_u.mutation.ClearMaterialCode()
return _u
}
// SetQuantity sets the "quantity" field.
func (_u *PackageBoxUpdateOne) SetQuantity(v int) *PackageBoxUpdateOne {
_u.mutation.ResetQuantity()
_u.mutation.SetQuantity(v)
return _u
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableQuantity(v *int) *PackageBoxUpdateOne {
if v != nil {
_u.SetQuantity(*v)
}
return _u
}
// AddQuantity adds value to the "quantity" field.
func (_u *PackageBoxUpdateOne) AddQuantity(v int) *PackageBoxUpdateOne {
_u.mutation.AddQuantity(v)
return _u
}
// SetOperator sets the "operator" field.
func (_u *PackageBoxUpdateOne) SetOperator(v string) *PackageBoxUpdateOne {
_u.mutation.SetOperator(v)
return _u
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableOperator(v *string) *PackageBoxUpdateOne {
if v != nil {
_u.SetOperator(*v)
}
return _u
}
// ClearOperator clears the value of the "operator" field.
func (_u *PackageBoxUpdateOne) ClearOperator() *PackageBoxUpdateOne {
_u.mutation.ClearOperator()
return _u
}
// SetRemark sets the "remark" field.
func (_u *PackageBoxUpdateOne) SetRemark(v string) *PackageBoxUpdateOne {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableRemark(v *string) *PackageBoxUpdateOne {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// ClearRemark clears the value of the "remark" field.
func (_u *PackageBoxUpdateOne) ClearRemark() *PackageBoxUpdateOne {
_u.mutation.ClearRemark()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *PackageBoxUpdateOne) SetCreatedAt(v int64) *PackageBoxUpdateOne {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *PackageBoxUpdateOne) SetNillableCreatedAt(v *int64) *PackageBoxUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *PackageBoxUpdateOne) AddCreatedAt(v int64) *PackageBoxUpdateOne {
_u.mutation.AddCreatedAt(v)
return _u
}
// Mutation returns the PackageBoxMutation object of the builder.
func (_u *PackageBoxUpdateOne) Mutation() *PackageBoxMutation {
return _u.mutation
}
// Where appends a list predicates to the PackageBoxUpdate builder.
func (_u *PackageBoxUpdateOne) Where(ps ...predicate.PackageBox) *PackageBoxUpdateOne {
_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 *PackageBoxUpdateOne) Select(field string, fields ...string) *PackageBoxUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated PackageBox entity.
func (_u *PackageBoxUpdateOne) Save(ctx context.Context) (*PackageBox, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *PackageBoxUpdateOne) SaveX(ctx context.Context) *PackageBox {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *PackageBoxUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *PackageBoxUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *PackageBoxUpdateOne) sqlSave(ctx context.Context) (_node *PackageBox, err error) {
_spec := sqlgraph.NewUpdateSpec(packagebox.Table, packagebox.Columns, sqlgraph.NewFieldSpec(packagebox.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "PackageBox.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, packagebox.FieldID)
for _, f := range fields {
if !packagebox.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != packagebox.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.BoxNo(); ok {
_spec.SetField(packagebox.FieldBoxNo, field.TypeString, value)
}
if value, ok := _u.mutation.SnList(); ok {
_spec.SetField(packagebox.FieldSnList, field.TypeString, value)
}
if _u.mutation.SnListCleared() {
_spec.ClearField(packagebox.FieldSnList, field.TypeString)
}
if value, ok := _u.mutation.MaterialCode(); ok {
_spec.SetField(packagebox.FieldMaterialCode, field.TypeString, value)
}
if _u.mutation.MaterialCodeCleared() {
_spec.ClearField(packagebox.FieldMaterialCode, field.TypeString)
}
if value, ok := _u.mutation.Quantity(); ok {
_spec.SetField(packagebox.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedQuantity(); ok {
_spec.AddField(packagebox.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.Operator(); ok {
_spec.SetField(packagebox.FieldOperator, field.TypeString, value)
}
if _u.mutation.OperatorCleared() {
_spec.ClearField(packagebox.FieldOperator, field.TypeString)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(packagebox.FieldRemark, field.TypeString, value)
}
if _u.mutation.RemarkCleared() {
_spec.ClearField(packagebox.FieldRemark, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(packagebox.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(packagebox.FieldCreatedAt, field.TypeInt64, value)
}
_node = &PackageBox{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{packagebox.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}