本次重构将原manage_mode字段拆分为独立的分类维度(manage_mode)和SN管理维度(sn_mode),实现全链路(MES/WMS/工位终端)的SN管理行为统一依据: 1. 新增sn_mode字段,定义1=序列号件、2=批次件、0=未选择,替代原manage_mode的SN判断逻辑 2. 移除冗余的manage_mode字段在多个实体中的使用,统一使用sn_mode决定业务行为 3. 新增工位接驳台配置,服务端固定接驳台,前端不可修改,确保AGV送达准确性 4. 优化检验记录导出,新增装配物料绑定明细,满足客户追溯需求 5. 修正前端提示文本,统一使用序列号件/批次件表述,与后端逻辑对齐
793 lines
23 KiB
Go
793 lines
23 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/material"
|
|
"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"
|
|
)
|
|
|
|
// MaterialUpdate is the builder for updating Material entities.
|
|
type MaterialUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *MaterialMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the MaterialUpdate builder.
|
|
func (_u *MaterialUpdate) Where(ps ...predicate.Material) *MaterialUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_u *MaterialUpdate) SetCode(v string) *MaterialUpdate {
|
|
_u.mutation.SetCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCode sets the "code" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableCode(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *MaterialUpdate) SetName(v string) *MaterialUpdate {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableName(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_u *MaterialUpdate) SetSpec(v string) *MaterialUpdate {
|
|
_u.mutation.SetSpec(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableSpec(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetSpec(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_u *MaterialUpdate) SetUnit(v string) *MaterialUpdate {
|
|
_u.mutation.SetUnit(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableUnit(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetUnit(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *MaterialUpdate) SetDescription(v string) *MaterialUpdate {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableDescription(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItemType sets the "itemType" field.
|
|
func (_u *MaterialUpdate) SetItemType(v int) *MaterialUpdate {
|
|
_u.mutation.ResetItemType()
|
|
_u.mutation.SetItemType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemType sets the "itemType" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableItemType(v *int) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetItemType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddItemType adds value to the "itemType" field.
|
|
func (_u *MaterialUpdate) AddItemType(v int) *MaterialUpdate {
|
|
_u.mutation.AddItemType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manageMode" field.
|
|
func (_u *MaterialUpdate) SetManageMode(v int) *MaterialUpdate {
|
|
_u.mutation.ResetManageMode()
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manageMode" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableManageMode(v *int) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetManageMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddManageMode adds value to the "manageMode" field.
|
|
func (_u *MaterialUpdate) AddManageMode(v int) *MaterialUpdate {
|
|
_u.mutation.AddManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetSnMode sets the "snMode" field.
|
|
func (_u *MaterialUpdate) SetSnMode(v int) *MaterialUpdate {
|
|
_u.mutation.ResetSnMode()
|
|
_u.mutation.SetSnMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSnMode sets the "snMode" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableSnMode(v *int) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetSnMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSnMode adds value to the "snMode" field.
|
|
func (_u *MaterialUpdate) AddSnMode(v int) *MaterialUpdate {
|
|
_u.mutation.AddSnMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetTemplateCode sets the "templateCode" field.
|
|
func (_u *MaterialUpdate) SetTemplateCode(v string) *MaterialUpdate {
|
|
_u.mutation.SetTemplateCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTemplateCode sets the "templateCode" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableTemplateCode(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetTemplateCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSafetyStock sets the "safetyStock" field.
|
|
func (_u *MaterialUpdate) SetSafetyStock(v int) *MaterialUpdate {
|
|
_u.mutation.ResetSafetyStock()
|
|
_u.mutation.SetSafetyStock(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSafetyStock sets the "safetyStock" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableSafetyStock(v *int) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetSafetyStock(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSafetyStock adds value to the "safetyStock" field.
|
|
func (_u *MaterialUpdate) AddSafetyStock(v int) *MaterialUpdate {
|
|
_u.mutation.AddSafetyStock(v)
|
|
return _u
|
|
}
|
|
|
|
// SetIsActive sets the "isActive" field.
|
|
func (_u *MaterialUpdate) SetIsActive(v bool) *MaterialUpdate {
|
|
_u.mutation.SetIsActive(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsActive sets the "isActive" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableIsActive(v *bool) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetIsActive(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSyncPending sets the "syncPending" field.
|
|
func (_u *MaterialUpdate) SetSyncPending(v bool) *MaterialUpdate {
|
|
_u.mutation.SetSyncPending(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSyncPending sets the "syncPending" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableSyncPending(v *bool) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetSyncPending(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
|
func (_u *MaterialUpdate) SetUpdatedAt(v time.Time) *MaterialUpdate {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the MaterialMutation object of the builder.
|
|
func (_u *MaterialUpdate) Mutation() *MaterialMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *MaterialUpdate) 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 *MaterialUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *MaterialUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MaterialUpdate) 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 *MaterialUpdate) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := material.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *MaterialUpdate) check() error {
|
|
if v, ok := _u.mutation.Code(); ok {
|
|
if err := material.CodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Material.code": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := material.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Material.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Spec(); ok {
|
|
if err := material.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "Material.spec": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Unit(); ok {
|
|
if err := material.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "Material.unit": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := material.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Material.description": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.TemplateCode(); ok {
|
|
if err := material.TemplateCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "templateCode", err: fmt.Errorf(`ent: validator failed for field "Material.templateCode": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *MaterialUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MaterialUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *MaterialUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(material.Table, material.Columns, sqlgraph.NewFieldSpec(material.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.Code(); ok {
|
|
_spec.SetField(material.FieldCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(material.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(material.FieldSpec, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(material.FieldUnit, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(material.FieldDescription, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ItemType(); ok {
|
|
_spec.SetField(material.FieldItemType, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedItemType(); ok {
|
|
_spec.AddField(material.FieldItemType, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.ManageMode(); ok {
|
|
_spec.SetField(material.FieldManageMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedManageMode(); ok {
|
|
_spec.AddField(material.FieldManageMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.SnMode(); ok {
|
|
_spec.SetField(material.FieldSnMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSnMode(); ok {
|
|
_spec.AddField(material.FieldSnMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.TemplateCode(); ok {
|
|
_spec.SetField(material.FieldTemplateCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.SafetyStock(); ok {
|
|
_spec.SetField(material.FieldSafetyStock, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSafetyStock(); ok {
|
|
_spec.AddField(material.FieldSafetyStock, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.IsActive(); ok {
|
|
_spec.SetField(material.FieldIsActive, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.SyncPending(); ok {
|
|
_spec.SetField(material.FieldSyncPending, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(material.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{material.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// MaterialUpdateOne is the builder for updating a single Material entity.
|
|
type MaterialUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *MaterialMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetCode sets the "code" field.
|
|
func (_u *MaterialUpdateOne) SetCode(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCode sets the "code" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableCode(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (_u *MaterialUpdateOne) SetName(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableName(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_u *MaterialUpdateOne) SetSpec(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetSpec(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableSpec(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetSpec(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_u *MaterialUpdateOne) SetUnit(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetUnit(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableUnit(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetUnit(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_u *MaterialUpdateOne) SetDescription(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetDescription(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableDescription(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetDescription(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetItemType sets the "itemType" field.
|
|
func (_u *MaterialUpdateOne) SetItemType(v int) *MaterialUpdateOne {
|
|
_u.mutation.ResetItemType()
|
|
_u.mutation.SetItemType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableItemType sets the "itemType" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableItemType(v *int) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetItemType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddItemType adds value to the "itemType" field.
|
|
func (_u *MaterialUpdateOne) AddItemType(v int) *MaterialUpdateOne {
|
|
_u.mutation.AddItemType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manageMode" field.
|
|
func (_u *MaterialUpdateOne) SetManageMode(v int) *MaterialUpdateOne {
|
|
_u.mutation.ResetManageMode()
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manageMode" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableManageMode(v *int) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetManageMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddManageMode adds value to the "manageMode" field.
|
|
func (_u *MaterialUpdateOne) AddManageMode(v int) *MaterialUpdateOne {
|
|
_u.mutation.AddManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetSnMode sets the "snMode" field.
|
|
func (_u *MaterialUpdateOne) SetSnMode(v int) *MaterialUpdateOne {
|
|
_u.mutation.ResetSnMode()
|
|
_u.mutation.SetSnMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSnMode sets the "snMode" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableSnMode(v *int) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetSnMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSnMode adds value to the "snMode" field.
|
|
func (_u *MaterialUpdateOne) AddSnMode(v int) *MaterialUpdateOne {
|
|
_u.mutation.AddSnMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetTemplateCode sets the "templateCode" field.
|
|
func (_u *MaterialUpdateOne) SetTemplateCode(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetTemplateCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTemplateCode sets the "templateCode" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableTemplateCode(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetTemplateCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSafetyStock sets the "safetyStock" field.
|
|
func (_u *MaterialUpdateOne) SetSafetyStock(v int) *MaterialUpdateOne {
|
|
_u.mutation.ResetSafetyStock()
|
|
_u.mutation.SetSafetyStock(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSafetyStock sets the "safetyStock" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableSafetyStock(v *int) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetSafetyStock(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddSafetyStock adds value to the "safetyStock" field.
|
|
func (_u *MaterialUpdateOne) AddSafetyStock(v int) *MaterialUpdateOne {
|
|
_u.mutation.AddSafetyStock(v)
|
|
return _u
|
|
}
|
|
|
|
// SetIsActive sets the "isActive" field.
|
|
func (_u *MaterialUpdateOne) SetIsActive(v bool) *MaterialUpdateOne {
|
|
_u.mutation.SetIsActive(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsActive sets the "isActive" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableIsActive(v *bool) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetIsActive(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSyncPending sets the "syncPending" field.
|
|
func (_u *MaterialUpdateOne) SetSyncPending(v bool) *MaterialUpdateOne {
|
|
_u.mutation.SetSyncPending(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSyncPending sets the "syncPending" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableSyncPending(v *bool) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetSyncPending(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updatedAt" field.
|
|
func (_u *MaterialUpdateOne) SetUpdatedAt(v time.Time) *MaterialUpdateOne {
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the MaterialMutation object of the builder.
|
|
func (_u *MaterialUpdateOne) Mutation() *MaterialMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the MaterialUpdate builder.
|
|
func (_u *MaterialUpdateOne) Where(ps ...predicate.Material) *MaterialUpdateOne {
|
|
_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 *MaterialUpdateOne) Select(field string, fields ...string) *MaterialUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Material entity.
|
|
func (_u *MaterialUpdateOne) Save(ctx context.Context) (*Material, error) {
|
|
_u.defaults()
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *MaterialUpdateOne) SaveX(ctx context.Context) *Material {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *MaterialUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *MaterialUpdateOne) 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 *MaterialUpdateOne) defaults() {
|
|
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
|
v := material.UpdateDefaultUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_u *MaterialUpdateOne) check() error {
|
|
if v, ok := _u.mutation.Code(); ok {
|
|
if err := material.CodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "code", err: fmt.Errorf(`ent: validator failed for field "Material.code": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Name(); ok {
|
|
if err := material.NameValidator(v); err != nil {
|
|
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Material.name": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Spec(); ok {
|
|
if err := material.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "Material.spec": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Unit(); ok {
|
|
if err := material.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "Material.unit": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Description(); ok {
|
|
if err := material.DescriptionValidator(v); err != nil {
|
|
return &ValidationError{Name: "description", err: fmt.Errorf(`ent: validator failed for field "Material.description": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.TemplateCode(); ok {
|
|
if err := material.TemplateCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "templateCode", err: fmt.Errorf(`ent: validator failed for field "Material.templateCode": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *MaterialUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MaterialUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *MaterialUpdateOne) sqlSave(ctx context.Context) (_node *Material, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(material.Table, material.Columns, sqlgraph.NewFieldSpec(material.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Material.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, material.FieldID)
|
|
for _, f := range fields {
|
|
if !material.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != material.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.Code(); ok {
|
|
_spec.SetField(material.FieldCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Name(); ok {
|
|
_spec.SetField(material.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(material.FieldSpec, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(material.FieldUnit, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(material.FieldDescription, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ItemType(); ok {
|
|
_spec.SetField(material.FieldItemType, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedItemType(); ok {
|
|
_spec.AddField(material.FieldItemType, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.ManageMode(); ok {
|
|
_spec.SetField(material.FieldManageMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedManageMode(); ok {
|
|
_spec.AddField(material.FieldManageMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.SnMode(); ok {
|
|
_spec.SetField(material.FieldSnMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSnMode(); ok {
|
|
_spec.AddField(material.FieldSnMode, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.TemplateCode(); ok {
|
|
_spec.SetField(material.FieldTemplateCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.SafetyStock(); ok {
|
|
_spec.SetField(material.FieldSafetyStock, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedSafetyStock(); ok {
|
|
_spec.AddField(material.FieldSafetyStock, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.IsActive(); ok {
|
|
_spec.SetField(material.FieldIsActive, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.SyncPending(); ok {
|
|
_spec.SetField(material.FieldSyncPending, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(material.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &Material{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{material.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|