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

456 lines
14 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/inbounddetail"
"bj_power_wms/ent/predicate"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// InboundDetailUpdate is the builder for updating InboundDetail entities.
type InboundDetailUpdate struct {
config
hooks []Hook
mutation *InboundDetailMutation
}
// Where appends a list predicates to the InboundDetailUpdate builder.
func (_u *InboundDetailUpdate) Where(ps ...predicate.InboundDetail) *InboundDetailUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetInboundNo sets the "inbound_no" field.
func (_u *InboundDetailUpdate) SetInboundNo(v string) *InboundDetailUpdate {
_u.mutation.SetInboundNo(v)
return _u
}
// SetNillableInboundNo sets the "inbound_no" field if the given value is not nil.
func (_u *InboundDetailUpdate) SetNillableInboundNo(v *string) *InboundDetailUpdate {
if v != nil {
_u.SetInboundNo(*v)
}
return _u
}
// SetSnCode sets the "sn_code" field.
func (_u *InboundDetailUpdate) SetSnCode(v string) *InboundDetailUpdate {
_u.mutation.SetSnCode(v)
return _u
}
// SetNillableSnCode sets the "sn_code" field if the given value is not nil.
func (_u *InboundDetailUpdate) SetNillableSnCode(v *string) *InboundDetailUpdate {
if v != nil {
_u.SetSnCode(*v)
}
return _u
}
// ClearSnCode clears the value of the "sn_code" field.
func (_u *InboundDetailUpdate) ClearSnCode() *InboundDetailUpdate {
_u.mutation.ClearSnCode()
return _u
}
// SetBatchNo sets the "batch_no" field.
func (_u *InboundDetailUpdate) SetBatchNo(v string) *InboundDetailUpdate {
_u.mutation.SetBatchNo(v)
return _u
}
// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
func (_u *InboundDetailUpdate) SetNillableBatchNo(v *string) *InboundDetailUpdate {
if v != nil {
_u.SetBatchNo(*v)
}
return _u
}
// ClearBatchNo clears the value of the "batch_no" field.
func (_u *InboundDetailUpdate) ClearBatchNo() *InboundDetailUpdate {
_u.mutation.ClearBatchNo()
return _u
}
// SetMaterialCode sets the "material_code" field.
func (_u *InboundDetailUpdate) SetMaterialCode(v string) *InboundDetailUpdate {
_u.mutation.SetMaterialCode(v)
return _u
}
// SetNillableMaterialCode sets the "material_code" field if the given value is not nil.
func (_u *InboundDetailUpdate) SetNillableMaterialCode(v *string) *InboundDetailUpdate {
if v != nil {
_u.SetMaterialCode(*v)
}
return _u
}
// SetQuantity sets the "quantity" field.
func (_u *InboundDetailUpdate) SetQuantity(v int) *InboundDetailUpdate {
_u.mutation.ResetQuantity()
_u.mutation.SetQuantity(v)
return _u
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_u *InboundDetailUpdate) SetNillableQuantity(v *int) *InboundDetailUpdate {
if v != nil {
_u.SetQuantity(*v)
}
return _u
}
// AddQuantity adds value to the "quantity" field.
func (_u *InboundDetailUpdate) AddQuantity(v int) *InboundDetailUpdate {
_u.mutation.AddQuantity(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *InboundDetailUpdate) SetCreatedAt(v int64) *InboundDetailUpdate {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *InboundDetailUpdate) SetNillableCreatedAt(v *int64) *InboundDetailUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *InboundDetailUpdate) AddCreatedAt(v int64) *InboundDetailUpdate {
_u.mutation.AddCreatedAt(v)
return _u
}
// Mutation returns the InboundDetailMutation object of the builder.
func (_u *InboundDetailUpdate) Mutation() *InboundDetailMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *InboundDetailUpdate) 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 *InboundDetailUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *InboundDetailUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *InboundDetailUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *InboundDetailUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(inbounddetail.Table, inbounddetail.Columns, sqlgraph.NewFieldSpec(inbounddetail.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.InboundNo(); ok {
_spec.SetField(inbounddetail.FieldInboundNo, field.TypeString, value)
}
if value, ok := _u.mutation.SnCode(); ok {
_spec.SetField(inbounddetail.FieldSnCode, field.TypeString, value)
}
if _u.mutation.SnCodeCleared() {
_spec.ClearField(inbounddetail.FieldSnCode, field.TypeString)
}
if value, ok := _u.mutation.BatchNo(); ok {
_spec.SetField(inbounddetail.FieldBatchNo, field.TypeString, value)
}
if _u.mutation.BatchNoCleared() {
_spec.ClearField(inbounddetail.FieldBatchNo, field.TypeString)
}
if value, ok := _u.mutation.MaterialCode(); ok {
_spec.SetField(inbounddetail.FieldMaterialCode, field.TypeString, value)
}
if value, ok := _u.mutation.Quantity(); ok {
_spec.SetField(inbounddetail.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedQuantity(); ok {
_spec.AddField(inbounddetail.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(inbounddetail.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(inbounddetail.FieldCreatedAt, field.TypeInt64, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{inbounddetail.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// InboundDetailUpdateOne is the builder for updating a single InboundDetail entity.
type InboundDetailUpdateOne struct {
config
fields []string
hooks []Hook
mutation *InboundDetailMutation
}
// SetInboundNo sets the "inbound_no" field.
func (_u *InboundDetailUpdateOne) SetInboundNo(v string) *InboundDetailUpdateOne {
_u.mutation.SetInboundNo(v)
return _u
}
// SetNillableInboundNo sets the "inbound_no" field if the given value is not nil.
func (_u *InboundDetailUpdateOne) SetNillableInboundNo(v *string) *InboundDetailUpdateOne {
if v != nil {
_u.SetInboundNo(*v)
}
return _u
}
// SetSnCode sets the "sn_code" field.
func (_u *InboundDetailUpdateOne) SetSnCode(v string) *InboundDetailUpdateOne {
_u.mutation.SetSnCode(v)
return _u
}
// SetNillableSnCode sets the "sn_code" field if the given value is not nil.
func (_u *InboundDetailUpdateOne) SetNillableSnCode(v *string) *InboundDetailUpdateOne {
if v != nil {
_u.SetSnCode(*v)
}
return _u
}
// ClearSnCode clears the value of the "sn_code" field.
func (_u *InboundDetailUpdateOne) ClearSnCode() *InboundDetailUpdateOne {
_u.mutation.ClearSnCode()
return _u
}
// SetBatchNo sets the "batch_no" field.
func (_u *InboundDetailUpdateOne) SetBatchNo(v string) *InboundDetailUpdateOne {
_u.mutation.SetBatchNo(v)
return _u
}
// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
func (_u *InboundDetailUpdateOne) SetNillableBatchNo(v *string) *InboundDetailUpdateOne {
if v != nil {
_u.SetBatchNo(*v)
}
return _u
}
// ClearBatchNo clears the value of the "batch_no" field.
func (_u *InboundDetailUpdateOne) ClearBatchNo() *InboundDetailUpdateOne {
_u.mutation.ClearBatchNo()
return _u
}
// SetMaterialCode sets the "material_code" field.
func (_u *InboundDetailUpdateOne) SetMaterialCode(v string) *InboundDetailUpdateOne {
_u.mutation.SetMaterialCode(v)
return _u
}
// SetNillableMaterialCode sets the "material_code" field if the given value is not nil.
func (_u *InboundDetailUpdateOne) SetNillableMaterialCode(v *string) *InboundDetailUpdateOne {
if v != nil {
_u.SetMaterialCode(*v)
}
return _u
}
// SetQuantity sets the "quantity" field.
func (_u *InboundDetailUpdateOne) SetQuantity(v int) *InboundDetailUpdateOne {
_u.mutation.ResetQuantity()
_u.mutation.SetQuantity(v)
return _u
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_u *InboundDetailUpdateOne) SetNillableQuantity(v *int) *InboundDetailUpdateOne {
if v != nil {
_u.SetQuantity(*v)
}
return _u
}
// AddQuantity adds value to the "quantity" field.
func (_u *InboundDetailUpdateOne) AddQuantity(v int) *InboundDetailUpdateOne {
_u.mutation.AddQuantity(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *InboundDetailUpdateOne) SetCreatedAt(v int64) *InboundDetailUpdateOne {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *InboundDetailUpdateOne) SetNillableCreatedAt(v *int64) *InboundDetailUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *InboundDetailUpdateOne) AddCreatedAt(v int64) *InboundDetailUpdateOne {
_u.mutation.AddCreatedAt(v)
return _u
}
// Mutation returns the InboundDetailMutation object of the builder.
func (_u *InboundDetailUpdateOne) Mutation() *InboundDetailMutation {
return _u.mutation
}
// Where appends a list predicates to the InboundDetailUpdate builder.
func (_u *InboundDetailUpdateOne) Where(ps ...predicate.InboundDetail) *InboundDetailUpdateOne {
_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 *InboundDetailUpdateOne) Select(field string, fields ...string) *InboundDetailUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated InboundDetail entity.
func (_u *InboundDetailUpdateOne) Save(ctx context.Context) (*InboundDetail, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *InboundDetailUpdateOne) SaveX(ctx context.Context) *InboundDetail {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *InboundDetailUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *InboundDetailUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *InboundDetailUpdateOne) sqlSave(ctx context.Context) (_node *InboundDetail, err error) {
_spec := sqlgraph.NewUpdateSpec(inbounddetail.Table, inbounddetail.Columns, sqlgraph.NewFieldSpec(inbounddetail.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "InboundDetail.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, inbounddetail.FieldID)
for _, f := range fields {
if !inbounddetail.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != inbounddetail.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.InboundNo(); ok {
_spec.SetField(inbounddetail.FieldInboundNo, field.TypeString, value)
}
if value, ok := _u.mutation.SnCode(); ok {
_spec.SetField(inbounddetail.FieldSnCode, field.TypeString, value)
}
if _u.mutation.SnCodeCleared() {
_spec.ClearField(inbounddetail.FieldSnCode, field.TypeString)
}
if value, ok := _u.mutation.BatchNo(); ok {
_spec.SetField(inbounddetail.FieldBatchNo, field.TypeString, value)
}
if _u.mutation.BatchNoCleared() {
_spec.ClearField(inbounddetail.FieldBatchNo, field.TypeString)
}
if value, ok := _u.mutation.MaterialCode(); ok {
_spec.SetField(inbounddetail.FieldMaterialCode, field.TypeString, value)
}
if value, ok := _u.mutation.Quantity(); ok {
_spec.SetField(inbounddetail.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedQuantity(); ok {
_spec.AddField(inbounddetail.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(inbounddetail.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(inbounddetail.FieldCreatedAt, field.TypeInt64, value)
}
_node = &InboundDetail{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{inbounddetail.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}