AGV 调度: - 任务重构为 GO_LOAD/TRANSPORT/EMPTY_RETURN/FREE 三段链,到位即停(ARRIVED)需人工确认装卸 - 自由调度单点步进,每段强制弹"请确保路径畅通无杂物";托盘回收独立工作台 - 接驳台 PLC 传感器检测到托盘即自动卸货放行,传感器故障由人工按钮兜底(无轮询) - 车辆状态只读展示(海康3.1.7 queryAgvStatus),调度仍由 RCS 负责 物料闭环: - 补料管理(SHORTAGE):工位申请 + 主管审批调增叫料池额度,与借料/差异补发三轨并行 - 损耗台账(loss_ledger):退料实际 < 理论必填原因、后审核,工单不记损耗 - 退料强制指定左/右接驳台,WMS 库管可代工位退料 下班闭环: - 工位终端自检接驳台剩余物料后下班;库管收货 + 托盘拉走后事件驱动自动结班 - 退出登录未下班仅作安全提示(不强制拦截、不新增责任审批) 接驳台左右按操作员朝向建模(dock.side 字段),废除"奇左偶右"隐式约定; 看板标签 / seed / 迁移补丁 / 布局文档统一为中文左/右。 产线布局说明:C1 前线头 AGV 点、C15 后线尾 AGV 点、外部 O1/O2/O3 散点, 清理修订痕迹为最终态描述。
874 lines
27 KiB
Go
874 lines
27 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/lossledger"
|
|
"bj_power_mes/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// LossLedgerUpdate is the builder for updating LossLedger entities.
|
|
type LossLedgerUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *LossLedgerMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// Where appends a list predicates to the LossLedgerUpdate builder.
|
|
func (_u *LossLedgerUpdate) Where(ps ...predicate.LossLedger) *LossLedgerUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetStationNo sets the "stationNo" field.
|
|
func (_u *LossLedgerUpdate) SetStationNo(v int) *LossLedgerUpdate {
|
|
_u.mutation.ResetStationNo()
|
|
_u.mutation.SetStationNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableStationNo(v *int) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetStationNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddStationNo adds value to the "stationNo" field.
|
|
func (_u *LossLedgerUpdate) AddStationNo(v int) *LossLedgerUpdate {
|
|
_u.mutation.AddStationNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_u *LossLedgerUpdate) SetMaterialCode(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetMaterialCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialCode sets the "materialCode" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableMaterialCode(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_u *LossLedgerUpdate) SetMaterialName(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetMaterialName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableMaterialName(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetMaterialName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTheoryQty sets the "theoryQty" field.
|
|
func (_u *LossLedgerUpdate) SetTheoryQty(v float64) *LossLedgerUpdate {
|
|
_u.mutation.ResetTheoryQty()
|
|
_u.mutation.SetTheoryQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTheoryQty sets the "theoryQty" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableTheoryQty(v *float64) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetTheoryQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddTheoryQty adds value to the "theoryQty" field.
|
|
func (_u *LossLedgerUpdate) AddTheoryQty(v float64) *LossLedgerUpdate {
|
|
_u.mutation.AddTheoryQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetActualQty sets the "actualQty" field.
|
|
func (_u *LossLedgerUpdate) SetActualQty(v float64) *LossLedgerUpdate {
|
|
_u.mutation.ResetActualQty()
|
|
_u.mutation.SetActualQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActualQty sets the "actualQty" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableActualQty(v *float64) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetActualQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddActualQty adds value to the "actualQty" field.
|
|
func (_u *LossLedgerUpdate) AddActualQty(v float64) *LossLedgerUpdate {
|
|
_u.mutation.AddActualQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetLossQty sets the "lossQty" field.
|
|
func (_u *LossLedgerUpdate) SetLossQty(v float64) *LossLedgerUpdate {
|
|
_u.mutation.ResetLossQty()
|
|
_u.mutation.SetLossQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLossQty sets the "lossQty" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableLossQty(v *float64) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetLossQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddLossQty adds value to the "lossQty" field.
|
|
func (_u *LossLedgerUpdate) AddLossQty(v float64) *LossLedgerUpdate {
|
|
_u.mutation.AddLossQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (_u *LossLedgerUpdate) SetReason(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetReason(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableReason sets the "reason" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableReason(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetReason(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetReturnNo sets the "returnNo" field.
|
|
func (_u *LossLedgerUpdate) SetReturnNo(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetReturnNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableReturnNo sets the "returnNo" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableReturnNo(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetReturnNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWorkOrderNo sets the "workOrderNo" field.
|
|
func (_u *LossLedgerUpdate) SetWorkOrderNo(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetWorkOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableWorkOrderNo(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetWorkOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *LossLedgerUpdate) SetStatus(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableStatus(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetComment sets the "comment" field.
|
|
func (_u *LossLedgerUpdate) SetComment(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetComment(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableComment sets the "comment" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableComment(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetComment(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCommenter sets the "commenter" field.
|
|
func (_u *LossLedgerUpdate) SetCommenter(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetCommenter(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommenter sets the "commenter" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableCommenter(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetCommenter(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCommentedAt sets the "commentedAt" field.
|
|
func (_u *LossLedgerUpdate) SetCommentedAt(v int64) *LossLedgerUpdate {
|
|
_u.mutation.ResetCommentedAt()
|
|
_u.mutation.SetCommentedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommentedAt sets the "commentedAt" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableCommentedAt(v *int64) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetCommentedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCommentedAt adds value to the "commentedAt" field.
|
|
func (_u *LossLedgerUpdate) AddCommentedAt(v int64) *LossLedgerUpdate {
|
|
_u.mutation.AddCommentedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_u *LossLedgerUpdate) SetOperator(v string) *LossLedgerUpdate {
|
|
_u.mutation.SetOperator(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdate) SetNillableOperator(v *string) *LossLedgerUpdate {
|
|
if v != nil {
|
|
_u.SetOperator(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the LossLedgerMutation object of the builder.
|
|
func (_u *LossLedgerUpdate) Mutation() *LossLedgerMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *LossLedgerUpdate) 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 *LossLedgerUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *LossLedgerUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *LossLedgerUpdate) 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 *LossLedgerUpdate) check() error {
|
|
if v, ok := _u.mutation.MaterialCode(); ok {
|
|
if err := lossledger.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "LossLedger.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialName(); ok {
|
|
if err := lossledger.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "LossLedger.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Reason(); ok {
|
|
if err := lossledger.ReasonValidator(v); err != nil {
|
|
return &ValidationError{Name: "reason", err: fmt.Errorf(`ent: validator failed for field "LossLedger.reason": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ReturnNo(); ok {
|
|
if err := lossledger.ReturnNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "returnNo", err: fmt.Errorf(`ent: validator failed for field "LossLedger.returnNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.WorkOrderNo(); ok {
|
|
if err := lossledger.WorkOrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "LossLedger.workOrderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := lossledger.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "LossLedger.status": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Comment(); ok {
|
|
if err := lossledger.CommentValidator(v); err != nil {
|
|
return &ValidationError{Name: "comment", err: fmt.Errorf(`ent: validator failed for field "LossLedger.comment": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Commenter(); ok {
|
|
if err := lossledger.CommenterValidator(v); err != nil {
|
|
return &ValidationError{Name: "commenter", err: fmt.Errorf(`ent: validator failed for field "LossLedger.commenter": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Operator(); ok {
|
|
if err := lossledger.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "LossLedger.operator": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *LossLedgerUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *LossLedgerUpdate {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *LossLedgerUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(lossledger.Table, lossledger.Columns, sqlgraph.NewFieldSpec(lossledger.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.StationNo(); ok {
|
|
_spec.SetField(lossledger.FieldStationNo, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedStationNo(); ok {
|
|
_spec.AddField(lossledger.FieldStationNo, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialCode(); ok {
|
|
_spec.SetField(lossledger.FieldMaterialCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialName(); ok {
|
|
_spec.SetField(lossledger.FieldMaterialName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.TheoryQty(); ok {
|
|
_spec.SetField(lossledger.FieldTheoryQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedTheoryQty(); ok {
|
|
_spec.AddField(lossledger.FieldTheoryQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.ActualQty(); ok {
|
|
_spec.SetField(lossledger.FieldActualQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedActualQty(); ok {
|
|
_spec.AddField(lossledger.FieldActualQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.LossQty(); ok {
|
|
_spec.SetField(lossledger.FieldLossQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedLossQty(); ok {
|
|
_spec.AddField(lossledger.FieldLossQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.Reason(); ok {
|
|
_spec.SetField(lossledger.FieldReason, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ReturnNo(); ok {
|
|
_spec.SetField(lossledger.FieldReturnNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WorkOrderNo(); ok {
|
|
_spec.SetField(lossledger.FieldWorkOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(lossledger.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Comment(); ok {
|
|
_spec.SetField(lossledger.FieldComment, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Commenter(); ok {
|
|
_spec.SetField(lossledger.FieldCommenter, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CommentedAt(); ok {
|
|
_spec.SetField(lossledger.FieldCommentedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCommentedAt(); ok {
|
|
_spec.AddField(lossledger.FieldCommentedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.Operator(); ok {
|
|
_spec.SetField(lossledger.FieldOperator, field.TypeString, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{lossledger.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// LossLedgerUpdateOne is the builder for updating a single LossLedger entity.
|
|
type LossLedgerUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *LossLedgerMutation
|
|
modifiers []func(*sql.UpdateBuilder)
|
|
}
|
|
|
|
// SetStationNo sets the "stationNo" field.
|
|
func (_u *LossLedgerUpdateOne) SetStationNo(v int) *LossLedgerUpdateOne {
|
|
_u.mutation.ResetStationNo()
|
|
_u.mutation.SetStationNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableStationNo(v *int) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetStationNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddStationNo adds value to the "stationNo" field.
|
|
func (_u *LossLedgerUpdateOne) AddStationNo(v int) *LossLedgerUpdateOne {
|
|
_u.mutation.AddStationNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialCode sets the "materialCode" field.
|
|
func (_u *LossLedgerUpdateOne) SetMaterialCode(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetMaterialCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialCode sets the "materialCode" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableMaterialCode(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetMaterialName sets the "materialName" field.
|
|
func (_u *LossLedgerUpdateOne) SetMaterialName(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetMaterialName(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableMaterialName sets the "materialName" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableMaterialName(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetMaterialName(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTheoryQty sets the "theoryQty" field.
|
|
func (_u *LossLedgerUpdateOne) SetTheoryQty(v float64) *LossLedgerUpdateOne {
|
|
_u.mutation.ResetTheoryQty()
|
|
_u.mutation.SetTheoryQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTheoryQty sets the "theoryQty" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableTheoryQty(v *float64) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetTheoryQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddTheoryQty adds value to the "theoryQty" field.
|
|
func (_u *LossLedgerUpdateOne) AddTheoryQty(v float64) *LossLedgerUpdateOne {
|
|
_u.mutation.AddTheoryQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetActualQty sets the "actualQty" field.
|
|
func (_u *LossLedgerUpdateOne) SetActualQty(v float64) *LossLedgerUpdateOne {
|
|
_u.mutation.ResetActualQty()
|
|
_u.mutation.SetActualQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableActualQty sets the "actualQty" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableActualQty(v *float64) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetActualQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddActualQty adds value to the "actualQty" field.
|
|
func (_u *LossLedgerUpdateOne) AddActualQty(v float64) *LossLedgerUpdateOne {
|
|
_u.mutation.AddActualQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetLossQty sets the "lossQty" field.
|
|
func (_u *LossLedgerUpdateOne) SetLossQty(v float64) *LossLedgerUpdateOne {
|
|
_u.mutation.ResetLossQty()
|
|
_u.mutation.SetLossQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLossQty sets the "lossQty" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableLossQty(v *float64) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetLossQty(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddLossQty adds value to the "lossQty" field.
|
|
func (_u *LossLedgerUpdateOne) AddLossQty(v float64) *LossLedgerUpdateOne {
|
|
_u.mutation.AddLossQty(v)
|
|
return _u
|
|
}
|
|
|
|
// SetReason sets the "reason" field.
|
|
func (_u *LossLedgerUpdateOne) SetReason(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetReason(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableReason sets the "reason" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableReason(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetReason(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetReturnNo sets the "returnNo" field.
|
|
func (_u *LossLedgerUpdateOne) SetReturnNo(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetReturnNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableReturnNo sets the "returnNo" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableReturnNo(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetReturnNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetWorkOrderNo sets the "workOrderNo" field.
|
|
func (_u *LossLedgerUpdateOne) SetWorkOrderNo(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetWorkOrderNo(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableWorkOrderNo(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetWorkOrderNo(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *LossLedgerUpdateOne) SetStatus(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableStatus(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetComment sets the "comment" field.
|
|
func (_u *LossLedgerUpdateOne) SetComment(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetComment(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableComment sets the "comment" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableComment(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetComment(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCommenter sets the "commenter" field.
|
|
func (_u *LossLedgerUpdateOne) SetCommenter(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetCommenter(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommenter sets the "commenter" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableCommenter(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetCommenter(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCommentedAt sets the "commentedAt" field.
|
|
func (_u *LossLedgerUpdateOne) SetCommentedAt(v int64) *LossLedgerUpdateOne {
|
|
_u.mutation.ResetCommentedAt()
|
|
_u.mutation.SetCommentedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCommentedAt sets the "commentedAt" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableCommentedAt(v *int64) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetCommentedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCommentedAt adds value to the "commentedAt" field.
|
|
func (_u *LossLedgerUpdateOne) AddCommentedAt(v int64) *LossLedgerUpdateOne {
|
|
_u.mutation.AddCommentedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_u *LossLedgerUpdateOne) SetOperator(v string) *LossLedgerUpdateOne {
|
|
_u.mutation.SetOperator(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_u *LossLedgerUpdateOne) SetNillableOperator(v *string) *LossLedgerUpdateOne {
|
|
if v != nil {
|
|
_u.SetOperator(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the LossLedgerMutation object of the builder.
|
|
func (_u *LossLedgerUpdateOne) Mutation() *LossLedgerMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the LossLedgerUpdate builder.
|
|
func (_u *LossLedgerUpdateOne) Where(ps ...predicate.LossLedger) *LossLedgerUpdateOne {
|
|
_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 *LossLedgerUpdateOne) Select(field string, fields ...string) *LossLedgerUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated LossLedger entity.
|
|
func (_u *LossLedgerUpdateOne) Save(ctx context.Context) (*LossLedger, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *LossLedgerUpdateOne) SaveX(ctx context.Context) *LossLedger {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *LossLedgerUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *LossLedgerUpdateOne) 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 *LossLedgerUpdateOne) check() error {
|
|
if v, ok := _u.mutation.MaterialCode(); ok {
|
|
if err := lossledger.MaterialCodeValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialCode", err: fmt.Errorf(`ent: validator failed for field "LossLedger.materialCode": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.MaterialName(); ok {
|
|
if err := lossledger.MaterialNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "materialName", err: fmt.Errorf(`ent: validator failed for field "LossLedger.materialName": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Reason(); ok {
|
|
if err := lossledger.ReasonValidator(v); err != nil {
|
|
return &ValidationError{Name: "reason", err: fmt.Errorf(`ent: validator failed for field "LossLedger.reason": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.ReturnNo(); ok {
|
|
if err := lossledger.ReturnNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "returnNo", err: fmt.Errorf(`ent: validator failed for field "LossLedger.returnNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.WorkOrderNo(); ok {
|
|
if err := lossledger.WorkOrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "LossLedger.workOrderNo": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Status(); ok {
|
|
if err := lossledger.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "LossLedger.status": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Comment(); ok {
|
|
if err := lossledger.CommentValidator(v); err != nil {
|
|
return &ValidationError{Name: "comment", err: fmt.Errorf(`ent: validator failed for field "LossLedger.comment": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Commenter(); ok {
|
|
if err := lossledger.CommenterValidator(v); err != nil {
|
|
return &ValidationError{Name: "commenter", err: fmt.Errorf(`ent: validator failed for field "LossLedger.commenter": %w`, err)}
|
|
}
|
|
}
|
|
if v, ok := _u.mutation.Operator(); ok {
|
|
if err := lossledger.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "LossLedger.operator": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
|
func (_u *LossLedgerUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *LossLedgerUpdateOne {
|
|
_u.modifiers = append(_u.modifiers, modifiers...)
|
|
return _u
|
|
}
|
|
|
|
func (_u *LossLedgerUpdateOne) sqlSave(ctx context.Context) (_node *LossLedger, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(lossledger.Table, lossledger.Columns, sqlgraph.NewFieldSpec(lossledger.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "LossLedger.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, lossledger.FieldID)
|
|
for _, f := range fields {
|
|
if !lossledger.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != lossledger.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.StationNo(); ok {
|
|
_spec.SetField(lossledger.FieldStationNo, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedStationNo(); ok {
|
|
_spec.AddField(lossledger.FieldStationNo, field.TypeInt, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialCode(); ok {
|
|
_spec.SetField(lossledger.FieldMaterialCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.MaterialName(); ok {
|
|
_spec.SetField(lossledger.FieldMaterialName, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.TheoryQty(); ok {
|
|
_spec.SetField(lossledger.FieldTheoryQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedTheoryQty(); ok {
|
|
_spec.AddField(lossledger.FieldTheoryQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.ActualQty(); ok {
|
|
_spec.SetField(lossledger.FieldActualQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedActualQty(); ok {
|
|
_spec.AddField(lossledger.FieldActualQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.LossQty(); ok {
|
|
_spec.SetField(lossledger.FieldLossQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedLossQty(); ok {
|
|
_spec.AddField(lossledger.FieldLossQty, field.TypeFloat64, value)
|
|
}
|
|
if value, ok := _u.mutation.Reason(); ok {
|
|
_spec.SetField(lossledger.FieldReason, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ReturnNo(); ok {
|
|
_spec.SetField(lossledger.FieldReturnNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.WorkOrderNo(); ok {
|
|
_spec.SetField(lossledger.FieldWorkOrderNo, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(lossledger.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Comment(); ok {
|
|
_spec.SetField(lossledger.FieldComment, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Commenter(); ok {
|
|
_spec.SetField(lossledger.FieldCommenter, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CommentedAt(); ok {
|
|
_spec.SetField(lossledger.FieldCommentedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCommentedAt(); ok {
|
|
_spec.AddField(lossledger.FieldCommentedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.Operator(); ok {
|
|
_spec.SetField(lossledger.FieldOperator, field.TypeString, value)
|
|
}
|
|
_spec.AddModifiers(_u.modifiers...)
|
|
_node = &LossLedger{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{lossledger.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|