Files
bj_power/bj_power_mes/ent/tx.go
T
SunYF 1e92b2a596 feat: 核心业务实体扩充(混产模板/产品BOM/试制记录)、WMS 库存检验增强与前端通用能力
- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页)
- WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报
- AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典
- 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列
- 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等)
- 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
2026-11-15 12:17:39 +08:00

352 lines
14 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"sync"
"entgo.io/ent/dialect"
)
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// AgvPoint is the client for interacting with the AgvPoint builders.
AgvPoint *AgvPointClient
// AgvTask is the client for interacting with the AgvTask builders.
AgvTask *AgvTaskClient
// AgvVehicleState is the client for interacting with the AgvVehicleState builders.
AgvVehicleState *AgvVehicleStateClient
// Alert is the client for interacting with the Alert builders.
Alert *AlertClient
// AlertRule is the client for interacting with the AlertRule builders.
AlertRule *AlertRuleClient
// AssociationTrace is the client for interacting with the AssociationTrace builders.
AssociationTrace *AssociationTraceClient
// Attachment is the client for interacting with the Attachment builders.
Attachment *AttachmentClient
// BackupRecord is the client for interacting with the BackupRecord builders.
BackupRecord *BackupRecordClient
// CallPool is the client for interacting with the CallPool builders.
CallPool *CallPoolClient
// DailyPlan is the client for interacting with the DailyPlan builders.
DailyPlan *DailyPlanClient
// Dock is the client for interacting with the Dock builders.
Dock *DockClient
// EventLog is the client for interacting with the EventLog builders.
EventLog *EventLogClient
// FlowMaterial is the client for interacting with the FlowMaterial builders.
FlowMaterial *FlowMaterialClient
// InspectionRecord is the client for interacting with the InspectionRecord builders.
InspectionRecord *InspectionRecordClient
// LinePoint is the client for interacting with the LinePoint builders.
LinePoint *LinePointClient
// LossLedger is the client for interacting with the LossLedger builders.
LossLedger *LossLedgerClient
// Material is the client for interacting with the Material builders.
Material *MaterialClient
// MaterialQtyReport is the client for interacting with the MaterialQtyReport builders.
MaterialQtyReport *MaterialQtyReportClient
// MaterialRequest is the client for interacting with the MaterialRequest builders.
MaterialRequest *MaterialRequestClient
// MixProductionTemplate is the client for interacting with the MixProductionTemplate builders.
MixProductionTemplate *MixProductionTemplateClient
// 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
// ProductBOM is the client for interacting with the ProductBOM builders.
ProductBOM *ProductBOMClient
// ProductProcess is the client for interacting with the ProductProcess builders.
ProductProcess *ProductProcessClient
// ProductProcessItem is the client for interacting with the ProductProcessItem builders.
ProductProcessItem *ProductProcessItemClient
// ProductProcessMaterial is the client for interacting with the ProductProcessMaterial builders.
ProductProcessMaterial *ProductProcessMaterialClient
// Role is the client for interacting with the Role builders.
Role *RoleClient
// SemiFlow is the client for interacting with the SemiFlow builders.
SemiFlow *SemiFlowClient
// ShortageRequest is the client for interacting with the ShortageRequest builders.
ShortageRequest *ShortageRequestClient
// Station is the client for interacting with the Station builders.
Station *StationClient
// StationShift is the client for interacting with the StationShift builders.
StationShift *StationShiftClient
// StationState is the client for interacting with the StationState builders.
StationState *StationStateClient
// StepCriterion is the client for interacting with the StepCriterion builders.
StepCriterion *StepCriterionClient
// StepData is the client for interacting with the StepData builders.
StepData *StepDataClient
// StepSignRecord is the client for interacting with the StepSignRecord builders.
StepSignRecord *StepSignRecordClient
// SyncFailure is the client for interacting with the SyncFailure builders.
SyncFailure *SyncFailureClient
// SysConfig is the client for interacting with the SysConfig builders.
SysConfig *SysConfigClient
// TorqueRecord is the client for interacting with the TorqueRecord builders.
TorqueRecord *TorqueRecordClient
// TrialRecord is the client for interacting with the TrialRecord builders.
TrialRecord *TrialRecordClient
// 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.
Workpiece *WorkpieceClient
// WorkpieceBind is the client for interacting with the WorkpieceBind builders.
WorkpieceBind *WorkpieceBindClient
// WorkpieceLifecycleLog is the client for interacting with the WorkpieceLifecycleLog builders.
WorkpieceLifecycleLog *WorkpieceLifecycleLogClient
// WorkpieceProcess is the client for interacting with the WorkpieceProcess builders.
WorkpieceProcess *WorkpieceProcessClient
// lazily loaded.
client *Client
clientOnce sync.Once
// ctx lives for the life of the transaction. It is
// the same context used by the underlying connection.
ctx context.Context
}
type (
// Committer is the interface that wraps the Commit method.
Committer interface {
Commit(context.Context, *Tx) error
}
// The CommitFunc type is an adapter to allow the use of ordinary
// function as a Committer. If f is a function with the appropriate
// signature, CommitFunc(f) is a Committer that calls f.
CommitFunc func(context.Context, *Tx) error
// CommitHook defines the "commit middleware". A function that gets a Committer
// and returns a Committer. For example:
//
// hook := func(next ent.Committer) ent.Committer {
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Commit(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
CommitHook func(Committer) Committer
)
// Commit calls f(ctx, m).
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Commit commits the transaction.
func (tx *Tx) Commit() error {
txDriver := tx.config.driver.(*txDriver)
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
return txDriver.tx.Commit()
})
txDriver.mu.Lock()
hooks := append([]CommitHook(nil), txDriver.onCommit...)
txDriver.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Commit(tx.ctx, tx)
}
// OnCommit adds a hook to call on commit.
func (tx *Tx) OnCommit(f CommitHook) {
txDriver := tx.config.driver.(*txDriver)
txDriver.mu.Lock()
txDriver.onCommit = append(txDriver.onCommit, f)
txDriver.mu.Unlock()
}
type (
// Rollbacker is the interface that wraps the Rollback method.
Rollbacker interface {
Rollback(context.Context, *Tx) error
}
// The RollbackFunc type is an adapter to allow the use of ordinary
// function as a Rollbacker. If f is a function with the appropriate
// signature, RollbackFunc(f) is a Rollbacker that calls f.
RollbackFunc func(context.Context, *Tx) error
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
// and returns a Rollbacker. For example:
//
// hook := func(next ent.Rollbacker) ent.Rollbacker {
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Rollback(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
RollbackHook func(Rollbacker) Rollbacker
)
// Rollback calls f(ctx, m).
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Rollback rollbacks the transaction.
func (tx *Tx) Rollback() error {
txDriver := tx.config.driver.(*txDriver)
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
return txDriver.tx.Rollback()
})
txDriver.mu.Lock()
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
txDriver.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Rollback(tx.ctx, tx)
}
// OnRollback adds a hook to call on rollback.
func (tx *Tx) OnRollback(f RollbackHook) {
txDriver := tx.config.driver.(*txDriver)
txDriver.mu.Lock()
txDriver.onRollback = append(txDriver.onRollback, f)
txDriver.mu.Unlock()
}
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {
tx.AgvPoint = NewAgvPointClient(tx.config)
tx.AgvTask = NewAgvTaskClient(tx.config)
tx.AgvVehicleState = NewAgvVehicleStateClient(tx.config)
tx.Alert = NewAlertClient(tx.config)
tx.AlertRule = NewAlertRuleClient(tx.config)
tx.AssociationTrace = NewAssociationTraceClient(tx.config)
tx.Attachment = NewAttachmentClient(tx.config)
tx.BackupRecord = NewBackupRecordClient(tx.config)
tx.CallPool = NewCallPoolClient(tx.config)
tx.DailyPlan = NewDailyPlanClient(tx.config)
tx.Dock = NewDockClient(tx.config)
tx.EventLog = NewEventLogClient(tx.config)
tx.FlowMaterial = NewFlowMaterialClient(tx.config)
tx.InspectionRecord = NewInspectionRecordClient(tx.config)
tx.LinePoint = NewLinePointClient(tx.config)
tx.LossLedger = NewLossLedgerClient(tx.config)
tx.Material = NewMaterialClient(tx.config)
tx.MaterialQtyReport = NewMaterialQtyReportClient(tx.config)
tx.MaterialRequest = NewMaterialRequestClient(tx.config)
tx.MixProductionTemplate = NewMixProductionTemplateClient(tx.config)
tx.Permission = NewPermissionClient(tx.config)
tx.PlcSendLog = NewPlcSendLogClient(tx.config)
tx.ProcessFlow = NewProcessFlowClient(tx.config)
tx.ProcessStep = NewProcessStepClient(tx.config)
tx.ProductBOM = NewProductBOMClient(tx.config)
tx.ProductProcess = NewProductProcessClient(tx.config)
tx.ProductProcessItem = NewProductProcessItemClient(tx.config)
tx.ProductProcessMaterial = NewProductProcessMaterialClient(tx.config)
tx.Role = NewRoleClient(tx.config)
tx.SemiFlow = NewSemiFlowClient(tx.config)
tx.ShortageRequest = NewShortageRequestClient(tx.config)
tx.Station = NewStationClient(tx.config)
tx.StationShift = NewStationShiftClient(tx.config)
tx.StationState = NewStationStateClient(tx.config)
tx.StepCriterion = NewStepCriterionClient(tx.config)
tx.StepData = NewStepDataClient(tx.config)
tx.StepSignRecord = NewStepSignRecordClient(tx.config)
tx.SyncFailure = NewSyncFailureClient(tx.config)
tx.SysConfig = NewSysConfigClient(tx.config)
tx.TorqueRecord = NewTorqueRecordClient(tx.config)
tx.TrialRecord = NewTrialRecordClient(tx.config)
tx.User = NewUserClient(tx.config)
tx.UserStation = NewUserStationClient(tx.config)
tx.WorkOrder = NewWorkOrderClient(tx.config)
tx.Workpiece = NewWorkpieceClient(tx.config)
tx.WorkpieceBind = NewWorkpieceBindClient(tx.config)
tx.WorkpieceLifecycleLog = NewWorkpieceLifecycleLogClient(tx.config)
tx.WorkpieceProcess = NewWorkpieceProcessClient(tx.config)
}
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
// The idea is to support transactions without adding any extra code to the builders.
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
// Commit and Rollback are nop for the internal builders and the user must call one
// of them in order to commit or rollback the transaction.
//
// If a closed transaction is embedded in one of the generated entities, and the entity
// applies a query, for example: AgvPoint.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.
type txDriver struct {
// the driver we started the transaction from.
drv dialect.Driver
// tx is the underlying transaction.
tx dialect.Tx
// completion hooks.
mu sync.Mutex
onCommit []CommitHook
onRollback []RollbackHook
}
// newTx creates a new transactional driver.
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
tx, err := drv.Tx(ctx)
if err != nil {
return nil, err
}
return &txDriver{tx: tx, drv: drv}, nil
}
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
// from the internal builders. Should be called only by the internal builders.
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
// Dialect returns the dialect of the driver we started the transaction from.
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
// Close is a nop close.
func (*txDriver) Close() error { return nil }
// Commit is a nop commit for the internal builders.
// User must call `Tx.Commit` in order to commit the transaction.
func (*txDriver) Commit() error { return nil }
// Rollback is a nop rollback for the internal builders.
// User must call `Tx.Rollback` in order to rollback the transaction.
func (*txDriver) Rollback() error { return nil }
// Exec calls tx.Exec.
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
return tx.tx.Exec(ctx, query, args, v)
}
// Query calls tx.Query.
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
return tx.tx.Query(ctx, query, args, v)
}
var _ dialect.Driver = (*txDriver)(nil)