- MES(B): 工单/BOM/备料/工序字典/PLC下发/拧紧/扫码报工/半成品/AGV/追溯逻辑,WMS与海康RCS客户端,看板Redis缓存API(概览/设备/进度/报警/趋势)+SSE - WMS(C): JWT滑动续签、Excel导入、盘点、内部API、种子数据、独立Postgres配置 - WMS客户端(E): Go网关8891反向代理+内嵌Vue3十页 - 工位终端(D): SQLite本地缓存+模拟拧紧源+内嵌Vue3页面 - Dashboard(A): 看板数据改接MES内部缓存API,SSE实时刷新+vite代理 - 清理各项目球形磨遗留代码,新增部署手册.md
768 lines
22 KiB
Go
768 lines
22 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/material"
|
|
"bj_power_wms/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// SetShortName sets the "short_name" field.
|
|
func (_u *MaterialUpdate) SetShortName(v string) *MaterialUpdate {
|
|
_u.mutation.SetShortName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableShortName sets the "short_name" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableShortName(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetShortName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearShortName clears the value of the "short_name" field.
|
|
func (_u *MaterialUpdate) ClearShortName() *MaterialUpdate {
|
|
_u.mutation.ClearShortName()
|
|
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
|
|
}
|
|
|
|
// ClearSpec clears the value of the "spec" field.
|
|
func (_u *MaterialUpdate) ClearSpec() *MaterialUpdate {
|
|
_u.mutation.ClearSpec()
|
|
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
|
|
}
|
|
|
|
// ClearUnit clears the value of the "unit" field.
|
|
func (_u *MaterialUpdate) ClearUnit() *MaterialUpdate {
|
|
_u.mutation.ClearUnit()
|
|
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
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *MaterialUpdate) ClearDescription() *MaterialUpdate {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manage_mode" field.
|
|
func (_u *MaterialUpdate) SetManageMode(v int) *MaterialUpdate {
|
|
_u.mutation.ResetManageMode()
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manage_mode" 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 "manage_mode" field.
|
|
func (_u *MaterialUpdate) AddManageMode(v int) *MaterialUpdate {
|
|
_u.mutation.AddManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetIsBatchManaged sets the "is_batch_managed" field.
|
|
func (_u *MaterialUpdate) SetIsBatchManaged(v bool) *MaterialUpdate {
|
|
_u.mutation.SetIsBatchManaged(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsBatchManaged sets the "is_batch_managed" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableIsBatchManaged(v *bool) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetIsBatchManaged(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetIsSerialManaged sets the "is_serial_managed" field.
|
|
func (_u *MaterialUpdate) SetIsSerialManaged(v bool) *MaterialUpdate {
|
|
_u.mutation.SetIsSerialManaged(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsSerialManaged sets the "is_serial_managed" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableIsSerialManaged(v *bool) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetIsSerialManaged(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialType sets the "material_type" field.
|
|
func (_u *MaterialUpdate) SetMaterialType(v string) *MaterialUpdate {
|
|
_u.mutation.SetMaterialType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialType sets the "material_type" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableMaterialType(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTemplateCode sets the "template_code" field.
|
|
func (_u *MaterialUpdate) SetTemplateCode(v string) *MaterialUpdate {
|
|
_u.mutation.SetTemplateCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTemplateCode sets the "template_code" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableTemplateCode(v *string) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetTemplateCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTemplateCode clears the value of the "template_code" field.
|
|
func (_u *MaterialUpdate) ClearTemplateCode() *MaterialUpdate {
|
|
_u.mutation.ClearTemplateCode()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *MaterialUpdate) SetCreatedAt(v int64) *MaterialUpdate {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableCreatedAt(v *int64) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *MaterialUpdate) AddCreatedAt(v int64) *MaterialUpdate {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *MaterialUpdate) SetUpdatedAt(v int64) *MaterialUpdate {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *MaterialUpdate) SetNillableUpdatedAt(v *int64) *MaterialUpdate {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *MaterialUpdate) AddUpdatedAt(v int64) *MaterialUpdate {
|
|
_u.mutation.AddUpdatedAt(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) {
|
|
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)
|
|
}
|
|
}
|
|
|
|
func (_u *MaterialUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
_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.ShortName(); ok {
|
|
_spec.SetField(material.FieldShortName, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ShortNameCleared() {
|
|
_spec.ClearField(material.FieldShortName, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(material.FieldSpec, field.TypeString, value)
|
|
}
|
|
if _u.mutation.SpecCleared() {
|
|
_spec.ClearField(material.FieldSpec, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(material.FieldUnit, field.TypeString, value)
|
|
}
|
|
if _u.mutation.UnitCleared() {
|
|
_spec.ClearField(material.FieldUnit, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(material.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(material.FieldDescription, field.TypeString)
|
|
}
|
|
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.IsBatchManaged(); ok {
|
|
_spec.SetField(material.FieldIsBatchManaged, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.IsSerialManaged(); ok {
|
|
_spec.SetField(material.FieldIsSerialManaged, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialType(); ok {
|
|
_spec.SetField(material.FieldMaterialType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.TemplateCode(); ok {
|
|
_spec.SetField(material.FieldTemplateCode, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TemplateCodeCleared() {
|
|
_spec.ClearField(material.FieldTemplateCode, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(material.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(material.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(material.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(material.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// SetShortName sets the "short_name" field.
|
|
func (_u *MaterialUpdateOne) SetShortName(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetShortName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableShortName sets the "short_name" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableShortName(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetShortName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearShortName clears the value of the "short_name" field.
|
|
func (_u *MaterialUpdateOne) ClearShortName() *MaterialUpdateOne {
|
|
_u.mutation.ClearShortName()
|
|
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
|
|
}
|
|
|
|
// ClearSpec clears the value of the "spec" field.
|
|
func (_u *MaterialUpdateOne) ClearSpec() *MaterialUpdateOne {
|
|
_u.mutation.ClearSpec()
|
|
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
|
|
}
|
|
|
|
// ClearUnit clears the value of the "unit" field.
|
|
func (_u *MaterialUpdateOne) ClearUnit() *MaterialUpdateOne {
|
|
_u.mutation.ClearUnit()
|
|
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
|
|
}
|
|
|
|
// ClearDescription clears the value of the "description" field.
|
|
func (_u *MaterialUpdateOne) ClearDescription() *MaterialUpdateOne {
|
|
_u.mutation.ClearDescription()
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manage_mode" field.
|
|
func (_u *MaterialUpdateOne) SetManageMode(v int) *MaterialUpdateOne {
|
|
_u.mutation.ResetManageMode()
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manage_mode" 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 "manage_mode" field.
|
|
func (_u *MaterialUpdateOne) AddManageMode(v int) *MaterialUpdateOne {
|
|
_u.mutation.AddManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetIsBatchManaged sets the "is_batch_managed" field.
|
|
func (_u *MaterialUpdateOne) SetIsBatchManaged(v bool) *MaterialUpdateOne {
|
|
_u.mutation.SetIsBatchManaged(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsBatchManaged sets the "is_batch_managed" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableIsBatchManaged(v *bool) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetIsBatchManaged(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetIsSerialManaged sets the "is_serial_managed" field.
|
|
func (_u *MaterialUpdateOne) SetIsSerialManaged(v bool) *MaterialUpdateOne {
|
|
_u.mutation.SetIsSerialManaged(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableIsSerialManaged sets the "is_serial_managed" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableIsSerialManaged(v *bool) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetIsSerialManaged(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialType sets the "material_type" field.
|
|
func (_u *MaterialUpdateOne) SetMaterialType(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetMaterialType(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialType sets the "material_type" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableMaterialType(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialType(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTemplateCode sets the "template_code" field.
|
|
func (_u *MaterialUpdateOne) SetTemplateCode(v string) *MaterialUpdateOne {
|
|
_u.mutation.SetTemplateCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTemplateCode sets the "template_code" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableTemplateCode(v *string) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetTemplateCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTemplateCode clears the value of the "template_code" field.
|
|
func (_u *MaterialUpdateOne) ClearTemplateCode() *MaterialUpdateOne {
|
|
_u.mutation.ClearTemplateCode()
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *MaterialUpdateOne) SetCreatedAt(v int64) *MaterialUpdateOne {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableCreatedAt(v *int64) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *MaterialUpdateOne) AddCreatedAt(v int64) *MaterialUpdateOne {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *MaterialUpdateOne) SetUpdatedAt(v int64) *MaterialUpdateOne {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *MaterialUpdateOne) SetNillableUpdatedAt(v *int64) *MaterialUpdateOne {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *MaterialUpdateOne) AddUpdatedAt(v int64) *MaterialUpdateOne {
|
|
_u.mutation.AddUpdatedAt(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) {
|
|
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)
|
|
}
|
|
}
|
|
|
|
func (_u *MaterialUpdateOne) sqlSave(ctx context.Context) (_node *Material, err error) {
|
|
_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.ShortName(); ok {
|
|
_spec.SetField(material.FieldShortName, field.TypeString, value)
|
|
}
|
|
if _u.mutation.ShortNameCleared() {
|
|
_spec.ClearField(material.FieldShortName, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(material.FieldSpec, field.TypeString, value)
|
|
}
|
|
if _u.mutation.SpecCleared() {
|
|
_spec.ClearField(material.FieldSpec, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(material.FieldUnit, field.TypeString, value)
|
|
}
|
|
if _u.mutation.UnitCleared() {
|
|
_spec.ClearField(material.FieldUnit, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Description(); ok {
|
|
_spec.SetField(material.FieldDescription, field.TypeString, value)
|
|
}
|
|
if _u.mutation.DescriptionCleared() {
|
|
_spec.ClearField(material.FieldDescription, field.TypeString)
|
|
}
|
|
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.IsBatchManaged(); ok {
|
|
_spec.SetField(material.FieldIsBatchManaged, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.IsSerialManaged(); ok {
|
|
_spec.SetField(material.FieldIsSerialManaged, field.TypeBool, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialType(); ok {
|
|
_spec.SetField(material.FieldMaterialType, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.TemplateCode(); ok {
|
|
_spec.SetField(material.FieldTemplateCode, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TemplateCodeCleared() {
|
|
_spec.ClearField(material.FieldTemplateCode, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(material.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(material.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(material.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(material.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
_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
|
|
}
|