1. 新增装机绑定实体与相关CRUD逻辑,支持工件工序物料绑定/解绑 2. 为BOM物料新增装配工序字段,支持按工序校验绑定 3. 扩展权限表,新增父权限码字段支持菜单按钮关联 4. 统一各页面帮助弹窗参数,新增角色管理帮助文档 5. 新增公共格式化工具函数,优化侧边栏菜单展开逻辑 6. 新增工位终端绑定代理接口与MES内部绑定API 7. 修复主入口数据库连接与schema初始化逻辑,新增一键迁移工具
746 lines
24 KiB
Go
746 lines
24 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/predicate"
|
|
"bj_power_mes/ent/workpiecebind"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// WorkpieceBindUpdate is the builder for updating WorkpieceBind entities.
|
|
type WorkpieceBindUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *WorkpieceBindMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the WorkpieceBindUpdate builder.
|
|
func (_u *WorkpieceBindUpdate) Where(ps ...predicate.WorkpieceBind) *WorkpieceBindUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetSn sets the "sn" field.
|
|
func (_u *WorkpieceBindUpdate) SetSn(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetSn(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSn sets the "sn" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableSn(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetSn(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOrderNo sets the "orderNo" field.
|
|
func (_u *WorkpieceBindUpdate) SetOrderNo(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableOrderNo(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetProcessCode sets the "processCode" field.
|
|
func (_u *WorkpieceBindUpdate) SetProcessCode(v int) *WorkpieceBindUpdate {
|
|
_u.mutation.ResetProcessCode()
|
|
_u.mutation.SetProcessCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProcessCode sets the "processCode" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableProcessCode(v *int) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetProcessCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddProcessCode adds value to the "processCode" field.
|
|
func (_u *WorkpieceBindUpdate) AddProcessCode(v int) *WorkpieceBindUpdate {
|
|
_u.mutation.AddProcessCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetStationNo sets the "stationNo" field.
|
|
func (_u *WorkpieceBindUpdate) SetStationNo(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetStationNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableStationNo(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetStationNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_u *WorkpieceBindUpdate) SetMaterialCode(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetMaterialCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialCode sets the "materialCode" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableMaterialCode(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_u *WorkpieceBindUpdate) SetMaterialName(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetMaterialName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableMaterialName(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_u *WorkpieceBindUpdate) SetSpec(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetSpec(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableSpec(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetSpec(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_u *WorkpieceBindUpdate) SetUnit(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetUnit(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableUnit(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetUnit(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manageMode" field.
|
|
func (_u *WorkpieceBindUpdate) SetManageMode(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manageMode" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableManageMode(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetManageMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBindValue sets the "bindValue" field.
|
|
func (_u *WorkpieceBindUpdate) SetBindValue(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetBindValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBindValue sets the "bindValue" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableBindValue(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetBindValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBindType sets the "bindType" field.
|
|
func (_u *WorkpieceBindUpdate) SetBindType(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetBindType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBindType sets the "bindType" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableBindType(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetBindType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_u *WorkpieceBindUpdate) SetOperator(v string) *WorkpieceBindUpdate {
|
|
_u.mutation.SetOperator(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdate) SetNillableOperator(v *string) *WorkpieceBindUpdate {
|
|
if v != nil {
|
|
_u.SetOperator(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the WorkpieceBindMutation object of the builder.
|
|
func (_u *WorkpieceBindUpdate) Mutation() *WorkpieceBindMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *WorkpieceBindUpdate) 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 *WorkpieceBindUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *WorkpieceBindUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *WorkpieceBindUpdate) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *WorkpieceBindUpdate) check() error {
|
|
if v, ok := _u.mutation.Sn(); ok {
|
|
if err := workpiecebind.SnValidator(v); err != nil {
|
|
return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.sn": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.OrderNo(); ok {
|
|
if err := workpiecebind.OrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.orderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.StationNo(); ok {
|
|
if err := workpiecebind.StationNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "stationNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.stationNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialCode(); ok {
|
|
if err := workpiecebind.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialName(); ok {
|
|
if err := workpiecebind.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Spec(); ok {
|
|
if err := workpiecebind.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.spec": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Unit(); ok {
|
|
if err := workpiecebind.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.unit": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ManageMode(); ok {
|
|
if err := workpiecebind.ManageModeValidator(v); err != nil {
|
|
return &ValidationError{Name: "manageMode", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.manageMode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.BindValue(); ok {
|
|
if err := workpiecebind.BindValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "bindValue", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.bindValue": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.BindType(); ok {
|
|
if err := workpiecebind.BindTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "bindType", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.bindType": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Operator(); ok {
|
|
if err := workpiecebind.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.operator": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *WorkpieceBindUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WorkpieceBindUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *WorkpieceBindUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(workpiecebind.Table, workpiecebind.Columns, sqlgraph.NewFieldSpec(workpiecebind.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(workpiecebind.FieldSn, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OrderNo(); ok {
|
|
_spec.SetField(workpiecebind.FieldOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ProcessCode(); ok {
|
|
_spec.SetField(workpiecebind.FieldProcessCode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedProcessCode(); ok {
|
|
_spec.AddField(workpiecebind.FieldProcessCode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.StationNo(); ok {
|
|
_spec.SetField(workpiecebind.FieldStationNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialCode(); ok {
|
|
_spec.SetField(workpiecebind.FieldMaterialCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialName(); ok {
|
|
_spec.SetField(workpiecebind.FieldMaterialName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(workpiecebind.FieldSpec, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(workpiecebind.FieldUnit, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ManageMode(); ok {
|
|
_spec.SetField(workpiecebind.FieldManageMode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.BindValue(); ok {
|
|
_spec.SetField(workpiecebind.FieldBindValue, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.BindType(); ok {
|
|
_spec.SetField(workpiecebind.FieldBindType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Operator(); ok {
|
|
_spec.SetField(workpiecebind.FieldOperator, field.TypeString, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{workpiecebind.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// WorkpieceBindUpdateOne is the builder for updating a single WorkpieceBind entity.
|
|
type WorkpieceBindUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *WorkpieceBindMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetSn sets the "sn" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetSn(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetSn(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSn sets the "sn" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableSn(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetSn(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOrderNo sets the "orderNo" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetOrderNo(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableOrderNo(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetProcessCode sets the "processCode" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetProcessCode(v int) *WorkpieceBindUpdateOne {
|
|
_u.mutation.ResetProcessCode()
|
|
_u.mutation.SetProcessCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProcessCode sets the "processCode" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableProcessCode(v *int) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetProcessCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddProcessCode adds value to the "processCode" field.
|
|
func (_u *WorkpieceBindUpdateOne) AddProcessCode(v int) *WorkpieceBindUpdateOne {
|
|
_u.mutation.AddProcessCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetStationNo sets the "stationNo" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetStationNo(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetStationNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableStationNo(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetStationNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetMaterialCode(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetMaterialCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialCode sets the "materialCode" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableMaterialCode(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetMaterialName(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetMaterialName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableMaterialName(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetSpec(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetSpec(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableSpec(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetSpec(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetUnit(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetUnit(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableUnit(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetUnit(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manageMode" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetManageMode(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manageMode" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableManageMode(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetManageMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBindValue sets the "bindValue" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetBindValue(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetBindValue(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBindValue sets the "bindValue" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableBindValue(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetBindValue(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetBindType sets the "bindType" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetBindType(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetBindType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableBindType sets the "bindType" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableBindType(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetBindType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_u *WorkpieceBindUpdateOne) SetOperator(v string) *WorkpieceBindUpdateOne {
|
|
_u.mutation.SetOperator(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_u *WorkpieceBindUpdateOne) SetNillableOperator(v *string) *WorkpieceBindUpdateOne {
|
|
if v != nil {
|
|
_u.SetOperator(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the WorkpieceBindMutation object of the builder.
|
|
func (_u *WorkpieceBindUpdateOne) Mutation() *WorkpieceBindMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the WorkpieceBindUpdate builder.
|
|
func (_u *WorkpieceBindUpdateOne) Where(ps ...predicate.WorkpieceBind) *WorkpieceBindUpdateOne {
|
|
_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 *WorkpieceBindUpdateOne) Select(field string, fields ...string) *WorkpieceBindUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated WorkpieceBind entity.
|
|
func (_u *WorkpieceBindUpdateOne) Save(ctx context.Context) (*WorkpieceBind, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *WorkpieceBindUpdateOne) SaveX(ctx context.Context) *WorkpieceBind {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *WorkpieceBindUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *WorkpieceBindUpdateOne) ExecX(ctx context.Context) {
|
|
if err := _u.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *WorkpieceBindUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Sn(); ok {
|
|
if err := workpiecebind.SnValidator(v); err != nil {
|
|
return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.sn": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.OrderNo(); ok {
|
|
if err := workpiecebind.OrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.orderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.StationNo(); ok {
|
|
if err := workpiecebind.StationNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "stationNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.stationNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialCode(); ok {
|
|
if err := workpiecebind.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialName(); ok {
|
|
if err := workpiecebind.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Spec(); ok {
|
|
if err := workpiecebind.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.spec": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Unit(); ok {
|
|
if err := workpiecebind.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.unit": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ManageMode(); ok {
|
|
if err := workpiecebind.ManageModeValidator(v); err != nil {
|
|
return &ValidationError{Name: "manageMode", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.manageMode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.BindValue(); ok {
|
|
if err := workpiecebind.BindValueValidator(v); err != nil {
|
|
return &ValidationError{Name: "bindValue", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.bindValue": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.BindType(); ok {
|
|
if err := workpiecebind.BindTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "bindType", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.bindType": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Operator(); ok {
|
|
if err := workpiecebind.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "WorkpieceBind.operator": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *WorkpieceBindUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WorkpieceBindUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *WorkpieceBindUpdateOne) sqlSave(ctx context.Context) (_node *WorkpieceBind, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(workpiecebind.Table, workpiecebind.Columns, sqlgraph.NewFieldSpec(workpiecebind.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WorkpieceBind.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, workpiecebind.FieldID)
|
|
for _, f := range fields {
|
|
if !workpiecebind.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != workpiecebind.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(workpiecebind.FieldSn, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.OrderNo(); ok {
|
|
_spec.SetField(workpiecebind.FieldOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ProcessCode(); ok {
|
|
_spec.SetField(workpiecebind.FieldProcessCode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedProcessCode(); ok {
|
|
_spec.AddField(workpiecebind.FieldProcessCode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.StationNo(); ok {
|
|
_spec.SetField(workpiecebind.FieldStationNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialCode(); ok {
|
|
_spec.SetField(workpiecebind.FieldMaterialCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialName(); ok {
|
|
_spec.SetField(workpiecebind.FieldMaterialName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(workpiecebind.FieldSpec, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(workpiecebind.FieldUnit, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ManageMode(); ok {
|
|
_spec.SetField(workpiecebind.FieldManageMode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.BindValue(); ok {
|
|
_spec.SetField(workpiecebind.FieldBindValue, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.BindType(); ok {
|
|
_spec.SetField(workpiecebind.FieldBindType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Operator(); ok {
|
|
_spec.SetField(workpiecebind.FieldOperator, field.TypeString, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &WorkpieceBind{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{workpiecebind.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|