1. 通用优化: - 统一系统标题为"库房客户端"/"MES产线控制",移除北自所前缀 - 调整内置账号密码为统一123456,优化密码校验逻辑 - 新增数据库自动创建逻辑,简化部署流程 - 修复日志时间格式配置,优化日志输出 - 新增纯数字密码安全提示 2. MES系统优化: - 新增日排产管理功能,支持增删改查与自动算料生成备料单 - 重构BOM模块,改为按产品编码维护而非工单维度 - 新增工艺参数模板配置与手动报工页面 - 新增产品类型自动编码功能 - 优化菜单结构,调整工单管理、扫码报工等页面名称与路由 - 新增删除日排产接口与权限保护 - 修复物料清单查询逻辑,适配新BOM结构 - 新增refreshToken支持,优化登录会话管理 3. WMS系统优化: - 新增基础数据维护页面,支持区域与物料档案管理 - 新增工单列表下拉接口,对接MES获取未完成工单优先展示 - 优化入库管理提示文案,替换英文提示为中文 - 修复精密件入库校验逻辑,优化错误提示 - 优化Excel导入功能,新增备注字段支持 - 优化登录页面与菜单文案,统一备料台账名称 - 新增自动打开浏览器功能,优化客户端启动体验 - 修复备料出库页面查询提示文案 - 新增WMS与MES对接配置,完善内部API调用逻辑 4. 其他优化: - 删除冗余的旧版静态资源文件,更新资源引用路径 - 新增帮助文档,完善基础数据模块说明 - 修复多处文案不统一、英文残留问题
693 lines
21 KiB
Go
693 lines
21 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/bomitem"
|
|
"bj_power_mes/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/dialect/sql/sqljson"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// BomItemUpdate is the builder for updating BomItem entities.
|
|
type BomItemUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *BomItemMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the BomItemUpdate builder.
|
|
func (_u *BomItemUpdate) Where(ps ...predicate.BomItem) *BomItemUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetProductCode sets the "productCode" field.
|
|
func (_u *BomItemUpdate) SetProductCode(v string) *BomItemUpdate {
|
|
_u.mutation.SetProductCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProductCode sets the "productCode" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableProductCode(v *string) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetProductCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_u *BomItemUpdate) SetMaterialCode(v string) *BomItemUpdate {
|
|
_u.mutation.SetMaterialCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialCode sets the "materialCode" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableMaterialCode(v *string) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_u *BomItemUpdate) SetMaterialName(v string) *BomItemUpdate {
|
|
_u.mutation.SetMaterialName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableMaterialName(v *string) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_u *BomItemUpdate) SetSpec(v string) *BomItemUpdate {
|
|
_u.mutation.SetSpec(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableSpec(v *string) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetSpec(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_u *BomItemUpdate) SetUnit(v string) *BomItemUpdate {
|
|
_u.mutation.SetUnit(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableUnit(v *string) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetUnit(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manageMode" field.
|
|
func (_u *BomItemUpdate) SetManageMode(v string) *BomItemUpdate {
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manageMode" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableManageMode(v *string) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetManageMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnitQty sets the "unitQty" field.
|
|
func (_u *BomItemUpdate) SetUnitQty(v float64) *BomItemUpdate {
|
|
_u.mutation.ResetUnitQty()
|
|
_u.mutation.SetUnitQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnitQty sets the "unitQty" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableUnitQty(v *float64) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetUnitQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUnitQty adds value to the "unitQty" field.
|
|
func (_u *BomItemUpdate) AddUnitQty(v float64) *BomItemUpdate {
|
|
_u.mutation.AddUnitQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetLossRate sets the "lossRate" field.
|
|
func (_u *BomItemUpdate) SetLossRate(v float64) *BomItemUpdate {
|
|
_u.mutation.ResetLossRate()
|
|
_u.mutation.SetLossRate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLossRate sets the "lossRate" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableLossRate(v *float64) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetLossRate(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddLossRate adds value to the "lossRate" field.
|
|
func (_u *BomItemUpdate) AddLossRate(v float64) *BomItemUpdate {
|
|
_u.mutation.AddLossRate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetRequiredQty sets the "requiredQty" field.
|
|
func (_u *BomItemUpdate) SetRequiredQty(v float64) *BomItemUpdate {
|
|
_u.mutation.ResetRequiredQty()
|
|
_u.mutation.SetRequiredQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRequiredQty sets the "requiredQty" field if the given value is not nil.
|
|
func (_u *BomItemUpdate) SetNillableRequiredQty(v *float64) *BomItemUpdate {
|
|
if v != nil {
|
|
_u.SetRequiredQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddRequiredQty adds value to the "requiredQty" field.
|
|
func (_u *BomItemUpdate) AddRequiredQty(v float64) *BomItemUpdate {
|
|
_u.mutation.AddRequiredQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetSerialSns sets the "serialSns" field.
|
|
func (_u *BomItemUpdate) SetSerialSns(v []string) *BomItemUpdate {
|
|
_u.mutation.SetSerialSns(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendSerialSns appends value to the "serialSns" field.
|
|
func (_u *BomItemUpdate) AppendSerialSns(v []string) *BomItemUpdate {
|
|
_u.mutation.AppendSerialSns(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearSerialSns clears the value of the "serialSns" field.
|
|
func (_u *BomItemUpdate) ClearSerialSns() *BomItemUpdate {
|
|
_u.mutation.ClearSerialSns()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the BomItemMutation object of the builder.
|
|
func (_u *BomItemUpdate) Mutation() *BomItemMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *BomItemUpdate) 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 *BomItemUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *BomItemUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *BomItemUpdate) 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 *BomItemUpdate) check() error {
|
|
if v, ok := _u.mutation.ProductCode(); ok {
|
|
if err := bomitem.ProductCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "productCode", err: fmt.Errorf(`ent: validator failed for field "BomItem.productCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialCode(); ok {
|
|
if err := bomitem.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "BomItem.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialName(); ok {
|
|
if err := bomitem.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "BomItem.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Spec(); ok {
|
|
if err := bomitem.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "BomItem.spec": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Unit(); ok {
|
|
if err := bomitem.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "BomItem.unit": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ManageMode(); ok {
|
|
if err := bomitem.ManageModeValidator(v); err != nil {
|
|
return &ValidationError{Name: "manageMode", err: fmt.Errorf(`ent: validator failed for field "BomItem.manageMode": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *BomItemUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *BomItemUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *BomItemUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(bomitem.Table, bomitem.Columns, sqlgraph.NewFieldSpec(bomitem.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.ProductCode(); ok {
|
|
_spec.SetField(bomitem.FieldProductCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialCode(); ok {
|
|
_spec.SetField(bomitem.FieldMaterialCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialName(); ok {
|
|
_spec.SetField(bomitem.FieldMaterialName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(bomitem.FieldSpec, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(bomitem.FieldUnit, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ManageMode(); ok {
|
|
_spec.SetField(bomitem.FieldManageMode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.UnitQty(); ok {
|
|
_spec.SetField(bomitem.FieldUnitQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUnitQty(); ok {
|
|
_spec.AddField(bomitem.FieldUnitQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.LossRate(); ok {
|
|
_spec.SetField(bomitem.FieldLossRate, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedLossRate(); ok {
|
|
_spec.AddField(bomitem.FieldLossRate, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.RequiredQty(); ok {
|
|
_spec.SetField(bomitem.FieldRequiredQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedRequiredQty(); ok {
|
|
_spec.AddField(bomitem.FieldRequiredQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.SerialSns(); ok {
|
|
_spec.SetField(bomitem.FieldSerialSns, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedSerialSns(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, bomitem.FieldSerialSns, value)
|
|
})
|
|
}
|
|
if _u.mutation.SerialSnsCleared() {
|
|
_spec.ClearField(bomitem.FieldSerialSns, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{bomitem.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// BomItemUpdateOne is the builder for updating a single BomItem entity.
|
|
type BomItemUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *BomItemMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetProductCode sets the "productCode" field.
|
|
func (_u *BomItemUpdateOne) SetProductCode(v string) *BomItemUpdateOne {
|
|
_u.mutation.SetProductCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableProductCode sets the "productCode" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableProductCode(v *string) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetProductCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_u *BomItemUpdateOne) SetMaterialCode(v string) *BomItemUpdateOne {
|
|
_u.mutation.SetMaterialCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialCode sets the "materialCode" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableMaterialCode(v *string) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_u *BomItemUpdateOne) SetMaterialName(v string) *BomItemUpdateOne {
|
|
_u.mutation.SetMaterialName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableMaterialName(v *string) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetSpec sets the "spec" field.
|
|
func (_u *BomItemUpdateOne) SetSpec(v string) *BomItemUpdateOne {
|
|
_u.mutation.SetSpec(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableSpec sets the "spec" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableSpec(v *string) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetSpec(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnit sets the "unit" field.
|
|
func (_u *BomItemUpdateOne) SetUnit(v string) *BomItemUpdateOne {
|
|
_u.mutation.SetUnit(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnit sets the "unit" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableUnit(v *string) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetUnit(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetManageMode sets the "manageMode" field.
|
|
func (_u *BomItemUpdateOne) SetManageMode(v string) *BomItemUpdateOne {
|
|
_u.mutation.SetManageMode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableManageMode sets the "manageMode" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableManageMode(v *string) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetManageMode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetUnitQty sets the "unitQty" field.
|
|
func (_u *BomItemUpdateOne) SetUnitQty(v float64) *BomItemUpdateOne {
|
|
_u.mutation.ResetUnitQty()
|
|
_u.mutation.SetUnitQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUnitQty sets the "unitQty" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableUnitQty(v *float64) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetUnitQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUnitQty adds value to the "unitQty" field.
|
|
func (_u *BomItemUpdateOne) AddUnitQty(v float64) *BomItemUpdateOne {
|
|
_u.mutation.AddUnitQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetLossRate sets the "lossRate" field.
|
|
func (_u *BomItemUpdateOne) SetLossRate(v float64) *BomItemUpdateOne {
|
|
_u.mutation.ResetLossRate()
|
|
_u.mutation.SetLossRate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLossRate sets the "lossRate" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableLossRate(v *float64) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetLossRate(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddLossRate adds value to the "lossRate" field.
|
|
func (_u *BomItemUpdateOne) AddLossRate(v float64) *BomItemUpdateOne {
|
|
_u.mutation.AddLossRate(v)
|
|
return _u
|
|
}
|
|
|
|
// SetRequiredQty sets the "requiredQty" field.
|
|
func (_u *BomItemUpdateOne) SetRequiredQty(v float64) *BomItemUpdateOne {
|
|
_u.mutation.ResetRequiredQty()
|
|
_u.mutation.SetRequiredQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRequiredQty sets the "requiredQty" field if the given value is not nil.
|
|
func (_u *BomItemUpdateOne) SetNillableRequiredQty(v *float64) *BomItemUpdateOne {
|
|
if v != nil {
|
|
_u.SetRequiredQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddRequiredQty adds value to the "requiredQty" field.
|
|
func (_u *BomItemUpdateOne) AddRequiredQty(v float64) *BomItemUpdateOne {
|
|
_u.mutation.AddRequiredQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetSerialSns sets the "serialSns" field.
|
|
func (_u *BomItemUpdateOne) SetSerialSns(v []string) *BomItemUpdateOne {
|
|
_u.mutation.SetSerialSns(v)
|
|
return _u
|
|
}
|
|
|
|
// AppendSerialSns appends value to the "serialSns" field.
|
|
func (_u *BomItemUpdateOne) AppendSerialSns(v []string) *BomItemUpdateOne {
|
|
_u.mutation.AppendSerialSns(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearSerialSns clears the value of the "serialSns" field.
|
|
func (_u *BomItemUpdateOne) ClearSerialSns() *BomItemUpdateOne {
|
|
_u.mutation.ClearSerialSns()
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the BomItemMutation object of the builder.
|
|
func (_u *BomItemUpdateOne) Mutation() *BomItemMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the BomItemUpdate builder.
|
|
func (_u *BomItemUpdateOne) Where(ps ...predicate.BomItem) *BomItemUpdateOne {
|
|
_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 *BomItemUpdateOne) Select(field string, fields ...string) *BomItemUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated BomItem entity.
|
|
func (_u *BomItemUpdateOne) Save(ctx context.Context) (*BomItem, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *BomItemUpdateOne) SaveX(ctx context.Context) *BomItem {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *BomItemUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *BomItemUpdateOne) 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 *BomItemUpdateOne) check() error {
|
|
if v, ok := _u.mutation.ProductCode(); ok {
|
|
if err := bomitem.ProductCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "productCode", err: fmt.Errorf(`ent: validator failed for field "BomItem.productCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialCode(); ok {
|
|
if err := bomitem.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "BomItem.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialName(); ok {
|
|
if err := bomitem.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "BomItem.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Spec(); ok {
|
|
if err := bomitem.SpecValidator(v); err != nil {
|
|
return &ValidationError{Name: "spec", err: fmt.Errorf(`ent: validator failed for field "BomItem.spec": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Unit(); ok {
|
|
if err := bomitem.UnitValidator(v); err != nil {
|
|
return &ValidationError{Name: "unit", err: fmt.Errorf(`ent: validator failed for field "BomItem.unit": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ManageMode(); ok {
|
|
if err := bomitem.ManageModeValidator(v); err != nil {
|
|
return &ValidationError{Name: "manageMode", err: fmt.Errorf(`ent: validator failed for field "BomItem.manageMode": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *BomItemUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *BomItemUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *BomItemUpdateOne) sqlSave(ctx context.Context) (_node *BomItem, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(bomitem.Table, bomitem.Columns, sqlgraph.NewFieldSpec(bomitem.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "BomItem.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, bomitem.FieldID)
|
|
for _, f := range fields {
|
|
if !bomitem.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != bomitem.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.ProductCode(); ok {
|
|
_spec.SetField(bomitem.FieldProductCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialCode(); ok {
|
|
_spec.SetField(bomitem.FieldMaterialCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialName(); ok {
|
|
_spec.SetField(bomitem.FieldMaterialName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Spec(); ok {
|
|
_spec.SetField(bomitem.FieldSpec, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Unit(); ok {
|
|
_spec.SetField(bomitem.FieldUnit, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ManageMode(); ok {
|
|
_spec.SetField(bomitem.FieldManageMode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.UnitQty(); ok {
|
|
_spec.SetField(bomitem.FieldUnitQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUnitQty(); ok {
|
|
_spec.AddField(bomitem.FieldUnitQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.LossRate(); ok {
|
|
_spec.SetField(bomitem.FieldLossRate, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedLossRate(); ok {
|
|
_spec.AddField(bomitem.FieldLossRate, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.RequiredQty(); ok {
|
|
_spec.SetField(bomitem.FieldRequiredQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedRequiredQty(); ok {
|
|
_spec.AddField(bomitem.FieldRequiredQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.SerialSns(); ok {
|
|
_spec.SetField(bomitem.FieldSerialSns, field.TypeJSON, value)
|
|
}
|
|
if value, ok := _u.mutation.AppendedSerialSns(); ok {
|
|
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
|
sqljson.Append(u, bomitem.FieldSerialSns, value)
|
|
})
|
|
}
|
|
if _u.mutation.SerialSnsCleared() {
|
|
_spec.ClearField(bomitem.FieldSerialSns, field.TypeJSON)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &BomItem{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{bomitem.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|