diff --git a/bj_power_mes/ent/client.go b/bj_power_mes/ent/client.go index c1d5196..0b68e76 100644 --- a/bj_power_mes/ent/client.go +++ b/bj_power_mes/ent/client.go @@ -44,6 +44,7 @@ import ( "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpiecebind" + "bj_power_mes/ent/workpiecelifecyclelog" "bj_power_mes/ent/workpieceprocess" "entgo.io/ent" @@ -122,6 +123,8 @@ type Client struct { Workpiece *WorkpieceClient // WorkpieceBind is the client for interacting with the WorkpieceBind builders. WorkpieceBind *WorkpieceBindClient + // WorkpieceLifecycleLog is the client for interacting with the WorkpieceLifecycleLog builders. + WorkpieceLifecycleLog *WorkpieceLifecycleLogClient // WorkpieceProcess is the client for interacting with the WorkpieceProcess builders. WorkpieceProcess *WorkpieceProcessClient } @@ -168,6 +171,7 @@ func (c *Client) init() { c.WorkOrder = NewWorkOrderClient(c.config) c.Workpiece = NewWorkpieceClient(c.config) c.WorkpieceBind = NewWorkpieceBindClient(c.config) + c.WorkpieceLifecycleLog = NewWorkpieceLifecycleLogClient(c.config) c.WorkpieceProcess = NewWorkpieceProcessClient(c.config) } @@ -259,42 +263,43 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - Alert: NewAlertClient(cfg), - AlertRule: NewAlertRuleClient(cfg), - AssociationTrace: NewAssociationTraceClient(cfg), - Attachment: NewAttachmentClient(cfg), - DailyPlan: NewDailyPlanClient(cfg), - Dock: NewDockClient(cfg), - EventLog: NewEventLogClient(cfg), - FlowMaterial: NewFlowMaterialClient(cfg), - InspectionRecord: NewInspectionRecordClient(cfg), - LinePoint: NewLinePointClient(cfg), - Material: NewMaterialClient(cfg), - MaterialQtyReport: NewMaterialQtyReportClient(cfg), - MaterialRequest: NewMaterialRequestClient(cfg), - Permission: NewPermissionClient(cfg), - PlcSendLog: NewPlcSendLogClient(cfg), - ProcessFlow: NewProcessFlowClient(cfg), - ProcessStep: NewProcessStepClient(cfg), - ProductProcess: NewProductProcessClient(cfg), - ProductProcessItem: NewProductProcessItemClient(cfg), - Role: NewRoleClient(cfg), - SemiFlow: NewSemiFlowClient(cfg), - Station: NewStationClient(cfg), - StationState: NewStationStateClient(cfg), - StepCriterion: NewStepCriterionClient(cfg), - StepData: NewStepDataClient(cfg), - StepSignRecord: NewStepSignRecordClient(cfg), - SysConfig: NewSysConfigClient(cfg), - TorqueRecord: NewTorqueRecordClient(cfg), - User: NewUserClient(cfg), - UserStation: NewUserStationClient(cfg), - WorkOrder: NewWorkOrderClient(cfg), - Workpiece: NewWorkpieceClient(cfg), - WorkpieceBind: NewWorkpieceBindClient(cfg), - WorkpieceProcess: NewWorkpieceProcessClient(cfg), + ctx: ctx, + config: cfg, + Alert: NewAlertClient(cfg), + AlertRule: NewAlertRuleClient(cfg), + AssociationTrace: NewAssociationTraceClient(cfg), + Attachment: NewAttachmentClient(cfg), + DailyPlan: NewDailyPlanClient(cfg), + Dock: NewDockClient(cfg), + EventLog: NewEventLogClient(cfg), + FlowMaterial: NewFlowMaterialClient(cfg), + InspectionRecord: NewInspectionRecordClient(cfg), + LinePoint: NewLinePointClient(cfg), + Material: NewMaterialClient(cfg), + MaterialQtyReport: NewMaterialQtyReportClient(cfg), + MaterialRequest: NewMaterialRequestClient(cfg), + Permission: NewPermissionClient(cfg), + PlcSendLog: NewPlcSendLogClient(cfg), + ProcessFlow: NewProcessFlowClient(cfg), + ProcessStep: NewProcessStepClient(cfg), + ProductProcess: NewProductProcessClient(cfg), + ProductProcessItem: NewProductProcessItemClient(cfg), + Role: NewRoleClient(cfg), + SemiFlow: NewSemiFlowClient(cfg), + Station: NewStationClient(cfg), + StationState: NewStationStateClient(cfg), + StepCriterion: NewStepCriterionClient(cfg), + StepData: NewStepDataClient(cfg), + StepSignRecord: NewStepSignRecordClient(cfg), + SysConfig: NewSysConfigClient(cfg), + TorqueRecord: NewTorqueRecordClient(cfg), + User: NewUserClient(cfg), + UserStation: NewUserStationClient(cfg), + WorkOrder: NewWorkOrderClient(cfg), + Workpiece: NewWorkpieceClient(cfg), + WorkpieceBind: NewWorkpieceBindClient(cfg), + WorkpieceLifecycleLog: NewWorkpieceLifecycleLogClient(cfg), + WorkpieceProcess: NewWorkpieceProcessClient(cfg), }, nil } @@ -312,42 +317,43 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - Alert: NewAlertClient(cfg), - AlertRule: NewAlertRuleClient(cfg), - AssociationTrace: NewAssociationTraceClient(cfg), - Attachment: NewAttachmentClient(cfg), - DailyPlan: NewDailyPlanClient(cfg), - Dock: NewDockClient(cfg), - EventLog: NewEventLogClient(cfg), - FlowMaterial: NewFlowMaterialClient(cfg), - InspectionRecord: NewInspectionRecordClient(cfg), - LinePoint: NewLinePointClient(cfg), - Material: NewMaterialClient(cfg), - MaterialQtyReport: NewMaterialQtyReportClient(cfg), - MaterialRequest: NewMaterialRequestClient(cfg), - Permission: NewPermissionClient(cfg), - PlcSendLog: NewPlcSendLogClient(cfg), - ProcessFlow: NewProcessFlowClient(cfg), - ProcessStep: NewProcessStepClient(cfg), - ProductProcess: NewProductProcessClient(cfg), - ProductProcessItem: NewProductProcessItemClient(cfg), - Role: NewRoleClient(cfg), - SemiFlow: NewSemiFlowClient(cfg), - Station: NewStationClient(cfg), - StationState: NewStationStateClient(cfg), - StepCriterion: NewStepCriterionClient(cfg), - StepData: NewStepDataClient(cfg), - StepSignRecord: NewStepSignRecordClient(cfg), - SysConfig: NewSysConfigClient(cfg), - TorqueRecord: NewTorqueRecordClient(cfg), - User: NewUserClient(cfg), - UserStation: NewUserStationClient(cfg), - WorkOrder: NewWorkOrderClient(cfg), - Workpiece: NewWorkpieceClient(cfg), - WorkpieceBind: NewWorkpieceBindClient(cfg), - WorkpieceProcess: NewWorkpieceProcessClient(cfg), + ctx: ctx, + config: cfg, + Alert: NewAlertClient(cfg), + AlertRule: NewAlertRuleClient(cfg), + AssociationTrace: NewAssociationTraceClient(cfg), + Attachment: NewAttachmentClient(cfg), + DailyPlan: NewDailyPlanClient(cfg), + Dock: NewDockClient(cfg), + EventLog: NewEventLogClient(cfg), + FlowMaterial: NewFlowMaterialClient(cfg), + InspectionRecord: NewInspectionRecordClient(cfg), + LinePoint: NewLinePointClient(cfg), + Material: NewMaterialClient(cfg), + MaterialQtyReport: NewMaterialQtyReportClient(cfg), + MaterialRequest: NewMaterialRequestClient(cfg), + Permission: NewPermissionClient(cfg), + PlcSendLog: NewPlcSendLogClient(cfg), + ProcessFlow: NewProcessFlowClient(cfg), + ProcessStep: NewProcessStepClient(cfg), + ProductProcess: NewProductProcessClient(cfg), + ProductProcessItem: NewProductProcessItemClient(cfg), + Role: NewRoleClient(cfg), + SemiFlow: NewSemiFlowClient(cfg), + Station: NewStationClient(cfg), + StationState: NewStationStateClient(cfg), + StepCriterion: NewStepCriterionClient(cfg), + StepData: NewStepDataClient(cfg), + StepSignRecord: NewStepSignRecordClient(cfg), + SysConfig: NewSysConfigClient(cfg), + TorqueRecord: NewTorqueRecordClient(cfg), + User: NewUserClient(cfg), + UserStation: NewUserStationClient(cfg), + WorkOrder: NewWorkOrderClient(cfg), + Workpiece: NewWorkpieceClient(cfg), + WorkpieceBind: NewWorkpieceBindClient(cfg), + WorkpieceLifecycleLog: NewWorkpieceLifecycleLogClient(cfg), + WorkpieceProcess: NewWorkpieceProcessClient(cfg), }, nil } @@ -383,7 +389,8 @@ func (c *Client) Use(hooks ...Hook) { c.ProcessFlow, c.ProcessStep, c.ProductProcess, c.ProductProcessItem, c.Role, c.SemiFlow, c.Station, c.StationState, c.StepCriterion, c.StepData, c.StepSignRecord, c.SysConfig, c.TorqueRecord, c.User, c.UserStation, - c.WorkOrder, c.Workpiece, c.WorkpieceBind, c.WorkpieceProcess, + c.WorkOrder, c.Workpiece, c.WorkpieceBind, c.WorkpieceLifecycleLog, + c.WorkpieceProcess, } { n.Use(hooks...) } @@ -399,7 +406,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.ProcessFlow, c.ProcessStep, c.ProductProcess, c.ProductProcessItem, c.Role, c.SemiFlow, c.Station, c.StationState, c.StepCriterion, c.StepData, c.StepSignRecord, c.SysConfig, c.TorqueRecord, c.User, c.UserStation, - c.WorkOrder, c.Workpiece, c.WorkpieceBind, c.WorkpieceProcess, + c.WorkOrder, c.Workpiece, c.WorkpieceBind, c.WorkpieceLifecycleLog, + c.WorkpieceProcess, } { n.Intercept(interceptors...) } @@ -474,6 +482,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.Workpiece.mutate(ctx, m) case *WorkpieceBindMutation: return c.WorkpieceBind.mutate(ctx, m) + case *WorkpieceLifecycleLogMutation: + return c.WorkpieceLifecycleLog.mutate(ctx, m) case *WorkpieceProcessMutation: return c.WorkpieceProcess.mutate(ctx, m) default: @@ -4870,6 +4880,139 @@ func (c *WorkpieceBindClient) mutate(ctx context.Context, m *WorkpieceBindMutati } } +// WorkpieceLifecycleLogClient is a client for the WorkpieceLifecycleLog schema. +type WorkpieceLifecycleLogClient struct { + config +} + +// NewWorkpieceLifecycleLogClient returns a client for the WorkpieceLifecycleLog from the given config. +func NewWorkpieceLifecycleLogClient(c config) *WorkpieceLifecycleLogClient { + return &WorkpieceLifecycleLogClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `workpiecelifecyclelog.Hooks(f(g(h())))`. +func (c *WorkpieceLifecycleLogClient) Use(hooks ...Hook) { + c.hooks.WorkpieceLifecycleLog = append(c.hooks.WorkpieceLifecycleLog, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `workpiecelifecyclelog.Intercept(f(g(h())))`. +func (c *WorkpieceLifecycleLogClient) Intercept(interceptors ...Interceptor) { + c.inters.WorkpieceLifecycleLog = append(c.inters.WorkpieceLifecycleLog, interceptors...) +} + +// Create returns a builder for creating a WorkpieceLifecycleLog entity. +func (c *WorkpieceLifecycleLogClient) Create() *WorkpieceLifecycleLogCreate { + mutation := newWorkpieceLifecycleLogMutation(c.config, OpCreate) + return &WorkpieceLifecycleLogCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of WorkpieceLifecycleLog entities. +func (c *WorkpieceLifecycleLogClient) CreateBulk(builders ...*WorkpieceLifecycleLogCreate) *WorkpieceLifecycleLogCreateBulk { + return &WorkpieceLifecycleLogCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *WorkpieceLifecycleLogClient) MapCreateBulk(slice any, setFunc func(*WorkpieceLifecycleLogCreate, int)) *WorkpieceLifecycleLogCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &WorkpieceLifecycleLogCreateBulk{err: fmt.Errorf("calling to WorkpieceLifecycleLogClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*WorkpieceLifecycleLogCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &WorkpieceLifecycleLogCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for WorkpieceLifecycleLog. +func (c *WorkpieceLifecycleLogClient) Update() *WorkpieceLifecycleLogUpdate { + mutation := newWorkpieceLifecycleLogMutation(c.config, OpUpdate) + return &WorkpieceLifecycleLogUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *WorkpieceLifecycleLogClient) UpdateOne(_m *WorkpieceLifecycleLog) *WorkpieceLifecycleLogUpdateOne { + mutation := newWorkpieceLifecycleLogMutation(c.config, OpUpdateOne, withWorkpieceLifecycleLog(_m)) + return &WorkpieceLifecycleLogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *WorkpieceLifecycleLogClient) UpdateOneID(id int) *WorkpieceLifecycleLogUpdateOne { + mutation := newWorkpieceLifecycleLogMutation(c.config, OpUpdateOne, withWorkpieceLifecycleLogID(id)) + return &WorkpieceLifecycleLogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for WorkpieceLifecycleLog. +func (c *WorkpieceLifecycleLogClient) Delete() *WorkpieceLifecycleLogDelete { + mutation := newWorkpieceLifecycleLogMutation(c.config, OpDelete) + return &WorkpieceLifecycleLogDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *WorkpieceLifecycleLogClient) DeleteOne(_m *WorkpieceLifecycleLog) *WorkpieceLifecycleLogDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *WorkpieceLifecycleLogClient) DeleteOneID(id int) *WorkpieceLifecycleLogDeleteOne { + builder := c.Delete().Where(workpiecelifecyclelog.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &WorkpieceLifecycleLogDeleteOne{builder} +} + +// Query returns a query builder for WorkpieceLifecycleLog. +func (c *WorkpieceLifecycleLogClient) Query() *WorkpieceLifecycleLogQuery { + return &WorkpieceLifecycleLogQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeWorkpieceLifecycleLog}, + inters: c.Interceptors(), + } +} + +// Get returns a WorkpieceLifecycleLog entity by its id. +func (c *WorkpieceLifecycleLogClient) Get(ctx context.Context, id int) (*WorkpieceLifecycleLog, error) { + return c.Query().Where(workpiecelifecyclelog.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *WorkpieceLifecycleLogClient) GetX(ctx context.Context, id int) *WorkpieceLifecycleLog { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *WorkpieceLifecycleLogClient) Hooks() []Hook { + return c.hooks.WorkpieceLifecycleLog +} + +// Interceptors returns the client interceptors. +func (c *WorkpieceLifecycleLogClient) Interceptors() []Interceptor { + return c.inters.WorkpieceLifecycleLog +} + +func (c *WorkpieceLifecycleLogClient) mutate(ctx context.Context, m *WorkpieceLifecycleLogMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&WorkpieceLifecycleLogCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&WorkpieceLifecycleLogUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&WorkpieceLifecycleLogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&WorkpieceLifecycleLogDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown WorkpieceLifecycleLog mutation op: %q", m.Op()) + } +} + // WorkpieceProcessClient is a client for the WorkpieceProcess schema. type WorkpieceProcessClient struct { config @@ -5011,7 +5154,8 @@ type ( MaterialRequest, Permission, PlcSendLog, ProcessFlow, ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, Station, StationState, StepCriterion, StepData, StepSignRecord, SysConfig, TorqueRecord, User, - UserStation, WorkOrder, Workpiece, WorkpieceBind, WorkpieceProcess []ent.Hook + UserStation, WorkOrder, Workpiece, WorkpieceBind, WorkpieceLifecycleLog, + WorkpieceProcess []ent.Hook } inters struct { Alert, AlertRule, AssociationTrace, Attachment, DailyPlan, Dock, EventLog, @@ -5019,7 +5163,7 @@ type ( MaterialRequest, Permission, PlcSendLog, ProcessFlow, ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, Station, StationState, StepCriterion, StepData, StepSignRecord, SysConfig, TorqueRecord, User, - UserStation, WorkOrder, Workpiece, WorkpieceBind, + UserStation, WorkOrder, Workpiece, WorkpieceBind, WorkpieceLifecycleLog, WorkpieceProcess []ent.Interceptor } ) diff --git a/bj_power_mes/ent/ent.go b/bj_power_mes/ent/ent.go index 31e55d0..e6bdbf7 100644 --- a/bj_power_mes/ent/ent.go +++ b/bj_power_mes/ent/ent.go @@ -36,6 +36,7 @@ import ( "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpiecebind" + "bj_power_mes/ent/workpiecelifecyclelog" "bj_power_mes/ent/workpieceprocess" "context" "errors" @@ -106,40 +107,41 @@ var ( func checkColumn(t, c string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - alert.Table: alert.ValidColumn, - alertrule.Table: alertrule.ValidColumn, - associationtrace.Table: associationtrace.ValidColumn, - attachment.Table: attachment.ValidColumn, - dailyplan.Table: dailyplan.ValidColumn, - dock.Table: dock.ValidColumn, - eventlog.Table: eventlog.ValidColumn, - flowmaterial.Table: flowmaterial.ValidColumn, - inspectionrecord.Table: inspectionrecord.ValidColumn, - linepoint.Table: linepoint.ValidColumn, - material.Table: material.ValidColumn, - materialqtyreport.Table: materialqtyreport.ValidColumn, - materialrequest.Table: materialrequest.ValidColumn, - permission.Table: permission.ValidColumn, - plcsendlog.Table: plcsendlog.ValidColumn, - processflow.Table: processflow.ValidColumn, - processstep.Table: processstep.ValidColumn, - productprocess.Table: productprocess.ValidColumn, - productprocessitem.Table: productprocessitem.ValidColumn, - role.Table: role.ValidColumn, - semiflow.Table: semiflow.ValidColumn, - station.Table: station.ValidColumn, - stationstate.Table: stationstate.ValidColumn, - stepcriterion.Table: stepcriterion.ValidColumn, - stepdata.Table: stepdata.ValidColumn, - stepsignrecord.Table: stepsignrecord.ValidColumn, - sysconfig.Table: sysconfig.ValidColumn, - torquerecord.Table: torquerecord.ValidColumn, - user.Table: user.ValidColumn, - userstation.Table: userstation.ValidColumn, - workorder.Table: workorder.ValidColumn, - workpiece.Table: workpiece.ValidColumn, - workpiecebind.Table: workpiecebind.ValidColumn, - workpieceprocess.Table: workpieceprocess.ValidColumn, + alert.Table: alert.ValidColumn, + alertrule.Table: alertrule.ValidColumn, + associationtrace.Table: associationtrace.ValidColumn, + attachment.Table: attachment.ValidColumn, + dailyplan.Table: dailyplan.ValidColumn, + dock.Table: dock.ValidColumn, + eventlog.Table: eventlog.ValidColumn, + flowmaterial.Table: flowmaterial.ValidColumn, + inspectionrecord.Table: inspectionrecord.ValidColumn, + linepoint.Table: linepoint.ValidColumn, + material.Table: material.ValidColumn, + materialqtyreport.Table: materialqtyreport.ValidColumn, + materialrequest.Table: materialrequest.ValidColumn, + permission.Table: permission.ValidColumn, + plcsendlog.Table: plcsendlog.ValidColumn, + processflow.Table: processflow.ValidColumn, + processstep.Table: processstep.ValidColumn, + productprocess.Table: productprocess.ValidColumn, + productprocessitem.Table: productprocessitem.ValidColumn, + role.Table: role.ValidColumn, + semiflow.Table: semiflow.ValidColumn, + station.Table: station.ValidColumn, + stationstate.Table: stationstate.ValidColumn, + stepcriterion.Table: stepcriterion.ValidColumn, + stepdata.Table: stepdata.ValidColumn, + stepsignrecord.Table: stepsignrecord.ValidColumn, + sysconfig.Table: sysconfig.ValidColumn, + torquerecord.Table: torquerecord.ValidColumn, + user.Table: user.ValidColumn, + userstation.Table: userstation.ValidColumn, + workorder.Table: workorder.ValidColumn, + workpiece.Table: workpiece.ValidColumn, + workpiecebind.Table: workpiecebind.ValidColumn, + workpiecelifecyclelog.Table: workpiecelifecyclelog.ValidColumn, + workpieceprocess.Table: workpieceprocess.ValidColumn, }) }) return columnCheck(t, c) diff --git a/bj_power_mes/ent/hook/hook.go b/bj_power_mes/ent/hook/hook.go index 77b25d8..3fb6082 100644 --- a/bj_power_mes/ent/hook/hook.go +++ b/bj_power_mes/ent/hook/hook.go @@ -404,6 +404,18 @@ func (f WorkpieceBindFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Valu return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WorkpieceBindMutation", m) } +// The WorkpieceLifecycleLogFunc type is an adapter to allow the use of ordinary +// function as WorkpieceLifecycleLog mutator. +type WorkpieceLifecycleLogFunc func(context.Context, *ent.WorkpieceLifecycleLogMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f WorkpieceLifecycleLogFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.WorkpieceLifecycleLogMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.WorkpieceLifecycleLogMutation", m) +} + // The WorkpieceProcessFunc type is an adapter to allow the use of ordinary // function as WorkpieceProcess mutator. type WorkpieceProcessFunc func(context.Context, *ent.WorkpieceProcessMutation) (ent.Value, error) diff --git a/bj_power_mes/ent/migrate/schema.go b/bj_power_mes/ent/migrate/schema.go index c286af3..b66a88b 100644 --- a/bj_power_mes/ent/migrate/schema.go +++ b/bj_power_mes/ent/migrate/schema.go @@ -1097,8 +1097,9 @@ var ( {Name: "sn", Type: field.TypeString, Unique: true, Size: 64, Comment: "工件唯一SN"}, {Name: "order_no", Type: field.TypeString, Size: 64, Comment: "所属工单", Default: ""}, {Name: "work_order_id", Type: field.TypeInt, Nullable: true, Comment: "工单ID"}, - {Name: "current_station_no", Type: field.TypeInt, Nullable: true, Comment: "最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条)"}, - {Name: "status", Type: field.TypeString, Size: 20, Default: "ONLINE"}, + {Name: "current_station_no", Type: field.TypeInt, Nullable: true, Comment: "业务位置:最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条)"}, + {Name: "at_station_no", Type: field.TypeInt, Nullable: true, Comment: "物理位置:工件当前实际所在工位号(0=未在工位;建档/到达即写,完工/入库清空)"}, + {Name: "status", Type: field.TypeString, Size: 20, Default: "NEW"}, {Name: "online_at", Type: field.TypeTime, Nullable: true, Comment: "进线时间"}, {Name: "done_at", Type: field.TypeTime, Nullable: true, Comment: "完工时间"}, {Name: "created_at", Type: field.TypeTime}, @@ -1124,7 +1125,7 @@ var ( { Name: "workpiece_status", Unique: false, - Columns: []*schema.Column{WorkpieceColumns[5]}, + Columns: []*schema.Column{WorkpieceColumns[6]}, }, }, } @@ -1179,6 +1180,45 @@ var ( }, }, } + // WorkpieceLifecycleLogColumns holds the columns for the "workpiece_lifecycle_log" table. + WorkpieceLifecycleLogColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "sn", Type: field.TypeString, Size: 64, Comment: "工件SN"}, + {Name: "work_order_no", Type: field.TypeString, Size: 64, Comment: "所属工单", Default: ""}, + {Name: "action", Type: field.TypeString, Size: 20, Comment: "状态动作:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED"}, + {Name: "from_status", Type: field.TypeString, Size: 20, Comment: "变更前状态", Default: ""}, + {Name: "to_status", Type: field.TypeString, Size: 20, Comment: "变更后状态", Default: ""}, + {Name: "station_no", Type: field.TypeInt, Nullable: true, Comment: "关联工位号"}, + {Name: "flow_seq", Type: field.TypeInt, Nullable: true, Comment: "工艺序号(工序顺序)"}, + {Name: "operator", Type: field.TypeString, Size: 64, Comment: "操作人", Default: ""}, + {Name: "source", Type: field.TypeString, Size: 32, Comment: "来源:workstation/mes/admin/reconcile", Default: ""}, + {Name: "remark", Type: field.TypeString, Size: 255, Comment: "备注", Default: ""}, + {Name: "created_at", Type: field.TypeTime}, + } + // WorkpieceLifecycleLogTable holds the schema information for the "workpiece_lifecycle_log" table. + WorkpieceLifecycleLogTable = &schema.Table{ + Name: "workpiece_lifecycle_log", + Comment: "工件生命周期状态流水:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED,所有状态变更点同事务写", + Columns: WorkpieceLifecycleLogColumns, + PrimaryKey: []*schema.Column{WorkpieceLifecycleLogColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "workpiecelifecyclelog_sn_created_at", + Unique: false, + Columns: []*schema.Column{WorkpieceLifecycleLogColumns[1], WorkpieceLifecycleLogColumns[11]}, + }, + { + Name: "workpiecelifecyclelog_work_order_no_created_at", + Unique: false, + Columns: []*schema.Column{WorkpieceLifecycleLogColumns[2], WorkpieceLifecycleLogColumns[11]}, + }, + { + Name: "workpiecelifecyclelog_action_created_at", + Unique: false, + Columns: []*schema.Column{WorkpieceLifecycleLogColumns[3], WorkpieceLifecycleLogColumns[11]}, + }, + }, + } // WorkpieceProcessColumns holds the columns for the "workpiece_process" table. WorkpieceProcessColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -1266,6 +1306,7 @@ var ( WorkOrderTable, WorkpieceTable, WorkpieceBindTable, + WorkpieceLifecycleLogTable, WorkpieceProcessTable, } ) @@ -1370,6 +1411,9 @@ func init() { WorkpieceBindTable.Annotation = &entsql.Annotation{ Table: "workpiece_bind", } + WorkpieceLifecycleLogTable.Annotation = &entsql.Annotation{ + Table: "workpiece_lifecycle_log", + } WorkpieceProcessTable.Annotation = &entsql.Annotation{ Table: "workpiece_process", } diff --git a/bj_power_mes/ent/mutation.go b/bj_power_mes/ent/mutation.go index 0c20792..aab30d2 100644 --- a/bj_power_mes/ent/mutation.go +++ b/bj_power_mes/ent/mutation.go @@ -37,6 +37,7 @@ import ( "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpiecebind" + "bj_power_mes/ent/workpiecelifecyclelog" "bj_power_mes/ent/workpieceprocess" "context" "errors" @@ -57,40 +58,41 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeAlert = "Alert" - TypeAlertRule = "AlertRule" - TypeAssociationTrace = "AssociationTrace" - TypeAttachment = "Attachment" - TypeDailyPlan = "DailyPlan" - TypeDock = "Dock" - TypeEventLog = "EventLog" - TypeFlowMaterial = "FlowMaterial" - TypeInspectionRecord = "InspectionRecord" - TypeLinePoint = "LinePoint" - TypeMaterial = "Material" - TypeMaterialQtyReport = "MaterialQtyReport" - TypeMaterialRequest = "MaterialRequest" - TypePermission = "Permission" - TypePlcSendLog = "PlcSendLog" - TypeProcessFlow = "ProcessFlow" - TypeProcessStep = "ProcessStep" - TypeProductProcess = "ProductProcess" - TypeProductProcessItem = "ProductProcessItem" - TypeRole = "Role" - TypeSemiFlow = "SemiFlow" - TypeStation = "Station" - TypeStationState = "StationState" - TypeStepCriterion = "StepCriterion" - TypeStepData = "StepData" - TypeStepSignRecord = "StepSignRecord" - TypeSysConfig = "SysConfig" - TypeTorqueRecord = "TorqueRecord" - TypeUser = "User" - TypeUserStation = "UserStation" - TypeWorkOrder = "WorkOrder" - TypeWorkpiece = "Workpiece" - TypeWorkpieceBind = "WorkpieceBind" - TypeWorkpieceProcess = "WorkpieceProcess" + TypeAlert = "Alert" + TypeAlertRule = "AlertRule" + TypeAssociationTrace = "AssociationTrace" + TypeAttachment = "Attachment" + TypeDailyPlan = "DailyPlan" + TypeDock = "Dock" + TypeEventLog = "EventLog" + TypeFlowMaterial = "FlowMaterial" + TypeInspectionRecord = "InspectionRecord" + TypeLinePoint = "LinePoint" + TypeMaterial = "Material" + TypeMaterialQtyReport = "MaterialQtyReport" + TypeMaterialRequest = "MaterialRequest" + TypePermission = "Permission" + TypePlcSendLog = "PlcSendLog" + TypeProcessFlow = "ProcessFlow" + TypeProcessStep = "ProcessStep" + TypeProductProcess = "ProductProcess" + TypeProductProcessItem = "ProductProcessItem" + TypeRole = "Role" + TypeSemiFlow = "SemiFlow" + TypeStation = "Station" + TypeStationState = "StationState" + TypeStepCriterion = "StepCriterion" + TypeStepData = "StepData" + TypeStepSignRecord = "StepSignRecord" + TypeSysConfig = "SysConfig" + TypeTorqueRecord = "TorqueRecord" + TypeUser = "User" + TypeUserStation = "UserStation" + TypeWorkOrder = "WorkOrder" + TypeWorkpiece = "Workpiece" + TypeWorkpieceBind = "WorkpieceBind" + TypeWorkpieceLifecycleLog = "WorkpieceLifecycleLog" + TypeWorkpieceProcess = "WorkpieceProcess" ) // AlertMutation represents an operation that mutates the Alert nodes in the graph. @@ -30197,6 +30199,8 @@ type WorkpieceMutation struct { addworkOrderId *int currentStationNo *int addcurrentStationNo *int + atStationNo *int + addatStationNo *int status *string onlineAt *time.Time doneAt *time.Time @@ -30524,6 +30528,76 @@ func (m *WorkpieceMutation) ResetCurrentStationNo() { delete(m.clearedFields, workpiece.FieldCurrentStationNo) } +// SetAtStationNo sets the "atStationNo" field. +func (m *WorkpieceMutation) SetAtStationNo(i int) { + m.atStationNo = &i + m.addatStationNo = nil +} + +// AtStationNo returns the value of the "atStationNo" field in the mutation. +func (m *WorkpieceMutation) AtStationNo() (r int, exists bool) { + v := m.atStationNo + if v == nil { + return + } + return *v, true +} + +// OldAtStationNo returns the old "atStationNo" field's value of the Workpiece entity. +// If the Workpiece object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceMutation) OldAtStationNo(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAtStationNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAtStationNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAtStationNo: %w", err) + } + return oldValue.AtStationNo, nil +} + +// AddAtStationNo adds i to the "atStationNo" field. +func (m *WorkpieceMutation) AddAtStationNo(i int) { + if m.addatStationNo != nil { + *m.addatStationNo += i + } else { + m.addatStationNo = &i + } +} + +// AddedAtStationNo returns the value that was added to the "atStationNo" field in this mutation. +func (m *WorkpieceMutation) AddedAtStationNo() (r int, exists bool) { + v := m.addatStationNo + if v == nil { + return + } + return *v, true +} + +// ClearAtStationNo clears the value of the "atStationNo" field. +func (m *WorkpieceMutation) ClearAtStationNo() { + m.atStationNo = nil + m.addatStationNo = nil + m.clearedFields[workpiece.FieldAtStationNo] = struct{}{} +} + +// AtStationNoCleared returns if the "atStationNo" field was cleared in this mutation. +func (m *WorkpieceMutation) AtStationNoCleared() bool { + _, ok := m.clearedFields[workpiece.FieldAtStationNo] + return ok +} + +// ResetAtStationNo resets all changes to the "atStationNo" field. +func (m *WorkpieceMutation) ResetAtStationNo() { + m.atStationNo = nil + m.addatStationNo = nil + delete(m.clearedFields, workpiece.FieldAtStationNo) +} + // SetStatus sets the "status" field. func (m *WorkpieceMutation) SetStatus(s string) { m.status = &s @@ -30777,7 +30851,7 @@ func (m *WorkpieceMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *WorkpieceMutation) Fields() []string { - fields := make([]string, 0, 9) + fields := make([]string, 0, 10) if m.sn != nil { fields = append(fields, workpiece.FieldSn) } @@ -30790,6 +30864,9 @@ func (m *WorkpieceMutation) Fields() []string { if m.currentStationNo != nil { fields = append(fields, workpiece.FieldCurrentStationNo) } + if m.atStationNo != nil { + fields = append(fields, workpiece.FieldAtStationNo) + } if m.status != nil { fields = append(fields, workpiece.FieldStatus) } @@ -30821,6 +30898,8 @@ func (m *WorkpieceMutation) Field(name string) (ent.Value, bool) { return m.WorkOrderId() case workpiece.FieldCurrentStationNo: return m.CurrentStationNo() + case workpiece.FieldAtStationNo: + return m.AtStationNo() case workpiece.FieldStatus: return m.Status() case workpiece.FieldOnlineAt: @@ -30848,6 +30927,8 @@ func (m *WorkpieceMutation) OldField(ctx context.Context, name string) (ent.Valu return m.OldWorkOrderId(ctx) case workpiece.FieldCurrentStationNo: return m.OldCurrentStationNo(ctx) + case workpiece.FieldAtStationNo: + return m.OldAtStationNo(ctx) case workpiece.FieldStatus: return m.OldStatus(ctx) case workpiece.FieldOnlineAt: @@ -30895,6 +30976,13 @@ func (m *WorkpieceMutation) SetField(name string, value ent.Value) error { } m.SetCurrentStationNo(v) return nil + case workpiece.FieldAtStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAtStationNo(v) + return nil case workpiece.FieldStatus: v, ok := value.(string) if !ok { @@ -30944,6 +31032,9 @@ func (m *WorkpieceMutation) AddedFields() []string { if m.addcurrentStationNo != nil { fields = append(fields, workpiece.FieldCurrentStationNo) } + if m.addatStationNo != nil { + fields = append(fields, workpiece.FieldAtStationNo) + } return fields } @@ -30956,6 +31047,8 @@ func (m *WorkpieceMutation) AddedField(name string) (ent.Value, bool) { return m.AddedWorkOrderId() case workpiece.FieldCurrentStationNo: return m.AddedCurrentStationNo() + case workpiece.FieldAtStationNo: + return m.AddedAtStationNo() } return nil, false } @@ -30979,6 +31072,13 @@ func (m *WorkpieceMutation) AddField(name string, value ent.Value) error { } m.AddCurrentStationNo(v) return nil + case workpiece.FieldAtStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddAtStationNo(v) + return nil } return fmt.Errorf("unknown Workpiece numeric field %s", name) } @@ -30993,6 +31093,9 @@ func (m *WorkpieceMutation) ClearedFields() []string { if m.FieldCleared(workpiece.FieldCurrentStationNo) { fields = append(fields, workpiece.FieldCurrentStationNo) } + if m.FieldCleared(workpiece.FieldAtStationNo) { + fields = append(fields, workpiece.FieldAtStationNo) + } if m.FieldCleared(workpiece.FieldOnlineAt) { fields = append(fields, workpiece.FieldOnlineAt) } @@ -31022,6 +31125,9 @@ func (m *WorkpieceMutation) ClearField(name string) error { case workpiece.FieldCurrentStationNo: m.ClearCurrentStationNo() return nil + case workpiece.FieldAtStationNo: + m.ClearAtStationNo() + return nil case workpiece.FieldOnlineAt: m.ClearOnlineAt() return nil @@ -31051,6 +31157,9 @@ func (m *WorkpieceMutation) ResetField(name string) error { case workpiece.FieldCurrentStationNo: m.ResetCurrentStationNo() return nil + case workpiece.FieldAtStationNo: + m.ResetAtStationNo() + return nil case workpiece.FieldStatus: m.ResetStatus() return nil @@ -32167,6 +32276,990 @@ func (m *WorkpieceBindMutation) ResetEdge(name string) error { return fmt.Errorf("unknown WorkpieceBind edge %s", name) } +// WorkpieceLifecycleLogMutation represents an operation that mutates the WorkpieceLifecycleLog nodes in the graph. +type WorkpieceLifecycleLogMutation struct { + config + op Op + typ string + id *int + sn *string + workOrderNo *string + action *string + fromStatus *string + toStatus *string + stationNo *int + addstationNo *int + flowSeq *int + addflowSeq *int + operator *string + source *string + remark *string + createdAt *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*WorkpieceLifecycleLog, error) + predicates []predicate.WorkpieceLifecycleLog +} + +var _ ent.Mutation = (*WorkpieceLifecycleLogMutation)(nil) + +// workpiecelifecyclelogOption allows management of the mutation configuration using functional options. +type workpiecelifecyclelogOption func(*WorkpieceLifecycleLogMutation) + +// newWorkpieceLifecycleLogMutation creates new mutation for the WorkpieceLifecycleLog entity. +func newWorkpieceLifecycleLogMutation(c config, op Op, opts ...workpiecelifecyclelogOption) *WorkpieceLifecycleLogMutation { + m := &WorkpieceLifecycleLogMutation{ + config: c, + op: op, + typ: TypeWorkpieceLifecycleLog, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withWorkpieceLifecycleLogID sets the ID field of the mutation. +func withWorkpieceLifecycleLogID(id int) workpiecelifecyclelogOption { + return func(m *WorkpieceLifecycleLogMutation) { + var ( + err error + once sync.Once + value *WorkpieceLifecycleLog + ) + m.oldValue = func(ctx context.Context) (*WorkpieceLifecycleLog, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().WorkpieceLifecycleLog.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withWorkpieceLifecycleLog sets the old WorkpieceLifecycleLog of the mutation. +func withWorkpieceLifecycleLog(node *WorkpieceLifecycleLog) workpiecelifecyclelogOption { + return func(m *WorkpieceLifecycleLogMutation) { + m.oldValue = func(context.Context) (*WorkpieceLifecycleLog, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m WorkpieceLifecycleLogMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m WorkpieceLifecycleLogMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of WorkpieceLifecycleLog entities. +func (m *WorkpieceLifecycleLogMutation) SetID(id int) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *WorkpieceLifecycleLogMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *WorkpieceLifecycleLogMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().WorkpieceLifecycleLog.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetSn sets the "sn" field. +func (m *WorkpieceLifecycleLogMutation) SetSn(s string) { + m.sn = &s +} + +// Sn returns the value of the "sn" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) Sn() (r string, exists bool) { + v := m.sn + if v == nil { + return + } + return *v, true +} + +// OldSn returns the old "sn" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldSn(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSn is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSn requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSn: %w", err) + } + return oldValue.Sn, nil +} + +// ResetSn resets all changes to the "sn" field. +func (m *WorkpieceLifecycleLogMutation) ResetSn() { + m.sn = nil +} + +// SetWorkOrderNo sets the "workOrderNo" field. +func (m *WorkpieceLifecycleLogMutation) SetWorkOrderNo(s string) { + m.workOrderNo = &s +} + +// WorkOrderNo returns the value of the "workOrderNo" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) WorkOrderNo() (r string, exists bool) { + v := m.workOrderNo + if v == nil { + return + } + return *v, true +} + +// OldWorkOrderNo returns the old "workOrderNo" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldWorkOrderNo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWorkOrderNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWorkOrderNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWorkOrderNo: %w", err) + } + return oldValue.WorkOrderNo, nil +} + +// ResetWorkOrderNo resets all changes to the "workOrderNo" field. +func (m *WorkpieceLifecycleLogMutation) ResetWorkOrderNo() { + m.workOrderNo = nil +} + +// SetAction sets the "action" field. +func (m *WorkpieceLifecycleLogMutation) SetAction(s string) { + m.action = &s +} + +// Action returns the value of the "action" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) Action() (r string, exists bool) { + v := m.action + if v == nil { + return + } + return *v, true +} + +// OldAction returns the old "action" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldAction(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldAction is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldAction requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldAction: %w", err) + } + return oldValue.Action, nil +} + +// ResetAction resets all changes to the "action" field. +func (m *WorkpieceLifecycleLogMutation) ResetAction() { + m.action = nil +} + +// SetFromStatus sets the "fromStatus" field. +func (m *WorkpieceLifecycleLogMutation) SetFromStatus(s string) { + m.fromStatus = &s +} + +// FromStatus returns the value of the "fromStatus" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) FromStatus() (r string, exists bool) { + v := m.fromStatus + if v == nil { + return + } + return *v, true +} + +// OldFromStatus returns the old "fromStatus" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldFromStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFromStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFromStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFromStatus: %w", err) + } + return oldValue.FromStatus, nil +} + +// ResetFromStatus resets all changes to the "fromStatus" field. +func (m *WorkpieceLifecycleLogMutation) ResetFromStatus() { + m.fromStatus = nil +} + +// SetToStatus sets the "toStatus" field. +func (m *WorkpieceLifecycleLogMutation) SetToStatus(s string) { + m.toStatus = &s +} + +// ToStatus returns the value of the "toStatus" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) ToStatus() (r string, exists bool) { + v := m.toStatus + if v == nil { + return + } + return *v, true +} + +// OldToStatus returns the old "toStatus" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldToStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldToStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldToStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldToStatus: %w", err) + } + return oldValue.ToStatus, nil +} + +// ResetToStatus resets all changes to the "toStatus" field. +func (m *WorkpieceLifecycleLogMutation) ResetToStatus() { + m.toStatus = nil +} + +// SetStationNo sets the "stationNo" field. +func (m *WorkpieceLifecycleLogMutation) SetStationNo(i int) { + m.stationNo = &i + m.addstationNo = nil +} + +// StationNo returns the value of the "stationNo" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) StationNo() (r int, exists bool) { + v := m.stationNo + if v == nil { + return + } + return *v, true +} + +// OldStationNo returns the old "stationNo" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldStationNo(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStationNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStationNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStationNo: %w", err) + } + return oldValue.StationNo, nil +} + +// AddStationNo adds i to the "stationNo" field. +func (m *WorkpieceLifecycleLogMutation) AddStationNo(i int) { + if m.addstationNo != nil { + *m.addstationNo += i + } else { + m.addstationNo = &i + } +} + +// AddedStationNo returns the value that was added to the "stationNo" field in this mutation. +func (m *WorkpieceLifecycleLogMutation) AddedStationNo() (r int, exists bool) { + v := m.addstationNo + if v == nil { + return + } + return *v, true +} + +// ClearStationNo clears the value of the "stationNo" field. +func (m *WorkpieceLifecycleLogMutation) ClearStationNo() { + m.stationNo = nil + m.addstationNo = nil + m.clearedFields[workpiecelifecyclelog.FieldStationNo] = struct{}{} +} + +// StationNoCleared returns if the "stationNo" field was cleared in this mutation. +func (m *WorkpieceLifecycleLogMutation) StationNoCleared() bool { + _, ok := m.clearedFields[workpiecelifecyclelog.FieldStationNo] + return ok +} + +// ResetStationNo resets all changes to the "stationNo" field. +func (m *WorkpieceLifecycleLogMutation) ResetStationNo() { + m.stationNo = nil + m.addstationNo = nil + delete(m.clearedFields, workpiecelifecyclelog.FieldStationNo) +} + +// SetFlowSeq sets the "flowSeq" field. +func (m *WorkpieceLifecycleLogMutation) SetFlowSeq(i int) { + m.flowSeq = &i + m.addflowSeq = nil +} + +// FlowSeq returns the value of the "flowSeq" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) FlowSeq() (r int, exists bool) { + v := m.flowSeq + if v == nil { + return + } + return *v, true +} + +// OldFlowSeq returns the old "flowSeq" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldFlowSeq(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFlowSeq is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFlowSeq requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFlowSeq: %w", err) + } + return oldValue.FlowSeq, nil +} + +// AddFlowSeq adds i to the "flowSeq" field. +func (m *WorkpieceLifecycleLogMutation) AddFlowSeq(i int) { + if m.addflowSeq != nil { + *m.addflowSeq += i + } else { + m.addflowSeq = &i + } +} + +// AddedFlowSeq returns the value that was added to the "flowSeq" field in this mutation. +func (m *WorkpieceLifecycleLogMutation) AddedFlowSeq() (r int, exists bool) { + v := m.addflowSeq + if v == nil { + return + } + return *v, true +} + +// ClearFlowSeq clears the value of the "flowSeq" field. +func (m *WorkpieceLifecycleLogMutation) ClearFlowSeq() { + m.flowSeq = nil + m.addflowSeq = nil + m.clearedFields[workpiecelifecyclelog.FieldFlowSeq] = struct{}{} +} + +// FlowSeqCleared returns if the "flowSeq" field was cleared in this mutation. +func (m *WorkpieceLifecycleLogMutation) FlowSeqCleared() bool { + _, ok := m.clearedFields[workpiecelifecyclelog.FieldFlowSeq] + return ok +} + +// ResetFlowSeq resets all changes to the "flowSeq" field. +func (m *WorkpieceLifecycleLogMutation) ResetFlowSeq() { + m.flowSeq = nil + m.addflowSeq = nil + delete(m.clearedFields, workpiecelifecyclelog.FieldFlowSeq) +} + +// SetOperator sets the "operator" field. +func (m *WorkpieceLifecycleLogMutation) SetOperator(s string) { + m.operator = &s +} + +// Operator returns the value of the "operator" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) Operator() (r string, exists bool) { + v := m.operator + if v == nil { + return + } + return *v, true +} + +// OldOperator returns the old "operator" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldOperator(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldOperator is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldOperator requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldOperator: %w", err) + } + return oldValue.Operator, nil +} + +// ResetOperator resets all changes to the "operator" field. +func (m *WorkpieceLifecycleLogMutation) ResetOperator() { + m.operator = nil +} + +// SetSource sets the "source" field. +func (m *WorkpieceLifecycleLogMutation) SetSource(s string) { + m.source = &s +} + +// Source returns the value of the "source" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) Source() (r string, exists bool) { + v := m.source + if v == nil { + return + } + return *v, true +} + +// OldSource returns the old "source" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldSource(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldSource is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldSource requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldSource: %w", err) + } + return oldValue.Source, nil +} + +// ResetSource resets all changes to the "source" field. +func (m *WorkpieceLifecycleLogMutation) ResetSource() { + m.source = nil +} + +// SetRemark sets the "remark" field. +func (m *WorkpieceLifecycleLogMutation) SetRemark(s string) { + m.remark = &s +} + +// Remark returns the value of the "remark" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) Remark() (r string, exists bool) { + v := m.remark + if v == nil { + return + } + return *v, true +} + +// OldRemark returns the old "remark" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldRemark(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRemark is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRemark requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRemark: %w", err) + } + return oldValue.Remark, nil +} + +// ResetRemark resets all changes to the "remark" field. +func (m *WorkpieceLifecycleLogMutation) ResetRemark() { + m.remark = nil +} + +// SetCreatedAt sets the "createdAt" field. +func (m *WorkpieceLifecycleLogMutation) SetCreatedAt(t time.Time) { + m.createdAt = &t +} + +// CreatedAt returns the value of the "createdAt" field in the mutation. +func (m *WorkpieceLifecycleLogMutation) CreatedAt() (r time.Time, exists bool) { + v := m.createdAt + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "createdAt" field's value of the WorkpieceLifecycleLog entity. +// If the WorkpieceLifecycleLog object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *WorkpieceLifecycleLogMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "createdAt" field. +func (m *WorkpieceLifecycleLogMutation) ResetCreatedAt() { + m.createdAt = nil +} + +// Where appends a list predicates to the WorkpieceLifecycleLogMutation builder. +func (m *WorkpieceLifecycleLogMutation) Where(ps ...predicate.WorkpieceLifecycleLog) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the WorkpieceLifecycleLogMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *WorkpieceLifecycleLogMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.WorkpieceLifecycleLog, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *WorkpieceLifecycleLogMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *WorkpieceLifecycleLogMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (WorkpieceLifecycleLog). +func (m *WorkpieceLifecycleLogMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *WorkpieceLifecycleLogMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.sn != nil { + fields = append(fields, workpiecelifecyclelog.FieldSn) + } + if m.workOrderNo != nil { + fields = append(fields, workpiecelifecyclelog.FieldWorkOrderNo) + } + if m.action != nil { + fields = append(fields, workpiecelifecyclelog.FieldAction) + } + if m.fromStatus != nil { + fields = append(fields, workpiecelifecyclelog.FieldFromStatus) + } + if m.toStatus != nil { + fields = append(fields, workpiecelifecyclelog.FieldToStatus) + } + if m.stationNo != nil { + fields = append(fields, workpiecelifecyclelog.FieldStationNo) + } + if m.flowSeq != nil { + fields = append(fields, workpiecelifecyclelog.FieldFlowSeq) + } + if m.operator != nil { + fields = append(fields, workpiecelifecyclelog.FieldOperator) + } + if m.source != nil { + fields = append(fields, workpiecelifecyclelog.FieldSource) + } + if m.remark != nil { + fields = append(fields, workpiecelifecyclelog.FieldRemark) + } + if m.createdAt != nil { + fields = append(fields, workpiecelifecyclelog.FieldCreatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *WorkpieceLifecycleLogMutation) Field(name string) (ent.Value, bool) { + switch name { + case workpiecelifecyclelog.FieldSn: + return m.Sn() + case workpiecelifecyclelog.FieldWorkOrderNo: + return m.WorkOrderNo() + case workpiecelifecyclelog.FieldAction: + return m.Action() + case workpiecelifecyclelog.FieldFromStatus: + return m.FromStatus() + case workpiecelifecyclelog.FieldToStatus: + return m.ToStatus() + case workpiecelifecyclelog.FieldStationNo: + return m.StationNo() + case workpiecelifecyclelog.FieldFlowSeq: + return m.FlowSeq() + case workpiecelifecyclelog.FieldOperator: + return m.Operator() + case workpiecelifecyclelog.FieldSource: + return m.Source() + case workpiecelifecyclelog.FieldRemark: + return m.Remark() + case workpiecelifecyclelog.FieldCreatedAt: + return m.CreatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *WorkpieceLifecycleLogMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case workpiecelifecyclelog.FieldSn: + return m.OldSn(ctx) + case workpiecelifecyclelog.FieldWorkOrderNo: + return m.OldWorkOrderNo(ctx) + case workpiecelifecyclelog.FieldAction: + return m.OldAction(ctx) + case workpiecelifecyclelog.FieldFromStatus: + return m.OldFromStatus(ctx) + case workpiecelifecyclelog.FieldToStatus: + return m.OldToStatus(ctx) + case workpiecelifecyclelog.FieldStationNo: + return m.OldStationNo(ctx) + case workpiecelifecyclelog.FieldFlowSeq: + return m.OldFlowSeq(ctx) + case workpiecelifecyclelog.FieldOperator: + return m.OldOperator(ctx) + case workpiecelifecyclelog.FieldSource: + return m.OldSource(ctx) + case workpiecelifecyclelog.FieldRemark: + return m.OldRemark(ctx) + case workpiecelifecyclelog.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown WorkpieceLifecycleLog field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *WorkpieceLifecycleLogMutation) SetField(name string, value ent.Value) error { + switch name { + case workpiecelifecyclelog.FieldSn: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSn(v) + return nil + case workpiecelifecyclelog.FieldWorkOrderNo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWorkOrderNo(v) + return nil + case workpiecelifecyclelog.FieldAction: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetAction(v) + return nil + case workpiecelifecyclelog.FieldFromStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFromStatus(v) + return nil + case workpiecelifecyclelog.FieldToStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetToStatus(v) + return nil + case workpiecelifecyclelog.FieldStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStationNo(v) + return nil + case workpiecelifecyclelog.FieldFlowSeq: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFlowSeq(v) + return nil + case workpiecelifecyclelog.FieldOperator: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOperator(v) + return nil + case workpiecelifecyclelog.FieldSource: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSource(v) + return nil + case workpiecelifecyclelog.FieldRemark: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRemark(v) + return nil + case workpiecelifecyclelog.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown WorkpieceLifecycleLog field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *WorkpieceLifecycleLogMutation) AddedFields() []string { + var fields []string + if m.addstationNo != nil { + fields = append(fields, workpiecelifecyclelog.FieldStationNo) + } + if m.addflowSeq != nil { + fields = append(fields, workpiecelifecyclelog.FieldFlowSeq) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *WorkpieceLifecycleLogMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case workpiecelifecyclelog.FieldStationNo: + return m.AddedStationNo() + case workpiecelifecyclelog.FieldFlowSeq: + return m.AddedFlowSeq() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *WorkpieceLifecycleLogMutation) AddField(name string, value ent.Value) error { + switch name { + case workpiecelifecyclelog.FieldStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddStationNo(v) + return nil + case workpiecelifecyclelog.FieldFlowSeq: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddFlowSeq(v) + return nil + } + return fmt.Errorf("unknown WorkpieceLifecycleLog numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *WorkpieceLifecycleLogMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(workpiecelifecyclelog.FieldStationNo) { + fields = append(fields, workpiecelifecyclelog.FieldStationNo) + } + if m.FieldCleared(workpiecelifecyclelog.FieldFlowSeq) { + fields = append(fields, workpiecelifecyclelog.FieldFlowSeq) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *WorkpieceLifecycleLogMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *WorkpieceLifecycleLogMutation) ClearField(name string) error { + switch name { + case workpiecelifecyclelog.FieldStationNo: + m.ClearStationNo() + return nil + case workpiecelifecyclelog.FieldFlowSeq: + m.ClearFlowSeq() + return nil + } + return fmt.Errorf("unknown WorkpieceLifecycleLog nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *WorkpieceLifecycleLogMutation) ResetField(name string) error { + switch name { + case workpiecelifecyclelog.FieldSn: + m.ResetSn() + return nil + case workpiecelifecyclelog.FieldWorkOrderNo: + m.ResetWorkOrderNo() + return nil + case workpiecelifecyclelog.FieldAction: + m.ResetAction() + return nil + case workpiecelifecyclelog.FieldFromStatus: + m.ResetFromStatus() + return nil + case workpiecelifecyclelog.FieldToStatus: + m.ResetToStatus() + return nil + case workpiecelifecyclelog.FieldStationNo: + m.ResetStationNo() + return nil + case workpiecelifecyclelog.FieldFlowSeq: + m.ResetFlowSeq() + return nil + case workpiecelifecyclelog.FieldOperator: + m.ResetOperator() + return nil + case workpiecelifecyclelog.FieldSource: + m.ResetSource() + return nil + case workpiecelifecyclelog.FieldRemark: + m.ResetRemark() + return nil + case workpiecelifecyclelog.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown WorkpieceLifecycleLog field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *WorkpieceLifecycleLogMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *WorkpieceLifecycleLogMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *WorkpieceLifecycleLogMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *WorkpieceLifecycleLogMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *WorkpieceLifecycleLogMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *WorkpieceLifecycleLogMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *WorkpieceLifecycleLogMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown WorkpieceLifecycleLog unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *WorkpieceLifecycleLogMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown WorkpieceLifecycleLog edge %s", name) +} + // WorkpieceProcessMutation represents an operation that mutates the WorkpieceProcess nodes in the graph. type WorkpieceProcessMutation struct { config diff --git a/bj_power_mes/ent/predicate/predicate.go b/bj_power_mes/ent/predicate/predicate.go index 5c1b73d..148233d 100644 --- a/bj_power_mes/ent/predicate/predicate.go +++ b/bj_power_mes/ent/predicate/predicate.go @@ -105,5 +105,8 @@ type Workpiece func(*sql.Selector) // WorkpieceBind is the predicate function for workpiecebind builders. type WorkpieceBind func(*sql.Selector) +// WorkpieceLifecycleLog is the predicate function for workpiecelifecyclelog builders. +type WorkpieceLifecycleLog func(*sql.Selector) + // WorkpieceProcess is the predicate function for workpieceprocess builders. type WorkpieceProcess func(*sql.Selector) diff --git a/bj_power_mes/ent/runtime.go b/bj_power_mes/ent/runtime.go index baa0a04..8b320dd 100644 --- a/bj_power_mes/ent/runtime.go +++ b/bj_power_mes/ent/runtime.go @@ -36,6 +36,7 @@ import ( "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpiecebind" + "bj_power_mes/ent/workpiecelifecyclelog" "bj_power_mes/ent/workpieceprocess" "bj_power_mes/schema" "time" @@ -1714,17 +1715,17 @@ func init() { // workpiece.OrderNoValidator is a validator for the "orderNo" field. It is called by the builders before save. workpiece.OrderNoValidator = workpieceDescOrderNo.Validators[0].(func(string) error) // workpieceDescStatus is the schema descriptor for status field. - workpieceDescStatus := workpieceFields[5].Descriptor() + workpieceDescStatus := workpieceFields[6].Descriptor() // workpiece.DefaultStatus holds the default value on creation for the status field. workpiece.DefaultStatus = workpieceDescStatus.Default.(string) // workpiece.StatusValidator is a validator for the "status" field. It is called by the builders before save. workpiece.StatusValidator = workpieceDescStatus.Validators[0].(func(string) error) // workpieceDescCreatedAt is the schema descriptor for createdAt field. - workpieceDescCreatedAt := workpieceFields[8].Descriptor() + workpieceDescCreatedAt := workpieceFields[9].Descriptor() // workpiece.DefaultCreatedAt holds the default value on creation for the createdAt field. workpiece.DefaultCreatedAt = workpieceDescCreatedAt.Default.(func() time.Time) // workpieceDescUpdatedAt is the schema descriptor for updatedAt field. - workpieceDescUpdatedAt := workpieceFields[9].Descriptor() + workpieceDescUpdatedAt := workpieceFields[10].Descriptor() // workpiece.DefaultUpdatedAt holds the default value on creation for the updatedAt field. workpiece.DefaultUpdatedAt = workpieceDescUpdatedAt.Default.(func() time.Time) // workpiece.UpdateDefaultUpdatedAt holds the default value on update for the updatedAt field. @@ -1801,6 +1802,60 @@ func init() { workpiecebindDescID := workpiecebindFields[0].Descriptor() // workpiecebind.IDValidator is a validator for the "id" field. It is called by the builders before save. workpiecebind.IDValidator = workpiecebindDescID.Validators[0].(func(int) error) + workpiecelifecyclelogFields := schema.WorkpieceLifecycleLog{}.Fields() + _ = workpiecelifecyclelogFields + // workpiecelifecyclelogDescSn is the schema descriptor for sn field. + workpiecelifecyclelogDescSn := workpiecelifecyclelogFields[1].Descriptor() + // workpiecelifecyclelog.SnValidator is a validator for the "sn" field. It is called by the builders before save. + workpiecelifecyclelog.SnValidator = workpiecelifecyclelogDescSn.Validators[0].(func(string) error) + // workpiecelifecyclelogDescWorkOrderNo is the schema descriptor for workOrderNo field. + workpiecelifecyclelogDescWorkOrderNo := workpiecelifecyclelogFields[2].Descriptor() + // workpiecelifecyclelog.DefaultWorkOrderNo holds the default value on creation for the workOrderNo field. + workpiecelifecyclelog.DefaultWorkOrderNo = workpiecelifecyclelogDescWorkOrderNo.Default.(string) + // workpiecelifecyclelog.WorkOrderNoValidator is a validator for the "workOrderNo" field. It is called by the builders before save. + workpiecelifecyclelog.WorkOrderNoValidator = workpiecelifecyclelogDescWorkOrderNo.Validators[0].(func(string) error) + // workpiecelifecyclelogDescAction is the schema descriptor for action field. + workpiecelifecyclelogDescAction := workpiecelifecyclelogFields[3].Descriptor() + // workpiecelifecyclelog.ActionValidator is a validator for the "action" field. It is called by the builders before save. + workpiecelifecyclelog.ActionValidator = workpiecelifecyclelogDescAction.Validators[0].(func(string) error) + // workpiecelifecyclelogDescFromStatus is the schema descriptor for fromStatus field. + workpiecelifecyclelogDescFromStatus := workpiecelifecyclelogFields[4].Descriptor() + // workpiecelifecyclelog.DefaultFromStatus holds the default value on creation for the fromStatus field. + workpiecelifecyclelog.DefaultFromStatus = workpiecelifecyclelogDescFromStatus.Default.(string) + // workpiecelifecyclelog.FromStatusValidator is a validator for the "fromStatus" field. It is called by the builders before save. + workpiecelifecyclelog.FromStatusValidator = workpiecelifecyclelogDescFromStatus.Validators[0].(func(string) error) + // workpiecelifecyclelogDescToStatus is the schema descriptor for toStatus field. + workpiecelifecyclelogDescToStatus := workpiecelifecyclelogFields[5].Descriptor() + // workpiecelifecyclelog.DefaultToStatus holds the default value on creation for the toStatus field. + workpiecelifecyclelog.DefaultToStatus = workpiecelifecyclelogDescToStatus.Default.(string) + // workpiecelifecyclelog.ToStatusValidator is a validator for the "toStatus" field. It is called by the builders before save. + workpiecelifecyclelog.ToStatusValidator = workpiecelifecyclelogDescToStatus.Validators[0].(func(string) error) + // workpiecelifecyclelogDescOperator is the schema descriptor for operator field. + workpiecelifecyclelogDescOperator := workpiecelifecyclelogFields[8].Descriptor() + // workpiecelifecyclelog.DefaultOperator holds the default value on creation for the operator field. + workpiecelifecyclelog.DefaultOperator = workpiecelifecyclelogDescOperator.Default.(string) + // workpiecelifecyclelog.OperatorValidator is a validator for the "operator" field. It is called by the builders before save. + workpiecelifecyclelog.OperatorValidator = workpiecelifecyclelogDescOperator.Validators[0].(func(string) error) + // workpiecelifecyclelogDescSource is the schema descriptor for source field. + workpiecelifecyclelogDescSource := workpiecelifecyclelogFields[9].Descriptor() + // workpiecelifecyclelog.DefaultSource holds the default value on creation for the source field. + workpiecelifecyclelog.DefaultSource = workpiecelifecyclelogDescSource.Default.(string) + // workpiecelifecyclelog.SourceValidator is a validator for the "source" field. It is called by the builders before save. + workpiecelifecyclelog.SourceValidator = workpiecelifecyclelogDescSource.Validators[0].(func(string) error) + // workpiecelifecyclelogDescRemark is the schema descriptor for remark field. + workpiecelifecyclelogDescRemark := workpiecelifecyclelogFields[10].Descriptor() + // workpiecelifecyclelog.DefaultRemark holds the default value on creation for the remark field. + workpiecelifecyclelog.DefaultRemark = workpiecelifecyclelogDescRemark.Default.(string) + // workpiecelifecyclelog.RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + workpiecelifecyclelog.RemarkValidator = workpiecelifecyclelogDescRemark.Validators[0].(func(string) error) + // workpiecelifecyclelogDescCreatedAt is the schema descriptor for createdAt field. + workpiecelifecyclelogDescCreatedAt := workpiecelifecyclelogFields[11].Descriptor() + // workpiecelifecyclelog.DefaultCreatedAt holds the default value on creation for the createdAt field. + workpiecelifecyclelog.DefaultCreatedAt = workpiecelifecyclelogDescCreatedAt.Default.(func() time.Time) + // workpiecelifecyclelogDescID is the schema descriptor for id field. + workpiecelifecyclelogDescID := workpiecelifecyclelogFields[0].Descriptor() + // workpiecelifecyclelog.IDValidator is a validator for the "id" field. It is called by the builders before save. + workpiecelifecyclelog.IDValidator = workpiecelifecyclelogDescID.Validators[0].(func(int) error) workpieceprocessFields := schema.WorkpieceProcess{}.Fields() _ = workpieceprocessFields // workpieceprocessDescSn is the schema descriptor for sn field. diff --git a/bj_power_mes/ent/tx.go b/bj_power_mes/ent/tx.go index 9a55182..4cf44a2 100644 --- a/bj_power_mes/ent/tx.go +++ b/bj_power_mes/ent/tx.go @@ -78,6 +78,8 @@ type Tx struct { Workpiece *WorkpieceClient // WorkpieceBind is the client for interacting with the WorkpieceBind builders. WorkpieceBind *WorkpieceBindClient + // WorkpieceLifecycleLog is the client for interacting with the WorkpieceLifecycleLog builders. + WorkpieceLifecycleLog *WorkpieceLifecycleLogClient // WorkpieceProcess is the client for interacting with the WorkpieceProcess builders. WorkpieceProcess *WorkpieceProcessClient @@ -244,6 +246,7 @@ func (tx *Tx) init() { tx.WorkOrder = NewWorkOrderClient(tx.config) tx.Workpiece = NewWorkpieceClient(tx.config) tx.WorkpieceBind = NewWorkpieceBindClient(tx.config) + tx.WorkpieceLifecycleLog = NewWorkpieceLifecycleLogClient(tx.config) tx.WorkpieceProcess = NewWorkpieceProcessClient(tx.config) } diff --git a/bj_power_mes/ent/workpiece.go b/bj_power_mes/ent/workpiece.go index 4c3ef6d..e97c1f9 100644 --- a/bj_power_mes/ent/workpiece.go +++ b/bj_power_mes/ent/workpiece.go @@ -23,8 +23,10 @@ type Workpiece struct { OrderNo string `json:"orderNo,omitempty"` // 工单ID WorkOrderId int `json:"workOrderId,omitempty"` - // 最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条) + // 业务位置:最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条) CurrentStationNo int `json:"currentStationNo,omitempty"` + // 物理位置:工件当前实际所在工位号(0=未在工位;建档/到达即写,完工/入库清空) + AtStationNo int `json:"atStationNo,omitempty"` // Status holds the value of the "status" field. Status string `json:"status,omitempty"` // 进线时间 @@ -43,7 +45,7 @@ func (*Workpiece) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case workpiece.FieldID, workpiece.FieldWorkOrderId, workpiece.FieldCurrentStationNo: + case workpiece.FieldID, workpiece.FieldWorkOrderId, workpiece.FieldCurrentStationNo, workpiece.FieldAtStationNo: values[i] = new(sql.NullInt64) case workpiece.FieldSn, workpiece.FieldOrderNo, workpiece.FieldStatus: values[i] = new(sql.NullString) @@ -94,6 +96,12 @@ func (_m *Workpiece) assignValues(columns []string, values []any) error { } else if value.Valid { _m.CurrentStationNo = int(value.Int64) } + case workpiece.FieldAtStationNo: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field atStationNo", values[i]) + } else if value.Valid { + _m.AtStationNo = int(value.Int64) + } case workpiece.FieldStatus: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) @@ -175,6 +183,9 @@ func (_m *Workpiece) String() string { builder.WriteString("currentStationNo=") builder.WriteString(fmt.Sprintf("%v", _m.CurrentStationNo)) builder.WriteString(", ") + builder.WriteString("atStationNo=") + builder.WriteString(fmt.Sprintf("%v", _m.AtStationNo)) + builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(_m.Status) builder.WriteString(", ") diff --git a/bj_power_mes/ent/workpiece/where.go b/bj_power_mes/ent/workpiece/where.go index 2e2c07d..c21ed07 100644 --- a/bj_power_mes/ent/workpiece/where.go +++ b/bj_power_mes/ent/workpiece/where.go @@ -74,6 +74,11 @@ func CurrentStationNo(v int) predicate.Workpiece { return predicate.Workpiece(sql.FieldEQ(FieldCurrentStationNo, v)) } +// AtStationNo applies equality check predicate on the "atStationNo" field. It's identical to AtStationNoEQ. +func AtStationNo(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldEQ(FieldAtStationNo, v)) +} + // Status applies equality check predicate on the "status" field. It's identical to StatusEQ. func Status(v string) predicate.Workpiece { return predicate.Workpiece(sql.FieldEQ(FieldStatus, v)) @@ -329,6 +334,56 @@ func CurrentStationNoNotNil() predicate.Workpiece { return predicate.Workpiece(sql.FieldNotNull(FieldCurrentStationNo)) } +// AtStationNoEQ applies the EQ predicate on the "atStationNo" field. +func AtStationNoEQ(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldEQ(FieldAtStationNo, v)) +} + +// AtStationNoNEQ applies the NEQ predicate on the "atStationNo" field. +func AtStationNoNEQ(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldNEQ(FieldAtStationNo, v)) +} + +// AtStationNoIn applies the In predicate on the "atStationNo" field. +func AtStationNoIn(vs ...int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldIn(FieldAtStationNo, vs...)) +} + +// AtStationNoNotIn applies the NotIn predicate on the "atStationNo" field. +func AtStationNoNotIn(vs ...int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldNotIn(FieldAtStationNo, vs...)) +} + +// AtStationNoGT applies the GT predicate on the "atStationNo" field. +func AtStationNoGT(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldGT(FieldAtStationNo, v)) +} + +// AtStationNoGTE applies the GTE predicate on the "atStationNo" field. +func AtStationNoGTE(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldGTE(FieldAtStationNo, v)) +} + +// AtStationNoLT applies the LT predicate on the "atStationNo" field. +func AtStationNoLT(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldLT(FieldAtStationNo, v)) +} + +// AtStationNoLTE applies the LTE predicate on the "atStationNo" field. +func AtStationNoLTE(v int) predicate.Workpiece { + return predicate.Workpiece(sql.FieldLTE(FieldAtStationNo, v)) +} + +// AtStationNoIsNil applies the IsNil predicate on the "atStationNo" field. +func AtStationNoIsNil() predicate.Workpiece { + return predicate.Workpiece(sql.FieldIsNull(FieldAtStationNo)) +} + +// AtStationNoNotNil applies the NotNil predicate on the "atStationNo" field. +func AtStationNoNotNil() predicate.Workpiece { + return predicate.Workpiece(sql.FieldNotNull(FieldAtStationNo)) +} + // StatusEQ applies the EQ predicate on the "status" field. func StatusEQ(v string) predicate.Workpiece { return predicate.Workpiece(sql.FieldEQ(FieldStatus, v)) diff --git a/bj_power_mes/ent/workpiece/workpiece.go b/bj_power_mes/ent/workpiece/workpiece.go index ee5589f..9f0670f 100644 --- a/bj_power_mes/ent/workpiece/workpiece.go +++ b/bj_power_mes/ent/workpiece/workpiece.go @@ -21,6 +21,8 @@ const ( FieldWorkOrderId = "work_order_id" // FieldCurrentStationNo holds the string denoting the currentstationno field in the database. FieldCurrentStationNo = "current_station_no" + // FieldAtStationNo holds the string denoting the atstationno field in the database. + FieldAtStationNo = "at_station_no" // FieldStatus holds the string denoting the status field in the database. FieldStatus = "status" // FieldOnlineAt holds the string denoting the onlineat field in the database. @@ -42,6 +44,7 @@ var Columns = []string{ FieldOrderNo, FieldWorkOrderId, FieldCurrentStationNo, + FieldAtStationNo, FieldStatus, FieldOnlineAt, FieldDoneAt, @@ -108,6 +111,11 @@ func ByCurrentStationNo(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldCurrentStationNo, opts...).ToFunc() } +// ByAtStationNo orders the results by the atStationNo field. +func ByAtStationNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAtStationNo, opts...).ToFunc() +} + // ByStatus orders the results by the status field. func ByStatus(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldStatus, opts...).ToFunc() diff --git a/bj_power_mes/ent/workpiece_create.go b/bj_power_mes/ent/workpiece_create.go index 5884a5a..d76f472 100644 --- a/bj_power_mes/ent/workpiece_create.go +++ b/bj_power_mes/ent/workpiece_create.go @@ -68,6 +68,20 @@ func (_c *WorkpieceCreate) SetNillableCurrentStationNo(v *int) *WorkpieceCreate return _c } +// SetAtStationNo sets the "atStationNo" field. +func (_c *WorkpieceCreate) SetAtStationNo(v int) *WorkpieceCreate { + _c.mutation.SetAtStationNo(v) + return _c +} + +// SetNillableAtStationNo sets the "atStationNo" field if the given value is not nil. +func (_c *WorkpieceCreate) SetNillableAtStationNo(v *int) *WorkpieceCreate { + if v != nil { + _c.SetAtStationNo(*v) + } + return _c +} + // SetStatus sets the "status" field. func (_c *WorkpieceCreate) SetStatus(v string) *WorkpieceCreate { _c.mutation.SetStatus(v) @@ -279,6 +293,10 @@ func (_c *WorkpieceCreate) createSpec() (*Workpiece, *sqlgraph.CreateSpec) { _spec.SetField(workpiece.FieldCurrentStationNo, field.TypeInt, value) _node.CurrentStationNo = value } + if value, ok := _c.mutation.AtStationNo(); ok { + _spec.SetField(workpiece.FieldAtStationNo, field.TypeInt, value) + _node.AtStationNo = value + } if value, ok := _c.mutation.Status(); ok { _spec.SetField(workpiece.FieldStatus, field.TypeString, value) _node.Status = value diff --git a/bj_power_mes/ent/workpiece_update.go b/bj_power_mes/ent/workpiece_update.go index 9f8314f..362fcba 100644 --- a/bj_power_mes/ent/workpiece_update.go +++ b/bj_power_mes/ent/workpiece_update.go @@ -111,6 +111,33 @@ func (_u *WorkpieceUpdate) ClearCurrentStationNo() *WorkpieceUpdate { return _u } +// SetAtStationNo sets the "atStationNo" field. +func (_u *WorkpieceUpdate) SetAtStationNo(v int) *WorkpieceUpdate { + _u.mutation.ResetAtStationNo() + _u.mutation.SetAtStationNo(v) + return _u +} + +// SetNillableAtStationNo sets the "atStationNo" field if the given value is not nil. +func (_u *WorkpieceUpdate) SetNillableAtStationNo(v *int) *WorkpieceUpdate { + if v != nil { + _u.SetAtStationNo(*v) + } + return _u +} + +// AddAtStationNo adds value to the "atStationNo" field. +func (_u *WorkpieceUpdate) AddAtStationNo(v int) *WorkpieceUpdate { + _u.mutation.AddAtStationNo(v) + return _u +} + +// ClearAtStationNo clears the value of the "atStationNo" field. +func (_u *WorkpieceUpdate) ClearAtStationNo() *WorkpieceUpdate { + _u.mutation.ClearAtStationNo() + return _u +} + // SetStatus sets the "status" field. func (_u *WorkpieceUpdate) SetStatus(v string) *WorkpieceUpdate { _u.mutation.SetStatus(v) @@ -280,6 +307,15 @@ func (_u *WorkpieceUpdate) sqlSave(ctx context.Context) (_node int, err error) { if _u.mutation.CurrentStationNoCleared() { _spec.ClearField(workpiece.FieldCurrentStationNo, field.TypeInt) } + if value, ok := _u.mutation.AtStationNo(); ok { + _spec.SetField(workpiece.FieldAtStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedAtStationNo(); ok { + _spec.AddField(workpiece.FieldAtStationNo, field.TypeInt, value) + } + if _u.mutation.AtStationNoCleared() { + _spec.ClearField(workpiece.FieldAtStationNo, field.TypeInt) + } if value, ok := _u.mutation.Status(); ok { _spec.SetField(workpiece.FieldStatus, field.TypeString, value) } @@ -405,6 +441,33 @@ func (_u *WorkpieceUpdateOne) ClearCurrentStationNo() *WorkpieceUpdateOne { return _u } +// SetAtStationNo sets the "atStationNo" field. +func (_u *WorkpieceUpdateOne) SetAtStationNo(v int) *WorkpieceUpdateOne { + _u.mutation.ResetAtStationNo() + _u.mutation.SetAtStationNo(v) + return _u +} + +// SetNillableAtStationNo sets the "atStationNo" field if the given value is not nil. +func (_u *WorkpieceUpdateOne) SetNillableAtStationNo(v *int) *WorkpieceUpdateOne { + if v != nil { + _u.SetAtStationNo(*v) + } + return _u +} + +// AddAtStationNo adds value to the "atStationNo" field. +func (_u *WorkpieceUpdateOne) AddAtStationNo(v int) *WorkpieceUpdateOne { + _u.mutation.AddAtStationNo(v) + return _u +} + +// ClearAtStationNo clears the value of the "atStationNo" field. +func (_u *WorkpieceUpdateOne) ClearAtStationNo() *WorkpieceUpdateOne { + _u.mutation.ClearAtStationNo() + return _u +} + // SetStatus sets the "status" field. func (_u *WorkpieceUpdateOne) SetStatus(v string) *WorkpieceUpdateOne { _u.mutation.SetStatus(v) @@ -604,6 +667,15 @@ func (_u *WorkpieceUpdateOne) sqlSave(ctx context.Context) (_node *Workpiece, er if _u.mutation.CurrentStationNoCleared() { _spec.ClearField(workpiece.FieldCurrentStationNo, field.TypeInt) } + if value, ok := _u.mutation.AtStationNo(); ok { + _spec.SetField(workpiece.FieldAtStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedAtStationNo(); ok { + _spec.AddField(workpiece.FieldAtStationNo, field.TypeInt, value) + } + if _u.mutation.AtStationNoCleared() { + _spec.ClearField(workpiece.FieldAtStationNo, field.TypeInt) + } if value, ok := _u.mutation.Status(); ok { _spec.SetField(workpiece.FieldStatus, field.TypeString, value) } diff --git a/bj_power_mes/ent/workpiecelifecyclelog.go b/bj_power_mes/ent/workpiecelifecyclelog.go new file mode 100644 index 0000000..19295e4 --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog.go @@ -0,0 +1,216 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/workpiecelifecyclelog" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// 工件生命周期状态流水:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED,所有状态变更点同事务写 +type WorkpieceLifecycleLog struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 工件SN + Sn string `json:"sn,omitempty"` + // 所属工单 + WorkOrderNo string `json:"workOrderNo,omitempty"` + // 状态动作:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED + Action string `json:"action,omitempty"` + // 变更前状态 + FromStatus string `json:"fromStatus,omitempty"` + // 变更后状态 + ToStatus string `json:"toStatus,omitempty"` + // 关联工位号 + StationNo int `json:"stationNo,omitempty"` + // 工艺序号(工序顺序) + FlowSeq int `json:"flowSeq,omitempty"` + // 操作人 + Operator string `json:"operator,omitempty"` + // 来源:workstation/mes/admin/reconcile + Source string `json:"source,omitempty"` + // 备注 + Remark string `json:"remark,omitempty"` + // CreatedAt holds the value of the "createdAt" field. + CreatedAt time.Time `json:"createdAt,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*WorkpieceLifecycleLog) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case workpiecelifecyclelog.FieldID, workpiecelifecyclelog.FieldStationNo, workpiecelifecyclelog.FieldFlowSeq: + values[i] = new(sql.NullInt64) + case workpiecelifecyclelog.FieldSn, workpiecelifecyclelog.FieldWorkOrderNo, workpiecelifecyclelog.FieldAction, workpiecelifecyclelog.FieldFromStatus, workpiecelifecyclelog.FieldToStatus, workpiecelifecyclelog.FieldOperator, workpiecelifecyclelog.FieldSource, workpiecelifecyclelog.FieldRemark: + values[i] = new(sql.NullString) + case workpiecelifecyclelog.FieldCreatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the WorkpieceLifecycleLog fields. +func (_m *WorkpieceLifecycleLog) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case workpiecelifecyclelog.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case workpiecelifecyclelog.FieldSn: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field sn", values[i]) + } else if value.Valid { + _m.Sn = value.String + } + case workpiecelifecyclelog.FieldWorkOrderNo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field workOrderNo", values[i]) + } else if value.Valid { + _m.WorkOrderNo = value.String + } + case workpiecelifecyclelog.FieldAction: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field action", values[i]) + } else if value.Valid { + _m.Action = value.String + } + case workpiecelifecyclelog.FieldFromStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field fromStatus", values[i]) + } else if value.Valid { + _m.FromStatus = value.String + } + case workpiecelifecyclelog.FieldToStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field toStatus", values[i]) + } else if value.Valid { + _m.ToStatus = value.String + } + case workpiecelifecyclelog.FieldStationNo: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field stationNo", values[i]) + } else if value.Valid { + _m.StationNo = int(value.Int64) + } + case workpiecelifecyclelog.FieldFlowSeq: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field flowSeq", values[i]) + } else if value.Valid { + _m.FlowSeq = int(value.Int64) + } + case workpiecelifecyclelog.FieldOperator: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field operator", values[i]) + } else if value.Valid { + _m.Operator = value.String + } + case workpiecelifecyclelog.FieldSource: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field source", values[i]) + } else if value.Valid { + _m.Source = value.String + } + case workpiecelifecyclelog.FieldRemark: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field remark", values[i]) + } else if value.Valid { + _m.Remark = value.String + } + case workpiecelifecyclelog.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field createdAt", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the WorkpieceLifecycleLog. +// This includes values selected through modifiers, order, etc. +func (_m *WorkpieceLifecycleLog) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this WorkpieceLifecycleLog. +// Note that you need to call WorkpieceLifecycleLog.Unwrap() before calling this method if this WorkpieceLifecycleLog +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *WorkpieceLifecycleLog) Update() *WorkpieceLifecycleLogUpdateOne { + return NewWorkpieceLifecycleLogClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the WorkpieceLifecycleLog entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *WorkpieceLifecycleLog) Unwrap() *WorkpieceLifecycleLog { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: WorkpieceLifecycleLog is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *WorkpieceLifecycleLog) String() string { + var builder strings.Builder + builder.WriteString("WorkpieceLifecycleLog(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("sn=") + builder.WriteString(_m.Sn) + builder.WriteString(", ") + builder.WriteString("workOrderNo=") + builder.WriteString(_m.WorkOrderNo) + builder.WriteString(", ") + builder.WriteString("action=") + builder.WriteString(_m.Action) + builder.WriteString(", ") + builder.WriteString("fromStatus=") + builder.WriteString(_m.FromStatus) + builder.WriteString(", ") + builder.WriteString("toStatus=") + builder.WriteString(_m.ToStatus) + builder.WriteString(", ") + builder.WriteString("stationNo=") + builder.WriteString(fmt.Sprintf("%v", _m.StationNo)) + builder.WriteString(", ") + builder.WriteString("flowSeq=") + builder.WriteString(fmt.Sprintf("%v", _m.FlowSeq)) + builder.WriteString(", ") + builder.WriteString("operator=") + builder.WriteString(_m.Operator) + builder.WriteString(", ") + builder.WriteString("source=") + builder.WriteString(_m.Source) + builder.WriteString(", ") + builder.WriteString("remark=") + builder.WriteString(_m.Remark) + builder.WriteString(", ") + builder.WriteString("createdAt=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// WorkpieceLifecycleLogs is a parsable slice of WorkpieceLifecycleLog. +type WorkpieceLifecycleLogs []*WorkpieceLifecycleLog diff --git a/bj_power_mes/ent/workpiecelifecyclelog/where.go b/bj_power_mes/ent/workpiecelifecyclelog/where.go new file mode 100644 index 0000000..dc72145 --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog/where.go @@ -0,0 +1,785 @@ +// Code generated by ent, DO NOT EDIT. + +package workpiecelifecyclelog + +import ( + "bj_power_mes/ent/predicate" + "time" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldID, id)) +} + +// Sn applies equality check predicate on the "sn" field. It's identical to SnEQ. +func Sn(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldSn, v)) +} + +// WorkOrderNo applies equality check predicate on the "workOrderNo" field. It's identical to WorkOrderNoEQ. +func WorkOrderNo(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldWorkOrderNo, v)) +} + +// Action applies equality check predicate on the "action" field. It's identical to ActionEQ. +func Action(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldAction, v)) +} + +// FromStatus applies equality check predicate on the "fromStatus" field. It's identical to FromStatusEQ. +func FromStatus(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldFromStatus, v)) +} + +// ToStatus applies equality check predicate on the "toStatus" field. It's identical to ToStatusEQ. +func ToStatus(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldToStatus, v)) +} + +// StationNo applies equality check predicate on the "stationNo" field. It's identical to StationNoEQ. +func StationNo(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldStationNo, v)) +} + +// FlowSeq applies equality check predicate on the "flowSeq" field. It's identical to FlowSeqEQ. +func FlowSeq(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldFlowSeq, v)) +} + +// Operator applies equality check predicate on the "operator" field. It's identical to OperatorEQ. +func Operator(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldOperator, v)) +} + +// Source applies equality check predicate on the "source" field. It's identical to SourceEQ. +func Source(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldSource, v)) +} + +// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. +func Remark(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldRemark, v)) +} + +// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldCreatedAt, v)) +} + +// SnEQ applies the EQ predicate on the "sn" field. +func SnEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldSn, v)) +} + +// SnNEQ applies the NEQ predicate on the "sn" field. +func SnNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldSn, v)) +} + +// SnIn applies the In predicate on the "sn" field. +func SnIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldSn, vs...)) +} + +// SnNotIn applies the NotIn predicate on the "sn" field. +func SnNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldSn, vs...)) +} + +// SnGT applies the GT predicate on the "sn" field. +func SnGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldSn, v)) +} + +// SnGTE applies the GTE predicate on the "sn" field. +func SnGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldSn, v)) +} + +// SnLT applies the LT predicate on the "sn" field. +func SnLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldSn, v)) +} + +// SnLTE applies the LTE predicate on the "sn" field. +func SnLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldSn, v)) +} + +// SnContains applies the Contains predicate on the "sn" field. +func SnContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldSn, v)) +} + +// SnHasPrefix applies the HasPrefix predicate on the "sn" field. +func SnHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldSn, v)) +} + +// SnHasSuffix applies the HasSuffix predicate on the "sn" field. +func SnHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldSn, v)) +} + +// SnEqualFold applies the EqualFold predicate on the "sn" field. +func SnEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldSn, v)) +} + +// SnContainsFold applies the ContainsFold predicate on the "sn" field. +func SnContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldSn, v)) +} + +// WorkOrderNoEQ applies the EQ predicate on the "workOrderNo" field. +func WorkOrderNoEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldWorkOrderNo, v)) +} + +// WorkOrderNoNEQ applies the NEQ predicate on the "workOrderNo" field. +func WorkOrderNoNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldWorkOrderNo, v)) +} + +// WorkOrderNoIn applies the In predicate on the "workOrderNo" field. +func WorkOrderNoIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldWorkOrderNo, vs...)) +} + +// WorkOrderNoNotIn applies the NotIn predicate on the "workOrderNo" field. +func WorkOrderNoNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldWorkOrderNo, vs...)) +} + +// WorkOrderNoGT applies the GT predicate on the "workOrderNo" field. +func WorkOrderNoGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldWorkOrderNo, v)) +} + +// WorkOrderNoGTE applies the GTE predicate on the "workOrderNo" field. +func WorkOrderNoGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldWorkOrderNo, v)) +} + +// WorkOrderNoLT applies the LT predicate on the "workOrderNo" field. +func WorkOrderNoLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldWorkOrderNo, v)) +} + +// WorkOrderNoLTE applies the LTE predicate on the "workOrderNo" field. +func WorkOrderNoLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldWorkOrderNo, v)) +} + +// WorkOrderNoContains applies the Contains predicate on the "workOrderNo" field. +func WorkOrderNoContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldWorkOrderNo, v)) +} + +// WorkOrderNoHasPrefix applies the HasPrefix predicate on the "workOrderNo" field. +func WorkOrderNoHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldWorkOrderNo, v)) +} + +// WorkOrderNoHasSuffix applies the HasSuffix predicate on the "workOrderNo" field. +func WorkOrderNoHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldWorkOrderNo, v)) +} + +// WorkOrderNoEqualFold applies the EqualFold predicate on the "workOrderNo" field. +func WorkOrderNoEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldWorkOrderNo, v)) +} + +// WorkOrderNoContainsFold applies the ContainsFold predicate on the "workOrderNo" field. +func WorkOrderNoContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldWorkOrderNo, v)) +} + +// ActionEQ applies the EQ predicate on the "action" field. +func ActionEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldAction, v)) +} + +// ActionNEQ applies the NEQ predicate on the "action" field. +func ActionNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldAction, v)) +} + +// ActionIn applies the In predicate on the "action" field. +func ActionIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldAction, vs...)) +} + +// ActionNotIn applies the NotIn predicate on the "action" field. +func ActionNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldAction, vs...)) +} + +// ActionGT applies the GT predicate on the "action" field. +func ActionGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldAction, v)) +} + +// ActionGTE applies the GTE predicate on the "action" field. +func ActionGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldAction, v)) +} + +// ActionLT applies the LT predicate on the "action" field. +func ActionLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldAction, v)) +} + +// ActionLTE applies the LTE predicate on the "action" field. +func ActionLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldAction, v)) +} + +// ActionContains applies the Contains predicate on the "action" field. +func ActionContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldAction, v)) +} + +// ActionHasPrefix applies the HasPrefix predicate on the "action" field. +func ActionHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldAction, v)) +} + +// ActionHasSuffix applies the HasSuffix predicate on the "action" field. +func ActionHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldAction, v)) +} + +// ActionEqualFold applies the EqualFold predicate on the "action" field. +func ActionEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldAction, v)) +} + +// ActionContainsFold applies the ContainsFold predicate on the "action" field. +func ActionContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldAction, v)) +} + +// FromStatusEQ applies the EQ predicate on the "fromStatus" field. +func FromStatusEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldFromStatus, v)) +} + +// FromStatusNEQ applies the NEQ predicate on the "fromStatus" field. +func FromStatusNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldFromStatus, v)) +} + +// FromStatusIn applies the In predicate on the "fromStatus" field. +func FromStatusIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldFromStatus, vs...)) +} + +// FromStatusNotIn applies the NotIn predicate on the "fromStatus" field. +func FromStatusNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldFromStatus, vs...)) +} + +// FromStatusGT applies the GT predicate on the "fromStatus" field. +func FromStatusGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldFromStatus, v)) +} + +// FromStatusGTE applies the GTE predicate on the "fromStatus" field. +func FromStatusGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldFromStatus, v)) +} + +// FromStatusLT applies the LT predicate on the "fromStatus" field. +func FromStatusLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldFromStatus, v)) +} + +// FromStatusLTE applies the LTE predicate on the "fromStatus" field. +func FromStatusLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldFromStatus, v)) +} + +// FromStatusContains applies the Contains predicate on the "fromStatus" field. +func FromStatusContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldFromStatus, v)) +} + +// FromStatusHasPrefix applies the HasPrefix predicate on the "fromStatus" field. +func FromStatusHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldFromStatus, v)) +} + +// FromStatusHasSuffix applies the HasSuffix predicate on the "fromStatus" field. +func FromStatusHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldFromStatus, v)) +} + +// FromStatusEqualFold applies the EqualFold predicate on the "fromStatus" field. +func FromStatusEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldFromStatus, v)) +} + +// FromStatusContainsFold applies the ContainsFold predicate on the "fromStatus" field. +func FromStatusContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldFromStatus, v)) +} + +// ToStatusEQ applies the EQ predicate on the "toStatus" field. +func ToStatusEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldToStatus, v)) +} + +// ToStatusNEQ applies the NEQ predicate on the "toStatus" field. +func ToStatusNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldToStatus, v)) +} + +// ToStatusIn applies the In predicate on the "toStatus" field. +func ToStatusIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldToStatus, vs...)) +} + +// ToStatusNotIn applies the NotIn predicate on the "toStatus" field. +func ToStatusNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldToStatus, vs...)) +} + +// ToStatusGT applies the GT predicate on the "toStatus" field. +func ToStatusGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldToStatus, v)) +} + +// ToStatusGTE applies the GTE predicate on the "toStatus" field. +func ToStatusGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldToStatus, v)) +} + +// ToStatusLT applies the LT predicate on the "toStatus" field. +func ToStatusLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldToStatus, v)) +} + +// ToStatusLTE applies the LTE predicate on the "toStatus" field. +func ToStatusLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldToStatus, v)) +} + +// ToStatusContains applies the Contains predicate on the "toStatus" field. +func ToStatusContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldToStatus, v)) +} + +// ToStatusHasPrefix applies the HasPrefix predicate on the "toStatus" field. +func ToStatusHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldToStatus, v)) +} + +// ToStatusHasSuffix applies the HasSuffix predicate on the "toStatus" field. +func ToStatusHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldToStatus, v)) +} + +// ToStatusEqualFold applies the EqualFold predicate on the "toStatus" field. +func ToStatusEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldToStatus, v)) +} + +// ToStatusContainsFold applies the ContainsFold predicate on the "toStatus" field. +func ToStatusContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldToStatus, v)) +} + +// StationNoEQ applies the EQ predicate on the "stationNo" field. +func StationNoEQ(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldStationNo, v)) +} + +// StationNoNEQ applies the NEQ predicate on the "stationNo" field. +func StationNoNEQ(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldStationNo, v)) +} + +// StationNoIn applies the In predicate on the "stationNo" field. +func StationNoIn(vs ...int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldStationNo, vs...)) +} + +// StationNoNotIn applies the NotIn predicate on the "stationNo" field. +func StationNoNotIn(vs ...int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldStationNo, vs...)) +} + +// StationNoGT applies the GT predicate on the "stationNo" field. +func StationNoGT(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldStationNo, v)) +} + +// StationNoGTE applies the GTE predicate on the "stationNo" field. +func StationNoGTE(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldStationNo, v)) +} + +// StationNoLT applies the LT predicate on the "stationNo" field. +func StationNoLT(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldStationNo, v)) +} + +// StationNoLTE applies the LTE predicate on the "stationNo" field. +func StationNoLTE(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldStationNo, v)) +} + +// StationNoIsNil applies the IsNil predicate on the "stationNo" field. +func StationNoIsNil() predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIsNull(FieldStationNo)) +} + +// StationNoNotNil applies the NotNil predicate on the "stationNo" field. +func StationNoNotNil() predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotNull(FieldStationNo)) +} + +// FlowSeqEQ applies the EQ predicate on the "flowSeq" field. +func FlowSeqEQ(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldFlowSeq, v)) +} + +// FlowSeqNEQ applies the NEQ predicate on the "flowSeq" field. +func FlowSeqNEQ(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldFlowSeq, v)) +} + +// FlowSeqIn applies the In predicate on the "flowSeq" field. +func FlowSeqIn(vs ...int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldFlowSeq, vs...)) +} + +// FlowSeqNotIn applies the NotIn predicate on the "flowSeq" field. +func FlowSeqNotIn(vs ...int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldFlowSeq, vs...)) +} + +// FlowSeqGT applies the GT predicate on the "flowSeq" field. +func FlowSeqGT(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldFlowSeq, v)) +} + +// FlowSeqGTE applies the GTE predicate on the "flowSeq" field. +func FlowSeqGTE(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldFlowSeq, v)) +} + +// FlowSeqLT applies the LT predicate on the "flowSeq" field. +func FlowSeqLT(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldFlowSeq, v)) +} + +// FlowSeqLTE applies the LTE predicate on the "flowSeq" field. +func FlowSeqLTE(v int) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldFlowSeq, v)) +} + +// FlowSeqIsNil applies the IsNil predicate on the "flowSeq" field. +func FlowSeqIsNil() predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIsNull(FieldFlowSeq)) +} + +// FlowSeqNotNil applies the NotNil predicate on the "flowSeq" field. +func FlowSeqNotNil() predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotNull(FieldFlowSeq)) +} + +// OperatorEQ applies the EQ predicate on the "operator" field. +func OperatorEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldOperator, v)) +} + +// OperatorNEQ applies the NEQ predicate on the "operator" field. +func OperatorNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldOperator, v)) +} + +// OperatorIn applies the In predicate on the "operator" field. +func OperatorIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldOperator, vs...)) +} + +// OperatorNotIn applies the NotIn predicate on the "operator" field. +func OperatorNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldOperator, vs...)) +} + +// OperatorGT applies the GT predicate on the "operator" field. +func OperatorGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldOperator, v)) +} + +// OperatorGTE applies the GTE predicate on the "operator" field. +func OperatorGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldOperator, v)) +} + +// OperatorLT applies the LT predicate on the "operator" field. +func OperatorLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldOperator, v)) +} + +// OperatorLTE applies the LTE predicate on the "operator" field. +func OperatorLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldOperator, v)) +} + +// OperatorContains applies the Contains predicate on the "operator" field. +func OperatorContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldOperator, v)) +} + +// OperatorHasPrefix applies the HasPrefix predicate on the "operator" field. +func OperatorHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldOperator, v)) +} + +// OperatorHasSuffix applies the HasSuffix predicate on the "operator" field. +func OperatorHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldOperator, v)) +} + +// OperatorEqualFold applies the EqualFold predicate on the "operator" field. +func OperatorEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldOperator, v)) +} + +// OperatorContainsFold applies the ContainsFold predicate on the "operator" field. +func OperatorContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldOperator, v)) +} + +// SourceEQ applies the EQ predicate on the "source" field. +func SourceEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldSource, v)) +} + +// SourceNEQ applies the NEQ predicate on the "source" field. +func SourceNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldSource, v)) +} + +// SourceIn applies the In predicate on the "source" field. +func SourceIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldSource, vs...)) +} + +// SourceNotIn applies the NotIn predicate on the "source" field. +func SourceNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldSource, vs...)) +} + +// SourceGT applies the GT predicate on the "source" field. +func SourceGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldSource, v)) +} + +// SourceGTE applies the GTE predicate on the "source" field. +func SourceGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldSource, v)) +} + +// SourceLT applies the LT predicate on the "source" field. +func SourceLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldSource, v)) +} + +// SourceLTE applies the LTE predicate on the "source" field. +func SourceLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldSource, v)) +} + +// SourceContains applies the Contains predicate on the "source" field. +func SourceContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldSource, v)) +} + +// SourceHasPrefix applies the HasPrefix predicate on the "source" field. +func SourceHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldSource, v)) +} + +// SourceHasSuffix applies the HasSuffix predicate on the "source" field. +func SourceHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldSource, v)) +} + +// SourceEqualFold applies the EqualFold predicate on the "source" field. +func SourceEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldSource, v)) +} + +// SourceContainsFold applies the ContainsFold predicate on the "source" field. +func SourceContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldSource, v)) +} + +// RemarkEQ applies the EQ predicate on the "remark" field. +func RemarkEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldRemark, v)) +} + +// RemarkNEQ applies the NEQ predicate on the "remark" field. +func RemarkNEQ(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldRemark, v)) +} + +// RemarkIn applies the In predicate on the "remark" field. +func RemarkIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldRemark, vs...)) +} + +// RemarkNotIn applies the NotIn predicate on the "remark" field. +func RemarkNotIn(vs ...string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldRemark, vs...)) +} + +// RemarkGT applies the GT predicate on the "remark" field. +func RemarkGT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldRemark, v)) +} + +// RemarkGTE applies the GTE predicate on the "remark" field. +func RemarkGTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldRemark, v)) +} + +// RemarkLT applies the LT predicate on the "remark" field. +func RemarkLT(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldRemark, v)) +} + +// RemarkLTE applies the LTE predicate on the "remark" field. +func RemarkLTE(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldRemark, v)) +} + +// RemarkContains applies the Contains predicate on the "remark" field. +func RemarkContains(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContains(FieldRemark, v)) +} + +// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. +func RemarkHasPrefix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasPrefix(FieldRemark, v)) +} + +// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. +func RemarkHasSuffix(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldHasSuffix(FieldRemark, v)) +} + +// RemarkEqualFold applies the EqualFold predicate on the "remark" field. +func RemarkEqualFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEqualFold(FieldRemark, v)) +} + +// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. +func RemarkContainsFold(v string) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldContainsFold(FieldRemark, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +func CreatedAtEQ(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +func CreatedAtNEQ(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "createdAt" field. +func CreatedAtIn(vs ...time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +func CreatedAtNotIn(vs ...time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "createdAt" field. +func CreatedAtGT(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +func CreatedAtGTE(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "createdAt" field. +func CreatedAtLT(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +func CreatedAtLTE(v time.Time) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.FieldLTE(FieldCreatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.WorkpieceLifecycleLog) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.WorkpieceLifecycleLog) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.WorkpieceLifecycleLog) predicate.WorkpieceLifecycleLog { + return predicate.WorkpieceLifecycleLog(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/workpiecelifecyclelog/workpiecelifecyclelog.go b/bj_power_mes/ent/workpiecelifecyclelog/workpiecelifecyclelog.go new file mode 100644 index 0000000..bde8574 --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog/workpiecelifecyclelog.go @@ -0,0 +1,164 @@ +// Code generated by ent, DO NOT EDIT. + +package workpiecelifecyclelog + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the workpiecelifecyclelog type in the database. + Label = "workpiece_lifecycle_log" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldSn holds the string denoting the sn field in the database. + FieldSn = "sn" + // FieldWorkOrderNo holds the string denoting the workorderno field in the database. + FieldWorkOrderNo = "work_order_no" + // FieldAction holds the string denoting the action field in the database. + FieldAction = "action" + // FieldFromStatus holds the string denoting the fromstatus field in the database. + FieldFromStatus = "from_status" + // FieldToStatus holds the string denoting the tostatus field in the database. + FieldToStatus = "to_status" + // FieldStationNo holds the string denoting the stationno field in the database. + FieldStationNo = "station_no" + // FieldFlowSeq holds the string denoting the flowseq field in the database. + FieldFlowSeq = "flow_seq" + // FieldOperator holds the string denoting the operator field in the database. + FieldOperator = "operator" + // FieldSource holds the string denoting the source field in the database. + FieldSource = "source" + // FieldRemark holds the string denoting the remark field in the database. + FieldRemark = "remark" + // FieldCreatedAt holds the string denoting the createdat field in the database. + FieldCreatedAt = "created_at" + // Table holds the table name of the workpiecelifecyclelog in the database. + Table = "workpiece_lifecycle_log" +) + +// Columns holds all SQL columns for workpiecelifecyclelog fields. +var Columns = []string{ + FieldID, + FieldSn, + FieldWorkOrderNo, + FieldAction, + FieldFromStatus, + FieldToStatus, + FieldStationNo, + FieldFlowSeq, + FieldOperator, + FieldSource, + FieldRemark, + FieldCreatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // SnValidator is a validator for the "sn" field. It is called by the builders before save. + SnValidator func(string) error + // DefaultWorkOrderNo holds the default value on creation for the "workOrderNo" field. + DefaultWorkOrderNo string + // WorkOrderNoValidator is a validator for the "workOrderNo" field. It is called by the builders before save. + WorkOrderNoValidator func(string) error + // ActionValidator is a validator for the "action" field. It is called by the builders before save. + ActionValidator func(string) error + // DefaultFromStatus holds the default value on creation for the "fromStatus" field. + DefaultFromStatus string + // FromStatusValidator is a validator for the "fromStatus" field. It is called by the builders before save. + FromStatusValidator func(string) error + // DefaultToStatus holds the default value on creation for the "toStatus" field. + DefaultToStatus string + // ToStatusValidator is a validator for the "toStatus" field. It is called by the builders before save. + ToStatusValidator func(string) error + // DefaultOperator holds the default value on creation for the "operator" field. + DefaultOperator string + // OperatorValidator is a validator for the "operator" field. It is called by the builders before save. + OperatorValidator func(string) error + // DefaultSource holds the default value on creation for the "source" field. + DefaultSource string + // SourceValidator is a validator for the "source" field. It is called by the builders before save. + SourceValidator func(string) error + // DefaultRemark holds the default value on creation for the "remark" field. + DefaultRemark string + // RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + RemarkValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + DefaultCreatedAt func() time.Time + // IDValidator is a validator for the "id" field. It is called by the builders before save. + IDValidator func(int) error +) + +// OrderOption defines the ordering options for the WorkpieceLifecycleLog queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// BySn orders the results by the sn field. +func BySn(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSn, opts...).ToFunc() +} + +// ByWorkOrderNo orders the results by the workOrderNo field. +func ByWorkOrderNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldWorkOrderNo, opts...).ToFunc() +} + +// ByAction orders the results by the action field. +func ByAction(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAction, opts...).ToFunc() +} + +// ByFromStatus orders the results by the fromStatus field. +func ByFromStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFromStatus, opts...).ToFunc() +} + +// ByToStatus orders the results by the toStatus field. +func ByToStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldToStatus, opts...).ToFunc() +} + +// ByStationNo orders the results by the stationNo field. +func ByStationNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStationNo, opts...).ToFunc() +} + +// ByFlowSeq orders the results by the flowSeq field. +func ByFlowSeq(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFlowSeq, opts...).ToFunc() +} + +// ByOperator orders the results by the operator field. +func ByOperator(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOperator, opts...).ToFunc() +} + +// BySource orders the results by the source field. +func BySource(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSource, opts...).ToFunc() +} + +// ByRemark orders the results by the remark field. +func ByRemark(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRemark, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the createdAt field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} diff --git a/bj_power_mes/ent/workpiecelifecyclelog_create.go b/bj_power_mes/ent/workpiecelifecyclelog_create.go new file mode 100644 index 0000000..7483e4e --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog_create.go @@ -0,0 +1,471 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/workpiecelifecyclelog" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// WorkpieceLifecycleLogCreate is the builder for creating a WorkpieceLifecycleLog entity. +type WorkpieceLifecycleLogCreate struct { + config + mutation *WorkpieceLifecycleLogMutation + hooks []Hook +} + +// SetSn sets the "sn" field. +func (_c *WorkpieceLifecycleLogCreate) SetSn(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetSn(v) + return _c +} + +// SetWorkOrderNo sets the "workOrderNo" field. +func (_c *WorkpieceLifecycleLogCreate) SetWorkOrderNo(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetWorkOrderNo(v) + return _c +} + +// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableWorkOrderNo(v *string) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetWorkOrderNo(*v) + } + return _c +} + +// SetAction sets the "action" field. +func (_c *WorkpieceLifecycleLogCreate) SetAction(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetAction(v) + return _c +} + +// SetFromStatus sets the "fromStatus" field. +func (_c *WorkpieceLifecycleLogCreate) SetFromStatus(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetFromStatus(v) + return _c +} + +// SetNillableFromStatus sets the "fromStatus" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableFromStatus(v *string) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetFromStatus(*v) + } + return _c +} + +// SetToStatus sets the "toStatus" field. +func (_c *WorkpieceLifecycleLogCreate) SetToStatus(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetToStatus(v) + return _c +} + +// SetNillableToStatus sets the "toStatus" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableToStatus(v *string) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetToStatus(*v) + } + return _c +} + +// SetStationNo sets the "stationNo" field. +func (_c *WorkpieceLifecycleLogCreate) SetStationNo(v int) *WorkpieceLifecycleLogCreate { + _c.mutation.SetStationNo(v) + return _c +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableStationNo(v *int) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetStationNo(*v) + } + return _c +} + +// SetFlowSeq sets the "flowSeq" field. +func (_c *WorkpieceLifecycleLogCreate) SetFlowSeq(v int) *WorkpieceLifecycleLogCreate { + _c.mutation.SetFlowSeq(v) + return _c +} + +// SetNillableFlowSeq sets the "flowSeq" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableFlowSeq(v *int) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetFlowSeq(*v) + } + return _c +} + +// SetOperator sets the "operator" field. +func (_c *WorkpieceLifecycleLogCreate) SetOperator(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetOperator(v) + return _c +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableOperator(v *string) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetOperator(*v) + } + return _c +} + +// SetSource sets the "source" field. +func (_c *WorkpieceLifecycleLogCreate) SetSource(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetSource(v) + return _c +} + +// SetNillableSource sets the "source" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableSource(v *string) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetSource(*v) + } + return _c +} + +// SetRemark sets the "remark" field. +func (_c *WorkpieceLifecycleLogCreate) SetRemark(v string) *WorkpieceLifecycleLogCreate { + _c.mutation.SetRemark(v) + return _c +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableRemark(v *string) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetRemark(*v) + } + return _c +} + +// SetCreatedAt sets the "createdAt" field. +func (_c *WorkpieceLifecycleLogCreate) SetCreatedAt(v time.Time) *WorkpieceLifecycleLogCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (_c *WorkpieceLifecycleLogCreate) SetNillableCreatedAt(v *time.Time) *WorkpieceLifecycleLogCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *WorkpieceLifecycleLogCreate) SetID(v int) *WorkpieceLifecycleLogCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the WorkpieceLifecycleLogMutation object of the builder. +func (_c *WorkpieceLifecycleLogCreate) Mutation() *WorkpieceLifecycleLogMutation { + return _c.mutation +} + +// Save creates the WorkpieceLifecycleLog in the database. +func (_c *WorkpieceLifecycleLogCreate) Save(ctx context.Context) (*WorkpieceLifecycleLog, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *WorkpieceLifecycleLogCreate) SaveX(ctx context.Context) *WorkpieceLifecycleLog { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *WorkpieceLifecycleLogCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *WorkpieceLifecycleLogCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *WorkpieceLifecycleLogCreate) defaults() { + if _, ok := _c.mutation.WorkOrderNo(); !ok { + v := workpiecelifecyclelog.DefaultWorkOrderNo + _c.mutation.SetWorkOrderNo(v) + } + if _, ok := _c.mutation.FromStatus(); !ok { + v := workpiecelifecyclelog.DefaultFromStatus + _c.mutation.SetFromStatus(v) + } + if _, ok := _c.mutation.ToStatus(); !ok { + v := workpiecelifecyclelog.DefaultToStatus + _c.mutation.SetToStatus(v) + } + if _, ok := _c.mutation.Operator(); !ok { + v := workpiecelifecyclelog.DefaultOperator + _c.mutation.SetOperator(v) + } + if _, ok := _c.mutation.Source(); !ok { + v := workpiecelifecyclelog.DefaultSource + _c.mutation.SetSource(v) + } + if _, ok := _c.mutation.Remark(); !ok { + v := workpiecelifecyclelog.DefaultRemark + _c.mutation.SetRemark(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := workpiecelifecyclelog.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *WorkpieceLifecycleLogCreate) check() error { + if _, ok := _c.mutation.Sn(); !ok { + return &ValidationError{Name: "sn", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.sn"`)} + } + if v, ok := _c.mutation.Sn(); ok { + if err := workpiecelifecyclelog.SnValidator(v); err != nil { + return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.sn": %w`, err)} + } + } + if _, ok := _c.mutation.WorkOrderNo(); !ok { + return &ValidationError{Name: "workOrderNo", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.workOrderNo"`)} + } + if v, ok := _c.mutation.WorkOrderNo(); ok { + if err := workpiecelifecyclelog.WorkOrderNoValidator(v); err != nil { + return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.workOrderNo": %w`, err)} + } + } + if _, ok := _c.mutation.Action(); !ok { + return &ValidationError{Name: "action", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.action"`)} + } + if v, ok := _c.mutation.Action(); ok { + if err := workpiecelifecyclelog.ActionValidator(v); err != nil { + return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.action": %w`, err)} + } + } + if _, ok := _c.mutation.FromStatus(); !ok { + return &ValidationError{Name: "fromStatus", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.fromStatus"`)} + } + if v, ok := _c.mutation.FromStatus(); ok { + if err := workpiecelifecyclelog.FromStatusValidator(v); err != nil { + return &ValidationError{Name: "fromStatus", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.fromStatus": %w`, err)} + } + } + if _, ok := _c.mutation.ToStatus(); !ok { + return &ValidationError{Name: "toStatus", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.toStatus"`)} + } + if v, ok := _c.mutation.ToStatus(); ok { + if err := workpiecelifecyclelog.ToStatusValidator(v); err != nil { + return &ValidationError{Name: "toStatus", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.toStatus": %w`, err)} + } + } + if _, ok := _c.mutation.Operator(); !ok { + return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.operator"`)} + } + if v, ok := _c.mutation.Operator(); ok { + if err := workpiecelifecyclelog.OperatorValidator(v); err != nil { + return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.operator": %w`, err)} + } + } + if _, ok := _c.mutation.Source(); !ok { + return &ValidationError{Name: "source", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.source"`)} + } + if v, ok := _c.mutation.Source(); ok { + if err := workpiecelifecyclelog.SourceValidator(v); err != nil { + return &ValidationError{Name: "source", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.source": %w`, err)} + } + } + if _, ok := _c.mutation.Remark(); !ok { + return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.remark"`)} + } + if v, ok := _c.mutation.Remark(); ok { + if err := workpiecelifecyclelog.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.remark": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "WorkpieceLifecycleLog.createdAt"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := workpiecelifecyclelog.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.id": %w`, err)} + } + } + return nil +} + +func (_c *WorkpieceLifecycleLogCreate) sqlSave(ctx context.Context) (*WorkpieceLifecycleLog, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int(id) + } + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *WorkpieceLifecycleLogCreate) createSpec() (*WorkpieceLifecycleLog, *sqlgraph.CreateSpec) { + var ( + _node = &WorkpieceLifecycleLog{config: _c.config} + _spec = sqlgraph.NewCreateSpec(workpiecelifecyclelog.Table, sqlgraph.NewFieldSpec(workpiecelifecyclelog.FieldID, field.TypeInt)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.Sn(); ok { + _spec.SetField(workpiecelifecyclelog.FieldSn, field.TypeString, value) + _node.Sn = value + } + if value, ok := _c.mutation.WorkOrderNo(); ok { + _spec.SetField(workpiecelifecyclelog.FieldWorkOrderNo, field.TypeString, value) + _node.WorkOrderNo = value + } + if value, ok := _c.mutation.Action(); ok { + _spec.SetField(workpiecelifecyclelog.FieldAction, field.TypeString, value) + _node.Action = value + } + if value, ok := _c.mutation.FromStatus(); ok { + _spec.SetField(workpiecelifecyclelog.FieldFromStatus, field.TypeString, value) + _node.FromStatus = value + } + if value, ok := _c.mutation.ToStatus(); ok { + _spec.SetField(workpiecelifecyclelog.FieldToStatus, field.TypeString, value) + _node.ToStatus = value + } + if value, ok := _c.mutation.StationNo(); ok { + _spec.SetField(workpiecelifecyclelog.FieldStationNo, field.TypeInt, value) + _node.StationNo = value + } + if value, ok := _c.mutation.FlowSeq(); ok { + _spec.SetField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt, value) + _node.FlowSeq = value + } + if value, ok := _c.mutation.Operator(); ok { + _spec.SetField(workpiecelifecyclelog.FieldOperator, field.TypeString, value) + _node.Operator = value + } + if value, ok := _c.mutation.Source(); ok { + _spec.SetField(workpiecelifecyclelog.FieldSource, field.TypeString, value) + _node.Source = value + } + if value, ok := _c.mutation.Remark(); ok { + _spec.SetField(workpiecelifecyclelog.FieldRemark, field.TypeString, value) + _node.Remark = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(workpiecelifecyclelog.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + return _node, _spec +} + +// WorkpieceLifecycleLogCreateBulk is the builder for creating many WorkpieceLifecycleLog entities in bulk. +type WorkpieceLifecycleLogCreateBulk struct { + config + err error + builders []*WorkpieceLifecycleLogCreate +} + +// Save creates the WorkpieceLifecycleLog entities in the database. +func (_c *WorkpieceLifecycleLogCreateBulk) Save(ctx context.Context) ([]*WorkpieceLifecycleLog, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*WorkpieceLifecycleLog, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*WorkpieceLifecycleLogMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *WorkpieceLifecycleLogCreateBulk) SaveX(ctx context.Context) []*WorkpieceLifecycleLog { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *WorkpieceLifecycleLogCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *WorkpieceLifecycleLogCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/workpiecelifecyclelog_delete.go b/bj_power_mes/ent/workpiecelifecyclelog_delete.go new file mode 100644 index 0000000..98717df --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/workpiecelifecyclelog" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// WorkpieceLifecycleLogDelete is the builder for deleting a WorkpieceLifecycleLog entity. +type WorkpieceLifecycleLogDelete struct { + config + hooks []Hook + mutation *WorkpieceLifecycleLogMutation +} + +// Where appends a list predicates to the WorkpieceLifecycleLogDelete builder. +func (_d *WorkpieceLifecycleLogDelete) Where(ps ...predicate.WorkpieceLifecycleLog) *WorkpieceLifecycleLogDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *WorkpieceLifecycleLogDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *WorkpieceLifecycleLogDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *WorkpieceLifecycleLogDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(workpiecelifecyclelog.Table, sqlgraph.NewFieldSpec(workpiecelifecyclelog.FieldID, field.TypeInt)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// WorkpieceLifecycleLogDeleteOne is the builder for deleting a single WorkpieceLifecycleLog entity. +type WorkpieceLifecycleLogDeleteOne struct { + _d *WorkpieceLifecycleLogDelete +} + +// Where appends a list predicates to the WorkpieceLifecycleLogDelete builder. +func (_d *WorkpieceLifecycleLogDeleteOne) Where(ps ...predicate.WorkpieceLifecycleLog) *WorkpieceLifecycleLogDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *WorkpieceLifecycleLogDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{workpiecelifecyclelog.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *WorkpieceLifecycleLogDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/workpiecelifecyclelog_query.go b/bj_power_mes/ent/workpiecelifecyclelog_query.go new file mode 100644 index 0000000..aadc652 --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/workpiecelifecyclelog" + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// WorkpieceLifecycleLogQuery is the builder for querying WorkpieceLifecycleLog entities. +type WorkpieceLifecycleLogQuery struct { + config + ctx *QueryContext + order []workpiecelifecyclelog.OrderOption + inters []Interceptor + predicates []predicate.WorkpieceLifecycleLog + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the WorkpieceLifecycleLogQuery builder. +func (_q *WorkpieceLifecycleLogQuery) Where(ps ...predicate.WorkpieceLifecycleLog) *WorkpieceLifecycleLogQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *WorkpieceLifecycleLogQuery) Limit(limit int) *WorkpieceLifecycleLogQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *WorkpieceLifecycleLogQuery) Offset(offset int) *WorkpieceLifecycleLogQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *WorkpieceLifecycleLogQuery) Unique(unique bool) *WorkpieceLifecycleLogQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *WorkpieceLifecycleLogQuery) Order(o ...workpiecelifecyclelog.OrderOption) *WorkpieceLifecycleLogQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first WorkpieceLifecycleLog entity from the query. +// Returns a *NotFoundError when no WorkpieceLifecycleLog was found. +func (_q *WorkpieceLifecycleLogQuery) First(ctx context.Context) (*WorkpieceLifecycleLog, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{workpiecelifecyclelog.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) FirstX(ctx context.Context) *WorkpieceLifecycleLog { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first WorkpieceLifecycleLog ID from the query. +// Returns a *NotFoundError when no WorkpieceLifecycleLog ID was found. +func (_q *WorkpieceLifecycleLogQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{workpiecelifecyclelog.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single WorkpieceLifecycleLog entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one WorkpieceLifecycleLog entity is found. +// Returns a *NotFoundError when no WorkpieceLifecycleLog entities are found. +func (_q *WorkpieceLifecycleLogQuery) Only(ctx context.Context) (*WorkpieceLifecycleLog, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{workpiecelifecyclelog.Label} + default: + return nil, &NotSingularError{workpiecelifecyclelog.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) OnlyX(ctx context.Context) *WorkpieceLifecycleLog { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only WorkpieceLifecycleLog ID in the query. +// Returns a *NotSingularError when more than one WorkpieceLifecycleLog ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *WorkpieceLifecycleLogQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{workpiecelifecyclelog.Label} + default: + err = &NotSingularError{workpiecelifecyclelog.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) OnlyIDX(ctx context.Context) int { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of WorkpieceLifecycleLogs. +func (_q *WorkpieceLifecycleLogQuery) All(ctx context.Context) ([]*WorkpieceLifecycleLog, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*WorkpieceLifecycleLog, *WorkpieceLifecycleLogQuery]() + return withInterceptors[[]*WorkpieceLifecycleLog](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) AllX(ctx context.Context) []*WorkpieceLifecycleLog { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of WorkpieceLifecycleLog IDs. +func (_q *WorkpieceLifecycleLogQuery) IDs(ctx context.Context) (ids []int, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(workpiecelifecyclelog.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) IDsX(ctx context.Context) []int { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *WorkpieceLifecycleLogQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*WorkpieceLifecycleLogQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *WorkpieceLifecycleLogQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *WorkpieceLifecycleLogQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the WorkpieceLifecycleLogQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *WorkpieceLifecycleLogQuery) Clone() *WorkpieceLifecycleLogQuery { + if _q == nil { + return nil + } + return &WorkpieceLifecycleLogQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]workpiecelifecyclelog.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.WorkpieceLifecycleLog{}, _q.predicates...), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Sn string `json:"sn,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.WorkpieceLifecycleLog.Query(). +// GroupBy(workpiecelifecyclelog.FieldSn). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *WorkpieceLifecycleLogQuery) GroupBy(field string, fields ...string) *WorkpieceLifecycleLogGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &WorkpieceLifecycleLogGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = workpiecelifecyclelog.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Sn string `json:"sn,omitempty"` +// } +// +// client.WorkpieceLifecycleLog.Query(). +// Select(workpiecelifecyclelog.FieldSn). +// Scan(ctx, &v) +func (_q *WorkpieceLifecycleLogQuery) Select(fields ...string) *WorkpieceLifecycleLogSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &WorkpieceLifecycleLogSelect{WorkpieceLifecycleLogQuery: _q} + sbuild.label = workpiecelifecyclelog.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a WorkpieceLifecycleLogSelect configured with the given aggregations. +func (_q *WorkpieceLifecycleLogQuery) Aggregate(fns ...AggregateFunc) *WorkpieceLifecycleLogSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *WorkpieceLifecycleLogQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !workpiecelifecyclelog.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *WorkpieceLifecycleLogQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*WorkpieceLifecycleLog, error) { + var ( + nodes = []*WorkpieceLifecycleLog{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*WorkpieceLifecycleLog).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &WorkpieceLifecycleLog{config: _q.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (_q *WorkpieceLifecycleLogQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *WorkpieceLifecycleLogQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(workpiecelifecyclelog.Table, workpiecelifecyclelog.Columns, sqlgraph.NewFieldSpec(workpiecelifecyclelog.FieldID, field.TypeInt)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, workpiecelifecyclelog.FieldID) + for i := range fields { + if fields[i] != workpiecelifecyclelog.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *WorkpieceLifecycleLogQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(workpiecelifecyclelog.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = workpiecelifecyclelog.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ForUpdate locks the selected rows against concurrent updates, and prevent them from being +// updated, deleted or "selected ... for update" by other sessions, until the transaction is +// either committed or rolled-back. +func (_q *WorkpieceLifecycleLogQuery) ForUpdate(opts ...sql.LockOption) *WorkpieceLifecycleLogQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock +// on any rows that are read. Other sessions can read the rows, but cannot modify them +// until your transaction commits. +func (_q *WorkpieceLifecycleLogQuery) ForShare(opts ...sql.LockOption) *WorkpieceLifecycleLogQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_q *WorkpieceLifecycleLogQuery) Modify(modifiers ...func(s *sql.Selector)) *WorkpieceLifecycleLogSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// WorkpieceLifecycleLogGroupBy is the group-by builder for WorkpieceLifecycleLog entities. +type WorkpieceLifecycleLogGroupBy struct { + selector + build *WorkpieceLifecycleLogQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *WorkpieceLifecycleLogGroupBy) Aggregate(fns ...AggregateFunc) *WorkpieceLifecycleLogGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *WorkpieceLifecycleLogGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*WorkpieceLifecycleLogQuery, *WorkpieceLifecycleLogGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *WorkpieceLifecycleLogGroupBy) sqlScan(ctx context.Context, root *WorkpieceLifecycleLogQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// WorkpieceLifecycleLogSelect is the builder for selecting fields of WorkpieceLifecycleLog entities. +type WorkpieceLifecycleLogSelect struct { + *WorkpieceLifecycleLogQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *WorkpieceLifecycleLogSelect) Aggregate(fns ...AggregateFunc) *WorkpieceLifecycleLogSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *WorkpieceLifecycleLogSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*WorkpieceLifecycleLogQuery, *WorkpieceLifecycleLogSelect](ctx, _s.WorkpieceLifecycleLogQuery, _s, _s.inters, v) +} + +func (_s *WorkpieceLifecycleLogSelect) sqlScan(ctx context.Context, root *WorkpieceLifecycleLogQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_s *WorkpieceLifecycleLogSelect) Modify(modifiers ...func(s *sql.Selector)) *WorkpieceLifecycleLogSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/workpiecelifecyclelog_update.go b/bj_power_mes/ent/workpiecelifecyclelog_update.go new file mode 100644 index 0000000..02a6338 --- /dev/null +++ b/bj_power_mes/ent/workpiecelifecyclelog_update.go @@ -0,0 +1,703 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/workpiecelifecyclelog" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// WorkpieceLifecycleLogUpdate is the builder for updating WorkpieceLifecycleLog entities. +type WorkpieceLifecycleLogUpdate struct { + config + hooks []Hook + mutation *WorkpieceLifecycleLogMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the WorkpieceLifecycleLogUpdate builder. +func (_u *WorkpieceLifecycleLogUpdate) Where(ps ...predicate.WorkpieceLifecycleLog) *WorkpieceLifecycleLogUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetSn sets the "sn" field. +func (_u *WorkpieceLifecycleLogUpdate) SetSn(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetSn(v) + return _u +} + +// SetNillableSn sets the "sn" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableSn(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetSn(*v) + } + return _u +} + +// SetWorkOrderNo sets the "workOrderNo" field. +func (_u *WorkpieceLifecycleLogUpdate) SetWorkOrderNo(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetWorkOrderNo(v) + return _u +} + +// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableWorkOrderNo(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetWorkOrderNo(*v) + } + return _u +} + +// SetAction sets the "action" field. +func (_u *WorkpieceLifecycleLogUpdate) SetAction(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetAction(v) + return _u +} + +// SetNillableAction sets the "action" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableAction(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetAction(*v) + } + return _u +} + +// SetFromStatus sets the "fromStatus" field. +func (_u *WorkpieceLifecycleLogUpdate) SetFromStatus(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetFromStatus(v) + return _u +} + +// SetNillableFromStatus sets the "fromStatus" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableFromStatus(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetFromStatus(*v) + } + return _u +} + +// SetToStatus sets the "toStatus" field. +func (_u *WorkpieceLifecycleLogUpdate) SetToStatus(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetToStatus(v) + return _u +} + +// SetNillableToStatus sets the "toStatus" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableToStatus(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetToStatus(*v) + } + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *WorkpieceLifecycleLogUpdate) SetStationNo(v int) *WorkpieceLifecycleLogUpdate { + _u.mutation.ResetStationNo() + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableStationNo(v *int) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// AddStationNo adds value to the "stationNo" field. +func (_u *WorkpieceLifecycleLogUpdate) AddStationNo(v int) *WorkpieceLifecycleLogUpdate { + _u.mutation.AddStationNo(v) + return _u +} + +// ClearStationNo clears the value of the "stationNo" field. +func (_u *WorkpieceLifecycleLogUpdate) ClearStationNo() *WorkpieceLifecycleLogUpdate { + _u.mutation.ClearStationNo() + return _u +} + +// SetFlowSeq sets the "flowSeq" field. +func (_u *WorkpieceLifecycleLogUpdate) SetFlowSeq(v int) *WorkpieceLifecycleLogUpdate { + _u.mutation.ResetFlowSeq() + _u.mutation.SetFlowSeq(v) + return _u +} + +// SetNillableFlowSeq sets the "flowSeq" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableFlowSeq(v *int) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetFlowSeq(*v) + } + return _u +} + +// AddFlowSeq adds value to the "flowSeq" field. +func (_u *WorkpieceLifecycleLogUpdate) AddFlowSeq(v int) *WorkpieceLifecycleLogUpdate { + _u.mutation.AddFlowSeq(v) + return _u +} + +// ClearFlowSeq clears the value of the "flowSeq" field. +func (_u *WorkpieceLifecycleLogUpdate) ClearFlowSeq() *WorkpieceLifecycleLogUpdate { + _u.mutation.ClearFlowSeq() + return _u +} + +// SetOperator sets the "operator" field. +func (_u *WorkpieceLifecycleLogUpdate) SetOperator(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetOperator(v) + return _u +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableOperator(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetOperator(*v) + } + return _u +} + +// SetSource sets the "source" field. +func (_u *WorkpieceLifecycleLogUpdate) SetSource(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetSource(v) + return _u +} + +// SetNillableSource sets the "source" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableSource(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetSource(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *WorkpieceLifecycleLogUpdate) SetRemark(v string) *WorkpieceLifecycleLogUpdate { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdate) SetNillableRemark(v *string) *WorkpieceLifecycleLogUpdate { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// Mutation returns the WorkpieceLifecycleLogMutation object of the builder. +func (_u *WorkpieceLifecycleLogUpdate) Mutation() *WorkpieceLifecycleLogMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *WorkpieceLifecycleLogUpdate) 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 *WorkpieceLifecycleLogUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *WorkpieceLifecycleLogUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *WorkpieceLifecycleLogUpdate) 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 *WorkpieceLifecycleLogUpdate) check() error { + if v, ok := _u.mutation.Sn(); ok { + if err := workpiecelifecyclelog.SnValidator(v); err != nil { + return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.sn": %w`, err)} + } + } + if v, ok := _u.mutation.WorkOrderNo(); ok { + if err := workpiecelifecyclelog.WorkOrderNoValidator(v); err != nil { + return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.workOrderNo": %w`, err)} + } + } + if v, ok := _u.mutation.Action(); ok { + if err := workpiecelifecyclelog.ActionValidator(v); err != nil { + return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.action": %w`, err)} + } + } + if v, ok := _u.mutation.FromStatus(); ok { + if err := workpiecelifecyclelog.FromStatusValidator(v); err != nil { + return &ValidationError{Name: "fromStatus", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.fromStatus": %w`, err)} + } + } + if v, ok := _u.mutation.ToStatus(); ok { + if err := workpiecelifecyclelog.ToStatusValidator(v); err != nil { + return &ValidationError{Name: "toStatus", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.toStatus": %w`, err)} + } + } + if v, ok := _u.mutation.Operator(); ok { + if err := workpiecelifecyclelog.OperatorValidator(v); err != nil { + return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.operator": %w`, err)} + } + } + if v, ok := _u.mutation.Source(); ok { + if err := workpiecelifecyclelog.SourceValidator(v); err != nil { + return &ValidationError{Name: "source", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.source": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := workpiecelifecyclelog.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.remark": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *WorkpieceLifecycleLogUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WorkpieceLifecycleLogUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *WorkpieceLifecycleLogUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(workpiecelifecyclelog.Table, workpiecelifecyclelog.Columns, sqlgraph.NewFieldSpec(workpiecelifecyclelog.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.Sn(); ok { + _spec.SetField(workpiecelifecyclelog.FieldSn, field.TypeString, value) + } + if value, ok := _u.mutation.WorkOrderNo(); ok { + _spec.SetField(workpiecelifecyclelog.FieldWorkOrderNo, field.TypeString, value) + } + if value, ok := _u.mutation.Action(); ok { + _spec.SetField(workpiecelifecyclelog.FieldAction, field.TypeString, value) + } + if value, ok := _u.mutation.FromStatus(); ok { + _spec.SetField(workpiecelifecyclelog.FieldFromStatus, field.TypeString, value) + } + if value, ok := _u.mutation.ToStatus(); ok { + _spec.SetField(workpiecelifecyclelog.FieldToStatus, field.TypeString, value) + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(workpiecelifecyclelog.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedStationNo(); ok { + _spec.AddField(workpiecelifecyclelog.FieldStationNo, field.TypeInt, value) + } + if _u.mutation.StationNoCleared() { + _spec.ClearField(workpiecelifecyclelog.FieldStationNo, field.TypeInt) + } + if value, ok := _u.mutation.FlowSeq(); ok { + _spec.SetField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedFlowSeq(); ok { + _spec.AddField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt, value) + } + if _u.mutation.FlowSeqCleared() { + _spec.ClearField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt) + } + if value, ok := _u.mutation.Operator(); ok { + _spec.SetField(workpiecelifecyclelog.FieldOperator, field.TypeString, value) + } + if value, ok := _u.mutation.Source(); ok { + _spec.SetField(workpiecelifecyclelog.FieldSource, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(workpiecelifecyclelog.FieldRemark, 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{workpiecelifecyclelog.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// WorkpieceLifecycleLogUpdateOne is the builder for updating a single WorkpieceLifecycleLog entity. +type WorkpieceLifecycleLogUpdateOne struct { + config + fields []string + hooks []Hook + mutation *WorkpieceLifecycleLogMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetSn sets the "sn" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetSn(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetSn(v) + return _u +} + +// SetNillableSn sets the "sn" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableSn(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetSn(*v) + } + return _u +} + +// SetWorkOrderNo sets the "workOrderNo" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetWorkOrderNo(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetWorkOrderNo(v) + return _u +} + +// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableWorkOrderNo(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetWorkOrderNo(*v) + } + return _u +} + +// SetAction sets the "action" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetAction(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetAction(v) + return _u +} + +// SetNillableAction sets the "action" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableAction(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetAction(*v) + } + return _u +} + +// SetFromStatus sets the "fromStatus" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetFromStatus(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetFromStatus(v) + return _u +} + +// SetNillableFromStatus sets the "fromStatus" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableFromStatus(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetFromStatus(*v) + } + return _u +} + +// SetToStatus sets the "toStatus" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetToStatus(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetToStatus(v) + return _u +} + +// SetNillableToStatus sets the "toStatus" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableToStatus(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetToStatus(*v) + } + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetStationNo(v int) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.ResetStationNo() + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableStationNo(v *int) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// AddStationNo adds value to the "stationNo" field. +func (_u *WorkpieceLifecycleLogUpdateOne) AddStationNo(v int) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.AddStationNo(v) + return _u +} + +// ClearStationNo clears the value of the "stationNo" field. +func (_u *WorkpieceLifecycleLogUpdateOne) ClearStationNo() *WorkpieceLifecycleLogUpdateOne { + _u.mutation.ClearStationNo() + return _u +} + +// SetFlowSeq sets the "flowSeq" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetFlowSeq(v int) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.ResetFlowSeq() + _u.mutation.SetFlowSeq(v) + return _u +} + +// SetNillableFlowSeq sets the "flowSeq" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableFlowSeq(v *int) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetFlowSeq(*v) + } + return _u +} + +// AddFlowSeq adds value to the "flowSeq" field. +func (_u *WorkpieceLifecycleLogUpdateOne) AddFlowSeq(v int) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.AddFlowSeq(v) + return _u +} + +// ClearFlowSeq clears the value of the "flowSeq" field. +func (_u *WorkpieceLifecycleLogUpdateOne) ClearFlowSeq() *WorkpieceLifecycleLogUpdateOne { + _u.mutation.ClearFlowSeq() + return _u +} + +// SetOperator sets the "operator" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetOperator(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetOperator(v) + return _u +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableOperator(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetOperator(*v) + } + return _u +} + +// SetSource sets the "source" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetSource(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetSource(v) + return _u +} + +// SetNillableSource sets the "source" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableSource(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetSource(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *WorkpieceLifecycleLogUpdateOne) SetRemark(v string) *WorkpieceLifecycleLogUpdateOne { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *WorkpieceLifecycleLogUpdateOne) SetNillableRemark(v *string) *WorkpieceLifecycleLogUpdateOne { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// Mutation returns the WorkpieceLifecycleLogMutation object of the builder. +func (_u *WorkpieceLifecycleLogUpdateOne) Mutation() *WorkpieceLifecycleLogMutation { + return _u.mutation +} + +// Where appends a list predicates to the WorkpieceLifecycleLogUpdate builder. +func (_u *WorkpieceLifecycleLogUpdateOne) Where(ps ...predicate.WorkpieceLifecycleLog) *WorkpieceLifecycleLogUpdateOne { + _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 *WorkpieceLifecycleLogUpdateOne) Select(field string, fields ...string) *WorkpieceLifecycleLogUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated WorkpieceLifecycleLog entity. +func (_u *WorkpieceLifecycleLogUpdateOne) Save(ctx context.Context) (*WorkpieceLifecycleLog, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *WorkpieceLifecycleLogUpdateOne) SaveX(ctx context.Context) *WorkpieceLifecycleLog { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *WorkpieceLifecycleLogUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *WorkpieceLifecycleLogUpdateOne) 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 *WorkpieceLifecycleLogUpdateOne) check() error { + if v, ok := _u.mutation.Sn(); ok { + if err := workpiecelifecyclelog.SnValidator(v); err != nil { + return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.sn": %w`, err)} + } + } + if v, ok := _u.mutation.WorkOrderNo(); ok { + if err := workpiecelifecyclelog.WorkOrderNoValidator(v); err != nil { + return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.workOrderNo": %w`, err)} + } + } + if v, ok := _u.mutation.Action(); ok { + if err := workpiecelifecyclelog.ActionValidator(v); err != nil { + return &ValidationError{Name: "action", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.action": %w`, err)} + } + } + if v, ok := _u.mutation.FromStatus(); ok { + if err := workpiecelifecyclelog.FromStatusValidator(v); err != nil { + return &ValidationError{Name: "fromStatus", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.fromStatus": %w`, err)} + } + } + if v, ok := _u.mutation.ToStatus(); ok { + if err := workpiecelifecyclelog.ToStatusValidator(v); err != nil { + return &ValidationError{Name: "toStatus", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.toStatus": %w`, err)} + } + } + if v, ok := _u.mutation.Operator(); ok { + if err := workpiecelifecyclelog.OperatorValidator(v); err != nil { + return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.operator": %w`, err)} + } + } + if v, ok := _u.mutation.Source(); ok { + if err := workpiecelifecyclelog.SourceValidator(v); err != nil { + return &ValidationError{Name: "source", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.source": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := workpiecelifecyclelog.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "WorkpieceLifecycleLog.remark": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *WorkpieceLifecycleLogUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *WorkpieceLifecycleLogUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *WorkpieceLifecycleLogUpdateOne) sqlSave(ctx context.Context) (_node *WorkpieceLifecycleLog, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(workpiecelifecyclelog.Table, workpiecelifecyclelog.Columns, sqlgraph.NewFieldSpec(workpiecelifecyclelog.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "WorkpieceLifecycleLog.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, workpiecelifecyclelog.FieldID) + for _, f := range fields { + if !workpiecelifecyclelog.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != workpiecelifecyclelog.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.Sn(); ok { + _spec.SetField(workpiecelifecyclelog.FieldSn, field.TypeString, value) + } + if value, ok := _u.mutation.WorkOrderNo(); ok { + _spec.SetField(workpiecelifecyclelog.FieldWorkOrderNo, field.TypeString, value) + } + if value, ok := _u.mutation.Action(); ok { + _spec.SetField(workpiecelifecyclelog.FieldAction, field.TypeString, value) + } + if value, ok := _u.mutation.FromStatus(); ok { + _spec.SetField(workpiecelifecyclelog.FieldFromStatus, field.TypeString, value) + } + if value, ok := _u.mutation.ToStatus(); ok { + _spec.SetField(workpiecelifecyclelog.FieldToStatus, field.TypeString, value) + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(workpiecelifecyclelog.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedStationNo(); ok { + _spec.AddField(workpiecelifecyclelog.FieldStationNo, field.TypeInt, value) + } + if _u.mutation.StationNoCleared() { + _spec.ClearField(workpiecelifecyclelog.FieldStationNo, field.TypeInt) + } + if value, ok := _u.mutation.FlowSeq(); ok { + _spec.SetField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedFlowSeq(); ok { + _spec.AddField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt, value) + } + if _u.mutation.FlowSeqCleared() { + _spec.ClearField(workpiecelifecyclelog.FieldFlowSeq, field.TypeInt) + } + if value, ok := _u.mutation.Operator(); ok { + _spec.SetField(workpiecelifecyclelog.FieldOperator, field.TypeString, value) + } + if value, ok := _u.mutation.Source(); ok { + _spec.SetField(workpiecelifecyclelog.FieldSource, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(workpiecelifecyclelog.FieldRemark, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + _node = &WorkpieceLifecycleLog{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{workpiecelifecyclelog.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_mes/frontend/src/help.js b/bj_power_mes/frontend/src/help.js index 76cfeda..3562118 100644 --- a/bj_power_mes/frontend/src/help.js +++ b/bj_power_mes/frontend/src/help.js @@ -164,7 +164,7 @@ export const helpPlc = { } export const helpStation = { - title: '工位绑定(工位总览)', + title: '工位管理(工位总览)', overview: '工位数以数据库为准。本页可新增工位与改名;每个工位在下方下拉选择启用的工艺即完成绑定;一个工位只能绑定一个工艺;内置工位不允许删除。\n\n工位分「内置」与「自定义」两类:内置工位由种子/初始化数据产生(数据库 is_builtin=true),对应实体产线位置,需与 PLC 通讯并按工位号顺序流转,不允许修改工位类型、不允许删除;自定义工位是在本页点击「新增工位」创建的,可修改类型、可删除。\n\n绑定关系即本页下拉:选择「启用」的工艺即完成绑定(工位号即顺序号);工单的执行路线由工单的「工艺组合」决定,本页只维护工位↔工艺绑定,不再有按日派工。\n\n停单/恢复:工人在工位终端自主停单/恢复,管理端在本页/日排产侧同步展示当日停单状态(只读)。\n\n数据链路:本页绑定工艺 → 工单勾选工艺组合 → 工位终端按绑定工艺的工艺步骤采集 → 报工按考核标准自动判 合格/不合格。', fields: [ @@ -177,16 +177,16 @@ export const helpStation = { { name: '绑定工艺', source: '本页下拉选择「启用」的工艺即完成绑定。', purpose: '该工位执行的工艺(决定工艺步骤/考核标准/PDF/物料清单);一个工位只能绑定一个工艺', fill: '在本页下拉为该工位选择启用工艺;工单执行路线由工单工艺组合决定' }, { name: '终端可见页签', source: '本页「页签」按钮配置(station.visibleTabs)。', purpose: '该工位终端允许显示哪些功能页签(上线建档/作业/物料/产线点位(上料/下料)/工艺文件/巡检/下线完工),按工位差异化界面', fill: '点「页签」勾选;全部不勾 = 显示全部页签,保存后终端下次拉取任务生效' }, { name: '删除', source: '本页操作。', purpose: '删除自定义工位', fill: '仅自定义工位可删除;内置工位不允许删除' }, - { name: '虚拟工位 0 / 13', source: '系统预置。工位号 0=上线位、13=下线位。', purpose: '产线进线口建档上线、出料口完工入库,由 PAD 操作,不连 PLC/拧紧枪', fill: '只读;上线位/下线位在工位终端(PAD)用「上线建档」「下线完工」面板操作' } + { name: '虚拟工位 0 / 13', source: '系统预置虚拟工位(工位号 0、13)。', purpose: '原用作产线进线口/出料口的虚拟上下线位,现已废弃该特殊含义,降级为普通虚拟工位', fill: '只读;上线建档/下线完工不再绑定 0/13,改由工位终端「页签」配置(station.visibleTabs)决定哪些工位可显示该面板,任意授权工位均可操作' } ] } export const helpVirtualStation = { title: '虚拟工位作业(MES 后台人工报工)', overview: - '虚拟工位 = 没有终端硬件(无屏、无 PLC、无拧紧枪)的工位(如包装等辅助工序,线下位类型)。这类工位无法用工位终端,由操作人用自己的手机/电脑登录 MES 后台,在本页完成作业:选择自己的虚拟工位 → 选工单、扫/输工件SN → 查看当前工艺步骤与应绑配料 → 逐项录入 → 点「完成报工」。\n\n与工位终端走同一套接口与校验(/station/task、/station/report):齐套校验、检测确认校验、不可倒序报工等规则完全一致;拧紧步骤因无硬件不在本页采集(由物理工位拧紧枪采集)。\n\n权限:菜单「虚拟工位作业」按账号开通(角色管理勾选 produce.virtualstation),不给普通账号开「工位绑定」等管理菜单即可。', + '虚拟工位 = 没有终端硬件(无屏、无 PLC、无拧紧枪)的工位(如包装等辅助工序,线下位类型)。这类工位无法用工位终端,由操作人用自己的手机/电脑登录 MES 后台,在本页完成作业:选择自己的虚拟工位 → 选工单、扫/输工件SN → 查看当前工艺步骤与应绑配料 → 逐项录入 → 点「完成报工」。\n\n与工位终端走同一套接口与校验(/station/task、/station/report):齐套校验、检测确认校验、不可倒序报工等规则完全一致;拧紧步骤因无硬件不在本页采集(由物理工位拧紧枪采集)。\n\n权限:菜单「虚拟工位作业」按账号开通(角色管理勾选 produce.virtualstation),不给普通账号开「工位管理」等管理菜单即可。', fields: [ - { name: '选择虚拟工位', source: '下拉来自「工位绑定」页维护的工位(建议给虚拟工序建线下位类型工位)。', purpose: '报工落在哪个工位(报工校验工位必须在工单工艺组合中)', fill: '选择自己负责的虚拟工位' }, + { name: '选择虚拟工位', source: '下拉来自「工位管理」页维护的工位(建议给虚拟工序建线下位类型工位)。', purpose: '报工落在哪个工位(报工校验工位必须在工单工艺组合中)', fill: '选择自己负责的虚拟工位' }, { name: '工单', source: '今日已启用日排产且工单已下发/在制(与终端口径一致)。', purpose: '本工位今天该干哪些工单', fill: '选择当前作业的工单' }, { name: '工件SN', source: '上线建档时系统生成的工件唯一码(标签/二维码)。', purpose: '定位工件与所属工单,报工/绑定都挂在 SN 下', fill: '扫码或手输后回车载入' }, { name: '工艺步骤', source: '工位绑定工艺的步骤模板(工艺页维护)。', purpose: '本工位要做什么、考核标准是什么', fill: '手填步骤逐项录入数值/结果;「检测确认」步骤需勾选;拧紧步骤由物理工位采集,本页只读' }, @@ -226,7 +226,7 @@ export const helpDock = { export const helpTrace = { title: '工件追溯', overview: - '输入工件 SN,查它的完整履历:进线/完工时间、各工位时间线、步骤考核数据(扭矩/角度)、拧紧记录、以及它用了哪些批次号/序列号=是。\n\n「检验记录」页签只读展示该工件的过程检/完工检结论(合格/部分通过/不合格)、处置方式、相关标准/试验记录单号、记录人及附件(点文件名打开),无记录显示"无检验记录"。\n\n数据来源:全部由前端各环节自动写入(扫码报工、拧紧采集、产线设备下发、工位完成),本页只读查询。\n\n与「生产流程卡」分工:本页以 **SN(工件成品序列号)** 为入口做全链路追溯——递归 BOM 组成树、装机绑定关系、暂存退库/重上线、检验记录等单件履历,适合查"某一台"的来龙去脉;生产流程卡以工单为主卡看工艺实绩/用料/签字,适合看"一整单"的进度。两页数据同源(均读工件实绩),按查询维度互补,不重复录入。\n\n入口说明:本页查询入口 SN 为**成品/工件序列号**(成品实例 SN);物料 SN 只在「装机绑定」页签里作为绑定值展示,不能作本页查询入口。', + '输入工件 SN,查它的完整履历:进线/完工时间、各工位时间线、步骤考核数据(扭矩/角度)、拧紧记录、以及它用了哪些批次号/序列号=是。\n\n「检验记录」页签只读展示该工件的过程检/完工检结论(合格/部分通过/不合格)、处置方式、相关标准/试验记录单号、记录人及附件(点文件名打开),无记录显示"无检验记录"。\n\n数据来源:全部由前端各环节自动写入(扫码报工、拧紧采集、产线设备下发、工位完成),本页只读查询。\n\n与「生产流程卡」分工:本页以 **SN(工件成品序列号)** 为入口做全链路追溯——物料清单递归组成树、装机绑定关系、暂存退库/重上线、检验记录等单件履历,适合查"某一台"的来龙去脉;生产流程卡以工单为主卡看工艺实绩/用料/签字,适合看"一整单"的进度。两页数据同源(均读工件实绩),按查询维度互补,不重复录入。\n\n入口说明:本页查询入口 SN 为**成品/工件序列号**(成品实例 SN);物料 SN 只在「装机绑定」页签里作为绑定值展示,不能作本页查询入口。', fields: [ { name: '工件SN', source: '扫码枪/手输。来自工件条码。', purpose: '要追溯的工件唯一序列号', fill: '扫 SN 或手动输入后点查询' }, { name: '工单号', source: '手动输入。筛选条件。', purpose: '按工单号列出该工单下全部工件,再点行内「追溯」查看单个工件履历', fill: '可空;支持模糊匹配,回车即查' } @@ -440,7 +440,7 @@ export const helpInspect = { export const helpProcessCard = { title: '生产流程卡(工单维度主卡)', overview: - '本页以**工单**为唯一主键,展示该工单的「生产实绩 / 追溯卡」:工序实绩、用料清单、成品明细与签字确认;并保留成品 SN 维度的追溯子视图。\n\n三个查询入口(数据源同一套):\n· 工单号 → 工单主卡(首选);\n· 成品SN → 成品追溯卡(SN 维度,逐件追溯工序/用料/拧紧/签字);\n· 产品型号 → 该型号下的工单列表(仅筛选入口,点行内「查看主卡」回到工单维度)。\n\n概念统一:物料「类型」(结构件/电气件/其他)取自 WMS 物料档案 manage_mode;物料「序列号」(序列号=是逐件录 SN / 序列号=否按批)两维严格分离。用料清单按 序列号=是 / 序列号=否 两组分别展示。\n\n用料清单数据来自装配实绩(工位终端装机绑定 workpiece_bind):序列号=是列出每件实际 SN,序列号=否列出批次号。\n\n签字区:操作工 / 检验员 / 审核人 按实际签字人展示(含签字次数与最近时间),单据级「批准人」留手签空位,系统不代填、不加字段。\n\n打印/导出:点「打印 / 导出 PDF」,系统在新窗口打开排版好的 A4 卡片版式,浏览器打印选「另存为 PDF」即导出电子档。\n\n分工:本页是**工单维度主卡**(看一整单的工艺实绩/用料/签字);单件 SN 全链路履历(含装机绑定、递归 BOM、暂存退库、检验记录)由「工件追溯」页按 SN 入口提供。两者数据同源,按"查整单进度"还是"查单件履历"互补选择。', + '本页以**工单**为唯一主键,展示该工单的「生产实绩 / 追溯卡」:工序实绩、用料清单、成品明细与签字确认;并保留成品 SN 维度的追溯子视图。\n\n三个查询入口(数据源同一套):\n· 工单号 → 工单主卡(首选);\n· 成品SN → 成品追溯卡(SN 维度,逐件追溯工序/用料/拧紧/签字);\n· 产品型号 → 该型号下的工单列表(仅筛选入口,点行内「查看主卡」回到工单维度)。\n\n概念统一:物料「类型」(结构件/电气件/其他)取自 WMS 物料档案 manage_mode;物料「序列号」(序列号=是逐件录 SN / 序列号=否按批)两维严格分离。用料清单按 序列号=是 / 序列号=否 两组分别展示。\n\n用料清单数据来自装配实绩(工位终端装机绑定 workpiece_bind):序列号=是列出每件实际 SN,序列号=否列出批次号。\n\n签字区:操作工 / 检验员 / 审核人 按实际签字人展示(含签字次数与最近时间),单据级「批准人」留手签空位,系统不代填、不加字段。\n\n打印/导出:点「打印 / 导出 PDF」,系统在新窗口打开排版好的 A4 卡片版式,浏览器打印选「另存为 PDF」即导出电子档。\n\n分工:本页是**工单维度主卡**(看一整单的工艺实绩/用料/签字);单件 SN 全链路履历(含装机绑定、物料清单递归组成、暂存退库、检验记录)由「工件追溯」页按 SN 入口提供。两者数据同源,按"查整单进度"还是"查单件履历"互补选择。', fields: [ { name: '产品型号', source: '下拉选择,来自「物料档案」页(WMS 物料主数据)。', purpose: '按型号筛选其下工单列表', fill: '选定后清空工单号/SN,进入型号筛选模式' }, { name: '工单号', source: '手工填写。', purpose: '直接查某工单的生产流程卡主卡', fill: '回车或点查询' }, @@ -501,11 +501,11 @@ export const helpQuality = { export const helpWip = { title: '在制品(跨天在制视图)', overview: - '在制品 = 已进线但尚未完工的工件(状态 已上线/在制/返修),跨天继续停留在此列表中。\n\n数据来源:MES 工件实时状态(GET /workpieces/in-process)。当前工位支持 0=上线位(虚拟)、1~12=物理工位、13=下线位(虚拟),工位数以数据库为准。\n\n与日排产的关系:已进线未完工的工件跨天继续,日排产仅排「未开工数量」,不会重复排产。停留时长自进线起算,便于发现滞留件。', + '在制品 = 已进线但尚未完工的工件,跨天继续停留在此列表中。\n\n数据来源:MES 工件实时状态(GET /workpieces/in-process)。\n\n工件六态生命周期(单字段 workpiece.status 直接流转):新建 NEW → 已上线 ONLINE(唯一触发=上线建档)→ 在制 PROCESSING(报工)→ 下线完工按成品工艺是否走完分流:走完=完工 DONE、未走完=半成品入库 SEMI_STORED(入库一次解锁一次、可再次上线循环);报废 SCRAPPED 仅由质检处置触发。\n\n工位说明:工位 1~12 为实体物理工位(工位数以数据库为准);原虚拟位 0/13(上线位/下线位)已废弃,降级为普通虚拟工位;上线建档与下线完工由工位终端「页签」配置(station.visibleTabs)驱动,可在任意授权工位执行,不再绑定特定工位号。\n\n与日排产的关系:已进线未完工的工件跨天继续,日排产仅排「未开工数量」,不会重复排产。停留时长自进线起算,便于发现滞留件。', fields: [ { name: '工单号', source: '手动输入。筛选条件。', purpose: '只看某个工单的在制品', fill: '可空=全部;支持模糊匹配,回车即查' }, { name: '当前工位', source: '按工件状态与工位组合推算。', purpose: '工件此刻停在哪一工位', fill: '只读,可筛选' }, - { name: '状态', source: '系统维护。', purpose: '已上线/在制/返修', fill: '只读,可筛选' }, + { name: '状态', source: '系统维护(六态单字段)。', purpose: '新建/已上线/在制/半成品入库/完工/报废', fill: '只读,可筛选' }, { name: '进度', source: '已完成步骤数 / 工艺组合总步骤数。', purpose: '看该件走到第几步', fill: '只读' }, { name: '停留时长', source: '自上线时间起算。', purpose: '发现长时间滞留的在制品', fill: '只读' } ] diff --git a/bj_power_mes/frontend/src/layouts/MainLayout.vue b/bj_power_mes/frontend/src/layouts/MainLayout.vue index 88fb37a..712a32e 100644 --- a/bj_power_mes/frontend/src/layouts/MainLayout.vue +++ b/bj_power_mes/frontend/src/layouts/MainLayout.vue @@ -151,7 +151,7 @@ const menuGroups = [ { title: '基础配置', icon: Box, children: [ { code: 'produce.processflow', name: '工艺', path: '/process-flow', icon: Operation }, - { code: 'produce.station', name: '工位绑定', path: '/station', icon: Link }, + { code: 'produce.station', name: '工位管理', path: '/station', icon: Link }, { code: 'produce.dock', name: '接驳台维护', path: '/dock', icon: Aim }, { code: 'produce.product', name: '物料档案', path: '/product-type', icon: Box } ] diff --git a/bj_power_mes/frontend/src/pages/AlertRule.vue b/bj_power_mes/frontend/src/pages/AlertRule.vue index fbad312..7350a03 100644 --- a/bj_power_mes/frontend/src/pages/AlertRule.vue +++ b/bj_power_mes/frontend/src/pages/AlertRule.vue @@ -15,7 +15,7 @@ - + diff --git a/bj_power_mes/frontend/src/pages/DailyPlan.vue b/bj_power_mes/frontend/src/pages/DailyPlan.vue index 889bbe1..cd0be82 100644 --- a/bj_power_mes/frontend/src/pages/DailyPlan.vue +++ b/bj_power_mes/frontend/src/pages/DailyPlan.vue @@ -376,7 +376,7 @@ const statusText = (s) => (statusOptions.find((x) => x.v === s) || {}).l || s const planStatusTag = (s) => s === 'DONE' ? 'success' : s === 'PROCESSING' ? 'warning' : s === 'CONFIRMED' ? 'primary' : 'info' -const woStatusMap = { CREATED: '已创建', RELEASED: '已下发', IN_PROGRESS: '执行中', PAUSED: '已暂停', DONE: '已完成', CANCELLED: '已取消' } +const woStatusMap = { CREATED: '已创建', IN_PROGRESS: '下发并开工', PAUSED: '已暂停', DONE: '已完成', CANCELLED: '已取消' } const woStatusText = (s) => woStatusMap[s] || s async function loadStations() { diff --git a/bj_power_mes/frontend/src/pages/EventLog.vue b/bj_power_mes/frontend/src/pages/EventLog.vue index 76db7c3..1bdc47b 100644 --- a/bj_power_mes/frontend/src/pages/EventLog.vue +++ b/bj_power_mes/frontend/src/pages/EventLog.vue @@ -71,7 +71,7 @@ const EVENT_FAMILIES = [ { label: '日排产', value: 'daily.plan.' }, { label: '备料单', value: 'material.request.' }, { label: '工艺', value: 'process.flow.' }, - { label: '工位绑定', value: 'station.' }, + { label: '工位管理', value: 'station.' }, { label: '工位下发', value: 'plc.' }, { label: '拧紧', value: 'torque.' }, { label: '报工/完工', value: 'scan.' }, diff --git a/bj_power_mes/frontend/src/pages/MaterialRequest.vue b/bj_power_mes/frontend/src/pages/MaterialRequest.vue index 6274177..2a64bca 100644 --- a/bj_power_mes/frontend/src/pages/MaterialRequest.vue +++ b/bj_power_mes/frontend/src/pages/MaterialRequest.vue @@ -234,7 +234,7 @@ async function onExpandRow(row, expandedRows) { } } -// 导出 CSV(带 BOM,Excel 直接打开中文不乱码;MES 前端无 xlsx 库,纯前端导出) +// 导出 CSV(带物料清单列,Excel 直接打开中文不乱码;MES 前端无 xlsx 库,纯前端导出) async function exportLedgerCsv() { if (!(await confirmExport(progressRows.value.length, '物料去向对账记录'))) return const header = ['工单号', '图号', '物料名称', '目标工位', '需求', '已发出', '已退回', '已接料', '已消耗', '在途', '工位余', '待发缺口', '对账状态', '台账状态'] diff --git a/bj_power_mes/frontend/src/pages/ProductProcess.vue b/bj_power_mes/frontend/src/pages/ProductProcess.vue index 917628f..a369b52 100644 --- a/bj_power_mes/frontend/src/pages/ProductProcess.vue +++ b/bj_power_mes/frontend/src/pages/ProductProcess.vue @@ -41,7 +41,7 @@ diff --git a/bj_power_mes/frontend/src/pages/ProductType.vue b/bj_power_mes/frontend/src/pages/ProductType.vue index cfb60dd..ad944f9 100644 --- a/bj_power_mes/frontend/src/pages/ProductType.vue +++ b/bj_power_mes/frontend/src/pages/ProductType.vue @@ -46,7 +46,7 @@ - + diff --git a/bj_power_mes/frontend/src/pages/Station.vue b/bj_power_mes/frontend/src/pages/Station.vue index 27fcf20..7f9f1f5 100644 --- a/bj_power_mes/frontend/src/pages/Station.vue +++ b/bj_power_mes/frontend/src/pages/Station.vue @@ -61,7 +61,7 @@ diff --git a/bj_power_mes/frontend/src/pages/Wip.vue b/bj_power_mes/frontend/src/pages/Wip.vue index 191c1a7..2cd2358 100644 --- a/bj_power_mes/frontend/src/pages/Wip.vue +++ b/bj_power_mes/frontend/src/pages/Wip.vue @@ -15,7 +15,6 @@ - @@ -37,9 +36,6 @@
在制
{{ countBy('PROCESSING') }}
- -
返修
{{ countBy('REPAIR') }}
-
@@ -97,10 +93,10 @@ function countBy(st) { return list.value.filter((x) => x.status === st).length } function rowClass({ row }) { return row.dwellSec > 86400 ? 'wip-overdue' : '' } function statusText(s) { - return { ONLINE: '已上线', PROCESSING: '在制', REPAIR: '返修' }[s] || s + return { ONLINE: '已上线', PROCESSING: '在制' }[s] || s } function statusTag(s) { - return { ONLINE: 'info', PROCESSING: 'success', REPAIR: 'danger' }[s] || 'info' + return { ONLINE: 'info', PROCESSING: 'success' }[s] || 'info' } function fmtDur(sec) { const s = Number(sec) || 0 diff --git a/bj_power_mes/frontend/src/pages/WorkOrder.vue b/bj_power_mes/frontend/src/pages/WorkOrder.vue index c70a041..2145dc1 100644 --- a/bj_power_mes/frontend/src/pages/WorkOrder.vue +++ b/bj_power_mes/frontend/src/pages/WorkOrder.vue @@ -82,7 +82,7 @@ :disabled="!hasCombination(row)" command="schedule">自动排产 {{ a.l }} 编辑 - 删除 @@ -168,7 +168,7 @@ + title="排产仅排「未开工数量 = 工单总数 − 已完工 − 在产未完工」:生成预览后可逐日调节数量(前松/中紧/后松等任意节奏),各日合计须与应排总数一致;确认后生成未启用(PENDING)排产,工单「下发并开工」后到「日排产」页面人工启用即生效。" /> @@ -298,14 +298,15 @@ import PageHelp from '../components/PageHelp.vue' import { helpWorkOrder } from '../help' const statusOptions = [ - { v: 'CREATED', l: '已创建' }, { v: 'RELEASED', l: '已下发' }, - { v: 'IN_PROGRESS', l: '执行中' }, { v: 'PAUSED', l: '已暂停' }, + { v: 'CREATED', l: '已创建' }, + { v: 'IN_PROGRESS', l: '下发并开工' }, + { v: 'PAUSED', l: '已暂停' }, { v: 'DONE', l: '已完成' }, { v: 'CANCELLED', l: '已取消' } ] const statusText = (s) => (statusOptions.find((x) => x.v === s) || {}).l || s -// 状态固定配色:已创建=灰(info) / 已下发=蓝(primary) / 执行中=绿(success) / 已暂停=橙(warning) / 已取消=红(danger) / 已完成=深绿(success) +// 状态固定配色(方案 A):已创建=灰(info) / 下发并开工=绿(success) / 已暂停=橙(warning) / 已完成=深绿(success) / 已取消=红(danger) const statusTagType = (s) => ( - { CREATED: 'info', RELEASED: 'primary', IN_PROGRESS: 'success', PAUSED: 'warning', CANCELLED: 'danger', DONE: 'success' }[s] || 'info' + { CREATED: 'info', IN_PROGRESS: 'success', PAUSED: 'warning', CANCELLED: 'danger', DONE: 'success' }[s] || 'info' ) // 归属(一级编号):合同号/科技项目号 二选一,值域与 WMS inventories.ownership_type 一致 @@ -315,25 +316,21 @@ const ownershipOptions = [ const ownershipText = (t) => (ownershipOptions.find((o) => o.v === t) || {}).l || '-' // 工件SN列表(详情抽屉):状态/当前工位/类型(sn_mode:1=序列号=是 2=序列号=否,取自产品图号对应物料档案) -const pieceStatusMap = { ONLINE: '已上线', PROCESSING: '在制', DONE: '完工', REPAIR: '返修', SCRAPPED: '报废' } +const pieceStatusMap = { NEW: '待上线', ONLINE: '已上线', PROCESSING: '在制', SEMI_STORED: '半成品入库', DONE: '完工', SCRAPPED: '报废' } const pieceStatusText = (s) => pieceStatusMap[s] || s const stationText = (n) => (n > 0 ? '工位' + n : '-') const snModeText = (m) => (m === 1 ? '序列号=是' : m === 2 ? '序列号=否' : '-') -// 状态流转:给出当前状态可执行的下一个动作(按钮文案随当前状态变化) +// 状态流转:给出当前状态可执行的下一个动作(按钮文案随当前状态变化,方案 A) function statusActionBtn(status) { const map = { - CREATED: '下发 ▾', PENDING: '下发 ▾', CONFIRMED: '开工 ▾', - RELEASED: '开工 ▾', IN_PROGRESS: '执行中 ▾', PAUSED: '已暂停 ▾' + CREATED: '下发并开工 ▾', IN_PROGRESS: '执行中 ▾', PAUSED: '已暂停 ▾' } return map[status] || '' } function statusActions(status) { const map = { - CREATED: [{ v: 'RELEASED', l: '下发工单' }, { v: 'CANCELLED', l: '取消工单' }], - PENDING: [{ v: 'RELEASED', l: '下发工单' }, { v: 'CANCELLED', l: '取消工单' }], - CONFIRMED: [{ v: 'IN_PROGRESS', l: '开始执行' }, { v: 'CANCELLED', l: '取消工单' }], - RELEASED: [{ v: 'IN_PROGRESS', l: '开始执行' }, { v: 'CANCELLED', l: '取消工单' }], + CREATED: [{ v: 'IN_PROGRESS', l: '下发并开工' }, { v: 'CANCELLED', l: '取消工单' }], IN_PROGRESS: [{ v: 'PAUSED', l: '暂停' }, { v: 'DONE', l: '完工' }], PAUSED: [{ v: 'IN_PROGRESS', l: '恢复执行' }, { v: 'CANCELLED', l: '取消工单' }] } diff --git a/bj_power_mes/frontend/src/router/index.js b/bj_power_mes/frontend/src/router/index.js index 5b9274f..ba2000b 100644 --- a/bj_power_mes/frontend/src/router/index.js +++ b/bj_power_mes/frontend/src/router/index.js @@ -15,7 +15,7 @@ const routes = [ { path: 'qty-report', name: 'QtyReport', component: () => import('../pages/QtyReport.vue'), meta: { title: '数量不符处理' } }, { path: 'plc-send', name: 'PlcSend', component: () => import('../pages/PlcSend.vue'), meta: { title: '工位组合下发' } }, { path: 'process-flow', name: 'ProcessFlow', component: () => import('../pages/ProcessFlow.vue'), meta: { title: '工艺' } }, - { path: 'station', name: 'Station', component: () => import('../pages/Station.vue'), meta: { title: '工位绑定' } }, + { path: 'station', name: 'Station', component: () => import('../pages/Station.vue'), meta: { title: '工位管理' } }, { path: 'dock', name: 'Dock', component: () => import('../pages/Dock.vue'), meta: { title: '接驳台维护' } }, { path: 'performance', name: 'Performance', component: () => import('../pages/Performance.vue'), meta: { title: '绩效报表' } }, { path: 'inspect', name: 'Inspect', component: () => import('../pages/Inspect.vue'), meta: { title: '巡检终端' } }, diff --git a/bj_power_mes/internal/logic/dailyplan.go b/bj_power_mes/internal/logic/dailyplan.go index ffb76fd..c98e6c0 100644 --- a/bj_power_mes/internal/logic/dailyplan.go +++ b/bj_power_mes/internal/logic/dailyplan.go @@ -372,7 +372,7 @@ type UnplannedWorkOrder struct { // 用于日排产页顶部「有 N 个工单尚未排产」入口;每次进入页面查询一次即可(前端缓存 60s)。 func (s *Service) ListUnplannedWorkOrders(ctx context.Context) ([]*UnplannedWorkOrder, error) { wos, err := s.ctx.EntClient.WorkOrder.Query(). - Where(workorder.StatusIn("CREATED", "RELEASED", "IN_PROGRESS")).All(ctx) + Where(workorder.StatusIn("CREATED", "IN_PROGRESS")).All(ctx) if err != nil { return nil, err } @@ -409,7 +409,7 @@ func (s *Service) DeleteDailyPlan(ctx context.Context, id int) error { // SetDailyPlanStatus 日排产启用/停用(人工专用入口,POST /daily-plans/:id/status): // 仅允许 PENDING(待执行)↔CONFIRMED(已启用) 之间切换;执行中/已完成/已取消由系统联动维护,无人工入口。 -// 启用(→CONFIRMED)前校验所属工单(按排产 orderNo 查)状态必须为 RELEASED 或 IN_PROGRESS。 +// 启用(→CONFIRMED)前校验所属工单(按排产 orderNo 查)状态必须为 IN_PROGRESS(下发并开工)。 // 只 UPDATE status 字段,绝不触碰计划数量/分产量等其它列。 func (s *Service) SetDailyPlanStatus(ctx context.Context, id int, target, operator string) error { if id <= 0 { @@ -433,8 +433,8 @@ func (s *Service) SetDailyPlanStatus(ctx context.Context, id int, target, operat if err != nil { return errors.New("工单不存在") } - if wo.Status != "RELEASED" && wo.Status != "IN_PROGRESS" { - return errors.New("工单未下发,不能启用排产") + if wo.Status != "IN_PROGRESS" { + return errors.New("工单未开工,不能启用排产") } } if err := s.ctx.EntClient.DailyPlan.UpdateOneID(id).SetStatus(target).Exec(ctx); err != nil { diff --git a/bj_power_mes/internal/logic/dashboard.go b/bj_power_mes/internal/logic/dashboard.go index 7837a45..dfa00c2 100644 --- a/bj_power_mes/internal/logic/dashboard.go +++ b/bj_power_mes/internal/logic/dashboard.go @@ -756,7 +756,7 @@ func rankOrderStatus(status string) int { case "IN_PROGRESS": return 0 case "RELEASED": - return 1 + return 0 // 存量兼容:旧 RELEASED 等同已下发并开工 case "CREATED": return 2 case "COMPLETED": diff --git a/bj_power_mes/internal/logic/materialsync.go b/bj_power_mes/internal/logic/materialsync.go index 04d8a9b..c2231c0 100644 --- a/bj_power_mes/internal/logic/materialsync.go +++ b/bj_power_mes/internal/logic/materialsync.go @@ -68,12 +68,17 @@ func (s *Service) UpsertLocalMaterial(ctx context.Context, req MaterialUpsertReq if req.SnMode == 1 || req.SnMode == 2 { snMode = req.SnMode } + // 物料类别防落 0:显式合法值(1原材料/2半成品/3成品/4其他)才覆盖,否则保留本地值(与 snMode 禁止落 0 同款口径)。 + itemType := existing.ItemType + if req.ItemType >= 1 && req.ItemType <= 4 { + itemType = req.ItemType + } _, err = s.ctx.EntClient.Material.UpdateOneID(existing.ID). SetName(req.Name). SetSpec(req.Spec). SetUnit(req.Unit). SetDescription(req.Description). - SetItemType(req.ItemType). + SetItemType(itemType). SetManageMode(req.ManageMode). SetSnMode(snMode). SetTemplateCode(req.TemplateCode). @@ -92,7 +97,7 @@ func (s *Service) UpsertLocalMaterial(ctx context.Context, req MaterialUpsertReq SetSpec(req.Spec). SetUnit(req.Unit). SetDescription(req.Description). - SetItemType(req.ItemType). + SetItemType(resolveItemType(req.ItemType)). SetManageMode(req.ManageMode). SetSnMode(resolveSnMode(req.SnMode, req.ManageMode)). SetTemplateCode(req.TemplateCode). @@ -103,6 +108,15 @@ func (s *Service) UpsertLocalMaterial(ctx context.Context, req MaterialUpsertReq return err == nil, err } +// resolveItemType 物料类别兜底:MES 物料档案=WMS 成品物料视图,来源未带合法类别(1原材料/2半成品/3成品/4其他) +// 时兜底 3 成品,避免落 0/1 导致列表误显示「原材料」(问题.md 待办3,2026-10-12)。 +func resolveItemType(v int) int { + if v >= 1 && v <= 4 { + return v + } + return 3 +} + // materialUpsertOf 本地物料行 → 推 WMS 载荷。 func materialUpsertOf(m *ent.Material) wmsclient.MaterialUpsert { active := m.IsActive diff --git a/bj_power_mes/internal/logic/processflow.go b/bj_power_mes/internal/logic/processflow.go index 2fb36d7..796932e 100644 --- a/bj_power_mes/internal/logic/processflow.go +++ b/bj_power_mes/internal/logic/processflow.go @@ -483,8 +483,8 @@ func (s *Service) StationTask(ctx context.Context, stationNo int) (map[string]an if err != nil { return nil, errors.New("工位不存在或未配置") } - // 工位终端可见工单 = 今日已启用排产(CONFIRMED/执行中)且工单已下发/在制(RELEASED/IN_PROGRESS)。 - // 与状态机对齐:工单下发=批准生产、排产启用=排进某一天;未下发或未排进今天的工单,终端一律不显示。 + // 工位终端可见工单 = 今日已启用排产(CONFIRMED/执行中)且工单已下发并开工(IN_PROGRESS)。 + // 与状态机对齐(方案 A):工单「下发并开工」=批准生产、排产启用=排进某一天;未开工或未排进今天的工单,终端一律不显示。 orderNos := []string{} today := time.Now().Format("2006-01-02") plans, _ := s.ctx.EntClient.DailyPlan.Query(). @@ -500,7 +500,7 @@ func (s *Service) StationTask(ctx context.Context, stationNo int) (map[string]an } if len(nos) > 0 { wos, _ := s.ctx.EntClient.WorkOrder.Query(). - Where(workorder.WorkOrderNoIn(nos...), workorder.StatusIn("RELEASED", "IN_PROGRESS")). + Where(workorder.WorkOrderNoIn(nos...), workorder.StatusIn("IN_PROGRESS")). Order(ent.Asc(workorder.FieldID)).All(ctx) for _, w := range wos { orderNos = append(orderNos, w.WorkOrderNo) diff --git a/bj_power_mes/internal/logic/semi.go b/bj_power_mes/internal/logic/semi.go index 7282e40..5800943 100644 --- a/bj_power_mes/internal/logic/semi.go +++ b/bj_power_mes/internal/logic/semi.go @@ -7,6 +7,7 @@ import ( "bj_power_mes/ent" "bj_power_mes/ent/semiflow" "bj_power_mes/ent/workpiece" + "bj_power_mes/ent/workpiecelifecyclelog" "bj_power_mes/internal/wmsclient" ) @@ -88,6 +89,18 @@ func (s *Service) ListSemiFlows(ctx context.Context, sn, orderNo string) ([]*ent return q.Order(ent.Desc(semiflow.FieldID)).All(ctx) } +// CountSemiIn 半成品入库次数 = workpiece_lifecycle_log.action='SEMI_IN' 记录数(三.3:替代原 CountSemiStored)。 +// 问题.md 一.5:上线次数=状态驱动、入库一次解锁一次、入库次数有记录可追溯; +// 入库次数统一以 lifecycle 状态流水为权威源,不再依赖 semiflow 业务流水。 +func (s *Service) CountSemiIn(ctx context.Context, sn string) int { + n, err := s.ctx.EntClient.WorkpieceLifecycleLog.Query(). + Where(workpiecelifecyclelog.Sn(sn), workpiecelifecyclelog.Action("SEMI_IN")).Count(ctx) + if err != nil { + return 0 + } + return n +} + // ListEventLogs 操作日志查询(按工单号/操作人;operators 为候选列表,任一命中即算) func (s *Service) ListEventLogs(ctx context.Context, orderNo string, operators []string, eventType string, fromMs, toMs int64, page, pageSize int) ([]*ent.EventLog, int, error) { return s.ctx.EventLog.Query(ctx, eventType, orderNo, operators, fromMs, toMs, page, pageSize) diff --git a/bj_power_mes/internal/logic/workorder.go b/bj_power_mes/internal/logic/workorder.go index cd5db43..84b5ba7 100644 --- a/bj_power_mes/internal/logic/workorder.go +++ b/bj_power_mes/internal/logic/workorder.go @@ -71,7 +71,18 @@ func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operato status = "CREATED" // 创建恒为已创建;不允许直接创建到后续状态 } // 工艺组合 = 唯一路线源头([{flowId,stationNo}],工位号升序执行) - b := s.ctx.EntClient.WorkOrder.Create(). + tx, err := s.ctx.EntClient.Tx(ctx) + if err != nil { + return err + } + committed := false + defer func() { + if !committed { + _ = tx.Rollback() + } + }() + client := tx.Client() + wo, err := client.WorkOrder.Create(). SetWorkOrderNo(req.WorkOrderNo). SetProductTypeId(req.ProductTypeId). SetProductCode(req.ProductCode). @@ -80,21 +91,24 @@ func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operato SetContractNo(req.ContractNo). SetOwnershipType(req.OwnershipType). SetProductSerial(req.ProductSerial). - SetStatus(status) + SetStatus(status).Save(ctx) + if err != nil { + return err + } if req.PlanStart != "" { if t, err := parseDate(req.PlanStart); err == nil { - b.SetPlanStart(t) + wo, _ = client.WorkOrder.UpdateOneID(wo.ID).SetPlanStart(t).Save(ctx) } } if req.PlanEnd != "" { if t, err := parseDate(req.PlanEnd); err == nil { - b.SetPlanEnd(t) + wo, _ = client.WorkOrder.UpdateOneID(wo.ID).SetPlanEnd(t).Save(ctx) } } // 完成日期(Item M):前端必填,后端有值即落库 if req.DueDate != "" { if t, err := parseDate(req.DueDate); err == nil { - b.SetDueDate(t) + wo, _ = client.WorkOrder.UpdateOneID(wo.ID).SetDueDate(t).Save(ctx) } } // 工艺组合(唯一路线源头):传了才校验并写入 @@ -103,20 +117,43 @@ func (s *Service) CreateWorkOrder(ctx context.Context, req WorkOrderReq, operato if err != nil { return err } - b.SetFlowCombination(flowItemsToMaps(items)) + if _, err := client.WorkOrder.UpdateOneID(wo.ID).SetFlowCombination(flowItemsToMaps(items)).Save(ctx); err != nil { + return err + } } // 来源产品工艺:传了必须存在( ACTIVE/停用均可落——前端只列启用的,此处宽松校验存在性) if req.ProductProcessId > 0 { if _, err := s.ctx.EntClient.ProductProcess.Get(ctx, req.ProductProcessId); err != nil { return errors.New("所选产品工艺不存在") } - b.SetProductProcessId(req.ProductProcessId) + if _, err := client.WorkOrder.UpdateOneID(wo.ID).SetProductProcessId(req.ProductProcessId).Save(ctx); err != nil { + return err + } } // 创建人(Item M):取当前登录用户 - b.SetCreatedBy(operator) - if _, err := b.Save(ctx); err != nil { + if _, err := client.WorkOrder.UpdateOneID(wo.ID).SetCreatedBy(operator).Save(ctx); err != nil { return err } + // 二.3 建工单(CREATED)按数量预生成 SN,全 NEW,与工单同事务提交(上限 999;命名 {工单号}-{3位序号})。 + // 新工单无既有 SN,直接采用标准格式;若存在历史 SN 冲突由 Unique 约束兜底报错。 + if req.Quantity > 0 { + if req.Quantity > 999 { + return errors.New("单次建工单数量上限 999,请分批创建") + } + bulk := make([]*ent.WorkpieceCreate, 0, req.Quantity) + for i := 1; i <= req.Quantity; i++ { + sn := fmt.Sprintf("%s-%03d", req.WorkOrderNo, i) + bulk = append(bulk, client.Workpiece.Create(). + SetSn(sn).SetOrderNo(req.WorkOrderNo).SetWorkOrderId(wo.ID).SetStatus("NEW")) + } + if err := client.Workpiece.CreateBulk(bulk...).Exec(ctx); err != nil { + return err + } + } + if err := tx.Commit(); err != nil { + return err + } + committed = true s.ctx.EventLog.Write(ctx, "work.order.create", req.WorkOrderNo, operator, "work_order", req.WorkOrderNo, "创建工单", map[string]any{"quantity": req.Quantity}) s.notifyDashboard() return nil @@ -245,6 +282,14 @@ func (s *Service) UpdateWorkOrder(ctx context.Context, req WorkOrderReq, operato u.SetProductProcessId(req.ProductProcessId) } if req.Quantity > 0 { + // 二.3 边界#1:减数量只允许在所有预生成 SN 仍为 NEW 时进行(已有 SN 进入生产则禁止减) + if req.Quantity < old.Quantity { + nonNew, _ := s.ctx.EntClient.Workpiece.Query(). + Where(workpiece.OrderNo(old.WorkOrderNo), workpiece.StatusNEQ("NEW")).Count(ctx) + if nonNew > 0 { + return fmt.Errorf("该工单已有 %d 个 SN 进入生产(非 NEW),禁止减少工单数量", nonNew) + } + } u.SetQuantity(req.Quantity) } if req.ProductCode != "" { @@ -381,33 +426,31 @@ func (s *Service) GetWorkOrder(ctx context.Context, id int) (*ent.WorkOrder, err return s.ctx.EntClient.WorkOrder.Query().Order(ent.Desc(workorder.FieldID)).First(ctx) } -// 工单状态白名单(统一枚举:已创建/已下发/执行中/已暂停/已完成/已取消)。 -// 另含两个存量旧枚举 PENDING(待排产) / CONFIRMED(已确认):历史数据在改造前已落库, -// 仅保留为兼容(接收与状态机放行),新工单不再产生;不改动库内已有行(不做 DB 迁移)。 +// 工单状态白名单(方案 A 定稿,问题.md 一/计划.md): +// CREATED(已创建) / IN_PROGRESS(下发并开工) / PAUSED(已暂停) / DONE(已完成) / CANCELLED(已取消)。 +// PENDING/CONFIRMED(待排产/已确认) 与 RELEASED(已下发) 为方案 A 前旧枚举,已废弃: +// 新工单不再产生;本机不再放行。残留旧数据由"旧数据可删库"清理。 var workOrderStatuses = map[string]bool{ - "CREATED": true, "RELEASED": true, "IN_PROGRESS": true, + "CREATED": true, "IN_PROGRESS": true, "PAUSED": true, "DONE": true, "CANCELLED": true, - "PENDING": true, "CONFIRMED": true, // 存量兼容(历史工单) } -// workOrderTransitions 工单状态流转表:from → {to...} -// CREATED 可下发/取消;RELEASED 可开工/取消;IN_PROGRESS 可暂停/完工; +// workOrderTransitions 工单状态流转表:from → {to...}(方案 A) +// CREATED 可下发并开工/取消;IN_PROGRESS 可暂停/完工; // PAUSED 可恢复/取消;DONE/CANCELLED 为终态,不再流转。 var workOrderTransitions = map[string]map[string]bool{ - "CREATED": {"RELEASED": true, "CANCELLED": true}, - "RELEASED": {"IN_PROGRESS": true, "CANCELLED": true}, + "CREATED": {"IN_PROGRESS": true, "CANCELLED": true}, "IN_PROGRESS": {"PAUSED": true, "DONE": true}, "PAUSED": {"IN_PROGRESS": true, "CANCELLED": true}, "DONE": {}, "CANCELLED": {}, - // 兼容存量旧枚举:PENDING(待排产)≈已创建可发布,CONFIRMED(已确认)≈已下发可开工 - "PENDING": {"RELEASED": true, "CANCELLED": true}, - "CONFIRMED": {"IN_PROGRESS": true, "CANCELLED": true}, + // 存量兼容(残留 RELEASED 旧数据,等同已下发待开工):允许 →下发并开工/取消;新单不再产生。 + "RELEASED": {"IN_PROGRESS": true, "CANCELLED": true}, } -// SetWorkOrderStatus 工单状态流转(发布/开工/暂停/恢复/完工/取消)。 +// SetWorkOrderStatus 工单状态流转(下发并开工/暂停/恢复/完工/取消)。 // 校验流转合法性;写 eventlog 记录 原状态/新状态/原因;终态联动处理(见 cancelPlansOfOrder)。 -// 注意:下发=RELEASED 仅做「置状态 + 事件日志 + 排产联动」,不调 WMS、不生成物料需求 +// 注意:下发并开工=IN_PROGRESS 仅做「置状态 + 事件日志 + 排产联动」,不调 WMS、不生成物料需求 // (备料单由「生成备料单」按钮/日排产独立触发),避免一次下发造成副作用越界。 func (s *Service) SetWorkOrderStatus(ctx context.Context, id int, status, reason, operator string) error { if id <= 0 { @@ -426,12 +469,12 @@ func (s *Service) SetWorkOrderStatus(ctx context.Context, id int, status, reason if !workOrderTransitions[wo.Status][status] { return fmt.Errorf("不允许从「%s」变更为「%s」", statusTextCN(wo.Status), statusTextCN(status)) } - // 工艺组合守卫:下发/开工必须有工艺组合(建单允许空组合,组合是"怎么生产"的前提) + // 工艺组合守卫:下发并开工必须有工艺组合(建单允许空组合,组合是"怎么生产"的前提) // 多工单混生产:移除原"单工单互斥"(一条产线允许同时执行多个工单; // 工位级天然串行=一个工位一次装一个工件,备料/报工/追溯全按工单挂账互不干扰) - if status == "RELEASED" || status == "IN_PROGRESS" { + if status == "IN_PROGRESS" { if len(wo.FlowCombination) == 0 { - return errors.New("该工单未配置工艺组合,请先在工单编辑中勾选工艺组合后再下发/开工") + return errors.New("该工单未配置工艺组合,请先在工单编辑中勾选工艺组合后再下发并开工") } } upd := s.ctx.EntClient.WorkOrder.UpdateOneID(id).SetStatus(status) @@ -454,8 +497,9 @@ func (s *Service) SetWorkOrderStatus(ctx context.Context, id int, status, reason // statusTextCN 状态枚举中文文案 func statusTextCN(s string) string { m := map[string]string{ - "CREATED": "已创建", "RELEASED": "已下发", "IN_PROGRESS": "执行中", + "CREATED": "已创建", "IN_PROGRESS": "下发并开工", "PAUSED": "已暂停", "DONE": "已完成", "CANCELLED": "已取消", + "RELEASED": "下发并开工", // 存量兼容:旧 RELEASED 等同已下发待开工 } if v, ok := m[s]; ok { return v @@ -463,9 +507,9 @@ func statusTextCN(s string) string { return s } -// DeleteWorkOrder 删除工单。 -// 安全条件:① 状态仅限 已创建(CREATED,兼容存量 PENDING/CONFIRMED 未开始生产);② 无日排产记录; -// ③ 未生成备料单;④ 无任何工件生产数据。已下发/执行中/已暂停/已完成/已取消一律不可删除。 +// DeleteWorkOrder 删除工单(方案 A:仅「已创建」可删)。 +// 安全条件:① 状态仅限 CREATED;② 无日排产记录;③ 未生成备料单; +// ④ 无任何 SN 进入生产(状态≠NEW)。仅预生成的 NEW SN 不阻止删除(二.3 边界#2)。 func (s *Service) DeleteWorkOrder(ctx context.Context, id int, operator string) error { if id <= 0 { return errors.New("缺少 id") @@ -474,8 +518,8 @@ func (s *Service) DeleteWorkOrder(ctx context.Context, id int, operator string) if err != nil { return errors.New("工单不存在") } - if wo.Status != "CREATED" && wo.Status != "PENDING" && wo.Status != "CONFIRMED" { - return errors.New("仅「已创建」状态的工单可删除;已下发、执行中或已结束的工单不能删除") + if wo.Status != "CREATED" { + return errors.New("仅「已创建」状态的工单可删除;下发并开工、执行中或已结束的工单不能删除") } if n, err := s.ctx.EntClient.DailyPlan.Query().Where(dailyplan.OrderNo(wo.WorkOrderNo)).Count(ctx); err == nil && n > 0 { return errors.New("该工单已有日排产记录,请先删除对应排产后再删除工单") @@ -483,8 +527,10 @@ func (s *Service) DeleteWorkOrder(ctx context.Context, id int, operator string) if n, err := s.ctx.EntClient.MaterialRequest.Query().Where(materialrequest.OrderNo(wo.WorkOrderNo)).Count(ctx); err == nil && n > 0 { return errors.New("该工单已生成备料单,不能删除") } - if n, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.OrderNo(wo.WorkOrderNo)).Count(ctx); err == nil && n > 0 { - return errors.New("该工单已有工件生产数据,不能删除") + // 二.3 边界#2:有任何 SN 已进入生产(状态≠NEW) 则禁止删除;仅预生成未上线的 NEW SN 不阻止。 + if n, err := s.ctx.EntClient.Workpiece.Query(). + Where(workpiece.OrderNo(wo.WorkOrderNo), workpiece.StatusNEQ("NEW")).Count(ctx); err == nil && n > 0 { + return errors.New("该工单已有工件进入生产,不能删除") } if err := s.ctx.EntClient.WorkOrder.DeleteOneID(id).Exec(ctx); err != nil { return err diff --git a/bj_power_mes/internal/logic/workpiece.go b/bj_power_mes/internal/logic/workpiece.go index a57cd8d..b3b19cd 100644 --- a/bj_power_mes/internal/logic/workpiece.go +++ b/bj_power_mes/internal/logic/workpiece.go @@ -80,6 +80,7 @@ type OnlineReq struct { Sn string `json:"sn"` OrderNo string `json:"orderNo"` WorkOrderId int `json:"workOrderId"` + StationNo int `json:"stationNo"` // 建档落点工位(二.4/二.11);0/空=沿用旧虚拟位模型(终端 0/13 重构未完成时兼容) } // OnlineWorkpiece 工件进线登记(返回提示文案,供响应透出)。 @@ -100,10 +101,16 @@ func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator s return "", err } if exist != nil { - if exist.Status == "DONE" || exist.Status == "SCRAPPED" { + switch exist.Status { + case "DONE", "SCRAPPED": return "", errors.New("工件已完工/报废,不可重复上线登记") + case "NEW": + // 预生成 SN 首次上线建档:NEW→ONLINE,不涉及 WMS 出库;写物理位置+资格校验 + return s.onlineNewWorkpiece(ctx, exist, req, operator) + default: + // ONLINE/PROCESSING/SEMI_STORED:重上线继续(半成品出库解锁一次上线资格) + return s.reonlineWorkpiece(ctx, exist, req, operator) } - return s.reonlineWorkpiece(ctx, exist, operator) } } // 解析工单(sn_mode 挂在产品型号/物料档案上,必须先定位工单→产品) @@ -156,11 +163,13 @@ func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator s } if err := s.ctx.EntClient.Workpiece.Create(). SetSn(req.Sn).SetOrderNo(req.OrderNo).SetWorkOrderId(req.WorkOrderId). - SetStatus("ONLINE").SetOnlineAt(time.Now()).Exec(ctx); err != nil { + SetStatus("ONLINE").SetOnlineAt(time.Now()).SetAtStationNo(req.StationNo).Exec(ctx); err != nil { return "", err } + // 二.2 物理位置:建档落点写入 at_station;三.2 状态流水 NEW→ONLINE + s.writeLifecycle(ctx, req.Sn, req.OrderNo, "NEW", "ONLINE", req.StationNo, 0, operator, "workstation", "上线建档") s.ctx.EventLog.Write(ctx, "workpiece.online", req.OrderNo, operator, "workpiece", req.Sn, - "工件进线登记", map[string]any{"snMode": snMode, + "工件进线登记", map[string]any{"snMode": snMode, "stationNo": req.StationNo, "snSource": map[int]string{1: "SCANNED", 2: "AUTO"}[snMode]}) s.notifyDashboard() return "进线登记成功", nil @@ -173,7 +182,47 @@ func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator s // 顺序保证:校验全部通过后才产生出库这一副作用,避免"已出库却登记失败"的悬挂状态; // // ③ 下一站工位当天停单时提示"工位N已停止接单"(复用 GetStationPaused 既有停单判定,不阻断登记)。 -func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, operator string) (string, error) { +// onlineNewWorkpiece 预生成 SN 首次上线建档(NEW→ONLINE)。 +// 二.4 资格校验:新件必须落点在工序1工位(工艺组合中工位号最小者);落点未传(终端 0/13 重构未完成)时放行但不校验。 +// 不涉及 WMS 出库(从未入半成品库);写物理位置 at_station=落点,记生命周期 NEW→ONLINE。 +func (s *Service) onlineNewWorkpiece(ctx context.Context, wp *ent.Workpiece, req OnlineReq, operator string) (string, error) { + wo := s.workpieceWorkOrder(ctx, wp) + items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo) + if len(items) == 0 { + return "", errors.New("工单未配置工艺组合") + } + first := items[0].StationNo + for _, it := range items { + if it.StationNo < first { + first = it.StationNo + } + } + if req.StationNo > 0 && req.StationNo != first { + return "", fmt.Errorf("新件建档必须落在工序1工位(工位%d),当前落点工位%d不符合资格", first, req.StationNo) + } + station := req.StationNo + if station == 0 { + station = first // 终端未传落点时按工序1兜底,避免 at_station 失真 + } + if _, e := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID). + SetStatus("ONLINE").SetOnlineAt(time.Now()).SetAtStationNo(station).Save(ctx); e != nil { + return "", e + } + // 二.2 物理位置 + 三.2 状态流水 NEW→ONLINE + s.writeLifecycle(ctx, wp.Sn, wp.OrderNo, "NEW", "ONLINE", station, 0, operator, "workstation", "上线建档") + s.ctx.EventLog.Write(ctx, "workpiece.online", wp.OrderNo, operator, "workpiece", wp.Sn, + "预生成SN上线建档", map[string]any{"stationNo": station}) + s.notifyDashboard() + return "进线登记成功", nil +} + +// reonlineWorkpiece 重上线(暂存退库后再次进线): +// ① 先校验:工单组合非空且存在下一站(stationNo > currentStationNo),无副作用不通过即拒绝; +// ② 再调 SemiFlow(OUTBOUND) 让 WMS 半成品出库,失败则报错不继续(文案含 WMS 原文)—— +// 顺序保证:校验全部通过后才产生出库这一副作用,避免"已出库却登记失败"的悬挂状态; +// ③ 下一站工位当天停单时提示"工位N已停止接单"(复用 GetStationPaused 既有停单判定,不阻断登记)。 +// 出库一次解锁一次(一.5):置回 ONLINE 并写物理位置 at_station=下一站;记生命周期 SEMI_OUT。 +func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, req OnlineReq, operator string) (string, error) { items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, s.workpieceWorkOrder(ctx, wp)) if len(items) == 0 { return "", errors.New("工单未配置工艺组合") @@ -187,9 +236,20 @@ func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, oper if next == 0 { return "", fmt.Errorf("工件已报工至工位%d,工艺组合中无下一站", wp.CurrentStationNo) } + // 二.4 资格校验:半成品(SEMI_STORED)重上线落点须为后续工序工位(=下一站);未传落点时按下一站兜底 + if req.StationNo > 0 && req.StationNo != next { + return "", fmt.Errorf("半成品重上线须落在后续工序工位(工位%d),当前落点工位%d不符合资格", next, req.StationNo) + } if err := s.SemiFlow(ctx, SemiReq{Sn: wp.Sn, OrderNo: wp.OrderNo, Action: "OUTBOUND"}, operator); err != nil { return "", fmt.Errorf("重上线失败:%s", err.Error()) } + // 出库一次解锁一次(问题.md 一.5):置回 ONLINE,写物理位置=下一站,等待在所选工位重新上线建档。 + if _, e := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID). + SetStatus("ONLINE").SetAtStationNo(next).Save(ctx); e != nil { + return "", fmt.Errorf("重上线解锁状态失败:%s", e.Error()) + } + // 二.2 物理位置 + 三.2 状态流水 SEMI_STORED→ONLINE(出库 SEMI_OUT) + s.writeLifecycle(ctx, wp.Sn, wp.OrderNo, "SEMI_STORED", "ONLINE", next, 0, operator, "workstation", "半成品出库重上线") msg := fmt.Sprintf("重上线成功,继续执行:工位%d·%s", next, s.flowNameById(ctx, nextFlow)) if s.GetStationPaused(ctx, next) { msg += "(注意:工位" + itoa(next) + "已停止接单)" @@ -200,6 +260,41 @@ func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, oper return msg, nil } +// writeLifecycle 写工件生命周期状态流水(三.2 / P2 定稿:所有 status 变更点同事务写)。 +// action 值域:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED;from/to 为变更前后状态。 +// 入库次数统一 count(action='SEMI_IN'),不再依赖 semiflow(CountSemiStored 已删)。 +func (s *Service) writeLifecycle(ctx context.Context, sn, orderNo, from, to string, stationNo, flowSeq int, operator, source, remark string) { + if sn == "" { + return + } + _, _ = s.ctx.EntClient.WorkpieceLifecycleLog.Create(). + SetSn(sn).SetWorkOrderNo(orderNo).SetAction(toAction(to, from)). + SetFromStatus(from).SetToStatus(to).SetStationNo(stationNo).SetFlowSeq(flowSeq). + SetOperator(operator).SetSource(source).SetRemark(remark).Save(ctx) +} + +// toAction 由 状态变更 推导 lifecycle action(三.2 枚举)。 +func toAction(to, from string) string { + switch to { + case "ONLINE": + return "ONLINE" + case "PROCESSING": + return "REPORT" + case "SEMI_STORED": + return "SEMI_IN" + case "DONE": + return "DONE" + case "SCRAPPED": + return "SCRAPPED" + case "NEW": + return "NEW" + } + if from == "SEMI_STORED" && to == "ONLINE" { + return "SEMI_OUT" + } + return to +} + // workpieceWorkOrder 取工件所属工单:优先 workOrderId,缺失按 orderNo 兜底解析 func (s *Service) workpieceWorkOrder(ctx context.Context, wp *ent.Workpiece) *ent.WorkOrder { if wp.WorkOrderId > 0 { @@ -257,7 +352,7 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera if err != nil { return errors.New("工件未进线登记") } - // 严格校验(业务口径已确认):仅“在制”工件可报工;DONE/REPAIR/SCRAPPED 一律拒绝。 + // 严格校验(业务口径已确认):仅“在制”工件可报工;DONE/SCRAPPED 一律拒绝(REPAIR 已退役)。 if wp.Status != "ONLINE" && wp.Status != "PROCESSING" { return errors.New("工件当前状态为「" + wp.Status + "」,非在制,不允许报工") } @@ -387,7 +482,14 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera return err } if _, err := client.Workpiece.UpdateOneID(wp.ID). - SetCurrentStationNo(req.StationNo).SetStatus("PROCESSING").Save(ctx); err != nil { + SetCurrentStationNo(req.StationNo).SetAtStationNo(req.StationNo).SetStatus("PROCESSING").Save(ctx); err != nil { + return err + } + // 二.2 物理位置随报工推进 + 三.2 状态流水 REPORT(同事务) + if _, err := client.WorkpieceLifecycleLog.Create(). + SetSn(req.Sn).SetWorkOrderNo(wp.OrderNo).SetAction("REPORT"). + SetFromStatus(wp.Status).SetToStatus("PROCESSING").SetStationNo(req.StationNo). + SetOperator(operator).SetSource("workstation").SetRemark("工位报工").Save(ctx); err != nil { return err } if err := tx.Commit(); err != nil { @@ -608,36 +710,58 @@ func (s *Service) DoneWorkpiece(ctx context.Context, req DoneReq, operator strin } else if miss != "" { return errors.New("完工前必须绑齐全部装配物料:" + miss) } - now := time.Now() - _, _ = s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID). - SetStatus("DONE").SetDoneAt(now).Save(ctx) - - existID, _ := s.ctx.EntClient.AssociationTrace.Query(). - Where(associationtrace.FinishedSn(req.Sn)).FirstID(ctx) - if existID > 0 { - _, _ = s.ctx.EntClient.AssociationTrace.UpdateOneID(existID). - SetBatchItems(req.BatchItems).SetSerialItems(req.SerialItems).SetOperator(operator).Save(ctx) - } else { - routeStr := "" - if items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo); len(items) > 0 { - routeStr = RouteStationsStrOfWO(items) - } - _, err = s.ctx.EntClient.AssociationTrace.Create(). - SetFinishedSn(req.Sn).SetOrderNo(wp.OrderNo).SetProcessCode(routeStr). - SetBatchItems(req.BatchItems).SetSerialItems(req.SerialItems). - SetOperator(operator).Save(ctx) - if err != nil { - return err - } + // 下线完工分流(问题.md 二.2 + 一.7):不强制最后一道工序,任何工序均可下线; + // 成品工艺已全部报工→DONE(完工);未全部完成→SEMI_STORED(半成品入库)。 + // 二.2 物理位置:完工/入库均清空 at_station(件已离产线/入半成品库)。 + // 三.2 入库次数统一 count(action='SEMI_IN'),不再依赖 semiflow(CountSemiStored 已删)。 + routeItems, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo) + routeCount := len(routeItems) + reported := 0 + if routeCount > 0 { + reported, _ = s.ctx.EntClient.WorkpieceProcess.Query(). + Where(workpieceprocess.Sn(req.Sn), workpieceprocess.Status("DONE")).Count(ctx) + } + status := "DONE" + if routeCount > 0 && reported < routeCount { + status = "SEMI_STORED" + } + now := time.Now() + upd := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID).SetStatus(status).SetAtStationNo(0) + if status == "DONE" { + upd = upd.SetDoneAt(now) + } + if _, err := upd.Save(ctx); err != nil { + return err + } + // 三.2 状态流水:DONE→DONE;SEMI_STORED→补 INBOUND 缺口(SEMI_IN) + s.writeLifecycle(ctx, req.Sn, wp.OrderNo, wp.Status, status, 0, 0, operator, "workstation", "下线完工") + if status == "DONE" { + existID, _ := s.ctx.EntClient.AssociationTrace.Query(). + Where(associationtrace.FinishedSn(req.Sn)).FirstID(ctx) + if existID > 0 { + _, _ = s.ctx.EntClient.AssociationTrace.UpdateOneID(existID). + SetBatchItems(req.BatchItems).SetSerialItems(req.SerialItems).SetOperator(operator).Save(ctx) + } else { + routeStr := "" + if items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, wo); len(items) > 0 { + routeStr = RouteStationsStrOfWO(items) + } + if _, cerr := s.ctx.EntClient.AssociationTrace.Create(). + SetFinishedSn(req.Sn).SetOrderNo(wp.OrderNo).SetProcessCode(routeStr). + SetBatchItems(req.BatchItems).SetSerialItems(req.SerialItems). + SetOperator(operator).Save(ctx); cerr != nil { + return cerr + } + } + s.bumpWorkOrderProgress(ctx, wp.OrderNo, req.Sn) + s.bumpDailyPlanCompleted(ctx, wp.OrderNo, now) + // 反冲扣账:物料在当道工序被消耗,完工即按整份物料清单反冲扣 WMS 库存。 + // 失败仅记 eventlog 不阻塞完工。 + s.backflushWorkpiece(ctx, wp, operator) + s.ctx.EventLog.Write(ctx, "workpiece.done", wp.OrderNo, operator, "workpiece", req.Sn, "完工+关联追溯", map[string]any{"batchItems": req.BatchItems, "serialItems": req.SerialItems}) + } else { + s.ctx.EventLog.Write(ctx, "workpiece.semi_stored", wp.OrderNo, operator, "workpiece", req.Sn, "下线完工(半成品入库)", map[string]any{"routeCount": routeCount, "reported": reported}) } - s.bumpWorkOrderProgress(ctx, wp.OrderNo, req.Sn) - s.bumpDailyPlanCompleted(ctx, wp.OrderNo, now) - s.ctx.EventLog.Write(ctx, "workpiece.done", wp.OrderNo, operator, "workpiece", req.Sn, "完工+关联追溯", map[string]any{"batchItems": req.BatchItems, "serialItems": req.SerialItems}) - // 完工确认 = 生产完成(方案A定稿):此处不再回流 WMS 入库,成品改由「完工检」结论触发—— - // 完工检合格(已通过/部分通过)才回流入库,见 inspection.go finishedInspectionInbound。 - // 反冲扣账:物料在当道工序被消耗,完工即按整份物料清单反冲扣 WMS 库存。 - // 失败仅记 eventlog 不阻塞完工。 - s.backflushWorkpiece(ctx, wp, operator) s.notifyDashboard() return nil } @@ -712,6 +836,7 @@ func (s *Service) Trace(ctx context.Context, sn string) (map[string]any, error) "torqueRecords": torque, "bindTrace": bindVO, "semiFlows": semiFlows, + "semiStoredCount": s.CountSemiIn(ctx, sn), // 半成品入库次数(三.3:count(action='SEMI_IN'),一.5 可追溯) "inspections": inspections, "signs": signs, }, nil @@ -849,8 +974,8 @@ type InProcessItem struct { TotalSteps int `json:"totalSteps"` } -// WorkpiecesInProcess 列出停在各工位、尚未完工的在制品(ONLINE/PROCESSING/REPAIR)。 -// stationNo<=0 返回全部;stationNo>0 仅返回当前停在该工位(0=上线位, 13=下线位)的工件。 +// WorkpiecesInProcess 列出停在各工位、尚未完工的在制品(ONLINE/PROCESSING)。 +// stationNo<=0 返回全部;stationNo>0 仅返回当前停在该工位的工件。 // orderNo 非空时按工单号模糊过滤(客户第12条「记录查看加一项看工单号查询」)。 // 已进线未完工的工件跨天继续,日排产仅排「未开工数量」,不会重复排产。 func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderNo string) ([]InProcessItem, error) { @@ -858,7 +983,6 @@ func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderN Where(workpiece.Or( workpiece.Status("ONLINE"), workpiece.Status("PROCESSING"), - workpiece.Status("REPAIR"), )) if orderNo != "" { q = q.Where(workpiece.OrderNoContainsFold(orderNo)) @@ -893,9 +1017,9 @@ func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderN maxStation = c } } - // 推算当前物理工位:ONLINE 在 上线位(0);PROCESSING 且已到末端 → 下线位(13) + // 推算当前物理工位:ONLINE 在未分配工位;PROCESSING 且已到末端 → 对应下线位 cur := 0 - if wp.Status == "PROCESSING" || wp.Status == "REPAIR" { + if wp.Status == "PROCESSING" { cp := wp.CurrentStationNo if cp <= 0 { cp = maxStation diff --git a/bj_power_mes/schema/workpiece.go b/bj_power_mes/schema/workpiece.go index f6574e4..769a783 100644 --- a/bj_power_mes/schema/workpiece.go +++ b/bj_power_mes/schema/workpiece.go @@ -25,9 +25,16 @@ func (Workpiece) Fields() []ent.Field { field.String("sn").Unique().MaxLen(64).Comment("工件唯一SN"), field.String("orderNo").Default("").MaxLen(64).Comment("所属工单"), field.Int("workOrderId").Optional().Comment("工单ID"), - field.Int("currentStationNo").Optional().Comment("最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条)"), - // ONLINE(已进线) / PROCESSING(在工位) / DONE(完工) / REPAIR / SCRAPPED - field.String("status").Default("ONLINE").MaxLen(20), + field.Int("currentStationNo").Optional().Comment("业务位置:最后完成报工的工位号(0=未报任何工艺;下一道=工艺组合中工位号更大的下一条)"), + // atStationNo = 物理位置:工件当前实际所在工位(建档/到达即写,完工/入库清空)。 + // 与 currentStationNo(业务位置=最后报工工位) 区分,解决 PLC↔MES 对账时"件已到岗未报工"的滞后误报(问题.md 二.2)。 + field.Int("atStationNo").Optional().Comment("物理位置:工件当前实际所在工位号(0=未在工位;建档/到达即写,完工/入库清空)"), + // 工件生命周期六态(问题.md 一.1 已定稿,单字段状态驱动): + // NEW(随工单预生成的待上线SN) / ONLINE(已进线未报工) / PROCESSING(在工位报工中) + // / SEMI_STORED(半成品入库,已下线完工但成品工艺未结束) / DONE(完工) / SCRAPPED(报废) + // NEW→ONLINE 唯一触发=上线建档(一.6);ONLINE 与 PROCESSING 必须分开(一.1)。 + // 六态为完整枚举,REPAIR 已退役(六.6),不再作为合法状态。 + field.String("status").Default("NEW").MaxLen(20), field.Time("onlineAt").Optional().Nillable().Comment("进线时间"), field.Time("doneAt").Optional().Nillable().Comment("完工时间"), field.Time("createdAt").Default(time.Now).Immutable(), diff --git a/bj_power_mes/schema/workpiece_lifecycle_log.go b/bj_power_mes/schema/workpiece_lifecycle_log.go new file mode 100644 index 0000000..cc04df5 --- /dev/null +++ b/bj_power_mes/schema/workpiece_lifecycle_log.go @@ -0,0 +1,51 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" + "entgo.io/ent/schema/index" +) + +// WorkpieceLifecycleLog 工件生命周期状态流水(问题.md 三 / P2 定稿)。 +// 与 semiflow(业务流水:含库位、数量) 并存、同事务写: +// - semiflow = 业务流水(谁写不变),不再作计数源 +// - workpiece_lifecycle_log = 状态流水(from/to status),所有 status 变更点同事务写 +// +// action 值域:NEW / ONLINE / REPORT / SEMI_IN / SEMI_OUT / DONE / SCRAPPED +// 入库次数统一 count(action='SEMI_IN'),原 CountSemiStored 已删除(semi.go)。 +type WorkpieceLifecycleLog struct { + ent.Schema +} + +func (WorkpieceLifecycleLog) Annotations() []schema.Annotation { + return []schema.Annotation{entsql.Annotation{Table: "workpiece_lifecycle_log"}, entsql.WithComments(true), schema.Comment("工件生命周期状态流水:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED,所有状态变更点同事务写")} +} + +func (WorkpieceLifecycleLog) Fields() []ent.Field { + return []ent.Field{ + field.Int("id").Positive(), + field.String("sn").MaxLen(64).Comment("工件SN"), + field.String("workOrderNo").Default("").MaxLen(64).Comment("所属工单"), + field.String("action").MaxLen(20).Comment("状态动作:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED"), + field.String("fromStatus").Default("").MaxLen(20).Comment("变更前状态"), + field.String("toStatus").Default("").MaxLen(20).Comment("变更后状态"), + field.Int("stationNo").Optional().Comment("关联工位号"), + field.Int("flowSeq").Optional().Comment("工艺序号(工序顺序)"), + field.String("operator").Default("").MaxLen(64).Comment("操作人"), + field.String("source").Default("").MaxLen(32).Comment("来源:workstation/mes/admin/reconcile"), + field.String("remark").Default("").MaxLen(255).Comment("备注"), + field.Time("createdAt").Default(time.Now).Immutable(), + } +} + +func (WorkpieceLifecycleLog) Indexes() []ent.Index { + return []ent.Index{ + index.Fields("sn", "createdAt"), + index.Fields("workOrderNo", "createdAt"), + index.Fields("action", "createdAt"), + } +} diff --git a/bj_power_wms/frontend/src/pages/BaseData.vue b/bj_power_wms/frontend/src/pages/BaseData.vue index fdddfba..8b282db 100644 --- a/bj_power_wms/frontend/src/pages/BaseData.vue +++ b/bj_power_wms/frontend/src/pages/BaseData.vue @@ -486,9 +486,9 @@ function matTypeText(m) { if (m === 3) return '其他' return m === 2 ? '电气件' : '结构件' } -// 序列号显示(记账语境:1是(序列号=是)/2否(序列号=否)/0未选择) +// 序列号显示(与 MES 物料档案对齐:1是/2否/其他未选择) function snModeText(v) { - return Number(v) === 1 ? '逐件录SN' : Number(v) === 2 ? '按数量(不录SN)' : '未选择' + return Number(v) === 1 ? '是' : Number(v) === 2 ? '否' : '-' } // 区域维护 / 物料档案共用同一组件:切换菜单时复用,watch(mode, immediate) 保证进入即加载 @@ -609,7 +609,7 @@ async function onMaterialFile(e) {
@@ -667,7 +667,7 @@ async function onMaterialFile(e) { - + @@ -723,7 +723,7 @@ async function onMaterialFile(e) { - + @@ -780,7 +780,7 @@ async function onMaterialFile(e) { - + @@ -1013,7 +1013,7 @@ async function onMaterialFile(e) { - + diff --git a/bj_power_workstation/frontend/src/help.js b/bj_power_workstation/frontend/src/help.js index d07b8c2..6c4f009 100644 --- a/bj_power_workstation/frontend/src/help.js +++ b/bj_power_workstation/frontend/src/help.js @@ -84,7 +84,7 @@ export const helpPdf = { export const helpOnline = { title: '上线建档 使用说明', overview: - '上线建档运行在产线进线口(工位号 0)。成品在此登记建档、按物料清单核对领料,建档上线后流转到第 1 道装配工位。\n\n标准流程:①选工单(带出产品、序列号件口径与物料清单)→ ②按物料清单核对应领料 → ③按口径录入工件 SN(序列号件扫来料SN / 批次件自动发号)→ ④点「确认建档上线」。\n\n数据链路:工单/物料清单/序列号件口径(MES) → 建档上线(MES 生成在制工件,工位号 0) → 流转到装配工位。', + '上线建档在配置了「上线建档」页签的工位终端执行(原虚拟位 0/13 已废弃,任意授权工位均可操作)。成品在此登记建档、按物料清单核对领料,建档上线后流转到下一道装配工位。\n\n标准流程:①选工单(带出产品、序列号口径与物料清单)→ ②按物料清单核对应领料 → ③按口径录入工件 SN(序列号=是扫来料SN / 序列号=否自动发号)→ ④点「确认建档上线」。\n\n数据链路:工单/物料清单/序列号口径(MES) → 建档上线(MES 生成在制工件) → 流转到装配工位。', sections: [ { title: '选工单与产品', @@ -104,9 +104,9 @@ export const helpOnline = { }, { title: '工件 SN 与建档提交', - overview: 'SN 是成品唯一编号,按产品档案「序列号件」口径分流:序列号件须扫已在 WMS 入库登记的来料SN(不再自动发号);批次件提交后系统自动发号,全程可追溯。', + overview: 'SN 是成品唯一编号,按产品档案「序列号」口径分流:序列号=是须扫已在 WMS 入库登记的来料SN(不再自动发号);序列号=否提交后系统自动发号,全程可追溯。', fields: [ - { name: '工件 SN', source: '序列号件:扫码枪扫来料SN(需已在 WMS 入库登记);批次件:系统自动生成。', purpose: '唯一识别本台成品,拧紧/工艺/追溯都挂在此 SN 下', fill: '序列号件=扫描来料SN(必填,MES 校验其在 WMS 库存);批次件=无需手填,提交后系统自动发号' }, + { name: '工件 SN', source: '序列号=是:扫码枪扫来料SN(需已在 WMS 入库登记);序列号=否:系统自动生成。', purpose: '唯一识别本台成品,拧紧/工艺/追溯都挂在此 SN 下', fill: '序列号=是=扫描来料SN(必填,MES 校验其在 WMS 库存);序列号=否=无需手填,提交后系统自动发号' }, { name: '上线位在制品', source: 'MES 实时查询。工位号 0 的在制工件。', purpose: '看清已建档待流转的工件,防止重复建档', fill: '只读展示,点「刷新」更新' }, { name: '确认建档上线', source: '按钮操作 + 确认框。数据上报到 MES。', purpose: '正式建档上线,工件进入产线待第 1 工位加工', fill: '满足工单/SN/领料核对后点击并二次确认;MES 不可达时自动离线缓存重传' } ] @@ -145,13 +145,13 @@ export const helpOffline = { export const helpMaterial = { title: '物料 / 叫料 使用说明', overview: - '本页用于装配物料绑定与缺料叫料。序列号件必须扫码 SN 绑定(一件一码可追溯),批次件按批次绑定(口径=MES 物料档案「序列号件」);缺料时提交叫料,AGV 自动送达本工位固定接驳台(由工位终端配置文件设定)。', + '本页用于装配物料绑定与缺料叫料。序列号=是必须扫码 SN 绑定(一件一码可追溯),序列号=否按批次绑定(口径=MES 物料档案「序列号」);缺料时提交叫料,AGV 自动送达本工位固定接驳台(由工位终端配置文件设定)。', sections: [ { title: '装配物料绑定', overview: '先在「作业」页扫描工件 SN,再按本工位应绑物料逐项扫码绑定。', fields: [ - { name: '应绑物料', source: 'MES 物料清单。按产品与工位带出。', purpose: '列明本工位需绑定的物料及已绑/应绑数量', fill: '对照标签:序列号件扫 SN、批次件扫批次号,回车或点「绑定」' }, + { name: '应绑物料', source: 'MES 物料清单。按产品与工位带出。', purpose: '列明本工位需绑定的物料及已绑/应绑数量', fill: '对照标签:序列号=是扫 SN、序列号=否扫批次号,回车或点「绑定」' }, { name: '已绑标签', source: 'MES 绑定记录。', purpose: '展示已绑定的 SN/批次,可点 × 撤销', fill: '绑错时点标签上的 × 撤销重绑' }, { name: '已绑齐/未绑齐', source: '系统统计。已绑数 / 应绑数。', purpose: '提示本工位物料是否齐套', fill: '未绑齐会红色提示缺料,需补齐后才能完工' } ] diff --git a/bj_power_workstation/frontend/src/views/panels/InspectPanel.vue b/bj_power_workstation/frontend/src/views/panels/InspectPanel.vue index 3769725..7e1fa94 100644 --- a/bj_power_workstation/frontend/src/views/panels/InspectPanel.vue +++ b/bj_power_workstation/frontend/src/views/panels/InspectPanel.vue @@ -59,7 +59,7 @@ - + diff --git a/bj_power_workstation/frontend/src/views/panels/MaterialPanel.vue b/bj_power_workstation/frontend/src/views/panels/MaterialPanel.vue index 4912265..9352f56 100644 --- a/bj_power_workstation/frontend/src/views/panels/MaterialPanel.vue +++ b/bj_power_workstation/frontend/src/views/panels/MaterialPanel.vue @@ -1,6 +1,6 @@