687 lines
20 KiB
Go
687 lines
20 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/predicate"
|
|
"bj_power_mes/ent/workpiece"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// WorkpieceUpdate is the builder for updating Workpiece entities.
|
|
type WorkpieceUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *WorkpieceMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the WorkpieceUpdate builder.
|
|
func (_u *WorkpieceUpdate) Where(ps ...predicate.Workpiece) *WorkpieceUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetSn sets the "sn" field.
|
|
func (_u *WorkpieceUpdate) SetSn(v string) *WorkpieceUpdate {
|
|
_u.mutation.SetSn(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSn sets the "sn" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableSn(v *string) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetSn(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOrderNo sets the "orderNo" field.
|
|
func (_u *WorkpieceUpdate) SetOrderNo(v string) *WorkpieceUpdate {
|
|
_u.mutation.SetOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableOrderNo(v *string) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWorkOrderId sets the "workOrderId" field.
|
|
func (_u *WorkpieceUpdate) SetWorkOrderId(v int) *WorkpieceUpdate {
|
|
_u.mutation.ResetWorkOrderId()
|
|
_u.mutation.SetWorkOrderId(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkOrderId sets the "workOrderId" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableWorkOrderId(v *int) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetWorkOrderId(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddWorkOrderId adds value to the "workOrderId" field.
|
|
func (_u *WorkpieceUpdate) AddWorkOrderId(v int) *WorkpieceUpdate {
|
|
_u.mutation.AddWorkOrderId(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearWorkOrderId clears the value of the "workOrderId" field.
|
|
func (_u *WorkpieceUpdate) ClearWorkOrderId() *WorkpieceUpdate {
|
|
_u.mutation.ClearWorkOrderId()
|
|
return _u
|
|
}
|
|
|
|
// SetProcessSeq sets the "processSeq" field.
|
|
func (_u *WorkpieceUpdate) SetProcessSeq(v string) *WorkpieceUpdate {
|
|
_u.mutation.SetProcessSeq(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProcessSeq sets the "processSeq" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableProcessSeq(v *string) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetProcessSeq(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCurrentProcess sets the "currentProcess" field.
|
|
func (_u *WorkpieceUpdate) SetCurrentProcess(v int) *WorkpieceUpdate {
|
|
_u.mutation.ResetCurrentProcess()
|
|
_u.mutation.SetCurrentProcess(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCurrentProcess sets the "currentProcess" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableCurrentProcess(v *int) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetCurrentProcess(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCurrentProcess adds value to the "currentProcess" field.
|
|
func (_u *WorkpieceUpdate) AddCurrentProcess(v int) *WorkpieceUpdate {
|
|
_u.mutation.AddCurrentProcess(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearCurrentProcess clears the value of the "currentProcess" field.
|
|
func (_u *WorkpieceUpdate) ClearCurrentProcess() *WorkpieceUpdate {
|
|
_u.mutation.ClearCurrentProcess()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *WorkpieceUpdate) SetStatus(v string) *WorkpieceUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableStatus(v *string) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOnlineAt sets the "onlineAt" field.
|
|
func (_u *WorkpieceUpdate) SetOnlineAt(v time.Time) *WorkpieceUpdate {
|
|
_u.mutation.SetOnlineAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOnlineAt sets the "onlineAt" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableOnlineAt(v *time.Time) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetOnlineAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearOnlineAt clears the value of the "onlineAt" field.
|
|
func (_u *WorkpieceUpdate) ClearOnlineAt() *WorkpieceUpdate {
|
|
_u.mutation.ClearOnlineAt()
|
|
return _u
|
|
}
|
|
|
|
// SetDoneAt sets the "doneAt" field.
|
|
func (_u *WorkpieceUpdate) SetDoneAt(v time.Time) *WorkpieceUpdate {
|
|
_u.mutation.SetDoneAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDoneAt sets the "doneAt" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdate) SetNillableDoneAt(v *time.Time) *WorkpieceUpdate {
|
|
if v != nil {
|
|
_u.SetDoneAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDoneAt clears the value of the "doneAt" field.
|
|
func (_u *WorkpieceUpdate) ClearDoneAt() *WorkpieceUpdate {
|
|
_u.mutation.ClearDoneAt()
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
|
func (_u *WorkpieceUpdate) SetUpdatedAt(v time.Time) *WorkpieceUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updatedAt" field.
|
|
func (_u *WorkpieceUpdate) ClearUpdatedAt() *WorkpieceUpdate {
|
|
_u.mutation.ClearUpdatedAt()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the WorkpieceMutation object of the builder.
|
|
func (_u *WorkpieceUpdate) Mutation() *WorkpieceMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *WorkpieceUpdate) 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 *WorkpieceUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *WorkpieceUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *WorkpieceUpdate) 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 *WorkpieceUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() {
|
|
v := workpiece.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *WorkpieceUpdate) check() error {
|
|
if v, ok := _u.mutation.Sn(); ok {
|
|
if err := workpiece.SnValidator(v); err != nil {
|
|
return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "Workpiece.sn": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.OrderNo(); ok {
|
|
if err := workpiece.OrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "Workpiece.orderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ProcessSeq(); ok {
|
|
if err := workpiece.ProcessSeqValidator(v); err != nil {
|
|
return &ValidationError{Name: "processSeq", err: fmt.Errorf(`ent: validator failed for field "Workpiece.processSeq": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := workpiece.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Workpiece.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *WorkpieceUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WorkpieceUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *WorkpieceUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(workpiece.Table, workpiece.Columns, sqlgraph.NewFieldSpec(workpiece.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.Sn(); ok {
|
|
_spec.SetField(workpiece.FieldSn, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OrderNo(); ok {
|
|
_spec.SetField(workpiece.FieldOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WorkOrderId(); ok {
|
|
_spec.SetField(workpiece.FieldWorkOrderId, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedWorkOrderId(); ok {
|
|
_spec.AddField(workpiece.FieldWorkOrderId, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.WorkOrderIdCleared() {
|
|
_spec.ClearField(workpiece.FieldWorkOrderId, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.ProcessSeq(); ok {
|
|
_spec.SetField(workpiece.FieldProcessSeq, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CurrentProcess(); ok {
|
|
_spec.SetField(workpiece.FieldCurrentProcess, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCurrentProcess(); ok {
|
|
_spec.AddField(workpiece.FieldCurrentProcess, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.CurrentProcessCleared() {
|
|
_spec.ClearField(workpiece.FieldCurrentProcess, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(workpiece.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OnlineAt(); ok {
|
|
_spec.SetField(workpiece.FieldOnlineAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.OnlineAtCleared() {
|
|
_spec.ClearField(workpiece.FieldOnlineAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.DoneAt(); ok {
|
|
_spec.SetField(workpiece.FieldDoneAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DoneAtCleared() {
|
|
_spec.ClearField(workpiece.FieldDoneAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(workpiece.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.UpdatedAtCleared() {
|
|
_spec.ClearField(workpiece.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{workpiece.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// WorkpieceUpdateOne is the builder for updating a single Workpiece entity.
|
|
type WorkpieceUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *WorkpieceMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetSn sets the "sn" field.
|
|
func (_u *WorkpieceUpdateOne) SetSn(v string) *WorkpieceUpdateOne {
|
|
_u.mutation.SetSn(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSn sets the "sn" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableSn(v *string) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetSn(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOrderNo sets the "orderNo" field.
|
|
func (_u *WorkpieceUpdateOne) SetOrderNo(v string) *WorkpieceUpdateOne {
|
|
_u.mutation.SetOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableOrderNo(v *string) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWorkOrderId sets the "workOrderId" field.
|
|
func (_u *WorkpieceUpdateOne) SetWorkOrderId(v int) *WorkpieceUpdateOne {
|
|
_u.mutation.ResetWorkOrderId()
|
|
_u.mutation.SetWorkOrderId(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkOrderId sets the "workOrderId" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableWorkOrderId(v *int) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetWorkOrderId(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddWorkOrderId adds value to the "workOrderId" field.
|
|
func (_u *WorkpieceUpdateOne) AddWorkOrderId(v int) *WorkpieceUpdateOne {
|
|
_u.mutation.AddWorkOrderId(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearWorkOrderId clears the value of the "workOrderId" field.
|
|
func (_u *WorkpieceUpdateOne) ClearWorkOrderId() *WorkpieceUpdateOne {
|
|
_u.mutation.ClearWorkOrderId()
|
|
return _u
|
|
}
|
|
|
|
// SetProcessSeq sets the "processSeq" field.
|
|
func (_u *WorkpieceUpdateOne) SetProcessSeq(v string) *WorkpieceUpdateOne {
|
|
_u.mutation.SetProcessSeq(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProcessSeq sets the "processSeq" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableProcessSeq(v *string) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetProcessSeq(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCurrentProcess sets the "currentProcess" field.
|
|
func (_u *WorkpieceUpdateOne) SetCurrentProcess(v int) *WorkpieceUpdateOne {
|
|
_u.mutation.ResetCurrentProcess()
|
|
_u.mutation.SetCurrentProcess(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCurrentProcess sets the "currentProcess" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableCurrentProcess(v *int) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetCurrentProcess(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCurrentProcess adds value to the "currentProcess" field.
|
|
func (_u *WorkpieceUpdateOne) AddCurrentProcess(v int) *WorkpieceUpdateOne {
|
|
_u.mutation.AddCurrentProcess(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearCurrentProcess clears the value of the "currentProcess" field.
|
|
func (_u *WorkpieceUpdateOne) ClearCurrentProcess() *WorkpieceUpdateOne {
|
|
_u.mutation.ClearCurrentProcess()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *WorkpieceUpdateOne) SetStatus(v string) *WorkpieceUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableStatus(v *string) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOnlineAt sets the "onlineAt" field.
|
|
func (_u *WorkpieceUpdateOne) SetOnlineAt(v time.Time) *WorkpieceUpdateOne {
|
|
_u.mutation.SetOnlineAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOnlineAt sets the "onlineAt" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableOnlineAt(v *time.Time) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetOnlineAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearOnlineAt clears the value of the "onlineAt" field.
|
|
func (_u *WorkpieceUpdateOne) ClearOnlineAt() *WorkpieceUpdateOne {
|
|
_u.mutation.ClearOnlineAt()
|
|
return _u
|
|
}
|
|
|
|
// SetDoneAt sets the "doneAt" field.
|
|
func (_u *WorkpieceUpdateOne) SetDoneAt(v time.Time) *WorkpieceUpdateOne {
|
|
_u.mutation.SetDoneAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDoneAt sets the "doneAt" field if the given value is not nil.
|
|
func (_u *WorkpieceUpdateOne) SetNillableDoneAt(v *time.Time) *WorkpieceUpdateOne {
|
|
if v != nil {
|
|
_u.SetDoneAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearDoneAt clears the value of the "doneAt" field.
|
|
func (_u *WorkpieceUpdateOne) ClearDoneAt() *WorkpieceUpdateOne {
|
|
_u.mutation.ClearDoneAt()
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
|
func (_u *WorkpieceUpdateOne) SetUpdatedAt(v time.Time) *WorkpieceUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearUpdatedAt clears the value of the "updatedAt" field.
|
|
func (_u *WorkpieceUpdateOne) ClearUpdatedAt() *WorkpieceUpdateOne {
|
|
_u.mutation.ClearUpdatedAt()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the WorkpieceMutation object of the builder.
|
|
func (_u *WorkpieceUpdateOne) Mutation() *WorkpieceMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the WorkpieceUpdate builder.
|
|
func (_u *WorkpieceUpdateOne) Where(ps ...predicate.Workpiece) *WorkpieceUpdateOne {
|
|
_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 *WorkpieceUpdateOne) Select(field string, fields ...string) *WorkpieceUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Workpiece entity.
|
|
func (_u *WorkpieceUpdateOne) Save(ctx context.Context) (*Workpiece, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *WorkpieceUpdateOne) SaveX(ctx context.Context) *Workpiece {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *WorkpieceUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *WorkpieceUpdateOne) 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 *WorkpieceUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() {
|
|
v := workpiece.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *WorkpieceUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Sn(); ok {
|
|
if err := workpiece.SnValidator(v); err != nil {
|
|
return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "Workpiece.sn": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.OrderNo(); ok {
|
|
if err := workpiece.OrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "Workpiece.orderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ProcessSeq(); ok {
|
|
if err := workpiece.ProcessSeqValidator(v); err != nil {
|
|
return &ValidationError{Name: "processSeq", err: fmt.Errorf(`ent: validator failed for field "Workpiece.processSeq": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := workpiece.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Workpiece.status": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *WorkpieceUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WorkpieceUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *WorkpieceUpdateOne) sqlSave(ctx context.Context) (_node *Workpiece, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(workpiece.Table, workpiece.Columns, sqlgraph.NewFieldSpec(workpiece.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Workpiece.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, workpiece.FieldID)
|
|
for _, f := range fields {
|
|
if !workpiece.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != workpiece.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.Sn(); ok {
|
|
_spec.SetField(workpiece.FieldSn, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OrderNo(); ok {
|
|
_spec.SetField(workpiece.FieldOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WorkOrderId(); ok {
|
|
_spec.SetField(workpiece.FieldWorkOrderId, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedWorkOrderId(); ok {
|
|
_spec.AddField(workpiece.FieldWorkOrderId, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.WorkOrderIdCleared() {
|
|
_spec.ClearField(workpiece.FieldWorkOrderId, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.ProcessSeq(); ok {
|
|
_spec.SetField(workpiece.FieldProcessSeq, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CurrentProcess(); ok {
|
|
_spec.SetField(workpiece.FieldCurrentProcess, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCurrentProcess(); ok {
|
|
_spec.AddField(workpiece.FieldCurrentProcess, field.TypeInt, value)
|
|
}
|
|
if _u.mutation.CurrentProcessCleared() {
|
|
_spec.ClearField(workpiece.FieldCurrentProcess, field.TypeInt)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(workpiece.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OnlineAt(); ok {
|
|
_spec.SetField(workpiece.FieldOnlineAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.OnlineAtCleared() {
|
|
_spec.ClearField(workpiece.FieldOnlineAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.DoneAt(); ok {
|
|
_spec.SetField(workpiece.FieldDoneAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.DoneAtCleared() {
|
|
_spec.ClearField(workpiece.FieldDoneAt, field.TypeTime)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(workpiece.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if _u.mutation.UpdatedAtCleared() {
|
|
_spec.ClearField(workpiece.FieldUpdatedAt, field.TypeTime)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &Workpiece{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{workpiece.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|