diff --git a/bj_power_mes/ent/client.go b/bj_power_mes/ent/client.go index cd0a8b4..1ff9c48 100644 --- a/bj_power_mes/ent/client.go +++ b/bj_power_mes/ent/client.go @@ -29,7 +29,6 @@ import ( "bj_power_mes/ent/processstep" "bj_power_mes/ent/producttype" "bj_power_mes/ent/role" - "bj_power_mes/ent/scanrecord" "bj_power_mes/ent/semiflow" "bj_power_mes/ent/station" "bj_power_mes/ent/stationprocess" @@ -47,8 +46,6 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" - - stdsql "database/sql" ) // Client is the client that holds all ent builders. @@ -92,8 +89,6 @@ type Client struct { ProductType *ProductTypeClient // Role is the client for interacting with the Role builders. Role *RoleClient - // ScanRecord is the client for interacting with the ScanRecord builders. - ScanRecord *ScanRecordClient // SemiFlow is the client for interacting with the SemiFlow builders. SemiFlow *SemiFlowClient // Station is the client for interacting with the Station builders. @@ -149,7 +144,6 @@ func (c *Client) init() { c.ProcessStep = NewProcessStepClient(c.config) c.ProductType = NewProductTypeClient(c.config) c.Role = NewRoleClient(c.config) - c.ScanRecord = NewScanRecordClient(c.config) c.SemiFlow = NewSemiFlowClient(c.config) c.Station = NewStationClient(c.config) c.StationProcess = NewStationProcessClient(c.config) @@ -273,7 +267,6 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { ProcessStep: NewProcessStepClient(cfg), ProductType: NewProductTypeClient(cfg), Role: NewRoleClient(cfg), - ScanRecord: NewScanRecordClient(cfg), SemiFlow: NewSemiFlowClient(cfg), Station: NewStationClient(cfg), StationProcess: NewStationProcessClient(cfg), @@ -324,7 +317,6 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) ProcessStep: NewProcessStepClient(cfg), ProductType: NewProductTypeClient(cfg), Role: NewRoleClient(cfg), - ScanRecord: NewScanRecordClient(cfg), SemiFlow: NewSemiFlowClient(cfg), Station: NewStationClient(cfg), StationProcess: NewStationProcessClient(cfg), @@ -370,10 +362,9 @@ func (c *Client) Use(hooks ...Hook) { c.Alert, c.AlertRule, c.AssociationTrace, c.Attachment, c.BomItem, c.DailyPlan, c.EventLog, c.InspectionRecord, c.LinePoint, c.MaterialQtyReport, c.MaterialRequest, c.Permission, c.PlcMoveCmd, c.PlcSendLog, c.ProcessFlow, - c.ProcessStep, c.ProductType, c.Role, c.ScanRecord, c.SemiFlow, c.Station, - c.StationProcess, c.StepCriterion, c.StepData, c.TorqueAuditLog, - c.TorqueRecord, c.User, c.UserStation, c.WorkOrder, c.Workpiece, - c.WorkpieceBind, c.WorkpieceProcess, + c.ProcessStep, c.ProductType, c.Role, c.SemiFlow, c.Station, c.StationProcess, + c.StepCriterion, c.StepData, c.TorqueAuditLog, c.TorqueRecord, c.User, + c.UserStation, c.WorkOrder, c.Workpiece, c.WorkpieceBind, c.WorkpieceProcess, } { n.Use(hooks...) } @@ -386,10 +377,9 @@ func (c *Client) Intercept(interceptors ...Interceptor) { c.Alert, c.AlertRule, c.AssociationTrace, c.Attachment, c.BomItem, c.DailyPlan, c.EventLog, c.InspectionRecord, c.LinePoint, c.MaterialQtyReport, c.MaterialRequest, c.Permission, c.PlcMoveCmd, c.PlcSendLog, c.ProcessFlow, - c.ProcessStep, c.ProductType, c.Role, c.ScanRecord, c.SemiFlow, c.Station, - c.StationProcess, c.StepCriterion, c.StepData, c.TorqueAuditLog, - c.TorqueRecord, c.User, c.UserStation, c.WorkOrder, c.Workpiece, - c.WorkpieceBind, c.WorkpieceProcess, + c.ProcessStep, c.ProductType, c.Role, c.SemiFlow, c.Station, c.StationProcess, + c.StepCriterion, c.StepData, c.TorqueAuditLog, c.TorqueRecord, c.User, + c.UserStation, c.WorkOrder, c.Workpiece, c.WorkpieceBind, c.WorkpieceProcess, } { n.Intercept(interceptors...) } @@ -434,8 +424,6 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.ProductType.mutate(ctx, m) case *RoleMutation: return c.Role.mutate(ctx, m) - case *ScanRecordMutation: - return c.ScanRecord.mutate(ctx, m) case *SemiFlowMutation: return c.SemiFlow.mutate(ctx, m) case *StationMutation: @@ -2861,139 +2849,6 @@ func (c *RoleClient) mutate(ctx context.Context, m *RoleMutation) (Value, error) } } -// ScanRecordClient is a client for the ScanRecord schema. -type ScanRecordClient struct { - config -} - -// NewScanRecordClient returns a client for the ScanRecord from the given config. -func NewScanRecordClient(c config) *ScanRecordClient { - return &ScanRecordClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `scanrecord.Hooks(f(g(h())))`. -func (c *ScanRecordClient) Use(hooks ...Hook) { - c.hooks.ScanRecord = append(c.hooks.ScanRecord, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `scanrecord.Intercept(f(g(h())))`. -func (c *ScanRecordClient) Intercept(interceptors ...Interceptor) { - c.inters.ScanRecord = append(c.inters.ScanRecord, interceptors...) -} - -// Create returns a builder for creating a ScanRecord entity. -func (c *ScanRecordClient) Create() *ScanRecordCreate { - mutation := newScanRecordMutation(c.config, OpCreate) - return &ScanRecordCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of ScanRecord entities. -func (c *ScanRecordClient) CreateBulk(builders ...*ScanRecordCreate) *ScanRecordCreateBulk { - return &ScanRecordCreateBulk{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 *ScanRecordClient) MapCreateBulk(slice any, setFunc func(*ScanRecordCreate, int)) *ScanRecordCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &ScanRecordCreateBulk{err: fmt.Errorf("calling to ScanRecordClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*ScanRecordCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &ScanRecordCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for ScanRecord. -func (c *ScanRecordClient) Update() *ScanRecordUpdate { - mutation := newScanRecordMutation(c.config, OpUpdate) - return &ScanRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *ScanRecordClient) UpdateOne(_m *ScanRecord) *ScanRecordUpdateOne { - mutation := newScanRecordMutation(c.config, OpUpdateOne, withScanRecord(_m)) - return &ScanRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *ScanRecordClient) UpdateOneID(id int) *ScanRecordUpdateOne { - mutation := newScanRecordMutation(c.config, OpUpdateOne, withScanRecordID(id)) - return &ScanRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for ScanRecord. -func (c *ScanRecordClient) Delete() *ScanRecordDelete { - mutation := newScanRecordMutation(c.config, OpDelete) - return &ScanRecordDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *ScanRecordClient) DeleteOne(_m *ScanRecord) *ScanRecordDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *ScanRecordClient) DeleteOneID(id int) *ScanRecordDeleteOne { - builder := c.Delete().Where(scanrecord.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &ScanRecordDeleteOne{builder} -} - -// Query returns a query builder for ScanRecord. -func (c *ScanRecordClient) Query() *ScanRecordQuery { - return &ScanRecordQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeScanRecord}, - inters: c.Interceptors(), - } -} - -// Get returns a ScanRecord entity by its id. -func (c *ScanRecordClient) Get(ctx context.Context, id int) (*ScanRecord, error) { - return c.Query().Where(scanrecord.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *ScanRecordClient) GetX(ctx context.Context, id int) *ScanRecord { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *ScanRecordClient) Hooks() []Hook { - return c.hooks.ScanRecord -} - -// Interceptors returns the client interceptors. -func (c *ScanRecordClient) Interceptors() []Interceptor { - return c.inters.ScanRecord -} - -func (c *ScanRecordClient) mutate(ctx context.Context, m *ScanRecordMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&ScanRecordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&ScanRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&ScanRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&ScanRecordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown ScanRecord mutation op: %q", m.Op()) - } -} - // SemiFlowClient is a client for the SemiFlow schema. type SemiFlowClient struct { config @@ -4728,41 +4583,17 @@ type ( hooks struct { Alert, AlertRule, AssociationTrace, Attachment, BomItem, DailyPlan, EventLog, InspectionRecord, LinePoint, MaterialQtyReport, MaterialRequest, Permission, - PlcMoveCmd, PlcSendLog, ProcessFlow, ProcessStep, ProductType, Role, - ScanRecord, SemiFlow, Station, StationProcess, StepCriterion, StepData, - TorqueAuditLog, TorqueRecord, User, UserStation, WorkOrder, Workpiece, - WorkpieceBind, WorkpieceProcess []ent.Hook + PlcMoveCmd, PlcSendLog, ProcessFlow, ProcessStep, ProductType, Role, SemiFlow, + Station, StationProcess, StepCriterion, StepData, TorqueAuditLog, TorqueRecord, + User, UserStation, WorkOrder, Workpiece, WorkpieceBind, + WorkpieceProcess []ent.Hook } inters struct { Alert, AlertRule, AssociationTrace, Attachment, BomItem, DailyPlan, EventLog, InspectionRecord, LinePoint, MaterialQtyReport, MaterialRequest, Permission, - PlcMoveCmd, PlcSendLog, ProcessFlow, ProcessStep, ProductType, Role, - ScanRecord, SemiFlow, Station, StationProcess, StepCriterion, StepData, - TorqueAuditLog, TorqueRecord, User, UserStation, WorkOrder, Workpiece, - WorkpieceBind, WorkpieceProcess []ent.Interceptor + PlcMoveCmd, PlcSendLog, ProcessFlow, ProcessStep, ProductType, Role, SemiFlow, + Station, StationProcess, StepCriterion, StepData, TorqueAuditLog, TorqueRecord, + User, UserStation, WorkOrder, Workpiece, WorkpieceBind, + WorkpieceProcess []ent.Interceptor } ) - -// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it. -// See, database/sql#DB.ExecContext for more information. -func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { - ex, ok := c.driver.(interface { - ExecContext(context.Context, string, ...any) (stdsql.Result, error) - }) - if !ok { - return nil, fmt.Errorf("Driver.ExecContext is not supported") - } - return ex.ExecContext(ctx, query, args...) -} - -// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it. -// See, database/sql#DB.QueryContext for more information. -func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { - q, ok := c.driver.(interface { - QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) - }) - if !ok { - return nil, fmt.Errorf("Driver.QueryContext is not supported") - } - return q.QueryContext(ctx, query, args...) -} diff --git a/bj_power_mes/ent/ent.go b/bj_power_mes/ent/ent.go index 47cb146..8044519 100644 --- a/bj_power_mes/ent/ent.go +++ b/bj_power_mes/ent/ent.go @@ -21,7 +21,6 @@ import ( "bj_power_mes/ent/processstep" "bj_power_mes/ent/producttype" "bj_power_mes/ent/role" - "bj_power_mes/ent/scanrecord" "bj_power_mes/ent/semiflow" "bj_power_mes/ent/station" "bj_power_mes/ent/stationprocess" @@ -122,7 +121,6 @@ func checkColumn(t, c string) error { processstep.Table: processstep.ValidColumn, producttype.Table: producttype.ValidColumn, role.Table: role.ValidColumn, - scanrecord.Table: scanrecord.ValidColumn, semiflow.Table: semiflow.ValidColumn, station.Table: station.ValidColumn, stationprocess.Table: stationprocess.ValidColumn, diff --git a/bj_power_mes/ent/hook/hook.go b/bj_power_mes/ent/hook/hook.go index a3a5a8a..54542bc 100644 --- a/bj_power_mes/ent/hook/hook.go +++ b/bj_power_mes/ent/hook/hook.go @@ -224,18 +224,6 @@ func (f RoleFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.RoleMutation", m) } -// The ScanRecordFunc type is an adapter to allow the use of ordinary -// function as ScanRecord mutator. -type ScanRecordFunc func(context.Context, *ent.ScanRecordMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f ScanRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.ScanRecordMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ScanRecordMutation", m) -} - // The SemiFlowFunc type is an adapter to allow the use of ordinary // function as SemiFlow mutator. type SemiFlowFunc func(context.Context, *ent.SemiFlowMutation) (ent.Value, error) diff --git a/bj_power_mes/ent/migrate/schema.go b/bj_power_mes/ent/migrate/schema.go index e498de1..ea31e8a 100644 --- a/bj_power_mes/ent/migrate/schema.go +++ b/bj_power_mes/ent/migrate/schema.go @@ -645,46 +645,6 @@ var ( }, }, } - // ScanRecordColumns holds the columns for the "scan_record" table. - ScanRecordColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "station", Type: field.TypeString, Size: 32, Default: ""}, - {Name: "sn", Type: field.TypeString, Size: 64}, - {Name: "order_no", Type: field.TypeString, Size: 64, Default: ""}, - {Name: "type", Type: field.TypeString, Size: 20, Default: "PROCESS"}, - {Name: "process_code", Type: field.TypeInt, Nullable: true}, - {Name: "operator", Type: field.TypeString, Size: 64, Default: ""}, - {Name: "time", Type: field.TypeTime}, - {Name: "created_at", Type: field.TypeTime}, - } - // ScanRecordTable holds the schema information for the "scan_record" table. - ScanRecordTable = &schema.Table{ - Name: "scan_record", - Columns: ScanRecordColumns, - PrimaryKey: []*schema.Column{ScanRecordColumns[0]}, - Indexes: []*schema.Index{ - { - Name: "scanrecord_station", - Unique: false, - Columns: []*schema.Column{ScanRecordColumns[1]}, - }, - { - Name: "scanrecord_sn", - Unique: false, - Columns: []*schema.Column{ScanRecordColumns[2]}, - }, - { - Name: "scanrecord_order_no", - Unique: false, - Columns: []*schema.Column{ScanRecordColumns[3]}, - }, - { - Name: "scanrecord_created_at", - Unique: false, - Columns: []*schema.Column{ScanRecordColumns[8]}, - }, - }, - } // SemiFlowColumns holds the columns for the "semi_flow" table. SemiFlowColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -1181,7 +1141,6 @@ var ( ProcessStepTable, ProductTypeTable, RoleTable, - ScanRecordTable, SemiFlowTable, StationTable, StationProcessTable, @@ -1253,9 +1212,6 @@ func init() { RoleTable.Annotation = &entsql.Annotation{ Table: "role", } - ScanRecordTable.Annotation = &entsql.Annotation{ - Table: "scan_record", - } SemiFlowTable.Annotation = &entsql.Annotation{ Table: "semi_flow", } diff --git a/bj_power_mes/ent/mutation.go b/bj_power_mes/ent/mutation.go index 0f3ffc9..4dff793 100644 --- a/bj_power_mes/ent/mutation.go +++ b/bj_power_mes/ent/mutation.go @@ -22,7 +22,6 @@ import ( "bj_power_mes/ent/processstep" "bj_power_mes/ent/producttype" "bj_power_mes/ent/role" - "bj_power_mes/ent/scanrecord" "bj_power_mes/ent/semiflow" "bj_power_mes/ent/station" "bj_power_mes/ent/stationprocess" @@ -73,7 +72,6 @@ const ( TypeProcessStep = "ProcessStep" TypeProductType = "ProductType" TypeRole = "Role" - TypeScanRecord = "ScanRecord" TypeSemiFlow = "SemiFlow" TypeStation = "Station" TypeStationProcess = "StationProcess" @@ -17744,775 +17742,6 @@ func (m *RoleMutation) ResetEdge(name string) error { return fmt.Errorf("unknown Role edge %s", name) } -// ScanRecordMutation represents an operation that mutates the ScanRecord nodes in the graph. -type ScanRecordMutation struct { - config - op Op - typ string - id *int - station *string - sn *string - orderNo *string - _type *string - processCode *int - addprocessCode *int - operator *string - time *time.Time - createdAt *time.Time - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*ScanRecord, error) - predicates []predicate.ScanRecord -} - -var _ ent.Mutation = (*ScanRecordMutation)(nil) - -// scanrecordOption allows management of the mutation configuration using functional options. -type scanrecordOption func(*ScanRecordMutation) - -// newScanRecordMutation creates new mutation for the ScanRecord entity. -func newScanRecordMutation(c config, op Op, opts ...scanrecordOption) *ScanRecordMutation { - m := &ScanRecordMutation{ - config: c, - op: op, - typ: TypeScanRecord, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withScanRecordID sets the ID field of the mutation. -func withScanRecordID(id int) scanrecordOption { - return func(m *ScanRecordMutation) { - var ( - err error - once sync.Once - value *ScanRecord - ) - m.oldValue = func(ctx context.Context) (*ScanRecord, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().ScanRecord.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withScanRecord sets the old ScanRecord of the mutation. -func withScanRecord(node *ScanRecord) scanrecordOption { - return func(m *ScanRecordMutation) { - m.oldValue = func(context.Context) (*ScanRecord, 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 ScanRecordMutation) 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 ScanRecordMutation) 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 ScanRecord entities. -func (m *ScanRecordMutation) 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 *ScanRecordMutation) 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 *ScanRecordMutation) 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().ScanRecord.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetStation sets the "station" field. -func (m *ScanRecordMutation) SetStation(s string) { - m.station = &s -} - -// Station returns the value of the "station" field in the mutation. -func (m *ScanRecordMutation) Station() (r string, exists bool) { - v := m.station - if v == nil { - return - } - return *v, true -} - -// OldStation returns the old "station" field's value of the ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) OldStation(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldStation is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldStation requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldStation: %w", err) - } - return oldValue.Station, nil -} - -// ResetStation resets all changes to the "station" field. -func (m *ScanRecordMutation) ResetStation() { - m.station = nil -} - -// SetSn sets the "sn" field. -func (m *ScanRecordMutation) SetSn(s string) { - m.sn = &s -} - -// Sn returns the value of the "sn" field in the mutation. -func (m *ScanRecordMutation) 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 ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) 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 *ScanRecordMutation) ResetSn() { - m.sn = nil -} - -// SetOrderNo sets the "orderNo" field. -func (m *ScanRecordMutation) SetOrderNo(s string) { - m.orderNo = &s -} - -// OrderNo returns the value of the "orderNo" field in the mutation. -func (m *ScanRecordMutation) OrderNo() (r string, exists bool) { - v := m.orderNo - if v == nil { - return - } - return *v, true -} - -// OldOrderNo returns the old "orderNo" field's value of the ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) OldOrderNo(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldOrderNo is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldOrderNo requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldOrderNo: %w", err) - } - return oldValue.OrderNo, nil -} - -// ResetOrderNo resets all changes to the "orderNo" field. -func (m *ScanRecordMutation) ResetOrderNo() { - m.orderNo = nil -} - -// SetType sets the "type" field. -func (m *ScanRecordMutation) SetType(s string) { - m._type = &s -} - -// GetType returns the value of the "type" field in the mutation. -func (m *ScanRecordMutation) GetType() (r string, exists bool) { - v := m._type - if v == nil { - return - } - return *v, true -} - -// OldType returns the old "type" field's value of the ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) OldType(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldType is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldType requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldType: %w", err) - } - return oldValue.Type, nil -} - -// ResetType resets all changes to the "type" field. -func (m *ScanRecordMutation) ResetType() { - m._type = nil -} - -// SetProcessCode sets the "processCode" field. -func (m *ScanRecordMutation) SetProcessCode(i int) { - m.processCode = &i - m.addprocessCode = nil -} - -// ProcessCode returns the value of the "processCode" field in the mutation. -func (m *ScanRecordMutation) ProcessCode() (r int, exists bool) { - v := m.processCode - if v == nil { - return - } - return *v, true -} - -// OldProcessCode returns the old "processCode" field's value of the ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) OldProcessCode(ctx context.Context) (v int, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldProcessCode is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldProcessCode requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldProcessCode: %w", err) - } - return oldValue.ProcessCode, nil -} - -// AddProcessCode adds i to the "processCode" field. -func (m *ScanRecordMutation) AddProcessCode(i int) { - if m.addprocessCode != nil { - *m.addprocessCode += i - } else { - m.addprocessCode = &i - } -} - -// AddedProcessCode returns the value that was added to the "processCode" field in this mutation. -func (m *ScanRecordMutation) AddedProcessCode() (r int, exists bool) { - v := m.addprocessCode - if v == nil { - return - } - return *v, true -} - -// ClearProcessCode clears the value of the "processCode" field. -func (m *ScanRecordMutation) ClearProcessCode() { - m.processCode = nil - m.addprocessCode = nil - m.clearedFields[scanrecord.FieldProcessCode] = struct{}{} -} - -// ProcessCodeCleared returns if the "processCode" field was cleared in this mutation. -func (m *ScanRecordMutation) ProcessCodeCleared() bool { - _, ok := m.clearedFields[scanrecord.FieldProcessCode] - return ok -} - -// ResetProcessCode resets all changes to the "processCode" field. -func (m *ScanRecordMutation) ResetProcessCode() { - m.processCode = nil - m.addprocessCode = nil - delete(m.clearedFields, scanrecord.FieldProcessCode) -} - -// SetOperator sets the "operator" field. -func (m *ScanRecordMutation) SetOperator(s string) { - m.operator = &s -} - -// Operator returns the value of the "operator" field in the mutation. -func (m *ScanRecordMutation) 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 ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) 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 *ScanRecordMutation) ResetOperator() { - m.operator = nil -} - -// SetTime sets the "time" field. -func (m *ScanRecordMutation) SetTime(t time.Time) { - m.time = &t -} - -// Time returns the value of the "time" field in the mutation. -func (m *ScanRecordMutation) Time() (r time.Time, exists bool) { - v := m.time - if v == nil { - return - } - return *v, true -} - -// OldTime returns the old "time" field's value of the ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) OldTime(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldTime is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldTime requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldTime: %w", err) - } - return oldValue.Time, nil -} - -// ResetTime resets all changes to the "time" field. -func (m *ScanRecordMutation) ResetTime() { - m.time = nil -} - -// SetCreatedAt sets the "createdAt" field. -func (m *ScanRecordMutation) SetCreatedAt(t time.Time) { - m.createdAt = &t -} - -// CreatedAt returns the value of the "createdAt" field in the mutation. -func (m *ScanRecordMutation) 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 ScanRecord entity. -// If the ScanRecord 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 *ScanRecordMutation) 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 *ScanRecordMutation) ResetCreatedAt() { - m.createdAt = nil -} - -// Where appends a list predicates to the ScanRecordMutation builder. -func (m *ScanRecordMutation) Where(ps ...predicate.ScanRecord) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the ScanRecordMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *ScanRecordMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.ScanRecord, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *ScanRecordMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *ScanRecordMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (ScanRecord). -func (m *ScanRecordMutation) 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 *ScanRecordMutation) Fields() []string { - fields := make([]string, 0, 8) - if m.station != nil { - fields = append(fields, scanrecord.FieldStation) - } - if m.sn != nil { - fields = append(fields, scanrecord.FieldSn) - } - if m.orderNo != nil { - fields = append(fields, scanrecord.FieldOrderNo) - } - if m._type != nil { - fields = append(fields, scanrecord.FieldType) - } - if m.processCode != nil { - fields = append(fields, scanrecord.FieldProcessCode) - } - if m.operator != nil { - fields = append(fields, scanrecord.FieldOperator) - } - if m.time != nil { - fields = append(fields, scanrecord.FieldTime) - } - if m.createdAt != nil { - fields = append(fields, scanrecord.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 *ScanRecordMutation) Field(name string) (ent.Value, bool) { - switch name { - case scanrecord.FieldStation: - return m.Station() - case scanrecord.FieldSn: - return m.Sn() - case scanrecord.FieldOrderNo: - return m.OrderNo() - case scanrecord.FieldType: - return m.GetType() - case scanrecord.FieldProcessCode: - return m.ProcessCode() - case scanrecord.FieldOperator: - return m.Operator() - case scanrecord.FieldTime: - return m.Time() - case scanrecord.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 *ScanRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case scanrecord.FieldStation: - return m.OldStation(ctx) - case scanrecord.FieldSn: - return m.OldSn(ctx) - case scanrecord.FieldOrderNo: - return m.OldOrderNo(ctx) - case scanrecord.FieldType: - return m.OldType(ctx) - case scanrecord.FieldProcessCode: - return m.OldProcessCode(ctx) - case scanrecord.FieldOperator: - return m.OldOperator(ctx) - case scanrecord.FieldTime: - return m.OldTime(ctx) - case scanrecord.FieldCreatedAt: - return m.OldCreatedAt(ctx) - } - return nil, fmt.Errorf("unknown ScanRecord 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 *ScanRecordMutation) SetField(name string, value ent.Value) error { - switch name { - case scanrecord.FieldStation: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetStation(v) - return nil - case scanrecord.FieldSn: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetSn(v) - return nil - case scanrecord.FieldOrderNo: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetOrderNo(v) - return nil - case scanrecord.FieldType: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetType(v) - return nil - case scanrecord.FieldProcessCode: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetProcessCode(v) - return nil - case scanrecord.FieldOperator: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetOperator(v) - return nil - case scanrecord.FieldTime: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTime(v) - return nil - case scanrecord.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 ScanRecord field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *ScanRecordMutation) AddedFields() []string { - var fields []string - if m.addprocessCode != nil { - fields = append(fields, scanrecord.FieldProcessCode) - } - 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 *ScanRecordMutation) AddedField(name string) (ent.Value, bool) { - switch name { - case scanrecord.FieldProcessCode: - return m.AddedProcessCode() - } - 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 *ScanRecordMutation) AddField(name string, value ent.Value) error { - switch name { - case scanrecord.FieldProcessCode: - v, ok := value.(int) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.AddProcessCode(v) - return nil - } - return fmt.Errorf("unknown ScanRecord numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *ScanRecordMutation) ClearedFields() []string { - var fields []string - if m.FieldCleared(scanrecord.FieldProcessCode) { - fields = append(fields, scanrecord.FieldProcessCode) - } - return fields -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *ScanRecordMutation) 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 *ScanRecordMutation) ClearField(name string) error { - switch name { - case scanrecord.FieldProcessCode: - m.ClearProcessCode() - return nil - } - return fmt.Errorf("unknown ScanRecord 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 *ScanRecordMutation) ResetField(name string) error { - switch name { - case scanrecord.FieldStation: - m.ResetStation() - return nil - case scanrecord.FieldSn: - m.ResetSn() - return nil - case scanrecord.FieldOrderNo: - m.ResetOrderNo() - return nil - case scanrecord.FieldType: - m.ResetType() - return nil - case scanrecord.FieldProcessCode: - m.ResetProcessCode() - return nil - case scanrecord.FieldOperator: - m.ResetOperator() - return nil - case scanrecord.FieldTime: - m.ResetTime() - return nil - case scanrecord.FieldCreatedAt: - m.ResetCreatedAt() - return nil - } - return fmt.Errorf("unknown ScanRecord field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *ScanRecordMutation) 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 *ScanRecordMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *ScanRecordMutation) 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 *ScanRecordMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *ScanRecordMutation) 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 *ScanRecordMutation) 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 *ScanRecordMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown ScanRecord 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 *ScanRecordMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown ScanRecord edge %s", name) -} - // SemiFlowMutation represents an operation that mutates the SemiFlow nodes in the graph. type SemiFlowMutation struct { config diff --git a/bj_power_mes/ent/predicate/predicate.go b/bj_power_mes/ent/predicate/predicate.go index 1e50b9b..7da5558 100644 --- a/bj_power_mes/ent/predicate/predicate.go +++ b/bj_power_mes/ent/predicate/predicate.go @@ -60,9 +60,6 @@ type ProductType func(*sql.Selector) // Role is the predicate function for role builders. type Role func(*sql.Selector) -// ScanRecord is the predicate function for scanrecord builders. -type ScanRecord func(*sql.Selector) - // SemiFlow is the predicate function for semiflow builders. type SemiFlow func(*sql.Selector) diff --git a/bj_power_mes/ent/runtime.go b/bj_power_mes/ent/runtime.go index 29d4c20..a097cdc 100644 --- a/bj_power_mes/ent/runtime.go +++ b/bj_power_mes/ent/runtime.go @@ -21,7 +21,6 @@ import ( "bj_power_mes/ent/processstep" "bj_power_mes/ent/producttype" "bj_power_mes/ent/role" - "bj_power_mes/ent/scanrecord" "bj_power_mes/ent/semiflow" "bj_power_mes/ent/station" "bj_power_mes/ent/stationprocess" @@ -1121,48 +1120,6 @@ func init() { roleDescID := roleFields[0].Descriptor() // role.IDValidator is a validator for the "id" field. It is called by the builders before save. role.IDValidator = roleDescID.Validators[0].(func(int) error) - scanrecordFields := schema.ScanRecord{}.Fields() - _ = scanrecordFields - // scanrecordDescStation is the schema descriptor for station field. - scanrecordDescStation := scanrecordFields[1].Descriptor() - // scanrecord.DefaultStation holds the default value on creation for the station field. - scanrecord.DefaultStation = scanrecordDescStation.Default.(string) - // scanrecord.StationValidator is a validator for the "station" field. It is called by the builders before save. - scanrecord.StationValidator = scanrecordDescStation.Validators[0].(func(string) error) - // scanrecordDescSn is the schema descriptor for sn field. - scanrecordDescSn := scanrecordFields[2].Descriptor() - // scanrecord.SnValidator is a validator for the "sn" field. It is called by the builders before save. - scanrecord.SnValidator = scanrecordDescSn.Validators[0].(func(string) error) - // scanrecordDescOrderNo is the schema descriptor for orderNo field. - scanrecordDescOrderNo := scanrecordFields[3].Descriptor() - // scanrecord.DefaultOrderNo holds the default value on creation for the orderNo field. - scanrecord.DefaultOrderNo = scanrecordDescOrderNo.Default.(string) - // scanrecord.OrderNoValidator is a validator for the "orderNo" field. It is called by the builders before save. - scanrecord.OrderNoValidator = scanrecordDescOrderNo.Validators[0].(func(string) error) - // scanrecordDescType is the schema descriptor for type field. - scanrecordDescType := scanrecordFields[4].Descriptor() - // scanrecord.DefaultType holds the default value on creation for the type field. - scanrecord.DefaultType = scanrecordDescType.Default.(string) - // scanrecord.TypeValidator is a validator for the "type" field. It is called by the builders before save. - scanrecord.TypeValidator = scanrecordDescType.Validators[0].(func(string) error) - // scanrecordDescOperator is the schema descriptor for operator field. - scanrecordDescOperator := scanrecordFields[6].Descriptor() - // scanrecord.DefaultOperator holds the default value on creation for the operator field. - scanrecord.DefaultOperator = scanrecordDescOperator.Default.(string) - // scanrecord.OperatorValidator is a validator for the "operator" field. It is called by the builders before save. - scanrecord.OperatorValidator = scanrecordDescOperator.Validators[0].(func(string) error) - // scanrecordDescTime is the schema descriptor for time field. - scanrecordDescTime := scanrecordFields[7].Descriptor() - // scanrecord.DefaultTime holds the default value on creation for the time field. - scanrecord.DefaultTime = scanrecordDescTime.Default.(func() time.Time) - // scanrecordDescCreatedAt is the schema descriptor for createdAt field. - scanrecordDescCreatedAt := scanrecordFields[8].Descriptor() - // scanrecord.DefaultCreatedAt holds the default value on creation for the createdAt field. - scanrecord.DefaultCreatedAt = scanrecordDescCreatedAt.Default.(func() time.Time) - // scanrecordDescID is the schema descriptor for id field. - scanrecordDescID := scanrecordFields[0].Descriptor() - // scanrecord.IDValidator is a validator for the "id" field. It is called by the builders before save. - scanrecord.IDValidator = scanrecordDescID.Validators[0].(func(int) error) semiflowFields := schema.SemiFlow{}.Fields() _ = semiflowFields // semiflowDescSn is the schema descriptor for sn field. diff --git a/bj_power_mes/ent/scanrecord.go b/bj_power_mes/ent/scanrecord.go deleted file mode 100644 index f86ebed..0000000 --- a/bj_power_mes/ent/scanrecord.go +++ /dev/null @@ -1,183 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_mes/ent/scanrecord" - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" -) - -// ScanRecord is the model entity for the ScanRecord schema. -type ScanRecord struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // 工位/扫码点 - Station string `json:"station,omitempty"` - // 工件SN - Sn string `json:"sn,omitempty"` - // 工单号 - OrderNo string `json:"orderNo,omitempty"` - // 报工类型 - Type string `json:"type,omitempty"` - // 工序号 1~12 - ProcessCode int `json:"processCode,omitempty"` - // 操作人 - Operator string `json:"operator,omitempty"` - // 报工时间 - Time time.Time `json:"time,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 (*ScanRecord) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case scanrecord.FieldID, scanrecord.FieldProcessCode: - values[i] = new(sql.NullInt64) - case scanrecord.FieldStation, scanrecord.FieldSn, scanrecord.FieldOrderNo, scanrecord.FieldType, scanrecord.FieldOperator: - values[i] = new(sql.NullString) - case scanrecord.FieldTime, scanrecord.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 ScanRecord fields. -func (_m *ScanRecord) 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 scanrecord.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 scanrecord.FieldStation: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field station", values[i]) - } else if value.Valid { - _m.Station = value.String - } - case scanrecord.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 scanrecord.FieldOrderNo: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field orderNo", values[i]) - } else if value.Valid { - _m.OrderNo = value.String - } - case scanrecord.FieldType: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field type", values[i]) - } else if value.Valid { - _m.Type = value.String - } - case scanrecord.FieldProcessCode: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for field processCode", values[i]) - } else if value.Valid { - _m.ProcessCode = int(value.Int64) - } - case scanrecord.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 scanrecord.FieldTime: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field time", values[i]) - } else if value.Valid { - _m.Time = value.Time - } - case scanrecord.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 ScanRecord. -// This includes values selected through modifiers, order, etc. -func (_m *ScanRecord) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// Update returns a builder for updating this ScanRecord. -// Note that you need to call ScanRecord.Unwrap() before calling this method if this ScanRecord -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *ScanRecord) Update() *ScanRecordUpdateOne { - return NewScanRecordClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the ScanRecord 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 *ScanRecord) Unwrap() *ScanRecord { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: ScanRecord is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *ScanRecord) String() string { - var builder strings.Builder - builder.WriteString("ScanRecord(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("station=") - builder.WriteString(_m.Station) - builder.WriteString(", ") - builder.WriteString("sn=") - builder.WriteString(_m.Sn) - builder.WriteString(", ") - builder.WriteString("orderNo=") - builder.WriteString(_m.OrderNo) - builder.WriteString(", ") - builder.WriteString("type=") - builder.WriteString(_m.Type) - builder.WriteString(", ") - builder.WriteString("processCode=") - builder.WriteString(fmt.Sprintf("%v", _m.ProcessCode)) - builder.WriteString(", ") - builder.WriteString("operator=") - builder.WriteString(_m.Operator) - builder.WriteString(", ") - builder.WriteString("time=") - builder.WriteString(_m.Time.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("createdAt=") - builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// ScanRecords is a parsable slice of ScanRecord. -type ScanRecords []*ScanRecord diff --git a/bj_power_mes/ent/scanrecord/scanrecord.go b/bj_power_mes/ent/scanrecord/scanrecord.go deleted file mode 100644 index 25abbeb..0000000 --- a/bj_power_mes/ent/scanrecord/scanrecord.go +++ /dev/null @@ -1,132 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package scanrecord - -import ( - "time" - - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the scanrecord type in the database. - Label = "scan_record" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldStation holds the string denoting the station field in the database. - FieldStation = "station" - // FieldSn holds the string denoting the sn field in the database. - FieldSn = "sn" - // FieldOrderNo holds the string denoting the orderno field in the database. - FieldOrderNo = "order_no" - // FieldType holds the string denoting the type field in the database. - FieldType = "type" - // FieldProcessCode holds the string denoting the processcode field in the database. - FieldProcessCode = "process_code" - // FieldOperator holds the string denoting the operator field in the database. - FieldOperator = "operator" - // FieldTime holds the string denoting the time field in the database. - FieldTime = "time" - // FieldCreatedAt holds the string denoting the createdat field in the database. - FieldCreatedAt = "created_at" - // Table holds the table name of the scanrecord in the database. - Table = "scan_record" -) - -// Columns holds all SQL columns for scanrecord fields. -var Columns = []string{ - FieldID, - FieldStation, - FieldSn, - FieldOrderNo, - FieldType, - FieldProcessCode, - FieldOperator, - FieldTime, - 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 ( - // DefaultStation holds the default value on creation for the "station" field. - DefaultStation string - // StationValidator is a validator for the "station" field. It is called by the builders before save. - StationValidator func(string) error - // SnValidator is a validator for the "sn" field. It is called by the builders before save. - SnValidator func(string) error - // DefaultOrderNo holds the default value on creation for the "orderNo" field. - DefaultOrderNo string - // OrderNoValidator is a validator for the "orderNo" field. It is called by the builders before save. - OrderNoValidator func(string) error - // DefaultType holds the default value on creation for the "type" field. - DefaultType string - // TypeValidator is a validator for the "type" field. It is called by the builders before save. - TypeValidator 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 - // DefaultTime holds the default value on creation for the "time" field. - DefaultTime func() time.Time - // 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 ScanRecord 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() -} - -// ByStation orders the results by the station field. -func ByStation(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldStation, opts...).ToFunc() -} - -// BySn orders the results by the sn field. -func BySn(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldSn, opts...).ToFunc() -} - -// ByOrderNo orders the results by the orderNo field. -func ByOrderNo(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldOrderNo, opts...).ToFunc() -} - -// ByType orders the results by the type field. -func ByType(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldType, opts...).ToFunc() -} - -// ByProcessCode orders the results by the processCode field. -func ByProcessCode(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldProcessCode, opts...).ToFunc() -} - -// ByOperator orders the results by the operator field. -func ByOperator(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldOperator, opts...).ToFunc() -} - -// ByTime orders the results by the time field. -func ByTime(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldTime, 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/scanrecord/where.go b/bj_power_mes/ent/scanrecord/where.go deleted file mode 100644 index 8f09f12..0000000 --- a/bj_power_mes/ent/scanrecord/where.go +++ /dev/null @@ -1,565 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package scanrecord - -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.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldID, id)) -} - -// Station applies equality check predicate on the "station" field. It's identical to StationEQ. -func Station(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldStation, v)) -} - -// Sn applies equality check predicate on the "sn" field. It's identical to SnEQ. -func Sn(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldSn, v)) -} - -// OrderNo applies equality check predicate on the "orderNo" field. It's identical to OrderNoEQ. -func OrderNo(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldOrderNo, v)) -} - -// Type applies equality check predicate on the "type" field. It's identical to TypeEQ. -func Type(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldType, v)) -} - -// ProcessCode applies equality check predicate on the "processCode" field. It's identical to ProcessCodeEQ. -func ProcessCode(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldProcessCode, v)) -} - -// Operator applies equality check predicate on the "operator" field. It's identical to OperatorEQ. -func Operator(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldOperator, v)) -} - -// Time applies equality check predicate on the "time" field. It's identical to TimeEQ. -func Time(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldTime, v)) -} - -// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldCreatedAt, v)) -} - -// StationEQ applies the EQ predicate on the "station" field. -func StationEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldStation, v)) -} - -// StationNEQ applies the NEQ predicate on the "station" field. -func StationNEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldStation, v)) -} - -// StationIn applies the In predicate on the "station" field. -func StationIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldStation, vs...)) -} - -// StationNotIn applies the NotIn predicate on the "station" field. -func StationNotIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldStation, vs...)) -} - -// StationGT applies the GT predicate on the "station" field. -func StationGT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldStation, v)) -} - -// StationGTE applies the GTE predicate on the "station" field. -func StationGTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldStation, v)) -} - -// StationLT applies the LT predicate on the "station" field. -func StationLT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldStation, v)) -} - -// StationLTE applies the LTE predicate on the "station" field. -func StationLTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldStation, v)) -} - -// StationContains applies the Contains predicate on the "station" field. -func StationContains(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContains(FieldStation, v)) -} - -// StationHasPrefix applies the HasPrefix predicate on the "station" field. -func StationHasPrefix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasPrefix(FieldStation, v)) -} - -// StationHasSuffix applies the HasSuffix predicate on the "station" field. -func StationHasSuffix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasSuffix(FieldStation, v)) -} - -// StationEqualFold applies the EqualFold predicate on the "station" field. -func StationEqualFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEqualFold(FieldStation, v)) -} - -// StationContainsFold applies the ContainsFold predicate on the "station" field. -func StationContainsFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContainsFold(FieldStation, v)) -} - -// SnEQ applies the EQ predicate on the "sn" field. -func SnEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldSn, v)) -} - -// SnNEQ applies the NEQ predicate on the "sn" field. -func SnNEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldSn, v)) -} - -// SnIn applies the In predicate on the "sn" field. -func SnIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldSn, vs...)) -} - -// SnNotIn applies the NotIn predicate on the "sn" field. -func SnNotIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldSn, vs...)) -} - -// SnGT applies the GT predicate on the "sn" field. -func SnGT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldSn, v)) -} - -// SnGTE applies the GTE predicate on the "sn" field. -func SnGTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldSn, v)) -} - -// SnLT applies the LT predicate on the "sn" field. -func SnLT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldSn, v)) -} - -// SnLTE applies the LTE predicate on the "sn" field. -func SnLTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldSn, v)) -} - -// SnContains applies the Contains predicate on the "sn" field. -func SnContains(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContains(FieldSn, v)) -} - -// SnHasPrefix applies the HasPrefix predicate on the "sn" field. -func SnHasPrefix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasPrefix(FieldSn, v)) -} - -// SnHasSuffix applies the HasSuffix predicate on the "sn" field. -func SnHasSuffix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasSuffix(FieldSn, v)) -} - -// SnEqualFold applies the EqualFold predicate on the "sn" field. -func SnEqualFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEqualFold(FieldSn, v)) -} - -// SnContainsFold applies the ContainsFold predicate on the "sn" field. -func SnContainsFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContainsFold(FieldSn, v)) -} - -// OrderNoEQ applies the EQ predicate on the "orderNo" field. -func OrderNoEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldOrderNo, v)) -} - -// OrderNoNEQ applies the NEQ predicate on the "orderNo" field. -func OrderNoNEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldOrderNo, v)) -} - -// OrderNoIn applies the In predicate on the "orderNo" field. -func OrderNoIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldOrderNo, vs...)) -} - -// OrderNoNotIn applies the NotIn predicate on the "orderNo" field. -func OrderNoNotIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldOrderNo, vs...)) -} - -// OrderNoGT applies the GT predicate on the "orderNo" field. -func OrderNoGT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldOrderNo, v)) -} - -// OrderNoGTE applies the GTE predicate on the "orderNo" field. -func OrderNoGTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldOrderNo, v)) -} - -// OrderNoLT applies the LT predicate on the "orderNo" field. -func OrderNoLT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldOrderNo, v)) -} - -// OrderNoLTE applies the LTE predicate on the "orderNo" field. -func OrderNoLTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldOrderNo, v)) -} - -// OrderNoContains applies the Contains predicate on the "orderNo" field. -func OrderNoContains(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContains(FieldOrderNo, v)) -} - -// OrderNoHasPrefix applies the HasPrefix predicate on the "orderNo" field. -func OrderNoHasPrefix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasPrefix(FieldOrderNo, v)) -} - -// OrderNoHasSuffix applies the HasSuffix predicate on the "orderNo" field. -func OrderNoHasSuffix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasSuffix(FieldOrderNo, v)) -} - -// OrderNoEqualFold applies the EqualFold predicate on the "orderNo" field. -func OrderNoEqualFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEqualFold(FieldOrderNo, v)) -} - -// OrderNoContainsFold applies the ContainsFold predicate on the "orderNo" field. -func OrderNoContainsFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContainsFold(FieldOrderNo, v)) -} - -// TypeEQ applies the EQ predicate on the "type" field. -func TypeEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldType, v)) -} - -// TypeNEQ applies the NEQ predicate on the "type" field. -func TypeNEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldType, v)) -} - -// TypeIn applies the In predicate on the "type" field. -func TypeIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldType, vs...)) -} - -// TypeNotIn applies the NotIn predicate on the "type" field. -func TypeNotIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldType, vs...)) -} - -// TypeGT applies the GT predicate on the "type" field. -func TypeGT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldType, v)) -} - -// TypeGTE applies the GTE predicate on the "type" field. -func TypeGTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldType, v)) -} - -// TypeLT applies the LT predicate on the "type" field. -func TypeLT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldType, v)) -} - -// TypeLTE applies the LTE predicate on the "type" field. -func TypeLTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldType, v)) -} - -// TypeContains applies the Contains predicate on the "type" field. -func TypeContains(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContains(FieldType, v)) -} - -// TypeHasPrefix applies the HasPrefix predicate on the "type" field. -func TypeHasPrefix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasPrefix(FieldType, v)) -} - -// TypeHasSuffix applies the HasSuffix predicate on the "type" field. -func TypeHasSuffix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasSuffix(FieldType, v)) -} - -// TypeEqualFold applies the EqualFold predicate on the "type" field. -func TypeEqualFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEqualFold(FieldType, v)) -} - -// TypeContainsFold applies the ContainsFold predicate on the "type" field. -func TypeContainsFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContainsFold(FieldType, v)) -} - -// ProcessCodeEQ applies the EQ predicate on the "processCode" field. -func ProcessCodeEQ(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldProcessCode, v)) -} - -// ProcessCodeNEQ applies the NEQ predicate on the "processCode" field. -func ProcessCodeNEQ(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldProcessCode, v)) -} - -// ProcessCodeIn applies the In predicate on the "processCode" field. -func ProcessCodeIn(vs ...int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldProcessCode, vs...)) -} - -// ProcessCodeNotIn applies the NotIn predicate on the "processCode" field. -func ProcessCodeNotIn(vs ...int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldProcessCode, vs...)) -} - -// ProcessCodeGT applies the GT predicate on the "processCode" field. -func ProcessCodeGT(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldProcessCode, v)) -} - -// ProcessCodeGTE applies the GTE predicate on the "processCode" field. -func ProcessCodeGTE(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldProcessCode, v)) -} - -// ProcessCodeLT applies the LT predicate on the "processCode" field. -func ProcessCodeLT(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldProcessCode, v)) -} - -// ProcessCodeLTE applies the LTE predicate on the "processCode" field. -func ProcessCodeLTE(v int) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldProcessCode, v)) -} - -// ProcessCodeIsNil applies the IsNil predicate on the "processCode" field. -func ProcessCodeIsNil() predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIsNull(FieldProcessCode)) -} - -// ProcessCodeNotNil applies the NotNil predicate on the "processCode" field. -func ProcessCodeNotNil() predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotNull(FieldProcessCode)) -} - -// OperatorEQ applies the EQ predicate on the "operator" field. -func OperatorEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldOperator, v)) -} - -// OperatorNEQ applies the NEQ predicate on the "operator" field. -func OperatorNEQ(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldOperator, v)) -} - -// OperatorIn applies the In predicate on the "operator" field. -func OperatorIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldOperator, vs...)) -} - -// OperatorNotIn applies the NotIn predicate on the "operator" field. -func OperatorNotIn(vs ...string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldOperator, vs...)) -} - -// OperatorGT applies the GT predicate on the "operator" field. -func OperatorGT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldOperator, v)) -} - -// OperatorGTE applies the GTE predicate on the "operator" field. -func OperatorGTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldOperator, v)) -} - -// OperatorLT applies the LT predicate on the "operator" field. -func OperatorLT(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldOperator, v)) -} - -// OperatorLTE applies the LTE predicate on the "operator" field. -func OperatorLTE(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldOperator, v)) -} - -// OperatorContains applies the Contains predicate on the "operator" field. -func OperatorContains(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContains(FieldOperator, v)) -} - -// OperatorHasPrefix applies the HasPrefix predicate on the "operator" field. -func OperatorHasPrefix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasPrefix(FieldOperator, v)) -} - -// OperatorHasSuffix applies the HasSuffix predicate on the "operator" field. -func OperatorHasSuffix(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldHasSuffix(FieldOperator, v)) -} - -// OperatorEqualFold applies the EqualFold predicate on the "operator" field. -func OperatorEqualFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEqualFold(FieldOperator, v)) -} - -// OperatorContainsFold applies the ContainsFold predicate on the "operator" field. -func OperatorContainsFold(v string) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldContainsFold(FieldOperator, v)) -} - -// TimeEQ applies the EQ predicate on the "time" field. -func TimeEQ(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldTime, v)) -} - -// TimeNEQ applies the NEQ predicate on the "time" field. -func TimeNEQ(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldTime, v)) -} - -// TimeIn applies the In predicate on the "time" field. -func TimeIn(vs ...time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldTime, vs...)) -} - -// TimeNotIn applies the NotIn predicate on the "time" field. -func TimeNotIn(vs ...time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldTime, vs...)) -} - -// TimeGT applies the GT predicate on the "time" field. -func TimeGT(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldTime, v)) -} - -// TimeGTE applies the GTE predicate on the "time" field. -func TimeGTE(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldTime, v)) -} - -// TimeLT applies the LT predicate on the "time" field. -func TimeLT(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldTime, v)) -} - -// TimeLTE applies the LTE predicate on the "time" field. -func TimeLTE(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldTime, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "createdAt" field. -func CreatedAtEQ(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. -func CreatedAtNEQ(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "createdAt" field. -func CreatedAtIn(vs ...time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. -func CreatedAtNotIn(vs ...time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "createdAt" field. -func CreatedAtGT(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "createdAt" field. -func CreatedAtGTE(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "createdAt" field. -func CreatedAtLT(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "createdAt" field. -func CreatedAtLTE(v time.Time) predicate.ScanRecord { - return predicate.ScanRecord(sql.FieldLTE(FieldCreatedAt, v)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.ScanRecord) predicate.ScanRecord { - return predicate.ScanRecord(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.ScanRecord) predicate.ScanRecord { - return predicate.ScanRecord(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.ScanRecord) predicate.ScanRecord { - return predicate.ScanRecord(sql.NotPredicates(p)) -} diff --git a/bj_power_mes/ent/scanrecord_create.go b/bj_power_mes/ent/scanrecord_create.go deleted file mode 100644 index 8f45071..0000000 --- a/bj_power_mes/ent/scanrecord_create.go +++ /dev/null @@ -1,400 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_mes/ent/scanrecord" - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// ScanRecordCreate is the builder for creating a ScanRecord entity. -type ScanRecordCreate struct { - config - mutation *ScanRecordMutation - hooks []Hook -} - -// SetStation sets the "station" field. -func (_c *ScanRecordCreate) SetStation(v string) *ScanRecordCreate { - _c.mutation.SetStation(v) - return _c -} - -// SetNillableStation sets the "station" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableStation(v *string) *ScanRecordCreate { - if v != nil { - _c.SetStation(*v) - } - return _c -} - -// SetSn sets the "sn" field. -func (_c *ScanRecordCreate) SetSn(v string) *ScanRecordCreate { - _c.mutation.SetSn(v) - return _c -} - -// SetOrderNo sets the "orderNo" field. -func (_c *ScanRecordCreate) SetOrderNo(v string) *ScanRecordCreate { - _c.mutation.SetOrderNo(v) - return _c -} - -// SetNillableOrderNo sets the "orderNo" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableOrderNo(v *string) *ScanRecordCreate { - if v != nil { - _c.SetOrderNo(*v) - } - return _c -} - -// SetType sets the "type" field. -func (_c *ScanRecordCreate) SetType(v string) *ScanRecordCreate { - _c.mutation.SetType(v) - return _c -} - -// SetNillableType sets the "type" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableType(v *string) *ScanRecordCreate { - if v != nil { - _c.SetType(*v) - } - return _c -} - -// SetProcessCode sets the "processCode" field. -func (_c *ScanRecordCreate) SetProcessCode(v int) *ScanRecordCreate { - _c.mutation.SetProcessCode(v) - return _c -} - -// SetNillableProcessCode sets the "processCode" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableProcessCode(v *int) *ScanRecordCreate { - if v != nil { - _c.SetProcessCode(*v) - } - return _c -} - -// SetOperator sets the "operator" field. -func (_c *ScanRecordCreate) SetOperator(v string) *ScanRecordCreate { - _c.mutation.SetOperator(v) - return _c -} - -// SetNillableOperator sets the "operator" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableOperator(v *string) *ScanRecordCreate { - if v != nil { - _c.SetOperator(*v) - } - return _c -} - -// SetTime sets the "time" field. -func (_c *ScanRecordCreate) SetTime(v time.Time) *ScanRecordCreate { - _c.mutation.SetTime(v) - return _c -} - -// SetNillableTime sets the "time" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableTime(v *time.Time) *ScanRecordCreate { - if v != nil { - _c.SetTime(*v) - } - return _c -} - -// SetCreatedAt sets the "createdAt" field. -func (_c *ScanRecordCreate) SetCreatedAt(v time.Time) *ScanRecordCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. -func (_c *ScanRecordCreate) SetNillableCreatedAt(v *time.Time) *ScanRecordCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetID sets the "id" field. -func (_c *ScanRecordCreate) SetID(v int) *ScanRecordCreate { - _c.mutation.SetID(v) - return _c -} - -// Mutation returns the ScanRecordMutation object of the builder. -func (_c *ScanRecordCreate) Mutation() *ScanRecordMutation { - return _c.mutation -} - -// Save creates the ScanRecord in the database. -func (_c *ScanRecordCreate) Save(ctx context.Context) (*ScanRecord, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *ScanRecordCreate) SaveX(ctx context.Context) *ScanRecord { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *ScanRecordCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *ScanRecordCreate) 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 *ScanRecordCreate) defaults() { - if _, ok := _c.mutation.Station(); !ok { - v := scanrecord.DefaultStation - _c.mutation.SetStation(v) - } - if _, ok := _c.mutation.OrderNo(); !ok { - v := scanrecord.DefaultOrderNo - _c.mutation.SetOrderNo(v) - } - if _, ok := _c.mutation.GetType(); !ok { - v := scanrecord.DefaultType - _c.mutation.SetType(v) - } - if _, ok := _c.mutation.Operator(); !ok { - v := scanrecord.DefaultOperator - _c.mutation.SetOperator(v) - } - if _, ok := _c.mutation.Time(); !ok { - v := scanrecord.DefaultTime() - _c.mutation.SetTime(v) - } - if _, ok := _c.mutation.CreatedAt(); !ok { - v := scanrecord.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *ScanRecordCreate) check() error { - if _, ok := _c.mutation.Station(); !ok { - return &ValidationError{Name: "station", err: errors.New(`ent: missing required field "ScanRecord.station"`)} - } - if v, ok := _c.mutation.Station(); ok { - if err := scanrecord.StationValidator(v); err != nil { - return &ValidationError{Name: "station", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.station": %w`, err)} - } - } - if _, ok := _c.mutation.Sn(); !ok { - return &ValidationError{Name: "sn", err: errors.New(`ent: missing required field "ScanRecord.sn"`)} - } - if v, ok := _c.mutation.Sn(); ok { - if err := scanrecord.SnValidator(v); err != nil { - return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.sn": %w`, err)} - } - } - if _, ok := _c.mutation.OrderNo(); !ok { - return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "ScanRecord.orderNo"`)} - } - if v, ok := _c.mutation.OrderNo(); ok { - if err := scanrecord.OrderNoValidator(v); err != nil { - return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.orderNo": %w`, err)} - } - } - if _, ok := _c.mutation.GetType(); !ok { - return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "ScanRecord.type"`)} - } - if v, ok := _c.mutation.GetType(); ok { - if err := scanrecord.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.type": %w`, err)} - } - } - if _, ok := _c.mutation.Operator(); !ok { - return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "ScanRecord.operator"`)} - } - if v, ok := _c.mutation.Operator(); ok { - if err := scanrecord.OperatorValidator(v); err != nil { - return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.operator": %w`, err)} - } - } - if _, ok := _c.mutation.Time(); !ok { - return &ValidationError{Name: "time", err: errors.New(`ent: missing required field "ScanRecord.time"`)} - } - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "ScanRecord.createdAt"`)} - } - if v, ok := _c.mutation.ID(); ok { - if err := scanrecord.IDValidator(v); err != nil { - return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.id": %w`, err)} - } - } - return nil -} - -func (_c *ScanRecordCreate) sqlSave(ctx context.Context) (*ScanRecord, 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 *ScanRecordCreate) createSpec() (*ScanRecord, *sqlgraph.CreateSpec) { - var ( - _node = &ScanRecord{config: _c.config} - _spec = sqlgraph.NewCreateSpec(scanrecord.Table, sqlgraph.NewFieldSpec(scanrecord.FieldID, field.TypeInt)) - ) - if id, ok := _c.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := _c.mutation.Station(); ok { - _spec.SetField(scanrecord.FieldStation, field.TypeString, value) - _node.Station = value - } - if value, ok := _c.mutation.Sn(); ok { - _spec.SetField(scanrecord.FieldSn, field.TypeString, value) - _node.Sn = value - } - if value, ok := _c.mutation.OrderNo(); ok { - _spec.SetField(scanrecord.FieldOrderNo, field.TypeString, value) - _node.OrderNo = value - } - if value, ok := _c.mutation.GetType(); ok { - _spec.SetField(scanrecord.FieldType, field.TypeString, value) - _node.Type = value - } - if value, ok := _c.mutation.ProcessCode(); ok { - _spec.SetField(scanrecord.FieldProcessCode, field.TypeInt, value) - _node.ProcessCode = value - } - if value, ok := _c.mutation.Operator(); ok { - _spec.SetField(scanrecord.FieldOperator, field.TypeString, value) - _node.Operator = value - } - if value, ok := _c.mutation.Time(); ok { - _spec.SetField(scanrecord.FieldTime, field.TypeTime, value) - _node.Time = value - } - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(scanrecord.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - return _node, _spec -} - -// ScanRecordCreateBulk is the builder for creating many ScanRecord entities in bulk. -type ScanRecordCreateBulk struct { - config - err error - builders []*ScanRecordCreate -} - -// Save creates the ScanRecord entities in the database. -func (_c *ScanRecordCreateBulk) Save(ctx context.Context) ([]*ScanRecord, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*ScanRecord, 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.(*ScanRecordMutation) - 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 *ScanRecordCreateBulk) SaveX(ctx context.Context) []*ScanRecord { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *ScanRecordCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *ScanRecordCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/bj_power_mes/ent/scanrecord_delete.go b/bj_power_mes/ent/scanrecord_delete.go deleted file mode 100644 index 5e8da12..0000000 --- a/bj_power_mes/ent/scanrecord_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_mes/ent/predicate" - "bj_power_mes/ent/scanrecord" - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// ScanRecordDelete is the builder for deleting a ScanRecord entity. -type ScanRecordDelete struct { - config - hooks []Hook - mutation *ScanRecordMutation -} - -// Where appends a list predicates to the ScanRecordDelete builder. -func (_d *ScanRecordDelete) Where(ps ...predicate.ScanRecord) *ScanRecordDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *ScanRecordDelete) 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 *ScanRecordDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *ScanRecordDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(scanrecord.Table, sqlgraph.NewFieldSpec(scanrecord.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 -} - -// ScanRecordDeleteOne is the builder for deleting a single ScanRecord entity. -type ScanRecordDeleteOne struct { - _d *ScanRecordDelete -} - -// Where appends a list predicates to the ScanRecordDelete builder. -func (_d *ScanRecordDeleteOne) Where(ps ...predicate.ScanRecord) *ScanRecordDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *ScanRecordDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{scanrecord.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *ScanRecordDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/bj_power_mes/ent/scanrecord_query.go b/bj_power_mes/ent/scanrecord_query.go deleted file mode 100644 index e9cb2ab..0000000 --- a/bj_power_mes/ent/scanrecord_query.go +++ /dev/null @@ -1,577 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_mes/ent/predicate" - "bj_power_mes/ent/scanrecord" - "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" -) - -// ScanRecordQuery is the builder for querying ScanRecord entities. -type ScanRecordQuery struct { - config - ctx *QueryContext - order []scanrecord.OrderOption - inters []Interceptor - predicates []predicate.ScanRecord - 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 ScanRecordQuery builder. -func (_q *ScanRecordQuery) Where(ps ...predicate.ScanRecord) *ScanRecordQuery { - _q.predicates = append(_q.predicates, ps...) - return _q -} - -// Limit the number of records to be returned by this query. -func (_q *ScanRecordQuery) Limit(limit int) *ScanRecordQuery { - _q.ctx.Limit = &limit - return _q -} - -// Offset to start from. -func (_q *ScanRecordQuery) Offset(offset int) *ScanRecordQuery { - _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 *ScanRecordQuery) Unique(unique bool) *ScanRecordQuery { - _q.ctx.Unique = &unique - return _q -} - -// Order specifies how the records should be ordered. -func (_q *ScanRecordQuery) Order(o ...scanrecord.OrderOption) *ScanRecordQuery { - _q.order = append(_q.order, o...) - return _q -} - -// First returns the first ScanRecord entity from the query. -// Returns a *NotFoundError when no ScanRecord was found. -func (_q *ScanRecordQuery) First(ctx context.Context) (*ScanRecord, 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{scanrecord.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (_q *ScanRecordQuery) FirstX(ctx context.Context) *ScanRecord { - node, err := _q.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first ScanRecord ID from the query. -// Returns a *NotFoundError when no ScanRecord ID was found. -func (_q *ScanRecordQuery) 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{scanrecord.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *ScanRecordQuery) FirstIDX(ctx context.Context) int { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single ScanRecord entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one ScanRecord entity is found. -// Returns a *NotFoundError when no ScanRecord entities are found. -func (_q *ScanRecordQuery) Only(ctx context.Context) (*ScanRecord, 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{scanrecord.Label} - default: - return nil, &NotSingularError{scanrecord.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (_q *ScanRecordQuery) OnlyX(ctx context.Context) *ScanRecord { - node, err := _q.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only ScanRecord ID in the query. -// Returns a *NotSingularError when more than one ScanRecord ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *ScanRecordQuery) 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{scanrecord.Label} - default: - err = &NotSingularError{scanrecord.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *ScanRecordQuery) 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 ScanRecords. -func (_q *ScanRecordQuery) All(ctx context.Context) ([]*ScanRecord, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*ScanRecord, *ScanRecordQuery]() - return withInterceptors[[]*ScanRecord](ctx, _q, qr, _q.inters) -} - -// AllX is like All, but panics if an error occurs. -func (_q *ScanRecordQuery) AllX(ctx context.Context) []*ScanRecord { - nodes, err := _q.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of ScanRecord IDs. -func (_q *ScanRecordQuery) 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(scanrecord.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *ScanRecordQuery) 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 *ScanRecordQuery) 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[*ScanRecordQuery](), _q.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (_q *ScanRecordQuery) 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 *ScanRecordQuery) 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 *ScanRecordQuery) ExistX(ctx context.Context) bool { - exist, err := _q.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the ScanRecordQuery 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 *ScanRecordQuery) Clone() *ScanRecordQuery { - if _q == nil { - return nil - } - return &ScanRecordQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]scanrecord.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.ScanRecord{}, _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 { -// Station string `json:"station,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.ScanRecord.Query(). -// GroupBy(scanrecord.FieldStation). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (_q *ScanRecordQuery) GroupBy(field string, fields ...string) *ScanRecordGroupBy { - _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &ScanRecordGroupBy{build: _q} - grbuild.flds = &_q.ctx.Fields - grbuild.label = scanrecord.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 { -// Station string `json:"station,omitempty"` -// } -// -// client.ScanRecord.Query(). -// Select(scanrecord.FieldStation). -// Scan(ctx, &v) -func (_q *ScanRecordQuery) Select(fields ...string) *ScanRecordSelect { - _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &ScanRecordSelect{ScanRecordQuery: _q} - sbuild.label = scanrecord.Label - sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a ScanRecordSelect configured with the given aggregations. -func (_q *ScanRecordQuery) Aggregate(fns ...AggregateFunc) *ScanRecordSelect { - return _q.Select().Aggregate(fns...) -} - -func (_q *ScanRecordQuery) 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 !scanrecord.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 *ScanRecordQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ScanRecord, error) { - var ( - nodes = []*ScanRecord{} - _spec = _q.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*ScanRecord).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &ScanRecord{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 *ScanRecordQuery) 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 *ScanRecordQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(scanrecord.Table, scanrecord.Columns, sqlgraph.NewFieldSpec(scanrecord.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, scanrecord.FieldID) - for i := range fields { - if fields[i] != scanrecord.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 *ScanRecordQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(scanrecord.Table) - columns := _q.ctx.Fields - if len(columns) == 0 { - columns = scanrecord.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 *ScanRecordQuery) ForUpdate(opts ...sql.LockOption) *ScanRecordQuery { - 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 *ScanRecordQuery) ForShare(opts ...sql.LockOption) *ScanRecordQuery { - 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 *ScanRecordQuery) Modify(modifiers ...func(s *sql.Selector)) *ScanRecordSelect { - _q.modifiers = append(_q.modifiers, modifiers...) - return _q.Select() -} - -// ScanRecordGroupBy is the group-by builder for ScanRecord entities. -type ScanRecordGroupBy struct { - selector - build *ScanRecordQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (_g *ScanRecordGroupBy) Aggregate(fns ...AggregateFunc) *ScanRecordGroupBy { - _g.fns = append(_g.fns, fns...) - return _g -} - -// Scan applies the selector query and scans the result into the given value. -func (_g *ScanRecordGroupBy) 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[*ScanRecordQuery, *ScanRecordGroupBy](ctx, _g.build, _g, _g.build.inters, v) -} - -func (_g *ScanRecordGroupBy) sqlScan(ctx context.Context, root *ScanRecordQuery, 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) -} - -// ScanRecordSelect is the builder for selecting fields of ScanRecord entities. -type ScanRecordSelect struct { - *ScanRecordQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (_s *ScanRecordSelect) Aggregate(fns ...AggregateFunc) *ScanRecordSelect { - _s.fns = append(_s.fns, fns...) - return _s -} - -// Scan applies the selector query and scans the result into the given value. -func (_s *ScanRecordSelect) 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[*ScanRecordQuery, *ScanRecordSelect](ctx, _s.ScanRecordQuery, _s, _s.inters, v) -} - -func (_s *ScanRecordSelect) sqlScan(ctx context.Context, root *ScanRecordQuery, 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 *ScanRecordSelect) Modify(modifiers ...func(s *sql.Selector)) *ScanRecordSelect { - _s.modifiers = append(_s.modifiers, modifiers...) - return _s -} diff --git a/bj_power_mes/ent/scanrecord_update.go b/bj_power_mes/ent/scanrecord_update.go deleted file mode 100644 index 6aaa9b6..0000000 --- a/bj_power_mes/ent/scanrecord_update.go +++ /dev/null @@ -1,534 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "bj_power_mes/ent/predicate" - "bj_power_mes/ent/scanrecord" - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// ScanRecordUpdate is the builder for updating ScanRecord entities. -type ScanRecordUpdate struct { - config - hooks []Hook - mutation *ScanRecordMutation - modifiers []func(*sql.UpdateBuilder) -} - -// Where appends a list predicates to the ScanRecordUpdate builder. -func (_u *ScanRecordUpdate) Where(ps ...predicate.ScanRecord) *ScanRecordUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetStation sets the "station" field. -func (_u *ScanRecordUpdate) SetStation(v string) *ScanRecordUpdate { - _u.mutation.SetStation(v) - return _u -} - -// SetNillableStation sets the "station" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableStation(v *string) *ScanRecordUpdate { - if v != nil { - _u.SetStation(*v) - } - return _u -} - -// SetSn sets the "sn" field. -func (_u *ScanRecordUpdate) SetSn(v string) *ScanRecordUpdate { - _u.mutation.SetSn(v) - return _u -} - -// SetNillableSn sets the "sn" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableSn(v *string) *ScanRecordUpdate { - if v != nil { - _u.SetSn(*v) - } - return _u -} - -// SetOrderNo sets the "orderNo" field. -func (_u *ScanRecordUpdate) SetOrderNo(v string) *ScanRecordUpdate { - _u.mutation.SetOrderNo(v) - return _u -} - -// SetNillableOrderNo sets the "orderNo" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableOrderNo(v *string) *ScanRecordUpdate { - if v != nil { - _u.SetOrderNo(*v) - } - return _u -} - -// SetType sets the "type" field. -func (_u *ScanRecordUpdate) SetType(v string) *ScanRecordUpdate { - _u.mutation.SetType(v) - return _u -} - -// SetNillableType sets the "type" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableType(v *string) *ScanRecordUpdate { - if v != nil { - _u.SetType(*v) - } - return _u -} - -// SetProcessCode sets the "processCode" field. -func (_u *ScanRecordUpdate) SetProcessCode(v int) *ScanRecordUpdate { - _u.mutation.ResetProcessCode() - _u.mutation.SetProcessCode(v) - return _u -} - -// SetNillableProcessCode sets the "processCode" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableProcessCode(v *int) *ScanRecordUpdate { - if v != nil { - _u.SetProcessCode(*v) - } - return _u -} - -// AddProcessCode adds value to the "processCode" field. -func (_u *ScanRecordUpdate) AddProcessCode(v int) *ScanRecordUpdate { - _u.mutation.AddProcessCode(v) - return _u -} - -// ClearProcessCode clears the value of the "processCode" field. -func (_u *ScanRecordUpdate) ClearProcessCode() *ScanRecordUpdate { - _u.mutation.ClearProcessCode() - return _u -} - -// SetOperator sets the "operator" field. -func (_u *ScanRecordUpdate) SetOperator(v string) *ScanRecordUpdate { - _u.mutation.SetOperator(v) - return _u -} - -// SetNillableOperator sets the "operator" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableOperator(v *string) *ScanRecordUpdate { - if v != nil { - _u.SetOperator(*v) - } - return _u -} - -// SetTime sets the "time" field. -func (_u *ScanRecordUpdate) SetTime(v time.Time) *ScanRecordUpdate { - _u.mutation.SetTime(v) - return _u -} - -// SetNillableTime sets the "time" field if the given value is not nil. -func (_u *ScanRecordUpdate) SetNillableTime(v *time.Time) *ScanRecordUpdate { - if v != nil { - _u.SetTime(*v) - } - return _u -} - -// Mutation returns the ScanRecordMutation object of the builder. -func (_u *ScanRecordUpdate) Mutation() *ScanRecordMutation { - return _u.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *ScanRecordUpdate) 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 *ScanRecordUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *ScanRecordUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *ScanRecordUpdate) 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 *ScanRecordUpdate) check() error { - if v, ok := _u.mutation.Station(); ok { - if err := scanrecord.StationValidator(v); err != nil { - return &ValidationError{Name: "station", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.station": %w`, err)} - } - } - if v, ok := _u.mutation.Sn(); ok { - if err := scanrecord.SnValidator(v); err != nil { - return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.sn": %w`, err)} - } - } - if v, ok := _u.mutation.OrderNo(); ok { - if err := scanrecord.OrderNoValidator(v); err != nil { - return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.orderNo": %w`, err)} - } - } - if v, ok := _u.mutation.GetType(); ok { - if err := scanrecord.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.type": %w`, err)} - } - } - if v, ok := _u.mutation.Operator(); ok { - if err := scanrecord.OperatorValidator(v); err != nil { - return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.operator": %w`, err)} - } - } - return nil -} - -// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. -func (_u *ScanRecordUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ScanRecordUpdate { - _u.modifiers = append(_u.modifiers, modifiers...) - return _u -} - -func (_u *ScanRecordUpdate) sqlSave(ctx context.Context) (_node int, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(scanrecord.Table, scanrecord.Columns, sqlgraph.NewFieldSpec(scanrecord.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.Station(); ok { - _spec.SetField(scanrecord.FieldStation, field.TypeString, value) - } - if value, ok := _u.mutation.Sn(); ok { - _spec.SetField(scanrecord.FieldSn, field.TypeString, value) - } - if value, ok := _u.mutation.OrderNo(); ok { - _spec.SetField(scanrecord.FieldOrderNo, field.TypeString, value) - } - if value, ok := _u.mutation.GetType(); ok { - _spec.SetField(scanrecord.FieldType, field.TypeString, value) - } - if value, ok := _u.mutation.ProcessCode(); ok { - _spec.SetField(scanrecord.FieldProcessCode, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedProcessCode(); ok { - _spec.AddField(scanrecord.FieldProcessCode, field.TypeInt, value) - } - if _u.mutation.ProcessCodeCleared() { - _spec.ClearField(scanrecord.FieldProcessCode, field.TypeInt) - } - if value, ok := _u.mutation.Operator(); ok { - _spec.SetField(scanrecord.FieldOperator, field.TypeString, value) - } - if value, ok := _u.mutation.Time(); ok { - _spec.SetField(scanrecord.FieldTime, field.TypeTime, value) - } - _spec.AddModifiers(_u.modifiers...) - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{scanrecord.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// ScanRecordUpdateOne is the builder for updating a single ScanRecord entity. -type ScanRecordUpdateOne struct { - config - fields []string - hooks []Hook - mutation *ScanRecordMutation - modifiers []func(*sql.UpdateBuilder) -} - -// SetStation sets the "station" field. -func (_u *ScanRecordUpdateOne) SetStation(v string) *ScanRecordUpdateOne { - _u.mutation.SetStation(v) - return _u -} - -// SetNillableStation sets the "station" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableStation(v *string) *ScanRecordUpdateOne { - if v != nil { - _u.SetStation(*v) - } - return _u -} - -// SetSn sets the "sn" field. -func (_u *ScanRecordUpdateOne) SetSn(v string) *ScanRecordUpdateOne { - _u.mutation.SetSn(v) - return _u -} - -// SetNillableSn sets the "sn" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableSn(v *string) *ScanRecordUpdateOne { - if v != nil { - _u.SetSn(*v) - } - return _u -} - -// SetOrderNo sets the "orderNo" field. -func (_u *ScanRecordUpdateOne) SetOrderNo(v string) *ScanRecordUpdateOne { - _u.mutation.SetOrderNo(v) - return _u -} - -// SetNillableOrderNo sets the "orderNo" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableOrderNo(v *string) *ScanRecordUpdateOne { - if v != nil { - _u.SetOrderNo(*v) - } - return _u -} - -// SetType sets the "type" field. -func (_u *ScanRecordUpdateOne) SetType(v string) *ScanRecordUpdateOne { - _u.mutation.SetType(v) - return _u -} - -// SetNillableType sets the "type" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableType(v *string) *ScanRecordUpdateOne { - if v != nil { - _u.SetType(*v) - } - return _u -} - -// SetProcessCode sets the "processCode" field. -func (_u *ScanRecordUpdateOne) SetProcessCode(v int) *ScanRecordUpdateOne { - _u.mutation.ResetProcessCode() - _u.mutation.SetProcessCode(v) - return _u -} - -// SetNillableProcessCode sets the "processCode" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableProcessCode(v *int) *ScanRecordUpdateOne { - if v != nil { - _u.SetProcessCode(*v) - } - return _u -} - -// AddProcessCode adds value to the "processCode" field. -func (_u *ScanRecordUpdateOne) AddProcessCode(v int) *ScanRecordUpdateOne { - _u.mutation.AddProcessCode(v) - return _u -} - -// ClearProcessCode clears the value of the "processCode" field. -func (_u *ScanRecordUpdateOne) ClearProcessCode() *ScanRecordUpdateOne { - _u.mutation.ClearProcessCode() - return _u -} - -// SetOperator sets the "operator" field. -func (_u *ScanRecordUpdateOne) SetOperator(v string) *ScanRecordUpdateOne { - _u.mutation.SetOperator(v) - return _u -} - -// SetNillableOperator sets the "operator" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableOperator(v *string) *ScanRecordUpdateOne { - if v != nil { - _u.SetOperator(*v) - } - return _u -} - -// SetTime sets the "time" field. -func (_u *ScanRecordUpdateOne) SetTime(v time.Time) *ScanRecordUpdateOne { - _u.mutation.SetTime(v) - return _u -} - -// SetNillableTime sets the "time" field if the given value is not nil. -func (_u *ScanRecordUpdateOne) SetNillableTime(v *time.Time) *ScanRecordUpdateOne { - if v != nil { - _u.SetTime(*v) - } - return _u -} - -// Mutation returns the ScanRecordMutation object of the builder. -func (_u *ScanRecordUpdateOne) Mutation() *ScanRecordMutation { - return _u.mutation -} - -// Where appends a list predicates to the ScanRecordUpdate builder. -func (_u *ScanRecordUpdateOne) Where(ps ...predicate.ScanRecord) *ScanRecordUpdateOne { - _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 *ScanRecordUpdateOne) Select(field string, fields ...string) *ScanRecordUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated ScanRecord entity. -func (_u *ScanRecordUpdateOne) Save(ctx context.Context) (*ScanRecord, error) { - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *ScanRecordUpdateOne) SaveX(ctx context.Context) *ScanRecord { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *ScanRecordUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *ScanRecordUpdateOne) 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 *ScanRecordUpdateOne) check() error { - if v, ok := _u.mutation.Station(); ok { - if err := scanrecord.StationValidator(v); err != nil { - return &ValidationError{Name: "station", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.station": %w`, err)} - } - } - if v, ok := _u.mutation.Sn(); ok { - if err := scanrecord.SnValidator(v); err != nil { - return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.sn": %w`, err)} - } - } - if v, ok := _u.mutation.OrderNo(); ok { - if err := scanrecord.OrderNoValidator(v); err != nil { - return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.orderNo": %w`, err)} - } - } - if v, ok := _u.mutation.GetType(); ok { - if err := scanrecord.TypeValidator(v); err != nil { - return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.type": %w`, err)} - } - } - if v, ok := _u.mutation.Operator(); ok { - if err := scanrecord.OperatorValidator(v); err != nil { - return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "ScanRecord.operator": %w`, err)} - } - } - return nil -} - -// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. -func (_u *ScanRecordUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ScanRecordUpdateOne { - _u.modifiers = append(_u.modifiers, modifiers...) - return _u -} - -func (_u *ScanRecordUpdateOne) sqlSave(ctx context.Context) (_node *ScanRecord, err error) { - if err := _u.check(); err != nil { - return _node, err - } - _spec := sqlgraph.NewUpdateSpec(scanrecord.Table, scanrecord.Columns, sqlgraph.NewFieldSpec(scanrecord.FieldID, field.TypeInt)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ScanRecord.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, scanrecord.FieldID) - for _, f := range fields { - if !scanrecord.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != scanrecord.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.Station(); ok { - _spec.SetField(scanrecord.FieldStation, field.TypeString, value) - } - if value, ok := _u.mutation.Sn(); ok { - _spec.SetField(scanrecord.FieldSn, field.TypeString, value) - } - if value, ok := _u.mutation.OrderNo(); ok { - _spec.SetField(scanrecord.FieldOrderNo, field.TypeString, value) - } - if value, ok := _u.mutation.GetType(); ok { - _spec.SetField(scanrecord.FieldType, field.TypeString, value) - } - if value, ok := _u.mutation.ProcessCode(); ok { - _spec.SetField(scanrecord.FieldProcessCode, field.TypeInt, value) - } - if value, ok := _u.mutation.AddedProcessCode(); ok { - _spec.AddField(scanrecord.FieldProcessCode, field.TypeInt, value) - } - if _u.mutation.ProcessCodeCleared() { - _spec.ClearField(scanrecord.FieldProcessCode, field.TypeInt) - } - if value, ok := _u.mutation.Operator(); ok { - _spec.SetField(scanrecord.FieldOperator, field.TypeString, value) - } - if value, ok := _u.mutation.Time(); ok { - _spec.SetField(scanrecord.FieldTime, field.TypeTime, value) - } - _spec.AddModifiers(_u.modifiers...) - _node = &ScanRecord{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{scanrecord.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/ent/tx.go b/bj_power_mes/ent/tx.go index c510304..9c2de04 100644 --- a/bj_power_mes/ent/tx.go +++ b/bj_power_mes/ent/tx.go @@ -4,8 +4,6 @@ package ent import ( "context" - stdsql "database/sql" - "fmt" "sync" "entgo.io/ent/dialect" @@ -50,8 +48,6 @@ type Tx struct { ProductType *ProductTypeClient // Role is the client for interacting with the Role builders. Role *RoleClient - // ScanRecord is the client for interacting with the ScanRecord builders. - ScanRecord *ScanRecordClient // SemiFlow is the client for interacting with the SemiFlow builders. SemiFlow *SemiFlowClient // Station is the client for interacting with the Station builders. @@ -227,7 +223,6 @@ func (tx *Tx) init() { tx.ProcessStep = NewProcessStepClient(tx.config) tx.ProductType = NewProductTypeClient(tx.config) tx.Role = NewRoleClient(tx.config) - tx.ScanRecord = NewScanRecordClient(tx.config) tx.SemiFlow = NewSemiFlowClient(tx.config) tx.Station = NewStationClient(tx.config) tx.StationProcess = NewStationProcessClient(tx.config) @@ -303,27 +298,3 @@ func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error } var _ dialect.Driver = (*txDriver)(nil) - -// ExecContext allows calling the underlying ExecContext method of the transaction if it is supported by it. -// See, database/sql#Tx.ExecContext for more information. -func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { - ex, ok := tx.tx.(interface { - ExecContext(context.Context, string, ...any) (stdsql.Result, error) - }) - if !ok { - return nil, fmt.Errorf("Tx.ExecContext is not supported") - } - return ex.ExecContext(ctx, query, args...) -} - -// QueryContext allows calling the underlying QueryContext method of the transaction if it is supported by it. -// See, database/sql#Tx.QueryContext for more information. -func (tx *txDriver) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { - q, ok := tx.tx.(interface { - QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) - }) - if !ok { - return nil, fmt.Errorf("Tx.QueryContext is not supported") - } - return q.QueryContext(ctx, query, args...) -} diff --git a/bj_power_mes/frontend/src/help.js b/bj_power_mes/frontend/src/help.js index 5299a5e..6a4e485 100644 --- a/bj_power_mes/frontend/src/help.js +++ b/bj_power_mes/frontend/src/help.js @@ -211,13 +211,13 @@ export const helpTorque = { export const helpScan = { title: '手动报工(工位工序步骤完成上报)', overview: - '页面分两个页签:「报工录入」(默认打开)、「报工记录」(点击才加载,分页)。\n\n录入流程:选择工位、扫入/输入工件 SN 后,系统自动载入该工位「启用」工艺流程的工序步骤(扭矩/角度/尺寸等采集项),逐参数录入提交;提交后写报工实绩 + 步骤数据,系统按考核标准自动判定 合格/不合格。\n\n装机绑定:若该产品在本工序配置了需绑定的装配物料(物料清单「装配工位」),会出现装机绑定区——电气件扫 SN、结构件扫/输批次号,逐项绑齐(已绑/需绑)后才允许提交报工;未配置物料则不校验。\n\n数据链路:工艺流程(工序步骤+考核标准) + 物料清单 装机配置 → 本页选工位扫 SN 自动载入 → 绑料+录参数 → 判 合格/不合格 → 工件追溯可见。', + '页面分两个页签:「报工录入」(默认打开)、「报工记录」(点击才加载,分页)。\n\n录入流程:扫入/输入工件 SN 后,系统自动带出该工件的「应报工位」并载入该工位「启用」工艺流程的工序步骤(扭矩/角度/尺寸等采集项);工位也可手动选择。逐参数录入提交;提交后写报工实绩 + 步骤数据,系统按考核标准自动判定 合格/不合格。\n\n放行校验(严格):必须“在制(已进线/在工位) 且 当前工序(=已完成工序+1) == 所选工位”才允许报工,禁止跳站/漏站/重复报同一站;扫 SN 后页面实时给出校验结果,后端报工时再次强校验。\n\n装机绑定:若该产品在本工序配置了需绑定的装配物料(物料清单「装配工位」),会出现装机绑定区——电气件扫 SN、结构件扫/输批次号,逐项绑齐(已绑/需绑)后才允许提交报工;未配置物料则不校验。\n\n报工记录:「报工记录」页签展示真实报工实绩(本页手动报工与工位终端报工均在此可见),可按 SN / 工单号 / 工位 筛选。\n\n数据链路:工艺流程(工序步骤+考核标准) + 物料清单 装机配置 → 本页扫 SN 自动带出工位并载入 → 绑料+录参数 → 判 合格/不合格 → 报工记录/工件追溯可见。', fields: [ - { name: '工位', source: '下拉选择(工位数以数据库为准)。', purpose: '哪个工位在报工,选择后自动载入该工位的工序步骤', fill: '选择工位 1~12' }, - { name: '工件SN', source: '扫码枪扫描或手输。来自工件条码。', purpose: '工件的唯一序列号,报工对象', fill: '扫码枪扫入,与工位一起触发自动载入' }, + { name: '工件SN', source: '扫码枪扫描或手输。来自工件条码。', purpose: '工件的唯一序列号,报工对象;扫入后自动带出工件状态与应报工位', fill: '扫码枪扫入或手输,触发自动带出工位与工艺步骤' }, + { name: '工位', source: '扫 SN 自动带出「应报工位」;也可下拉手动选择(工位数以数据库为准)。', purpose: '哪个工位在报工;手选时受工件应报工位约束', fill: '自动带出或手选工位 1~12,须等于应报工位方可报工' }, { name: '各步骤采集值', source: '手工填写 或 拧紧枪自动带出(视采集方式)。字段由【工艺流程】的工序步骤人为定义。', purpose: '收集该工位的扭矩/角度/尺寸等参数,按标准判定合格与否', fill: '逐条填采集值,未维护标准的步骤仅记录' }, { name: '装机绑定(物料/已绑/需绑)', source: '来自物料清单的「装配工位」配置(按工单锁定的物料清单过滤)。', purpose: '该工件本工序应装哪些料;电气件按 SN、结构件按批次绑定,齐套后才允许报工', fill: '在绑定输入框扫码或录入后点「绑定」,绑齐后提交报工' }, - { name: '报工记录查询(SN / 工单号)', source: '「报工记录」页签筛选条件,分页查看。', purpose: '查历史报工实绩', fill: '可空=全部' } + { name: '报工记录查询(SN / 工单号 / 工位)', source: '「报工记录」页签筛选条件,分页查看真实报工实绩(含手动与工位终端报工)。', purpose: '查历史报工实绩', fill: '可空=全部' } ] } diff --git a/bj_power_mes/frontend/src/pages/Inspect.vue b/bj_power_mes/frontend/src/pages/Inspect.vue index b78f671..34b7ab0 100644 --- a/bj_power_mes/frontend/src/pages/Inspect.vue +++ b/bj_power_mes/frontend/src/pages/Inspect.vue @@ -285,6 +285,7 @@ import PageHelp from '../components/PageHelp.vue' import { helpInspect } from '../help' import { loadStationNos } from '../utils/stations' import request from '../utils/request' +import { confirmExport } from '../utils/confirm' import { fmtTime } from '../utils/format' // ---------- 当前用户与权限 ---------- @@ -504,6 +505,7 @@ async function exportCsv() { }) const rows = data?.list || [] if (!rows.length) return ElMessage.warning('当前筛选条件下没有记录') + if (!(await confirmExport(rows.length, '巡检记录'))) return const esc = (v) => { const s = v == null ? '' : String(v); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s } const header = ['ID', '时间', '类型', '工位', '班次', '工单号', 'SN', '结果', '点检项/异常类型', '备注/签字', '操作人', '照片'] const lines = [header.join(',')] diff --git a/bj_power_mes/frontend/src/pages/MaterialRequest.vue b/bj_power_mes/frontend/src/pages/MaterialRequest.vue index c2bd253..ef69b50 100644 --- a/bj_power_mes/frontend/src/pages/MaterialRequest.vue +++ b/bj_power_mes/frontend/src/pages/MaterialRequest.vue @@ -157,6 +157,7 @@ import { reactive, ref, onMounted } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import request from '../utils/request' +import { confirmExport } from '../utils/confirm' import { can } from '../utils/perm' import PageHelp from '../components/PageHelp.vue' import { helpMaterial } from '../help' @@ -225,7 +226,8 @@ async function onExpandRow(row, expandedRows) { } // 导出 CSV(带 BOM,Excel 直接打开中文不乱码;MES 前端无 xlsx 库,纯前端导出) -function exportLedgerCsv() { +async function exportLedgerCsv() { + if (!(await confirmExport(progressRows.value.length, '物料去向对账记录'))) return const header = ['工单号', '图号', '物料名称', '目标工位', '需求', '已发出', '已退回', '已接料', '已消耗', '在途', '工位余', '待发缺口', '对账状态', '台账状态'] const lines = [header.join(',')] for (const r of progressRows.value) { diff --git a/bj_power_mes/frontend/src/pages/Performance.vue b/bj_power_mes/frontend/src/pages/Performance.vue index f9a9944..afd1a66 100644 --- a/bj_power_mes/frontend/src/pages/Performance.vue +++ b/bj_power_mes/frontend/src/pages/Performance.vue @@ -151,6 +151,7 @@ import PageHelp from '../components/PageHelp.vue' import { helpPerformance } from '../help' import { loadStationNos } from '../utils/stations' import request from '../utils/request' +import { confirmExportMessage } from '../utils/confirm' // 后端三视图各自真分页(默认20):byOperator/byStation/detail 各带 {total, list} const activeTab = ref('byOperator') @@ -234,6 +235,19 @@ async function load() { // 导出:后端一个 xlsx 三个 sheet(按人/按工位/明细),执行统一导出时间硬规则 async function exportXlsx() { const [from, to] = query.range || [] + const base = { + operator: query.operator || '', stationNo: query.stationNo || '', + orderNo: query.orderNo.trim(), from: from || '', to: to || '' + } + // 按与导出相同口径取三张表的条数,用于确认告知 + const cnt = (await request.get('/performance', { + params: { ...base, opPage: 1, opPageSize: 1, stPage: 1, stPageSize: 1, detPage: 1, detPageSize: 1 } + })) || {} + const op = cnt.byOperator?.total || 0 + const st = cnt.byStation?.total || 0 + const det = cnt.detail?.total || 0 + const msg = `即将导出绩效报表(时间 ${from || '不限'} 至 ${to || '不限'}):\n明细 ${det} 条、按人汇总 ${op} 人、按工位汇总 ${st} 个工位,是否继续?` + if (!(await confirmExportMessage(msg))) return const params = { operator: query.operator || '', stationNo: query.stationNo || '', orderNo: query.orderNo.trim(), diff --git a/bj_power_mes/frontend/src/pages/ProductType.vue b/bj_power_mes/frontend/src/pages/ProductType.vue index 275c5b9..33cd653 100644 --- a/bj_power_mes/frontend/src/pages/ProductType.vue +++ b/bj_power_mes/frontend/src/pages/ProductType.vue @@ -74,6 +74,7 @@ import { reactive, ref, onMounted } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' import request from '../utils/request' +import { confirmExport } from '../utils/confirm' import { can } from '../utils/perm' import PageHelp from '../components/PageHelp.vue' import { helpProductType } from '../help' @@ -153,6 +154,9 @@ async function exportXlsx() { isActive: filters.isActive, startDate: filters.startDate, endDate: filters.endDate } + // 按与导出完全相同的筛选取精确条数,确认后才下载 + const cnt = await request.get('/product-types/page', { params: { ...params, page: 1, pageSize: 1 } }) + if (!(await confirmExport(cnt?.total ?? null, '物料档案'))) return const blob = await request.get('/product-types/export', { params, responseType: 'blob' }) const a = document.createElement('a') a.href = URL.createObjectURL(blob) diff --git a/bj_power_mes/frontend/src/pages/Scan.vue b/bj_power_mes/frontend/src/pages/Scan.vue index 3d5f76d..31e9ffc 100644 --- a/bj_power_mes/frontend/src/pages/Scan.vue +++ b/bj_power_mes/frontend/src/pages/Scan.vue @@ -3,15 +3,21 @@ + + + - + - 已自动载入当前工位应做步骤 + + +
@@ -85,23 +91,33 @@ - + + - - - 刷新 + + + + + + + + 查询 - - - - + + + + + + - + + @@ -112,7 +128,7 @@ diff --git a/bj_power_mes/frontend/src/utils/confirm.js b/bj_power_mes/frontend/src/utils/confirm.js new file mode 100644 index 0000000..1144680 --- /dev/null +++ b/bj_power_mes/frontend/src/utils/confirm.js @@ -0,0 +1,26 @@ +import { ElMessageBox } from 'element-plus' + +// 导出前统一确认:告知用户即将导出的数据条数。 +// count 为 null/undefined(无法预知条数)时提示“全部”;否则回显具体条数。 +export async function confirmExport(count, name = '数据') { + const msg = (count === null || count === undefined) + ? `即将导出全部${name},是否继续?` + : `即将导出 ${count} 条${name},是否继续?` + return confirmExportMessage(msg) +} + +// 自定义文案的导出确认:用于多 Sheet 报表等无法用单一条数概括的场景。 +export async function confirmExportMessage(msg, title = '导出确认') { + try { + await ElMessageBox.confirm(msg, title, { + confirmButtonText: '确认导出', + cancelButtonText: '取消', + type: 'warning' + }) + return true + } catch { + return false + } +} + +export default { confirmExport, confirmExportMessage } diff --git a/bj_power_mes/internal/handler/production/plc_torque_scan.go b/bj_power_mes/internal/handler/production/plc_torque_scan.go index 83201f7..45861f3 100644 --- a/bj_power_mes/internal/handler/production/plc_torque_scan.go +++ b/bj_power_mes/internal/handler/production/plc_torque_scan.go @@ -126,28 +126,15 @@ func TorqueStatHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { } } -// ---------- 扫码报工 ---------- +// ---------- 报工记录 ---------- -func ScanReportHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - var req logic.ScanReq - if err := httpx.ParseJSON(r, &req); err != nil { - httpx.BadRequest(w, "请求体解析失败") - return - } - if err := logic.New(svcCtx).ReportScan(r.Context(), req, operator(r, "")); err != nil { - httpx.Fail(w, 3205, err.Error()) - return - } - httpx.OkMessage(w, "扫码成功", nil) - } -} - -func ScanRecordsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +// ReportRecordsHandler GET /workpiece/process/records?sn=&orderNo=&stationNo=&page=&pageSize= +// 报工记录列表:直查真实报工表 workpiece_process,手动报工与工位终端报工均在此可见(报工闭环)。 +func ReportRecordsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() - data, total, err := logic.New(svcCtx).ListScanRecords(r.Context(), q.Get("sn"), q.Get("orderNo"), - atoiDefault(q.Get("page"), 1), atoiDefault(q.Get("pageSize"), 20)) + data, total, err := logic.New(svcCtx).ListProcessRecords(r.Context(), q.Get("sn"), q.Get("orderNo"), + atoiDefault(q.Get("stationNo"), 0), atoiDefault(q.Get("page"), 1), atoiDefault(q.Get("pageSize"), 20)) if err != nil { httpx.Fail(w, 3206, err.Error()) return diff --git a/bj_power_mes/internal/handler/routes_production.go b/bj_power_mes/internal/handler/routes_production.go index c4cf229..7f119d8 100644 --- a/bj_power_mes/internal/handler/routes_production.go +++ b/bj_power_mes/internal/handler/routes_production.go @@ -192,8 +192,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext {Method: http.MethodPost, Path: "/torque/audit", Handler: production.TorqueAuditHandler(serverCtx)}, {Method: http.MethodGet, Path: "/torque/audit-log", Handler: production.TorqueAuditLogHandler(serverCtx)}, - {Method: http.MethodPost, Path: "/scan/report", Handler: production.ScanReportHandler(serverCtx)}, - {Method: http.MethodGet, Path: "/scan/records", Handler: production.ScanRecordsHandler(serverCtx)}, + {Method: http.MethodGet, Path: "/workpiece/process/records", Handler: production.ReportRecordsHandler(serverCtx)}, {Method: http.MethodGet, Path: "/process-steps", Handler: production.ProcessStepsHandler(serverCtx)}, {Method: http.MethodPost, Path: "/workpiece/online", Handler: production.OnlineWorkpieceHandler(serverCtx)}, diff --git a/bj_power_mes/internal/logic/scan.go b/bj_power_mes/internal/logic/scan.go index a9144ed..cfc27c4 100644 --- a/bj_power_mes/internal/logic/scan.go +++ b/bj_power_mes/internal/logic/scan.go @@ -2,56 +2,13 @@ package logic import ( "context" - "errors" "time" - "bj_power_mes/ent" "bj_power_mes/ent/dailyplan" - "bj_power_mes/ent/scanrecord" "bj_power_mes/ent/workorder" - "bj_power_mes/ent/workpiece" ) -type ScanReq struct { - Station string `json:"station"` - Sn string `json:"sn"` - OrderNo string `json:"orderNo"` - Type string `json:"type"` // ONLINE / PROCESS / DONE / TEMP_STORE - ProcessCode int `json:"processCode"` - Operator string `json:"operator"` -} - -// ReportScan 扫码报工:记录 scan_record,并更新工单进度 -func (s *Service) ReportScan(ctx context.Context, req ScanReq, operator string) error { - if req.Sn == "" { - return errors.New("sn 不能为空") - } - scanType := req.Type - if scanType == "" { - scanType = "PROCESS" - } - if req.Operator == "" { - req.Operator = operator - } - _, err := s.ctx.EntClient.ScanRecord.Create(). - SetStation(req.Station).SetSn(req.Sn).SetOrderNo(req.OrderNo). - SetType(scanType).SetProcessCode(req.ProcessCode).SetOperator(req.Operator). - SetTime(time.Now()).Save(ctx) - if err != nil { - return err - } - s.ctx.EventLog.Write(ctx, "scan.report", req.OrderNo, operator, "scan_record", req.Sn, "扫码报工", map[string]any{"station": req.Station, "type": scanType, "processCode": req.ProcessCode}) - - // 更新工单进度:调高 finished 进度(去重按 sn+工序) - wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx) - if err == nil && wp != nil && wp.WorkOrderId > 0 { - s.bumpWorkOrderProgress(ctx, wp.OrderNo, wp.Sn) - } - s.notifyDashboard() - return nil -} - -// bumpWorkOrderProgress 增加工单已完成数量(由完工动作驱动;扫码报工仅流转状态不重复计数) +// bumpWorkOrderProgress 增加工单已完成数量(由完工动作驱动) func (s *Service) bumpWorkOrderProgress(ctx context.Context, orderNo, sn string) { wo, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.WorkOrderNo(orderNo)).First(ctx) if err != nil || wo == nil { @@ -90,24 +47,3 @@ func (s *Service) bumpDailyPlanCompleted(ctx context.Context, orderNo string, t SetCompletedQty(newQty).SetStatus(st).Save(ctx) } } - -// ListScanRecords 查询扫码报工记录 -func (s *Service) ListScanRecords(ctx context.Context, sn, orderNo string, page, pageSize int) ([]*ent.ScanRecord, int, error) { - q := s.ctx.EntClient.ScanRecord.Query() - if sn != "" { - q = q.Where(scanrecord.Sn(sn)) - } - if orderNo != "" { - q = q.Where(scanrecord.OrderNoEqualFold(orderNo)) - } - if sn != "" { - q = q.Where(scanrecord.SnEqualFold(sn)) - } - total, err := q.Count(ctx) - if err != nil { - return nil, 0, err - } - rows, err := q.Order(ent.Desc(scanrecord.FieldID)). - Offset((page - 1) * pageSize).Limit(pageSize).All(ctx) - return rows, total, err -} diff --git a/bj_power_mes/internal/logic/seed.go b/bj_power_mes/internal/logic/seed.go index e441e01..9e351aa 100644 --- a/bj_power_mes/internal/logic/seed.go +++ b/bj_power_mes/internal/logic/seed.go @@ -12,7 +12,7 @@ import ( "golang.org/x/crypto/bcrypt" ) -// Seed 初始化:超级管理员、默认角色、默认菜单权限、12 道工序与工位派工 +// Seed 初始化:超级管理员、默认角色、默认菜单权限、产线工位(内置只读主数据;工艺流程由用户自建不预置) func (s *Service) Seed(ctx context.Context) error { // 1. 默认角色(已存在则合并权限码,保证新按钮权限能落到已有角色上) roles := []struct{ name, code string }{ @@ -168,37 +168,23 @@ func (s *Service) Seed(ctx context.Context) error { // 清掉存量角色里的旧码与旧菜单定义行(幂等);新菜单 produce.qty 在 1. 的 seedMenus 中定义。 migrateLegacyQtyReport(ctx, s) - // 4. 初始化工位与默认工艺流程(工位绑定流程,流程承载步骤) - seedFlowsAndStations(ctx, s) + // 4. 初始化产线工位(内置只读主数据);工艺流程/工序步骤由用户在「工艺流程」页自建,不预置 + seedStations(ctx, s) return nil } -func seedFlowsAndStations(ctx context.Context, s *Service) { - // 初始数据:12 个工位(工位数量以数据库为准,这里只做首次初始化;要 13 个就往 station 表插一行) - // 初始化的工位一律为「内置工位」:需连 PLC、必须按工位号顺序流转、不可改类型、不可删除; - // 其中 1~10 号工位对应实体接驳台,11/12 为产线末端无接驳台。 +func seedStations(ctx context.Context, s *Service) { + // 工位是产线固定物理工位,一律「内置工位」:需连 PLC、按工位号顺序流转、不可改类型、不可删除、仅可改名, + // 属系统内置只读主数据(同 WMS 接驳台),故由种子初始化。12 个装配工位(1~10 带接驳台,11/12 产线末端无接驳台); + // 工位数量以数据库为准,要 13 个就往 station 表插一行。 + // 工艺流程/工序步骤不在此预置:流程可在「工艺流程」页新建/编辑/删除/启停,是用户可维护的业务数据, + // 由实施按产品工艺自建、并在「关联工位」页绑定到工位(station.flow_id),不硬编码进种子。 for i := 1; i <= 12; i++ { - st, err := s.ctx.EntClient.Station.Query().Where(station.StationNo(i)).First(ctx) - if err != nil { - st, _ = s.ctx.EntClient.Station.Create(). + if _, err := s.ctx.EntClient.Station.Query().Where(station.StationNo(i)).First(ctx); err != nil { + _, _ = s.ctx.EntClient.Station.Create(). SetStationNo(i).SetName("装配工位" + strconv.Itoa(i)).SetStatus("ENABLED"). SetIsBuiltin(true).SetHasDock(i <= 10).Save(ctx) } - if st == nil || st.FlowId > 0 { - continue - } - flow, err := s.ctx.EntClient.ProcessFlow.Create(). - SetName("工位" + strconv.Itoa(i) + "_默认"). - SetStatus("ACTIVE").SetRemark("默认工艺流程").Save(ctx) - if err != nil { - continue - } - if _, err := s.ctx.EntClient.ProcessStep.Create(). - SetFlowId(flow.ID).SetSeq(1).SetName("装配完成").SetCollectType("NONE").Save(ctx); err == nil && i == 3 { - _, _ = s.ctx.EntClient.ProcessStep.Create(). - SetFlowId(flow.ID).SetSeq(2).SetName("拧紧扭矩").SetCollectType("AUTO").SetIsTorque(true).Save(ctx) - } - _, _ = s.ctx.EntClient.Station.UpdateOneID(st.ID).SetFlowId(flow.ID).Save(ctx) } // 0 号(上线位) / 13 号(下线位) 虚拟工位:OFFLINE 类型,用 PAD 操作,不连 PLC、 // 不叫料、不进入产线组合排序;仅做上下线登记,不参与物理工位计数。 diff --git a/bj_power_mes/internal/logic/workpiece.go b/bj_power_mes/internal/logic/workpiece.go index ef0e1aa..5157104 100644 --- a/bj_power_mes/internal/logic/workpiece.go +++ b/bj_power_mes/internal/logic/workpiece.go @@ -132,6 +132,16 @@ func (s *Service) ReportProcess(ctx context.Context, req ReportProcessReq, opera if err != nil { return errors.New("工件未进线登记") } + // 严格校验(业务口径已确认):仅“在制”工件可报工,且必须按工序顺序流转,禁止跳站/漏站/重复报同一站。 + // 在制 = ONLINE(已进线) / PROCESSING(在工位);DONE/REPAIR/SCRAPPED 一律拒绝。 + if wp.Status != "ONLINE" && wp.Status != "PROCESSING" { + return errors.New("工件当前状态为「" + wp.Status + "」,非在制,不允许报工") + } + // 顺序流转:currentProcess 语义为“已报工完成的工序”(进线时=0),本工位必须是其下一道,即 processCode == currentProcess+1。 + if req.ProcessCode != wp.CurrentProcess+1 { + return errors.New("工序顺序不符:工件已完成工序" + itoa(wp.CurrentProcess) + + ",应在工位" + itoa(wp.CurrentProcess+1) + "报工,当前请求工位" + itoa(req.ProcessCode)) + } // 报工是"装机绑定→校验齐套→写实绩→写步骤考核→回写结果/工件状态"的多步写,必须整体事务化(方案 U3): // 任一步失败全部回滚,杜绝"实绩已建但工件状态没推进/结果没落"的半成品脏数据; // 校验(齐套/needCheck)也走同一 tx client,才能读到本事务内刚写入的绑定。 @@ -429,6 +439,56 @@ func (s *Service) Trace(ctx context.Context, sn string) (map[string]any, error) }, nil } +// ListProcessRecords 报工记录列表(分页):直接查真实报工表 workpiece_process, +// 手动报工与工位终端报工都在此可见,形成报工闭环(取代已废弃的 scan_record 查询)。 +func (s *Service) ListProcessRecords(ctx context.Context, sn, orderNo string, stationNo, page, pageSize int) ([]map[string]any, int, error) { + q := s.ctx.EntClient.WorkpieceProcess.Query() + if sn != "" { + q = q.Where(workpieceprocess.SnEqualFold(sn)) + } + if orderNo != "" { + q = q.Where(workpieceprocess.OrderNoEqualFold(orderNo)) + } + if stationNo > 0 { + q = q.Where(workpieceprocess.StationNo(itoa(stationNo))) + } + total, err := q.Count(ctx) + if err != nil { + return nil, 0, err + } + if page < 1 { + page = 1 + } + if pageSize < 1 { + pageSize = 20 + } + rows, err := q.Order(ent.Desc(workpieceprocess.FieldID)). + Offset((page - 1) * pageSize).Limit(pageSize).All(ctx) + if err != nil { + return nil, 0, err + } + list := make([]map[string]any, 0, len(rows)) + for _, r := range rows { + ended := "" + if r.EndedAt != nil { + ended = r.EndedAt.Format("2006-01-02 15:04:05") + } + list = append(list, map[string]any{ + "sn": r.Sn, + "orderNo": r.OrderNo, + "stationNo": r.StationNo, + "processCode": r.ProcessCode, + "processName": r.ProcessName, + "status": r.Status, + "result": r.Result, + "operator": r.Operator, + "durationSec": r.DurationSec, + "endedAt": ended, + }) + } + return list, total, nil +} + func (s *Service) ListWorkpieces(ctx context.Context, sn, orderNo string) ([]*ent.Workpiece, error) { q := s.ctx.EntClient.Workpiece.Query() if sn != "" { diff --git a/bj_power_mes/public/index.html b/bj_power_mes/public/index.html index c1bb051..77229d5 100644 --- a/bj_power_mes/public/index.html +++ b/bj_power_mes/public/index.html @@ -6,7 +6,7 @@ MES 产线控制 - + diff --git a/bj_power_mes/schema/scan_record.go b/bj_power_mes/schema/scan_record.go deleted file mode 100644 index 1d84df4..0000000 --- a/bj_power_mes/schema/scan_record.go +++ /dev/null @@ -1,44 +0,0 @@ -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" -) - -// ScanRecord 扫码报工记录(station,sn,orderNo,type,operator,time) -type ScanRecord struct { - ent.Schema -} - -func (ScanRecord) Annotations() []schema.Annotation { - return []schema.Annotation{entsql.Annotation{Table: "scan_record"}} -} - -func (ScanRecord) Fields() []ent.Field { - return []ent.Field{ - field.Int("id").Positive(), - field.String("station").Default("").MaxLen(32).Comment("工位/扫码点"), - field.String("sn").MaxLen(64).Comment("工件SN"), - field.String("orderNo").Default("").MaxLen(64).Comment("工单号"), - // ONLINE(进线) / PROCESS(工序报工) / DONE(完工) / TEMP_STORE(暂存) - field.String("type").Default("PROCESS").MaxLen(20).Comment("报工类型"), - field.Int("processCode").Optional().Comment("工序号 1~12"), - field.String("operator").Default("").MaxLen(64).Comment("操作人"), - field.Time("time").Default(time.Now).Comment("报工时间"), - field.Time("createdAt").Default(time.Now).Immutable(), - } -} - -func (ScanRecord) Indexes() []ent.Index { - return []ent.Index{ - index.Fields("station"), - index.Fields("sn"), - index.Fields("orderNo"), - index.Fields("createdAt"), - } -} diff --git a/bj_power_mes/tools/generate.go b/bj_power_mes/tools/generate.go new file mode 100644 index 0000000..a733f9c --- /dev/null +++ b/bj_power_mes/tools/generate.go @@ -0,0 +1,22 @@ +// ent 代码生成器:读取 ./schema 下的实体定义,生成 ./ent 目录下的 ORM 代码。 +// 用法(在 bj_power_mes 根目录):go run ./tools/generate.go +// 注意:Features 必须与既有生成代码保持一致(sql/modifier 提供 Modify、sql/lock 提供 ForUpdate/ForShare), +// 否则重生会丢失这些方法。 +package main + +import ( + "log" + + "entgo.io/ent/entc" + "entgo.io/ent/entc/gen" +) + +func main() { + if err := entc.Generate("./schema", &gen.Config{ + Target: "./ent", + Package: "bj_power_mes/ent", + Features: []gen.Feature{gen.FeatureModifier, gen.FeatureLock}, + }); err != nil { + log.Fatalf("running ent codegen: %v", err) + } +} diff --git a/bj_power_wms/frontend/src/help.js b/bj_power_wms/frontend/src/help.js index d2b1f5b..4e0972f 100644 --- a/bj_power_wms/frontend/src/help.js +++ b/bj_power_wms/frontend/src/help.js @@ -62,9 +62,9 @@ export const helpInbound = { export const helpOutbound = { title: '出库管理(统一主表)', overview: - '所有出库都落在同一张「出库主表」(OutboundOrder),用"类型"区分,装箱信息(箱号/SN清单/合同号)也直接记在主表上,不再单独建装箱表。\n三个页签:\n· 工单备料出库(MES):对接 MES 工单台账领料,强约束"单物料累计出库 ≤ 工单需求总量";未启用 MES 或工单未同步时,工单下拉可能为空,可直接手输工单号(需台账已同步)。\n· 通用出库:不依赖工单的手动出库(退料/退货/样品/报废/发货/其他),支持结构件批次与电气件 SN,填箱号即一并记录装箱;MES 不可用或无需挂靠工单时请用本页。\n· 出库记录:统一主表的全量查询与导出(一键导出 CSV,含装箱信息),含工单号与目标工位。\n选用原则:有 MES 工单要按 物料清单 领料 → 工单备料出库;无工单的自由出库/装箱发货 → 通用出库。\n\n通用出库操作顺序(客户诉求 问题17/18/20):① 先选物料(下拉统一显示 编码/图号/类型/品类)→ ② 系统自动判定出库类型(电气件/结构件,无需手选)→ ③ 选出库类别(纯标签,不联动任何地方;选「其他」时备注必填原因)→ ④ 填归属(工单编号/科技项目号/其他,非其他时编号必填)→ ⑤ 结构件从可用批次下拉选批次(默认 FIFO 首个)并填数量 / 电气件逐个扫 SN → ⑥ 选目标工位(下拉,来自 MES 工位列表,不可手输)。\n\n说明:出库单号由系统自动生成、不可修改,规则与入库一致(入库 IB+ / 出库 OB+ 同一编号规则);出库无法与入库批次/合同对应,故出库类别仅是标签记录,列表与出库单都显示。质量门禁:发货/样品/其他类出库仅允许「合格」品;退货/报废/退料类豁免(本身即处置不合格品)。', + '所有出库都落在同一张「出库主表」(OutboundOrder),用"类型"区分,装箱信息(箱号/SN清单/合同号)也直接记在主表上,不再单独建装箱表。\n三个页签:\n· 工单备料出库(MES):对接 MES 工单台账领料,强约束"单物料累计出库 ≤ 工单需求总量";工单号下拉选择(来自 MES 实时工单,未完成优先,无输入默认展示前 20 条),支持输入模糊搜索;MES 不可达或工单未同步时下拉可能为空,可手输兜底(需台账已同步)。\n· 通用出库:不依赖工单的手动出库(退料/退货/样品/报废/发货/其他),支持结构件批次与电气件 SN,填箱号即一并记录装箱;MES 不可用或无需挂靠工单时请用本页。\n· 出库记录:统一主表的全量查询与导出(一键导出 CSV,含装箱信息),含工单号与目标工位。\n选用原则:有 MES 工单要按 物料清单 领料 → 工单备料出库;无工单的自由出库/装箱发货 → 通用出库。\n\n通用出库操作顺序(客户诉求 问题17/18/20):① 先选物料(下拉统一显示 编码/图号/类型/品类)→ ② 系统自动判定出库类型(电气件/结构件,无需手选)→ ③ 选出库类别(纯标签,不联动任何地方;选「其他」时备注必填原因)→ ④ 填归属(工单编号/科技项目号/其他,非其他时编号必填)→ ⑤ 结构件从可用批次下拉选批次(默认 FIFO 首个)并填数量 / 电气件逐个扫 SN → ⑥ 选目标工位(下拉,来自 MES 工位列表,不可手输)。\n\n说明:出库单号由系统自动生成、不可修改,规则与入库一致(入库 IB+ / 出库 OB+ 同一编号规则);出库无法与入库批次/合同对应,故出库类别仅是标签记录,列表与出库单都显示。质量门禁:发货/样品/其他类出库仅允许「合格」品;退货/报废/退料类豁免(本身即处置不合格品)。', fields: [ - { name: '备料出库-工单号', source: '手动输入。数据来自 MES 已建的工单及导入的物料台账。', purpose: '出库挂靠的工单,决定可领料总量与需求缺口', fill: '输入工单号回车,查询该工单的物料台账' }, + { name: '备料出库-工单号', source: '下拉选择 + 模糊搜索。数据来自 MES 实时工单(未完成优先,无输入默认前 20 条)。', purpose: '出库挂靠的工单,决定可领料总量与需求缺口', fill: '下拉选工单号(或输入关键字模糊搜索;MES 不可达时可手输兜底),选中即查询该工单的物料台账' }, { name: '备料出库-目标工位', source: '下拉选择 DOCK01~DOCK20(选填,可过滤搜索)。', purpose: 'AGV 配送送达的接驳台(toDock 参数)', fill: '选择如 DOCK05;不选默认运到产线入口 DOCK01' }, { name: '备料出库-一键分配出库', source: '系统自动按 FIFO 分配。数据来自合格区Z02的批次库存。', purpose: '从合格区按先进先出凑够缺口并出库', fill: '点按钮,系统自动算批次并二次确认' }, { name: '通用出库-物料', source: '下拉选择(全项目统一组件)。', purpose: '选定要出库的物料', fill: '下拉显示 编码/图号/类型(电气件/结构件/其他)/品类(原材料/半成品/成品/其他),支持远程搜索' }, @@ -255,14 +255,14 @@ export const helpZone = { export const helpDock = { title: '接驳台维护', overview: - '维护全厂接驳台(AGV 取送货的物理停靠位)主数据。接驳台是独立主数据,不依附工位:除了产线各工位旁,库房收货口、线边缓存区等其他位置也有接驳台位。\n\n三种类型:\n· 产线:位于产线工位旁,必须绑定一个工位号,且与工位一一对应(一个工位只能有一个接驳台、一个接驳台只能给一个工位);\n· 库房:库房收货/发货口(如 DOCK21),不绑定工位;\n· 其他:缓存区、暂存位等,不绑定工位。\n\n接驳台编码是产线与 AGV 任务的引用锚点,创建后不可修改;MES「关联工位」页绑定接驳台时从本页数据实时拉取。有托盘占用的接驳台不允许删除,需先处理托盘。', + '查看全厂接驳台(AGV 取送货的物理停靠位)。接驳台是系统预置的只读主数据,本页仅供查看,不提供新增/修改/删除。\n\n三种类型:\n· 产线:位于产线工位旁,与工位一一对应(DOCK01~20 对应工位 1~20,一个工位一个接驳台);\n· 库房:库房收货/发货口(如 DOCK21),不绑定工位;\n· 其他:缓存区、暂存位等,不绑定工位。\n\n接驳台编码是产线与 AGV 任务的引用锚点;MES「关联工位」页绑定接驳台时从本页数据实时拉取。', fields: [ - { name: '接驳台编码', source: '手工填写,创建后不可改。', purpose: '接驳台唯一编号,产线/AGV 任务据此定位', fill: '如 DOCK21、DOCK22;建议 DOCK+两位数字' }, - { name: '接驳台名称', source: '手工填写。', purpose: '接驳台中文名,便于识别', fill: '如 库房收货接驳台、三号缓存接驳台' }, - { name: '类型', source: '选择:产线 / 库房 / 其他。', purpose: '区分接驳台所处位置与用途', fill: '产线接驳台需填工位号;库房/其他不填' }, - { name: '绑定工位号', source: '仅产线类型填写。', purpose: '该接驳台服务哪个工位,与工位 1:1', fill: '如 3 表示 3 号工位;该工位已绑定其他接驳台时会提示' }, - { name: '托盘状态', source: '系统自动维护(PLC 托盘传感器 / AGV 到位卸货)。', purpose: '看该接驳台当前是否被占用', fill: '不可手改;有托盘的接驳台不允许删除' }, - { name: '状态', source: '选择:启用 / 停用。', purpose: '停用的接驳台不再参与配送与下拉选择', fill: '默认启用' } + { name: '接驳台编码', source: '系统预置,只读。', purpose: '接驳台唯一编号,产线/AGV 任务据此定位', fill: '只读查看,如 DOCK01~DOCK21' }, + { name: '接驳台名称', source: '系统预置,只读。', purpose: '接驳台中文名,便于识别', fill: '只读查看' }, + { name: '类型', source: '系统预置:产线 / 库房 / 其他。', purpose: '区分接驳台所处位置与用途', fill: '只读;产线接驳台绑定工位号,库房/其他不绑定' }, + { name: '绑定工位号', source: '仅产线类型有,与工位 1:1。', purpose: '该接驳台服务哪个工位', fill: '只读,如 3 表示 3 号工位' }, + { name: '托盘状态', source: '系统自动维护(PLC 托盘传感器 / AGV 到位卸货)。', purpose: '看该接驳台当前是否被占用', fill: '只读,实时反映是否有托盘占用' }, + { name: '状态', source: '系统预置:启用 / 停用。', purpose: '停用的接驳台不再参与配送与下拉选择', fill: '只读查看' } ] } diff --git a/bj_power_wms/frontend/src/pages/BaseData.vue b/bj_power_wms/frontend/src/pages/BaseData.vue index be995dc..f59192e 100644 --- a/bj_power_wms/frontend/src/pages/BaseData.vue +++ b/bj_power_wms/frontend/src/pages/BaseData.vue @@ -55,6 +55,7 @@ const f2Shelf = ref([]); const f3Shelf = ref([]); const f3Layer = ref([]) const f4Shelf = ref([]); const f4Layer = ref([]) const cShelf = ref([]); const cLayer = ref([]) const bShelf = ref([]) +const lbShelf = ref([]) async function picker(level, params) { const data = await request.get('/zone/picker', { params: { level, ...params } }) @@ -239,6 +240,47 @@ async function submitBatch() { } } +/* ---------- 区域维护:层批量生成 ---------- */ +const layerBatchDialog = ref(false) +const layerBatchForm = reactive({ zoneCode: '', shelfNo: '', layerStart: 1, layerEnd: 1 }) +const layerBatchPreview = ref([]) +const layerBatchPreviewing = ref(false) +const layerBatchSubmitting = ref(false) + +function openLayerBatchGen() { + Object.assign(layerBatchForm, { zoneCode: '', shelfNo: '', layerStart: 1, layerEnd: 1 }) + layerBatchPreview.value = [] + layerBatchDialog.value = true +} +async function onLayerBatchRegionChange() { + layerBatchForm.shelfNo = '' + await loadShelfOpts(lbShelf, layerBatchForm.zoneCode) +} +async function previewLayerBatch() { + if (!layerBatchForm.zoneCode || !layerBatchForm.shelfNo) { ElMessage.warning('请选择区域与货架'); return } + layerBatchPreviewing.value = true + try { + const data = await request.post('/zone/batch-generate', { ...layerBatchForm, level: 3, preview: true }) + layerBatchPreview.value = data?.list || [] + } finally { + layerBatchPreviewing.value = false + } +} +async function submitLayerBatch() { + const go = await confirmAction(`已预检 ${layerBatchPreview.value.length} 个层,确认批量生成到库位表?(已存在的自动跳过)`, '批量生成确认') + if (!go) return + layerBatchSubmitting.value = true + try { + const data = await request.post('/zone/batch-generate', { ...layerBatchForm, level: 3, preview: false }) + ElMessage.success(`已生成 ${data?.created || 0} 个层,跳过已存在 ${data?.skipped || 0} 个`) + layerBatchDialog.value = false + zoneTabLoaded[3] = false + if (activeZoneTab.value === 3) await loadNodes(3) + } finally { + layerBatchSubmitting.value = false + } +} + /* ---------- 物料档案维护 ---------- */ const materials = ref([]) const materialTotal = ref(0) @@ -411,8 +453,11 @@ async function exportMaterials() { name: matFilter.name.trim(), spec: matFilter.spec.trim(), manageMode: matFilter.manageMode, - itemType: matFilter.itemType - }, '物料档案.xlsx') + itemType: matFilter.itemType, + startDate: matFilter.startDate, + endDate: matFilter.endDate + }, '物料档案.xlsx', { countUrl: '/material/query', name: '物料档案' }) + if (!name) return ElMessage.success('已导出:' + name) } catch (e) { ElMessage.error('导出失败:' + (e?.message || e)) @@ -603,6 +648,7 @@ async function onMaterialFile(e) { 查询 新增层 + 批量生成层 @@ -763,6 +809,41 @@ async function onMaterialFile(e) { 共 {{ batchPreview.length }} 个位置,其中已存在 {{ batchPreview.filter(x=>x.exists).length }} 个(生成时自动跳过)。
+ + + + + + + + + + + + + + + + + + + + + 预览 + 确认生成 + + + + + + + + + +
+ 共 {{ layerBatchPreview.length }} 个层,其中已存在 {{ layerBatchPreview.filter(x=>x.exists).length }} 个(生成时自动跳过)。 +
+
diff --git a/bj_power_wms/frontend/src/pages/Dock.vue b/bj_power_wms/frontend/src/pages/Dock.vue index 04570ca..1571057 100644 --- a/bj_power_wms/frontend/src/pages/Dock.vue +++ b/bj_power_wms/frontend/src/pages/Dock.vue @@ -2,7 +2,7 @@
+ title="接驳台是产线与库房之间供 AGV 取送货的物理停靠位,为系统预置的只读主数据,本页仅供查看。类型分 产线 / 库房 / 其他:产线接驳台与工位一一对应(DOCK01~20 对应工位 1~20),库房接驳台为收货/发货口(DOCK21),其他为缓存/暂存位;只有产线接驳台绑定工位号。" /> diff --git a/bj_power_wms/frontend/src/pages/Inbound.vue b/bj_power_wms/frontend/src/pages/Inbound.vue index ebddb00..82c7a4e 100644 --- a/bj_power_wms/frontend/src/pages/Inbound.vue +++ b/bj_power_wms/frontend/src/pages/Inbound.vue @@ -440,7 +440,7 @@ async function exportCsv() { voided: filters.voided, startDate: dateRange.value?.[0] || '', endDate: dateRange.value?.[1] || '' - }, '入库管理.xlsx') + }, '入库管理.xlsx', { countUrl: '/inbound/query', name: '入库记录' }) } catch (e) { /* 错误提示由请求层统一处理 */ } diff --git a/bj_power_wms/frontend/src/pages/Inspection.vue b/bj_power_wms/frontend/src/pages/Inspection.vue index a4691a1..65274cf 100644 --- a/bj_power_wms/frontend/src/pages/Inspection.vue +++ b/bj_power_wms/frontend/src/pages/Inspection.vue @@ -333,7 +333,7 @@ async function exportCsv() { inspector: filters.inspector.trim(), startDate: filters.startDate, endDate: filters.endDate - }, '检验记录.xlsx') + }, '检验记录.xlsx', { countUrl: '/inspection/query', name: '检验记录' }) } catch (e) { /* 错误提示由请求层统一处理 */ } diff --git a/bj_power_wms/frontend/src/pages/Inventory.vue b/bj_power_wms/frontend/src/pages/Inventory.vue index 49f528c..1908d2c 100644 --- a/bj_power_wms/frontend/src/pages/Inventory.vue +++ b/bj_power_wms/frontend/src/pages/Inventory.vue @@ -233,11 +233,11 @@ async function exportCsv() { materialCode: filters.materialCode.trim(), materialName: filters.materialName.trim(), manageMode: filters.manageMode - }, '物料汇总.xlsx') + }, '物料汇总.xlsx', { count: matTotal.value, name: '物料汇总' }) return } if (viewTab.value === 'summary') { - await exportXlsxFetch('/api/stock/export', { view: 'zone' }, '区域汇总.xlsx') + await exportXlsxFetch('/api/stock/export', { view: 'zone' }, '区域汇总.xlsx', { count: summaryRows.value.length, name: '区域汇总' }) return } await exportXlsxFetch('/api/stock/export', { @@ -248,7 +248,7 @@ async function exportCsv() { manageMode: filters.manageMode, startDate: filters.startDate, endDate: filters.endDate - }, '库存汇总.xlsx') + }, '库存汇总.xlsx', { countUrl: '/stock/query', name: '库存明细' }) } catch (e) { // 错误信息已由 request 层处理 } diff --git a/bj_power_wms/frontend/src/pages/Outbound.vue b/bj_power_wms/frontend/src/pages/Outbound.vue index 15feff5..a2e652f 100644 --- a/bj_power_wms/frontend/src/pages/Outbound.vue +++ b/bj_power_wms/frontend/src/pages/Outbound.vue @@ -24,14 +24,22 @@ const loadingPrep = ref(false) const queried = ref(false) const rows = ref([]) -onMounted(loadOrders) -async function loadOrders() { +const orders = ref([]) +const ordersLoading = ref(false) +// 工单号来自 MES 实时查询:无输入默认拉「未完成优先」的前 20 条;输入时按工单号模糊远程搜索。 +async function searchOrders(query) { + ordersLoading.value = true try { - const data = await request.get('/orders', { params: { page: 1, pageSize: 200 } }) + const data = await request.get('/orders', { params: { orderNo: query || '', limit: 20 } }) orders.value = Array.isArray(data) ? data : data?.list || [] } catch { orders.value = [] } + finally { ordersLoading.value = false } } -const orders = ref([]) +async function loadOrders() { await searchOrders('') } +function orderLabel(o) { return o.productName ? `${o.workOrderNo} ${o.productName}` : o.workOrderNo } +// 选中下拉项或手输兜底(allow-create)后直接查该工单台账 +function onOrderPick(v) { if (v && String(v).trim()) queryPrep() } +onMounted(loadOrders) const pendingRows = computed(() => rows.value.filter(r => r.status !== '领料完结')) function gapOf(row) { return Math.max((row.totalQty || 0) - (row.outQty || 0), 0) } @@ -326,7 +334,14 @@ async function submitGen() { } /* ===================== 出库记录(统一主表,全部 + 导出) ===================== */ -const recFilters = reactive({ outboundType: '', status: '', materialCode: '', boxNo: '', ownershipType: '', dateRange: [] }) +// 出库记录默认展示近 3 个月(与后端导出时间硬规则一致,保证「列表条数 = 导出条数」) +function recDefaultRange() { + const p = (n) => String(n).padStart(2, '0') + const fmt = (d) => `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}` + const end = new Date(); const start = new Date(); start.setMonth(start.getMonth() - 3) + return [fmt(start), fmt(end)] +} +const recFilters = reactive({ outboundType: '', status: '', materialCode: '', boxNo: '', ownershipType: '', dateRange: recDefaultRange() }) const recRows = ref([]) const recTotal = ref(0) const loadingRec = ref(false) @@ -346,8 +361,8 @@ async function loadRecords() { page: recPage.current, pageSize: recPage.size } if (Array.isArray(recFilters.dateRange) && recFilters.dateRange.length === 2) { - params.startAt = new Date(recFilters.dateRange[0]).getTime() - params.endAt = new Date(recFilters.dateRange[1]).getTime() + 86399999 + params.startDate = recFilters.dateRange[0] + params.endDate = recFilters.dateRange[1] } const data = await request.get('/outbound/query', { params }) recRows.value = (data?.list || []).map(r => ({ ...r, snCodes: snOf(r) })) @@ -355,16 +370,20 @@ async function loadRecords() { } finally { loadingRec.value = false } } function searchRec() { recPage.current = 1; loadRecords() } -function resetRec() { Object.assign(recFilters, { outboundType: '', status: '', materialCode: '', boxNo: '', dateRange: [] }); searchRec() } +function resetRec() { Object.assign(recFilters, { outboundType: '', status: '', materialCode: '', boxNo: '', dateRange: recDefaultRange() }); searchRec() } function downloadCSV() { + // 时间窗口与列表保持一致:未选/已清空时回落近 3 个月,保证确认框条数 = 实际导出条数 + const dr = (Array.isArray(recFilters.dateRange) && recFilters.dateRange.length === 2) ? recFilters.dateRange : recDefaultRange() exportXlsxFetch('/api/outbound/export', { outboundType: recFilters.outboundType, status: recFilters.status, materialCode: recFilters.materialCode.trim(), - boxNo: recFilters.boxNo.trim() - }, '出库管理.xlsx') - .then(() => ElMessage.success('导出成功')) + boxNo: recFilters.boxNo.trim(), + startDate: dr[0], + endDate: dr[1] + }, '出库管理.xlsx', { countUrl: '/outbound/query', name: '出库记录' }) + .then((name) => { if (name) ElMessage.success('已导出:' + name) }) .catch(() => ElMessage.error('导出失败')) } @@ -387,8 +406,15 @@ onMounted(loadDicts) - + + + {{ o.workOrderNo }} + {{ o.productName }} {{ o.status }} + + diff --git a/bj_power_wms/frontend/src/pages/Semi.vue b/bj_power_wms/frontend/src/pages/Semi.vue index 6ea321d..d82985c 100644 --- a/bj_power_wms/frontend/src/pages/Semi.vue +++ b/bj_power_wms/frontend/src/pages/Semi.vue @@ -11,15 +11,14 @@ import MaterialSelect from '../components/MaterialSelect.vue' import AttachmentPanel from '../components/AttachmentPanel.vue' import { helpSemi } from '../help' -// 半成品/成品附件(bizType=semi,bizId=SN) +// 半成品附件(bizType=semi,bizId=SN) const attachDrawer = reactive({ visible: false, sn: '' }) function openAttach(row) { Object.assign(attachDrawer, { visible: true, sn: row.sn }) } -/* ---------- 半成品/成品入库 ---------- - * 客户诉求 问题记录 L222:半成品与成品入库要区分(category 2/3); - * L218 成品入库 9 字段:SN/图号/归属/产品状态/相关标准/试验记录单号/记录员/记录日期/工单号。 */ +/* ---------- 半成品入库(category=2) ---------- + * 成品由 MES 完工自动回流入库、经 WMS 完工检验,不在本页手工入库。 */ const operator = getRealName() const todayStr = new Date().toLocaleDateString('sv-SE') @@ -33,11 +32,11 @@ function newInForm() { recordedBy: operator, recordedAt: todayStr } } -// inForms[2]=半成品入库表单,inForms[3]=成品入库表单 -const inForms = reactive({ 2: newInForm(), 3: newInForm() }) -const snInputs = reactive({ 2: '', 3: '' }) -const snLists = reactive({ 2: [], 3: [] }) -const inbounding = reactive({ 2: false, 3: false }) +// inForms[2]=半成品入库表单(category=2) +const inForms = reactive({ 2: newInForm() }) +const snInputs = reactive({ 2: '' }) +const snLists = reactive({ 2: [] }) +const inbounding = reactive({ 2: false }) function addSnLines(cat) { for (let raw of String(snInputs[cat]).split(/\s+/)) { @@ -53,7 +52,7 @@ function removeSn(cat, i) { async function submitInbound(cat) { const f = inForms[cat] - const label = cat === 3 ? '成品' : '半成品' + const label = '半成品' if (!f.materialCode) { ElMessage.warning('请选择物料') return @@ -62,10 +61,6 @@ async function submitInbound(cat) { ElMessage.warning('请扫码录入 SN(回车追加)') return } - if (cat === 3 && !f.productStatus) { - ElMessage.warning('成品入库请选择产品状态(已通过/部分通过/返修)') - return - } // 归属必选(与入库管理同口径,不再有「无」);选其他可不填编号,工单号/科技项目号必须填编号 if (!f.ownershipType) { ElMessage.warning('请选择归属(工单编号 / 科技项目号 / 其他)') @@ -109,11 +104,11 @@ async function submitInbound(cat) { } } -/* ---------- 半成品/成品出库(扫SN带出 + 出库原因按钮,客户诉求 L224) ---------- */ +/* ---------- 半成品出库(扫SN带出 + 出库原因按钮);成品发货走「出库管理」通用出库 ---------- */ const outReasons = ['包装', '继续生产', '检验试验', '其他'] -// outForms[2]=半成品出库,outForms[3]=成品出库 -const outForms = reactive({ 2: { sn: '', info: null, reason: '' }, 3: { sn: '', info: null, reason: '' } }) -const outbounding = reactive({ 2: false, 3: false }) +// outForms[2]=半成品出库(category=2) +const outForms = reactive({ 2: { sn: '', info: null, reason: '' } }) +const outbounding = reactive({ 2: false }) // 扫 SN 回车:带出该件信息(物料/已完成工序/工单/归属),再点原因按钮出库 async function scanSn(cat) { @@ -126,7 +121,7 @@ async function scanSn(cat) { const data = await request.get('/semi/query', { params: { sn, category: cat, page: 1, pageSize: 5 } }) const hit = (data?.list || []).find((r) => r.sn === sn) if (!hit) { - ElMessage.warning(`未找到该 SN 的${cat === 3 ? '成品' : '半成品'}记录`) + ElMessage.warning(`未找到该 SN 的半成品记录`) return } if (hit.status !== '在库') { @@ -139,7 +134,7 @@ async function scanSn(cat) { async function submitOutbound(cat) { const f = outForms[cat] - const label = cat === 3 ? '成品' : '半成品' + const label = '半成品' const sn = f.sn.trim() if (!sn) { ElMessage.warning('请扫描或输入 SN') @@ -167,8 +162,8 @@ async function submitOutbound(cat) { } } -/* ---------- 半成品/成品查询(L230 加归属;L222 品类筛选) ---------- */ -const qForm = reactive({ materialCode: '', status: '', sn: '', ownershipNo: '', category: '' }) +/* ---------- 半成品查询(L230 加归属) ---------- */ +const qForm = reactive({ materialCode: '', status: '', sn: '', ownershipNo: '' }) const list = ref([]) const total = ref(0) const loading = ref(false) @@ -183,7 +178,6 @@ async function loadList() { status: qForm.status, sn: qForm.sn.trim(), ownershipNo: qForm.ownershipNo.trim(), - category: qForm.category || undefined, page: page.current, pageSize: page.size } @@ -271,73 +265,6 @@ onMounted(() => {
- - - - - - - - - 已通过 - 部分通过 - 返修 - - - - - - -
- - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - -
-
待入库 SN:{{ snLists[3].length }}
- - - - - - - -
- 提交成品入库 - 清空 -
-
- @@ -366,43 +293,9 @@ onMounted(() => { - - - - - - - - -
图号:{{ outForms[3].info.materialCode || '-' }} 名称:{{ outForms[3].info.materialName || '-' }} 产品状态:{{ outForms[3].info.productStatus || '-' }}
-
工单号:{{ outForms[3].info.orderNo || '-' }} 归属:{{ outForms[3].info.ownershipNo || '-' }} 试验记录单号:{{ outForms[3].info.testRecordNo || '-' }}
-
- - - - {{ r }} - - - - - - - 成品出库 - - -
- - + - - - - - - @@ -424,13 +317,6 @@ onMounted(() => { - - - @@ -442,9 +328,6 @@ onMounted(() => { - - - @@ -477,8 +360,8 @@ onMounted(() => {
- - + + diff --git a/bj_power_wms/frontend/src/pages/Stocktake.vue b/bj_power_wms/frontend/src/pages/Stocktake.vue index 661a179..4b10e84 100644 --- a/bj_power_wms/frontend/src/pages/Stocktake.vue +++ b/bj_power_wms/frontend/src/pages/Stocktake.vue @@ -258,9 +258,10 @@ function statusTagType(s) { } } -async function exportDetail(no) { +async function exportDetail(row) { try { - await exportXlsxFetch('/api/stocktake/export', { stocktakeNo: no }, `盘点明细_${no}.xlsx`) + await exportXlsxFetch('/api/stocktake/export', { stocktakeNo: row.stocktakeNo }, `盘点明细_${row.stocktakeNo}.xlsx`, + { count: row.totalTargets, name: '盘点明细' }) } catch (e) { ElMessage.error('导出失败:' + (e?.message || e)) } @@ -503,7 +504,7 @@ const currentStep = computed(() => { diff --git a/bj_power_wms/frontend/src/utils/export.js b/bj_power_wms/frontend/src/utils/export.js index 3728224..19733a7 100644 --- a/bj_power_wms/frontend/src/utils/export.js +++ b/bj_power_wms/frontend/src/utils/export.js @@ -1,5 +1,42 @@ import request from './request' import { getToken } from './auth' +import { confirmAction } from './confirm' + +// 导出前统一确认:告知用户即将导出的数据条数。 +// count 为 null/undefined 时(无法预知条数)提示“全部”;否则回显具体条数。 +export async function confirmExport(count, name = '数据') { + const msg = (count === null || count === undefined) + ? `即将导出全部${name},是否继续?` + : `即将导出 ${count} 条${name},是否继续?` + return confirmAction(msg, '导出确认', { confirmButtonText: '确认导出', cancelButtonText: '取消' }) +} + +function ymd(d) { + const p = (n) => String(n).padStart(2, '0') + return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}` +} + +// effExportParams 归一化导出日期参数,避免后端 normalizeExportRange「只传一端即报错(400)」: +// 仅当 params 显式带有 startDate/endDate 键时生效;一端为空则补齐(缺结束=今天,缺起始=结束前推3个月); +// 两端都空则保持为空(由后端按各自规则处理,列表与导出用同一份参数,条数才一致)。 +export function effExportParams(params) { + if (!params || (!('startDate' in params) && !('endDate' in params))) return params + let s = params.startDate || '' + let e = params.endDate || '' + if (s && !e) e = ymd(new Date()) + else if (!s && e) { const d = new Date(e); d.setMonth(d.getMonth() - 3); s = ymd(d) } + return { ...params, startDate: s, endDate: e } +} + +// countByQuery 用与导出完全相同的筛选参数请求列表接口(pageSize=1)拿精确总数, +// 保证「确认框条数」= 实际导出条数(列表与导出共用同一套 where 条件)。 +async function countByQuery(countUrl, params) { + try { + const data = await request.get(countUrl, { params: { ...params, page: 1, pageSize: 1 } }) + const t = data?.total + return (t === null || t === undefined) ? null : Number(t) + } catch { return null } +} // 下载 xlsx 导出:后端返回 .xlsx 二进制,文件名由后端 Content-Disposition 指定。 // 各导出接口:{path}?format=xlsx&<筛选参数> @@ -33,8 +70,18 @@ export function exportXlsx(path, params, fallbackName = '导出.xlsx') { } // 带 token 的二进制下载(保底方式:直接构造带 Authorization 的 fetch) -export async function exportXlsxFetch(path, params, fallbackName = '导出.xlsx') { - const qs = new URLSearchParams({ format: 'xlsx', ...params }).toString() +// confirm:导出前确认。默认 true=弹确认框但不显示条数(提示“全部”); +// 传 { count, name } 直接回显条数;或传 { countUrl, name } 由本函数用相同筛选参数拉取精确条数; +// 传 false 可跳过确认(不建议)。 +export async function exportXlsxFetch(path, params, fallbackName = '导出.xlsx', confirm = true) { + const eff = effExportParams(params) + if (confirm) { + const opt = confirm === true ? {} : confirm + let count = (opt.count === null || opt.count === undefined) ? null : opt.count + if (count === null && opt.countUrl) count = await countByQuery(opt.countUrl, eff) + if (!(await confirmExport(count, opt.name))) return null + } + const qs = new URLSearchParams({ format: 'xlsx', ...eff }).toString() const res = await fetch(`${path}?${qs}`, { headers: { Authorization: `Bearer ${getToken()}` } }) @@ -64,4 +111,4 @@ export async function exportXlsxFetch(path, params, fallbackName = '导出.xlsx' return filename } -export default { exportXlsx, exportXlsxFetch } \ No newline at end of file +export default { exportXlsx, exportXlsxFetch, confirmExport } \ No newline at end of file diff --git a/bj_power_wms/internal/db/seed.go b/bj_power_wms/internal/db/seed.go index ae54155..7607d31 100644 --- a/bj_power_wms/internal/db/seed.go +++ b/bj_power_wms/internal/db/seed.go @@ -14,36 +14,15 @@ import ( // // 生产环境口径(用户裁决 2026-09-20):种子只允许写入系统跑起来所必需的固定主数据, // 严禁预置演示物料/演示库存/演示账号等假业务数据。具体: -// - 区域:库房四大基础分区 Z01~Z04(库存落位的根节点,level=1); // - 管理员账号:admin(初始密码 123456,登录后应立即修改);其余账号由管理员在「账号管理」按需创建、分配角色; -// - 接驳台:DOCK01~20(产线,DOCKn↔工位n)+ DOCK21(库房收货),系统预置只读主数据(dock.go 不提供增删改)。 +// - 接驳台:DOCK01~20(产线,DOCKn↔工位n)+ DOCK21(库房收货),系统预置只读主数据(dock.go 不提供增删改,只能靠种子写入)。 // +// 不预置区域/库位:区域是现场库房布局,因项目而异,且「区域维护」页面可增删改,由实施按现场实际建立,不硬编码进种子。 // 权限与角色不在此:由 handler.SeedRBAC 幂等初始化(reset-all/seed 命令与 POST /api/rbac/seed 共用同一函数)。 func SeedIfEmpty(client *ent.Client) error { ctx := context.Background() - // 1. 区域(层级节点 level=1) - zones, _ := client.Zone.Query().Count(ctx) - if zones == 0 { - for _, z := range []struct{ code, name string }{ - {"Z01", "待检区"}, - {"Z02", "标准存储区"}, - {"Z03", "暂存区"}, - {"Z04", "退货区"}, - } { - client.Zone.Create(). - SetLevel(1). - SetCode(z.code). - SetZoneName(z.name). - SetZoneCode(z.code). - SetParentCode(""). - SetStatus("启用"). - SaveX(ctx) - } - slog.Info("seed: zones created") - } - - // 2. 管理员账号(唯一预置账号;初始密码 123456,登录后应立即修改) + // 1. 管理员账号(唯一预置账号;初始密码 123456,登录后应立即修改) users, _ := client.User.Query().Count(ctx) if users == 0 { adminHash, _ := bcrypt.GenerateFromPassword([]byte("123456"), bcrypt.DefaultCost) @@ -56,7 +35,7 @@ func SeedIfEmpty(client *ent.Client) error { slog.Info("seed: admin user created (admin/123456)") } - // 3. 接驳台主数据 DOCK01~20(产线, DOCKn↔工位n) + DOCK21(库房) + // 2. 接驳台主数据 DOCK01~20(产线, DOCKn↔工位n) + DOCK21(库房) docks, _ := client.Dock.Query().Count(ctx) if docks == 0 { for i := 1; i <= 20; i++ { diff --git a/bj_power_wms/internal/handler/misc.go b/bj_power_wms/internal/handler/misc.go index e4780d5..44375d0 100644 --- a/bj_power_wms/internal/handler/misc.go +++ b/bj_power_wms/internal/handler/misc.go @@ -240,8 +240,8 @@ func semiView(inv *ent.Inventory) *semiViewRow { } } -// querySemiHandler 半成品/成品查询(读统一库存主表 category=2/3) -// 客户诉求 L230:查询增加归属(工单号/科技项目号);L222:半成品与成品分开查(category 参数)。 +// querySemiHandler 半成品查询(读统一库存主表 category=2 半成品)。 +// 半成品管理页只处理半成品;成品由 MES 完工回流入库、经 WMS 完工检验,在「库存查询」页按品类查看,不在本页手工出入库。 func querySemiHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { page := atoi(r.URL.Query().Get("page"), 1) @@ -250,12 +250,8 @@ func querySemiHandler(ctx *svc.ServiceContext) http.HandlerFunc { status := r.URL.Query().Get("status") sn := r.URL.Query().Get("sn") ownershipNo := r.URL.Query().Get("ownershipNo") - category := atoi(r.URL.Query().Get("category"), 0) // 2=半成品 3=成品 0=两者都查 - q := ctx.EntClient.Inventory.Query().Where(inventory.CategoryIn(invCatSemi, invCatFinished)) - if category == invCatSemi || category == invCatFinished { - q = q.Where(inventory.CategoryEQ(category)) - } + q := ctx.EntClient.Inventory.Query().Where(inventory.CategoryEQ(invCatSemi)) if materialCode != "" { q = q.Where(inventory.MaterialCodeEqualFold(materialCode)) } diff --git a/bj_power_wms/internal/handler/orders.go b/bj_power_wms/internal/handler/orders.go index c0e08a9..e857ad2 100644 --- a/bj_power_wms/internal/handler/orders.go +++ b/bj_power_wms/internal/handler/orders.go @@ -3,6 +3,7 @@ package handler import ( "encoding/json" "net/http" + "net/url" "sort" "time" @@ -26,8 +27,15 @@ type mesOrder struct { // ordersHandler 调用 MES 内部接口获取工单列表,把未完成工单排前面,供备料出库下拉选择 func ordersHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - url := ctx.Config.Mes.BaseURL + "/api/internal/order/query?orderNo=" + r.URL.Query().Get("orderNo") - req, err := http.NewRequest(http.MethodGet, url, nil) + orderNo := r.URL.Query().Get("orderNo") + // limit:无输入条件时默认返回 20 条(未完成优先),供备料出库工单号下拉首屏展示; + // 模糊搜索时同样返回匹配结果的前 limit 条。 + limit := atoi(r.URL.Query().Get("limit"), 20) + if limit <= 0 { + limit = 20 + } + mesURL := ctx.Config.Mes.BaseURL + "/api/internal/order/query?orderNo=" + url.QueryEscape(orderNo) + req, err := http.NewRequest(http.MethodGet, mesURL, nil) if err != nil { // 构造请求都失败属代码级异常,返回空列表让备料出库页可降级(仍可手输工单号) ok(w, []mesOrder{}) @@ -66,6 +74,10 @@ func ordersHandler(ctx *svc.ServiceContext) http.HandlerFunc { } return list[i].WorkOrderNo < list[j].WorkOrderNo }) + // 排序(未完成优先)后截断:无输入默认前 20 条;模糊搜索返回匹配的前 20 条。 + if len(list) > limit { + list = list[:limit] + } ok(w, list) } } diff --git a/bj_power_wms/internal/handler/zone.go b/bj_power_wms/internal/handler/zone.go index 9dfa690..a942c4f 100644 --- a/bj_power_wms/internal/handler/zone.go +++ b/bj_power_wms/internal/handler/zone.go @@ -463,11 +463,13 @@ type zoneBatchGenReq struct { LayerEnd int `json:"layerEnd"` PosStart int `json:"posStart"` PosEnd int `json:"posEnd"` + Level int `json:"level"` // 3=批量生成层(level3) 4=批量生成位置号(level4,默认,同时确保层存在) Preview bool `json:"preview"` } -// batchGenerateHandler 批量生成位置号:选区域→货架→层范围→位置范围,先预览后提交。 -// 自动确保层节点(level3)存在;已存在的位置号跳过不重复建。 +// batchGenerateHandler 批量生成库位节点:选区域→货架→范围,先预览后提交。 +// level=3:只生成「层」节点(按层范围);level=4(默认):生成「位置号」节点(层×位置),并自动确保层节点存在。 +// 已存在的节点跳过不重复建。 func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { var req zoneBatchGenReq @@ -481,8 +483,16 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc { fail(w, http.StatusBadRequest, "请选择区域与货架") return } - if req.LayerStart < 0 || req.LayerEnd < req.LayerStart || req.PosStart < 0 || req.PosEnd < req.PosStart { - fail(w, http.StatusBadRequest, "层/位置起止不合法(起始需 ≤ 结束,且 ≥ 0)") + level := req.Level + if level != 3 { + level = 4 + } + if req.LayerStart < 0 || req.LayerEnd < req.LayerStart { + fail(w, http.StatusBadRequest, "层起止不合法(起始需 ≤ 结束,且 ≥ 0)") + return + } + if level == 4 && (req.PosStart < 0 || req.PosEnd < req.PosStart) { + fail(w, http.StatusBadRequest, "位置起止不合法(起始需 ≤ 结束,且 ≥ 0)") return } sh, err := ctx.EntClient.Zone.Query().Where(zone.LevelEQ(2), zone.ZoneCodeEQ(req.ZoneCode), zone.CodeEQ(req.ShelfNo)).Only(ctx0()) @@ -496,6 +506,52 @@ func batchGenerateHandler(ctx *svc.ServiceContext) http.HandlerFunc { for l := req.LayerStart; l <= req.LayerEnd; l++ { layers = append(layers, l) } + + // ---------- level=3:批量生成层节点 ---------- + if level == 3 { + if len(layers) > 2000 { + fail(w, http.StatusBadRequest, "一次最多生成 2000 个层,请缩小范围") + return + } + type genLayer struct { + LayerNo string `json:"layerNo"` + LayerName string `json:"layerName"` + Exists bool `json:"exists"` + } + layerList := make([]genLayer, 0, len(layers)) + for _, l := range layers { + ls := strconv.Itoa(l) + exists, _ := ctx.EntClient.Zone.Query(). + Where(zone.LevelEQ(3), zone.ZoneCodeEQ(zoneCode), zone.ShelfNoEQ(req.ShelfNo), zone.CodeEQ(ls)).Exist(ctx0()) + layerList = append(layerList, genLayer{LayerNo: ls, LayerName: req.ShelfNo + "架" + ls + "层", Exists: exists}) + } + if req.Preview { + ok(w, map[string]any{"preview": true, "level": 3, "list": layerList, "total": len(layerList)}) + return + } + createdL, skippedL := 0, 0 + for _, it := range layerList { + if it.Exists { + skippedL++ + continue + } + if _, err := ctx.EntClient.Zone.Create(). + SetLevel(3).SetCode(it.LayerNo).SetParentCode(req.ShelfNo). + SetZoneCode(zoneCode).SetShelfNo(req.ShelfNo).SetLayerNo(it.LayerNo). + SetName(it.LayerName).SetStatus("启用").Save(ctx0()); err != nil { + fail(w, http.StatusInternalServerError, "创建层失败: "+err.Error()) + return + } + createdL++ + } + ctx.EventLog.Write(ctx0(), "zone.batch", r.Header.Get("X-Username"), "zone", req.ShelfNo, + "批量生成层 "+req.ZoneCode+"/"+req.ShelfNo+" 层"+strconv.Itoa(req.LayerStart)+"-"+strconv.Itoa(req.LayerEnd)+ + ":新建"+strconv.Itoa(createdL)+" 跳过"+strconv.Itoa(skippedL), nil) + ok(w, map[string]any{"preview": false, "level": 3, "created": createdL, "skipped": skippedL, "total": len(layers)}) + return + } + + // ---------- level=4:批量生成位置号 ---------- poss := make([]int, 0) for p := req.PosStart; p <= req.PosEnd; p++ { poss = append(poss, p) diff --git a/bj_power_wms/web/static/index.html b/bj_power_wms/web/static/index.html index 539077d..e22ed34 100644 --- a/bj_power_wms/web/static/index.html +++ b/bj_power_wms/web/static/index.html @@ -6,7 +6,7 @@ WMS库房管理 - + diff --git a/案例.md b/案例.md new file mode 100644 index 0000000..dc70e2a --- /dev/null +++ b/案例.md @@ -0,0 +1,511 @@ +任务:通读 bj_power 代码,生成业务契约文档 + +【你要读的代码】 +- bj_power_mes、bj_power_wms、bj_power_workstation 三个 Go 项目的 handler、logic、schema +- 各项目 frontend/src/pages/*.vue +- 根目录所有 .md 文档(只作背景,代码是唯一事实) + +【文档定位】 +这是给业务方和开发看的业务场景流水账,不是代码审计报告。 +用业务语言写,人能看懂。不要贴代码,不要标行号,不要贴函数名。 + +【铁律】 +1. 读代码,但用业务语言描述,不暴露代码细节。 +2. 业务逻辑如果跑不通,记录下来,停止后续操作。 +3. 如何判断逻辑跑不通? 每一步,都有 前置条件、执行过程、产生的数据。如果 本步骤需要的数据条件, 前面步骤无法提供,就是业务流程不通。 +4. 不写"应该怎样"、"建议改成"、"后续优化"。 +5. 不合并场景,不擅自拆分。 +6. 英文枚举名转中文。 + +【第一步:列场景清单】 +通读代码后,列出系统实际支持的全部业务场景。 +每个场景写:场景名、从哪个菜单进入、干什么事。 +清单只写代码里真实存在的。列完清单后,直接进入第二步,不要停下来等确认。 + +【第二步:在此文档 写三份 大标题】 + +文档1:业务流程 + 顶层地图。主链路 + 异常链路,每个节点指向“案例”的场景编号。 + 一个节点一句话。不重复场景内容。 + +文档2:案例 + 场景流水,禁止写分支,从头到尾只有一条路径,禁止写 "如果...就..."、"否则..."、"另一种情况"。每个场景独立成章,格式: + ## 场景N:场景名 + ### 前置条件 + ### 操作步骤(角色 + 系统 + 菜单 + 填什么字段(关键字段即可) + 点什么按钮) + ### 系统反应(业务语言,如"库存扣减204颗,锁定量清零") + ### 数据变化(哪个表、哪个字段、变成什么值) + ### 验证点(页面能看到什么、数据库断言什么、数量等式是否成立) + ### 对不上的地方(标红,只标真正对不上的,不标"代码在哪") + +文档3:回归测试 + 可断言用例。按场景分组,格式: + ## 测试场景N:场景名 + ### 前置数据准备(SQL 或 API) + ### 执行步骤(API 路径 + body) + ### 预期结果(表名 + 字段 + 期望值) + ### 数量等式断言 + ### 清理步骤 + 断言必须是具体数值/状态/条数,不能写"页面正常"。 + +【执行顺序】 +1. 列场景清单 +2. 写业务流程 +3. 写案例(一次一个场景,写完继续下一个,不要停) +4. 写回归测试 + +【禁止】 +1. 禁止凭想象写业务逻辑 +2. 禁止把设计文档当事实 +3. 禁止贴代码、标行号、贴函数名 +4. 禁止写"应该"、"建议"、"后续优化" +5. 禁止模糊断言 +6. 禁止英文枚举直接写文档 +7. 禁止在案例里写代码细节 + + + + +下面是执行结果输出文本: + + +# 第一步:业务场景清单 + +> 清单只列代码里真实存在的菜单与功能。分三套系统:WMS 库房管理(端口 8890)、MES 产线控制(端口 8888)、工位终端(端口 8892)。 + +## 一、WMS 库房管理 + +| 编号 | 场景名 | 入口菜单 | 干什么事 | +|---|---|---|---| +| W1 | 登录 | 登录页 | 库管员/管理员用账号密码登录,取得访问令牌 | +| W2 | 工作台 | 工作台 | 查看库存总览、预警等首页概览 | +| W3 | 入库登记 | 入库管理 | 结构件按批次、电气件按序列号登记入库,支持 Excel 批量导入,入库后库存增加 | +| W4 | 入库作废 | 入库管理 | 对已登记入库单填原因作废,库存按批次/序列号精确回滚 | +| W5 | 备料出库 | 出库管理 | 按工单备料出库,装箱、指定目标工位,库存扣减 | +| W6 | 通用出库 | 出库管理 | 非工单的一般出库,库存扣减 | +| W7 | 退库确认 | 退库确认 | 工位退回物料,库管确认收货后库存加回 | +| W8 | 库存查询 | 库存查询 | 按物料汇总/区域汇总/明细三种口径查库存 | +| W9 | 来料检验 | 来料检验 | 登记来料检验结论,合格/不合格翻转与处置 | +| W10 | 过程检验 | 过程检验 | 登记生产过程检验结论与处置 | +| W11 | 完工检验 | 完工检验 | 登记完工检验结论与处置 | +| W12 | 库存盘点 | 库存盘点 | 发起盘点、扫码录入实盘、完成写回差异、取消、导出明细 | +| W13 | 半成品入库/出库 | 半成品管理 | 半成品入库存/出库存与查询 | +| W14 | 工单备料台账 | 工单备料台账 | 查看某工单各物料的锁定量/在途量/线边量/已接料量四段台账 | +| W15 | AGV 配送 | AGV配送 | 向海康调度系统下发搬运任务、查看任务与接驳台状态、取消 | +| W16 | 区域维护 | 区域维护 | 维护区域/货架/层/位置号四级库位结构,支持批量生成 | +| W17 | 物料档案维护 | 物料档案 | 新增/修改/查询物料档案,支持导入导出 | +| W18 | 接驳台维护 | 接驳台维护 | 查看系统预置的接驳台只读主数据 | +| W19 | 账号管理 | 账号管理 | 增删改查登录账号、分配角色 | +| W20 | 角色管理 | 角色管理 | 增删改查角色、配置权限 | +| W21 | 操作日志 | 操作日志 | 查询系统操作留痕 | +| W22 | 附件中心 | 附件中心 | 集中查看/归档/清理各业务上传的附件 | +| W23 | 修改密码 | 修改密码 | 当前用户修改自己的登录密码 | +| W24 | 库存大屏 | 库存大屏(免登录) | 全屏展示库存概览 | + +## 二、MES 产线控制 + +| 编号 | 场景名 | 入口菜单 | 干什么事 | +|---|---|---|---| +| M1 | 工单管理 | 工单管理 | 新增/修改/查询工单、切换工单状态、自动排产 | +| M2 | 日排产 | 日排产 | 为工单编排每日生产计划、推荐接驳台 | +| M3 | 产品物料清单 | 产品物料清单 | 维护产品型号的 BOM,支持导入、删除条目 | +| M4 | 备料单 | 备料单 | 按 BOM 生成备料单、领料、触发 WMS 自动出库、查看配送进度 | +| M5 | 数量不符处理 | 数量不符处理 | 处理工位上报的物料数量不符,查看统计 | +| M6 | 工位组合下发 | 工位组合下发 | 把工艺下发到 PLC,查看下发日志 | +| M7 | 拧紧查询 | 拧紧查询 | 查询拧紧记录、按组统计、审计修改 | +| M8 | 工艺流程 | 工艺流程 | 维护产品型号的工艺流程与工序步骤、上传工艺文件 | +| M9 | 关联工位 | 关联工位 | 维护工位、配置工位与工序的派工关系 | +| M10 | 绩效报表 | 绩效报表 | 按人/按工位/明细三口径统计工作量并导出 | +| M11 | 巡检终端 | 巡检终端 | 登记巡检记录、上传照片、一键生成工序间检验记录 | +| M12 | 质量检验 | 质量检验 | 查 BOM 物料、登记检验处置、生成不合格单 | +| M13 | 在制品 | 在制品 | 查看线上在制工件 | +| M14 | 手动报工 | 手动报工 | 工件上线、工序报工、完工 | +| M15 | 工件追溯 | 工件追溯 | 按工件追溯全流程、面板绑定/解绑 | +| M16 | 生产流程卡 | 生产流程卡 | 打印工单流程卡、查看型号全景流程卡 | +| M17 | 物料档案 | 物料档案 | 维护产品型号/物料档案 | +| M18 | 预警中心 | 预警中心 | 配置预警规则、查看预警、标记已读、应急呼叫 | +| M19 | 附件中心 | 附件中心 | 查看/下载/归档/删除附件 | +| M20 | 操作日志 | 操作日志 | 查询操作留痕 | +| M21 | 账号管理 | 账号管理 | 增删改查账号、分配角色 | +| M22 | 角色管理 | 角色管理 | 增删改查角色与权限 | +| M23 | 修改密码 | 修改密码 | 当前用户修改密码 | + +## 三、工位终端(产线现场触摸屏) + +| 编号 | 场景名 | 入口 | 干什么事 | +|---|---|---|---| +| S1 | 工位登录/登出 | 主界面 | 工位操作员登录、登出 | +| S2 | 当前任务 | 主界面 | 显示本工位当前应生产的任务 | +| S3 | 工件上线 | 上线面板 | 扫码工件上线建档 | +| S4 | 报工/拧紧 | 工作面板 | 按工序采集数据、记录拧紧、工序完工报工、暂存 | +| S5 | 工件下线/完工 | 下线面板 | 工件末道完工下线 | +| S6 | 面板绑定 | 工作面板 | 工件与面板绑定/解绑 | +| S7 | 移料/叫料 | 移动面板 | 产线点位移料、叫料、占用点位 | +| S8 | 领料 | 物料面板 | 查看备料单、确认接料 | +| S9 | 巡检 | 巡检面板 | 现场提交巡检、上传照片 | +| S10 | 数量不符上报 | 物料面板 | 上报物料数量不符 | +| S11 | 退料 | 物料面板 | 工位退回物料,生成 WMS 退库单 | +| S12 | 应急呼叫 | 主界面 | 现场发起应急呼叫 | +| S13 | 工艺文件查看 | 主界面 | 查看工序对应的工艺文件(PDF) | +| S14 | 工作量查询 | 主界面 | 查看本工位工作量 | +| S15 | 离线同步 | 主界面 | 断网时本地暂存、恢复后回传,查看同步状态 | + +--- + +> 场景清单完毕。以下进入第二步:写三份文档(业务流程 / 案例 / 回归测试)。 + + +# 文档1:业务流程 + +> 顶层地图。一个节点一句话,括号内指向「文档2:案例」的场景编号。 + +## 主链路(从合同到成品入库) + +1. 建产品型号与 BOM,定义一台产品由哪些物料、多少数量构成(M17、M3)。 +2. 维护工艺流程与工位派工,定义型号要过哪些工序、每道工序在哪个工位干(M8、M9)。 +3. 按合同建工单,一个合同对应一个工单,定下产品型号与数量(M1)。 +4. 对工单做日排产,把工单排到具体生产日并推荐接驳台(M2)。 +5. 按排产生成备料单,算出每个工位、每道工序需要哪些物料、多少量(M4)。 +6. WMS 备料出库,按备料单从库存扣料、装箱、指定目标工位,台账记「已发出」(W5)。 +7. AGV 把料从库房搬到接驳台(W15)。 +8. 工位扫码接料,备料单记「已接料」,在途量清零(S8)。 +9. 工件上线建档,一件产品进入产线(S3、M14)。 +10. 逐道工序报工,采集过程数据、记录拧紧、推进工件工序状态(S4、M14)。 +11. 过程巡检与质检,记录工序间检验结论(S9、M11、M12)。 +12. 末道完工下线,成品经内部接口自动回流 WMS 入库为成品,并按整份 BOM 反冲核销台账「已消耗」(S5)。 +13. 工件追溯与绩效统计,回看全流程、按人/工位汇总工作量(M15、M10)。 + +## 异常链路 + +- 来料不合格:来料检验判不合格后做退货/让步处置(W9)。 +- 数量不符:工位上报物料数量不符(S10)→ MES 处理并生成补发备料单(M5、M4)。 +- 退料:工位退回物料(S11)→ WMS 退库确认收货、库存加回、台账记「已退回」(W7)。 +- 入库作废:入库单填原因作废,库存按批次/序列号回滚(W4)。 +- 质检不合格:质量检验判不合格并生成不合格单(M12)。 +- 盘点差异:盘点扫码录入实盘,完成时写回盘盈盘亏(W12)。 +- 拧紧超差:拧紧记录超差被审计修改并留痕(M7)。 +- 应急呼叫:工位现场发起应急呼叫,进预警中心(S12、M18)。 +- 断网离线:工位断网本地暂存,恢复后回传(S15)。 + +## 支撑域(不在主链路上,但全局依赖) + +- 主数据:区域库位四级结构(W16)、物料档案(W17/M17)、接驳台(W18)。 +- 库存查询与台账:库存三口径查询(W8)、工单备料四段量台账(W14)。 +- 权限与留痕:账号(W19/M21)、角色(W20/M22)、操作日志(W21/M20)、修改密码(W23/M23)。 +- 附件与展示:附件中心(W22/M19)、库存大屏(W24)、生产流程卡(M16)、在制品看板(M13)、预警中心(M18)。 +- 下发:工位组合下发到 PLC(M6)。 + + +# 文档2:案例 + +> 每个场景独立成章,从头到尾只一条路径。数据变化写到表/字段/值。本批为生产主链路(工单→排产→派工→备料→接料→上线→报工→完工→追溯)。 + +## 场景 M1:建工单 +### 前置条件 +- 已存在产品型号(物料档案 M17),型号编码记为 CP001。 +### 操作步骤 +- 计划员登录 MES,进「工单管理」,点「新增工单」,填:工单号 WO20260920、产品型号 CP001、数量 10、合同编号 HT001、工程编号 GC001、产品序号 01、完成日期 2026-09-30,点「保存」。 +### 系统反应 +- 工单创建成功,状态为「已创建」,完成数量 0、NG 数量 0,创建人记为当前登录用户。 +### 数据变化 +- work_order 表新增一行:workOrderNo=WO20260920、productCode=CP001、quantity=10、finishedNum=0、failNum=0、contractNo=HT001、projectNo=GC001、productSerial=01、status=CREATED。 +### 验证点 +- 工单管理列表出现 WO20260920,状态「已创建」,数量 10,完成 0。 +- 数据库断言:work_order 中 workOrderNo=WO20260920 的行 status='CREATED' 且 quantity=10。 +### 对不上的地方 +- 无,链路打通。 + +## 场景 M2:日排产 +### 前置条件 +- 工单 WO20260920 存在(M1)。 +### 操作步骤 +- 计划员在 MES「日排产」,选工单 WO20260920、排产日期 2026-09-20、计划数量 10,点「保存」。 +### 系统反应 +- 生成当日排产计划,状态「待生产」,系统给出推荐接驳台。 +### 数据变化 +- daily_plan 表新增一行:orderNo=WO20260920、planDate=2026-09-20、planQty=10、completedQty=0、status=PENDING。 +### 验证点 +- 日排产列表出现 2026-09-20 / WO20260920 / 计划 10。 +- 数据库断言:daily_plan 中 (planDate=2026-09-20, orderNo=WO20260920) 唯一一行,planQty=10。 +### 对不上的地方 +- 无。 + +## 场景 M9:工位派工 +### 前置条件 +- 型号 CP001 的工艺流程含工序 1、工序 2(M8);工位 1、工位 2 已维护(M9 关联工位)。 +### 操作步骤 +- 工艺员在 MES「关联工位」,选生效日期 2026-09-20,把工位 1 派给工序 1、工位 2 派给工序 2,点「保存」。 +### 系统反应 +- 当日派工生效,同工位同天同班次覆盖式写入。 +### 数据变化 +- station_process 写入行:(stationNo=1, processCode=1, effectDate=2026-09-20)、(stationNo=2, processCode=2, effectDate=2026-09-20)。 +### 验证点 +- 数据库断言:station_process 中 effectDate=2026-09-20 存在工位1→工序1、工位2→工序2;(stationNo,effectDate,shift) 唯一。 +### 对不上的地方 +- 无。 + +## 场景 M4:生成备料单并自动出库 +### 前置条件 +- 工单 WO20260920 已排产到 2026-09-20(M2);今日已配工位派工(M9)。 +- 型号 CP001 已配 BOM(M3):物料 M-A(结构件、单台用量 2、损耗率 0、装配工序 1)、物料 M-B(电气件、单台用量 4、装配工序 2)。 +- WMS 物料档案存在 M-A、M-B(W17);WMS 有 M-A、M-B 的合格在库库存。 +### 操作步骤 +- 计划员在 MES「备料单」,选排产日期 2026-09-20,点「生成备料单」。 +### 系统反应 +- 系统把 BOM 展开到叶子,按工位拆料:工位 1 需 M-A = 10×2 = 20,工位 2 需 M-B = 10×4 = 40。 +- 生成前校验 M-A、M-B 在 WMS 物料档案存在(缺失则不生成并回缺料清单)。 +- 生成后把工单需求总量同步到 WMS 台账:M-A total_qty=20、M-B total_qty=40。 +- 随即自动出库:按 FIFO 从合格在库库存扣料,补足未发数量;缺料则记「备料未齐套」预警。 +### 数据变化 +- material_request 新增行:(orderNo=WO20260920, planDate=2026-09-20, materialCode=M-A, stationNo=1, processCode=1, reqQty=20, sentQty=20, status=LOCKED);M-B 同理 reqQty=40、stationNo=2、sentQty=40。 +- WMS order_material_ledger:M-A total_qty=20、out_qty=20;M-B total_qty=40、out_qty=40。 +- WMS outbound_order:新增出库单 outbound_type=workorder、status=已出库、order_no=WO20260920;outbound_detail 记批次/SN 与数量。 +- WMS inventory:M-A 对应批次 quantity 减 20;M-B 对应 40 个 SN status 由「在库」→「出库」。 +### 验证点 +- 备料单列表出现 M-A(工位1,需20)、M-B(工位2,需40),已发出=需求。 +- 数量等式:material_request.sentQty ≤ reqQty;台账 net_out = out_qty − returned_qty ≤ total_qty;库存可用 = quantity − locked_qty ≥ 0。 +- WMS 工单备料台账(W14)显示 M-A 已发出 20 / 需求 20。 +### 对不上的地方 +- 无。 + +## 场景 S8:工位扫码接料 +### 前置条件 +- 备料单 M-A(工位1) 已发出 sentQty=20(M4),料已送到工位。 +### 操作步骤 +- 工位 1 操作员在工位终端「物料面板」,扫备料单/物料码,点「接料」。 +### 系统反应 +- 系统登记已接料,接料量不超过已发出量;接满且已发齐需求时备料单完结。 +### 数据变化 +- material_request(M-A,工位1):receivedQty 0→20、receivedAt=当前时间、receiveBy=操作员、status LOCKED→DONE。 +### 验证点 +- 备料单状态「已完成」,已接料 20。 +- 数量等式:在途 = sentQty − receivedQty = 0;receivedQty ≤ sentQty。 +### 对不上的地方 +- 无。 + +## 场景 S3:工件上线 +### 前置条件 +- 工单 WO20260920 存在。 +### 操作步骤 +- 上线位操作员在工位终端「上线面板」,扫工件 SN0001、选工单 WO20260920,点「上线」。 +### 系统反应 +- 工件建档进线,状态「已进线」,记进线时间。 +### 数据变化 +- workpiece 新增行:sn=SN0001、orderNo=WO20260920、workOrderId=工单ID、status=ONLINE、currentProcess=0、onlineAt=当前时间。 +### 验证点 +- 在制品(M13)出现 SN0001,状态在制,当前工位=上线位。 +- 数据库断言:workpiece sn=SN0001 status='ONLINE' currentProcess=0。 +### 对不上的地方 +- 无。 + +## 场景 S4:工序报工 +### 前置条件 +- 工件 SN0001 已上线(S3),currentProcess=0。 +- 工位 1 今日派工为工序 1(M9)并绑定工艺流程;本工序 BOM 物料 M-A 已在工位接料(S8)。 +### 操作步骤 +- 工位 1 操作员在「工作面板」,上料时系统记开始时间,装配后录入各步骤实测值、勾选需检测确认的步骤、绑定本工序装配物料(M-A 批次号),点「报工」。 +### 系统反应 +- 系统强校验:工件在制、本工位是下一道工序(工序号=已完成工序+1)、装配物料齐套、需检测确认的步骤已勾选。 +- 校验通过后写报工实绩与步骤考核,按考核标准判定 OK/NG,推进工件工序状态。 +### 数据变化 +- workpiece_process 新增行:sn=SN0001、processCode=1、stationNo=1、status=DONE、result=OK(全部步骤合格)或 NG、operator、startedAt/endedAt/durationSec。 +- step_data 新增各步骤实测行:value、is_ok 按考核标准判定。 +- workpiece_bind:本工序绑定的 M-A 批次落库。 +- workpiece(SN0001):currentProcess 0→1,status ONLINE→PROCESSING。 +### 验证点 +- 报工记录(M14)出现 SN0001 工序1 记录,结果 OK。 +- 数量等式:workpiece.currentProcess = 已报工工序数;durationSec = endedAt − startedAt(≥0)。 +- 数据库断言:workpiece_process(sn=SN0001,processCode=1) 存在且 status='DONE'。 +### 对不上的地方 +- 无。(跳站/漏站/工件非在制/物料未绑齐/需检测步骤未勾选时,报工被拒——属前置校验,非链路断裂。) + +## 场景 S5:完工下线并成品回流入库 +### 前置条件 +- 工件 SN0001 已报完全部工序(S4),当前工序=末道工序;全部工序装配物料已绑齐。 +### 操作步骤 +- 下线位操作员在「下线面板」,扫工件 SN0001,录入结构件批次清单/电气件 SN 清单,点「完工」。 +### 系统反应 +- 系统兜底校验全部工序物料齐套,登记完工,生成成品关联追溯。 +- 成品经内部接口自动回流 WMS,入库为成品;并按整份 BOM 反冲核销工单台账「已消耗」。 +- 工单完成数量 +1,日排产完成数量 +1。 +### 数据变化 +- workpiece(SN0001):status PROCESSING→DONE,doneAt=当前时间。 +- association_trace 新增/更新:finishedSn=SN0001、orderNo=WO20260920、batchItems=[结构件批次]、serialItems=[电气件SN]、operator。 +- work_order(WO20260920):finishedNum +1;daily_plan:completedQty +1。 +- WMS inventory:新增成品行 category=3、material_code=CP001、sn_code=SN0001、manage_mode=2、quantity=1、order_no=WO20260920、status=在库。 +- WMS order_material_ledger:M-A、M-B 的 consumed_qty 按整份 BOM 单件消耗累加(核销上限=net_out−已消耗)。 +### 验证点 +- 在制品不再显示 SN0001;工件追溯(M15)可查到全流程。 +- WMS 库存查询(W8)成品口径出现 CP001/SN0001。 +- 数量等式:consumed_qty ≤ net_out_qty = out_qty − returned_qty;工单 finishedNum ≤ quantity。 +### 对不上的地方 +- 反冲只核销台账 consumed_qty,不扣库存、不生成出库单(WMS 实际行为);但 MES 侧完工反冲的实现注释写「生成 backflush 出库单」,与 WMS 实际行为对不上。业务链路本身打通(库存已在备料出库时扣过,不重复扣),仅注释误导。 + +## 场景 M15:工件追溯 +### 前置条件 +- 工件 SN0001 已完工(S5)。 +### 操作步骤 +- 质量员在 MES「工件追溯」,输入 SN0001,点「查询」。 +### 系统反应 +- 系统按 SN 汇总工序时间线、操作人、步骤数据、装配物料批次/SN、拧紧数据、成品关联追溯。 +### 数据变化 +- 只读,无写入。 +### 验证点 +- 页面显示 SN0001 全部工序记录、绑定的结构件批次与电气件 SN、拧紧记录。 +- 数据库断言:association_trace finishedSn=SN0001 的 batchItems/serialItems 与页面一致。 +### 对不上的地方 +- 无。 + + +# 文档3:回归测试 + +> 可断言用例,按场景分组。断言为具体数值/状态/条数。MES 接口前缀 /api/v1(需 JWT);WMS 接口前缀 /api(需 JWT);内部接口带 X-API-TOKEN。 +> 公共前置:用管理员账号 POST /api/v1/login 取 token,后续 MES 请求带 Authorization: Bearer ;WMS 同理 POST /api/auth/login。 + +## 测试场景 M1:建工单 +### 前置数据准备(SQL) +- 确保产品型号存在:INSERT INTO product_type(code,name) VALUES('CP001','测试产品') ON CONFLICT DO NOTHING;(取回其 id 记为 :ptId) +### 执行步骤(API) +- POST /api/v1/work-orders,body:{"workOrderNo":"WO20260920","productTypeId":,"productCode":"CP001","productName":"测试产品","quantity":10,"contractNo":"HT001","projectNo":"GC001","productSerial":"01","dueDate":"2026-09-30T00:00:00Z"} +### 预期结果 +- work_order:workOrderNo='WO20260920' 新增一行,status='CREATED'、quantity=10、finishedNum=0、failNum=0、contractNo='HT001'。 +### 数量等式断言 +- SELECT count(*) FROM work_order WHERE workOrderNo='WO20260920' → 1;finishedNum=0 且 finishedNum ≤ quantity。 +### 清理步骤 +- DELETE FROM work_order WHERE workOrderNo='WO20260920'; + +## 测试场景 M2:日排产 +### 前置数据准备 +- 工单 WO20260920 存在(M1)。 +### 执行步骤(API) +- POST /api/v1/daily-plans,body:{"orderNo":"WO20260920","planDate":"2026-09-20","planQty":10} +### 预期结果 +- daily_plan:(orderNo='WO20260920',planDate='2026-09-20') 新增一行,planQty=10、completedQty=0、status='PENDING'。 +### 数量等式断言 +- SELECT count(*) FROM daily_plan WHERE orderNo='WO20260920' AND planDate='2026-09-20' → 1(planDate+orderNo 唯一)。 +### 清理步骤 +- DELETE FROM daily_plan WHERE orderNo='WO20260920' AND planDate='2026-09-20'; + +## 测试场景 M9:工位派工 +### 前置数据准备 +- 工位 1、2 存在(station 表)。 +### 执行步骤(API) +- POST /api/v1/station-process/save,body:{"effectDate":"2026-09-20","items":[{"stationNo":1,"processCode":1},{"stationNo":2,"processCode":2}]} +### 预期结果 +- station_process:effectDate='2026-09-20' 存在 (stationNo=1,processCode=1) 与 (stationNo=2,processCode=2)。 +### 数量等式断言 +- SELECT count(*) FROM station_process WHERE effectDate='2026-09-20' AND stationNo IN(1,2) → 2;(stationNo,effectDate,shift) 无重复。 +### 清理步骤 +- DELETE FROM station_process WHERE effectDate='2026-09-20'; + +## 测试场景 M4:生成备料单并自动出库 +### 前置数据准备(SQL/API) +- BOM(MES work_order_bom):INSERT 两行:(productCode='CP001',bomName='默认',materialCode='M-A',manageMode='1',processCode=1,unitQty=2,lossRate=0)、(productCode='CP001',bomName='默认',materialCode='M-B',manageMode='2',processCode=2,unitQty=4,lossRate=0)。 +- WMS 物料档案:POST /api/material/create 建 M-A(结构件)、M-B(电气件)。 +- WMS 合格在库库存: + - INSERT INTO inventories(manage_mode,category,material_code,batch_no,quantity,locked_qty,quality_status,status) VALUES(1,1,'M-A','B001',100,0,'合格','在库'); + - 电气件 M-B 插 40 行 SN:INSERT INTO inventories(manage_mode,category,material_code,sn_code,quantity,locked_qty,quality_status,status) VALUES(2,1,'M-B','SNB0001',1,0,'合格','在库'); … 至 'SNB0040'。 +- 已存在 M1/M2/M9 的前置数据。 +### 执行步骤(API) +- POST /api/v1/material-requests/generate,body:{"planDate":"2026-09-20"} +### 预期结果 +- material_request:新增 (orderNo='WO20260920',materialCode='M-A',stationNo=1,processCode=1,reqQty=20,sentQty=20,status='LOCKED') 与 (materialCode='M-B',stationNo=2,reqQty=40,sentQty=40,status='LOCKED')。 +- WMS order_material_ledger:(WO20260920,'M-A') total_qty=20、out_qty=20;(WO20260920,'M-B') total_qty=40、out_qty=40。 +- WMS outbound_order:新增 outbound_type='workorder'、status='已出库'、order_no='WO20260920' 的出库单。 +- WMS inventories:M-A 批次 B001 quantity 100→80;M-B 的 40 个 SN status '在库'→'出库'。 +### 数量等式断言 +- material_request.sentQty ≤ reqQty(M-A:20≤20,M-B:40≤40)。 +- ledger net_out = out_qty − returned_qty ≤ total_qty(20≤20,40≤40)。 +- SELECT quantity FROM inventories WHERE batch_no='B001' → 80;SELECT count(*) FROM inventories WHERE material_code='M-B' AND status='出库' → 40。 +### 清理步骤 +- DELETE FROM material_request WHERE orderNo='WO20260920'; +- WMS:DELETE FROM outbound_detail WHERE order_no='WO20260920'; DELETE FROM outbound_order WHERE order_no='WO20260920'; DELETE FROM order_material_ledger WHERE order_no='WO20260920'; +- 回滚库存:UPDATE inventories SET quantity=100 WHERE batch_no='B001'; UPDATE inventories SET status='在库' WHERE material_code='M-B'; + +## 测试场景 S8:工位接料 +### 前置数据准备 +- 备料单 M-A(工位1) sentQty=20、status='LOCKED'(M4)。 +### 执行步骤(API) +- POST /api/v1/material-requests/receive,body:{"requestNo":"","qty":0}(qty=0 表示接本批全部剩余) +### 预期结果 +- material_request(M-A):receivedQty=20、status='DONE'、receiveBy 非空、receivedAt>0。 +### 数量等式断言 +- 在途 = sentQty − receivedQty = 0;receivedQty ≤ sentQty(20≤20)。 +### 清理步骤 +- 随 M4 清理一并删除 material_request。 + +## 测试场景 S3:工件上线 +### 前置数据准备 +- 工单 WO20260920 存在。 +### 执行步骤(API) +- POST /api/v1/workpiece/online,body:{"sn":"SN0001","orderNo":"WO20260920"} +### 预期结果 +- workpiece:sn='SN0001' 新增一行,status='ONLINE'、currentProcess=0、onlineAt 非空。 +### 数量等式断言 +- SELECT count(*) FROM workpiece WHERE sn='SN0001' → 1;sn 全局唯一。 +### 清理步骤 +- DELETE FROM workpiece WHERE sn='SN0001'; + +## 测试场景 S4:工序报工 +### 前置数据准备 +- 工件 SN0001 已上线(S3),currentProcess=0。 +- 工位 1 已绑定工艺流程(station.flowId>0),流程含工序 1 的步骤与考核标准;BOM 中 M-A processCode=1。 +### 执行步骤(API) +- POST /api/v1/workpiece/process/report,body:{"sn":"SN0001","processCode":1,"stationNo":1,"binds":[{"materialCode":"M-A","batchNo":"B001"}],"steps":[{"stepId":<步骤id>,"name":"步骤1","value":10,"checked":true}],"startedAt":"2026-09-20T09:00:00Z","endedAt":"2026-09-20T09:05:00Z"} +### 预期结果 +- workpiece_process:(sn='SN0001',processCode=1) 新增一行,status='DONE'、result='OK'(步骤均合格)、durationSec=300。 +- step_data:对应步骤行 is_ok=true。 +- workpiece(SN0001):currentProcess=1、status='PROCESSING'。 +### 数量等式断言 +- workpiece.currentProcess = SELECT count(*) FROM workpiece_process WHERE sn='SN0001' AND status='DONE' → 1。 +- durationSec = endedAt−startedAt = 300(≥0)。 +- 负用例:再次以 processCode=1 报工 → 拒绝(工序顺序不符,应报工序 2);以 processCode=3 报工 → 拒绝。 +### 清理步骤 +- DELETE FROM step_data WHERE sn='SN0001'; DELETE FROM workpiece_process WHERE sn='SN0001'; DELETE FROM workpiece_bind WHERE sn='SN0001'; + +## 测试场景 S5:完工下线并成品回流 +### 前置数据准备 +- 工件 SN0001 已报完全部工序(本例工序总数=2,先完成工序 2 报工),全部工序物料已绑齐。 +### 执行步骤(API) +- POST /api/v1/workpiece/done,body:{"sn":"SN0001","batchItems":["B001"],"serialItems":["SNB0001"]} +### 预期结果 +- workpiece(SN0001):status='DONE'、doneAt 非空。 +- association_trace:finishedSn='SN0001' 新增/更新,batchItems=['B001']、serialItems=['SNB0001']。 +- work_order(WO20260920):finishedNum 由 0→1;daily_plan(2026-09-20):completedQty 由 0→1。 +- WMS inventories:新增成品行 category=3、material_code='CP001'、sn_code='SN0001'、quantity=1、status='在库'、order_no='WO20260920'。 +- WMS order_material_ledger:M-A consumed_qty=2(单台用量2×完工1件)、M-B consumed_qty=4。 +### 数量等式断言 +- work_order.finishedNum=1 且 ≤ quantity(10)。 +- ledger consumed_qty ≤ net_out_qty(M-A:2≤20,M-B:4≤40)。 +- SELECT count(*) FROM inventories WHERE sn_code='SN0001' AND category=3 → 1。 +### 清理步骤 +- DELETE FROM association_trace WHERE finishedSn='SN0001'; +- WMS:DELETE FROM inventories WHERE sn_code='SN0001' AND category=3; UPDATE order_material_ledger SET consumed_qty=0 WHERE order_no='WO20260920'; + +## 测试场景 M15:工件追溯 +### 前置数据准备 +- 工件 SN0001 已完工(S5)。 +### 执行步骤(API) +- GET /api/v1/trace?sn=SN0001 +### 预期结果 +- 返回体含 workpiece、processTimeline(工序记录条数=已报工工序数)、associationTrace(batchItems/serialItems)、torqueRecords。 +### 数量等式断言 +- processTimeline 条数 = SELECT count(*) FROM workpiece_process WHERE sn='SN0001'。 +- associationTrace.finishedSn='SN0001' 与入参一致。 +### 清理步骤 +- 无写入,无需清理。 + + + + + + + + + + + + + + +