diff --git a/bj_power_mes/common/token/token.go b/bj_power_mes/common/token/token.go index 1fa1b68..a0bb214 100644 --- a/bj_power_mes/common/token/token.go +++ b/bj_power_mes/common/token/token.go @@ -10,12 +10,13 @@ import ( // Claims JWT 自定义负载 type Claims struct { - UserId int `json:"userId"` - Username string `json:"username"` - Name string `json:"name"` - RoleId int `json:"roleId"` - RoleCode string `json:"roleCode"` - RoleName string `json:"roleName"` + UserId int `json:"userId"` + Username string `json:"username"` + Name string `json:"name"` + RoleId int `json:"roleId"` + RoleCode string `json:"roleCode"` + RoleName string `json:"roleName"` + StationNo int `json:"stationNo,omitempty"` // 工位终端登录时的工位号 jwt.RegisteredClaims } diff --git a/bj_power_mes/ent/client.go b/bj_power_mes/ent/client.go index fd01861..cdaa1a3 100644 --- a/bj_power_mes/ent/client.go +++ b/bj_power_mes/ent/client.go @@ -15,19 +15,23 @@ import ( "bj_power_mes/ent/bomitem" "bj_power_mes/ent/dailyplan" "bj_power_mes/ent/eventlog" + "bj_power_mes/ent/inspectionrecord" "bj_power_mes/ent/materialrequest" "bj_power_mes/ent/permission" "bj_power_mes/ent/plcsendlog" + "bj_power_mes/ent/processflow" "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" "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" + "bj_power_mes/ent/userstation" "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpieceprocess" @@ -52,12 +56,16 @@ type Client struct { DailyPlan *DailyPlanClient // EventLog is the client for interacting with the EventLog builders. EventLog *EventLogClient + // InspectionRecord is the client for interacting with the InspectionRecord builders. + InspectionRecord *InspectionRecordClient // MaterialRequest is the client for interacting with the MaterialRequest builders. MaterialRequest *MaterialRequestClient // Permission is the client for interacting with the Permission builders. Permission *PermissionClient // PlcSendLog is the client for interacting with the PlcSendLog builders. PlcSendLog *PlcSendLogClient + // ProcessFlow is the client for interacting with the ProcessFlow builders. + ProcessFlow *ProcessFlowClient // ProcessStep is the client for interacting with the ProcessStep builders. ProcessStep *ProcessStepClient // ProductType is the client for interacting with the ProductType builders. @@ -68,6 +76,8 @@ type Client struct { ScanRecord *ScanRecordClient // SemiFlow is the client for interacting with the SemiFlow builders. SemiFlow *SemiFlowClient + // Station is the client for interacting with the Station builders. + Station *StationClient // StationProcess is the client for interacting with the StationProcess builders. StationProcess *StationProcessClient // StepCriterion is the client for interacting with the StepCriterion builders. @@ -78,6 +88,8 @@ type Client struct { TorqueRecord *TorqueRecordClient // User is the client for interacting with the User builders. User *UserClient + // UserStation is the client for interacting with the UserStation builders. + UserStation *UserStationClient // WorkOrder is the client for interacting with the WorkOrder builders. WorkOrder *WorkOrderClient // Workpiece is the client for interacting with the Workpiece builders. @@ -99,19 +111,23 @@ func (c *Client) init() { c.BomItem = NewBomItemClient(c.config) c.DailyPlan = NewDailyPlanClient(c.config) c.EventLog = NewEventLogClient(c.config) + c.InspectionRecord = NewInspectionRecordClient(c.config) c.MaterialRequest = NewMaterialRequestClient(c.config) c.Permission = NewPermissionClient(c.config) c.PlcSendLog = NewPlcSendLogClient(c.config) + c.ProcessFlow = NewProcessFlowClient(c.config) 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) c.StepCriterion = NewStepCriterionClient(c.config) c.StepData = NewStepDataClient(c.config) c.TorqueRecord = NewTorqueRecordClient(c.config) c.User = NewUserClient(c.config) + c.UserStation = NewUserStationClient(c.config) c.WorkOrder = NewWorkOrderClient(c.config) c.Workpiece = NewWorkpieceClient(c.config) c.WorkpieceProcess = NewWorkpieceProcessClient(c.config) @@ -211,19 +227,23 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { BomItem: NewBomItemClient(cfg), DailyPlan: NewDailyPlanClient(cfg), EventLog: NewEventLogClient(cfg), + InspectionRecord: NewInspectionRecordClient(cfg), MaterialRequest: NewMaterialRequestClient(cfg), Permission: NewPermissionClient(cfg), PlcSendLog: NewPlcSendLogClient(cfg), + ProcessFlow: NewProcessFlowClient(cfg), ProcessStep: NewProcessStepClient(cfg), ProductType: NewProductTypeClient(cfg), Role: NewRoleClient(cfg), ScanRecord: NewScanRecordClient(cfg), SemiFlow: NewSemiFlowClient(cfg), + Station: NewStationClient(cfg), StationProcess: NewStationProcessClient(cfg), StepCriterion: NewStepCriterionClient(cfg), StepData: NewStepDataClient(cfg), TorqueRecord: NewTorqueRecordClient(cfg), User: NewUserClient(cfg), + UserStation: NewUserStationClient(cfg), WorkOrder: NewWorkOrderClient(cfg), Workpiece: NewWorkpieceClient(cfg), WorkpieceProcess: NewWorkpieceProcessClient(cfg), @@ -250,19 +270,23 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) BomItem: NewBomItemClient(cfg), DailyPlan: NewDailyPlanClient(cfg), EventLog: NewEventLogClient(cfg), + InspectionRecord: NewInspectionRecordClient(cfg), MaterialRequest: NewMaterialRequestClient(cfg), Permission: NewPermissionClient(cfg), PlcSendLog: NewPlcSendLogClient(cfg), + ProcessFlow: NewProcessFlowClient(cfg), ProcessStep: NewProcessStepClient(cfg), ProductType: NewProductTypeClient(cfg), Role: NewRoleClient(cfg), ScanRecord: NewScanRecordClient(cfg), SemiFlow: NewSemiFlowClient(cfg), + Station: NewStationClient(cfg), StationProcess: NewStationProcessClient(cfg), StepCriterion: NewStepCriterionClient(cfg), StepData: NewStepDataClient(cfg), TorqueRecord: NewTorqueRecordClient(cfg), User: NewUserClient(cfg), + UserStation: NewUserStationClient(cfg), WorkOrder: NewWorkOrderClient(cfg), Workpiece: NewWorkpieceClient(cfg), WorkpieceProcess: NewWorkpieceProcessClient(cfg), @@ -295,10 +319,11 @@ func (c *Client) Close() error { // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ - c.AssociationTrace, c.BomItem, c.DailyPlan, c.EventLog, c.MaterialRequest, - c.Permission, c.PlcSendLog, c.ProcessStep, c.ProductType, c.Role, c.ScanRecord, - c.SemiFlow, c.StationProcess, c.StepCriterion, c.StepData, c.TorqueRecord, - c.User, c.WorkOrder, c.Workpiece, c.WorkpieceProcess, + c.AssociationTrace, c.BomItem, c.DailyPlan, c.EventLog, c.InspectionRecord, + c.MaterialRequest, c.Permission, c.PlcSendLog, c.ProcessFlow, c.ProcessStep, + c.ProductType, c.Role, c.ScanRecord, c.SemiFlow, c.Station, c.StationProcess, + c.StepCriterion, c.StepData, c.TorqueRecord, c.User, c.UserStation, + c.WorkOrder, c.Workpiece, c.WorkpieceProcess, } { n.Use(hooks...) } @@ -308,10 +333,11 @@ func (c *Client) Use(hooks ...Hook) { // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ - c.AssociationTrace, c.BomItem, c.DailyPlan, c.EventLog, c.MaterialRequest, - c.Permission, c.PlcSendLog, c.ProcessStep, c.ProductType, c.Role, c.ScanRecord, - c.SemiFlow, c.StationProcess, c.StepCriterion, c.StepData, c.TorqueRecord, - c.User, c.WorkOrder, c.Workpiece, c.WorkpieceProcess, + c.AssociationTrace, c.BomItem, c.DailyPlan, c.EventLog, c.InspectionRecord, + c.MaterialRequest, c.Permission, c.PlcSendLog, c.ProcessFlow, c.ProcessStep, + c.ProductType, c.Role, c.ScanRecord, c.SemiFlow, c.Station, c.StationProcess, + c.StepCriterion, c.StepData, c.TorqueRecord, c.User, c.UserStation, + c.WorkOrder, c.Workpiece, c.WorkpieceProcess, } { n.Intercept(interceptors...) } @@ -328,12 +354,16 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.DailyPlan.mutate(ctx, m) case *EventLogMutation: return c.EventLog.mutate(ctx, m) + case *InspectionRecordMutation: + return c.InspectionRecord.mutate(ctx, m) case *MaterialRequestMutation: return c.MaterialRequest.mutate(ctx, m) case *PermissionMutation: return c.Permission.mutate(ctx, m) case *PlcSendLogMutation: return c.PlcSendLog.mutate(ctx, m) + case *ProcessFlowMutation: + return c.ProcessFlow.mutate(ctx, m) case *ProcessStepMutation: return c.ProcessStep.mutate(ctx, m) case *ProductTypeMutation: @@ -344,6 +374,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.ScanRecord.mutate(ctx, m) case *SemiFlowMutation: return c.SemiFlow.mutate(ctx, m) + case *StationMutation: + return c.Station.mutate(ctx, m) case *StationProcessMutation: return c.StationProcess.mutate(ctx, m) case *StepCriterionMutation: @@ -354,6 +386,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.TorqueRecord.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) + case *UserStationMutation: + return c.UserStation.mutate(ctx, m) case *WorkOrderMutation: return c.WorkOrder.mutate(ctx, m) case *WorkpieceMutation: @@ -897,6 +931,139 @@ func (c *EventLogClient) mutate(ctx context.Context, m *EventLogMutation) (Value } } +// InspectionRecordClient is a client for the InspectionRecord schema. +type InspectionRecordClient struct { + config +} + +// NewInspectionRecordClient returns a client for the InspectionRecord from the given config. +func NewInspectionRecordClient(c config) *InspectionRecordClient { + return &InspectionRecordClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `inspectionrecord.Hooks(f(g(h())))`. +func (c *InspectionRecordClient) Use(hooks ...Hook) { + c.hooks.InspectionRecord = append(c.hooks.InspectionRecord, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `inspectionrecord.Intercept(f(g(h())))`. +func (c *InspectionRecordClient) Intercept(interceptors ...Interceptor) { + c.inters.InspectionRecord = append(c.inters.InspectionRecord, interceptors...) +} + +// Create returns a builder for creating a InspectionRecord entity. +func (c *InspectionRecordClient) Create() *InspectionRecordCreate { + mutation := newInspectionRecordMutation(c.config, OpCreate) + return &InspectionRecordCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of InspectionRecord entities. +func (c *InspectionRecordClient) CreateBulk(builders ...*InspectionRecordCreate) *InspectionRecordCreateBulk { + return &InspectionRecordCreateBulk{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 *InspectionRecordClient) MapCreateBulk(slice any, setFunc func(*InspectionRecordCreate, int)) *InspectionRecordCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &InspectionRecordCreateBulk{err: fmt.Errorf("calling to InspectionRecordClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*InspectionRecordCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &InspectionRecordCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for InspectionRecord. +func (c *InspectionRecordClient) Update() *InspectionRecordUpdate { + mutation := newInspectionRecordMutation(c.config, OpUpdate) + return &InspectionRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *InspectionRecordClient) UpdateOne(_m *InspectionRecord) *InspectionRecordUpdateOne { + mutation := newInspectionRecordMutation(c.config, OpUpdateOne, withInspectionRecord(_m)) + return &InspectionRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *InspectionRecordClient) UpdateOneID(id int) *InspectionRecordUpdateOne { + mutation := newInspectionRecordMutation(c.config, OpUpdateOne, withInspectionRecordID(id)) + return &InspectionRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for InspectionRecord. +func (c *InspectionRecordClient) Delete() *InspectionRecordDelete { + mutation := newInspectionRecordMutation(c.config, OpDelete) + return &InspectionRecordDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *InspectionRecordClient) DeleteOne(_m *InspectionRecord) *InspectionRecordDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *InspectionRecordClient) DeleteOneID(id int) *InspectionRecordDeleteOne { + builder := c.Delete().Where(inspectionrecord.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &InspectionRecordDeleteOne{builder} +} + +// Query returns a query builder for InspectionRecord. +func (c *InspectionRecordClient) Query() *InspectionRecordQuery { + return &InspectionRecordQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeInspectionRecord}, + inters: c.Interceptors(), + } +} + +// Get returns a InspectionRecord entity by its id. +func (c *InspectionRecordClient) Get(ctx context.Context, id int) (*InspectionRecord, error) { + return c.Query().Where(inspectionrecord.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *InspectionRecordClient) GetX(ctx context.Context, id int) *InspectionRecord { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *InspectionRecordClient) Hooks() []Hook { + return c.hooks.InspectionRecord +} + +// Interceptors returns the client interceptors. +func (c *InspectionRecordClient) Interceptors() []Interceptor { + return c.inters.InspectionRecord +} + +func (c *InspectionRecordClient) mutate(ctx context.Context, m *InspectionRecordMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&InspectionRecordCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&InspectionRecordUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&InspectionRecordUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&InspectionRecordDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown InspectionRecord mutation op: %q", m.Op()) + } +} + // MaterialRequestClient is a client for the MaterialRequest schema. type MaterialRequestClient struct { config @@ -1296,6 +1463,139 @@ func (c *PlcSendLogClient) mutate(ctx context.Context, m *PlcSendLogMutation) (V } } +// ProcessFlowClient is a client for the ProcessFlow schema. +type ProcessFlowClient struct { + config +} + +// NewProcessFlowClient returns a client for the ProcessFlow from the given config. +func NewProcessFlowClient(c config) *ProcessFlowClient { + return &ProcessFlowClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `processflow.Hooks(f(g(h())))`. +func (c *ProcessFlowClient) Use(hooks ...Hook) { + c.hooks.ProcessFlow = append(c.hooks.ProcessFlow, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `processflow.Intercept(f(g(h())))`. +func (c *ProcessFlowClient) Intercept(interceptors ...Interceptor) { + c.inters.ProcessFlow = append(c.inters.ProcessFlow, interceptors...) +} + +// Create returns a builder for creating a ProcessFlow entity. +func (c *ProcessFlowClient) Create() *ProcessFlowCreate { + mutation := newProcessFlowMutation(c.config, OpCreate) + return &ProcessFlowCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of ProcessFlow entities. +func (c *ProcessFlowClient) CreateBulk(builders ...*ProcessFlowCreate) *ProcessFlowCreateBulk { + return &ProcessFlowCreateBulk{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 *ProcessFlowClient) MapCreateBulk(slice any, setFunc func(*ProcessFlowCreate, int)) *ProcessFlowCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &ProcessFlowCreateBulk{err: fmt.Errorf("calling to ProcessFlowClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*ProcessFlowCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &ProcessFlowCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for ProcessFlow. +func (c *ProcessFlowClient) Update() *ProcessFlowUpdate { + mutation := newProcessFlowMutation(c.config, OpUpdate) + return &ProcessFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *ProcessFlowClient) UpdateOne(_m *ProcessFlow) *ProcessFlowUpdateOne { + mutation := newProcessFlowMutation(c.config, OpUpdateOne, withProcessFlow(_m)) + return &ProcessFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *ProcessFlowClient) UpdateOneID(id int) *ProcessFlowUpdateOne { + mutation := newProcessFlowMutation(c.config, OpUpdateOne, withProcessFlowID(id)) + return &ProcessFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for ProcessFlow. +func (c *ProcessFlowClient) Delete() *ProcessFlowDelete { + mutation := newProcessFlowMutation(c.config, OpDelete) + return &ProcessFlowDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *ProcessFlowClient) DeleteOne(_m *ProcessFlow) *ProcessFlowDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *ProcessFlowClient) DeleteOneID(id int) *ProcessFlowDeleteOne { + builder := c.Delete().Where(processflow.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &ProcessFlowDeleteOne{builder} +} + +// Query returns a query builder for ProcessFlow. +func (c *ProcessFlowClient) Query() *ProcessFlowQuery { + return &ProcessFlowQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeProcessFlow}, + inters: c.Interceptors(), + } +} + +// Get returns a ProcessFlow entity by its id. +func (c *ProcessFlowClient) Get(ctx context.Context, id int) (*ProcessFlow, error) { + return c.Query().Where(processflow.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *ProcessFlowClient) GetX(ctx context.Context, id int) *ProcessFlow { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *ProcessFlowClient) Hooks() []Hook { + return c.hooks.ProcessFlow +} + +// Interceptors returns the client interceptors. +func (c *ProcessFlowClient) Interceptors() []Interceptor { + return c.inters.ProcessFlow +} + +func (c *ProcessFlowClient) mutate(ctx context.Context, m *ProcessFlowMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ProcessFlowCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ProcessFlowUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ProcessFlowUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ProcessFlowDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown ProcessFlow mutation op: %q", m.Op()) + } +} + // ProcessStepClient is a client for the ProcessStep schema. type ProcessStepClient struct { config @@ -1961,6 +2261,139 @@ func (c *SemiFlowClient) mutate(ctx context.Context, m *SemiFlowMutation) (Value } } +// StationClient is a client for the Station schema. +type StationClient struct { + config +} + +// NewStationClient returns a client for the Station from the given config. +func NewStationClient(c config) *StationClient { + return &StationClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `station.Hooks(f(g(h())))`. +func (c *StationClient) Use(hooks ...Hook) { + c.hooks.Station = append(c.hooks.Station, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `station.Intercept(f(g(h())))`. +func (c *StationClient) Intercept(interceptors ...Interceptor) { + c.inters.Station = append(c.inters.Station, interceptors...) +} + +// Create returns a builder for creating a Station entity. +func (c *StationClient) Create() *StationCreate { + mutation := newStationMutation(c.config, OpCreate) + return &StationCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Station entities. +func (c *StationClient) CreateBulk(builders ...*StationCreate) *StationCreateBulk { + return &StationCreateBulk{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 *StationClient) MapCreateBulk(slice any, setFunc func(*StationCreate, int)) *StationCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &StationCreateBulk{err: fmt.Errorf("calling to StationClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*StationCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &StationCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Station. +func (c *StationClient) Update() *StationUpdate { + mutation := newStationMutation(c.config, OpUpdate) + return &StationUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *StationClient) UpdateOne(_m *Station) *StationUpdateOne { + mutation := newStationMutation(c.config, OpUpdateOne, withStation(_m)) + return &StationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *StationClient) UpdateOneID(id int) *StationUpdateOne { + mutation := newStationMutation(c.config, OpUpdateOne, withStationID(id)) + return &StationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Station. +func (c *StationClient) Delete() *StationDelete { + mutation := newStationMutation(c.config, OpDelete) + return &StationDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *StationClient) DeleteOne(_m *Station) *StationDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *StationClient) DeleteOneID(id int) *StationDeleteOne { + builder := c.Delete().Where(station.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &StationDeleteOne{builder} +} + +// Query returns a query builder for Station. +func (c *StationClient) Query() *StationQuery { + return &StationQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeStation}, + inters: c.Interceptors(), + } +} + +// Get returns a Station entity by its id. +func (c *StationClient) Get(ctx context.Context, id int) (*Station, error) { + return c.Query().Where(station.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *StationClient) GetX(ctx context.Context, id int) *Station { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *StationClient) Hooks() []Hook { + return c.hooks.Station +} + +// Interceptors returns the client interceptors. +func (c *StationClient) Interceptors() []Interceptor { + return c.inters.Station +} + +func (c *StationClient) mutate(ctx context.Context, m *StationMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&StationCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&StationUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&StationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&StationDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Station mutation op: %q", m.Op()) + } +} + // StationProcessClient is a client for the StationProcess schema. type StationProcessClient struct { config @@ -2626,6 +3059,139 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) } } +// UserStationClient is a client for the UserStation schema. +type UserStationClient struct { + config +} + +// NewUserStationClient returns a client for the UserStation from the given config. +func NewUserStationClient(c config) *UserStationClient { + return &UserStationClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `userstation.Hooks(f(g(h())))`. +func (c *UserStationClient) Use(hooks ...Hook) { + c.hooks.UserStation = append(c.hooks.UserStation, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `userstation.Intercept(f(g(h())))`. +func (c *UserStationClient) Intercept(interceptors ...Interceptor) { + c.inters.UserStation = append(c.inters.UserStation, interceptors...) +} + +// Create returns a builder for creating a UserStation entity. +func (c *UserStationClient) Create() *UserStationCreate { + mutation := newUserStationMutation(c.config, OpCreate) + return &UserStationCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of UserStation entities. +func (c *UserStationClient) CreateBulk(builders ...*UserStationCreate) *UserStationCreateBulk { + return &UserStationCreateBulk{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 *UserStationClient) MapCreateBulk(slice any, setFunc func(*UserStationCreate, int)) *UserStationCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserStationCreateBulk{err: fmt.Errorf("calling to UserStationClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserStationCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserStationCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for UserStation. +func (c *UserStationClient) Update() *UserStationUpdate { + mutation := newUserStationMutation(c.config, OpUpdate) + return &UserStationUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *UserStationClient) UpdateOne(_m *UserStation) *UserStationUpdateOne { + mutation := newUserStationMutation(c.config, OpUpdateOne, withUserStation(_m)) + return &UserStationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *UserStationClient) UpdateOneID(id int) *UserStationUpdateOne { + mutation := newUserStationMutation(c.config, OpUpdateOne, withUserStationID(id)) + return &UserStationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for UserStation. +func (c *UserStationClient) Delete() *UserStationDelete { + mutation := newUserStationMutation(c.config, OpDelete) + return &UserStationDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *UserStationClient) DeleteOne(_m *UserStation) *UserStationDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *UserStationClient) DeleteOneID(id int) *UserStationDeleteOne { + builder := c.Delete().Where(userstation.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &UserStationDeleteOne{builder} +} + +// Query returns a query builder for UserStation. +func (c *UserStationClient) Query() *UserStationQuery { + return &UserStationQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeUserStation}, + inters: c.Interceptors(), + } +} + +// Get returns a UserStation entity by its id. +func (c *UserStationClient) Get(ctx context.Context, id int) (*UserStation, error) { + return c.Query().Where(userstation.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *UserStationClient) GetX(ctx context.Context, id int) *UserStation { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *UserStationClient) Hooks() []Hook { + return c.hooks.UserStation +} + +// Interceptors returns the client interceptors. +func (c *UserStationClient) Interceptors() []Interceptor { + return c.inters.UserStation +} + +func (c *UserStationClient) mutate(ctx context.Context, m *UserStationMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserStationCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserStationUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserStationUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserStationDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown UserStation mutation op: %q", m.Op()) + } +} + // WorkOrderClient is a client for the WorkOrder schema. type WorkOrderClient struct { config @@ -3028,16 +3594,18 @@ func (c *WorkpieceProcessClient) mutate(ctx context.Context, m *WorkpieceProcess // hooks and interceptors per client, for fast access. type ( hooks struct { - AssociationTrace, BomItem, DailyPlan, EventLog, MaterialRequest, Permission, - PlcSendLog, ProcessStep, ProductType, Role, ScanRecord, SemiFlow, - StationProcess, StepCriterion, StepData, TorqueRecord, User, WorkOrder, - Workpiece, WorkpieceProcess []ent.Hook + AssociationTrace, BomItem, DailyPlan, EventLog, InspectionRecord, + MaterialRequest, Permission, PlcSendLog, ProcessFlow, ProcessStep, ProductType, + Role, ScanRecord, SemiFlow, Station, StationProcess, StepCriterion, StepData, + TorqueRecord, User, UserStation, WorkOrder, Workpiece, + WorkpieceProcess []ent.Hook } inters struct { - AssociationTrace, BomItem, DailyPlan, EventLog, MaterialRequest, Permission, - PlcSendLog, ProcessStep, ProductType, Role, ScanRecord, SemiFlow, - StationProcess, StepCriterion, StepData, TorqueRecord, User, WorkOrder, - Workpiece, WorkpieceProcess []ent.Interceptor + AssociationTrace, BomItem, DailyPlan, EventLog, InspectionRecord, + MaterialRequest, Permission, PlcSendLog, ProcessFlow, ProcessStep, ProductType, + Role, ScanRecord, SemiFlow, Station, StationProcess, StepCriterion, StepData, + TorqueRecord, User, UserStation, WorkOrder, Workpiece, + WorkpieceProcess []ent.Interceptor } ) diff --git a/bj_power_mes/ent/ent.go b/bj_power_mes/ent/ent.go index 7f107fc..67e859d 100644 --- a/bj_power_mes/ent/ent.go +++ b/bj_power_mes/ent/ent.go @@ -7,19 +7,23 @@ import ( "bj_power_mes/ent/bomitem" "bj_power_mes/ent/dailyplan" "bj_power_mes/ent/eventlog" + "bj_power_mes/ent/inspectionrecord" "bj_power_mes/ent/materialrequest" "bj_power_mes/ent/permission" "bj_power_mes/ent/plcsendlog" + "bj_power_mes/ent/processflow" "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" "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" + "bj_power_mes/ent/userstation" "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpieceprocess" @@ -96,19 +100,23 @@ func checkColumn(t, c string) error { bomitem.Table: bomitem.ValidColumn, dailyplan.Table: dailyplan.ValidColumn, eventlog.Table: eventlog.ValidColumn, + inspectionrecord.Table: inspectionrecord.ValidColumn, materialrequest.Table: materialrequest.ValidColumn, permission.Table: permission.ValidColumn, plcsendlog.Table: plcsendlog.ValidColumn, + processflow.Table: processflow.ValidColumn, 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, stepcriterion.Table: stepcriterion.ValidColumn, stepdata.Table: stepdata.ValidColumn, torquerecord.Table: torquerecord.ValidColumn, user.Table: user.ValidColumn, + userstation.Table: userstation.ValidColumn, workorder.Table: workorder.ValidColumn, workpiece.Table: workpiece.ValidColumn, workpieceprocess.Table: workpieceprocess.ValidColumn, diff --git a/bj_power_mes/ent/hook/hook.go b/bj_power_mes/ent/hook/hook.go index a8e4b18..a0639fb 100644 --- a/bj_power_mes/ent/hook/hook.go +++ b/bj_power_mes/ent/hook/hook.go @@ -56,6 +56,18 @@ func (f EventLogFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EventLogMutation", m) } +// The InspectionRecordFunc type is an adapter to allow the use of ordinary +// function as InspectionRecord mutator. +type InspectionRecordFunc func(context.Context, *ent.InspectionRecordMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f InspectionRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.InspectionRecordMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InspectionRecordMutation", m) +} + // The MaterialRequestFunc type is an adapter to allow the use of ordinary // function as MaterialRequest mutator. type MaterialRequestFunc func(context.Context, *ent.MaterialRequestMutation) (ent.Value, error) @@ -92,6 +104,18 @@ func (f PlcSendLogFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PlcSendLogMutation", m) } +// The ProcessFlowFunc type is an adapter to allow the use of ordinary +// function as ProcessFlow mutator. +type ProcessFlowFunc func(context.Context, *ent.ProcessFlowMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f ProcessFlowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.ProcessFlowMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ProcessFlowMutation", m) +} + // The ProcessStepFunc type is an adapter to allow the use of ordinary // function as ProcessStep mutator. type ProcessStepFunc func(context.Context, *ent.ProcessStepMutation) (ent.Value, error) @@ -152,6 +176,18 @@ func (f SemiFlowFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, er return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SemiFlowMutation", m) } +// The StationFunc type is an adapter to allow the use of ordinary +// function as Station mutator. +type StationFunc func(context.Context, *ent.StationMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f StationFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.StationMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StationMutation", m) +} + // The StationProcessFunc type is an adapter to allow the use of ordinary // function as StationProcess mutator. type StationProcessFunc func(context.Context, *ent.StationProcessMutation) (ent.Value, error) @@ -212,6 +248,18 @@ func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) } +// The UserStationFunc type is an adapter to allow the use of ordinary +// function as UserStation mutator. +type UserStationFunc func(context.Context, *ent.UserStationMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f UserStationFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.UserStationMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserStationMutation", m) +} + // The WorkOrderFunc type is an adapter to allow the use of ordinary // function as WorkOrder mutator. type WorkOrderFunc func(context.Context, *ent.WorkOrderMutation) (ent.Value, error) diff --git a/bj_power_mes/ent/inspectionrecord.go b/bj_power_mes/ent/inspectionrecord.go new file mode 100644 index 0000000..0c6fd67 --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord.go @@ -0,0 +1,221 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/inspectionrecord" + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// InspectionRecord is the model entity for the InspectionRecord schema. +type InspectionRecord struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 记录类型 CHECKIN/POINT/PROCESS/DONE/ALARM + Category string `json:"category,omitempty"` + // 工位号 + StationNo string `json:"stationNo,omitempty"` + // 班次 早/中/晚 + Shift string `json:"shift,omitempty"` + // 工单号 + OrderNo string `json:"orderNo,omitempty"` + // 工件SN + Sn string `json:"sn,omitempty"` + // 结论 + Result string `json:"result,omitempty"` + // 点检项/异常类型列表 + Items []string `json:"items,omitempty"` + // 拍照文件名 + Photo string `json:"photo,omitempty"` + // 文字描述/签字 + Remark string `json:"remark,omitempty"` + // 操作人 + Operator string `json:"operator,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 (*InspectionRecord) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case inspectionrecord.FieldItems: + values[i] = new([]byte) + case inspectionrecord.FieldID: + values[i] = new(sql.NullInt64) + case inspectionrecord.FieldCategory, inspectionrecord.FieldStationNo, inspectionrecord.FieldShift, inspectionrecord.FieldOrderNo, inspectionrecord.FieldSn, inspectionrecord.FieldResult, inspectionrecord.FieldPhoto, inspectionrecord.FieldRemark, inspectionrecord.FieldOperator: + values[i] = new(sql.NullString) + case inspectionrecord.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 InspectionRecord fields. +func (_m *InspectionRecord) 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 inspectionrecord.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 inspectionrecord.FieldCategory: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field category", values[i]) + } else if value.Valid { + _m.Category = value.String + } + case inspectionrecord.FieldStationNo: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field stationNo", values[i]) + } else if value.Valid { + _m.StationNo = value.String + } + case inspectionrecord.FieldShift: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field shift", values[i]) + } else if value.Valid { + _m.Shift = value.String + } + case inspectionrecord.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 inspectionrecord.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 inspectionrecord.FieldResult: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field result", values[i]) + } else if value.Valid { + _m.Result = value.String + } + case inspectionrecord.FieldItems: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field items", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Items); err != nil { + return fmt.Errorf("unmarshal field items: %w", err) + } + } + case inspectionrecord.FieldPhoto: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field photo", values[i]) + } else if value.Valid { + _m.Photo = value.String + } + case inspectionrecord.FieldRemark: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field remark", values[i]) + } else if value.Valid { + _m.Remark = value.String + } + case inspectionrecord.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 inspectionrecord.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 InspectionRecord. +// This includes values selected through modifiers, order, etc. +func (_m *InspectionRecord) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this InspectionRecord. +// Note that you need to call InspectionRecord.Unwrap() before calling this method if this InspectionRecord +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *InspectionRecord) Update() *InspectionRecordUpdateOne { + return NewInspectionRecordClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the InspectionRecord 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 *InspectionRecord) Unwrap() *InspectionRecord { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: InspectionRecord is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *InspectionRecord) String() string { + var builder strings.Builder + builder.WriteString("InspectionRecord(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("category=") + builder.WriteString(_m.Category) + builder.WriteString(", ") + builder.WriteString("stationNo=") + builder.WriteString(_m.StationNo) + builder.WriteString(", ") + builder.WriteString("shift=") + builder.WriteString(_m.Shift) + builder.WriteString(", ") + builder.WriteString("orderNo=") + builder.WriteString(_m.OrderNo) + builder.WriteString(", ") + builder.WriteString("sn=") + builder.WriteString(_m.Sn) + builder.WriteString(", ") + builder.WriteString("result=") + builder.WriteString(_m.Result) + builder.WriteString(", ") + builder.WriteString("items=") + builder.WriteString(fmt.Sprintf("%v", _m.Items)) + builder.WriteString(", ") + builder.WriteString("photo=") + builder.WriteString(_m.Photo) + builder.WriteString(", ") + builder.WriteString("remark=") + builder.WriteString(_m.Remark) + builder.WriteString(", ") + builder.WriteString("operator=") + builder.WriteString(_m.Operator) + builder.WriteString(", ") + builder.WriteString("createdAt=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// InspectionRecords is a parsable slice of InspectionRecord. +type InspectionRecords []*InspectionRecord diff --git a/bj_power_mes/ent/inspectionrecord/inspectionrecord.go b/bj_power_mes/ent/inspectionrecord/inspectionrecord.go new file mode 100644 index 0000000..2add6f1 --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord/inspectionrecord.go @@ -0,0 +1,165 @@ +// Code generated by ent, DO NOT EDIT. + +package inspectionrecord + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the inspectionrecord type in the database. + Label = "inspection_record" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCategory holds the string denoting the category field in the database. + FieldCategory = "category" + // FieldStationNo holds the string denoting the stationno field in the database. + FieldStationNo = "station_no" + // FieldShift holds the string denoting the shift field in the database. + FieldShift = "shift" + // FieldOrderNo holds the string denoting the orderno field in the database. + FieldOrderNo = "order_no" + // FieldSn holds the string denoting the sn field in the database. + FieldSn = "sn" + // FieldResult holds the string denoting the result field in the database. + FieldResult = "result" + // FieldItems holds the string denoting the items field in the database. + FieldItems = "items" + // FieldPhoto holds the string denoting the photo field in the database. + FieldPhoto = "photo" + // FieldRemark holds the string denoting the remark field in the database. + FieldRemark = "remark" + // FieldOperator holds the string denoting the operator field in the database. + FieldOperator = "operator" + // FieldCreatedAt holds the string denoting the createdat field in the database. + FieldCreatedAt = "created_at" + // Table holds the table name of the inspectionrecord in the database. + Table = "inspection_record" +) + +// Columns holds all SQL columns for inspectionrecord fields. +var Columns = []string{ + FieldID, + FieldCategory, + FieldStationNo, + FieldShift, + FieldOrderNo, + FieldSn, + FieldResult, + FieldItems, + FieldPhoto, + FieldRemark, + FieldOperator, + 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 ( + // CategoryValidator is a validator for the "category" field. It is called by the builders before save. + CategoryValidator func(string) error + // DefaultStationNo holds the default value on creation for the "stationNo" field. + DefaultStationNo string + // StationNoValidator is a validator for the "stationNo" field. It is called by the builders before save. + StationNoValidator func(string) error + // DefaultShift holds the default value on creation for the "shift" field. + DefaultShift string + // ShiftValidator is a validator for the "shift" field. It is called by the builders before save. + ShiftValidator 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 + // DefaultSn holds the default value on creation for the "sn" field. + DefaultSn string + // SnValidator is a validator for the "sn" field. It is called by the builders before save. + SnValidator func(string) error + // DefaultResult holds the default value on creation for the "result" field. + DefaultResult string + // ResultValidator is a validator for the "result" field. It is called by the builders before save. + ResultValidator func(string) error + // DefaultPhoto holds the default value on creation for the "photo" field. + DefaultPhoto string + // PhotoValidator is a validator for the "photo" field. It is called by the builders before save. + PhotoValidator func(string) error + // DefaultRemark holds the default value on creation for the "remark" field. + DefaultRemark string + // RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + RemarkValidator func(string) error + // 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 + // 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 InspectionRecord 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() +} + +// ByCategory orders the results by the category field. +func ByCategory(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCategory, opts...).ToFunc() +} + +// ByStationNo orders the results by the stationNo field. +func ByStationNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStationNo, opts...).ToFunc() +} + +// ByShift orders the results by the shift field. +func ByShift(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldShift, opts...).ToFunc() +} + +// ByOrderNo orders the results by the orderNo field. +func ByOrderNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOrderNo, opts...).ToFunc() +} + +// BySn orders the results by the sn field. +func BySn(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSn, opts...).ToFunc() +} + +// ByResult orders the results by the result field. +func ByResult(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldResult, opts...).ToFunc() +} + +// ByPhoto orders the results by the photo field. +func ByPhoto(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPhoto, opts...).ToFunc() +} + +// ByRemark orders the results by the remark field. +func ByRemark(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRemark, opts...).ToFunc() +} + +// ByOperator orders the results by the operator field. +func ByOperator(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldOperator, 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/inspectionrecord/where.go b/bj_power_mes/ent/inspectionrecord/where.go new file mode 100644 index 0000000..801440f --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord/where.go @@ -0,0 +1,755 @@ +// Code generated by ent, DO NOT EDIT. + +package inspectionrecord + +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.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldID, id)) +} + +// Category applies equality check predicate on the "category" field. It's identical to CategoryEQ. +func Category(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldCategory, v)) +} + +// StationNo applies equality check predicate on the "stationNo" field. It's identical to StationNoEQ. +func StationNo(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldStationNo, v)) +} + +// Shift applies equality check predicate on the "shift" field. It's identical to ShiftEQ. +func Shift(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldShift, v)) +} + +// OrderNo applies equality check predicate on the "orderNo" field. It's identical to OrderNoEQ. +func OrderNo(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldOrderNo, v)) +} + +// Sn applies equality check predicate on the "sn" field. It's identical to SnEQ. +func Sn(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldSn, v)) +} + +// Result applies equality check predicate on the "result" field. It's identical to ResultEQ. +func Result(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldResult, v)) +} + +// Photo applies equality check predicate on the "photo" field. It's identical to PhotoEQ. +func Photo(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldPhoto, v)) +} + +// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. +func Remark(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldRemark, v)) +} + +// Operator applies equality check predicate on the "operator" field. It's identical to OperatorEQ. +func Operator(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldOperator, v)) +} + +// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CategoryEQ applies the EQ predicate on the "category" field. +func CategoryEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldCategory, v)) +} + +// CategoryNEQ applies the NEQ predicate on the "category" field. +func CategoryNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldCategory, v)) +} + +// CategoryIn applies the In predicate on the "category" field. +func CategoryIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldCategory, vs...)) +} + +// CategoryNotIn applies the NotIn predicate on the "category" field. +func CategoryNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldCategory, vs...)) +} + +// CategoryGT applies the GT predicate on the "category" field. +func CategoryGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldCategory, v)) +} + +// CategoryGTE applies the GTE predicate on the "category" field. +func CategoryGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldCategory, v)) +} + +// CategoryLT applies the LT predicate on the "category" field. +func CategoryLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldCategory, v)) +} + +// CategoryLTE applies the LTE predicate on the "category" field. +func CategoryLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldCategory, v)) +} + +// CategoryContains applies the Contains predicate on the "category" field. +func CategoryContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldCategory, v)) +} + +// CategoryHasPrefix applies the HasPrefix predicate on the "category" field. +func CategoryHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldCategory, v)) +} + +// CategoryHasSuffix applies the HasSuffix predicate on the "category" field. +func CategoryHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldCategory, v)) +} + +// CategoryEqualFold applies the EqualFold predicate on the "category" field. +func CategoryEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldCategory, v)) +} + +// CategoryContainsFold applies the ContainsFold predicate on the "category" field. +func CategoryContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldCategory, v)) +} + +// StationNoEQ applies the EQ predicate on the "stationNo" field. +func StationNoEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldStationNo, v)) +} + +// StationNoNEQ applies the NEQ predicate on the "stationNo" field. +func StationNoNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldStationNo, v)) +} + +// StationNoIn applies the In predicate on the "stationNo" field. +func StationNoIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldStationNo, vs...)) +} + +// StationNoNotIn applies the NotIn predicate on the "stationNo" field. +func StationNoNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldStationNo, vs...)) +} + +// StationNoGT applies the GT predicate on the "stationNo" field. +func StationNoGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldStationNo, v)) +} + +// StationNoGTE applies the GTE predicate on the "stationNo" field. +func StationNoGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldStationNo, v)) +} + +// StationNoLT applies the LT predicate on the "stationNo" field. +func StationNoLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldStationNo, v)) +} + +// StationNoLTE applies the LTE predicate on the "stationNo" field. +func StationNoLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldStationNo, v)) +} + +// StationNoContains applies the Contains predicate on the "stationNo" field. +func StationNoContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldStationNo, v)) +} + +// StationNoHasPrefix applies the HasPrefix predicate on the "stationNo" field. +func StationNoHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldStationNo, v)) +} + +// StationNoHasSuffix applies the HasSuffix predicate on the "stationNo" field. +func StationNoHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldStationNo, v)) +} + +// StationNoEqualFold applies the EqualFold predicate on the "stationNo" field. +func StationNoEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldStationNo, v)) +} + +// StationNoContainsFold applies the ContainsFold predicate on the "stationNo" field. +func StationNoContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldStationNo, v)) +} + +// ShiftEQ applies the EQ predicate on the "shift" field. +func ShiftEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldShift, v)) +} + +// ShiftNEQ applies the NEQ predicate on the "shift" field. +func ShiftNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldShift, v)) +} + +// ShiftIn applies the In predicate on the "shift" field. +func ShiftIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldShift, vs...)) +} + +// ShiftNotIn applies the NotIn predicate on the "shift" field. +func ShiftNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldShift, vs...)) +} + +// ShiftGT applies the GT predicate on the "shift" field. +func ShiftGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldShift, v)) +} + +// ShiftGTE applies the GTE predicate on the "shift" field. +func ShiftGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldShift, v)) +} + +// ShiftLT applies the LT predicate on the "shift" field. +func ShiftLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldShift, v)) +} + +// ShiftLTE applies the LTE predicate on the "shift" field. +func ShiftLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldShift, v)) +} + +// ShiftContains applies the Contains predicate on the "shift" field. +func ShiftContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldShift, v)) +} + +// ShiftHasPrefix applies the HasPrefix predicate on the "shift" field. +func ShiftHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldShift, v)) +} + +// ShiftHasSuffix applies the HasSuffix predicate on the "shift" field. +func ShiftHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldShift, v)) +} + +// ShiftEqualFold applies the EqualFold predicate on the "shift" field. +func ShiftEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldShift, v)) +} + +// ShiftContainsFold applies the ContainsFold predicate on the "shift" field. +func ShiftContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldShift, v)) +} + +// OrderNoEQ applies the EQ predicate on the "orderNo" field. +func OrderNoEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldOrderNo, v)) +} + +// OrderNoNEQ applies the NEQ predicate on the "orderNo" field. +func OrderNoNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldOrderNo, v)) +} + +// OrderNoIn applies the In predicate on the "orderNo" field. +func OrderNoIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldOrderNo, vs...)) +} + +// OrderNoNotIn applies the NotIn predicate on the "orderNo" field. +func OrderNoNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldOrderNo, vs...)) +} + +// OrderNoGT applies the GT predicate on the "orderNo" field. +func OrderNoGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldOrderNo, v)) +} + +// OrderNoGTE applies the GTE predicate on the "orderNo" field. +func OrderNoGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldOrderNo, v)) +} + +// OrderNoLT applies the LT predicate on the "orderNo" field. +func OrderNoLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldOrderNo, v)) +} + +// OrderNoLTE applies the LTE predicate on the "orderNo" field. +func OrderNoLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldOrderNo, v)) +} + +// OrderNoContains applies the Contains predicate on the "orderNo" field. +func OrderNoContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldOrderNo, v)) +} + +// OrderNoHasPrefix applies the HasPrefix predicate on the "orderNo" field. +func OrderNoHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldOrderNo, v)) +} + +// OrderNoHasSuffix applies the HasSuffix predicate on the "orderNo" field. +func OrderNoHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldOrderNo, v)) +} + +// OrderNoEqualFold applies the EqualFold predicate on the "orderNo" field. +func OrderNoEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldOrderNo, v)) +} + +// OrderNoContainsFold applies the ContainsFold predicate on the "orderNo" field. +func OrderNoContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldOrderNo, v)) +} + +// SnEQ applies the EQ predicate on the "sn" field. +func SnEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldSn, v)) +} + +// SnNEQ applies the NEQ predicate on the "sn" field. +func SnNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldSn, v)) +} + +// SnIn applies the In predicate on the "sn" field. +func SnIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldSn, vs...)) +} + +// SnNotIn applies the NotIn predicate on the "sn" field. +func SnNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldSn, vs...)) +} + +// SnGT applies the GT predicate on the "sn" field. +func SnGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldSn, v)) +} + +// SnGTE applies the GTE predicate on the "sn" field. +func SnGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldSn, v)) +} + +// SnLT applies the LT predicate on the "sn" field. +func SnLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldSn, v)) +} + +// SnLTE applies the LTE predicate on the "sn" field. +func SnLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldSn, v)) +} + +// SnContains applies the Contains predicate on the "sn" field. +func SnContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldSn, v)) +} + +// SnHasPrefix applies the HasPrefix predicate on the "sn" field. +func SnHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldSn, v)) +} + +// SnHasSuffix applies the HasSuffix predicate on the "sn" field. +func SnHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldSn, v)) +} + +// SnEqualFold applies the EqualFold predicate on the "sn" field. +func SnEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldSn, v)) +} + +// SnContainsFold applies the ContainsFold predicate on the "sn" field. +func SnContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldSn, v)) +} + +// ResultEQ applies the EQ predicate on the "result" field. +func ResultEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldResult, v)) +} + +// ResultNEQ applies the NEQ predicate on the "result" field. +func ResultNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldResult, v)) +} + +// ResultIn applies the In predicate on the "result" field. +func ResultIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldResult, vs...)) +} + +// ResultNotIn applies the NotIn predicate on the "result" field. +func ResultNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldResult, vs...)) +} + +// ResultGT applies the GT predicate on the "result" field. +func ResultGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldResult, v)) +} + +// ResultGTE applies the GTE predicate on the "result" field. +func ResultGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldResult, v)) +} + +// ResultLT applies the LT predicate on the "result" field. +func ResultLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldResult, v)) +} + +// ResultLTE applies the LTE predicate on the "result" field. +func ResultLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldResult, v)) +} + +// ResultContains applies the Contains predicate on the "result" field. +func ResultContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldResult, v)) +} + +// ResultHasPrefix applies the HasPrefix predicate on the "result" field. +func ResultHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldResult, v)) +} + +// ResultHasSuffix applies the HasSuffix predicate on the "result" field. +func ResultHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldResult, v)) +} + +// ResultEqualFold applies the EqualFold predicate on the "result" field. +func ResultEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldResult, v)) +} + +// ResultContainsFold applies the ContainsFold predicate on the "result" field. +func ResultContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldResult, v)) +} + +// ItemsIsNil applies the IsNil predicate on the "items" field. +func ItemsIsNil() predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIsNull(FieldItems)) +} + +// ItemsNotNil applies the NotNil predicate on the "items" field. +func ItemsNotNil() predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotNull(FieldItems)) +} + +// PhotoEQ applies the EQ predicate on the "photo" field. +func PhotoEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldPhoto, v)) +} + +// PhotoNEQ applies the NEQ predicate on the "photo" field. +func PhotoNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldPhoto, v)) +} + +// PhotoIn applies the In predicate on the "photo" field. +func PhotoIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldPhoto, vs...)) +} + +// PhotoNotIn applies the NotIn predicate on the "photo" field. +func PhotoNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldPhoto, vs...)) +} + +// PhotoGT applies the GT predicate on the "photo" field. +func PhotoGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldPhoto, v)) +} + +// PhotoGTE applies the GTE predicate on the "photo" field. +func PhotoGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldPhoto, v)) +} + +// PhotoLT applies the LT predicate on the "photo" field. +func PhotoLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldPhoto, v)) +} + +// PhotoLTE applies the LTE predicate on the "photo" field. +func PhotoLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldPhoto, v)) +} + +// PhotoContains applies the Contains predicate on the "photo" field. +func PhotoContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldPhoto, v)) +} + +// PhotoHasPrefix applies the HasPrefix predicate on the "photo" field. +func PhotoHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldPhoto, v)) +} + +// PhotoHasSuffix applies the HasSuffix predicate on the "photo" field. +func PhotoHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldPhoto, v)) +} + +// PhotoEqualFold applies the EqualFold predicate on the "photo" field. +func PhotoEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldPhoto, v)) +} + +// PhotoContainsFold applies the ContainsFold predicate on the "photo" field. +func PhotoContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldPhoto, v)) +} + +// RemarkEQ applies the EQ predicate on the "remark" field. +func RemarkEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldRemark, v)) +} + +// RemarkNEQ applies the NEQ predicate on the "remark" field. +func RemarkNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldRemark, v)) +} + +// RemarkIn applies the In predicate on the "remark" field. +func RemarkIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldRemark, vs...)) +} + +// RemarkNotIn applies the NotIn predicate on the "remark" field. +func RemarkNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldRemark, vs...)) +} + +// RemarkGT applies the GT predicate on the "remark" field. +func RemarkGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldRemark, v)) +} + +// RemarkGTE applies the GTE predicate on the "remark" field. +func RemarkGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldRemark, v)) +} + +// RemarkLT applies the LT predicate on the "remark" field. +func RemarkLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldRemark, v)) +} + +// RemarkLTE applies the LTE predicate on the "remark" field. +func RemarkLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldRemark, v)) +} + +// RemarkContains applies the Contains predicate on the "remark" field. +func RemarkContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldRemark, v)) +} + +// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. +func RemarkHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldRemark, v)) +} + +// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. +func RemarkHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldRemark, v)) +} + +// RemarkEqualFold applies the EqualFold predicate on the "remark" field. +func RemarkEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldRemark, v)) +} + +// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. +func RemarkContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldRemark, v)) +} + +// OperatorEQ applies the EQ predicate on the "operator" field. +func OperatorEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldOperator, v)) +} + +// OperatorNEQ applies the NEQ predicate on the "operator" field. +func OperatorNEQ(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldOperator, v)) +} + +// OperatorIn applies the In predicate on the "operator" field. +func OperatorIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldOperator, vs...)) +} + +// OperatorNotIn applies the NotIn predicate on the "operator" field. +func OperatorNotIn(vs ...string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldOperator, vs...)) +} + +// OperatorGT applies the GT predicate on the "operator" field. +func OperatorGT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldOperator, v)) +} + +// OperatorGTE applies the GTE predicate on the "operator" field. +func OperatorGTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldOperator, v)) +} + +// OperatorLT applies the LT predicate on the "operator" field. +func OperatorLT(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldOperator, v)) +} + +// OperatorLTE applies the LTE predicate on the "operator" field. +func OperatorLTE(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldOperator, v)) +} + +// OperatorContains applies the Contains predicate on the "operator" field. +func OperatorContains(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContains(FieldOperator, v)) +} + +// OperatorHasPrefix applies the HasPrefix predicate on the "operator" field. +func OperatorHasPrefix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasPrefix(FieldOperator, v)) +} + +// OperatorHasSuffix applies the HasSuffix predicate on the "operator" field. +func OperatorHasSuffix(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldHasSuffix(FieldOperator, v)) +} + +// OperatorEqualFold applies the EqualFold predicate on the "operator" field. +func OperatorEqualFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEqualFold(FieldOperator, v)) +} + +// OperatorContainsFold applies the ContainsFold predicate on the "operator" field. +func OperatorContainsFold(v string) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldContainsFold(FieldOperator, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +func CreatedAtEQ(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +func CreatedAtNEQ(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "createdAt" field. +func CreatedAtIn(vs ...time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +func CreatedAtNotIn(vs ...time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "createdAt" field. +func CreatedAtGT(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +func CreatedAtGTE(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "createdAt" field. +func CreatedAtLT(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +func CreatedAtLTE(v time.Time) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.FieldLTE(FieldCreatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.InspectionRecord) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.InspectionRecord) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.InspectionRecord) predicate.InspectionRecord { + return predicate.InspectionRecord(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/inspectionrecord_create.go b/bj_power_mes/ent/inspectionrecord_create.go new file mode 100644 index 0000000..edaefef --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord_create.go @@ -0,0 +1,487 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/inspectionrecord" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// InspectionRecordCreate is the builder for creating a InspectionRecord entity. +type InspectionRecordCreate struct { + config + mutation *InspectionRecordMutation + hooks []Hook +} + +// SetCategory sets the "category" field. +func (_c *InspectionRecordCreate) SetCategory(v string) *InspectionRecordCreate { + _c.mutation.SetCategory(v) + return _c +} + +// SetStationNo sets the "stationNo" field. +func (_c *InspectionRecordCreate) SetStationNo(v string) *InspectionRecordCreate { + _c.mutation.SetStationNo(v) + return _c +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableStationNo(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetStationNo(*v) + } + return _c +} + +// SetShift sets the "shift" field. +func (_c *InspectionRecordCreate) SetShift(v string) *InspectionRecordCreate { + _c.mutation.SetShift(v) + return _c +} + +// SetNillableShift sets the "shift" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableShift(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetShift(*v) + } + return _c +} + +// SetOrderNo sets the "orderNo" field. +func (_c *InspectionRecordCreate) SetOrderNo(v string) *InspectionRecordCreate { + _c.mutation.SetOrderNo(v) + return _c +} + +// SetNillableOrderNo sets the "orderNo" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableOrderNo(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetOrderNo(*v) + } + return _c +} + +// SetSn sets the "sn" field. +func (_c *InspectionRecordCreate) SetSn(v string) *InspectionRecordCreate { + _c.mutation.SetSn(v) + return _c +} + +// SetNillableSn sets the "sn" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableSn(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetSn(*v) + } + return _c +} + +// SetResult sets the "result" field. +func (_c *InspectionRecordCreate) SetResult(v string) *InspectionRecordCreate { + _c.mutation.SetResult(v) + return _c +} + +// SetNillableResult sets the "result" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableResult(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetResult(*v) + } + return _c +} + +// SetItems sets the "items" field. +func (_c *InspectionRecordCreate) SetItems(v []string) *InspectionRecordCreate { + _c.mutation.SetItems(v) + return _c +} + +// SetPhoto sets the "photo" field. +func (_c *InspectionRecordCreate) SetPhoto(v string) *InspectionRecordCreate { + _c.mutation.SetPhoto(v) + return _c +} + +// SetNillablePhoto sets the "photo" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillablePhoto(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetPhoto(*v) + } + return _c +} + +// SetRemark sets the "remark" field. +func (_c *InspectionRecordCreate) SetRemark(v string) *InspectionRecordCreate { + _c.mutation.SetRemark(v) + return _c +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableRemark(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetRemark(*v) + } + return _c +} + +// SetOperator sets the "operator" field. +func (_c *InspectionRecordCreate) SetOperator(v string) *InspectionRecordCreate { + _c.mutation.SetOperator(v) + return _c +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableOperator(v *string) *InspectionRecordCreate { + if v != nil { + _c.SetOperator(*v) + } + return _c +} + +// SetCreatedAt sets the "createdAt" field. +func (_c *InspectionRecordCreate) SetCreatedAt(v time.Time) *InspectionRecordCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (_c *InspectionRecordCreate) SetNillableCreatedAt(v *time.Time) *InspectionRecordCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *InspectionRecordCreate) SetID(v int) *InspectionRecordCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the InspectionRecordMutation object of the builder. +func (_c *InspectionRecordCreate) Mutation() *InspectionRecordMutation { + return _c.mutation +} + +// Save creates the InspectionRecord in the database. +func (_c *InspectionRecordCreate) Save(ctx context.Context) (*InspectionRecord, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *InspectionRecordCreate) SaveX(ctx context.Context) *InspectionRecord { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *InspectionRecordCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *InspectionRecordCreate) 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 *InspectionRecordCreate) defaults() { + if _, ok := _c.mutation.StationNo(); !ok { + v := inspectionrecord.DefaultStationNo + _c.mutation.SetStationNo(v) + } + if _, ok := _c.mutation.Shift(); !ok { + v := inspectionrecord.DefaultShift + _c.mutation.SetShift(v) + } + if _, ok := _c.mutation.OrderNo(); !ok { + v := inspectionrecord.DefaultOrderNo + _c.mutation.SetOrderNo(v) + } + if _, ok := _c.mutation.Sn(); !ok { + v := inspectionrecord.DefaultSn + _c.mutation.SetSn(v) + } + if _, ok := _c.mutation.Result(); !ok { + v := inspectionrecord.DefaultResult + _c.mutation.SetResult(v) + } + if _, ok := _c.mutation.Photo(); !ok { + v := inspectionrecord.DefaultPhoto + _c.mutation.SetPhoto(v) + } + if _, ok := _c.mutation.Remark(); !ok { + v := inspectionrecord.DefaultRemark + _c.mutation.SetRemark(v) + } + if _, ok := _c.mutation.Operator(); !ok { + v := inspectionrecord.DefaultOperator + _c.mutation.SetOperator(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := inspectionrecord.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *InspectionRecordCreate) check() error { + if _, ok := _c.mutation.Category(); !ok { + return &ValidationError{Name: "category", err: errors.New(`ent: missing required field "InspectionRecord.category"`)} + } + if v, ok := _c.mutation.Category(); ok { + if err := inspectionrecord.CategoryValidator(v); err != nil { + return &ValidationError{Name: "category", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.category": %w`, err)} + } + } + if _, ok := _c.mutation.StationNo(); !ok { + return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "InspectionRecord.stationNo"`)} + } + if v, ok := _c.mutation.StationNo(); ok { + if err := inspectionrecord.StationNoValidator(v); err != nil { + return &ValidationError{Name: "stationNo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.stationNo": %w`, err)} + } + } + if _, ok := _c.mutation.Shift(); !ok { + return &ValidationError{Name: "shift", err: errors.New(`ent: missing required field "InspectionRecord.shift"`)} + } + if v, ok := _c.mutation.Shift(); ok { + if err := inspectionrecord.ShiftValidator(v); err != nil { + return &ValidationError{Name: "shift", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.shift": %w`, err)} + } + } + if _, ok := _c.mutation.OrderNo(); !ok { + return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "InspectionRecord.orderNo"`)} + } + if v, ok := _c.mutation.OrderNo(); ok { + if err := inspectionrecord.OrderNoValidator(v); err != nil { + return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.orderNo": %w`, err)} + } + } + if _, ok := _c.mutation.Sn(); !ok { + return &ValidationError{Name: "sn", err: errors.New(`ent: missing required field "InspectionRecord.sn"`)} + } + if v, ok := _c.mutation.Sn(); ok { + if err := inspectionrecord.SnValidator(v); err != nil { + return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.sn": %w`, err)} + } + } + if _, ok := _c.mutation.Result(); !ok { + return &ValidationError{Name: "result", err: errors.New(`ent: missing required field "InspectionRecord.result"`)} + } + if v, ok := _c.mutation.Result(); ok { + if err := inspectionrecord.ResultValidator(v); err != nil { + return &ValidationError{Name: "result", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.result": %w`, err)} + } + } + if _, ok := _c.mutation.Photo(); !ok { + return &ValidationError{Name: "photo", err: errors.New(`ent: missing required field "InspectionRecord.photo"`)} + } + if v, ok := _c.mutation.Photo(); ok { + if err := inspectionrecord.PhotoValidator(v); err != nil { + return &ValidationError{Name: "photo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.photo": %w`, err)} + } + } + if _, ok := _c.mutation.Remark(); !ok { + return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "InspectionRecord.remark"`)} + } + if v, ok := _c.mutation.Remark(); ok { + if err := inspectionrecord.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.remark": %w`, err)} + } + } + if _, ok := _c.mutation.Operator(); !ok { + return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "InspectionRecord.operator"`)} + } + if v, ok := _c.mutation.Operator(); ok { + if err := inspectionrecord.OperatorValidator(v); err != nil { + return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.operator": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "InspectionRecord.createdAt"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := inspectionrecord.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.id": %w`, err)} + } + } + return nil +} + +func (_c *InspectionRecordCreate) sqlSave(ctx context.Context) (*InspectionRecord, 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 *InspectionRecordCreate) createSpec() (*InspectionRecord, *sqlgraph.CreateSpec) { + var ( + _node = &InspectionRecord{config: _c.config} + _spec = sqlgraph.NewCreateSpec(inspectionrecord.Table, sqlgraph.NewFieldSpec(inspectionrecord.FieldID, field.TypeInt)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.Category(); ok { + _spec.SetField(inspectionrecord.FieldCategory, field.TypeString, value) + _node.Category = value + } + if value, ok := _c.mutation.StationNo(); ok { + _spec.SetField(inspectionrecord.FieldStationNo, field.TypeString, value) + _node.StationNo = value + } + if value, ok := _c.mutation.Shift(); ok { + _spec.SetField(inspectionrecord.FieldShift, field.TypeString, value) + _node.Shift = value + } + if value, ok := _c.mutation.OrderNo(); ok { + _spec.SetField(inspectionrecord.FieldOrderNo, field.TypeString, value) + _node.OrderNo = value + } + if value, ok := _c.mutation.Sn(); ok { + _spec.SetField(inspectionrecord.FieldSn, field.TypeString, value) + _node.Sn = value + } + if value, ok := _c.mutation.Result(); ok { + _spec.SetField(inspectionrecord.FieldResult, field.TypeString, value) + _node.Result = value + } + if value, ok := _c.mutation.Items(); ok { + _spec.SetField(inspectionrecord.FieldItems, field.TypeJSON, value) + _node.Items = value + } + if value, ok := _c.mutation.Photo(); ok { + _spec.SetField(inspectionrecord.FieldPhoto, field.TypeString, value) + _node.Photo = value + } + if value, ok := _c.mutation.Remark(); ok { + _spec.SetField(inspectionrecord.FieldRemark, field.TypeString, value) + _node.Remark = value + } + if value, ok := _c.mutation.Operator(); ok { + _spec.SetField(inspectionrecord.FieldOperator, field.TypeString, value) + _node.Operator = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(inspectionrecord.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + return _node, _spec +} + +// InspectionRecordCreateBulk is the builder for creating many InspectionRecord entities in bulk. +type InspectionRecordCreateBulk struct { + config + err error + builders []*InspectionRecordCreate +} + +// Save creates the InspectionRecord entities in the database. +func (_c *InspectionRecordCreateBulk) Save(ctx context.Context) ([]*InspectionRecord, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*InspectionRecord, 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.(*InspectionRecordMutation) + 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 *InspectionRecordCreateBulk) SaveX(ctx context.Context) []*InspectionRecord { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *InspectionRecordCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *InspectionRecordCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/inspectionrecord_delete.go b/bj_power_mes/ent/inspectionrecord_delete.go new file mode 100644 index 0000000..040d79c --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/inspectionrecord" + "bj_power_mes/ent/predicate" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// InspectionRecordDelete is the builder for deleting a InspectionRecord entity. +type InspectionRecordDelete struct { + config + hooks []Hook + mutation *InspectionRecordMutation +} + +// Where appends a list predicates to the InspectionRecordDelete builder. +func (_d *InspectionRecordDelete) Where(ps ...predicate.InspectionRecord) *InspectionRecordDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *InspectionRecordDelete) 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 *InspectionRecordDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *InspectionRecordDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(inspectionrecord.Table, sqlgraph.NewFieldSpec(inspectionrecord.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 +} + +// InspectionRecordDeleteOne is the builder for deleting a single InspectionRecord entity. +type InspectionRecordDeleteOne struct { + _d *InspectionRecordDelete +} + +// Where appends a list predicates to the InspectionRecordDelete builder. +func (_d *InspectionRecordDeleteOne) Where(ps ...predicate.InspectionRecord) *InspectionRecordDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *InspectionRecordDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{inspectionrecord.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *InspectionRecordDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/inspectionrecord_query.go b/bj_power_mes/ent/inspectionrecord_query.go new file mode 100644 index 0000000..710ce59 --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/inspectionrecord" + "bj_power_mes/ent/predicate" + "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" +) + +// InspectionRecordQuery is the builder for querying InspectionRecord entities. +type InspectionRecordQuery struct { + config + ctx *QueryContext + order []inspectionrecord.OrderOption + inters []Interceptor + predicates []predicate.InspectionRecord + 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 InspectionRecordQuery builder. +func (_q *InspectionRecordQuery) Where(ps ...predicate.InspectionRecord) *InspectionRecordQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *InspectionRecordQuery) Limit(limit int) *InspectionRecordQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *InspectionRecordQuery) Offset(offset int) *InspectionRecordQuery { + _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 *InspectionRecordQuery) Unique(unique bool) *InspectionRecordQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *InspectionRecordQuery) Order(o ...inspectionrecord.OrderOption) *InspectionRecordQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first InspectionRecord entity from the query. +// Returns a *NotFoundError when no InspectionRecord was found. +func (_q *InspectionRecordQuery) First(ctx context.Context) (*InspectionRecord, 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{inspectionrecord.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *InspectionRecordQuery) FirstX(ctx context.Context) *InspectionRecord { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first InspectionRecord ID from the query. +// Returns a *NotFoundError when no InspectionRecord ID was found. +func (_q *InspectionRecordQuery) 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{inspectionrecord.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *InspectionRecordQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single InspectionRecord entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one InspectionRecord entity is found. +// Returns a *NotFoundError when no InspectionRecord entities are found. +func (_q *InspectionRecordQuery) Only(ctx context.Context) (*InspectionRecord, 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{inspectionrecord.Label} + default: + return nil, &NotSingularError{inspectionrecord.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *InspectionRecordQuery) OnlyX(ctx context.Context) *InspectionRecord { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only InspectionRecord ID in the query. +// Returns a *NotSingularError when more than one InspectionRecord ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *InspectionRecordQuery) 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{inspectionrecord.Label} + default: + err = &NotSingularError{inspectionrecord.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *InspectionRecordQuery) 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 InspectionRecords. +func (_q *InspectionRecordQuery) All(ctx context.Context) ([]*InspectionRecord, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*InspectionRecord, *InspectionRecordQuery]() + return withInterceptors[[]*InspectionRecord](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *InspectionRecordQuery) AllX(ctx context.Context) []*InspectionRecord { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of InspectionRecord IDs. +func (_q *InspectionRecordQuery) 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(inspectionrecord.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *InspectionRecordQuery) 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 *InspectionRecordQuery) 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[*InspectionRecordQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *InspectionRecordQuery) 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 *InspectionRecordQuery) 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 *InspectionRecordQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the InspectionRecordQuery 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 *InspectionRecordQuery) Clone() *InspectionRecordQuery { + if _q == nil { + return nil + } + return &InspectionRecordQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]inspectionrecord.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.InspectionRecord{}, _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 { +// Category string `json:"category,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.InspectionRecord.Query(). +// GroupBy(inspectionrecord.FieldCategory). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *InspectionRecordQuery) GroupBy(field string, fields ...string) *InspectionRecordGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &InspectionRecordGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = inspectionrecord.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 { +// Category string `json:"category,omitempty"` +// } +// +// client.InspectionRecord.Query(). +// Select(inspectionrecord.FieldCategory). +// Scan(ctx, &v) +func (_q *InspectionRecordQuery) Select(fields ...string) *InspectionRecordSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &InspectionRecordSelect{InspectionRecordQuery: _q} + sbuild.label = inspectionrecord.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a InspectionRecordSelect configured with the given aggregations. +func (_q *InspectionRecordQuery) Aggregate(fns ...AggregateFunc) *InspectionRecordSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *InspectionRecordQuery) 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 !inspectionrecord.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 *InspectionRecordQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*InspectionRecord, error) { + var ( + nodes = []*InspectionRecord{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*InspectionRecord).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &InspectionRecord{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 *InspectionRecordQuery) 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 *InspectionRecordQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(inspectionrecord.Table, inspectionrecord.Columns, sqlgraph.NewFieldSpec(inspectionrecord.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, inspectionrecord.FieldID) + for i := range fields { + if fields[i] != inspectionrecord.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 *InspectionRecordQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(inspectionrecord.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = inspectionrecord.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 *InspectionRecordQuery) ForUpdate(opts ...sql.LockOption) *InspectionRecordQuery { + 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 *InspectionRecordQuery) ForShare(opts ...sql.LockOption) *InspectionRecordQuery { + 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 *InspectionRecordQuery) Modify(modifiers ...func(s *sql.Selector)) *InspectionRecordSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// InspectionRecordGroupBy is the group-by builder for InspectionRecord entities. +type InspectionRecordGroupBy struct { + selector + build *InspectionRecordQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *InspectionRecordGroupBy) Aggregate(fns ...AggregateFunc) *InspectionRecordGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *InspectionRecordGroupBy) 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[*InspectionRecordQuery, *InspectionRecordGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *InspectionRecordGroupBy) sqlScan(ctx context.Context, root *InspectionRecordQuery, 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) +} + +// InspectionRecordSelect is the builder for selecting fields of InspectionRecord entities. +type InspectionRecordSelect struct { + *InspectionRecordQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *InspectionRecordSelect) Aggregate(fns ...AggregateFunc) *InspectionRecordSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *InspectionRecordSelect) 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[*InspectionRecordQuery, *InspectionRecordSelect](ctx, _s.InspectionRecordQuery, _s, _s.inters, v) +} + +func (_s *InspectionRecordSelect) sqlScan(ctx context.Context, root *InspectionRecordQuery, 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 *InspectionRecordSelect) Modify(modifiers ...func(s *sql.Selector)) *InspectionRecordSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/inspectionrecord_update.go b/bj_power_mes/ent/inspectionrecord_update.go new file mode 100644 index 0000000..b3e5119 --- /dev/null +++ b/bj_power_mes/ent/inspectionrecord_update.go @@ -0,0 +1,662 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/inspectionrecord" + "bj_power_mes/ent/predicate" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/dialect/sql/sqljson" + "entgo.io/ent/schema/field" +) + +// InspectionRecordUpdate is the builder for updating InspectionRecord entities. +type InspectionRecordUpdate struct { + config + hooks []Hook + mutation *InspectionRecordMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the InspectionRecordUpdate builder. +func (_u *InspectionRecordUpdate) Where(ps ...predicate.InspectionRecord) *InspectionRecordUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetCategory sets the "category" field. +func (_u *InspectionRecordUpdate) SetCategory(v string) *InspectionRecordUpdate { + _u.mutation.SetCategory(v) + return _u +} + +// SetNillableCategory sets the "category" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableCategory(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetCategory(*v) + } + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *InspectionRecordUpdate) SetStationNo(v string) *InspectionRecordUpdate { + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableStationNo(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// SetShift sets the "shift" field. +func (_u *InspectionRecordUpdate) SetShift(v string) *InspectionRecordUpdate { + _u.mutation.SetShift(v) + return _u +} + +// SetNillableShift sets the "shift" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableShift(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetShift(*v) + } + return _u +} + +// SetOrderNo sets the "orderNo" field. +func (_u *InspectionRecordUpdate) SetOrderNo(v string) *InspectionRecordUpdate { + _u.mutation.SetOrderNo(v) + return _u +} + +// SetNillableOrderNo sets the "orderNo" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableOrderNo(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetOrderNo(*v) + } + return _u +} + +// SetSn sets the "sn" field. +func (_u *InspectionRecordUpdate) SetSn(v string) *InspectionRecordUpdate { + _u.mutation.SetSn(v) + return _u +} + +// SetNillableSn sets the "sn" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableSn(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetSn(*v) + } + return _u +} + +// SetResult sets the "result" field. +func (_u *InspectionRecordUpdate) SetResult(v string) *InspectionRecordUpdate { + _u.mutation.SetResult(v) + return _u +} + +// SetNillableResult sets the "result" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableResult(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetResult(*v) + } + return _u +} + +// SetItems sets the "items" field. +func (_u *InspectionRecordUpdate) SetItems(v []string) *InspectionRecordUpdate { + _u.mutation.SetItems(v) + return _u +} + +// AppendItems appends value to the "items" field. +func (_u *InspectionRecordUpdate) AppendItems(v []string) *InspectionRecordUpdate { + _u.mutation.AppendItems(v) + return _u +} + +// ClearItems clears the value of the "items" field. +func (_u *InspectionRecordUpdate) ClearItems() *InspectionRecordUpdate { + _u.mutation.ClearItems() + return _u +} + +// SetPhoto sets the "photo" field. +func (_u *InspectionRecordUpdate) SetPhoto(v string) *InspectionRecordUpdate { + _u.mutation.SetPhoto(v) + return _u +} + +// SetNillablePhoto sets the "photo" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillablePhoto(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetPhoto(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *InspectionRecordUpdate) SetRemark(v string) *InspectionRecordUpdate { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableRemark(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// SetOperator sets the "operator" field. +func (_u *InspectionRecordUpdate) SetOperator(v string) *InspectionRecordUpdate { + _u.mutation.SetOperator(v) + return _u +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_u *InspectionRecordUpdate) SetNillableOperator(v *string) *InspectionRecordUpdate { + if v != nil { + _u.SetOperator(*v) + } + return _u +} + +// Mutation returns the InspectionRecordMutation object of the builder. +func (_u *InspectionRecordUpdate) Mutation() *InspectionRecordMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *InspectionRecordUpdate) 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 *InspectionRecordUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *InspectionRecordUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *InspectionRecordUpdate) 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 *InspectionRecordUpdate) check() error { + if v, ok := _u.mutation.Category(); ok { + if err := inspectionrecord.CategoryValidator(v); err != nil { + return &ValidationError{Name: "category", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.category": %w`, err)} + } + } + if v, ok := _u.mutation.StationNo(); ok { + if err := inspectionrecord.StationNoValidator(v); err != nil { + return &ValidationError{Name: "stationNo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.stationNo": %w`, err)} + } + } + if v, ok := _u.mutation.Shift(); ok { + if err := inspectionrecord.ShiftValidator(v); err != nil { + return &ValidationError{Name: "shift", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.shift": %w`, err)} + } + } + if v, ok := _u.mutation.OrderNo(); ok { + if err := inspectionrecord.OrderNoValidator(v); err != nil { + return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.orderNo": %w`, err)} + } + } + if v, ok := _u.mutation.Sn(); ok { + if err := inspectionrecord.SnValidator(v); err != nil { + return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.sn": %w`, err)} + } + } + if v, ok := _u.mutation.Result(); ok { + if err := inspectionrecord.ResultValidator(v); err != nil { + return &ValidationError{Name: "result", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.result": %w`, err)} + } + } + if v, ok := _u.mutation.Photo(); ok { + if err := inspectionrecord.PhotoValidator(v); err != nil { + return &ValidationError{Name: "photo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.photo": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := inspectionrecord.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.remark": %w`, err)} + } + } + if v, ok := _u.mutation.Operator(); ok { + if err := inspectionrecord.OperatorValidator(v); err != nil { + return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.operator": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *InspectionRecordUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *InspectionRecordUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *InspectionRecordUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(inspectionrecord.Table, inspectionrecord.Columns, sqlgraph.NewFieldSpec(inspectionrecord.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.Category(); ok { + _spec.SetField(inspectionrecord.FieldCategory, field.TypeString, value) + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(inspectionrecord.FieldStationNo, field.TypeString, value) + } + if value, ok := _u.mutation.Shift(); ok { + _spec.SetField(inspectionrecord.FieldShift, field.TypeString, value) + } + if value, ok := _u.mutation.OrderNo(); ok { + _spec.SetField(inspectionrecord.FieldOrderNo, field.TypeString, value) + } + if value, ok := _u.mutation.Sn(); ok { + _spec.SetField(inspectionrecord.FieldSn, field.TypeString, value) + } + if value, ok := _u.mutation.Result(); ok { + _spec.SetField(inspectionrecord.FieldResult, field.TypeString, value) + } + if value, ok := _u.mutation.Items(); ok { + _spec.SetField(inspectionrecord.FieldItems, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedItems(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, inspectionrecord.FieldItems, value) + }) + } + if _u.mutation.ItemsCleared() { + _spec.ClearField(inspectionrecord.FieldItems, field.TypeJSON) + } + if value, ok := _u.mutation.Photo(); ok { + _spec.SetField(inspectionrecord.FieldPhoto, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(inspectionrecord.FieldRemark, field.TypeString, value) + } + if value, ok := _u.mutation.Operator(); ok { + _spec.SetField(inspectionrecord.FieldOperator, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{inspectionrecord.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// InspectionRecordUpdateOne is the builder for updating a single InspectionRecord entity. +type InspectionRecordUpdateOne struct { + config + fields []string + hooks []Hook + mutation *InspectionRecordMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetCategory sets the "category" field. +func (_u *InspectionRecordUpdateOne) SetCategory(v string) *InspectionRecordUpdateOne { + _u.mutation.SetCategory(v) + return _u +} + +// SetNillableCategory sets the "category" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableCategory(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetCategory(*v) + } + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *InspectionRecordUpdateOne) SetStationNo(v string) *InspectionRecordUpdateOne { + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableStationNo(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// SetShift sets the "shift" field. +func (_u *InspectionRecordUpdateOne) SetShift(v string) *InspectionRecordUpdateOne { + _u.mutation.SetShift(v) + return _u +} + +// SetNillableShift sets the "shift" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableShift(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetShift(*v) + } + return _u +} + +// SetOrderNo sets the "orderNo" field. +func (_u *InspectionRecordUpdateOne) SetOrderNo(v string) *InspectionRecordUpdateOne { + _u.mutation.SetOrderNo(v) + return _u +} + +// SetNillableOrderNo sets the "orderNo" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableOrderNo(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetOrderNo(*v) + } + return _u +} + +// SetSn sets the "sn" field. +func (_u *InspectionRecordUpdateOne) SetSn(v string) *InspectionRecordUpdateOne { + _u.mutation.SetSn(v) + return _u +} + +// SetNillableSn sets the "sn" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableSn(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetSn(*v) + } + return _u +} + +// SetResult sets the "result" field. +func (_u *InspectionRecordUpdateOne) SetResult(v string) *InspectionRecordUpdateOne { + _u.mutation.SetResult(v) + return _u +} + +// SetNillableResult sets the "result" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableResult(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetResult(*v) + } + return _u +} + +// SetItems sets the "items" field. +func (_u *InspectionRecordUpdateOne) SetItems(v []string) *InspectionRecordUpdateOne { + _u.mutation.SetItems(v) + return _u +} + +// AppendItems appends value to the "items" field. +func (_u *InspectionRecordUpdateOne) AppendItems(v []string) *InspectionRecordUpdateOne { + _u.mutation.AppendItems(v) + return _u +} + +// ClearItems clears the value of the "items" field. +func (_u *InspectionRecordUpdateOne) ClearItems() *InspectionRecordUpdateOne { + _u.mutation.ClearItems() + return _u +} + +// SetPhoto sets the "photo" field. +func (_u *InspectionRecordUpdateOne) SetPhoto(v string) *InspectionRecordUpdateOne { + _u.mutation.SetPhoto(v) + return _u +} + +// SetNillablePhoto sets the "photo" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillablePhoto(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetPhoto(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *InspectionRecordUpdateOne) SetRemark(v string) *InspectionRecordUpdateOne { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableRemark(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// SetOperator sets the "operator" field. +func (_u *InspectionRecordUpdateOne) SetOperator(v string) *InspectionRecordUpdateOne { + _u.mutation.SetOperator(v) + return _u +} + +// SetNillableOperator sets the "operator" field if the given value is not nil. +func (_u *InspectionRecordUpdateOne) SetNillableOperator(v *string) *InspectionRecordUpdateOne { + if v != nil { + _u.SetOperator(*v) + } + return _u +} + +// Mutation returns the InspectionRecordMutation object of the builder. +func (_u *InspectionRecordUpdateOne) Mutation() *InspectionRecordMutation { + return _u.mutation +} + +// Where appends a list predicates to the InspectionRecordUpdate builder. +func (_u *InspectionRecordUpdateOne) Where(ps ...predicate.InspectionRecord) *InspectionRecordUpdateOne { + _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 *InspectionRecordUpdateOne) Select(field string, fields ...string) *InspectionRecordUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated InspectionRecord entity. +func (_u *InspectionRecordUpdateOne) Save(ctx context.Context) (*InspectionRecord, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *InspectionRecordUpdateOne) SaveX(ctx context.Context) *InspectionRecord { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *InspectionRecordUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *InspectionRecordUpdateOne) 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 *InspectionRecordUpdateOne) check() error { + if v, ok := _u.mutation.Category(); ok { + if err := inspectionrecord.CategoryValidator(v); err != nil { + return &ValidationError{Name: "category", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.category": %w`, err)} + } + } + if v, ok := _u.mutation.StationNo(); ok { + if err := inspectionrecord.StationNoValidator(v); err != nil { + return &ValidationError{Name: "stationNo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.stationNo": %w`, err)} + } + } + if v, ok := _u.mutation.Shift(); ok { + if err := inspectionrecord.ShiftValidator(v); err != nil { + return &ValidationError{Name: "shift", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.shift": %w`, err)} + } + } + if v, ok := _u.mutation.OrderNo(); ok { + if err := inspectionrecord.OrderNoValidator(v); err != nil { + return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.orderNo": %w`, err)} + } + } + if v, ok := _u.mutation.Sn(); ok { + if err := inspectionrecord.SnValidator(v); err != nil { + return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.sn": %w`, err)} + } + } + if v, ok := _u.mutation.Result(); ok { + if err := inspectionrecord.ResultValidator(v); err != nil { + return &ValidationError{Name: "result", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.result": %w`, err)} + } + } + if v, ok := _u.mutation.Photo(); ok { + if err := inspectionrecord.PhotoValidator(v); err != nil { + return &ValidationError{Name: "photo", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.photo": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := inspectionrecord.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.remark": %w`, err)} + } + } + if v, ok := _u.mutation.Operator(); ok { + if err := inspectionrecord.OperatorValidator(v); err != nil { + return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "InspectionRecord.operator": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *InspectionRecordUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *InspectionRecordUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *InspectionRecordUpdateOne) sqlSave(ctx context.Context) (_node *InspectionRecord, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(inspectionrecord.Table, inspectionrecord.Columns, sqlgraph.NewFieldSpec(inspectionrecord.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "InspectionRecord.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, inspectionrecord.FieldID) + for _, f := range fields { + if !inspectionrecord.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != inspectionrecord.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.Category(); ok { + _spec.SetField(inspectionrecord.FieldCategory, field.TypeString, value) + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(inspectionrecord.FieldStationNo, field.TypeString, value) + } + if value, ok := _u.mutation.Shift(); ok { + _spec.SetField(inspectionrecord.FieldShift, field.TypeString, value) + } + if value, ok := _u.mutation.OrderNo(); ok { + _spec.SetField(inspectionrecord.FieldOrderNo, field.TypeString, value) + } + if value, ok := _u.mutation.Sn(); ok { + _spec.SetField(inspectionrecord.FieldSn, field.TypeString, value) + } + if value, ok := _u.mutation.Result(); ok { + _spec.SetField(inspectionrecord.FieldResult, field.TypeString, value) + } + if value, ok := _u.mutation.Items(); ok { + _spec.SetField(inspectionrecord.FieldItems, field.TypeJSON, value) + } + if value, ok := _u.mutation.AppendedItems(); ok { + _spec.AddModifier(func(u *sql.UpdateBuilder) { + sqljson.Append(u, inspectionrecord.FieldItems, value) + }) + } + if _u.mutation.ItemsCleared() { + _spec.ClearField(inspectionrecord.FieldItems, field.TypeJSON) + } + if value, ok := _u.mutation.Photo(); ok { + _spec.SetField(inspectionrecord.FieldPhoto, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(inspectionrecord.FieldRemark, field.TypeString, value) + } + if value, ok := _u.mutation.Operator(); ok { + _spec.SetField(inspectionrecord.FieldOperator, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + _node = &InspectionRecord{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{inspectionrecord.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/migrate/schema.go b/bj_power_mes/ent/migrate/schema.go index 6e5086c..97825a4 100644 --- a/bj_power_mes/ent/migrate/schema.go +++ b/bj_power_mes/ent/migrate/schema.go @@ -141,6 +141,49 @@ var ( }, }, } + // InspectionRecordColumns holds the columns for the "inspection_record" table. + InspectionRecordColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "category", Type: field.TypeString, Size: 20}, + {Name: "station_no", Type: field.TypeString, Size: 32, Default: ""}, + {Name: "shift", Type: field.TypeString, Size: 20, Default: ""}, + {Name: "order_no", Type: field.TypeString, Size: 64, Default: ""}, + {Name: "sn", Type: field.TypeString, Size: 64, Default: ""}, + {Name: "result", Type: field.TypeString, Size: 10, Default: "OK"}, + {Name: "items", Type: field.TypeJSON, Nullable: true, SchemaType: map[string]string{"postgres": "jsonb"}}, + {Name: "photo", Type: field.TypeString, Size: 255, Default: ""}, + {Name: "remark", Type: field.TypeString, Size: 500, Default: ""}, + {Name: "operator", Type: field.TypeString, Size: 64, Default: ""}, + {Name: "created_at", Type: field.TypeTime}, + } + // InspectionRecordTable holds the schema information for the "inspection_record" table. + InspectionRecordTable = &schema.Table{ + Name: "inspection_record", + Columns: InspectionRecordColumns, + PrimaryKey: []*schema.Column{InspectionRecordColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "inspectionrecord_category", + Unique: false, + Columns: []*schema.Column{InspectionRecordColumns[1]}, + }, + { + Name: "inspectionrecord_station_no", + Unique: false, + Columns: []*schema.Column{InspectionRecordColumns[2]}, + }, + { + Name: "inspectionrecord_order_no", + Unique: false, + Columns: []*schema.Column{InspectionRecordColumns[4]}, + }, + { + Name: "inspectionrecord_operator", + Unique: false, + Columns: []*schema.Column{InspectionRecordColumns[10]}, + }, + }, + } // MaterialRequestColumns holds the columns for the "material_request" table. MaterialRequestColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -245,9 +288,39 @@ var ( }, }, } + // ProcessFlowColumns holds the columns for the "process_flow" table. + ProcessFlowColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "name", Type: field.TypeString, Size: 128}, + {Name: "process_code", Type: field.TypeInt}, + {Name: "pdf_file", Type: field.TypeString, Size: 255, Default: ""}, + {Name: "status", Type: field.TypeString, Size: 20, Default: "ACTIVE"}, + {Name: "remark", Type: field.TypeString, Size: 255, Default: ""}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime, Nullable: true}, + } + // ProcessFlowTable holds the schema information for the "process_flow" table. + ProcessFlowTable = &schema.Table{ + Name: "process_flow", + Columns: ProcessFlowColumns, + PrimaryKey: []*schema.Column{ProcessFlowColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "processflow_process_code", + Unique: false, + Columns: []*schema.Column{ProcessFlowColumns[2]}, + }, + { + Name: "processflow_status", + Unique: false, + Columns: []*schema.Column{ProcessFlowColumns[4]}, + }, + }, + } // ProcessStepColumns holds the columns for the "process_step" table. ProcessStepColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "flow_id", Type: field.TypeInt, Nullable: true}, {Name: "process_code", Type: field.TypeInt}, {Name: "seq", Type: field.TypeInt, Default: 1}, {Name: "name", Type: field.TypeString, Size: 128}, @@ -265,6 +338,11 @@ var ( { Name: "processstep_process_code", Unique: false, + Columns: []*schema.Column{ProcessStepColumns[2]}, + }, + { + Name: "processstep_flow_id", + Unique: false, Columns: []*schema.Column{ProcessStepColumns[1]}, }, }, @@ -394,6 +472,28 @@ var ( }, }, } + // StationColumns holds the columns for the "station" table. + StationColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "station_no", Type: field.TypeInt, Unique: true}, + {Name: "name", Type: field.TypeString, Size: 64, Default: ""}, + {Name: "flow_id", Type: field.TypeInt, Nullable: true}, + {Name: "status", Type: field.TypeString, Size: 20, Default: "ENABLED"}, + {Name: "created_at", Type: field.TypeTime}, + } + // StationTable holds the schema information for the "station" table. + StationTable = &schema.Table{ + Name: "station", + Columns: StationColumns, + PrimaryKey: []*schema.Column{StationColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "station_station_no", + Unique: true, + Columns: []*schema.Column{StationColumns[1]}, + }, + }, + } // StationProcessColumns holds the columns for the "station_process" table. StationProcessColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -541,6 +641,8 @@ var ( {Name: "password", Type: field.TypeString, Size: 128}, {Name: "name", Type: field.TypeString, Size: 64, Default: ""}, {Name: "role_id", Type: field.TypeInt, Nullable: true}, + {Name: "can_login_workstation", Type: field.TypeBool, Default: false}, + {Name: "workstation_password", Type: field.TypeString, Nullable: true, Size: 128}, {Name: "status", Type: field.TypeString, Size: 20, Default: "ENABLED"}, {Name: "created_at", Type: field.TypeTime}, {Name: "updated_at", Type: field.TypeTime, Nullable: true}, @@ -563,6 +665,36 @@ var ( }, }, } + // UserStationColumns holds the columns for the "user_station" table. + UserStationColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "user_id", Type: field.TypeInt}, + {Name: "station_no", Type: field.TypeInt}, + {Name: "created_at", Type: field.TypeTime}, + } + // UserStationTable holds the schema information for the "user_station" table. + UserStationTable = &schema.Table{ + Name: "user_station", + Columns: UserStationColumns, + PrimaryKey: []*schema.Column{UserStationColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "userstation_user_id", + Unique: false, + Columns: []*schema.Column{UserStationColumns[1]}, + }, + { + Name: "userstation_station_no", + Unique: false, + Columns: []*schema.Column{UserStationColumns[2]}, + }, + { + Name: "userstation_user_id_station_no", + Unique: true, + Columns: []*schema.Column{UserStationColumns[1], UserStationColumns[2]}, + }, + }, + } // WorkOrderColumns holds the columns for the "work_order" table. WorkOrderColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -692,19 +824,23 @@ var ( WorkOrderBomTable, DailyPlanTable, EventLogTable, + InspectionRecordTable, MaterialRequestTable, PermissionTable, PlcSendLogTable, + ProcessFlowTable, ProcessStepTable, ProductTypeTable, RoleTable, ScanRecordTable, SemiFlowTable, + StationTable, StationProcessTable, StepCriterionTable, StepDataTable, TorqueRecordTable, UserTable, + UserStationTable, WorkOrderTable, WorkpieceTable, WorkpieceProcessTable, @@ -724,6 +860,9 @@ func init() { EventLogTable.Annotation = &entsql.Annotation{ Table: "event_log", } + InspectionRecordTable.Annotation = &entsql.Annotation{ + Table: "inspection_record", + } MaterialRequestTable.Annotation = &entsql.Annotation{ Table: "material_request", } @@ -733,6 +872,9 @@ func init() { PlcSendLogTable.Annotation = &entsql.Annotation{ Table: "plc_send_log", } + ProcessFlowTable.Annotation = &entsql.Annotation{ + Table: "process_flow", + } ProcessStepTable.Annotation = &entsql.Annotation{ Table: "process_step", } @@ -748,6 +890,9 @@ func init() { SemiFlowTable.Annotation = &entsql.Annotation{ Table: "semi_flow", } + StationTable.Annotation = &entsql.Annotation{ + Table: "station", + } StationProcessTable.Annotation = &entsql.Annotation{ Table: "station_process", } @@ -763,6 +908,9 @@ func init() { UserTable.Annotation = &entsql.Annotation{ Table: "user", } + UserStationTable.Annotation = &entsql.Annotation{ + Table: "user_station", + } WorkOrderTable.Annotation = &entsql.Annotation{ Table: "work_order", } diff --git a/bj_power_mes/ent/mutation.go b/bj_power_mes/ent/mutation.go index bd89439..48d8ae0 100644 --- a/bj_power_mes/ent/mutation.go +++ b/bj_power_mes/ent/mutation.go @@ -7,20 +7,24 @@ import ( "bj_power_mes/ent/bomitem" "bj_power_mes/ent/dailyplan" "bj_power_mes/ent/eventlog" + "bj_power_mes/ent/inspectionrecord" "bj_power_mes/ent/materialrequest" "bj_power_mes/ent/permission" "bj_power_mes/ent/plcsendlog" "bj_power_mes/ent/predicate" + "bj_power_mes/ent/processflow" "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" "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" + "bj_power_mes/ent/userstation" "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpieceprocess" @@ -47,19 +51,23 @@ const ( TypeBomItem = "BomItem" TypeDailyPlan = "DailyPlan" TypeEventLog = "EventLog" + TypeInspectionRecord = "InspectionRecord" TypeMaterialRequest = "MaterialRequest" TypePermission = "Permission" TypePlcSendLog = "PlcSendLog" + TypeProcessFlow = "ProcessFlow" TypeProcessStep = "ProcessStep" TypeProductType = "ProductType" TypeRole = "Role" TypeScanRecord = "ScanRecord" TypeSemiFlow = "SemiFlow" + TypeStation = "Station" TypeStationProcess = "StationProcess" TypeStepCriterion = "StepCriterion" TypeStepData = "StepData" TypeTorqueRecord = "TorqueRecord" TypeUser = "User" + TypeUserStation = "UserStation" TypeWorkOrder = "WorkOrder" TypeWorkpiece = "Workpiece" TypeWorkpieceProcess = "WorkpieceProcess" @@ -3342,6 +3350,917 @@ func (m *EventLogMutation) ResetEdge(name string) error { return fmt.Errorf("unknown EventLog edge %s", name) } +// InspectionRecordMutation represents an operation that mutates the InspectionRecord nodes in the graph. +type InspectionRecordMutation struct { + config + op Op + typ string + id *int + category *string + stationNo *string + shift *string + orderNo *string + sn *string + result *string + items *[]string + appenditems []string + photo *string + remark *string + operator *string + createdAt *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*InspectionRecord, error) + predicates []predicate.InspectionRecord +} + +var _ ent.Mutation = (*InspectionRecordMutation)(nil) + +// inspectionrecordOption allows management of the mutation configuration using functional options. +type inspectionrecordOption func(*InspectionRecordMutation) + +// newInspectionRecordMutation creates new mutation for the InspectionRecord entity. +func newInspectionRecordMutation(c config, op Op, opts ...inspectionrecordOption) *InspectionRecordMutation { + m := &InspectionRecordMutation{ + config: c, + op: op, + typ: TypeInspectionRecord, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withInspectionRecordID sets the ID field of the mutation. +func withInspectionRecordID(id int) inspectionrecordOption { + return func(m *InspectionRecordMutation) { + var ( + err error + once sync.Once + value *InspectionRecord + ) + m.oldValue = func(ctx context.Context) (*InspectionRecord, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().InspectionRecord.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withInspectionRecord sets the old InspectionRecord of the mutation. +func withInspectionRecord(node *InspectionRecord) inspectionrecordOption { + return func(m *InspectionRecordMutation) { + m.oldValue = func(context.Context) (*InspectionRecord, 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 InspectionRecordMutation) 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 InspectionRecordMutation) 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 InspectionRecord entities. +func (m *InspectionRecordMutation) 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 *InspectionRecordMutation) 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 *InspectionRecordMutation) 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().InspectionRecord.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetCategory sets the "category" field. +func (m *InspectionRecordMutation) SetCategory(s string) { + m.category = &s +} + +// Category returns the value of the "category" field in the mutation. +func (m *InspectionRecordMutation) Category() (r string, exists bool) { + v := m.category + if v == nil { + return + } + return *v, true +} + +// OldCategory returns the old "category" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldCategory(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCategory is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCategory requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCategory: %w", err) + } + return oldValue.Category, nil +} + +// ResetCategory resets all changes to the "category" field. +func (m *InspectionRecordMutation) ResetCategory() { + m.category = nil +} + +// SetStationNo sets the "stationNo" field. +func (m *InspectionRecordMutation) SetStationNo(s string) { + m.stationNo = &s +} + +// StationNo returns the value of the "stationNo" field in the mutation. +func (m *InspectionRecordMutation) StationNo() (r string, exists bool) { + v := m.stationNo + if v == nil { + return + } + return *v, true +} + +// OldStationNo returns the old "stationNo" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldStationNo(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStationNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStationNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStationNo: %w", err) + } + return oldValue.StationNo, nil +} + +// ResetStationNo resets all changes to the "stationNo" field. +func (m *InspectionRecordMutation) ResetStationNo() { + m.stationNo = nil +} + +// SetShift sets the "shift" field. +func (m *InspectionRecordMutation) SetShift(s string) { + m.shift = &s +} + +// Shift returns the value of the "shift" field in the mutation. +func (m *InspectionRecordMutation) Shift() (r string, exists bool) { + v := m.shift + if v == nil { + return + } + return *v, true +} + +// OldShift returns the old "shift" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldShift(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldShift is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldShift requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldShift: %w", err) + } + return oldValue.Shift, nil +} + +// ResetShift resets all changes to the "shift" field. +func (m *InspectionRecordMutation) ResetShift() { + m.shift = nil +} + +// SetOrderNo sets the "orderNo" field. +func (m *InspectionRecordMutation) SetOrderNo(s string) { + m.orderNo = &s +} + +// OrderNo returns the value of the "orderNo" field in the mutation. +func (m *InspectionRecordMutation) 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 InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) 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 *InspectionRecordMutation) ResetOrderNo() { + m.orderNo = nil +} + +// SetSn sets the "sn" field. +func (m *InspectionRecordMutation) SetSn(s string) { + m.sn = &s +} + +// Sn returns the value of the "sn" field in the mutation. +func (m *InspectionRecordMutation) 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 InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) 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 *InspectionRecordMutation) ResetSn() { + m.sn = nil +} + +// SetResult sets the "result" field. +func (m *InspectionRecordMutation) SetResult(s string) { + m.result = &s +} + +// Result returns the value of the "result" field in the mutation. +func (m *InspectionRecordMutation) Result() (r string, exists bool) { + v := m.result + if v == nil { + return + } + return *v, true +} + +// OldResult returns the old "result" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldResult(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldResult is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldResult requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldResult: %w", err) + } + return oldValue.Result, nil +} + +// ResetResult resets all changes to the "result" field. +func (m *InspectionRecordMutation) ResetResult() { + m.result = nil +} + +// SetItems sets the "items" field. +func (m *InspectionRecordMutation) SetItems(s []string) { + m.items = &s + m.appenditems = nil +} + +// Items returns the value of the "items" field in the mutation. +func (m *InspectionRecordMutation) Items() (r []string, exists bool) { + v := m.items + if v == nil { + return + } + return *v, true +} + +// OldItems returns the old "items" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldItems(ctx context.Context) (v []string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldItems is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldItems requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldItems: %w", err) + } + return oldValue.Items, nil +} + +// AppendItems adds s to the "items" field. +func (m *InspectionRecordMutation) AppendItems(s []string) { + m.appenditems = append(m.appenditems, s...) +} + +// AppendedItems returns the list of values that were appended to the "items" field in this mutation. +func (m *InspectionRecordMutation) AppendedItems() ([]string, bool) { + if len(m.appenditems) == 0 { + return nil, false + } + return m.appenditems, true +} + +// ClearItems clears the value of the "items" field. +func (m *InspectionRecordMutation) ClearItems() { + m.items = nil + m.appenditems = nil + m.clearedFields[inspectionrecord.FieldItems] = struct{}{} +} + +// ItemsCleared returns if the "items" field was cleared in this mutation. +func (m *InspectionRecordMutation) ItemsCleared() bool { + _, ok := m.clearedFields[inspectionrecord.FieldItems] + return ok +} + +// ResetItems resets all changes to the "items" field. +func (m *InspectionRecordMutation) ResetItems() { + m.items = nil + m.appenditems = nil + delete(m.clearedFields, inspectionrecord.FieldItems) +} + +// SetPhoto sets the "photo" field. +func (m *InspectionRecordMutation) SetPhoto(s string) { + m.photo = &s +} + +// Photo returns the value of the "photo" field in the mutation. +func (m *InspectionRecordMutation) Photo() (r string, exists bool) { + v := m.photo + if v == nil { + return + } + return *v, true +} + +// OldPhoto returns the old "photo" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldPhoto(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPhoto is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPhoto requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPhoto: %w", err) + } + return oldValue.Photo, nil +} + +// ResetPhoto resets all changes to the "photo" field. +func (m *InspectionRecordMutation) ResetPhoto() { + m.photo = nil +} + +// SetRemark sets the "remark" field. +func (m *InspectionRecordMutation) SetRemark(s string) { + m.remark = &s +} + +// Remark returns the value of the "remark" field in the mutation. +func (m *InspectionRecordMutation) Remark() (r string, exists bool) { + v := m.remark + if v == nil { + return + } + return *v, true +} + +// OldRemark returns the old "remark" field's value of the InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) OldRemark(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRemark is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRemark requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRemark: %w", err) + } + return oldValue.Remark, nil +} + +// ResetRemark resets all changes to the "remark" field. +func (m *InspectionRecordMutation) ResetRemark() { + m.remark = nil +} + +// SetOperator sets the "operator" field. +func (m *InspectionRecordMutation) SetOperator(s string) { + m.operator = &s +} + +// Operator returns the value of the "operator" field in the mutation. +func (m *InspectionRecordMutation) 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 InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) 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 *InspectionRecordMutation) ResetOperator() { + m.operator = nil +} + +// SetCreatedAt sets the "createdAt" field. +func (m *InspectionRecordMutation) SetCreatedAt(t time.Time) { + m.createdAt = &t +} + +// CreatedAt returns the value of the "createdAt" field in the mutation. +func (m *InspectionRecordMutation) 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 InspectionRecord entity. +// If the InspectionRecord 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 *InspectionRecordMutation) 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 *InspectionRecordMutation) ResetCreatedAt() { + m.createdAt = nil +} + +// Where appends a list predicates to the InspectionRecordMutation builder. +func (m *InspectionRecordMutation) Where(ps ...predicate.InspectionRecord) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the InspectionRecordMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *InspectionRecordMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.InspectionRecord, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *InspectionRecordMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *InspectionRecordMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (InspectionRecord). +func (m *InspectionRecordMutation) 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 *InspectionRecordMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.category != nil { + fields = append(fields, inspectionrecord.FieldCategory) + } + if m.stationNo != nil { + fields = append(fields, inspectionrecord.FieldStationNo) + } + if m.shift != nil { + fields = append(fields, inspectionrecord.FieldShift) + } + if m.orderNo != nil { + fields = append(fields, inspectionrecord.FieldOrderNo) + } + if m.sn != nil { + fields = append(fields, inspectionrecord.FieldSn) + } + if m.result != nil { + fields = append(fields, inspectionrecord.FieldResult) + } + if m.items != nil { + fields = append(fields, inspectionrecord.FieldItems) + } + if m.photo != nil { + fields = append(fields, inspectionrecord.FieldPhoto) + } + if m.remark != nil { + fields = append(fields, inspectionrecord.FieldRemark) + } + if m.operator != nil { + fields = append(fields, inspectionrecord.FieldOperator) + } + if m.createdAt != nil { + fields = append(fields, inspectionrecord.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 *InspectionRecordMutation) Field(name string) (ent.Value, bool) { + switch name { + case inspectionrecord.FieldCategory: + return m.Category() + case inspectionrecord.FieldStationNo: + return m.StationNo() + case inspectionrecord.FieldShift: + return m.Shift() + case inspectionrecord.FieldOrderNo: + return m.OrderNo() + case inspectionrecord.FieldSn: + return m.Sn() + case inspectionrecord.FieldResult: + return m.Result() + case inspectionrecord.FieldItems: + return m.Items() + case inspectionrecord.FieldPhoto: + return m.Photo() + case inspectionrecord.FieldRemark: + return m.Remark() + case inspectionrecord.FieldOperator: + return m.Operator() + case inspectionrecord.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 *InspectionRecordMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case inspectionrecord.FieldCategory: + return m.OldCategory(ctx) + case inspectionrecord.FieldStationNo: + return m.OldStationNo(ctx) + case inspectionrecord.FieldShift: + return m.OldShift(ctx) + case inspectionrecord.FieldOrderNo: + return m.OldOrderNo(ctx) + case inspectionrecord.FieldSn: + return m.OldSn(ctx) + case inspectionrecord.FieldResult: + return m.OldResult(ctx) + case inspectionrecord.FieldItems: + return m.OldItems(ctx) + case inspectionrecord.FieldPhoto: + return m.OldPhoto(ctx) + case inspectionrecord.FieldRemark: + return m.OldRemark(ctx) + case inspectionrecord.FieldOperator: + return m.OldOperator(ctx) + case inspectionrecord.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown InspectionRecord 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 *InspectionRecordMutation) SetField(name string, value ent.Value) error { + switch name { + case inspectionrecord.FieldCategory: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCategory(v) + return nil + case inspectionrecord.FieldStationNo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStationNo(v) + return nil + case inspectionrecord.FieldShift: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetShift(v) + return nil + case inspectionrecord.FieldOrderNo: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOrderNo(v) + return nil + case inspectionrecord.FieldSn: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetSn(v) + return nil + case inspectionrecord.FieldResult: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetResult(v) + return nil + case inspectionrecord.FieldItems: + v, ok := value.([]string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetItems(v) + return nil + case inspectionrecord.FieldPhoto: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPhoto(v) + return nil + case inspectionrecord.FieldRemark: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRemark(v) + return nil + case inspectionrecord.FieldOperator: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetOperator(v) + return nil + case inspectionrecord.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 InspectionRecord field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *InspectionRecordMutation) AddedFields() []string { + return nil +} + +// 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 *InspectionRecordMutation) AddedField(name string) (ent.Value, bool) { + 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 *InspectionRecordMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown InspectionRecord numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *InspectionRecordMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(inspectionrecord.FieldItems) { + fields = append(fields, inspectionrecord.FieldItems) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *InspectionRecordMutation) 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 *InspectionRecordMutation) ClearField(name string) error { + switch name { + case inspectionrecord.FieldItems: + m.ClearItems() + return nil + } + return fmt.Errorf("unknown InspectionRecord 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 *InspectionRecordMutation) ResetField(name string) error { + switch name { + case inspectionrecord.FieldCategory: + m.ResetCategory() + return nil + case inspectionrecord.FieldStationNo: + m.ResetStationNo() + return nil + case inspectionrecord.FieldShift: + m.ResetShift() + return nil + case inspectionrecord.FieldOrderNo: + m.ResetOrderNo() + return nil + case inspectionrecord.FieldSn: + m.ResetSn() + return nil + case inspectionrecord.FieldResult: + m.ResetResult() + return nil + case inspectionrecord.FieldItems: + m.ResetItems() + return nil + case inspectionrecord.FieldPhoto: + m.ResetPhoto() + return nil + case inspectionrecord.FieldRemark: + m.ResetRemark() + return nil + case inspectionrecord.FieldOperator: + m.ResetOperator() + return nil + case inspectionrecord.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown InspectionRecord field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *InspectionRecordMutation) 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 *InspectionRecordMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *InspectionRecordMutation) 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 *InspectionRecordMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *InspectionRecordMutation) 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 *InspectionRecordMutation) 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 *InspectionRecordMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown InspectionRecord 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 *InspectionRecordMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown InspectionRecord edge %s", name) +} + // MaterialRequestMutation represents an operation that mutates the MaterialRequest nodes in the graph. type MaterialRequestMutation struct { config @@ -6208,12 +7127,728 @@ func (m *PlcSendLogMutation) ResetEdge(name string) error { return fmt.Errorf("unknown PlcSendLog edge %s", name) } +// ProcessFlowMutation represents an operation that mutates the ProcessFlow nodes in the graph. +type ProcessFlowMutation struct { + config + op Op + typ string + id *int + name *string + processCode *int + addprocessCode *int + pdfFile *string + status *string + remark *string + createdAt *time.Time + updatedAt *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*ProcessFlow, error) + predicates []predicate.ProcessFlow +} + +var _ ent.Mutation = (*ProcessFlowMutation)(nil) + +// processflowOption allows management of the mutation configuration using functional options. +type processflowOption func(*ProcessFlowMutation) + +// newProcessFlowMutation creates new mutation for the ProcessFlow entity. +func newProcessFlowMutation(c config, op Op, opts ...processflowOption) *ProcessFlowMutation { + m := &ProcessFlowMutation{ + config: c, + op: op, + typ: TypeProcessFlow, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withProcessFlowID sets the ID field of the mutation. +func withProcessFlowID(id int) processflowOption { + return func(m *ProcessFlowMutation) { + var ( + err error + once sync.Once + value *ProcessFlow + ) + m.oldValue = func(ctx context.Context) (*ProcessFlow, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().ProcessFlow.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withProcessFlow sets the old ProcessFlow of the mutation. +func withProcessFlow(node *ProcessFlow) processflowOption { + return func(m *ProcessFlowMutation) { + m.oldValue = func(context.Context) (*ProcessFlow, 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 ProcessFlowMutation) 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 ProcessFlowMutation) 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 ProcessFlow entities. +func (m *ProcessFlowMutation) 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 *ProcessFlowMutation) 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 *ProcessFlowMutation) 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().ProcessFlow.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetName sets the "name" field. +func (m *ProcessFlowMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *ProcessFlowMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *ProcessFlowMutation) ResetName() { + m.name = nil +} + +// SetProcessCode sets the "processCode" field. +func (m *ProcessFlowMutation) SetProcessCode(i int) { + m.processCode = &i + m.addprocessCode = nil +} + +// ProcessCode returns the value of the "processCode" field in the mutation. +func (m *ProcessFlowMutation) 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 ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) 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 *ProcessFlowMutation) 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 *ProcessFlowMutation) AddedProcessCode() (r int, exists bool) { + v := m.addprocessCode + if v == nil { + return + } + return *v, true +} + +// ResetProcessCode resets all changes to the "processCode" field. +func (m *ProcessFlowMutation) ResetProcessCode() { + m.processCode = nil + m.addprocessCode = nil +} + +// SetPdfFile sets the "pdfFile" field. +func (m *ProcessFlowMutation) SetPdfFile(s string) { + m.pdfFile = &s +} + +// PdfFile returns the value of the "pdfFile" field in the mutation. +func (m *ProcessFlowMutation) PdfFile() (r string, exists bool) { + v := m.pdfFile + if v == nil { + return + } + return *v, true +} + +// OldPdfFile returns the old "pdfFile" field's value of the ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) OldPdfFile(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPdfFile is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPdfFile requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPdfFile: %w", err) + } + return oldValue.PdfFile, nil +} + +// ResetPdfFile resets all changes to the "pdfFile" field. +func (m *ProcessFlowMutation) ResetPdfFile() { + m.pdfFile = nil +} + +// SetStatus sets the "status" field. +func (m *ProcessFlowMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *ProcessFlowMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *ProcessFlowMutation) ResetStatus() { + m.status = nil +} + +// SetRemark sets the "remark" field. +func (m *ProcessFlowMutation) SetRemark(s string) { + m.remark = &s +} + +// Remark returns the value of the "remark" field in the mutation. +func (m *ProcessFlowMutation) Remark() (r string, exists bool) { + v := m.remark + if v == nil { + return + } + return *v, true +} + +// OldRemark returns the old "remark" field's value of the ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) OldRemark(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRemark is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRemark requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRemark: %w", err) + } + return oldValue.Remark, nil +} + +// ResetRemark resets all changes to the "remark" field. +func (m *ProcessFlowMutation) ResetRemark() { + m.remark = nil +} + +// SetCreatedAt sets the "createdAt" field. +func (m *ProcessFlowMutation) SetCreatedAt(t time.Time) { + m.createdAt = &t +} + +// CreatedAt returns the value of the "createdAt" field in the mutation. +func (m *ProcessFlowMutation) 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 ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) 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 *ProcessFlowMutation) ResetCreatedAt() { + m.createdAt = nil +} + +// SetUpdatedAt sets the "updatedAt" field. +func (m *ProcessFlowMutation) SetUpdatedAt(t time.Time) { + m.updatedAt = &t +} + +// UpdatedAt returns the value of the "updatedAt" field in the mutation. +func (m *ProcessFlowMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updatedAt + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updatedAt" field's value of the ProcessFlow entity. +// If the ProcessFlow 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 *ProcessFlowMutation) OldUpdatedAt(ctx context.Context) (v *time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ClearUpdatedAt clears the value of the "updatedAt" field. +func (m *ProcessFlowMutation) ClearUpdatedAt() { + m.updatedAt = nil + m.clearedFields[processflow.FieldUpdatedAt] = struct{}{} +} + +// UpdatedAtCleared returns if the "updatedAt" field was cleared in this mutation. +func (m *ProcessFlowMutation) UpdatedAtCleared() bool { + _, ok := m.clearedFields[processflow.FieldUpdatedAt] + return ok +} + +// ResetUpdatedAt resets all changes to the "updatedAt" field. +func (m *ProcessFlowMutation) ResetUpdatedAt() { + m.updatedAt = nil + delete(m.clearedFields, processflow.FieldUpdatedAt) +} + +// Where appends a list predicates to the ProcessFlowMutation builder. +func (m *ProcessFlowMutation) Where(ps ...predicate.ProcessFlow) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the ProcessFlowMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *ProcessFlowMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.ProcessFlow, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *ProcessFlowMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *ProcessFlowMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (ProcessFlow). +func (m *ProcessFlowMutation) 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 *ProcessFlowMutation) Fields() []string { + fields := make([]string, 0, 7) + if m.name != nil { + fields = append(fields, processflow.FieldName) + } + if m.processCode != nil { + fields = append(fields, processflow.FieldProcessCode) + } + if m.pdfFile != nil { + fields = append(fields, processflow.FieldPdfFile) + } + if m.status != nil { + fields = append(fields, processflow.FieldStatus) + } + if m.remark != nil { + fields = append(fields, processflow.FieldRemark) + } + if m.createdAt != nil { + fields = append(fields, processflow.FieldCreatedAt) + } + if m.updatedAt != nil { + fields = append(fields, processflow.FieldUpdatedAt) + } + 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 *ProcessFlowMutation) Field(name string) (ent.Value, bool) { + switch name { + case processflow.FieldName: + return m.Name() + case processflow.FieldProcessCode: + return m.ProcessCode() + case processflow.FieldPdfFile: + return m.PdfFile() + case processflow.FieldStatus: + return m.Status() + case processflow.FieldRemark: + return m.Remark() + case processflow.FieldCreatedAt: + return m.CreatedAt() + case processflow.FieldUpdatedAt: + return m.UpdatedAt() + } + 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 *ProcessFlowMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case processflow.FieldName: + return m.OldName(ctx) + case processflow.FieldProcessCode: + return m.OldProcessCode(ctx) + case processflow.FieldPdfFile: + return m.OldPdfFile(ctx) + case processflow.FieldStatus: + return m.OldStatus(ctx) + case processflow.FieldRemark: + return m.OldRemark(ctx) + case processflow.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case processflow.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown ProcessFlow 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 *ProcessFlowMutation) SetField(name string, value ent.Value) error { + switch name { + case processflow.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case processflow.FieldProcessCode: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetProcessCode(v) + return nil + case processflow.FieldPdfFile: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPdfFile(v) + return nil + case processflow.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case processflow.FieldRemark: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRemark(v) + return nil + case processflow.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case processflow.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown ProcessFlow field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *ProcessFlowMutation) AddedFields() []string { + var fields []string + if m.addprocessCode != nil { + fields = append(fields, processflow.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 *ProcessFlowMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case processflow.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 *ProcessFlowMutation) AddField(name string, value ent.Value) error { + switch name { + case processflow.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 ProcessFlow numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *ProcessFlowMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(processflow.FieldUpdatedAt) { + fields = append(fields, processflow.FieldUpdatedAt) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *ProcessFlowMutation) 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 *ProcessFlowMutation) ClearField(name string) error { + switch name { + case processflow.FieldUpdatedAt: + m.ClearUpdatedAt() + return nil + } + return fmt.Errorf("unknown ProcessFlow 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 *ProcessFlowMutation) ResetField(name string) error { + switch name { + case processflow.FieldName: + m.ResetName() + return nil + case processflow.FieldProcessCode: + m.ResetProcessCode() + return nil + case processflow.FieldPdfFile: + m.ResetPdfFile() + return nil + case processflow.FieldStatus: + m.ResetStatus() + return nil + case processflow.FieldRemark: + m.ResetRemark() + return nil + case processflow.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case processflow.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown ProcessFlow field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *ProcessFlowMutation) 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 *ProcessFlowMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *ProcessFlowMutation) 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 *ProcessFlowMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *ProcessFlowMutation) 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 *ProcessFlowMutation) 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 *ProcessFlowMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown ProcessFlow 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 *ProcessFlowMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown ProcessFlow edge %s", name) +} + // ProcessStepMutation represents an operation that mutates the ProcessStep nodes in the graph. type ProcessStepMutation struct { config op Op typ string id *int + flowId *int + addflowId *int processCode *int addprocessCode *int seq *int @@ -6333,6 +7968,76 @@ func (m *ProcessStepMutation) IDs(ctx context.Context) ([]int, error) { } } +// SetFlowId sets the "flowId" field. +func (m *ProcessStepMutation) SetFlowId(i int) { + m.flowId = &i + m.addflowId = nil +} + +// FlowId returns the value of the "flowId" field in the mutation. +func (m *ProcessStepMutation) FlowId() (r int, exists bool) { + v := m.flowId + if v == nil { + return + } + return *v, true +} + +// OldFlowId returns the old "flowId" field's value of the ProcessStep entity. +// If the ProcessStep 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 *ProcessStepMutation) OldFlowId(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFlowId is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFlowId requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFlowId: %w", err) + } + return oldValue.FlowId, nil +} + +// AddFlowId adds i to the "flowId" field. +func (m *ProcessStepMutation) AddFlowId(i int) { + if m.addflowId != nil { + *m.addflowId += i + } else { + m.addflowId = &i + } +} + +// AddedFlowId returns the value that was added to the "flowId" field in this mutation. +func (m *ProcessStepMutation) AddedFlowId() (r int, exists bool) { + v := m.addflowId + if v == nil { + return + } + return *v, true +} + +// ClearFlowId clears the value of the "flowId" field. +func (m *ProcessStepMutation) ClearFlowId() { + m.flowId = nil + m.addflowId = nil + m.clearedFields[processstep.FieldFlowId] = struct{}{} +} + +// FlowIdCleared returns if the "flowId" field was cleared in this mutation. +func (m *ProcessStepMutation) FlowIdCleared() bool { + _, ok := m.clearedFields[processstep.FieldFlowId] + return ok +} + +// ResetFlowId resets all changes to the "flowId" field. +func (m *ProcessStepMutation) ResetFlowId() { + m.flowId = nil + m.addflowId = nil + delete(m.clearedFields, processstep.FieldFlowId) +} + // SetProcessCode sets the "processCode" field. func (m *ProcessStepMutation) SetProcessCode(i int) { m.processCode = &i @@ -6659,7 +8364,10 @@ func (m *ProcessStepMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *ProcessStepMutation) Fields() []string { - fields := make([]string, 0, 7) + fields := make([]string, 0, 8) + if m.flowId != nil { + fields = append(fields, processstep.FieldFlowId) + } if m.processCode != nil { fields = append(fields, processstep.FieldProcessCode) } @@ -6689,6 +8397,8 @@ func (m *ProcessStepMutation) Fields() []string { // schema. func (m *ProcessStepMutation) Field(name string) (ent.Value, bool) { switch name { + case processstep.FieldFlowId: + return m.FlowId() case processstep.FieldProcessCode: return m.ProcessCode() case processstep.FieldSeq: @@ -6712,6 +8422,8 @@ func (m *ProcessStepMutation) Field(name string) (ent.Value, bool) { // database failed. func (m *ProcessStepMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { + case processstep.FieldFlowId: + return m.OldFlowId(ctx) case processstep.FieldProcessCode: return m.OldProcessCode(ctx) case processstep.FieldSeq: @@ -6735,6 +8447,13 @@ func (m *ProcessStepMutation) OldField(ctx context.Context, name string) (ent.Va // type. func (m *ProcessStepMutation) SetField(name string, value ent.Value) error { switch name { + case processstep.FieldFlowId: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFlowId(v) + return nil case processstep.FieldProcessCode: v, ok := value.(int) if !ok { @@ -6792,6 +8511,9 @@ func (m *ProcessStepMutation) SetField(name string, value ent.Value) error { // this mutation. func (m *ProcessStepMutation) AddedFields() []string { var fields []string + if m.addflowId != nil { + fields = append(fields, processstep.FieldFlowId) + } if m.addprocessCode != nil { fields = append(fields, processstep.FieldProcessCode) } @@ -6806,6 +8528,8 @@ func (m *ProcessStepMutation) AddedFields() []string { // was not set, or was not defined in the schema. func (m *ProcessStepMutation) AddedField(name string) (ent.Value, bool) { switch name { + case processstep.FieldFlowId: + return m.AddedFlowId() case processstep.FieldProcessCode: return m.AddedProcessCode() case processstep.FieldSeq: @@ -6819,6 +8543,13 @@ func (m *ProcessStepMutation) AddedField(name string) (ent.Value, bool) { // type. func (m *ProcessStepMutation) AddField(name string, value ent.Value) error { switch name { + case processstep.FieldFlowId: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddFlowId(v) + return nil case processstep.FieldProcessCode: v, ok := value.(int) if !ok { @@ -6840,7 +8571,11 @@ func (m *ProcessStepMutation) AddField(name string, value ent.Value) error { // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *ProcessStepMutation) ClearedFields() []string { - return nil + var fields []string + if m.FieldCleared(processstep.FieldFlowId) { + fields = append(fields, processstep.FieldFlowId) + } + return fields } // FieldCleared returns a boolean indicating if a field with the given name was @@ -6853,6 +8588,11 @@ func (m *ProcessStepMutation) FieldCleared(name string) bool { // 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 *ProcessStepMutation) ClearField(name string) error { + switch name { + case processstep.FieldFlowId: + m.ClearFlowId() + return nil + } return fmt.Errorf("unknown ProcessStep nullable field %s", name) } @@ -6860,6 +8600,9 @@ func (m *ProcessStepMutation) ClearField(name string) error { // It returns an error if the field is not defined in the schema. func (m *ProcessStepMutation) ResetField(name string) error { switch name { + case processstep.FieldFlowId: + m.ResetFlowId() + return nil case processstep.FieldProcessCode: m.ResetProcessCode() return nil @@ -9662,6 +11405,646 @@ func (m *SemiFlowMutation) ResetEdge(name string) error { return fmt.Errorf("unknown SemiFlow edge %s", name) } +// StationMutation represents an operation that mutates the Station nodes in the graph. +type StationMutation struct { + config + op Op + typ string + id *int + stationNo *int + addstationNo *int + name *string + flowId *int + addflowId *int + status *string + createdAt *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*Station, error) + predicates []predicate.Station +} + +var _ ent.Mutation = (*StationMutation)(nil) + +// stationOption allows management of the mutation configuration using functional options. +type stationOption func(*StationMutation) + +// newStationMutation creates new mutation for the Station entity. +func newStationMutation(c config, op Op, opts ...stationOption) *StationMutation { + m := &StationMutation{ + config: c, + op: op, + typ: TypeStation, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withStationID sets the ID field of the mutation. +func withStationID(id int) stationOption { + return func(m *StationMutation) { + var ( + err error + once sync.Once + value *Station + ) + m.oldValue = func(ctx context.Context) (*Station, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().Station.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withStation sets the old Station of the mutation. +func withStation(node *Station) stationOption { + return func(m *StationMutation) { + m.oldValue = func(context.Context) (*Station, 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 StationMutation) 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 StationMutation) 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 Station entities. +func (m *StationMutation) 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 *StationMutation) 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 *StationMutation) 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().Station.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetStationNo sets the "stationNo" field. +func (m *StationMutation) SetStationNo(i int) { + m.stationNo = &i + m.addstationNo = nil +} + +// StationNo returns the value of the "stationNo" field in the mutation. +func (m *StationMutation) StationNo() (r int, exists bool) { + v := m.stationNo + if v == nil { + return + } + return *v, true +} + +// OldStationNo returns the old "stationNo" field's value of the Station entity. +// If the Station 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 *StationMutation) OldStationNo(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStationNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStationNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStationNo: %w", err) + } + return oldValue.StationNo, nil +} + +// AddStationNo adds i to the "stationNo" field. +func (m *StationMutation) AddStationNo(i int) { + if m.addstationNo != nil { + *m.addstationNo += i + } else { + m.addstationNo = &i + } +} + +// AddedStationNo returns the value that was added to the "stationNo" field in this mutation. +func (m *StationMutation) AddedStationNo() (r int, exists bool) { + v := m.addstationNo + if v == nil { + return + } + return *v, true +} + +// ResetStationNo resets all changes to the "stationNo" field. +func (m *StationMutation) ResetStationNo() { + m.stationNo = nil + m.addstationNo = nil +} + +// SetName sets the "name" field. +func (m *StationMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *StationMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the Station entity. +// If the Station 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 *StationMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *StationMutation) ResetName() { + m.name = nil +} + +// SetFlowId sets the "flowId" field. +func (m *StationMutation) SetFlowId(i int) { + m.flowId = &i + m.addflowId = nil +} + +// FlowId returns the value of the "flowId" field in the mutation. +func (m *StationMutation) FlowId() (r int, exists bool) { + v := m.flowId + if v == nil { + return + } + return *v, true +} + +// OldFlowId returns the old "flowId" field's value of the Station entity. +// If the Station 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 *StationMutation) OldFlowId(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFlowId is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFlowId requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFlowId: %w", err) + } + return oldValue.FlowId, nil +} + +// AddFlowId adds i to the "flowId" field. +func (m *StationMutation) AddFlowId(i int) { + if m.addflowId != nil { + *m.addflowId += i + } else { + m.addflowId = &i + } +} + +// AddedFlowId returns the value that was added to the "flowId" field in this mutation. +func (m *StationMutation) AddedFlowId() (r int, exists bool) { + v := m.addflowId + if v == nil { + return + } + return *v, true +} + +// ClearFlowId clears the value of the "flowId" field. +func (m *StationMutation) ClearFlowId() { + m.flowId = nil + m.addflowId = nil + m.clearedFields[station.FieldFlowId] = struct{}{} +} + +// FlowIdCleared returns if the "flowId" field was cleared in this mutation. +func (m *StationMutation) FlowIdCleared() bool { + _, ok := m.clearedFields[station.FieldFlowId] + return ok +} + +// ResetFlowId resets all changes to the "flowId" field. +func (m *StationMutation) ResetFlowId() { + m.flowId = nil + m.addflowId = nil + delete(m.clearedFields, station.FieldFlowId) +} + +// SetStatus sets the "status" field. +func (m *StationMutation) SetStatus(s string) { + m.status = &s +} + +// Status returns the value of the "status" field in the mutation. +func (m *StationMutation) Status() (r string, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the Station entity. +// If the Station 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 *StationMutation) OldStatus(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *StationMutation) ResetStatus() { + m.status = nil +} + +// SetCreatedAt sets the "createdAt" field. +func (m *StationMutation) SetCreatedAt(t time.Time) { + m.createdAt = &t +} + +// CreatedAt returns the value of the "createdAt" field in the mutation. +func (m *StationMutation) 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 Station entity. +// If the Station 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 *StationMutation) 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 *StationMutation) ResetCreatedAt() { + m.createdAt = nil +} + +// Where appends a list predicates to the StationMutation builder. +func (m *StationMutation) Where(ps ...predicate.Station) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the StationMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *StationMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.Station, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *StationMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *StationMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (Station). +func (m *StationMutation) 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 *StationMutation) Fields() []string { + fields := make([]string, 0, 5) + if m.stationNo != nil { + fields = append(fields, station.FieldStationNo) + } + if m.name != nil { + fields = append(fields, station.FieldName) + } + if m.flowId != nil { + fields = append(fields, station.FieldFlowId) + } + if m.status != nil { + fields = append(fields, station.FieldStatus) + } + if m.createdAt != nil { + fields = append(fields, station.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 *StationMutation) Field(name string) (ent.Value, bool) { + switch name { + case station.FieldStationNo: + return m.StationNo() + case station.FieldName: + return m.Name() + case station.FieldFlowId: + return m.FlowId() + case station.FieldStatus: + return m.Status() + case station.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 *StationMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case station.FieldStationNo: + return m.OldStationNo(ctx) + case station.FieldName: + return m.OldName(ctx) + case station.FieldFlowId: + return m.OldFlowId(ctx) + case station.FieldStatus: + return m.OldStatus(ctx) + case station.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown Station 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 *StationMutation) SetField(name string, value ent.Value) error { + switch name { + case station.FieldStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStationNo(v) + return nil + case station.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case station.FieldFlowId: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFlowId(v) + return nil + case station.FieldStatus: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case station.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 Station field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *StationMutation) AddedFields() []string { + var fields []string + if m.addstationNo != nil { + fields = append(fields, station.FieldStationNo) + } + if m.addflowId != nil { + fields = append(fields, station.FieldFlowId) + } + 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 *StationMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case station.FieldStationNo: + return m.AddedStationNo() + case station.FieldFlowId: + return m.AddedFlowId() + } + 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 *StationMutation) AddField(name string, value ent.Value) error { + switch name { + case station.FieldStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddStationNo(v) + return nil + case station.FieldFlowId: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddFlowId(v) + return nil + } + return fmt.Errorf("unknown Station numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *StationMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(station.FieldFlowId) { + fields = append(fields, station.FieldFlowId) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *StationMutation) 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 *StationMutation) ClearField(name string) error { + switch name { + case station.FieldFlowId: + m.ClearFlowId() + return nil + } + return fmt.Errorf("unknown Station 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 *StationMutation) ResetField(name string) error { + switch name { + case station.FieldStationNo: + m.ResetStationNo() + return nil + case station.FieldName: + m.ResetName() + return nil + case station.FieldFlowId: + m.ResetFlowId() + return nil + case station.FieldStatus: + m.ResetStatus() + return nil + case station.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown Station field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *StationMutation) 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 *StationMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *StationMutation) 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 *StationMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *StationMutation) 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 *StationMutation) 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 *StationMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown Station 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 *StationMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown Station edge %s", name) +} + // StationProcessMutation represents an operation that mutates the StationProcess nodes in the graph. type StationProcessMutation struct { config @@ -13302,21 +15685,23 @@ func (m *TorqueRecordMutation) ResetEdge(name string) error { // UserMutation represents an operation that mutates the User nodes in the graph. type UserMutation struct { config - op Op - typ string - id *int - username *string - password *string - name *string - roleId *int - addroleId *int - status *string - createdAt *time.Time - updatedAt *time.Time - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*User, error) - predicates []predicate.User + op Op + typ string + id *int + username *string + password *string + name *string + roleId *int + addroleId *int + canLoginWorkstation *bool + workstationPassword *string + status *string + createdAt *time.Time + updatedAt *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*User, error) + predicates []predicate.User } var _ ent.Mutation = (*UserMutation)(nil) @@ -13601,6 +15986,91 @@ func (m *UserMutation) ResetRoleId() { delete(m.clearedFields, user.FieldRoleId) } +// SetCanLoginWorkstation sets the "canLoginWorkstation" field. +func (m *UserMutation) SetCanLoginWorkstation(b bool) { + m.canLoginWorkstation = &b +} + +// CanLoginWorkstation returns the value of the "canLoginWorkstation" field in the mutation. +func (m *UserMutation) CanLoginWorkstation() (r bool, exists bool) { + v := m.canLoginWorkstation + if v == nil { + return + } + return *v, true +} + +// OldCanLoginWorkstation returns the old "canLoginWorkstation" field's value of the User entity. +// If the User 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 *UserMutation) OldCanLoginWorkstation(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCanLoginWorkstation is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCanLoginWorkstation requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCanLoginWorkstation: %w", err) + } + return oldValue.CanLoginWorkstation, nil +} + +// ResetCanLoginWorkstation resets all changes to the "canLoginWorkstation" field. +func (m *UserMutation) ResetCanLoginWorkstation() { + m.canLoginWorkstation = nil +} + +// SetWorkstationPassword sets the "workstationPassword" field. +func (m *UserMutation) SetWorkstationPassword(s string) { + m.workstationPassword = &s +} + +// WorkstationPassword returns the value of the "workstationPassword" field in the mutation. +func (m *UserMutation) WorkstationPassword() (r string, exists bool) { + v := m.workstationPassword + if v == nil { + return + } + return *v, true +} + +// OldWorkstationPassword returns the old "workstationPassword" field's value of the User entity. +// If the User 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 *UserMutation) OldWorkstationPassword(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldWorkstationPassword is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldWorkstationPassword requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldWorkstationPassword: %w", err) + } + return oldValue.WorkstationPassword, nil +} + +// ClearWorkstationPassword clears the value of the "workstationPassword" field. +func (m *UserMutation) ClearWorkstationPassword() { + m.workstationPassword = nil + m.clearedFields[user.FieldWorkstationPassword] = struct{}{} +} + +// WorkstationPasswordCleared returns if the "workstationPassword" field was cleared in this mutation. +func (m *UserMutation) WorkstationPasswordCleared() bool { + _, ok := m.clearedFields[user.FieldWorkstationPassword] + return ok +} + +// ResetWorkstationPassword resets all changes to the "workstationPassword" field. +func (m *UserMutation) ResetWorkstationPassword() { + m.workstationPassword = nil + delete(m.clearedFields, user.FieldWorkstationPassword) +} + // SetStatus sets the "status" field. func (m *UserMutation) SetStatus(s string) { m.status = &s @@ -13756,7 +16226,7 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 7) + fields := make([]string, 0, 9) if m.username != nil { fields = append(fields, user.FieldUsername) } @@ -13769,6 +16239,12 @@ func (m *UserMutation) Fields() []string { if m.roleId != nil { fields = append(fields, user.FieldRoleId) } + if m.canLoginWorkstation != nil { + fields = append(fields, user.FieldCanLoginWorkstation) + } + if m.workstationPassword != nil { + fields = append(fields, user.FieldWorkstationPassword) + } if m.status != nil { fields = append(fields, user.FieldStatus) } @@ -13794,6 +16270,10 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { return m.Name() case user.FieldRoleId: return m.RoleId() + case user.FieldCanLoginWorkstation: + return m.CanLoginWorkstation() + case user.FieldWorkstationPassword: + return m.WorkstationPassword() case user.FieldStatus: return m.Status() case user.FieldCreatedAt: @@ -13817,6 +16297,10 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldName(ctx) case user.FieldRoleId: return m.OldRoleId(ctx) + case user.FieldCanLoginWorkstation: + return m.OldCanLoginWorkstation(ctx) + case user.FieldWorkstationPassword: + return m.OldWorkstationPassword(ctx) case user.FieldStatus: return m.OldStatus(ctx) case user.FieldCreatedAt: @@ -13860,6 +16344,20 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetRoleId(v) return nil + case user.FieldCanLoginWorkstation: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCanLoginWorkstation(v) + return nil + case user.FieldWorkstationPassword: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetWorkstationPassword(v) + return nil case user.FieldStatus: v, ok := value.(string) if !ok { @@ -13929,6 +16427,9 @@ func (m *UserMutation) ClearedFields() []string { if m.FieldCleared(user.FieldRoleId) { fields = append(fields, user.FieldRoleId) } + if m.FieldCleared(user.FieldWorkstationPassword) { + fields = append(fields, user.FieldWorkstationPassword) + } if m.FieldCleared(user.FieldUpdatedAt) { fields = append(fields, user.FieldUpdatedAt) } @@ -13949,6 +16450,9 @@ func (m *UserMutation) ClearField(name string) error { case user.FieldRoleId: m.ClearRoleId() return nil + case user.FieldWorkstationPassword: + m.ClearWorkstationPassword() + return nil case user.FieldUpdatedAt: m.ClearUpdatedAt() return nil @@ -13972,6 +16476,12 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldRoleId: m.ResetRoleId() return nil + case user.FieldCanLoginWorkstation: + m.ResetCanLoginWorkstation() + return nil + case user.FieldWorkstationPassword: + m.ResetWorkstationPassword() + return nil case user.FieldStatus: m.ResetStatus() return nil @@ -14033,6 +16543,515 @@ func (m *UserMutation) ResetEdge(name string) error { return fmt.Errorf("unknown User edge %s", name) } +// UserStationMutation represents an operation that mutates the UserStation nodes in the graph. +type UserStationMutation struct { + config + op Op + typ string + id *int + userId *int + adduserId *int + stationNo *int + addstationNo *int + createdAt *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*UserStation, error) + predicates []predicate.UserStation +} + +var _ ent.Mutation = (*UserStationMutation)(nil) + +// userstationOption allows management of the mutation configuration using functional options. +type userstationOption func(*UserStationMutation) + +// newUserStationMutation creates new mutation for the UserStation entity. +func newUserStationMutation(c config, op Op, opts ...userstationOption) *UserStationMutation { + m := &UserStationMutation{ + config: c, + op: op, + typ: TypeUserStation, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withUserStationID sets the ID field of the mutation. +func withUserStationID(id int) userstationOption { + return func(m *UserStationMutation) { + var ( + err error + once sync.Once + value *UserStation + ) + m.oldValue = func(ctx context.Context) (*UserStation, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().UserStation.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withUserStation sets the old UserStation of the mutation. +func withUserStation(node *UserStation) userstationOption { + return func(m *UserStationMutation) { + m.oldValue = func(context.Context) (*UserStation, 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 UserStationMutation) 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 UserStationMutation) 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 UserStation entities. +func (m *UserStationMutation) 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 *UserStationMutation) 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 *UserStationMutation) 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().UserStation.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetUserId sets the "userId" field. +func (m *UserStationMutation) SetUserId(i int) { + m.userId = &i + m.adduserId = nil +} + +// UserId returns the value of the "userId" field in the mutation. +func (m *UserStationMutation) UserId() (r int, exists bool) { + v := m.userId + if v == nil { + return + } + return *v, true +} + +// OldUserId returns the old "userId" field's value of the UserStation entity. +// If the UserStation 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 *UserStationMutation) OldUserId(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUserId is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUserId requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUserId: %w", err) + } + return oldValue.UserId, nil +} + +// AddUserId adds i to the "userId" field. +func (m *UserStationMutation) AddUserId(i int) { + if m.adduserId != nil { + *m.adduserId += i + } else { + m.adduserId = &i + } +} + +// AddedUserId returns the value that was added to the "userId" field in this mutation. +func (m *UserStationMutation) AddedUserId() (r int, exists bool) { + v := m.adduserId + if v == nil { + return + } + return *v, true +} + +// ResetUserId resets all changes to the "userId" field. +func (m *UserStationMutation) ResetUserId() { + m.userId = nil + m.adduserId = nil +} + +// SetStationNo sets the "stationNo" field. +func (m *UserStationMutation) SetStationNo(i int) { + m.stationNo = &i + m.addstationNo = nil +} + +// StationNo returns the value of the "stationNo" field in the mutation. +func (m *UserStationMutation) StationNo() (r int, exists bool) { + v := m.stationNo + if v == nil { + return + } + return *v, true +} + +// OldStationNo returns the old "stationNo" field's value of the UserStation entity. +// If the UserStation 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 *UserStationMutation) OldStationNo(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStationNo is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStationNo requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStationNo: %w", err) + } + return oldValue.StationNo, nil +} + +// AddStationNo adds i to the "stationNo" field. +func (m *UserStationMutation) AddStationNo(i int) { + if m.addstationNo != nil { + *m.addstationNo += i + } else { + m.addstationNo = &i + } +} + +// AddedStationNo returns the value that was added to the "stationNo" field in this mutation. +func (m *UserStationMutation) AddedStationNo() (r int, exists bool) { + v := m.addstationNo + if v == nil { + return + } + return *v, true +} + +// ResetStationNo resets all changes to the "stationNo" field. +func (m *UserStationMutation) ResetStationNo() { + m.stationNo = nil + m.addstationNo = nil +} + +// SetCreatedAt sets the "createdAt" field. +func (m *UserStationMutation) SetCreatedAt(t time.Time) { + m.createdAt = &t +} + +// CreatedAt returns the value of the "createdAt" field in the mutation. +func (m *UserStationMutation) 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 UserStation entity. +// If the UserStation 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 *UserStationMutation) 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 *UserStationMutation) ResetCreatedAt() { + m.createdAt = nil +} + +// Where appends a list predicates to the UserStationMutation builder. +func (m *UserStationMutation) Where(ps ...predicate.UserStation) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the UserStationMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *UserStationMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.UserStation, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *UserStationMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *UserStationMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (UserStation). +func (m *UserStationMutation) 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 *UserStationMutation) Fields() []string { + fields := make([]string, 0, 3) + if m.userId != nil { + fields = append(fields, userstation.FieldUserId) + } + if m.stationNo != nil { + fields = append(fields, userstation.FieldStationNo) + } + if m.createdAt != nil { + fields = append(fields, userstation.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 *UserStationMutation) Field(name string) (ent.Value, bool) { + switch name { + case userstation.FieldUserId: + return m.UserId() + case userstation.FieldStationNo: + return m.StationNo() + case userstation.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 *UserStationMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case userstation.FieldUserId: + return m.OldUserId(ctx) + case userstation.FieldStationNo: + return m.OldStationNo(ctx) + case userstation.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown UserStation 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 *UserStationMutation) SetField(name string, value ent.Value) error { + switch name { + case userstation.FieldUserId: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserId(v) + return nil + case userstation.FieldStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStationNo(v) + return nil + case userstation.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 UserStation field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *UserStationMutation) AddedFields() []string { + var fields []string + if m.adduserId != nil { + fields = append(fields, userstation.FieldUserId) + } + if m.addstationNo != nil { + fields = append(fields, userstation.FieldStationNo) + } + 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 *UserStationMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case userstation.FieldUserId: + return m.AddedUserId() + case userstation.FieldStationNo: + return m.AddedStationNo() + } + 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 *UserStationMutation) AddField(name string, value ent.Value) error { + switch name { + case userstation.FieldUserId: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUserId(v) + return nil + case userstation.FieldStationNo: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddStationNo(v) + return nil + } + return fmt.Errorf("unknown UserStation numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *UserStationMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *UserStationMutation) 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 *UserStationMutation) ClearField(name string) error { + return fmt.Errorf("unknown UserStation 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 *UserStationMutation) ResetField(name string) error { + switch name { + case userstation.FieldUserId: + m.ResetUserId() + return nil + case userstation.FieldStationNo: + m.ResetStationNo() + return nil + case userstation.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown UserStation field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *UserStationMutation) 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 *UserStationMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *UserStationMutation) 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 *UserStationMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *UserStationMutation) 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 *UserStationMutation) 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 *UserStationMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown UserStation 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 *UserStationMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown UserStation edge %s", name) +} + // WorkOrderMutation represents an operation that mutates the WorkOrder nodes in the graph. type WorkOrderMutation struct { config diff --git a/bj_power_mes/ent/predicate/predicate.go b/bj_power_mes/ent/predicate/predicate.go index 0aa320e..2524c59 100644 --- a/bj_power_mes/ent/predicate/predicate.go +++ b/bj_power_mes/ent/predicate/predicate.go @@ -18,6 +18,9 @@ type DailyPlan func(*sql.Selector) // EventLog is the predicate function for eventlog builders. type EventLog func(*sql.Selector) +// InspectionRecord is the predicate function for inspectionrecord builders. +type InspectionRecord func(*sql.Selector) + // MaterialRequest is the predicate function for materialrequest builders. type MaterialRequest func(*sql.Selector) @@ -27,6 +30,9 @@ type Permission func(*sql.Selector) // PlcSendLog is the predicate function for plcsendlog builders. type PlcSendLog func(*sql.Selector) +// ProcessFlow is the predicate function for processflow builders. +type ProcessFlow func(*sql.Selector) + // ProcessStep is the predicate function for processstep builders. type ProcessStep func(*sql.Selector) @@ -42,6 +48,9 @@ type ScanRecord func(*sql.Selector) // SemiFlow is the predicate function for semiflow builders. type SemiFlow func(*sql.Selector) +// Station is the predicate function for station builders. +type Station func(*sql.Selector) + // StationProcess is the predicate function for stationprocess builders. type StationProcess func(*sql.Selector) @@ -57,6 +66,9 @@ type TorqueRecord func(*sql.Selector) // User is the predicate function for user builders. type User func(*sql.Selector) +// UserStation is the predicate function for userstation builders. +type UserStation func(*sql.Selector) + // WorkOrder is the predicate function for workorder builders. type WorkOrder func(*sql.Selector) diff --git a/bj_power_mes/ent/processflow.go b/bj_power_mes/ent/processflow.go new file mode 100644 index 0000000..0db225e --- /dev/null +++ b/bj_power_mes/ent/processflow.go @@ -0,0 +1,175 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/processflow" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// ProcessFlow is the model entity for the ProcessFlow schema. +type ProcessFlow struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 流程名称,如 工序3_2026版 + Name string `json:"name,omitempty"` + // 工序编号 1..12 + ProcessCode int `json:"processCode,omitempty"` + // 工艺图纸文件名 + PdfFile string `json:"pdfFile,omitempty"` + // Status holds the value of the "status" field. + Status string `json:"status,omitempty"` + // Remark holds the value of the "remark" field. + Remark string `json:"remark,omitempty"` + // CreatedAt holds the value of the "createdAt" field. + CreatedAt time.Time `json:"createdAt,omitempty"` + // UpdatedAt holds the value of the "updatedAt" field. + UpdatedAt *time.Time `json:"updatedAt,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*ProcessFlow) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case processflow.FieldID, processflow.FieldProcessCode: + values[i] = new(sql.NullInt64) + case processflow.FieldName, processflow.FieldPdfFile, processflow.FieldStatus, processflow.FieldRemark: + values[i] = new(sql.NullString) + case processflow.FieldCreatedAt, processflow.FieldUpdatedAt: + 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 ProcessFlow fields. +func (_m *ProcessFlow) 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 processflow.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 processflow.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case processflow.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 processflow.FieldPdfFile: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field pdfFile", values[i]) + } else if value.Valid { + _m.PdfFile = value.String + } + case processflow.FieldStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + _m.Status = value.String + } + case processflow.FieldRemark: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field remark", values[i]) + } else if value.Valid { + _m.Remark = value.String + } + case processflow.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 + } + case processflow.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updatedAt", values[i]) + } else if value.Valid { + _m.UpdatedAt = new(time.Time) + *_m.UpdatedAt = 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 ProcessFlow. +// This includes values selected through modifiers, order, etc. +func (_m *ProcessFlow) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this ProcessFlow. +// Note that you need to call ProcessFlow.Unwrap() before calling this method if this ProcessFlow +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *ProcessFlow) Update() *ProcessFlowUpdateOne { + return NewProcessFlowClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the ProcessFlow 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 *ProcessFlow) Unwrap() *ProcessFlow { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: ProcessFlow is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *ProcessFlow) String() string { + var builder strings.Builder + builder.WriteString("ProcessFlow(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("processCode=") + builder.WriteString(fmt.Sprintf("%v", _m.ProcessCode)) + builder.WriteString(", ") + builder.WriteString("pdfFile=") + builder.WriteString(_m.PdfFile) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(_m.Status) + builder.WriteString(", ") + builder.WriteString("remark=") + builder.WriteString(_m.Remark) + builder.WriteString(", ") + builder.WriteString("createdAt=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + if v := _m.UpdatedAt; v != nil { + builder.WriteString("updatedAt=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteByte(')') + return builder.String() +} + +// ProcessFlows is a parsable slice of ProcessFlow. +type ProcessFlows []*ProcessFlow diff --git a/bj_power_mes/ent/processflow/processflow.go b/bj_power_mes/ent/processflow/processflow.go new file mode 100644 index 0000000..2f7356c --- /dev/null +++ b/bj_power_mes/ent/processflow/processflow.go @@ -0,0 +1,122 @@ +// Code generated by ent, DO NOT EDIT. + +package processflow + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the processflow type in the database. + Label = "process_flow" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldProcessCode holds the string denoting the processcode field in the database. + FieldProcessCode = "process_code" + // FieldPdfFile holds the string denoting the pdffile field in the database. + FieldPdfFile = "pdf_file" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldRemark holds the string denoting the remark field in the database. + FieldRemark = "remark" + // FieldCreatedAt holds the string denoting the createdat field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updatedat field in the database. + FieldUpdatedAt = "updated_at" + // Table holds the table name of the processflow in the database. + Table = "process_flow" +) + +// Columns holds all SQL columns for processflow fields. +var Columns = []string{ + FieldID, + FieldName, + FieldProcessCode, + FieldPdfFile, + FieldStatus, + FieldRemark, + FieldCreatedAt, + FieldUpdatedAt, +} + +// 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 ( + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DefaultPdfFile holds the default value on creation for the "pdfFile" field. + DefaultPdfFile string + // PdfFileValidator is a validator for the "pdfFile" field. It is called by the builders before save. + PdfFileValidator func(string) error + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus string + // StatusValidator is a validator for the "status" field. It is called by the builders before save. + StatusValidator func(string) error + // DefaultRemark holds the default value on creation for the "remark" field. + DefaultRemark string + // RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + RemarkValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + DefaultCreatedAt func() time.Time + // DefaultUpdatedAt holds the default value on creation for the "updatedAt" field. + DefaultUpdatedAt func() time.Time + // UpdateDefaultUpdatedAt holds the default value on update for the "updatedAt" field. + UpdateDefaultUpdatedAt 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 ProcessFlow 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() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByProcessCode orders the results by the processCode field. +func ByProcessCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldProcessCode, opts...).ToFunc() +} + +// ByPdfFile orders the results by the pdfFile field. +func ByPdfFile(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPdfFile, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByRemark orders the results by the remark field. +func ByRemark(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRemark, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the createdAt field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updatedAt field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} diff --git a/bj_power_mes/ent/processflow/where.go b/bj_power_mes/ent/processflow/where.go new file mode 100644 index 0000000..991b002 --- /dev/null +++ b/bj_power_mes/ent/processflow/where.go @@ -0,0 +1,495 @@ +// Code generated by ent, DO NOT EDIT. + +package processflow + +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.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldID, id)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldName, v)) +} + +// ProcessCode applies equality check predicate on the "processCode" field. It's identical to ProcessCodeEQ. +func ProcessCode(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldProcessCode, v)) +} + +// PdfFile applies equality check predicate on the "pdfFile" field. It's identical to PdfFileEQ. +func PdfFile(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldPdfFile, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldStatus, v)) +} + +// Remark applies equality check predicate on the "remark" field. It's identical to RemarkEQ. +func Remark(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldRemark, v)) +} + +// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updatedAt" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContainsFold(FieldName, v)) +} + +// ProcessCodeEQ applies the EQ predicate on the "processCode" field. +func ProcessCodeEQ(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldProcessCode, v)) +} + +// ProcessCodeNEQ applies the NEQ predicate on the "processCode" field. +func ProcessCodeNEQ(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldProcessCode, v)) +} + +// ProcessCodeIn applies the In predicate on the "processCode" field. +func ProcessCodeIn(vs ...int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldProcessCode, vs...)) +} + +// ProcessCodeNotIn applies the NotIn predicate on the "processCode" field. +func ProcessCodeNotIn(vs ...int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldProcessCode, vs...)) +} + +// ProcessCodeGT applies the GT predicate on the "processCode" field. +func ProcessCodeGT(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldProcessCode, v)) +} + +// ProcessCodeGTE applies the GTE predicate on the "processCode" field. +func ProcessCodeGTE(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldProcessCode, v)) +} + +// ProcessCodeLT applies the LT predicate on the "processCode" field. +func ProcessCodeLT(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldProcessCode, v)) +} + +// ProcessCodeLTE applies the LTE predicate on the "processCode" field. +func ProcessCodeLTE(v int) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldProcessCode, v)) +} + +// PdfFileEQ applies the EQ predicate on the "pdfFile" field. +func PdfFileEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldPdfFile, v)) +} + +// PdfFileNEQ applies the NEQ predicate on the "pdfFile" field. +func PdfFileNEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldPdfFile, v)) +} + +// PdfFileIn applies the In predicate on the "pdfFile" field. +func PdfFileIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldPdfFile, vs...)) +} + +// PdfFileNotIn applies the NotIn predicate on the "pdfFile" field. +func PdfFileNotIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldPdfFile, vs...)) +} + +// PdfFileGT applies the GT predicate on the "pdfFile" field. +func PdfFileGT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldPdfFile, v)) +} + +// PdfFileGTE applies the GTE predicate on the "pdfFile" field. +func PdfFileGTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldPdfFile, v)) +} + +// PdfFileLT applies the LT predicate on the "pdfFile" field. +func PdfFileLT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldPdfFile, v)) +} + +// PdfFileLTE applies the LTE predicate on the "pdfFile" field. +func PdfFileLTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldPdfFile, v)) +} + +// PdfFileContains applies the Contains predicate on the "pdfFile" field. +func PdfFileContains(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContains(FieldPdfFile, v)) +} + +// PdfFileHasPrefix applies the HasPrefix predicate on the "pdfFile" field. +func PdfFileHasPrefix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasPrefix(FieldPdfFile, v)) +} + +// PdfFileHasSuffix applies the HasSuffix predicate on the "pdfFile" field. +func PdfFileHasSuffix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasSuffix(FieldPdfFile, v)) +} + +// PdfFileEqualFold applies the EqualFold predicate on the "pdfFile" field. +func PdfFileEqualFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEqualFold(FieldPdfFile, v)) +} + +// PdfFileContainsFold applies the ContainsFold predicate on the "pdfFile" field. +func PdfFileContainsFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContainsFold(FieldPdfFile, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldStatus, v)) +} + +// StatusContains applies the Contains predicate on the "status" field. +func StatusContains(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContains(FieldStatus, v)) +} + +// StatusHasPrefix applies the HasPrefix predicate on the "status" field. +func StatusHasPrefix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasPrefix(FieldStatus, v)) +} + +// StatusHasSuffix applies the HasSuffix predicate on the "status" field. +func StatusHasSuffix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasSuffix(FieldStatus, v)) +} + +// StatusEqualFold applies the EqualFold predicate on the "status" field. +func StatusEqualFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEqualFold(FieldStatus, v)) +} + +// StatusContainsFold applies the ContainsFold predicate on the "status" field. +func StatusContainsFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContainsFold(FieldStatus, v)) +} + +// RemarkEQ applies the EQ predicate on the "remark" field. +func RemarkEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldRemark, v)) +} + +// RemarkNEQ applies the NEQ predicate on the "remark" field. +func RemarkNEQ(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldRemark, v)) +} + +// RemarkIn applies the In predicate on the "remark" field. +func RemarkIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldRemark, vs...)) +} + +// RemarkNotIn applies the NotIn predicate on the "remark" field. +func RemarkNotIn(vs ...string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldRemark, vs...)) +} + +// RemarkGT applies the GT predicate on the "remark" field. +func RemarkGT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldRemark, v)) +} + +// RemarkGTE applies the GTE predicate on the "remark" field. +func RemarkGTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldRemark, v)) +} + +// RemarkLT applies the LT predicate on the "remark" field. +func RemarkLT(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldRemark, v)) +} + +// RemarkLTE applies the LTE predicate on the "remark" field. +func RemarkLTE(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldRemark, v)) +} + +// RemarkContains applies the Contains predicate on the "remark" field. +func RemarkContains(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContains(FieldRemark, v)) +} + +// RemarkHasPrefix applies the HasPrefix predicate on the "remark" field. +func RemarkHasPrefix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasPrefix(FieldRemark, v)) +} + +// RemarkHasSuffix applies the HasSuffix predicate on the "remark" field. +func RemarkHasSuffix(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldHasSuffix(FieldRemark, v)) +} + +// RemarkEqualFold applies the EqualFold predicate on the "remark" field. +func RemarkEqualFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEqualFold(FieldRemark, v)) +} + +// RemarkContainsFold applies the ContainsFold predicate on the "remark" field. +func RemarkContainsFold(v string) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldContainsFold(FieldRemark, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +func CreatedAtEQ(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +func CreatedAtNEQ(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "createdAt" field. +func CreatedAtIn(vs ...time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +func CreatedAtNotIn(vs ...time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "createdAt" field. +func CreatedAtGT(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +func CreatedAtGTE(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "createdAt" field. +func CreatedAtLT(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +func CreatedAtLTE(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updatedAt" field. +func UpdatedAtEQ(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updatedAt" field. +func UpdatedAtNEQ(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updatedAt" field. +func UpdatedAtIn(vs ...time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updatedAt" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updatedAt" field. +func UpdatedAtGT(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updatedAt" field. +func UpdatedAtGTE(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updatedAt" field. +func UpdatedAtLT(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updatedAt" field. +func UpdatedAtLTE(v time.Time) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// UpdatedAtIsNil applies the IsNil predicate on the "updatedAt" field. +func UpdatedAtIsNil() predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldIsNull(FieldUpdatedAt)) +} + +// UpdatedAtNotNil applies the NotNil predicate on the "updatedAt" field. +func UpdatedAtNotNil() predicate.ProcessFlow { + return predicate.ProcessFlow(sql.FieldNotNull(FieldUpdatedAt)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.ProcessFlow) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.ProcessFlow) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.ProcessFlow) predicate.ProcessFlow { + return predicate.ProcessFlow(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/processflow_create.go b/bj_power_mes/ent/processflow_create.go new file mode 100644 index 0000000..a3dcfd3 --- /dev/null +++ b/bj_power_mes/ent/processflow_create.go @@ -0,0 +1,362 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/processflow" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ProcessFlowCreate is the builder for creating a ProcessFlow entity. +type ProcessFlowCreate struct { + config + mutation *ProcessFlowMutation + hooks []Hook +} + +// SetName sets the "name" field. +func (_c *ProcessFlowCreate) SetName(v string) *ProcessFlowCreate { + _c.mutation.SetName(v) + return _c +} + +// SetProcessCode sets the "processCode" field. +func (_c *ProcessFlowCreate) SetProcessCode(v int) *ProcessFlowCreate { + _c.mutation.SetProcessCode(v) + return _c +} + +// SetPdfFile sets the "pdfFile" field. +func (_c *ProcessFlowCreate) SetPdfFile(v string) *ProcessFlowCreate { + _c.mutation.SetPdfFile(v) + return _c +} + +// SetNillablePdfFile sets the "pdfFile" field if the given value is not nil. +func (_c *ProcessFlowCreate) SetNillablePdfFile(v *string) *ProcessFlowCreate { + if v != nil { + _c.SetPdfFile(*v) + } + return _c +} + +// SetStatus sets the "status" field. +func (_c *ProcessFlowCreate) SetStatus(v string) *ProcessFlowCreate { + _c.mutation.SetStatus(v) + return _c +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_c *ProcessFlowCreate) SetNillableStatus(v *string) *ProcessFlowCreate { + if v != nil { + _c.SetStatus(*v) + } + return _c +} + +// SetRemark sets the "remark" field. +func (_c *ProcessFlowCreate) SetRemark(v string) *ProcessFlowCreate { + _c.mutation.SetRemark(v) + return _c +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_c *ProcessFlowCreate) SetNillableRemark(v *string) *ProcessFlowCreate { + if v != nil { + _c.SetRemark(*v) + } + return _c +} + +// SetCreatedAt sets the "createdAt" field. +func (_c *ProcessFlowCreate) SetCreatedAt(v time.Time) *ProcessFlowCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (_c *ProcessFlowCreate) SetNillableCreatedAt(v *time.Time) *ProcessFlowCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetUpdatedAt sets the "updatedAt" field. +func (_c *ProcessFlowCreate) SetUpdatedAt(v time.Time) *ProcessFlowCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil. +func (_c *ProcessFlowCreate) SetNillableUpdatedAt(v *time.Time) *ProcessFlowCreate { + if v != nil { + _c.SetUpdatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *ProcessFlowCreate) SetID(v int) *ProcessFlowCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the ProcessFlowMutation object of the builder. +func (_c *ProcessFlowCreate) Mutation() *ProcessFlowMutation { + return _c.mutation +} + +// Save creates the ProcessFlow in the database. +func (_c *ProcessFlowCreate) Save(ctx context.Context) (*ProcessFlow, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *ProcessFlowCreate) SaveX(ctx context.Context) *ProcessFlow { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ProcessFlowCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ProcessFlowCreate) 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 *ProcessFlowCreate) defaults() { + if _, ok := _c.mutation.PdfFile(); !ok { + v := processflow.DefaultPdfFile + _c.mutation.SetPdfFile(v) + } + if _, ok := _c.mutation.Status(); !ok { + v := processflow.DefaultStatus + _c.mutation.SetStatus(v) + } + if _, ok := _c.mutation.Remark(); !ok { + v := processflow.DefaultRemark + _c.mutation.SetRemark(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := processflow.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + v := processflow.DefaultUpdatedAt() + _c.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *ProcessFlowCreate) check() error { + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "ProcessFlow.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := processflow.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.name": %w`, err)} + } + } + if _, ok := _c.mutation.ProcessCode(); !ok { + return &ValidationError{Name: "processCode", err: errors.New(`ent: missing required field "ProcessFlow.processCode"`)} + } + if _, ok := _c.mutation.PdfFile(); !ok { + return &ValidationError{Name: "pdfFile", err: errors.New(`ent: missing required field "ProcessFlow.pdfFile"`)} + } + if v, ok := _c.mutation.PdfFile(); ok { + if err := processflow.PdfFileValidator(v); err != nil { + return &ValidationError{Name: "pdfFile", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.pdfFile": %w`, err)} + } + } + if _, ok := _c.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "ProcessFlow.status"`)} + } + if v, ok := _c.mutation.Status(); ok { + if err := processflow.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.status": %w`, err)} + } + } + if _, ok := _c.mutation.Remark(); !ok { + return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "ProcessFlow.remark"`)} + } + if v, ok := _c.mutation.Remark(); ok { + if err := processflow.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.remark": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "ProcessFlow.createdAt"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := processflow.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.id": %w`, err)} + } + } + return nil +} + +func (_c *ProcessFlowCreate) sqlSave(ctx context.Context) (*ProcessFlow, 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 *ProcessFlowCreate) createSpec() (*ProcessFlow, *sqlgraph.CreateSpec) { + var ( + _node = &ProcessFlow{config: _c.config} + _spec = sqlgraph.NewCreateSpec(processflow.Table, sqlgraph.NewFieldSpec(processflow.FieldID, field.TypeInt)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(processflow.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.ProcessCode(); ok { + _spec.SetField(processflow.FieldProcessCode, field.TypeInt, value) + _node.ProcessCode = value + } + if value, ok := _c.mutation.PdfFile(); ok { + _spec.SetField(processflow.FieldPdfFile, field.TypeString, value) + _node.PdfFile = value + } + if value, ok := _c.mutation.Status(); ok { + _spec.SetField(processflow.FieldStatus, field.TypeString, value) + _node.Status = value + } + if value, ok := _c.mutation.Remark(); ok { + _spec.SetField(processflow.FieldRemark, field.TypeString, value) + _node.Remark = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(processflow.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(processflow.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = &value + } + return _node, _spec +} + +// ProcessFlowCreateBulk is the builder for creating many ProcessFlow entities in bulk. +type ProcessFlowCreateBulk struct { + config + err error + builders []*ProcessFlowCreate +} + +// Save creates the ProcessFlow entities in the database. +func (_c *ProcessFlowCreateBulk) Save(ctx context.Context) ([]*ProcessFlow, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*ProcessFlow, 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.(*ProcessFlowMutation) + 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 *ProcessFlowCreateBulk) SaveX(ctx context.Context) []*ProcessFlow { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *ProcessFlowCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *ProcessFlowCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/processflow_delete.go b/bj_power_mes/ent/processflow_delete.go new file mode 100644 index 0000000..b2f8f8c --- /dev/null +++ b/bj_power_mes/ent/processflow_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/processflow" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ProcessFlowDelete is the builder for deleting a ProcessFlow entity. +type ProcessFlowDelete struct { + config + hooks []Hook + mutation *ProcessFlowMutation +} + +// Where appends a list predicates to the ProcessFlowDelete builder. +func (_d *ProcessFlowDelete) Where(ps ...predicate.ProcessFlow) *ProcessFlowDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *ProcessFlowDelete) 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 *ProcessFlowDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *ProcessFlowDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(processflow.Table, sqlgraph.NewFieldSpec(processflow.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 +} + +// ProcessFlowDeleteOne is the builder for deleting a single ProcessFlow entity. +type ProcessFlowDeleteOne struct { + _d *ProcessFlowDelete +} + +// Where appends a list predicates to the ProcessFlowDelete builder. +func (_d *ProcessFlowDeleteOne) Where(ps ...predicate.ProcessFlow) *ProcessFlowDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *ProcessFlowDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{processflow.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *ProcessFlowDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/processflow_query.go b/bj_power_mes/ent/processflow_query.go new file mode 100644 index 0000000..544abaf --- /dev/null +++ b/bj_power_mes/ent/processflow_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/processflow" + "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" +) + +// ProcessFlowQuery is the builder for querying ProcessFlow entities. +type ProcessFlowQuery struct { + config + ctx *QueryContext + order []processflow.OrderOption + inters []Interceptor + predicates []predicate.ProcessFlow + 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 ProcessFlowQuery builder. +func (_q *ProcessFlowQuery) Where(ps ...predicate.ProcessFlow) *ProcessFlowQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *ProcessFlowQuery) Limit(limit int) *ProcessFlowQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *ProcessFlowQuery) Offset(offset int) *ProcessFlowQuery { + _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 *ProcessFlowQuery) Unique(unique bool) *ProcessFlowQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *ProcessFlowQuery) Order(o ...processflow.OrderOption) *ProcessFlowQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first ProcessFlow entity from the query. +// Returns a *NotFoundError when no ProcessFlow was found. +func (_q *ProcessFlowQuery) First(ctx context.Context) (*ProcessFlow, 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{processflow.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *ProcessFlowQuery) FirstX(ctx context.Context) *ProcessFlow { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first ProcessFlow ID from the query. +// Returns a *NotFoundError when no ProcessFlow ID was found. +func (_q *ProcessFlowQuery) 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{processflow.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *ProcessFlowQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single ProcessFlow entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one ProcessFlow entity is found. +// Returns a *NotFoundError when no ProcessFlow entities are found. +func (_q *ProcessFlowQuery) Only(ctx context.Context) (*ProcessFlow, 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{processflow.Label} + default: + return nil, &NotSingularError{processflow.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *ProcessFlowQuery) OnlyX(ctx context.Context) *ProcessFlow { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only ProcessFlow ID in the query. +// Returns a *NotSingularError when more than one ProcessFlow ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *ProcessFlowQuery) 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{processflow.Label} + default: + err = &NotSingularError{processflow.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *ProcessFlowQuery) 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 ProcessFlows. +func (_q *ProcessFlowQuery) All(ctx context.Context) ([]*ProcessFlow, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*ProcessFlow, *ProcessFlowQuery]() + return withInterceptors[[]*ProcessFlow](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *ProcessFlowQuery) AllX(ctx context.Context) []*ProcessFlow { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of ProcessFlow IDs. +func (_q *ProcessFlowQuery) 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(processflow.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *ProcessFlowQuery) 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 *ProcessFlowQuery) 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[*ProcessFlowQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *ProcessFlowQuery) 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 *ProcessFlowQuery) 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 *ProcessFlowQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the ProcessFlowQuery 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 *ProcessFlowQuery) Clone() *ProcessFlowQuery { + if _q == nil { + return nil + } + return &ProcessFlowQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]processflow.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.ProcessFlow{}, _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 { +// Name string `json:"name,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.ProcessFlow.Query(). +// GroupBy(processflow.FieldName). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *ProcessFlowQuery) GroupBy(field string, fields ...string) *ProcessFlowGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &ProcessFlowGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = processflow.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 { +// Name string `json:"name,omitempty"` +// } +// +// client.ProcessFlow.Query(). +// Select(processflow.FieldName). +// Scan(ctx, &v) +func (_q *ProcessFlowQuery) Select(fields ...string) *ProcessFlowSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &ProcessFlowSelect{ProcessFlowQuery: _q} + sbuild.label = processflow.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a ProcessFlowSelect configured with the given aggregations. +func (_q *ProcessFlowQuery) Aggregate(fns ...AggregateFunc) *ProcessFlowSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *ProcessFlowQuery) 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 !processflow.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 *ProcessFlowQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ProcessFlow, error) { + var ( + nodes = []*ProcessFlow{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*ProcessFlow).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &ProcessFlow{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 *ProcessFlowQuery) 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 *ProcessFlowQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(processflow.Table, processflow.Columns, sqlgraph.NewFieldSpec(processflow.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, processflow.FieldID) + for i := range fields { + if fields[i] != processflow.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 *ProcessFlowQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(processflow.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = processflow.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 *ProcessFlowQuery) ForUpdate(opts ...sql.LockOption) *ProcessFlowQuery { + 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 *ProcessFlowQuery) ForShare(opts ...sql.LockOption) *ProcessFlowQuery { + 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 *ProcessFlowQuery) Modify(modifiers ...func(s *sql.Selector)) *ProcessFlowSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// ProcessFlowGroupBy is the group-by builder for ProcessFlow entities. +type ProcessFlowGroupBy struct { + selector + build *ProcessFlowQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *ProcessFlowGroupBy) Aggregate(fns ...AggregateFunc) *ProcessFlowGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *ProcessFlowGroupBy) 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[*ProcessFlowQuery, *ProcessFlowGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *ProcessFlowGroupBy) sqlScan(ctx context.Context, root *ProcessFlowQuery, 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) +} + +// ProcessFlowSelect is the builder for selecting fields of ProcessFlow entities. +type ProcessFlowSelect struct { + *ProcessFlowQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *ProcessFlowSelect) Aggregate(fns ...AggregateFunc) *ProcessFlowSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *ProcessFlowSelect) 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[*ProcessFlowQuery, *ProcessFlowSelect](ctx, _s.ProcessFlowQuery, _s, _s.inters, v) +} + +func (_s *ProcessFlowSelect) sqlScan(ctx context.Context, root *ProcessFlowQuery, 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 *ProcessFlowSelect) Modify(modifiers ...func(s *sql.Selector)) *ProcessFlowSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/processflow_update.go b/bj_power_mes/ent/processflow_update.go new file mode 100644 index 0000000..8e1500d --- /dev/null +++ b/bj_power_mes/ent/processflow_update.go @@ -0,0 +1,492 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/processflow" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// ProcessFlowUpdate is the builder for updating ProcessFlow entities. +type ProcessFlowUpdate struct { + config + hooks []Hook + mutation *ProcessFlowMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the ProcessFlowUpdate builder. +func (_u *ProcessFlowUpdate) Where(ps ...predicate.ProcessFlow) *ProcessFlowUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetName sets the "name" field. +func (_u *ProcessFlowUpdate) SetName(v string) *ProcessFlowUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *ProcessFlowUpdate) SetNillableName(v *string) *ProcessFlowUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetProcessCode sets the "processCode" field. +func (_u *ProcessFlowUpdate) SetProcessCode(v int) *ProcessFlowUpdate { + _u.mutation.ResetProcessCode() + _u.mutation.SetProcessCode(v) + return _u +} + +// SetNillableProcessCode sets the "processCode" field if the given value is not nil. +func (_u *ProcessFlowUpdate) SetNillableProcessCode(v *int) *ProcessFlowUpdate { + if v != nil { + _u.SetProcessCode(*v) + } + return _u +} + +// AddProcessCode adds value to the "processCode" field. +func (_u *ProcessFlowUpdate) AddProcessCode(v int) *ProcessFlowUpdate { + _u.mutation.AddProcessCode(v) + return _u +} + +// SetPdfFile sets the "pdfFile" field. +func (_u *ProcessFlowUpdate) SetPdfFile(v string) *ProcessFlowUpdate { + _u.mutation.SetPdfFile(v) + return _u +} + +// SetNillablePdfFile sets the "pdfFile" field if the given value is not nil. +func (_u *ProcessFlowUpdate) SetNillablePdfFile(v *string) *ProcessFlowUpdate { + if v != nil { + _u.SetPdfFile(*v) + } + return _u +} + +// SetStatus sets the "status" field. +func (_u *ProcessFlowUpdate) SetStatus(v string) *ProcessFlowUpdate { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *ProcessFlowUpdate) SetNillableStatus(v *string) *ProcessFlowUpdate { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *ProcessFlowUpdate) SetRemark(v string) *ProcessFlowUpdate { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *ProcessFlowUpdate) SetNillableRemark(v *string) *ProcessFlowUpdate { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// SetUpdatedAt sets the "updatedAt" field. +func (_u *ProcessFlowUpdate) SetUpdatedAt(v time.Time) *ProcessFlowUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// ClearUpdatedAt clears the value of the "updatedAt" field. +func (_u *ProcessFlowUpdate) ClearUpdatedAt() *ProcessFlowUpdate { + _u.mutation.ClearUpdatedAt() + return _u +} + +// Mutation returns the ProcessFlowMutation object of the builder. +func (_u *ProcessFlowUpdate) Mutation() *ProcessFlowMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *ProcessFlowUpdate) Save(ctx context.Context) (int, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ProcessFlowUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *ProcessFlowUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ProcessFlowUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ProcessFlowUpdate) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() { + v := processflow.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ProcessFlowUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := processflow.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.name": %w`, err)} + } + } + if v, ok := _u.mutation.PdfFile(); ok { + if err := processflow.PdfFileValidator(v); err != nil { + return &ValidationError{Name: "pdfFile", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.pdfFile": %w`, err)} + } + } + if v, ok := _u.mutation.Status(); ok { + if err := processflow.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.status": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := processflow.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.remark": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *ProcessFlowUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProcessFlowUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *ProcessFlowUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(processflow.Table, processflow.Columns, sqlgraph.NewFieldSpec(processflow.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.Name(); ok { + _spec.SetField(processflow.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.ProcessCode(); ok { + _spec.SetField(processflow.FieldProcessCode, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedProcessCode(); ok { + _spec.AddField(processflow.FieldProcessCode, field.TypeInt, value) + } + if value, ok := _u.mutation.PdfFile(); ok { + _spec.SetField(processflow.FieldPdfFile, field.TypeString, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(processflow.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(processflow.FieldRemark, field.TypeString, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(processflow.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.UpdatedAtCleared() { + _spec.ClearField(processflow.FieldUpdatedAt, field.TypeTime) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{processflow.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// ProcessFlowUpdateOne is the builder for updating a single ProcessFlow entity. +type ProcessFlowUpdateOne struct { + config + fields []string + hooks []Hook + mutation *ProcessFlowMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetName sets the "name" field. +func (_u *ProcessFlowUpdateOne) SetName(v string) *ProcessFlowUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *ProcessFlowUpdateOne) SetNillableName(v *string) *ProcessFlowUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetProcessCode sets the "processCode" field. +func (_u *ProcessFlowUpdateOne) SetProcessCode(v int) *ProcessFlowUpdateOne { + _u.mutation.ResetProcessCode() + _u.mutation.SetProcessCode(v) + return _u +} + +// SetNillableProcessCode sets the "processCode" field if the given value is not nil. +func (_u *ProcessFlowUpdateOne) SetNillableProcessCode(v *int) *ProcessFlowUpdateOne { + if v != nil { + _u.SetProcessCode(*v) + } + return _u +} + +// AddProcessCode adds value to the "processCode" field. +func (_u *ProcessFlowUpdateOne) AddProcessCode(v int) *ProcessFlowUpdateOne { + _u.mutation.AddProcessCode(v) + return _u +} + +// SetPdfFile sets the "pdfFile" field. +func (_u *ProcessFlowUpdateOne) SetPdfFile(v string) *ProcessFlowUpdateOne { + _u.mutation.SetPdfFile(v) + return _u +} + +// SetNillablePdfFile sets the "pdfFile" field if the given value is not nil. +func (_u *ProcessFlowUpdateOne) SetNillablePdfFile(v *string) *ProcessFlowUpdateOne { + if v != nil { + _u.SetPdfFile(*v) + } + return _u +} + +// SetStatus sets the "status" field. +func (_u *ProcessFlowUpdateOne) SetStatus(v string) *ProcessFlowUpdateOne { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *ProcessFlowUpdateOne) SetNillableStatus(v *string) *ProcessFlowUpdateOne { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetRemark sets the "remark" field. +func (_u *ProcessFlowUpdateOne) SetRemark(v string) *ProcessFlowUpdateOne { + _u.mutation.SetRemark(v) + return _u +} + +// SetNillableRemark sets the "remark" field if the given value is not nil. +func (_u *ProcessFlowUpdateOne) SetNillableRemark(v *string) *ProcessFlowUpdateOne { + if v != nil { + _u.SetRemark(*v) + } + return _u +} + +// SetUpdatedAt sets the "updatedAt" field. +func (_u *ProcessFlowUpdateOne) SetUpdatedAt(v time.Time) *ProcessFlowUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// ClearUpdatedAt clears the value of the "updatedAt" field. +func (_u *ProcessFlowUpdateOne) ClearUpdatedAt() *ProcessFlowUpdateOne { + _u.mutation.ClearUpdatedAt() + return _u +} + +// Mutation returns the ProcessFlowMutation object of the builder. +func (_u *ProcessFlowUpdateOne) Mutation() *ProcessFlowMutation { + return _u.mutation +} + +// Where appends a list predicates to the ProcessFlowUpdate builder. +func (_u *ProcessFlowUpdateOne) Where(ps ...predicate.ProcessFlow) *ProcessFlowUpdateOne { + _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 *ProcessFlowUpdateOne) Select(field string, fields ...string) *ProcessFlowUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated ProcessFlow entity. +func (_u *ProcessFlowUpdateOne) Save(ctx context.Context) (*ProcessFlow, error) { + _u.defaults() + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *ProcessFlowUpdateOne) SaveX(ctx context.Context) *ProcessFlow { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *ProcessFlowUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *ProcessFlowUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_u *ProcessFlowUpdateOne) defaults() { + if _, ok := _u.mutation.UpdatedAt(); !ok && !_u.mutation.UpdatedAtCleared() { + v := processflow.UpdateDefaultUpdatedAt() + _u.mutation.SetUpdatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *ProcessFlowUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := processflow.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.name": %w`, err)} + } + } + if v, ok := _u.mutation.PdfFile(); ok { + if err := processflow.PdfFileValidator(v); err != nil { + return &ValidationError{Name: "pdfFile", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.pdfFile": %w`, err)} + } + } + if v, ok := _u.mutation.Status(); ok { + if err := processflow.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.status": %w`, err)} + } + } + if v, ok := _u.mutation.Remark(); ok { + if err := processflow.RemarkValidator(v); err != nil { + return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "ProcessFlow.remark": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *ProcessFlowUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProcessFlowUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *ProcessFlowUpdateOne) sqlSave(ctx context.Context) (_node *ProcessFlow, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(processflow.Table, processflow.Columns, sqlgraph.NewFieldSpec(processflow.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ProcessFlow.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, processflow.FieldID) + for _, f := range fields { + if !processflow.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != processflow.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.Name(); ok { + _spec.SetField(processflow.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.ProcessCode(); ok { + _spec.SetField(processflow.FieldProcessCode, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedProcessCode(); ok { + _spec.AddField(processflow.FieldProcessCode, field.TypeInt, value) + } + if value, ok := _u.mutation.PdfFile(); ok { + _spec.SetField(processflow.FieldPdfFile, field.TypeString, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(processflow.FieldStatus, field.TypeString, value) + } + if value, ok := _u.mutation.Remark(); ok { + _spec.SetField(processflow.FieldRemark, field.TypeString, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(processflow.FieldUpdatedAt, field.TypeTime, value) + } + if _u.mutation.UpdatedAtCleared() { + _spec.ClearField(processflow.FieldUpdatedAt, field.TypeTime) + } + _spec.AddModifiers(_u.modifiers...) + _node = &ProcessFlow{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{processflow.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/processstep.go b/bj_power_mes/ent/processstep.go index d6506b1..d900933 100644 --- a/bj_power_mes/ent/processstep.go +++ b/bj_power_mes/ent/processstep.go @@ -17,6 +17,8 @@ type ProcessStep struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` + // 所属工艺流程图ID(块3: 步骤改挂流程) + FlowId int `json:"flowId,omitempty"` // 工序代码 ProcessCode int `json:"processCode,omitempty"` // 步骤序号 @@ -41,7 +43,7 @@ func (*ProcessStep) scanValues(columns []string) ([]any, error) { switch columns[i] { case processstep.FieldIsTorque: values[i] = new(sql.NullBool) - case processstep.FieldID, processstep.FieldProcessCode, processstep.FieldSeq: + case processstep.FieldID, processstep.FieldFlowId, processstep.FieldProcessCode, processstep.FieldSeq: values[i] = new(sql.NullInt64) case processstep.FieldName, processstep.FieldCollectType, processstep.FieldRemark: values[i] = new(sql.NullString) @@ -68,6 +70,12 @@ func (_m *ProcessStep) assignValues(columns []string, values []any) error { return fmt.Errorf("unexpected type %T for field id", value) } _m.ID = int(value.Int64) + case processstep.FieldFlowId: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field flowId", values[i]) + } else if value.Valid { + _m.FlowId = int(value.Int64) + } case processstep.FieldProcessCode: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field processCode", values[i]) @@ -146,6 +154,9 @@ func (_m *ProcessStep) String() string { var builder strings.Builder builder.WriteString("ProcessStep(") builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("flowId=") + builder.WriteString(fmt.Sprintf("%v", _m.FlowId)) + builder.WriteString(", ") builder.WriteString("processCode=") builder.WriteString(fmt.Sprintf("%v", _m.ProcessCode)) builder.WriteString(", ") diff --git a/bj_power_mes/ent/processstep/processstep.go b/bj_power_mes/ent/processstep/processstep.go index b67323b..18d2cbd 100644 --- a/bj_power_mes/ent/processstep/processstep.go +++ b/bj_power_mes/ent/processstep/processstep.go @@ -13,6 +13,8 @@ const ( Label = "process_step" // FieldID holds the string denoting the id field in the database. FieldID = "id" + // FieldFlowId holds the string denoting the flowid field in the database. + FieldFlowId = "flow_id" // FieldProcessCode holds the string denoting the processcode field in the database. FieldProcessCode = "process_code" // FieldSeq holds the string denoting the seq field in the database. @@ -34,6 +36,7 @@ const ( // Columns holds all SQL columns for processstep fields. var Columns = []string{ FieldID, + FieldFlowId, FieldProcessCode, FieldSeq, FieldName, @@ -82,6 +85,11 @@ func ByID(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldID, opts...).ToFunc() } +// ByFlowId orders the results by the flowId field. +func ByFlowId(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFlowId, opts...).ToFunc() +} + // ByProcessCode orders the results by the processCode field. func ByProcessCode(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldProcessCode, opts...).ToFunc() diff --git a/bj_power_mes/ent/processstep/where.go b/bj_power_mes/ent/processstep/where.go index 78220bc..facf93c 100644 --- a/bj_power_mes/ent/processstep/where.go +++ b/bj_power_mes/ent/processstep/where.go @@ -54,6 +54,11 @@ func IDLTE(id int) predicate.ProcessStep { return predicate.ProcessStep(sql.FieldLTE(FieldID, id)) } +// FlowId applies equality check predicate on the "flowId" field. It's identical to FlowIdEQ. +func FlowId(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldEQ(FieldFlowId, v)) +} + // ProcessCode applies equality check predicate on the "processCode" field. It's identical to ProcessCodeEQ. func ProcessCode(v int) predicate.ProcessStep { return predicate.ProcessStep(sql.FieldEQ(FieldProcessCode, v)) @@ -89,6 +94,56 @@ func CreatedAt(v time.Time) predicate.ProcessStep { return predicate.ProcessStep(sql.FieldEQ(FieldCreatedAt, v)) } +// FlowIdEQ applies the EQ predicate on the "flowId" field. +func FlowIdEQ(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldEQ(FieldFlowId, v)) +} + +// FlowIdNEQ applies the NEQ predicate on the "flowId" field. +func FlowIdNEQ(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldNEQ(FieldFlowId, v)) +} + +// FlowIdIn applies the In predicate on the "flowId" field. +func FlowIdIn(vs ...int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldIn(FieldFlowId, vs...)) +} + +// FlowIdNotIn applies the NotIn predicate on the "flowId" field. +func FlowIdNotIn(vs ...int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldNotIn(FieldFlowId, vs...)) +} + +// FlowIdGT applies the GT predicate on the "flowId" field. +func FlowIdGT(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldGT(FieldFlowId, v)) +} + +// FlowIdGTE applies the GTE predicate on the "flowId" field. +func FlowIdGTE(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldGTE(FieldFlowId, v)) +} + +// FlowIdLT applies the LT predicate on the "flowId" field. +func FlowIdLT(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldLT(FieldFlowId, v)) +} + +// FlowIdLTE applies the LTE predicate on the "flowId" field. +func FlowIdLTE(v int) predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldLTE(FieldFlowId, v)) +} + +// FlowIdIsNil applies the IsNil predicate on the "flowId" field. +func FlowIdIsNil() predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldIsNull(FieldFlowId)) +} + +// FlowIdNotNil applies the NotNil predicate on the "flowId" field. +func FlowIdNotNil() predicate.ProcessStep { + return predicate.ProcessStep(sql.FieldNotNull(FieldFlowId)) +} + // ProcessCodeEQ applies the EQ predicate on the "processCode" field. func ProcessCodeEQ(v int) predicate.ProcessStep { return predicate.ProcessStep(sql.FieldEQ(FieldProcessCode, v)) diff --git a/bj_power_mes/ent/processstep_create.go b/bj_power_mes/ent/processstep_create.go index a87968e..6215939 100644 --- a/bj_power_mes/ent/processstep_create.go +++ b/bj_power_mes/ent/processstep_create.go @@ -20,6 +20,20 @@ type ProcessStepCreate struct { hooks []Hook } +// SetFlowId sets the "flowId" field. +func (_c *ProcessStepCreate) SetFlowId(v int) *ProcessStepCreate { + _c.mutation.SetFlowId(v) + return _c +} + +// SetNillableFlowId sets the "flowId" field if the given value is not nil. +func (_c *ProcessStepCreate) SetNillableFlowId(v *int) *ProcessStepCreate { + if v != nil { + _c.SetFlowId(*v) + } + return _c +} + // SetProcessCode sets the "processCode" field. func (_c *ProcessStepCreate) SetProcessCode(v int) *ProcessStepCreate { _c.mutation.SetProcessCode(v) @@ -240,6 +254,10 @@ func (_c *ProcessStepCreate) createSpec() (*ProcessStep, *sqlgraph.CreateSpec) { _node.ID = id _spec.ID.Value = id } + if value, ok := _c.mutation.FlowId(); ok { + _spec.SetField(processstep.FieldFlowId, field.TypeInt, value) + _node.FlowId = value + } if value, ok := _c.mutation.ProcessCode(); ok { _spec.SetField(processstep.FieldProcessCode, field.TypeInt, value) _node.ProcessCode = value diff --git a/bj_power_mes/ent/processstep_query.go b/bj_power_mes/ent/processstep_query.go index fbfec48..070477d 100644 --- a/bj_power_mes/ent/processstep_query.go +++ b/bj_power_mes/ent/processstep_query.go @@ -265,12 +265,12 @@ func (_q *ProcessStepQuery) Clone() *ProcessStepQuery { // Example: // // var v []struct { -// ProcessCode int `json:"processCode,omitempty"` +// FlowId int `json:"flowId,omitempty"` // Count int `json:"count,omitempty"` // } // // client.ProcessStep.Query(). -// GroupBy(processstep.FieldProcessCode). +// GroupBy(processstep.FieldFlowId). // Aggregate(ent.Count()). // Scan(ctx, &v) func (_q *ProcessStepQuery) GroupBy(field string, fields ...string) *ProcessStepGroupBy { @@ -288,11 +288,11 @@ func (_q *ProcessStepQuery) GroupBy(field string, fields ...string) *ProcessStep // Example: // // var v []struct { -// ProcessCode int `json:"processCode,omitempty"` +// FlowId int `json:"flowId,omitempty"` // } // // client.ProcessStep.Query(). -// Select(processstep.FieldProcessCode). +// Select(processstep.FieldFlowId). // Scan(ctx, &v) func (_q *ProcessStepQuery) Select(fields ...string) *ProcessStepSelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) diff --git a/bj_power_mes/ent/processstep_update.go b/bj_power_mes/ent/processstep_update.go index 8058b18..8f01fd5 100644 --- a/bj_power_mes/ent/processstep_update.go +++ b/bj_power_mes/ent/processstep_update.go @@ -28,6 +28,33 @@ func (_u *ProcessStepUpdate) Where(ps ...predicate.ProcessStep) *ProcessStepUpda return _u } +// SetFlowId sets the "flowId" field. +func (_u *ProcessStepUpdate) SetFlowId(v int) *ProcessStepUpdate { + _u.mutation.ResetFlowId() + _u.mutation.SetFlowId(v) + return _u +} + +// SetNillableFlowId sets the "flowId" field if the given value is not nil. +func (_u *ProcessStepUpdate) SetNillableFlowId(v *int) *ProcessStepUpdate { + if v != nil { + _u.SetFlowId(*v) + } + return _u +} + +// AddFlowId adds value to the "flowId" field. +func (_u *ProcessStepUpdate) AddFlowId(v int) *ProcessStepUpdate { + _u.mutation.AddFlowId(v) + return _u +} + +// ClearFlowId clears the value of the "flowId" field. +func (_u *ProcessStepUpdate) ClearFlowId() *ProcessStepUpdate { + _u.mutation.ClearFlowId() + return _u +} + // SetProcessCode sets the "processCode" field. func (_u *ProcessStepUpdate) SetProcessCode(v int) *ProcessStepUpdate { _u.mutation.ResetProcessCode() @@ -196,6 +223,15 @@ func (_u *ProcessStepUpdate) sqlSave(ctx context.Context) (_node int, err error) } } } + if value, ok := _u.mutation.FlowId(); ok { + _spec.SetField(processstep.FieldFlowId, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedFlowId(); ok { + _spec.AddField(processstep.FieldFlowId, field.TypeInt, value) + } + if _u.mutation.FlowIdCleared() { + _spec.ClearField(processstep.FieldFlowId, field.TypeInt) + } if value, ok := _u.mutation.ProcessCode(); ok { _spec.SetField(processstep.FieldProcessCode, field.TypeInt, value) } @@ -242,6 +278,33 @@ type ProcessStepUpdateOne struct { modifiers []func(*sql.UpdateBuilder) } +// SetFlowId sets the "flowId" field. +func (_u *ProcessStepUpdateOne) SetFlowId(v int) *ProcessStepUpdateOne { + _u.mutation.ResetFlowId() + _u.mutation.SetFlowId(v) + return _u +} + +// SetNillableFlowId sets the "flowId" field if the given value is not nil. +func (_u *ProcessStepUpdateOne) SetNillableFlowId(v *int) *ProcessStepUpdateOne { + if v != nil { + _u.SetFlowId(*v) + } + return _u +} + +// AddFlowId adds value to the "flowId" field. +func (_u *ProcessStepUpdateOne) AddFlowId(v int) *ProcessStepUpdateOne { + _u.mutation.AddFlowId(v) + return _u +} + +// ClearFlowId clears the value of the "flowId" field. +func (_u *ProcessStepUpdateOne) ClearFlowId() *ProcessStepUpdateOne { + _u.mutation.ClearFlowId() + return _u +} + // SetProcessCode sets the "processCode" field. func (_u *ProcessStepUpdateOne) SetProcessCode(v int) *ProcessStepUpdateOne { _u.mutation.ResetProcessCode() @@ -440,6 +503,15 @@ func (_u *ProcessStepUpdateOne) sqlSave(ctx context.Context) (_node *ProcessStep } } } + if value, ok := _u.mutation.FlowId(); ok { + _spec.SetField(processstep.FieldFlowId, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedFlowId(); ok { + _spec.AddField(processstep.FieldFlowId, field.TypeInt, value) + } + if _u.mutation.FlowIdCleared() { + _spec.ClearField(processstep.FieldFlowId, field.TypeInt) + } if value, ok := _u.mutation.ProcessCode(); ok { _spec.SetField(processstep.FieldProcessCode, field.TypeInt, value) } diff --git a/bj_power_mes/ent/runtime.go b/bj_power_mes/ent/runtime.go index 25f81a6..730f97e 100644 --- a/bj_power_mes/ent/runtime.go +++ b/bj_power_mes/ent/runtime.go @@ -7,19 +7,23 @@ import ( "bj_power_mes/ent/bomitem" "bj_power_mes/ent/dailyplan" "bj_power_mes/ent/eventlog" + "bj_power_mes/ent/inspectionrecord" "bj_power_mes/ent/materialrequest" "bj_power_mes/ent/permission" "bj_power_mes/ent/plcsendlog" + "bj_power_mes/ent/processflow" "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" "bj_power_mes/ent/stepcriterion" "bj_power_mes/ent/stepdata" "bj_power_mes/ent/torquerecord" "bj_power_mes/ent/user" + "bj_power_mes/ent/userstation" "bj_power_mes/ent/workorder" "bj_power_mes/ent/workpiece" "bj_power_mes/ent/workpieceprocess" @@ -205,6 +209,68 @@ func init() { eventlogDescID := eventlogFields[0].Descriptor() // eventlog.IDValidator is a validator for the "id" field. It is called by the builders before save. eventlog.IDValidator = eventlogDescID.Validators[0].(func(int) error) + inspectionrecordFields := schema.InspectionRecord{}.Fields() + _ = inspectionrecordFields + // inspectionrecordDescCategory is the schema descriptor for category field. + inspectionrecordDescCategory := inspectionrecordFields[1].Descriptor() + // inspectionrecord.CategoryValidator is a validator for the "category" field. It is called by the builders before save. + inspectionrecord.CategoryValidator = inspectionrecordDescCategory.Validators[0].(func(string) error) + // inspectionrecordDescStationNo is the schema descriptor for stationNo field. + inspectionrecordDescStationNo := inspectionrecordFields[2].Descriptor() + // inspectionrecord.DefaultStationNo holds the default value on creation for the stationNo field. + inspectionrecord.DefaultStationNo = inspectionrecordDescStationNo.Default.(string) + // inspectionrecord.StationNoValidator is a validator for the "stationNo" field. It is called by the builders before save. + inspectionrecord.StationNoValidator = inspectionrecordDescStationNo.Validators[0].(func(string) error) + // inspectionrecordDescShift is the schema descriptor for shift field. + inspectionrecordDescShift := inspectionrecordFields[3].Descriptor() + // inspectionrecord.DefaultShift holds the default value on creation for the shift field. + inspectionrecord.DefaultShift = inspectionrecordDescShift.Default.(string) + // inspectionrecord.ShiftValidator is a validator for the "shift" field. It is called by the builders before save. + inspectionrecord.ShiftValidator = inspectionrecordDescShift.Validators[0].(func(string) error) + // inspectionrecordDescOrderNo is the schema descriptor for orderNo field. + inspectionrecordDescOrderNo := inspectionrecordFields[4].Descriptor() + // inspectionrecord.DefaultOrderNo holds the default value on creation for the orderNo field. + inspectionrecord.DefaultOrderNo = inspectionrecordDescOrderNo.Default.(string) + // inspectionrecord.OrderNoValidator is a validator for the "orderNo" field. It is called by the builders before save. + inspectionrecord.OrderNoValidator = inspectionrecordDescOrderNo.Validators[0].(func(string) error) + // inspectionrecordDescSn is the schema descriptor for sn field. + inspectionrecordDescSn := inspectionrecordFields[5].Descriptor() + // inspectionrecord.DefaultSn holds the default value on creation for the sn field. + inspectionrecord.DefaultSn = inspectionrecordDescSn.Default.(string) + // inspectionrecord.SnValidator is a validator for the "sn" field. It is called by the builders before save. + inspectionrecord.SnValidator = inspectionrecordDescSn.Validators[0].(func(string) error) + // inspectionrecordDescResult is the schema descriptor for result field. + inspectionrecordDescResult := inspectionrecordFields[6].Descriptor() + // inspectionrecord.DefaultResult holds the default value on creation for the result field. + inspectionrecord.DefaultResult = inspectionrecordDescResult.Default.(string) + // inspectionrecord.ResultValidator is a validator for the "result" field. It is called by the builders before save. + inspectionrecord.ResultValidator = inspectionrecordDescResult.Validators[0].(func(string) error) + // inspectionrecordDescPhoto is the schema descriptor for photo field. + inspectionrecordDescPhoto := inspectionrecordFields[8].Descriptor() + // inspectionrecord.DefaultPhoto holds the default value on creation for the photo field. + inspectionrecord.DefaultPhoto = inspectionrecordDescPhoto.Default.(string) + // inspectionrecord.PhotoValidator is a validator for the "photo" field. It is called by the builders before save. + inspectionrecord.PhotoValidator = inspectionrecordDescPhoto.Validators[0].(func(string) error) + // inspectionrecordDescRemark is the schema descriptor for remark field. + inspectionrecordDescRemark := inspectionrecordFields[9].Descriptor() + // inspectionrecord.DefaultRemark holds the default value on creation for the remark field. + inspectionrecord.DefaultRemark = inspectionrecordDescRemark.Default.(string) + // inspectionrecord.RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + inspectionrecord.RemarkValidator = inspectionrecordDescRemark.Validators[0].(func(string) error) + // inspectionrecordDescOperator is the schema descriptor for operator field. + inspectionrecordDescOperator := inspectionrecordFields[10].Descriptor() + // inspectionrecord.DefaultOperator holds the default value on creation for the operator field. + inspectionrecord.DefaultOperator = inspectionrecordDescOperator.Default.(string) + // inspectionrecord.OperatorValidator is a validator for the "operator" field. It is called by the builders before save. + inspectionrecord.OperatorValidator = inspectionrecordDescOperator.Validators[0].(func(string) error) + // inspectionrecordDescCreatedAt is the schema descriptor for createdAt field. + inspectionrecordDescCreatedAt := inspectionrecordFields[11].Descriptor() + // inspectionrecord.DefaultCreatedAt holds the default value on creation for the createdAt field. + inspectionrecord.DefaultCreatedAt = inspectionrecordDescCreatedAt.Default.(func() time.Time) + // inspectionrecordDescID is the schema descriptor for id field. + inspectionrecordDescID := inspectionrecordFields[0].Descriptor() + // inspectionrecord.IDValidator is a validator for the "id" field. It is called by the builders before save. + inspectionrecord.IDValidator = inspectionrecordDescID.Validators[0].(func(int) error) materialrequestFields := schema.MaterialRequest{}.Fields() _ = materialrequestFields // materialrequestDescRequestNo is the schema descriptor for requestNo field. @@ -373,34 +439,72 @@ func init() { plcsendlogDescID := plcsendlogFields[0].Descriptor() // plcsendlog.IDValidator is a validator for the "id" field. It is called by the builders before save. plcsendlog.IDValidator = plcsendlogDescID.Validators[0].(func(int) error) + processflowFields := schema.ProcessFlow{}.Fields() + _ = processflowFields + // processflowDescName is the schema descriptor for name field. + processflowDescName := processflowFields[1].Descriptor() + // processflow.NameValidator is a validator for the "name" field. It is called by the builders before save. + processflow.NameValidator = processflowDescName.Validators[0].(func(string) error) + // processflowDescPdfFile is the schema descriptor for pdfFile field. + processflowDescPdfFile := processflowFields[3].Descriptor() + // processflow.DefaultPdfFile holds the default value on creation for the pdfFile field. + processflow.DefaultPdfFile = processflowDescPdfFile.Default.(string) + // processflow.PdfFileValidator is a validator for the "pdfFile" field. It is called by the builders before save. + processflow.PdfFileValidator = processflowDescPdfFile.Validators[0].(func(string) error) + // processflowDescStatus is the schema descriptor for status field. + processflowDescStatus := processflowFields[4].Descriptor() + // processflow.DefaultStatus holds the default value on creation for the status field. + processflow.DefaultStatus = processflowDescStatus.Default.(string) + // processflow.StatusValidator is a validator for the "status" field. It is called by the builders before save. + processflow.StatusValidator = processflowDescStatus.Validators[0].(func(string) error) + // processflowDescRemark is the schema descriptor for remark field. + processflowDescRemark := processflowFields[5].Descriptor() + // processflow.DefaultRemark holds the default value on creation for the remark field. + processflow.DefaultRemark = processflowDescRemark.Default.(string) + // processflow.RemarkValidator is a validator for the "remark" field. It is called by the builders before save. + processflow.RemarkValidator = processflowDescRemark.Validators[0].(func(string) error) + // processflowDescCreatedAt is the schema descriptor for createdAt field. + processflowDescCreatedAt := processflowFields[6].Descriptor() + // processflow.DefaultCreatedAt holds the default value on creation for the createdAt field. + processflow.DefaultCreatedAt = processflowDescCreatedAt.Default.(func() time.Time) + // processflowDescUpdatedAt is the schema descriptor for updatedAt field. + processflowDescUpdatedAt := processflowFields[7].Descriptor() + // processflow.DefaultUpdatedAt holds the default value on creation for the updatedAt field. + processflow.DefaultUpdatedAt = processflowDescUpdatedAt.Default.(func() time.Time) + // processflow.UpdateDefaultUpdatedAt holds the default value on update for the updatedAt field. + processflow.UpdateDefaultUpdatedAt = processflowDescUpdatedAt.UpdateDefault.(func() time.Time) + // processflowDescID is the schema descriptor for id field. + processflowDescID := processflowFields[0].Descriptor() + // processflow.IDValidator is a validator for the "id" field. It is called by the builders before save. + processflow.IDValidator = processflowDescID.Validators[0].(func(int) error) processstepFields := schema.ProcessStep{}.Fields() _ = processstepFields // processstepDescSeq is the schema descriptor for seq field. - processstepDescSeq := processstepFields[2].Descriptor() + processstepDescSeq := processstepFields[3].Descriptor() // processstep.DefaultSeq holds the default value on creation for the seq field. processstep.DefaultSeq = processstepDescSeq.Default.(int) // processstepDescName is the schema descriptor for name field. - processstepDescName := processstepFields[3].Descriptor() + processstepDescName := processstepFields[4].Descriptor() // processstep.NameValidator is a validator for the "name" field. It is called by the builders before save. processstep.NameValidator = processstepDescName.Validators[0].(func(string) error) // processstepDescCollectType is the schema descriptor for collectType field. - processstepDescCollectType := processstepFields[4].Descriptor() + processstepDescCollectType := processstepFields[5].Descriptor() // processstep.DefaultCollectType holds the default value on creation for the collectType field. processstep.DefaultCollectType = processstepDescCollectType.Default.(string) // processstep.CollectTypeValidator is a validator for the "collectType" field. It is called by the builders before save. processstep.CollectTypeValidator = processstepDescCollectType.Validators[0].(func(string) error) // processstepDescIsTorque is the schema descriptor for isTorque field. - processstepDescIsTorque := processstepFields[5].Descriptor() + processstepDescIsTorque := processstepFields[6].Descriptor() // processstep.DefaultIsTorque holds the default value on creation for the isTorque field. processstep.DefaultIsTorque = processstepDescIsTorque.Default.(bool) // processstepDescRemark is the schema descriptor for remark field. - processstepDescRemark := processstepFields[6].Descriptor() + processstepDescRemark := processstepFields[7].Descriptor() // processstep.DefaultRemark holds the default value on creation for the remark field. processstep.DefaultRemark = processstepDescRemark.Default.(string) // processstep.RemarkValidator is a validator for the "remark" field. It is called by the builders before save. processstep.RemarkValidator = processstepDescRemark.Validators[0].(func(string) error) // processstepDescCreatedAt is the schema descriptor for createdAt field. - processstepDescCreatedAt := processstepFields[7].Descriptor() + processstepDescCreatedAt := processstepFields[8].Descriptor() // processstep.DefaultCreatedAt holds the default value on creation for the createdAt field. processstep.DefaultCreatedAt = processstepDescCreatedAt.Default.(func() time.Time) // processstepDescID is the schema descriptor for id field. @@ -551,6 +655,28 @@ func init() { semiflowDescID := semiflowFields[0].Descriptor() // semiflow.IDValidator is a validator for the "id" field. It is called by the builders before save. semiflow.IDValidator = semiflowDescID.Validators[0].(func(int) error) + stationFields := schema.Station{}.Fields() + _ = stationFields + // stationDescName is the schema descriptor for name field. + stationDescName := stationFields[2].Descriptor() + // station.DefaultName holds the default value on creation for the name field. + station.DefaultName = stationDescName.Default.(string) + // station.NameValidator is a validator for the "name" field. It is called by the builders before save. + station.NameValidator = stationDescName.Validators[0].(func(string) error) + // stationDescStatus is the schema descriptor for status field. + stationDescStatus := stationFields[4].Descriptor() + // station.DefaultStatus holds the default value on creation for the status field. + station.DefaultStatus = stationDescStatus.Default.(string) + // station.StatusValidator is a validator for the "status" field. It is called by the builders before save. + station.StatusValidator = stationDescStatus.Validators[0].(func(string) error) + // stationDescCreatedAt is the schema descriptor for createdAt field. + stationDescCreatedAt := stationFields[5].Descriptor() + // station.DefaultCreatedAt holds the default value on creation for the createdAt field. + station.DefaultCreatedAt = stationDescCreatedAt.Default.(func() time.Time) + // stationDescID is the schema descriptor for id field. + stationDescID := stationFields[0].Descriptor() + // station.IDValidator is a validator for the "id" field. It is called by the builders before save. + station.IDValidator = stationDescID.Validators[0].(func(int) error) stationprocessFields := schema.StationProcess{}.Fields() _ = stationprocessFields // stationprocessDescEffectDate is the schema descriptor for effectDate field. @@ -737,18 +863,26 @@ func init() { user.DefaultName = userDescName.Default.(string) // user.NameValidator is a validator for the "name" field. It is called by the builders before save. user.NameValidator = userDescName.Validators[0].(func(string) error) + // userDescCanLoginWorkstation is the schema descriptor for canLoginWorkstation field. + userDescCanLoginWorkstation := userFields[5].Descriptor() + // user.DefaultCanLoginWorkstation holds the default value on creation for the canLoginWorkstation field. + user.DefaultCanLoginWorkstation = userDescCanLoginWorkstation.Default.(bool) + // userDescWorkstationPassword is the schema descriptor for workstationPassword field. + userDescWorkstationPassword := userFields[6].Descriptor() + // user.WorkstationPasswordValidator is a validator for the "workstationPassword" field. It is called by the builders before save. + user.WorkstationPasswordValidator = userDescWorkstationPassword.Validators[0].(func(string) error) // userDescStatus is the schema descriptor for status field. - userDescStatus := userFields[5].Descriptor() + userDescStatus := userFields[7].Descriptor() // user.DefaultStatus holds the default value on creation for the status field. user.DefaultStatus = userDescStatus.Default.(string) // user.StatusValidator is a validator for the "status" field. It is called by the builders before save. user.StatusValidator = userDescStatus.Validators[0].(func(string) error) // userDescCreatedAt is the schema descriptor for createdAt field. - userDescCreatedAt := userFields[6].Descriptor() + userDescCreatedAt := userFields[8].Descriptor() // user.DefaultCreatedAt holds the default value on creation for the createdAt field. user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time) // userDescUpdatedAt is the schema descriptor for updatedAt field. - userDescUpdatedAt := userFields[7].Descriptor() + userDescUpdatedAt := userFields[9].Descriptor() // user.DefaultUpdatedAt holds the default value on creation for the updatedAt field. user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time) // user.UpdateDefaultUpdatedAt holds the default value on update for the updatedAt field. @@ -757,6 +891,16 @@ func init() { userDescID := userFields[0].Descriptor() // user.IDValidator is a validator for the "id" field. It is called by the builders before save. user.IDValidator = userDescID.Validators[0].(func(int) error) + userstationFields := schema.UserStation{}.Fields() + _ = userstationFields + // userstationDescCreatedAt is the schema descriptor for createdAt field. + userstationDescCreatedAt := userstationFields[3].Descriptor() + // userstation.DefaultCreatedAt holds the default value on creation for the createdAt field. + userstation.DefaultCreatedAt = userstationDescCreatedAt.Default.(func() time.Time) + // userstationDescID is the schema descriptor for id field. + userstationDescID := userstationFields[0].Descriptor() + // userstation.IDValidator is a validator for the "id" field. It is called by the builders before save. + userstation.IDValidator = userstationDescID.Validators[0].(func(int) error) workorderFields := schema.WorkOrder{}.Fields() _ = workorderFields // workorderDescWorkOrderNo is the schema descriptor for workOrderNo field. diff --git a/bj_power_mes/ent/station.go b/bj_power_mes/ent/station.go new file mode 100644 index 0000000..d059ddc --- /dev/null +++ b/bj_power_mes/ent/station.go @@ -0,0 +1,150 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/station" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// Station is the model entity for the Station schema. +type Station struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 工位号 1..12 + StationNo int `json:"stationNo,omitempty"` + // 工位名称 + Name string `json:"name,omitempty"` + // 绑定工艺流程图ID + FlowId int `json:"flowId,omitempty"` + // Status holds the value of the "status" field. + Status string `json:"status,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 (*Station) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case station.FieldID, station.FieldStationNo, station.FieldFlowId: + values[i] = new(sql.NullInt64) + case station.FieldName, station.FieldStatus: + values[i] = new(sql.NullString) + case station.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 Station fields. +func (_m *Station) 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 station.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 station.FieldStationNo: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field stationNo", values[i]) + } else if value.Valid { + _m.StationNo = int(value.Int64) + } + case station.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case station.FieldFlowId: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field flowId", values[i]) + } else if value.Valid { + _m.FlowId = int(value.Int64) + } + case station.FieldStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + _m.Status = value.String + } + case station.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 Station. +// This includes values selected through modifiers, order, etc. +func (_m *Station) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this Station. +// Note that you need to call Station.Unwrap() before calling this method if this Station +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *Station) Update() *StationUpdateOne { + return NewStationClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the Station 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 *Station) Unwrap() *Station { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: Station is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *Station) String() string { + var builder strings.Builder + builder.WriteString("Station(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("stationNo=") + builder.WriteString(fmt.Sprintf("%v", _m.StationNo)) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("flowId=") + builder.WriteString(fmt.Sprintf("%v", _m.FlowId)) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(_m.Status) + builder.WriteString(", ") + builder.WriteString("createdAt=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// Stations is a parsable slice of Station. +type Stations []*Station diff --git a/bj_power_mes/ent/station/station.go b/bj_power_mes/ent/station/station.go new file mode 100644 index 0000000..6f88e70 --- /dev/null +++ b/bj_power_mes/ent/station/station.go @@ -0,0 +1,96 @@ +// Code generated by ent, DO NOT EDIT. + +package station + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the station type in the database. + Label = "station" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldStationNo holds the string denoting the stationno field in the database. + FieldStationNo = "station_no" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldFlowId holds the string denoting the flowid field in the database. + FieldFlowId = "flow_id" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldCreatedAt holds the string denoting the createdat field in the database. + FieldCreatedAt = "created_at" + // Table holds the table name of the station in the database. + Table = "station" +) + +// Columns holds all SQL columns for station fields. +var Columns = []string{ + FieldID, + FieldStationNo, + FieldName, + FieldFlowId, + FieldStatus, + 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 ( + // DefaultName holds the default value on creation for the "name" field. + DefaultName string + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DefaultStatus holds the default value on creation for the "status" field. + DefaultStatus string + // StatusValidator is a validator for the "status" field. It is called by the builders before save. + StatusValidator func(string) error + // DefaultCreatedAt holds the default value on creation for the "createdAt" field. + DefaultCreatedAt func() time.Time + // IDValidator is a validator for the "id" field. It is called by the builders before save. + IDValidator func(int) error +) + +// OrderOption defines the ordering options for the Station 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() +} + +// ByStationNo orders the results by the stationNo field. +func ByStationNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStationNo, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByFlowId orders the results by the flowId field. +func ByFlowId(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldFlowId, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, 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/station/where.go b/bj_power_mes/ent/station/where.go new file mode 100644 index 0000000..7b25d0c --- /dev/null +++ b/bj_power_mes/ent/station/where.go @@ -0,0 +1,355 @@ +// Code generated by ent, DO NOT EDIT. + +package station + +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.Station { + return predicate.Station(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.Station { + return predicate.Station(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.Station { + return predicate.Station(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.Station { + return predicate.Station(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.Station { + return predicate.Station(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.Station { + return predicate.Station(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.Station { + return predicate.Station(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.Station { + return predicate.Station(sql.FieldLTE(FieldID, id)) +} + +// StationNo applies equality check predicate on the "stationNo" field. It's identical to StationNoEQ. +func StationNo(v int) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldStationNo, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldName, v)) +} + +// FlowId applies equality check predicate on the "flowId" field. It's identical to FlowIdEQ. +func FlowId(v int) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldFlowId, v)) +} + +// Status applies equality check predicate on the "status" field. It's identical to StatusEQ. +func Status(v string) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldStatus, v)) +} + +// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldCreatedAt, v)) +} + +// StationNoEQ applies the EQ predicate on the "stationNo" field. +func StationNoEQ(v int) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldStationNo, v)) +} + +// StationNoNEQ applies the NEQ predicate on the "stationNo" field. +func StationNoNEQ(v int) predicate.Station { + return predicate.Station(sql.FieldNEQ(FieldStationNo, v)) +} + +// StationNoIn applies the In predicate on the "stationNo" field. +func StationNoIn(vs ...int) predicate.Station { + return predicate.Station(sql.FieldIn(FieldStationNo, vs...)) +} + +// StationNoNotIn applies the NotIn predicate on the "stationNo" field. +func StationNoNotIn(vs ...int) predicate.Station { + return predicate.Station(sql.FieldNotIn(FieldStationNo, vs...)) +} + +// StationNoGT applies the GT predicate on the "stationNo" field. +func StationNoGT(v int) predicate.Station { + return predicate.Station(sql.FieldGT(FieldStationNo, v)) +} + +// StationNoGTE applies the GTE predicate on the "stationNo" field. +func StationNoGTE(v int) predicate.Station { + return predicate.Station(sql.FieldGTE(FieldStationNo, v)) +} + +// StationNoLT applies the LT predicate on the "stationNo" field. +func StationNoLT(v int) predicate.Station { + return predicate.Station(sql.FieldLT(FieldStationNo, v)) +} + +// StationNoLTE applies the LTE predicate on the "stationNo" field. +func StationNoLTE(v int) predicate.Station { + return predicate.Station(sql.FieldLTE(FieldStationNo, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Station { + return predicate.Station(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Station { + return predicate.Station(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Station { + return predicate.Station(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Station { + return predicate.Station(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Station { + return predicate.Station(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Station { + return predicate.Station(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Station { + return predicate.Station(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Station { + return predicate.Station(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Station { + return predicate.Station(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Station { + return predicate.Station(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Station { + return predicate.Station(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Station { + return predicate.Station(sql.FieldContainsFold(FieldName, v)) +} + +// FlowIdEQ applies the EQ predicate on the "flowId" field. +func FlowIdEQ(v int) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldFlowId, v)) +} + +// FlowIdNEQ applies the NEQ predicate on the "flowId" field. +func FlowIdNEQ(v int) predicate.Station { + return predicate.Station(sql.FieldNEQ(FieldFlowId, v)) +} + +// FlowIdIn applies the In predicate on the "flowId" field. +func FlowIdIn(vs ...int) predicate.Station { + return predicate.Station(sql.FieldIn(FieldFlowId, vs...)) +} + +// FlowIdNotIn applies the NotIn predicate on the "flowId" field. +func FlowIdNotIn(vs ...int) predicate.Station { + return predicate.Station(sql.FieldNotIn(FieldFlowId, vs...)) +} + +// FlowIdGT applies the GT predicate on the "flowId" field. +func FlowIdGT(v int) predicate.Station { + return predicate.Station(sql.FieldGT(FieldFlowId, v)) +} + +// FlowIdGTE applies the GTE predicate on the "flowId" field. +func FlowIdGTE(v int) predicate.Station { + return predicate.Station(sql.FieldGTE(FieldFlowId, v)) +} + +// FlowIdLT applies the LT predicate on the "flowId" field. +func FlowIdLT(v int) predicate.Station { + return predicate.Station(sql.FieldLT(FieldFlowId, v)) +} + +// FlowIdLTE applies the LTE predicate on the "flowId" field. +func FlowIdLTE(v int) predicate.Station { + return predicate.Station(sql.FieldLTE(FieldFlowId, v)) +} + +// FlowIdIsNil applies the IsNil predicate on the "flowId" field. +func FlowIdIsNil() predicate.Station { + return predicate.Station(sql.FieldIsNull(FieldFlowId)) +} + +// FlowIdNotNil applies the NotNil predicate on the "flowId" field. +func FlowIdNotNil() predicate.Station { + return predicate.Station(sql.FieldNotNull(FieldFlowId)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v string) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v string) predicate.Station { + return predicate.Station(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...string) predicate.Station { + return predicate.Station(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...string) predicate.Station { + return predicate.Station(sql.FieldNotIn(FieldStatus, vs...)) +} + +// StatusGT applies the GT predicate on the "status" field. +func StatusGT(v string) predicate.Station { + return predicate.Station(sql.FieldGT(FieldStatus, v)) +} + +// StatusGTE applies the GTE predicate on the "status" field. +func StatusGTE(v string) predicate.Station { + return predicate.Station(sql.FieldGTE(FieldStatus, v)) +} + +// StatusLT applies the LT predicate on the "status" field. +func StatusLT(v string) predicate.Station { + return predicate.Station(sql.FieldLT(FieldStatus, v)) +} + +// StatusLTE applies the LTE predicate on the "status" field. +func StatusLTE(v string) predicate.Station { + return predicate.Station(sql.FieldLTE(FieldStatus, v)) +} + +// StatusContains applies the Contains predicate on the "status" field. +func StatusContains(v string) predicate.Station { + return predicate.Station(sql.FieldContains(FieldStatus, v)) +} + +// StatusHasPrefix applies the HasPrefix predicate on the "status" field. +func StatusHasPrefix(v string) predicate.Station { + return predicate.Station(sql.FieldHasPrefix(FieldStatus, v)) +} + +// StatusHasSuffix applies the HasSuffix predicate on the "status" field. +func StatusHasSuffix(v string) predicate.Station { + return predicate.Station(sql.FieldHasSuffix(FieldStatus, v)) +} + +// StatusEqualFold applies the EqualFold predicate on the "status" field. +func StatusEqualFold(v string) predicate.Station { + return predicate.Station(sql.FieldEqualFold(FieldStatus, v)) +} + +// StatusContainsFold applies the ContainsFold predicate on the "status" field. +func StatusContainsFold(v string) predicate.Station { + return predicate.Station(sql.FieldContainsFold(FieldStatus, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +func CreatedAtEQ(v time.Time) predicate.Station { + return predicate.Station(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +func CreatedAtNEQ(v time.Time) predicate.Station { + return predicate.Station(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "createdAt" field. +func CreatedAtIn(vs ...time.Time) predicate.Station { + return predicate.Station(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +func CreatedAtNotIn(vs ...time.Time) predicate.Station { + return predicate.Station(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "createdAt" field. +func CreatedAtGT(v time.Time) predicate.Station { + return predicate.Station(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +func CreatedAtGTE(v time.Time) predicate.Station { + return predicate.Station(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "createdAt" field. +func CreatedAtLT(v time.Time) predicate.Station { + return predicate.Station(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +func CreatedAtLTE(v time.Time) predicate.Station { + return predicate.Station(sql.FieldLTE(FieldCreatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Station) predicate.Station { + return predicate.Station(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Station) predicate.Station { + return predicate.Station(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Station) predicate.Station { + return predicate.Station(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/station_create.go b/bj_power_mes/ent/station_create.go new file mode 100644 index 0000000..f430b9b --- /dev/null +++ b/bj_power_mes/ent/station_create.go @@ -0,0 +1,310 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/station" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// StationCreate is the builder for creating a Station entity. +type StationCreate struct { + config + mutation *StationMutation + hooks []Hook +} + +// SetStationNo sets the "stationNo" field. +func (_c *StationCreate) SetStationNo(v int) *StationCreate { + _c.mutation.SetStationNo(v) + return _c +} + +// SetName sets the "name" field. +func (_c *StationCreate) SetName(v string) *StationCreate { + _c.mutation.SetName(v) + return _c +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_c *StationCreate) SetNillableName(v *string) *StationCreate { + if v != nil { + _c.SetName(*v) + } + return _c +} + +// SetFlowId sets the "flowId" field. +func (_c *StationCreate) SetFlowId(v int) *StationCreate { + _c.mutation.SetFlowId(v) + return _c +} + +// SetNillableFlowId sets the "flowId" field if the given value is not nil. +func (_c *StationCreate) SetNillableFlowId(v *int) *StationCreate { + if v != nil { + _c.SetFlowId(*v) + } + return _c +} + +// SetStatus sets the "status" field. +func (_c *StationCreate) SetStatus(v string) *StationCreate { + _c.mutation.SetStatus(v) + return _c +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_c *StationCreate) SetNillableStatus(v *string) *StationCreate { + if v != nil { + _c.SetStatus(*v) + } + return _c +} + +// SetCreatedAt sets the "createdAt" field. +func (_c *StationCreate) SetCreatedAt(v time.Time) *StationCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (_c *StationCreate) SetNillableCreatedAt(v *time.Time) *StationCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *StationCreate) SetID(v int) *StationCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the StationMutation object of the builder. +func (_c *StationCreate) Mutation() *StationMutation { + return _c.mutation +} + +// Save creates the Station in the database. +func (_c *StationCreate) Save(ctx context.Context) (*Station, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *StationCreate) SaveX(ctx context.Context) *Station { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *StationCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *StationCreate) 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 *StationCreate) defaults() { + if _, ok := _c.mutation.Name(); !ok { + v := station.DefaultName + _c.mutation.SetName(v) + } + if _, ok := _c.mutation.Status(); !ok { + v := station.DefaultStatus + _c.mutation.SetStatus(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := station.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *StationCreate) check() error { + if _, ok := _c.mutation.StationNo(); !ok { + return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "Station.stationNo"`)} + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Station.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := station.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Station.name": %w`, err)} + } + } + if _, ok := _c.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Station.status"`)} + } + if v, ok := _c.mutation.Status(); ok { + if err := station.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Station.status": %w`, err)} + } + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "Station.createdAt"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := station.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "Station.id": %w`, err)} + } + } + return nil +} + +func (_c *StationCreate) sqlSave(ctx context.Context) (*Station, 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 *StationCreate) createSpec() (*Station, *sqlgraph.CreateSpec) { + var ( + _node = &Station{config: _c.config} + _spec = sqlgraph.NewCreateSpec(station.Table, sqlgraph.NewFieldSpec(station.FieldID, field.TypeInt)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.StationNo(); ok { + _spec.SetField(station.FieldStationNo, field.TypeInt, value) + _node.StationNo = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(station.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.FlowId(); ok { + _spec.SetField(station.FieldFlowId, field.TypeInt, value) + _node.FlowId = value + } + if value, ok := _c.mutation.Status(); ok { + _spec.SetField(station.FieldStatus, field.TypeString, value) + _node.Status = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(station.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + return _node, _spec +} + +// StationCreateBulk is the builder for creating many Station entities in bulk. +type StationCreateBulk struct { + config + err error + builders []*StationCreate +} + +// Save creates the Station entities in the database. +func (_c *StationCreateBulk) Save(ctx context.Context) ([]*Station, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*Station, 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.(*StationMutation) + 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 *StationCreateBulk) SaveX(ctx context.Context) []*Station { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *StationCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *StationCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/station_delete.go b/bj_power_mes/ent/station_delete.go new file mode 100644 index 0000000..a04334e --- /dev/null +++ b/bj_power_mes/ent/station_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/station" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// StationDelete is the builder for deleting a Station entity. +type StationDelete struct { + config + hooks []Hook + mutation *StationMutation +} + +// Where appends a list predicates to the StationDelete builder. +func (_d *StationDelete) Where(ps ...predicate.Station) *StationDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *StationDelete) 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 *StationDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *StationDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(station.Table, sqlgraph.NewFieldSpec(station.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 +} + +// StationDeleteOne is the builder for deleting a single Station entity. +type StationDeleteOne struct { + _d *StationDelete +} + +// Where appends a list predicates to the StationDelete builder. +func (_d *StationDeleteOne) Where(ps ...predicate.Station) *StationDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *StationDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{station.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *StationDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/station_query.go b/bj_power_mes/ent/station_query.go new file mode 100644 index 0000000..03b0e38 --- /dev/null +++ b/bj_power_mes/ent/station_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/station" + "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" +) + +// StationQuery is the builder for querying Station entities. +type StationQuery struct { + config + ctx *QueryContext + order []station.OrderOption + inters []Interceptor + predicates []predicate.Station + 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 StationQuery builder. +func (_q *StationQuery) Where(ps ...predicate.Station) *StationQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *StationQuery) Limit(limit int) *StationQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *StationQuery) Offset(offset int) *StationQuery { + _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 *StationQuery) Unique(unique bool) *StationQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *StationQuery) Order(o ...station.OrderOption) *StationQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first Station entity from the query. +// Returns a *NotFoundError when no Station was found. +func (_q *StationQuery) First(ctx context.Context) (*Station, 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{station.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *StationQuery) FirstX(ctx context.Context) *Station { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Station ID from the query. +// Returns a *NotFoundError when no Station ID was found. +func (_q *StationQuery) 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{station.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *StationQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Station entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Station entity is found. +// Returns a *NotFoundError when no Station entities are found. +func (_q *StationQuery) Only(ctx context.Context) (*Station, 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{station.Label} + default: + return nil, &NotSingularError{station.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *StationQuery) OnlyX(ctx context.Context) *Station { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Station ID in the query. +// Returns a *NotSingularError when more than one Station ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *StationQuery) 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{station.Label} + default: + err = &NotSingularError{station.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *StationQuery) 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 Stations. +func (_q *StationQuery) All(ctx context.Context) ([]*Station, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*Station, *StationQuery]() + return withInterceptors[[]*Station](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *StationQuery) AllX(ctx context.Context) []*Station { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Station IDs. +func (_q *StationQuery) 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(station.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *StationQuery) 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 *StationQuery) 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[*StationQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *StationQuery) 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 *StationQuery) 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 *StationQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the StationQuery 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 *StationQuery) Clone() *StationQuery { + if _q == nil { + return nil + } + return &StationQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]station.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.Station{}, _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 { +// StationNo int `json:"stationNo,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Station.Query(). +// GroupBy(station.FieldStationNo). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *StationQuery) GroupBy(field string, fields ...string) *StationGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &StationGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = station.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 { +// StationNo int `json:"stationNo,omitempty"` +// } +// +// client.Station.Query(). +// Select(station.FieldStationNo). +// Scan(ctx, &v) +func (_q *StationQuery) Select(fields ...string) *StationSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &StationSelect{StationQuery: _q} + sbuild.label = station.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a StationSelect configured with the given aggregations. +func (_q *StationQuery) Aggregate(fns ...AggregateFunc) *StationSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *StationQuery) 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 !station.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 *StationQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Station, error) { + var ( + nodes = []*Station{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*Station).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &Station{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 *StationQuery) 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 *StationQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(station.Table, station.Columns, sqlgraph.NewFieldSpec(station.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, station.FieldID) + for i := range fields { + if fields[i] != station.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 *StationQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(station.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = station.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 *StationQuery) ForUpdate(opts ...sql.LockOption) *StationQuery { + 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 *StationQuery) ForShare(opts ...sql.LockOption) *StationQuery { + 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 *StationQuery) Modify(modifiers ...func(s *sql.Selector)) *StationSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// StationGroupBy is the group-by builder for Station entities. +type StationGroupBy struct { + selector + build *StationQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *StationGroupBy) Aggregate(fns ...AggregateFunc) *StationGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *StationGroupBy) 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[*StationQuery, *StationGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *StationGroupBy) sqlScan(ctx context.Context, root *StationQuery, 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) +} + +// StationSelect is the builder for selecting fields of Station entities. +type StationSelect struct { + *StationQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *StationSelect) Aggregate(fns ...AggregateFunc) *StationSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *StationSelect) 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[*StationQuery, *StationSelect](ctx, _s.StationQuery, _s, _s.inters, v) +} + +func (_s *StationSelect) sqlScan(ctx context.Context, root *StationQuery, 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 *StationSelect) Modify(modifiers ...func(s *sql.Selector)) *StationSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/station_update.go b/bj_power_mes/ent/station_update.go new file mode 100644 index 0000000..bc9eb8d --- /dev/null +++ b/bj_power_mes/ent/station_update.go @@ -0,0 +1,421 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/station" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// StationUpdate is the builder for updating Station entities. +type StationUpdate struct { + config + hooks []Hook + mutation *StationMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the StationUpdate builder. +func (_u *StationUpdate) Where(ps ...predicate.Station) *StationUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *StationUpdate) SetStationNo(v int) *StationUpdate { + _u.mutation.ResetStationNo() + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *StationUpdate) SetNillableStationNo(v *int) *StationUpdate { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// AddStationNo adds value to the "stationNo" field. +func (_u *StationUpdate) AddStationNo(v int) *StationUpdate { + _u.mutation.AddStationNo(v) + return _u +} + +// SetName sets the "name" field. +func (_u *StationUpdate) SetName(v string) *StationUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *StationUpdate) SetNillableName(v *string) *StationUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetFlowId sets the "flowId" field. +func (_u *StationUpdate) SetFlowId(v int) *StationUpdate { + _u.mutation.ResetFlowId() + _u.mutation.SetFlowId(v) + return _u +} + +// SetNillableFlowId sets the "flowId" field if the given value is not nil. +func (_u *StationUpdate) SetNillableFlowId(v *int) *StationUpdate { + if v != nil { + _u.SetFlowId(*v) + } + return _u +} + +// AddFlowId adds value to the "flowId" field. +func (_u *StationUpdate) AddFlowId(v int) *StationUpdate { + _u.mutation.AddFlowId(v) + return _u +} + +// ClearFlowId clears the value of the "flowId" field. +func (_u *StationUpdate) ClearFlowId() *StationUpdate { + _u.mutation.ClearFlowId() + return _u +} + +// SetStatus sets the "status" field. +func (_u *StationUpdate) SetStatus(v string) *StationUpdate { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *StationUpdate) SetNillableStatus(v *string) *StationUpdate { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// Mutation returns the StationMutation object of the builder. +func (_u *StationUpdate) Mutation() *StationMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *StationUpdate) 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 *StationUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *StationUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *StationUpdate) 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 *StationUpdate) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := station.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Station.name": %w`, err)} + } + } + if v, ok := _u.mutation.Status(); ok { + if err := station.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Station.status": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *StationUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *StationUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(station.Table, station.Columns, sqlgraph.NewFieldSpec(station.FieldID, field.TypeInt)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(station.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedStationNo(); ok { + _spec.AddField(station.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(station.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.FlowId(); ok { + _spec.SetField(station.FieldFlowId, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedFlowId(); ok { + _spec.AddField(station.FieldFlowId, field.TypeInt, value) + } + if _u.mutation.FlowIdCleared() { + _spec.ClearField(station.FieldFlowId, field.TypeInt) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(station.FieldStatus, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{station.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// StationUpdateOne is the builder for updating a single Station entity. +type StationUpdateOne struct { + config + fields []string + hooks []Hook + mutation *StationMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetStationNo sets the "stationNo" field. +func (_u *StationUpdateOne) SetStationNo(v int) *StationUpdateOne { + _u.mutation.ResetStationNo() + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *StationUpdateOne) SetNillableStationNo(v *int) *StationUpdateOne { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// AddStationNo adds value to the "stationNo" field. +func (_u *StationUpdateOne) AddStationNo(v int) *StationUpdateOne { + _u.mutation.AddStationNo(v) + return _u +} + +// SetName sets the "name" field. +func (_u *StationUpdateOne) SetName(v string) *StationUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *StationUpdateOne) SetNillableName(v *string) *StationUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetFlowId sets the "flowId" field. +func (_u *StationUpdateOne) SetFlowId(v int) *StationUpdateOne { + _u.mutation.ResetFlowId() + _u.mutation.SetFlowId(v) + return _u +} + +// SetNillableFlowId sets the "flowId" field if the given value is not nil. +func (_u *StationUpdateOne) SetNillableFlowId(v *int) *StationUpdateOne { + if v != nil { + _u.SetFlowId(*v) + } + return _u +} + +// AddFlowId adds value to the "flowId" field. +func (_u *StationUpdateOne) AddFlowId(v int) *StationUpdateOne { + _u.mutation.AddFlowId(v) + return _u +} + +// ClearFlowId clears the value of the "flowId" field. +func (_u *StationUpdateOne) ClearFlowId() *StationUpdateOne { + _u.mutation.ClearFlowId() + return _u +} + +// SetStatus sets the "status" field. +func (_u *StationUpdateOne) SetStatus(v string) *StationUpdateOne { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *StationUpdateOne) SetNillableStatus(v *string) *StationUpdateOne { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// Mutation returns the StationMutation object of the builder. +func (_u *StationUpdateOne) Mutation() *StationMutation { + return _u.mutation +} + +// Where appends a list predicates to the StationUpdate builder. +func (_u *StationUpdateOne) Where(ps ...predicate.Station) *StationUpdateOne { + _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 *StationUpdateOne) Select(field string, fields ...string) *StationUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated Station entity. +func (_u *StationUpdateOne) Save(ctx context.Context) (*Station, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *StationUpdateOne) SaveX(ctx context.Context) *Station { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *StationUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *StationUpdateOne) 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 *StationUpdateOne) check() error { + if v, ok := _u.mutation.Name(); ok { + if err := station.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "Station.name": %w`, err)} + } + } + if v, ok := _u.mutation.Status(); ok { + if err := station.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Station.status": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *StationUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *StationUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *StationUpdateOne) sqlSave(ctx context.Context) (_node *Station, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(station.Table, station.Columns, sqlgraph.NewFieldSpec(station.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Station.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, station.FieldID) + for _, f := range fields { + if !station.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != station.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(station.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedStationNo(); ok { + _spec.AddField(station.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(station.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.FlowId(); ok { + _spec.SetField(station.FieldFlowId, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedFlowId(); ok { + _spec.AddField(station.FieldFlowId, field.TypeInt, value) + } + if _u.mutation.FlowIdCleared() { + _spec.ClearField(station.FieldFlowId, field.TypeInt) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(station.FieldStatus, field.TypeString, value) + } + _spec.AddModifiers(_u.modifiers...) + _node = &Station{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{station.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 801e295..9febec6 100644 --- a/bj_power_mes/ent/tx.go +++ b/bj_power_mes/ent/tx.go @@ -22,12 +22,16 @@ type Tx struct { DailyPlan *DailyPlanClient // EventLog is the client for interacting with the EventLog builders. EventLog *EventLogClient + // InspectionRecord is the client for interacting with the InspectionRecord builders. + InspectionRecord *InspectionRecordClient // MaterialRequest is the client for interacting with the MaterialRequest builders. MaterialRequest *MaterialRequestClient // Permission is the client for interacting with the Permission builders. Permission *PermissionClient // PlcSendLog is the client for interacting with the PlcSendLog builders. PlcSendLog *PlcSendLogClient + // ProcessFlow is the client for interacting with the ProcessFlow builders. + ProcessFlow *ProcessFlowClient // ProcessStep is the client for interacting with the ProcessStep builders. ProcessStep *ProcessStepClient // ProductType is the client for interacting with the ProductType builders. @@ -38,6 +42,8 @@ type Tx struct { ScanRecord *ScanRecordClient // SemiFlow is the client for interacting with the SemiFlow builders. SemiFlow *SemiFlowClient + // Station is the client for interacting with the Station builders. + Station *StationClient // StationProcess is the client for interacting with the StationProcess builders. StationProcess *StationProcessClient // StepCriterion is the client for interacting with the StepCriterion builders. @@ -48,6 +54,8 @@ type Tx struct { TorqueRecord *TorqueRecordClient // User is the client for interacting with the User builders. User *UserClient + // UserStation is the client for interacting with the UserStation builders. + UserStation *UserStationClient // WorkOrder is the client for interacting with the WorkOrder builders. WorkOrder *WorkOrderClient // Workpiece is the client for interacting with the Workpiece builders. @@ -189,19 +197,23 @@ func (tx *Tx) init() { tx.BomItem = NewBomItemClient(tx.config) tx.DailyPlan = NewDailyPlanClient(tx.config) tx.EventLog = NewEventLogClient(tx.config) + tx.InspectionRecord = NewInspectionRecordClient(tx.config) tx.MaterialRequest = NewMaterialRequestClient(tx.config) tx.Permission = NewPermissionClient(tx.config) tx.PlcSendLog = NewPlcSendLogClient(tx.config) + tx.ProcessFlow = NewProcessFlowClient(tx.config) 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) tx.StepCriterion = NewStepCriterionClient(tx.config) tx.StepData = NewStepDataClient(tx.config) tx.TorqueRecord = NewTorqueRecordClient(tx.config) tx.User = NewUserClient(tx.config) + tx.UserStation = NewUserStationClient(tx.config) tx.WorkOrder = NewWorkOrderClient(tx.config) tx.Workpiece = NewWorkpieceClient(tx.config) tx.WorkpieceProcess = NewWorkpieceProcessClient(tx.config) diff --git a/bj_power_mes/ent/user.go b/bj_power_mes/ent/user.go index 15b9e1a..af5f942 100644 --- a/bj_power_mes/ent/user.go +++ b/bj_power_mes/ent/user.go @@ -25,6 +25,10 @@ type User struct { Name string `json:"name,omitempty"` // 角色ID RoleId int `json:"roleId,omitempty"` + // 是否允许登录工位终端 + CanLoginWorkstation bool `json:"canLoginWorkstation,omitempty"` + // 工位终端密码(bcrypt) + WorkstationPassword string `json:"workstationPassword,omitempty"` // Status holds the value of the "status" field. Status string `json:"status,omitempty"` // CreatedAt holds the value of the "createdAt" field. @@ -39,9 +43,11 @@ func (*User) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { + case user.FieldCanLoginWorkstation: + values[i] = new(sql.NullBool) case user.FieldID, user.FieldRoleId: values[i] = new(sql.NullInt64) - case user.FieldUsername, user.FieldPassword, user.FieldName, user.FieldStatus: + case user.FieldUsername, user.FieldPassword, user.FieldName, user.FieldWorkstationPassword, user.FieldStatus: values[i] = new(sql.NullString) case user.FieldCreatedAt, user.FieldUpdatedAt: values[i] = new(sql.NullTime) @@ -90,6 +96,18 @@ func (_m *User) assignValues(columns []string, values []any) error { } else if value.Valid { _m.RoleId = int(value.Int64) } + case user.FieldCanLoginWorkstation: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field canLoginWorkstation", values[i]) + } else if value.Valid { + _m.CanLoginWorkstation = value.Bool + } + case user.FieldWorkstationPassword: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field workstationPassword", values[i]) + } else if value.Valid { + _m.WorkstationPassword = value.String + } case user.FieldStatus: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) @@ -157,6 +175,12 @@ func (_m *User) String() string { builder.WriteString("roleId=") builder.WriteString(fmt.Sprintf("%v", _m.RoleId)) builder.WriteString(", ") + builder.WriteString("canLoginWorkstation=") + builder.WriteString(fmt.Sprintf("%v", _m.CanLoginWorkstation)) + builder.WriteString(", ") + builder.WriteString("workstationPassword=") + builder.WriteString(_m.WorkstationPassword) + builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(_m.Status) builder.WriteString(", ") diff --git a/bj_power_mes/ent/user/user.go b/bj_power_mes/ent/user/user.go index 386ad13..fec9ab6 100644 --- a/bj_power_mes/ent/user/user.go +++ b/bj_power_mes/ent/user/user.go @@ -21,6 +21,10 @@ const ( FieldName = "name" // FieldRoleId holds the string denoting the roleid field in the database. FieldRoleId = "role_id" + // FieldCanLoginWorkstation holds the string denoting the canloginworkstation field in the database. + FieldCanLoginWorkstation = "can_login_workstation" + // FieldWorkstationPassword holds the string denoting the workstationpassword field in the database. + FieldWorkstationPassword = "workstation_password" // FieldStatus holds the string denoting the status field in the database. FieldStatus = "status" // FieldCreatedAt holds the string denoting the createdat field in the database. @@ -38,6 +42,8 @@ var Columns = []string{ FieldPassword, FieldName, FieldRoleId, + FieldCanLoginWorkstation, + FieldWorkstationPassword, FieldStatus, FieldCreatedAt, FieldUpdatedAt, @@ -62,6 +68,10 @@ var ( DefaultName string // NameValidator is a validator for the "name" field. It is called by the builders before save. NameValidator func(string) error + // DefaultCanLoginWorkstation holds the default value on creation for the "canLoginWorkstation" field. + DefaultCanLoginWorkstation bool + // WorkstationPasswordValidator is a validator for the "workstationPassword" field. It is called by the builders before save. + WorkstationPasswordValidator func(string) error // DefaultStatus holds the default value on creation for the "status" field. DefaultStatus string // StatusValidator is a validator for the "status" field. It is called by the builders before save. @@ -104,6 +114,16 @@ func ByRoleId(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldRoleId, opts...).ToFunc() } +// ByCanLoginWorkstation orders the results by the canLoginWorkstation field. +func ByCanLoginWorkstation(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCanLoginWorkstation, opts...).ToFunc() +} + +// ByWorkstationPassword orders the results by the workstationPassword field. +func ByWorkstationPassword(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldWorkstationPassword, opts...).ToFunc() +} + // ByStatus orders the results by the status field. func ByStatus(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldStatus, opts...).ToFunc() diff --git a/bj_power_mes/ent/user/where.go b/bj_power_mes/ent/user/where.go index 31b9e29..42f67f1 100644 --- a/bj_power_mes/ent/user/where.go +++ b/bj_power_mes/ent/user/where.go @@ -74,6 +74,16 @@ func RoleId(v int) predicate.User { return predicate.User(sql.FieldEQ(FieldRoleId, v)) } +// CanLoginWorkstation applies equality check predicate on the "canLoginWorkstation" field. It's identical to CanLoginWorkstationEQ. +func CanLoginWorkstation(v bool) predicate.User { + return predicate.User(sql.FieldEQ(FieldCanLoginWorkstation, v)) +} + +// WorkstationPassword applies equality check predicate on the "workstationPassword" field. It's identical to WorkstationPasswordEQ. +func WorkstationPassword(v string) predicate.User { + return predicate.User(sql.FieldEQ(FieldWorkstationPassword, v)) +} + // Status applies equality check predicate on the "status" field. It's identical to StatusEQ. func Status(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldStatus, v)) @@ -334,6 +344,91 @@ func RoleIdNotNil() predicate.User { return predicate.User(sql.FieldNotNull(FieldRoleId)) } +// CanLoginWorkstationEQ applies the EQ predicate on the "canLoginWorkstation" field. +func CanLoginWorkstationEQ(v bool) predicate.User { + return predicate.User(sql.FieldEQ(FieldCanLoginWorkstation, v)) +} + +// CanLoginWorkstationNEQ applies the NEQ predicate on the "canLoginWorkstation" field. +func CanLoginWorkstationNEQ(v bool) predicate.User { + return predicate.User(sql.FieldNEQ(FieldCanLoginWorkstation, v)) +} + +// WorkstationPasswordEQ applies the EQ predicate on the "workstationPassword" field. +func WorkstationPasswordEQ(v string) predicate.User { + return predicate.User(sql.FieldEQ(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordNEQ applies the NEQ predicate on the "workstationPassword" field. +func WorkstationPasswordNEQ(v string) predicate.User { + return predicate.User(sql.FieldNEQ(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordIn applies the In predicate on the "workstationPassword" field. +func WorkstationPasswordIn(vs ...string) predicate.User { + return predicate.User(sql.FieldIn(FieldWorkstationPassword, vs...)) +} + +// WorkstationPasswordNotIn applies the NotIn predicate on the "workstationPassword" field. +func WorkstationPasswordNotIn(vs ...string) predicate.User { + return predicate.User(sql.FieldNotIn(FieldWorkstationPassword, vs...)) +} + +// WorkstationPasswordGT applies the GT predicate on the "workstationPassword" field. +func WorkstationPasswordGT(v string) predicate.User { + return predicate.User(sql.FieldGT(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordGTE applies the GTE predicate on the "workstationPassword" field. +func WorkstationPasswordGTE(v string) predicate.User { + return predicate.User(sql.FieldGTE(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordLT applies the LT predicate on the "workstationPassword" field. +func WorkstationPasswordLT(v string) predicate.User { + return predicate.User(sql.FieldLT(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordLTE applies the LTE predicate on the "workstationPassword" field. +func WorkstationPasswordLTE(v string) predicate.User { + return predicate.User(sql.FieldLTE(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordContains applies the Contains predicate on the "workstationPassword" field. +func WorkstationPasswordContains(v string) predicate.User { + return predicate.User(sql.FieldContains(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordHasPrefix applies the HasPrefix predicate on the "workstationPassword" field. +func WorkstationPasswordHasPrefix(v string) predicate.User { + return predicate.User(sql.FieldHasPrefix(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordHasSuffix applies the HasSuffix predicate on the "workstationPassword" field. +func WorkstationPasswordHasSuffix(v string) predicate.User { + return predicate.User(sql.FieldHasSuffix(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordIsNil applies the IsNil predicate on the "workstationPassword" field. +func WorkstationPasswordIsNil() predicate.User { + return predicate.User(sql.FieldIsNull(FieldWorkstationPassword)) +} + +// WorkstationPasswordNotNil applies the NotNil predicate on the "workstationPassword" field. +func WorkstationPasswordNotNil() predicate.User { + return predicate.User(sql.FieldNotNull(FieldWorkstationPassword)) +} + +// WorkstationPasswordEqualFold applies the EqualFold predicate on the "workstationPassword" field. +func WorkstationPasswordEqualFold(v string) predicate.User { + return predicate.User(sql.FieldEqualFold(FieldWorkstationPassword, v)) +} + +// WorkstationPasswordContainsFold applies the ContainsFold predicate on the "workstationPassword" field. +func WorkstationPasswordContainsFold(v string) predicate.User { + return predicate.User(sql.FieldContainsFold(FieldWorkstationPassword, v)) +} + // StatusEQ applies the EQ predicate on the "status" field. func StatusEQ(v string) predicate.User { return predicate.User(sql.FieldEQ(FieldStatus, v)) diff --git a/bj_power_mes/ent/user_create.go b/bj_power_mes/ent/user_create.go index 181b82c..38d7672 100644 --- a/bj_power_mes/ent/user_create.go +++ b/bj_power_mes/ent/user_create.go @@ -60,6 +60,34 @@ func (_c *UserCreate) SetNillableRoleId(v *int) *UserCreate { return _c } +// SetCanLoginWorkstation sets the "canLoginWorkstation" field. +func (_c *UserCreate) SetCanLoginWorkstation(v bool) *UserCreate { + _c.mutation.SetCanLoginWorkstation(v) + return _c +} + +// SetNillableCanLoginWorkstation sets the "canLoginWorkstation" field if the given value is not nil. +func (_c *UserCreate) SetNillableCanLoginWorkstation(v *bool) *UserCreate { + if v != nil { + _c.SetCanLoginWorkstation(*v) + } + return _c +} + +// SetWorkstationPassword sets the "workstationPassword" field. +func (_c *UserCreate) SetWorkstationPassword(v string) *UserCreate { + _c.mutation.SetWorkstationPassword(v) + return _c +} + +// SetNillableWorkstationPassword sets the "workstationPassword" field if the given value is not nil. +func (_c *UserCreate) SetNillableWorkstationPassword(v *string) *UserCreate { + if v != nil { + _c.SetWorkstationPassword(*v) + } + return _c +} + // SetStatus sets the "status" field. func (_c *UserCreate) SetStatus(v string) *UserCreate { _c.mutation.SetStatus(v) @@ -147,6 +175,10 @@ func (_c *UserCreate) defaults() { v := user.DefaultName _c.mutation.SetName(v) } + if _, ok := _c.mutation.CanLoginWorkstation(); !ok { + v := user.DefaultCanLoginWorkstation + _c.mutation.SetCanLoginWorkstation(v) + } if _, ok := _c.mutation.Status(); !ok { v := user.DefaultStatus _c.mutation.SetStatus(v) @@ -187,6 +219,14 @@ func (_c *UserCreate) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)} } } + if _, ok := _c.mutation.CanLoginWorkstation(); !ok { + return &ValidationError{Name: "canLoginWorkstation", err: errors.New(`ent: missing required field "User.canLoginWorkstation"`)} + } + if v, ok := _c.mutation.WorkstationPassword(); ok { + if err := user.WorkstationPasswordValidator(v); err != nil { + return &ValidationError{Name: "workstationPassword", err: fmt.Errorf(`ent: validator failed for field "User.workstationPassword": %w`, err)} + } + } if _, ok := _c.mutation.Status(); !ok { return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "User.status"`)} } @@ -251,6 +291,14 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { _spec.SetField(user.FieldRoleId, field.TypeInt, value) _node.RoleId = value } + if value, ok := _c.mutation.CanLoginWorkstation(); ok { + _spec.SetField(user.FieldCanLoginWorkstation, field.TypeBool, value) + _node.CanLoginWorkstation = value + } + if value, ok := _c.mutation.WorkstationPassword(); ok { + _spec.SetField(user.FieldWorkstationPassword, field.TypeString, value) + _node.WorkstationPassword = value + } if value, ok := _c.mutation.Status(); ok { _spec.SetField(user.FieldStatus, field.TypeString, value) _node.Status = value diff --git a/bj_power_mes/ent/user_update.go b/bj_power_mes/ent/user_update.go index 2df291a..a305fd7 100644 --- a/bj_power_mes/ent/user_update.go +++ b/bj_power_mes/ent/user_update.go @@ -98,6 +98,40 @@ func (_u *UserUpdate) ClearRoleId() *UserUpdate { return _u } +// SetCanLoginWorkstation sets the "canLoginWorkstation" field. +func (_u *UserUpdate) SetCanLoginWorkstation(v bool) *UserUpdate { + _u.mutation.SetCanLoginWorkstation(v) + return _u +} + +// SetNillableCanLoginWorkstation sets the "canLoginWorkstation" field if the given value is not nil. +func (_u *UserUpdate) SetNillableCanLoginWorkstation(v *bool) *UserUpdate { + if v != nil { + _u.SetCanLoginWorkstation(*v) + } + return _u +} + +// SetWorkstationPassword sets the "workstationPassword" field. +func (_u *UserUpdate) SetWorkstationPassword(v string) *UserUpdate { + _u.mutation.SetWorkstationPassword(v) + return _u +} + +// SetNillableWorkstationPassword sets the "workstationPassword" field if the given value is not nil. +func (_u *UserUpdate) SetNillableWorkstationPassword(v *string) *UserUpdate { + if v != nil { + _u.SetWorkstationPassword(*v) + } + return _u +} + +// ClearWorkstationPassword clears the value of the "workstationPassword" field. +func (_u *UserUpdate) ClearWorkstationPassword() *UserUpdate { + _u.mutation.ClearWorkstationPassword() + return _u +} + // SetStatus sets the "status" field. func (_u *UserUpdate) SetStatus(v string) *UserUpdate { _u.mutation.SetStatus(v) @@ -182,6 +216,11 @@ func (_u *UserUpdate) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)} } } + if v, ok := _u.mutation.WorkstationPassword(); ok { + if err := user.WorkstationPasswordValidator(v); err != nil { + return &ValidationError{Name: "workstationPassword", err: fmt.Errorf(`ent: validator failed for field "User.workstationPassword": %w`, err)} + } + } if v, ok := _u.mutation.Status(); ok { if err := user.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)} @@ -226,6 +265,15 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) { if _u.mutation.RoleIdCleared() { _spec.ClearField(user.FieldRoleId, field.TypeInt) } + if value, ok := _u.mutation.CanLoginWorkstation(); ok { + _spec.SetField(user.FieldCanLoginWorkstation, field.TypeBool, value) + } + if value, ok := _u.mutation.WorkstationPassword(); ok { + _spec.SetField(user.FieldWorkstationPassword, field.TypeString, value) + } + if _u.mutation.WorkstationPasswordCleared() { + _spec.ClearField(user.FieldWorkstationPassword, field.TypeString) + } if value, ok := _u.mutation.Status(); ok { _spec.SetField(user.FieldStatus, field.TypeString, value) } @@ -326,6 +374,40 @@ func (_u *UserUpdateOne) ClearRoleId() *UserUpdateOne { return _u } +// SetCanLoginWorkstation sets the "canLoginWorkstation" field. +func (_u *UserUpdateOne) SetCanLoginWorkstation(v bool) *UserUpdateOne { + _u.mutation.SetCanLoginWorkstation(v) + return _u +} + +// SetNillableCanLoginWorkstation sets the "canLoginWorkstation" field if the given value is not nil. +func (_u *UserUpdateOne) SetNillableCanLoginWorkstation(v *bool) *UserUpdateOne { + if v != nil { + _u.SetCanLoginWorkstation(*v) + } + return _u +} + +// SetWorkstationPassword sets the "workstationPassword" field. +func (_u *UserUpdateOne) SetWorkstationPassword(v string) *UserUpdateOne { + _u.mutation.SetWorkstationPassword(v) + return _u +} + +// SetNillableWorkstationPassword sets the "workstationPassword" field if the given value is not nil. +func (_u *UserUpdateOne) SetNillableWorkstationPassword(v *string) *UserUpdateOne { + if v != nil { + _u.SetWorkstationPassword(*v) + } + return _u +} + +// ClearWorkstationPassword clears the value of the "workstationPassword" field. +func (_u *UserUpdateOne) ClearWorkstationPassword() *UserUpdateOne { + _u.mutation.ClearWorkstationPassword() + return _u +} + // SetStatus sets the "status" field. func (_u *UserUpdateOne) SetStatus(v string) *UserUpdateOne { _u.mutation.SetStatus(v) @@ -423,6 +505,11 @@ func (_u *UserUpdateOne) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "User.name": %w`, err)} } } + if v, ok := _u.mutation.WorkstationPassword(); ok { + if err := user.WorkstationPasswordValidator(v); err != nil { + return &ValidationError{Name: "workstationPassword", err: fmt.Errorf(`ent: validator failed for field "User.workstationPassword": %w`, err)} + } + } if v, ok := _u.mutation.Status(); ok { if err := user.StatusValidator(v); err != nil { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "User.status": %w`, err)} @@ -484,6 +571,15 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { if _u.mutation.RoleIdCleared() { _spec.ClearField(user.FieldRoleId, field.TypeInt) } + if value, ok := _u.mutation.CanLoginWorkstation(); ok { + _spec.SetField(user.FieldCanLoginWorkstation, field.TypeBool, value) + } + if value, ok := _u.mutation.WorkstationPassword(); ok { + _spec.SetField(user.FieldWorkstationPassword, field.TypeString, value) + } + if _u.mutation.WorkstationPasswordCleared() { + _spec.ClearField(user.FieldWorkstationPassword, field.TypeString) + } if value, ok := _u.mutation.Status(); ok { _spec.SetField(user.FieldStatus, field.TypeString, value) } diff --git a/bj_power_mes/ent/userstation.go b/bj_power_mes/ent/userstation.go new file mode 100644 index 0000000..4dfde31 --- /dev/null +++ b/bj_power_mes/ent/userstation.go @@ -0,0 +1,126 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/userstation" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// UserStation is the model entity for the UserStation schema. +type UserStation struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // 用户ID + UserId int `json:"userId,omitempty"` + // 工位号 1..12 + StationNo int `json:"stationNo,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 (*UserStation) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case userstation.FieldID, userstation.FieldUserId, userstation.FieldStationNo: + values[i] = new(sql.NullInt64) + case userstation.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 UserStation fields. +func (_m *UserStation) 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 userstation.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 userstation.FieldUserId: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field userId", values[i]) + } else if value.Valid { + _m.UserId = int(value.Int64) + } + case userstation.FieldStationNo: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field stationNo", values[i]) + } else if value.Valid { + _m.StationNo = int(value.Int64) + } + case userstation.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 UserStation. +// This includes values selected through modifiers, order, etc. +func (_m *UserStation) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this UserStation. +// Note that you need to call UserStation.Unwrap() before calling this method if this UserStation +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *UserStation) Update() *UserStationUpdateOne { + return NewUserStationClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the UserStation 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 *UserStation) Unwrap() *UserStation { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: UserStation is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *UserStation) String() string { + var builder strings.Builder + builder.WriteString("UserStation(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("userId=") + builder.WriteString(fmt.Sprintf("%v", _m.UserId)) + builder.WriteString(", ") + builder.WriteString("stationNo=") + builder.WriteString(fmt.Sprintf("%v", _m.StationNo)) + builder.WriteString(", ") + builder.WriteString("createdAt=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// UserStations is a parsable slice of UserStation. +type UserStations []*UserStation diff --git a/bj_power_mes/ent/userstation/userstation.go b/bj_power_mes/ent/userstation/userstation.go new file mode 100644 index 0000000..5e4c96c --- /dev/null +++ b/bj_power_mes/ent/userstation/userstation.go @@ -0,0 +1,72 @@ +// Code generated by ent, DO NOT EDIT. + +package userstation + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the userstation type in the database. + Label = "user_station" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldUserId holds the string denoting the userid field in the database. + FieldUserId = "user_id" + // FieldStationNo holds the string denoting the stationno field in the database. + FieldStationNo = "station_no" + // FieldCreatedAt holds the string denoting the createdat field in the database. + FieldCreatedAt = "created_at" + // Table holds the table name of the userstation in the database. + Table = "user_station" +) + +// Columns holds all SQL columns for userstation fields. +var Columns = []string{ + FieldID, + FieldUserId, + FieldStationNo, + 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 ( + // 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 UserStation 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() +} + +// ByUserId orders the results by the userId field. +func ByUserId(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUserId, opts...).ToFunc() +} + +// ByStationNo orders the results by the stationNo field. +func ByStationNo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStationNo, 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/userstation/where.go b/bj_power_mes/ent/userstation/where.go new file mode 100644 index 0000000..3a1e28b --- /dev/null +++ b/bj_power_mes/ent/userstation/where.go @@ -0,0 +1,205 @@ +// Code generated by ent, DO NOT EDIT. + +package userstation + +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.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.UserStation { + return predicate.UserStation(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.UserStation { + return predicate.UserStation(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.UserStation { + return predicate.UserStation(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.UserStation { + return predicate.UserStation(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.UserStation { + return predicate.UserStation(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.UserStation { + return predicate.UserStation(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.UserStation { + return predicate.UserStation(sql.FieldLTE(FieldID, id)) +} + +// UserId applies equality check predicate on the "userId" field. It's identical to UserIdEQ. +func UserId(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldUserId, v)) +} + +// StationNo applies equality check predicate on the "stationNo" field. It's identical to StationNoEQ. +func StationNo(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldStationNo, v)) +} + +// CreatedAt applies equality check predicate on the "createdAt" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UserIdEQ applies the EQ predicate on the "userId" field. +func UserIdEQ(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldUserId, v)) +} + +// UserIdNEQ applies the NEQ predicate on the "userId" field. +func UserIdNEQ(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldNEQ(FieldUserId, v)) +} + +// UserIdIn applies the In predicate on the "userId" field. +func UserIdIn(vs ...int) predicate.UserStation { + return predicate.UserStation(sql.FieldIn(FieldUserId, vs...)) +} + +// UserIdNotIn applies the NotIn predicate on the "userId" field. +func UserIdNotIn(vs ...int) predicate.UserStation { + return predicate.UserStation(sql.FieldNotIn(FieldUserId, vs...)) +} + +// UserIdGT applies the GT predicate on the "userId" field. +func UserIdGT(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldGT(FieldUserId, v)) +} + +// UserIdGTE applies the GTE predicate on the "userId" field. +func UserIdGTE(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldGTE(FieldUserId, v)) +} + +// UserIdLT applies the LT predicate on the "userId" field. +func UserIdLT(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldLT(FieldUserId, v)) +} + +// UserIdLTE applies the LTE predicate on the "userId" field. +func UserIdLTE(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldLTE(FieldUserId, v)) +} + +// StationNoEQ applies the EQ predicate on the "stationNo" field. +func StationNoEQ(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldStationNo, v)) +} + +// StationNoNEQ applies the NEQ predicate on the "stationNo" field. +func StationNoNEQ(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldNEQ(FieldStationNo, v)) +} + +// StationNoIn applies the In predicate on the "stationNo" field. +func StationNoIn(vs ...int) predicate.UserStation { + return predicate.UserStation(sql.FieldIn(FieldStationNo, vs...)) +} + +// StationNoNotIn applies the NotIn predicate on the "stationNo" field. +func StationNoNotIn(vs ...int) predicate.UserStation { + return predicate.UserStation(sql.FieldNotIn(FieldStationNo, vs...)) +} + +// StationNoGT applies the GT predicate on the "stationNo" field. +func StationNoGT(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldGT(FieldStationNo, v)) +} + +// StationNoGTE applies the GTE predicate on the "stationNo" field. +func StationNoGTE(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldGTE(FieldStationNo, v)) +} + +// StationNoLT applies the LT predicate on the "stationNo" field. +func StationNoLT(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldLT(FieldStationNo, v)) +} + +// StationNoLTE applies the LTE predicate on the "stationNo" field. +func StationNoLTE(v int) predicate.UserStation { + return predicate.UserStation(sql.FieldLTE(FieldStationNo, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "createdAt" field. +func CreatedAtEQ(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "createdAt" field. +func CreatedAtNEQ(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "createdAt" field. +func CreatedAtIn(vs ...time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "createdAt" field. +func CreatedAtNotIn(vs ...time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "createdAt" field. +func CreatedAtGT(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "createdAt" field. +func CreatedAtGTE(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "createdAt" field. +func CreatedAtLT(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "createdAt" field. +func CreatedAtLTE(v time.Time) predicate.UserStation { + return predicate.UserStation(sql.FieldLTE(FieldCreatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.UserStation) predicate.UserStation { + return predicate.UserStation(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.UserStation) predicate.UserStation { + return predicate.UserStation(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.UserStation) predicate.UserStation { + return predicate.UserStation(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/userstation_create.go b/bj_power_mes/ent/userstation_create.go new file mode 100644 index 0000000..5301a62 --- /dev/null +++ b/bj_power_mes/ent/userstation_create.go @@ -0,0 +1,245 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/userstation" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// UserStationCreate is the builder for creating a UserStation entity. +type UserStationCreate struct { + config + mutation *UserStationMutation + hooks []Hook +} + +// SetUserId sets the "userId" field. +func (_c *UserStationCreate) SetUserId(v int) *UserStationCreate { + _c.mutation.SetUserId(v) + return _c +} + +// SetStationNo sets the "stationNo" field. +func (_c *UserStationCreate) SetStationNo(v int) *UserStationCreate { + _c.mutation.SetStationNo(v) + return _c +} + +// SetCreatedAt sets the "createdAt" field. +func (_c *UserStationCreate) SetCreatedAt(v time.Time) *UserStationCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil. +func (_c *UserStationCreate) SetNillableCreatedAt(v *time.Time) *UserStationCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// SetID sets the "id" field. +func (_c *UserStationCreate) SetID(v int) *UserStationCreate { + _c.mutation.SetID(v) + return _c +} + +// Mutation returns the UserStationMutation object of the builder. +func (_c *UserStationCreate) Mutation() *UserStationMutation { + return _c.mutation +} + +// Save creates the UserStation in the database. +func (_c *UserStationCreate) Save(ctx context.Context) (*UserStation, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *UserStationCreate) SaveX(ctx context.Context) *UserStation { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *UserStationCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *UserStationCreate) 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 *UserStationCreate) defaults() { + if _, ok := _c.mutation.CreatedAt(); !ok { + v := userstation.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *UserStationCreate) check() error { + if _, ok := _c.mutation.UserId(); !ok { + return &ValidationError{Name: "userId", err: errors.New(`ent: missing required field "UserStation.userId"`)} + } + if _, ok := _c.mutation.StationNo(); !ok { + return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "UserStation.stationNo"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "UserStation.createdAt"`)} + } + if v, ok := _c.mutation.ID(); ok { + if err := userstation.IDValidator(v); err != nil { + return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "UserStation.id": %w`, err)} + } + } + return nil +} + +func (_c *UserStationCreate) sqlSave(ctx context.Context) (*UserStation, 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 *UserStationCreate) createSpec() (*UserStation, *sqlgraph.CreateSpec) { + var ( + _node = &UserStation{config: _c.config} + _spec = sqlgraph.NewCreateSpec(userstation.Table, sqlgraph.NewFieldSpec(userstation.FieldID, field.TypeInt)) + ) + if id, ok := _c.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := _c.mutation.UserId(); ok { + _spec.SetField(userstation.FieldUserId, field.TypeInt, value) + _node.UserId = value + } + if value, ok := _c.mutation.StationNo(); ok { + _spec.SetField(userstation.FieldStationNo, field.TypeInt, value) + _node.StationNo = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(userstation.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + return _node, _spec +} + +// UserStationCreateBulk is the builder for creating many UserStation entities in bulk. +type UserStationCreateBulk struct { + config + err error + builders []*UserStationCreate +} + +// Save creates the UserStation entities in the database. +func (_c *UserStationCreateBulk) Save(ctx context.Context) ([]*UserStation, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*UserStation, 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.(*UserStationMutation) + 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 *UserStationCreateBulk) SaveX(ctx context.Context) []*UserStation { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *UserStationCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *UserStationCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/userstation_delete.go b/bj_power_mes/ent/userstation_delete.go new file mode 100644 index 0000000..dfb87ec --- /dev/null +++ b/bj_power_mes/ent/userstation_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/userstation" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// UserStationDelete is the builder for deleting a UserStation entity. +type UserStationDelete struct { + config + hooks []Hook + mutation *UserStationMutation +} + +// Where appends a list predicates to the UserStationDelete builder. +func (_d *UserStationDelete) Where(ps ...predicate.UserStation) *UserStationDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *UserStationDelete) 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 *UserStationDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *UserStationDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(userstation.Table, sqlgraph.NewFieldSpec(userstation.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 +} + +// UserStationDeleteOne is the builder for deleting a single UserStation entity. +type UserStationDeleteOne struct { + _d *UserStationDelete +} + +// Where appends a list predicates to the UserStationDelete builder. +func (_d *UserStationDeleteOne) Where(ps ...predicate.UserStation) *UserStationDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *UserStationDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{userstation.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *UserStationDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/userstation_query.go b/bj_power_mes/ent/userstation_query.go new file mode 100644 index 0000000..4812e86 --- /dev/null +++ b/bj_power_mes/ent/userstation_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/userstation" + "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" +) + +// UserStationQuery is the builder for querying UserStation entities. +type UserStationQuery struct { + config + ctx *QueryContext + order []userstation.OrderOption + inters []Interceptor + predicates []predicate.UserStation + 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 UserStationQuery builder. +func (_q *UserStationQuery) Where(ps ...predicate.UserStation) *UserStationQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *UserStationQuery) Limit(limit int) *UserStationQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *UserStationQuery) Offset(offset int) *UserStationQuery { + _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 *UserStationQuery) Unique(unique bool) *UserStationQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *UserStationQuery) Order(o ...userstation.OrderOption) *UserStationQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first UserStation entity from the query. +// Returns a *NotFoundError when no UserStation was found. +func (_q *UserStationQuery) First(ctx context.Context) (*UserStation, 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{userstation.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *UserStationQuery) FirstX(ctx context.Context) *UserStation { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first UserStation ID from the query. +// Returns a *NotFoundError when no UserStation ID was found. +func (_q *UserStationQuery) 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{userstation.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *UserStationQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single UserStation entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one UserStation entity is found. +// Returns a *NotFoundError when no UserStation entities are found. +func (_q *UserStationQuery) Only(ctx context.Context) (*UserStation, 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{userstation.Label} + default: + return nil, &NotSingularError{userstation.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *UserStationQuery) OnlyX(ctx context.Context) *UserStation { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only UserStation ID in the query. +// Returns a *NotSingularError when more than one UserStation ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *UserStationQuery) 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{userstation.Label} + default: + err = &NotSingularError{userstation.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *UserStationQuery) 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 UserStations. +func (_q *UserStationQuery) All(ctx context.Context) ([]*UserStation, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*UserStation, *UserStationQuery]() + return withInterceptors[[]*UserStation](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *UserStationQuery) AllX(ctx context.Context) []*UserStation { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of UserStation IDs. +func (_q *UserStationQuery) 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(userstation.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *UserStationQuery) 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 *UserStationQuery) 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[*UserStationQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *UserStationQuery) 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 *UserStationQuery) 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 *UserStationQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the UserStationQuery 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 *UserStationQuery) Clone() *UserStationQuery { + if _q == nil { + return nil + } + return &UserStationQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]userstation.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.UserStation{}, _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 { +// UserId int `json:"userId,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.UserStation.Query(). +// GroupBy(userstation.FieldUserId). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *UserStationQuery) GroupBy(field string, fields ...string) *UserStationGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &UserStationGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = userstation.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 { +// UserId int `json:"userId,omitempty"` +// } +// +// client.UserStation.Query(). +// Select(userstation.FieldUserId). +// Scan(ctx, &v) +func (_q *UserStationQuery) Select(fields ...string) *UserStationSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &UserStationSelect{UserStationQuery: _q} + sbuild.label = userstation.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a UserStationSelect configured with the given aggregations. +func (_q *UserStationQuery) Aggregate(fns ...AggregateFunc) *UserStationSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *UserStationQuery) 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 !userstation.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 *UserStationQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*UserStation, error) { + var ( + nodes = []*UserStation{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*UserStation).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &UserStation{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 *UserStationQuery) 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 *UserStationQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(userstation.Table, userstation.Columns, sqlgraph.NewFieldSpec(userstation.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, userstation.FieldID) + for i := range fields { + if fields[i] != userstation.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 *UserStationQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(userstation.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = userstation.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 *UserStationQuery) ForUpdate(opts ...sql.LockOption) *UserStationQuery { + 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 *UserStationQuery) ForShare(opts ...sql.LockOption) *UserStationQuery { + 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 *UserStationQuery) Modify(modifiers ...func(s *sql.Selector)) *UserStationSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// UserStationGroupBy is the group-by builder for UserStation entities. +type UserStationGroupBy struct { + selector + build *UserStationQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *UserStationGroupBy) Aggregate(fns ...AggregateFunc) *UserStationGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *UserStationGroupBy) 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[*UserStationQuery, *UserStationGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *UserStationGroupBy) sqlScan(ctx context.Context, root *UserStationQuery, 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) +} + +// UserStationSelect is the builder for selecting fields of UserStation entities. +type UserStationSelect struct { + *UserStationQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *UserStationSelect) Aggregate(fns ...AggregateFunc) *UserStationSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *UserStationSelect) 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[*UserStationQuery, *UserStationSelect](ctx, _s.UserStationQuery, _s, _s.inters, v) +} + +func (_s *UserStationSelect) sqlScan(ctx context.Context, root *UserStationQuery, 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 *UserStationSelect) Modify(modifiers ...func(s *sql.Selector)) *UserStationSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/userstation_update.go b/bj_power_mes/ent/userstation_update.go new file mode 100644 index 0000000..eb71d8d --- /dev/null +++ b/bj_power_mes/ent/userstation_update.go @@ -0,0 +1,299 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/predicate" + "bj_power_mes/ent/userstation" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// UserStationUpdate is the builder for updating UserStation entities. +type UserStationUpdate struct { + config + hooks []Hook + mutation *UserStationMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the UserStationUpdate builder. +func (_u *UserStationUpdate) Where(ps ...predicate.UserStation) *UserStationUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetUserId sets the "userId" field. +func (_u *UserStationUpdate) SetUserId(v int) *UserStationUpdate { + _u.mutation.ResetUserId() + _u.mutation.SetUserId(v) + return _u +} + +// SetNillableUserId sets the "userId" field if the given value is not nil. +func (_u *UserStationUpdate) SetNillableUserId(v *int) *UserStationUpdate { + if v != nil { + _u.SetUserId(*v) + } + return _u +} + +// AddUserId adds value to the "userId" field. +func (_u *UserStationUpdate) AddUserId(v int) *UserStationUpdate { + _u.mutation.AddUserId(v) + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *UserStationUpdate) SetStationNo(v int) *UserStationUpdate { + _u.mutation.ResetStationNo() + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *UserStationUpdate) SetNillableStationNo(v *int) *UserStationUpdate { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// AddStationNo adds value to the "stationNo" field. +func (_u *UserStationUpdate) AddStationNo(v int) *UserStationUpdate { + _u.mutation.AddStationNo(v) + return _u +} + +// Mutation returns the UserStationMutation object of the builder. +func (_u *UserStationUpdate) Mutation() *UserStationMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *UserStationUpdate) 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 *UserStationUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *UserStationUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *UserStationUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *UserStationUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserStationUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *UserStationUpdate) sqlSave(ctx context.Context) (_node int, err error) { + _spec := sqlgraph.NewUpdateSpec(userstation.Table, userstation.Columns, sqlgraph.NewFieldSpec(userstation.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.UserId(); ok { + _spec.SetField(userstation.FieldUserId, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedUserId(); ok { + _spec.AddField(userstation.FieldUserId, field.TypeInt, value) + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(userstation.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedStationNo(); ok { + _spec.AddField(userstation.FieldStationNo, field.TypeInt, value) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{userstation.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// UserStationUpdateOne is the builder for updating a single UserStation entity. +type UserStationUpdateOne struct { + config + fields []string + hooks []Hook + mutation *UserStationMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetUserId sets the "userId" field. +func (_u *UserStationUpdateOne) SetUserId(v int) *UserStationUpdateOne { + _u.mutation.ResetUserId() + _u.mutation.SetUserId(v) + return _u +} + +// SetNillableUserId sets the "userId" field if the given value is not nil. +func (_u *UserStationUpdateOne) SetNillableUserId(v *int) *UserStationUpdateOne { + if v != nil { + _u.SetUserId(*v) + } + return _u +} + +// AddUserId adds value to the "userId" field. +func (_u *UserStationUpdateOne) AddUserId(v int) *UserStationUpdateOne { + _u.mutation.AddUserId(v) + return _u +} + +// SetStationNo sets the "stationNo" field. +func (_u *UserStationUpdateOne) SetStationNo(v int) *UserStationUpdateOne { + _u.mutation.ResetStationNo() + _u.mutation.SetStationNo(v) + return _u +} + +// SetNillableStationNo sets the "stationNo" field if the given value is not nil. +func (_u *UserStationUpdateOne) SetNillableStationNo(v *int) *UserStationUpdateOne { + if v != nil { + _u.SetStationNo(*v) + } + return _u +} + +// AddStationNo adds value to the "stationNo" field. +func (_u *UserStationUpdateOne) AddStationNo(v int) *UserStationUpdateOne { + _u.mutation.AddStationNo(v) + return _u +} + +// Mutation returns the UserStationMutation object of the builder. +func (_u *UserStationUpdateOne) Mutation() *UserStationMutation { + return _u.mutation +} + +// Where appends a list predicates to the UserStationUpdate builder. +func (_u *UserStationUpdateOne) Where(ps ...predicate.UserStation) *UserStationUpdateOne { + _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 *UserStationUpdateOne) Select(field string, fields ...string) *UserStationUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated UserStation entity. +func (_u *UserStationUpdateOne) Save(ctx context.Context) (*UserStation, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *UserStationUpdateOne) SaveX(ctx context.Context) *UserStation { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *UserStationUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *UserStationUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *UserStationUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *UserStationUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *UserStationUpdateOne) sqlSave(ctx context.Context) (_node *UserStation, err error) { + _spec := sqlgraph.NewUpdateSpec(userstation.Table, userstation.Columns, sqlgraph.NewFieldSpec(userstation.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserStation.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, userstation.FieldID) + for _, f := range fields { + if !userstation.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != userstation.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.UserId(); ok { + _spec.SetField(userstation.FieldUserId, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedUserId(); ok { + _spec.AddField(userstation.FieldUserId, field.TypeInt, value) + } + if value, ok := _u.mutation.StationNo(); ok { + _spec.SetField(userstation.FieldStationNo, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedStationNo(); ok { + _spec.AddField(userstation.FieldStationNo, field.TypeInt, value) + } + _spec.AddModifiers(_u.modifiers...) + _node = &UserStation{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{userstation.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_mes/frontend/src/help.js b/bj_power_mes/frontend/src/help.js index 03a0223..9e4cd03 100644 --- a/bj_power_mes/frontend/src/help.js +++ b/bj_power_mes/frontend/src/help.js @@ -200,4 +200,87 @@ export const helpEventLog = { { name: '操作人', source: '筛选条件。数据来自日志中的 operator 字段。', purpose: '按操作人过滤', fill: '输入姓名/账号,可空=全部' }, { name: '类型', source: '筛选条件。数据来自日志中的事件类型字段。', purpose: '按事件类型过滤', fill: '如 EVENT_WORK_ORDER / EVENT_TORQUE,可空' } ] +} + +export const helpProcessFlow = { + title: '工艺流程(流程图 ↔ 工序编号 ↔ 工位)', + overview: + '维护「流程图 → 工序编号(1~12) → 工位」三层关系,是工位终端和巡检的基础。\n\n模型:一个流程图只包含一个工序编号(如"工序3"),一个工序编号可有多个流程图版本(如 工序3_2026版/工序3_2027版),一个工位同时只绑定一个流程图。工位绑定流程图后,工位终端报工时 processCode 从流程取。\n\n数据链路:本页维护流程图+步骤模板+考核标准 → 工位绑定流程图 → 工位终端扫码采集按步骤模板渲染 → 报工写步骤数据并按标准判 OK/NG → 工件追溯/绩效报表可见。\n步骤的采集方式与考核标准与【工艺参数】页共用同一套模板数据。', + fields: [ + { name: '流程名称', source: '手工填写。人为定义。', purpose: '流程图版本名,用于区分同工序的不同版本', fill: '如 工序3_2026版' }, + { name: '工序编号', source: '下拉选择(1~12)。与产线 12 道工序一一对应。', purpose: '该流程图绑定哪道工序;一个流程只能绑一道', fill: '如 3' }, + { name: '工艺图纸(PDF)', source: '本页上传。上传的文件由 MES 服务器保存,生成文件名。', purpose: '该工序的作业指导图,工位终端打开并预览', fill: '选择 PDF 文件上传,上传成功后显示文件名,可预览' }, + { name: '步骤模板', source: '本页维护(步骤名/采集方式/是否拧紧)。采集方式三选一:AUTO=拧紧枪自动采集、MANUAL=手动录入、NONE=仅记录。', purpose: '工位终端报工时按此模板动态渲染参数输入;AUTO 步骤的值由拧紧枪采集结果带出', fill: '如 拧紧扭矩(MANUAL)、装配完成(NONE)' }, + { name: '考核标准', source: '本页为每个步骤维护(名称/单位/判定逻辑/目标值或上下限)。', purpose: '报工时系统按此标准自动判定该步骤 OK/NG,判定结果进入追溯与流程卡', fill: '如 扭矩 RANGE [35,45];角度 GE 90' }, + { name: '工位号', source: '【工位管理】tab 维护。下拉选择本页流程,即完成工位绑定。', purpose: '工位(1~12)绑定哪个流程图;一个工位同时只绑一个', fill: '选择工位号 + 该工位要用的流程' } + ] +} + +export const helpPerformance = { + title: '绩效报表(工人工作量统计)', + overview: + '按 操作人 × 日期 × 工序 汇总每个工人的完成/合格/NG 数量,用于工作量与绩效统计。\n\n数据来源:全部由工位终端/手动报工的「工序完成上报」自动写入工序实绩(workpiece_process),本页只读统计,不手工录入。\n\n数据链路:工位终端报工(写工序实绩) → 本页按人/天/工序聚合 → 出报表。', + fields: [ + { name: '操作人', source: '筛选条件。来自工序实绩的 operator 字段(工位终端登录人)。', purpose: '只看某个工人的工作量', fill: '输入姓名/账号,可空=全部' }, + { name: '日期范围', source: '筛选条件。来自工序实绩的产生时间。', purpose: '按时间段统计', fill: '选择起止日期,可空=全部' }, + { name: '完成数', source: '自动汇总。该 操作人×日期×工序 的报工次数。', purpose: '工作量核心指标', fill: '只读' }, + { name: '合格数/NG数', source: '自动汇总。按工序实绩 result 字段(OK/NG)分类计数。', purpose: '质量指标,OK+NG=完成数', fill: '只读' }, + { name: '合格率', source: '自动计算 = 合格数/完成数。', purpose: '质量表现', fill: '只读' } + ] +} + +export const helpInspect = { + title: '巡检终端(PAD / PC 通用)', + overview: + '检验员/线长用手持平板(PAD)或电脑浏览器做巡检与检验确认,PC 与 PAD 访问同一地址、前端自适应。\n\n数据来源:全部记录提交后写入 MES 巡检记录表(inspection_record),用于追溯和流程卡输出,也可在看板触发报警。\n\n权限:菜单「巡检终端」+ 各功能独立按钮权限码(sys.inspect:checkin/point/process/done/alarm/view),由【角色权限管理】统一分配。操作工通常无此菜单。', + sections: [ + { + title: '开工签到', + fields: [ + { name: '班次', source: '手动选择(早/中/晚)。', purpose: '记录开工班次', fill: '选早/中/晚' }, + { name: '拍照', source: '调用浏览器相册/摄像头(input file capture)。照片上传到 MES 服务器。', purpose: '留证现场开工状态', fill: '点击拍照并上传' }, + { name: '提交', source: '提交时自动记录:时间、拍照人(登录账号)、工位号。', purpose: '形成签到记录,供追溯', fill: '选班次+拍照后提交' } + ] + }, + { + title: '工位点检', + fields: [ + { name: '工位号', source: '手动选择(1~12)。', purpose: '点检哪个工位', fill: '选 1~12' }, + { name: '点检项', source: '手动多选(设备运行正常/安全防护到位/工具齐全/工位清洁)。', purpose: '点检的项目清单', fill: '勾选已完成的项目' }, + { name: '拍照', source: '浏览器相册/摄像头上传。', purpose: '留证', fill: '拍照上传' } + ] + }, + { + title: '过程巡检', + fields: [ + { name: '工单号', source: '手动选择/搜索。来自【工单管理】已建工单。', purpose: '对哪个工单巡检,可查看其当前工序进度', fill: '搜索选择工单号' }, + { name: '合格/不合格', source: '手动选择(OK/NG)。', purpose: '本次巡检结论', fill: '选择合格或不合格' }, + { name: '签字', source: '手写/输入签字内容。', purpose: '检验人签字留证', fill: '输入签字内容' } + ] + }, + { + title: '完工确认', + fields: [ + { name: '工单号', source: '手动选择/搜索。来自【工单管理】。', purpose: '确认哪个工单全部工序完成', fill: '搜索选择工单号' }, + { name: '确认全部工序完成', source: '手动勾选。', purpose: '声明该工单全部工序已完成', fill: '勾选确认' }, + { name: '签字', source: '手写/输入。', purpose: '确认人签字留证', fill: '输入签字内容' } + ] + }, + { + title: '异常上报', + fields: [ + { name: '工位号', source: '手动选择(1~12)。', purpose: '异常发生在哪个工位', fill: '选 1~12' }, + { name: '异常类型', source: '手动多选(设备故障/物料异常/工艺偏差/安全隐患/其他)。', purpose: '异常分类', fill: '勾选异常类型' }, + { name: '拍照', source: '浏览器相册/摄像头上传。', purpose: '留证异常现场', fill: '拍照上传' }, + { name: '文字描述', source: '手动填写。', purpose: '异常详细说明', fill: '描述异常情况' } + ] + }, + { + title: '记录查看', + fields: [ + { name: '类型/操作人/日期', source: '筛选条件。来自巡检记录表各字段。', purpose: '过滤历史巡检记录', fill: '可空=全部' }, + { name: '图片', source: '提交时上传的照片,MES 服务器存储。', purpose: '点击缩略图放大查看留证照片', fill: '只读' } + ] + } + ] } \ No newline at end of file diff --git a/bj_power_mes/frontend/src/layouts/MainLayout.vue b/bj_power_mes/frontend/src/layouts/MainLayout.vue index e91f487..e484bfd 100644 --- a/bj_power_mes/frontend/src/layouts/MainLayout.vue +++ b/bj_power_mes/frontend/src/layouts/MainLayout.vue @@ -2,12 +2,16 @@ - {{ m.name }} +
+

无可用菜单

+

请联系管理员分配权限

+
@@ -50,9 +54,12 @@ const defaultMenus = [ { code: 'produce.plc', name: 'PLC工序下发', path: '/plc-send' }, { code: 'produce.torque', name: '拧紧查询', path: '/torque' }, { code: 'produce.step', name: '工艺参数', path: '/process-step' }, + { code: 'produce.processflow', name: '工艺流程', path: '/process-flow' }, + { code: 'produce.performance', name: '绩效报表', path: '/performance' }, { code: 'produce.scan', name: '手动报工', path: '/scan' }, { code: 'produce.trace', name: '工件追溯', path: '/trace' }, { code: 'produce.product', name: '产品类型', path: '/product-type' }, + { code: 'sys.inspect', name: '巡检终端', path: '/inspect' }, { code: 'sys.eventlog', name: '操作日志', path: '/event-log' }, { code: 'sys.rbac', name: '角色权限管理', path: '/rbac' } ] @@ -78,6 +85,8 @@ function doLogout() { diff --git a/bj_power_mes/frontend/src/pages/MaterialRequest.vue b/bj_power_mes/frontend/src/pages/MaterialRequest.vue index b7f4f62..3b51758 100644 --- a/bj_power_mes/frontend/src/pages/MaterialRequest.vue +++ b/bj_power_mes/frontend/src/pages/MaterialRequest.vue @@ -8,7 +8,7 @@ 查询 - 按日排产生成备料 + 按日排产生成备料 @@ -34,6 +34,7 @@ import { reactive, ref, onMounted } from 'vue' import { ElMessage } from 'element-plus' import request from '../utils/request' +import { can } from '../utils/perm' import PageHelp from '../components/PageHelp.vue' import { helpMaterial } from '../help' diff --git a/bj_power_mes/frontend/src/pages/Performance.vue b/bj_power_mes/frontend/src/pages/Performance.vue new file mode 100644 index 0000000..a117b02 --- /dev/null +++ b/bj_power_mes/frontend/src/pages/Performance.vue @@ -0,0 +1,144 @@ + + + + + diff --git a/bj_power_mes/frontend/src/pages/PlcSend.vue b/bj_power_mes/frontend/src/pages/PlcSend.vue index c33801c..0aa44e4 100644 --- a/bj_power_mes/frontend/src/pages/PlcSend.vue +++ b/bj_power_mes/frontend/src/pages/PlcSend.vue @@ -6,7 +6,7 @@ - 下发工序码 + 下发工序码 @@ -39,6 +39,7 @@ import { reactive, ref, onMounted } from 'vue' import { ElMessage } from 'element-plus' import request from '../utils/request' +import { can } from '../utils/perm' import PageHelp from '../components/PageHelp.vue' import { helpPlc } from '../help' diff --git a/bj_power_mes/frontend/src/pages/ProcessFlow.vue b/bj_power_mes/frontend/src/pages/ProcessFlow.vue new file mode 100644 index 0000000..5946baf --- /dev/null +++ b/bj_power_mes/frontend/src/pages/ProcessFlow.vue @@ -0,0 +1,479 @@ + + + + + diff --git a/bj_power_mes/frontend/src/pages/ProcessStep.vue b/bj_power_mes/frontend/src/pages/ProcessStep.vue index a4f726b..916aac9 100644 --- a/bj_power_mes/frontend/src/pages/ProcessStep.vue +++ b/bj_power_mes/frontend/src/pages/ProcessStep.vue @@ -7,7 +7,7 @@ 加载 - 保存该工序参数 + 保存该工序参数
- 新增步骤 + 新增步骤
@@ -95,6 +95,7 @@ import { reactive, ref, onMounted } from 'vue' import { ElMessage } from 'element-plus' import request from '../utils/request' +import { can } from '../utils/perm' import PageHelp from '../components/PageHelp.vue' import { helpProcessStep } from '../help' diff --git a/bj_power_mes/frontend/src/pages/ProductType.vue b/bj_power_mes/frontend/src/pages/ProductType.vue index cb3926d..2c34a52 100644 --- a/bj_power_mes/frontend/src/pages/ProductType.vue +++ b/bj_power_mes/frontend/src/pages/ProductType.vue @@ -1,7 +1,7 @@