Files
bj_power/bj_power_wms/ent/inventory_update.go
T
SunYF 68f50ee46e refactor(wms): 合并库存表为统一inventory,重构业务逻辑
1. 合并inventory_batch与serial_number为统一inventory表,用manage_mode区分结构件批次/精密件SN
2. 移除冗余的material_type字段与相关逻辑
3. 重构库存查询、检验、入库出库等业务逻辑适配新表结构
4. 调整前端路由与菜单,拆分基础数据为区域维护和物料档案
5. 优化入库校验逻辑,避免空单问题
6. 调整Vite构建配置,关闭自动清空输出目录
7. 为各模块添加详细中文注释,统一业务术语
8. 生成并更新Ent自动代码文件
2026-09-02 08:21:11 +08:00

964 lines
28 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/inventory"
"bj_power_wms/ent/predicate"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// InventoryUpdate is the builder for updating Inventory entities.
type InventoryUpdate struct {
config
hooks []Hook
mutation *InventoryMutation
}
// Where appends a list predicates to the InventoryUpdate builder.
func (_u *InventoryUpdate) Where(ps ...predicate.Inventory) *InventoryUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetManageMode sets the "manage_mode" field.
func (_u *InventoryUpdate) SetManageMode(v int) *InventoryUpdate {
_u.mutation.ResetManageMode()
_u.mutation.SetManageMode(v)
return _u
}
// SetNillableManageMode sets the "manage_mode" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableManageMode(v *int) *InventoryUpdate {
if v != nil {
_u.SetManageMode(*v)
}
return _u
}
// AddManageMode adds value to the "manage_mode" field.
func (_u *InventoryUpdate) AddManageMode(v int) *InventoryUpdate {
_u.mutation.AddManageMode(v)
return _u
}
// SetMaterialCode sets the "material_code" field.
func (_u *InventoryUpdate) SetMaterialCode(v string) *InventoryUpdate {
_u.mutation.SetMaterialCode(v)
return _u
}
// SetNillableMaterialCode sets the "material_code" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableMaterialCode(v *string) *InventoryUpdate {
if v != nil {
_u.SetMaterialCode(*v)
}
return _u
}
// SetMaterialName sets the "material_name" field.
func (_u *InventoryUpdate) SetMaterialName(v string) *InventoryUpdate {
_u.mutation.SetMaterialName(v)
return _u
}
// SetNillableMaterialName sets the "material_name" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableMaterialName(v *string) *InventoryUpdate {
if v != nil {
_u.SetMaterialName(*v)
}
return _u
}
// ClearMaterialName clears the value of the "material_name" field.
func (_u *InventoryUpdate) ClearMaterialName() *InventoryUpdate {
_u.mutation.ClearMaterialName()
return _u
}
// SetBatchNo sets the "batch_no" field.
func (_u *InventoryUpdate) SetBatchNo(v string) *InventoryUpdate {
_u.mutation.SetBatchNo(v)
return _u
}
// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableBatchNo(v *string) *InventoryUpdate {
if v != nil {
_u.SetBatchNo(*v)
}
return _u
}
// ClearBatchNo clears the value of the "batch_no" field.
func (_u *InventoryUpdate) ClearBatchNo() *InventoryUpdate {
_u.mutation.ClearBatchNo()
return _u
}
// SetSnCode sets the "sn_code" field.
func (_u *InventoryUpdate) SetSnCode(v string) *InventoryUpdate {
_u.mutation.SetSnCode(v)
return _u
}
// SetNillableSnCode sets the "sn_code" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableSnCode(v *string) *InventoryUpdate {
if v != nil {
_u.SetSnCode(*v)
}
return _u
}
// ClearSnCode clears the value of the "sn_code" field.
func (_u *InventoryUpdate) ClearSnCode() *InventoryUpdate {
_u.mutation.ClearSnCode()
return _u
}
// SetQuantity sets the "quantity" field.
func (_u *InventoryUpdate) SetQuantity(v int) *InventoryUpdate {
_u.mutation.ResetQuantity()
_u.mutation.SetQuantity(v)
return _u
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableQuantity(v *int) *InventoryUpdate {
if v != nil {
_u.SetQuantity(*v)
}
return _u
}
// AddQuantity adds value to the "quantity" field.
func (_u *InventoryUpdate) AddQuantity(v int) *InventoryUpdate {
_u.mutation.AddQuantity(v)
return _u
}
// SetLockedQty sets the "locked_qty" field.
func (_u *InventoryUpdate) SetLockedQty(v int) *InventoryUpdate {
_u.mutation.ResetLockedQty()
_u.mutation.SetLockedQty(v)
return _u
}
// SetNillableLockedQty sets the "locked_qty" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableLockedQty(v *int) *InventoryUpdate {
if v != nil {
_u.SetLockedQty(*v)
}
return _u
}
// AddLockedQty adds value to the "locked_qty" field.
func (_u *InventoryUpdate) AddLockedQty(v int) *InventoryUpdate {
_u.mutation.AddLockedQty(v)
return _u
}
// SetQualityStatus sets the "quality_status" field.
func (_u *InventoryUpdate) SetQualityStatus(v string) *InventoryUpdate {
_u.mutation.SetQualityStatus(v)
return _u
}
// SetNillableQualityStatus sets the "quality_status" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableQualityStatus(v *string) *InventoryUpdate {
if v != nil {
_u.SetQualityStatus(*v)
}
return _u
}
// SetZoneCode sets the "zone_code" field.
func (_u *InventoryUpdate) SetZoneCode(v string) *InventoryUpdate {
_u.mutation.SetZoneCode(v)
return _u
}
// SetNillableZoneCode sets the "zone_code" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableZoneCode(v *string) *InventoryUpdate {
if v != nil {
_u.SetZoneCode(*v)
}
return _u
}
// ClearZoneCode clears the value of the "zone_code" field.
func (_u *InventoryUpdate) ClearZoneCode() *InventoryUpdate {
_u.mutation.ClearZoneCode()
return _u
}
// SetStatus sets the "status" field.
func (_u *InventoryUpdate) SetStatus(v string) *InventoryUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableStatus(v *string) *InventoryUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetProductionDate sets the "production_date" field.
func (_u *InventoryUpdate) SetProductionDate(v string) *InventoryUpdate {
_u.mutation.SetProductionDate(v)
return _u
}
// SetNillableProductionDate sets the "production_date" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableProductionDate(v *string) *InventoryUpdate {
if v != nil {
_u.SetProductionDate(*v)
}
return _u
}
// ClearProductionDate clears the value of the "production_date" field.
func (_u *InventoryUpdate) ClearProductionDate() *InventoryUpdate {
_u.mutation.ClearProductionDate()
return _u
}
// SetSupplier sets the "supplier" field.
func (_u *InventoryUpdate) SetSupplier(v string) *InventoryUpdate {
_u.mutation.SetSupplier(v)
return _u
}
// SetNillableSupplier sets the "supplier" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableSupplier(v *string) *InventoryUpdate {
if v != nil {
_u.SetSupplier(*v)
}
return _u
}
// ClearSupplier clears the value of the "supplier" field.
func (_u *InventoryUpdate) ClearSupplier() *InventoryUpdate {
_u.mutation.ClearSupplier()
return _u
}
// SetInboundNo sets the "inbound_no" field.
func (_u *InventoryUpdate) SetInboundNo(v string) *InventoryUpdate {
_u.mutation.SetInboundNo(v)
return _u
}
// SetNillableInboundNo sets the "inbound_no" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableInboundNo(v *string) *InventoryUpdate {
if v != nil {
_u.SetInboundNo(*v)
}
return _u
}
// ClearInboundNo clears the value of the "inbound_no" field.
func (_u *InventoryUpdate) ClearInboundNo() *InventoryUpdate {
_u.mutation.ClearInboundNo()
return _u
}
// SetRemark sets the "remark" field.
func (_u *InventoryUpdate) SetRemark(v string) *InventoryUpdate {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableRemark(v *string) *InventoryUpdate {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// ClearRemark clears the value of the "remark" field.
func (_u *InventoryUpdate) ClearRemark() *InventoryUpdate {
_u.mutation.ClearRemark()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *InventoryUpdate) SetCreatedAt(v int64) *InventoryUpdate {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableCreatedAt(v *int64) *InventoryUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *InventoryUpdate) AddCreatedAt(v int64) *InventoryUpdate {
_u.mutation.AddCreatedAt(v)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *InventoryUpdate) SetUpdatedAt(v int64) *InventoryUpdate {
_u.mutation.ResetUpdatedAt()
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_u *InventoryUpdate) SetNillableUpdatedAt(v *int64) *InventoryUpdate {
if v != nil {
_u.SetUpdatedAt(*v)
}
return _u
}
// AddUpdatedAt adds value to the "updated_at" field.
func (_u *InventoryUpdate) AddUpdatedAt(v int64) *InventoryUpdate {
_u.mutation.AddUpdatedAt(v)
return _u
}
// Mutation returns the InventoryMutation object of the builder.
func (_u *InventoryUpdate) Mutation() *InventoryMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *InventoryUpdate) 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 *InventoryUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *InventoryUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *InventoryUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *InventoryUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(inventory.Table, inventory.Columns, sqlgraph.NewFieldSpec(inventory.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.ManageMode(); ok {
_spec.SetField(inventory.FieldManageMode, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedManageMode(); ok {
_spec.AddField(inventory.FieldManageMode, field.TypeInt, value)
}
if value, ok := _u.mutation.MaterialCode(); ok {
_spec.SetField(inventory.FieldMaterialCode, field.TypeString, value)
}
if value, ok := _u.mutation.MaterialName(); ok {
_spec.SetField(inventory.FieldMaterialName, field.TypeString, value)
}
if _u.mutation.MaterialNameCleared() {
_spec.ClearField(inventory.FieldMaterialName, field.TypeString)
}
if value, ok := _u.mutation.BatchNo(); ok {
_spec.SetField(inventory.FieldBatchNo, field.TypeString, value)
}
if _u.mutation.BatchNoCleared() {
_spec.ClearField(inventory.FieldBatchNo, field.TypeString)
}
if value, ok := _u.mutation.SnCode(); ok {
_spec.SetField(inventory.FieldSnCode, field.TypeString, value)
}
if _u.mutation.SnCodeCleared() {
_spec.ClearField(inventory.FieldSnCode, field.TypeString)
}
if value, ok := _u.mutation.Quantity(); ok {
_spec.SetField(inventory.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedQuantity(); ok {
_spec.AddField(inventory.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.LockedQty(); ok {
_spec.SetField(inventory.FieldLockedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedLockedQty(); ok {
_spec.AddField(inventory.FieldLockedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.QualityStatus(); ok {
_spec.SetField(inventory.FieldQualityStatus, field.TypeString, value)
}
if value, ok := _u.mutation.ZoneCode(); ok {
_spec.SetField(inventory.FieldZoneCode, field.TypeString, value)
}
if _u.mutation.ZoneCodeCleared() {
_spec.ClearField(inventory.FieldZoneCode, field.TypeString)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(inventory.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.ProductionDate(); ok {
_spec.SetField(inventory.FieldProductionDate, field.TypeString, value)
}
if _u.mutation.ProductionDateCleared() {
_spec.ClearField(inventory.FieldProductionDate, field.TypeString)
}
if value, ok := _u.mutation.Supplier(); ok {
_spec.SetField(inventory.FieldSupplier, field.TypeString, value)
}
if _u.mutation.SupplierCleared() {
_spec.ClearField(inventory.FieldSupplier, field.TypeString)
}
if value, ok := _u.mutation.InboundNo(); ok {
_spec.SetField(inventory.FieldInboundNo, field.TypeString, value)
}
if _u.mutation.InboundNoCleared() {
_spec.ClearField(inventory.FieldInboundNo, field.TypeString)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(inventory.FieldRemark, field.TypeString, value)
}
if _u.mutation.RemarkCleared() {
_spec.ClearField(inventory.FieldRemark, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(inventory.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(inventory.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(inventory.FieldUpdatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
_spec.AddField(inventory.FieldUpdatedAt, field.TypeInt64, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{inventory.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// InventoryUpdateOne is the builder for updating a single Inventory entity.
type InventoryUpdateOne struct {
config
fields []string
hooks []Hook
mutation *InventoryMutation
}
// SetManageMode sets the "manage_mode" field.
func (_u *InventoryUpdateOne) SetManageMode(v int) *InventoryUpdateOne {
_u.mutation.ResetManageMode()
_u.mutation.SetManageMode(v)
return _u
}
// SetNillableManageMode sets the "manage_mode" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableManageMode(v *int) *InventoryUpdateOne {
if v != nil {
_u.SetManageMode(*v)
}
return _u
}
// AddManageMode adds value to the "manage_mode" field.
func (_u *InventoryUpdateOne) AddManageMode(v int) *InventoryUpdateOne {
_u.mutation.AddManageMode(v)
return _u
}
// SetMaterialCode sets the "material_code" field.
func (_u *InventoryUpdateOne) SetMaterialCode(v string) *InventoryUpdateOne {
_u.mutation.SetMaterialCode(v)
return _u
}
// SetNillableMaterialCode sets the "material_code" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableMaterialCode(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetMaterialCode(*v)
}
return _u
}
// SetMaterialName sets the "material_name" field.
func (_u *InventoryUpdateOne) SetMaterialName(v string) *InventoryUpdateOne {
_u.mutation.SetMaterialName(v)
return _u
}
// SetNillableMaterialName sets the "material_name" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableMaterialName(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetMaterialName(*v)
}
return _u
}
// ClearMaterialName clears the value of the "material_name" field.
func (_u *InventoryUpdateOne) ClearMaterialName() *InventoryUpdateOne {
_u.mutation.ClearMaterialName()
return _u
}
// SetBatchNo sets the "batch_no" field.
func (_u *InventoryUpdateOne) SetBatchNo(v string) *InventoryUpdateOne {
_u.mutation.SetBatchNo(v)
return _u
}
// SetNillableBatchNo sets the "batch_no" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableBatchNo(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetBatchNo(*v)
}
return _u
}
// ClearBatchNo clears the value of the "batch_no" field.
func (_u *InventoryUpdateOne) ClearBatchNo() *InventoryUpdateOne {
_u.mutation.ClearBatchNo()
return _u
}
// SetSnCode sets the "sn_code" field.
func (_u *InventoryUpdateOne) SetSnCode(v string) *InventoryUpdateOne {
_u.mutation.SetSnCode(v)
return _u
}
// SetNillableSnCode sets the "sn_code" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableSnCode(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetSnCode(*v)
}
return _u
}
// ClearSnCode clears the value of the "sn_code" field.
func (_u *InventoryUpdateOne) ClearSnCode() *InventoryUpdateOne {
_u.mutation.ClearSnCode()
return _u
}
// SetQuantity sets the "quantity" field.
func (_u *InventoryUpdateOne) SetQuantity(v int) *InventoryUpdateOne {
_u.mutation.ResetQuantity()
_u.mutation.SetQuantity(v)
return _u
}
// SetNillableQuantity sets the "quantity" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableQuantity(v *int) *InventoryUpdateOne {
if v != nil {
_u.SetQuantity(*v)
}
return _u
}
// AddQuantity adds value to the "quantity" field.
func (_u *InventoryUpdateOne) AddQuantity(v int) *InventoryUpdateOne {
_u.mutation.AddQuantity(v)
return _u
}
// SetLockedQty sets the "locked_qty" field.
func (_u *InventoryUpdateOne) SetLockedQty(v int) *InventoryUpdateOne {
_u.mutation.ResetLockedQty()
_u.mutation.SetLockedQty(v)
return _u
}
// SetNillableLockedQty sets the "locked_qty" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableLockedQty(v *int) *InventoryUpdateOne {
if v != nil {
_u.SetLockedQty(*v)
}
return _u
}
// AddLockedQty adds value to the "locked_qty" field.
func (_u *InventoryUpdateOne) AddLockedQty(v int) *InventoryUpdateOne {
_u.mutation.AddLockedQty(v)
return _u
}
// SetQualityStatus sets the "quality_status" field.
func (_u *InventoryUpdateOne) SetQualityStatus(v string) *InventoryUpdateOne {
_u.mutation.SetQualityStatus(v)
return _u
}
// SetNillableQualityStatus sets the "quality_status" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableQualityStatus(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetQualityStatus(*v)
}
return _u
}
// SetZoneCode sets the "zone_code" field.
func (_u *InventoryUpdateOne) SetZoneCode(v string) *InventoryUpdateOne {
_u.mutation.SetZoneCode(v)
return _u
}
// SetNillableZoneCode sets the "zone_code" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableZoneCode(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetZoneCode(*v)
}
return _u
}
// ClearZoneCode clears the value of the "zone_code" field.
func (_u *InventoryUpdateOne) ClearZoneCode() *InventoryUpdateOne {
_u.mutation.ClearZoneCode()
return _u
}
// SetStatus sets the "status" field.
func (_u *InventoryUpdateOne) SetStatus(v string) *InventoryUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableStatus(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetProductionDate sets the "production_date" field.
func (_u *InventoryUpdateOne) SetProductionDate(v string) *InventoryUpdateOne {
_u.mutation.SetProductionDate(v)
return _u
}
// SetNillableProductionDate sets the "production_date" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableProductionDate(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetProductionDate(*v)
}
return _u
}
// ClearProductionDate clears the value of the "production_date" field.
func (_u *InventoryUpdateOne) ClearProductionDate() *InventoryUpdateOne {
_u.mutation.ClearProductionDate()
return _u
}
// SetSupplier sets the "supplier" field.
func (_u *InventoryUpdateOne) SetSupplier(v string) *InventoryUpdateOne {
_u.mutation.SetSupplier(v)
return _u
}
// SetNillableSupplier sets the "supplier" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableSupplier(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetSupplier(*v)
}
return _u
}
// ClearSupplier clears the value of the "supplier" field.
func (_u *InventoryUpdateOne) ClearSupplier() *InventoryUpdateOne {
_u.mutation.ClearSupplier()
return _u
}
// SetInboundNo sets the "inbound_no" field.
func (_u *InventoryUpdateOne) SetInboundNo(v string) *InventoryUpdateOne {
_u.mutation.SetInboundNo(v)
return _u
}
// SetNillableInboundNo sets the "inbound_no" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableInboundNo(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetInboundNo(*v)
}
return _u
}
// ClearInboundNo clears the value of the "inbound_no" field.
func (_u *InventoryUpdateOne) ClearInboundNo() *InventoryUpdateOne {
_u.mutation.ClearInboundNo()
return _u
}
// SetRemark sets the "remark" field.
func (_u *InventoryUpdateOne) SetRemark(v string) *InventoryUpdateOne {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableRemark(v *string) *InventoryUpdateOne {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// ClearRemark clears the value of the "remark" field.
func (_u *InventoryUpdateOne) ClearRemark() *InventoryUpdateOne {
_u.mutation.ClearRemark()
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *InventoryUpdateOne) SetCreatedAt(v int64) *InventoryUpdateOne {
_u.mutation.ResetCreatedAt()
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableCreatedAt(v *int64) *InventoryUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// AddCreatedAt adds value to the "created_at" field.
func (_u *InventoryUpdateOne) AddCreatedAt(v int64) *InventoryUpdateOne {
_u.mutation.AddCreatedAt(v)
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *InventoryUpdateOne) SetUpdatedAt(v int64) *InventoryUpdateOne {
_u.mutation.ResetUpdatedAt()
_u.mutation.SetUpdatedAt(v)
return _u
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_u *InventoryUpdateOne) SetNillableUpdatedAt(v *int64) *InventoryUpdateOne {
if v != nil {
_u.SetUpdatedAt(*v)
}
return _u
}
// AddUpdatedAt adds value to the "updated_at" field.
func (_u *InventoryUpdateOne) AddUpdatedAt(v int64) *InventoryUpdateOne {
_u.mutation.AddUpdatedAt(v)
return _u
}
// Mutation returns the InventoryMutation object of the builder.
func (_u *InventoryUpdateOne) Mutation() *InventoryMutation {
return _u.mutation
}
// Where appends a list predicates to the InventoryUpdate builder.
func (_u *InventoryUpdateOne) Where(ps ...predicate.Inventory) *InventoryUpdateOne {
_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 *InventoryUpdateOne) Select(field string, fields ...string) *InventoryUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Inventory entity.
func (_u *InventoryUpdateOne) Save(ctx context.Context) (*Inventory, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *InventoryUpdateOne) SaveX(ctx context.Context) *Inventory {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *InventoryUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *InventoryUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *InventoryUpdateOne) sqlSave(ctx context.Context) (_node *Inventory, err error) {
_spec := sqlgraph.NewUpdateSpec(inventory.Table, inventory.Columns, sqlgraph.NewFieldSpec(inventory.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Inventory.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, inventory.FieldID)
for _, f := range fields {
if !inventory.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != inventory.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.ManageMode(); ok {
_spec.SetField(inventory.FieldManageMode, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedManageMode(); ok {
_spec.AddField(inventory.FieldManageMode, field.TypeInt, value)
}
if value, ok := _u.mutation.MaterialCode(); ok {
_spec.SetField(inventory.FieldMaterialCode, field.TypeString, value)
}
if value, ok := _u.mutation.MaterialName(); ok {
_spec.SetField(inventory.FieldMaterialName, field.TypeString, value)
}
if _u.mutation.MaterialNameCleared() {
_spec.ClearField(inventory.FieldMaterialName, field.TypeString)
}
if value, ok := _u.mutation.BatchNo(); ok {
_spec.SetField(inventory.FieldBatchNo, field.TypeString, value)
}
if _u.mutation.BatchNoCleared() {
_spec.ClearField(inventory.FieldBatchNo, field.TypeString)
}
if value, ok := _u.mutation.SnCode(); ok {
_spec.SetField(inventory.FieldSnCode, field.TypeString, value)
}
if _u.mutation.SnCodeCleared() {
_spec.ClearField(inventory.FieldSnCode, field.TypeString)
}
if value, ok := _u.mutation.Quantity(); ok {
_spec.SetField(inventory.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedQuantity(); ok {
_spec.AddField(inventory.FieldQuantity, field.TypeInt, value)
}
if value, ok := _u.mutation.LockedQty(); ok {
_spec.SetField(inventory.FieldLockedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedLockedQty(); ok {
_spec.AddField(inventory.FieldLockedQty, field.TypeInt, value)
}
if value, ok := _u.mutation.QualityStatus(); ok {
_spec.SetField(inventory.FieldQualityStatus, field.TypeString, value)
}
if value, ok := _u.mutation.ZoneCode(); ok {
_spec.SetField(inventory.FieldZoneCode, field.TypeString, value)
}
if _u.mutation.ZoneCodeCleared() {
_spec.ClearField(inventory.FieldZoneCode, field.TypeString)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(inventory.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.ProductionDate(); ok {
_spec.SetField(inventory.FieldProductionDate, field.TypeString, value)
}
if _u.mutation.ProductionDateCleared() {
_spec.ClearField(inventory.FieldProductionDate, field.TypeString)
}
if value, ok := _u.mutation.Supplier(); ok {
_spec.SetField(inventory.FieldSupplier, field.TypeString, value)
}
if _u.mutation.SupplierCleared() {
_spec.ClearField(inventory.FieldSupplier, field.TypeString)
}
if value, ok := _u.mutation.InboundNo(); ok {
_spec.SetField(inventory.FieldInboundNo, field.TypeString, value)
}
if _u.mutation.InboundNoCleared() {
_spec.ClearField(inventory.FieldInboundNo, field.TypeString)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(inventory.FieldRemark, field.TypeString, value)
}
if _u.mutation.RemarkCleared() {
_spec.ClearField(inventory.FieldRemark, field.TypeString)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(inventory.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedCreatedAt(); ok {
_spec.AddField(inventory.FieldCreatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(inventory.FieldUpdatedAt, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
_spec.AddField(inventory.FieldUpdatedAt, field.TypeInt64, value)
}
_node = &Inventory{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{inventory.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}