【MES · 工位终端状态感知(11-28 第十三节拍板)】 - 新增 station_terminal_state / station_terminal_event 两表:当前状态镜像 + 状态变化流水 - 在线判定走既有 SSE 长连接存活:建连/断连/30s ping 心跳,90s 无心跳判离线,零 HTTP 轮询 - 登录/退出/暂停/恢复由终端事件驱动上报;新增「终端状态」管理页(produce.terminalstate,仅超级管理员):看在线/登录/操作人/接单/下班判定/心跳,抽屉看状态流水 - 库管代退料前置条件②「工人已下班」据此判定:未登录或终端离线任一即下班 【工位终端 · 全厂统一账号(11-28 拍板)】 - 删除本地账号表与 seed,登录直连 MES 用户表;本地 SQLite 只剩操作日志+登录态,断网不能换人 - SSE 客户端携带本机固定工位号,MES 据连接存活映射该工位在线状态 【单号短号规则(11-27 拍板)】 - 叫料单 MR / 叫料包 PK / 转产退库 TR / 配送单 DL:改「前缀+YYMMDD+3位当天序号」,每天从 001 归零、超 999 进 4 位 - MR 与 TR 同列不同前缀独立计数不撞号;进程内互斥分配 + DB 唯一索引兜底;历史时间戳号一律不动 【退料闭环(11-28)】 - 退库单新增 sn_list:工位提交的待退 SN 清单落库,收货逐颗扫码核对(不按批次分组、允许跨批次混合,所属批次系统按 SN 带出,库管不必填) - 收货改大数量必须有实物依据:SN 件以精确扫描的最终清单为准(条数相等且不重复);批次件必须落到真实启用的四级库位,禁止凭空加库存 - 余量参考值口径定稿(N4):应剩余量 = 实际备料 − 已消耗 − 已退 − 已损耗 - 损耗台账取消「后审核批注」:删 status/comment/commenter/commented_at 字段,WMS 确认收货当场落账闭环,MES 台账只读 【日排产 · 两种 PENDING 区分(11-26 口径定稿)】 - daily_plan 新增 discarded 废弃标记:停用打标、新建不打标;额度只算 CONFIRMED + 未废弃 PENDING - 工单管「要干几台」、日排产管「按天从哪个工位领多少料」,两张账不合并不互倒推;排产合计可小于工单数(缺口靠借料/补料审批摆出,不自动兜底) 【其他】 - SN 查询大小写脱敏(11-27):存储原样不强制大小写,匹配 LOWER(sn)=LOWER(?),扫 ABC-0001 与 abc-0001 命中同一件 - 拧紧枪人工跳过链路:设备未连接时人工跳过上报,「拧紧跳过(设备未连接)」前缀单独列示,不写 torque_record 绝不冒充设备结果 - 单据流转提示规则表全量 35 条(MES 18 + WMS 17):常驻提示条、单号可复制;单号字段逐条对后端响应实测,取不到不显示复制按钮 - PLC 快照缓存/对账、产线清线、绩效与拧紧枪配置页同步修正 【文档】 - 新增《临时结束.md》2026-11-26 日排产/叫料/完工口径大讨论定稿(含状态专项结论与被推翻旧说法留档);问题临时.md 全量更新
688 lines
21 KiB
Go
688 lines
21 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
|
|
}
|
|
|
|
// 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.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.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
|
|
}
|
|
|
|
// 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.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.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
|
|
}
|