Files
bj_power/bj_power_mes/ent/syncfailure_create.go
SunYF 7e8066ab66 feat: 同步失败(SyncFailure)实体化与 ent 全量重生成
- 新增 SyncFailure 实体:MES/WMS 两端 schema 源 + ent 生成码(create/delete/query/update 及子包)
- ent 框架文件全量重生成:client/ent/hook/migrate/mutation/predicate/runtime/tx
- 清理旧代码生成入口:删除 schema/gen.go 与 schema/tools/generate.go
- 同步失败页面调整:MES/WMS SyncFailure.vue 接入新实体,MES 产品工艺页同步调整
- 主程序入口注册新实体:bj_power_mes.go / bj_power_wms.go,工作站 main.go 同步调整
- 更新文档:WMS README、案例、问题记录;刷新 MES/WMS 前端构建产物
2026-11-12 15:52:51 +08:00

482 lines
14 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/syncfailure"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// SyncFailureCreate is the builder for creating a SyncFailure entity.
type SyncFailureCreate struct {
config
mutation *SyncFailureMutation
hooks []Hook
}
// SetDirection sets the "direction" field.
func (_c *SyncFailureCreate) SetDirection(v string) *SyncFailureCreate {
_c.mutation.SetDirection(v)
return _c
}
// SetNillableDirection sets the "direction" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableDirection(v *string) *SyncFailureCreate {
if v != nil {
_c.SetDirection(*v)
}
return _c
}
// SetBizType sets the "biz_type" field.
func (_c *SyncFailureCreate) SetBizType(v string) *SyncFailureCreate {
_c.mutation.SetBizType(v)
return _c
}
// SetNillableBizType sets the "biz_type" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableBizType(v *string) *SyncFailureCreate {
if v != nil {
_c.SetBizType(*v)
}
return _c
}
// SetBizKey sets the "biz_key" field.
func (_c *SyncFailureCreate) SetBizKey(v string) *SyncFailureCreate {
_c.mutation.SetBizKey(v)
return _c
}
// SetNillableBizKey sets the "biz_key" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableBizKey(v *string) *SyncFailureCreate {
if v != nil {
_c.SetBizKey(*v)
}
return _c
}
// SetEndpoint sets the "endpoint" field.
func (_c *SyncFailureCreate) SetEndpoint(v string) *SyncFailureCreate {
_c.mutation.SetEndpoint(v)
return _c
}
// SetNillableEndpoint sets the "endpoint" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableEndpoint(v *string) *SyncFailureCreate {
if v != nil {
_c.SetEndpoint(*v)
}
return _c
}
// SetPayloadJSON sets the "payload_json" field.
func (_c *SyncFailureCreate) SetPayloadJSON(v string) *SyncFailureCreate {
_c.mutation.SetPayloadJSON(v)
return _c
}
// SetNillablePayloadJSON sets the "payload_json" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillablePayloadJSON(v *string) *SyncFailureCreate {
if v != nil {
_c.SetPayloadJSON(*v)
}
return _c
}
// SetErrorMsg sets the "error_msg" field.
func (_c *SyncFailureCreate) SetErrorMsg(v string) *SyncFailureCreate {
_c.mutation.SetErrorMsg(v)
return _c
}
// SetNillableErrorMsg sets the "error_msg" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableErrorMsg(v *string) *SyncFailureCreate {
if v != nil {
_c.SetErrorMsg(*v)
}
return _c
}
// SetIdempotencyKey sets the "idempotency_key" field.
func (_c *SyncFailureCreate) SetIdempotencyKey(v string) *SyncFailureCreate {
_c.mutation.SetIdempotencyKey(v)
return _c
}
// SetStatus sets the "status" field.
func (_c *SyncFailureCreate) SetStatus(v string) *SyncFailureCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableStatus(v *string) *SyncFailureCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetRetryCount sets the "retry_count" field.
func (_c *SyncFailureCreate) SetRetryCount(v int32) *SyncFailureCreate {
_c.mutation.SetRetryCount(v)
return _c
}
// SetNillableRetryCount sets the "retry_count" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableRetryCount(v *int32) *SyncFailureCreate {
if v != nil {
_c.SetRetryCount(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *SyncFailureCreate) SetCreatedAt(v int64) *SyncFailureCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableCreatedAt(v *int64) *SyncFailureCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetLastErrorAt sets the "last_error_at" field.
func (_c *SyncFailureCreate) SetLastErrorAt(v int64) *SyncFailureCreate {
_c.mutation.SetLastErrorAt(v)
return _c
}
// SetNillableLastErrorAt sets the "last_error_at" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableLastErrorAt(v *int64) *SyncFailureCreate {
if v != nil {
_c.SetLastErrorAt(*v)
}
return _c
}
// SetHandledBy sets the "handled_by" field.
func (_c *SyncFailureCreate) SetHandledBy(v string) *SyncFailureCreate {
_c.mutation.SetHandledBy(v)
return _c
}
// SetNillableHandledBy sets the "handled_by" field if the given value is not nil.
func (_c *SyncFailureCreate) SetNillableHandledBy(v *string) *SyncFailureCreate {
if v != nil {
_c.SetHandledBy(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *SyncFailureCreate) SetID(v int) *SyncFailureCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the SyncFailureMutation object of the builder.
func (_c *SyncFailureCreate) Mutation() *SyncFailureMutation {
return _c.mutation
}
// Save creates the SyncFailure in the database.
func (_c *SyncFailureCreate) Save(ctx context.Context) (*SyncFailure, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *SyncFailureCreate) SaveX(ctx context.Context) *SyncFailure {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SyncFailureCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SyncFailureCreate) 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 *SyncFailureCreate) defaults() {
if _, ok := _c.mutation.Direction(); !ok {
v := syncfailure.DefaultDirection
_c.mutation.SetDirection(v)
}
if _, ok := _c.mutation.BizType(); !ok {
v := syncfailure.DefaultBizType
_c.mutation.SetBizType(v)
}
if _, ok := _c.mutation.BizKey(); !ok {
v := syncfailure.DefaultBizKey
_c.mutation.SetBizKey(v)
}
if _, ok := _c.mutation.Endpoint(); !ok {
v := syncfailure.DefaultEndpoint
_c.mutation.SetEndpoint(v)
}
if _, ok := _c.mutation.PayloadJSON(); !ok {
v := syncfailure.DefaultPayloadJSON
_c.mutation.SetPayloadJSON(v)
}
if _, ok := _c.mutation.ErrorMsg(); !ok {
v := syncfailure.DefaultErrorMsg
_c.mutation.SetErrorMsg(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := syncfailure.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.RetryCount(); !ok {
v := syncfailure.DefaultRetryCount
_c.mutation.SetRetryCount(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := syncfailure.DefaultCreatedAt
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.LastErrorAt(); !ok {
v := syncfailure.DefaultLastErrorAt
_c.mutation.SetLastErrorAt(v)
}
if _, ok := _c.mutation.HandledBy(); !ok {
v := syncfailure.DefaultHandledBy
_c.mutation.SetHandledBy(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *SyncFailureCreate) check() error {
if _, ok := _c.mutation.Direction(); !ok {
return &ValidationError{Name: "direction", err: errors.New(`ent: missing required field "SyncFailure.direction"`)}
}
if _, ok := _c.mutation.BizType(); !ok {
return &ValidationError{Name: "biz_type", err: errors.New(`ent: missing required field "SyncFailure.biz_type"`)}
}
if _, ok := _c.mutation.BizKey(); !ok {
return &ValidationError{Name: "biz_key", err: errors.New(`ent: missing required field "SyncFailure.biz_key"`)}
}
if _, ok := _c.mutation.Endpoint(); !ok {
return &ValidationError{Name: "endpoint", err: errors.New(`ent: missing required field "SyncFailure.endpoint"`)}
}
if _, ok := _c.mutation.PayloadJSON(); !ok {
return &ValidationError{Name: "payload_json", err: errors.New(`ent: missing required field "SyncFailure.payload_json"`)}
}
if _, ok := _c.mutation.ErrorMsg(); !ok {
return &ValidationError{Name: "error_msg", err: errors.New(`ent: missing required field "SyncFailure.error_msg"`)}
}
if _, ok := _c.mutation.IdempotencyKey(); !ok {
return &ValidationError{Name: "idempotency_key", err: errors.New(`ent: missing required field "SyncFailure.idempotency_key"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "SyncFailure.status"`)}
}
if _, ok := _c.mutation.RetryCount(); !ok {
return &ValidationError{Name: "retry_count", err: errors.New(`ent: missing required field "SyncFailure.retry_count"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "SyncFailure.created_at"`)}
}
if _, ok := _c.mutation.LastErrorAt(); !ok {
return &ValidationError{Name: "last_error_at", err: errors.New(`ent: missing required field "SyncFailure.last_error_at"`)}
}
if _, ok := _c.mutation.HandledBy(); !ok {
return &ValidationError{Name: "handled_by", err: errors.New(`ent: missing required field "SyncFailure.handled_by"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := syncfailure.IDValidator(v); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "SyncFailure.id": %w`, err)}
}
}
return nil
}
func (_c *SyncFailureCreate) sqlSave(ctx context.Context) (*SyncFailure, 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 *SyncFailureCreate) createSpec() (*SyncFailure, *sqlgraph.CreateSpec) {
var (
_node = &SyncFailure{config: _c.config}
_spec = sqlgraph.NewCreateSpec(syncfailure.Table, sqlgraph.NewFieldSpec(syncfailure.FieldID, field.TypeInt))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.Direction(); ok {
_spec.SetField(syncfailure.FieldDirection, field.TypeString, value)
_node.Direction = value
}
if value, ok := _c.mutation.BizType(); ok {
_spec.SetField(syncfailure.FieldBizType, field.TypeString, value)
_node.BizType = value
}
if value, ok := _c.mutation.BizKey(); ok {
_spec.SetField(syncfailure.FieldBizKey, field.TypeString, value)
_node.BizKey = value
}
if value, ok := _c.mutation.Endpoint(); ok {
_spec.SetField(syncfailure.FieldEndpoint, field.TypeString, value)
_node.Endpoint = value
}
if value, ok := _c.mutation.PayloadJSON(); ok {
_spec.SetField(syncfailure.FieldPayloadJSON, field.TypeString, value)
_node.PayloadJSON = value
}
if value, ok := _c.mutation.ErrorMsg(); ok {
_spec.SetField(syncfailure.FieldErrorMsg, field.TypeString, value)
_node.ErrorMsg = value
}
if value, ok := _c.mutation.IdempotencyKey(); ok {
_spec.SetField(syncfailure.FieldIdempotencyKey, field.TypeString, value)
_node.IdempotencyKey = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(syncfailure.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.RetryCount(); ok {
_spec.SetField(syncfailure.FieldRetryCount, field.TypeInt32, value)
_node.RetryCount = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(syncfailure.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.LastErrorAt(); ok {
_spec.SetField(syncfailure.FieldLastErrorAt, field.TypeInt64, value)
_node.LastErrorAt = value
}
if value, ok := _c.mutation.HandledBy(); ok {
_spec.SetField(syncfailure.FieldHandledBy, field.TypeString, value)
_node.HandledBy = value
}
return _node, _spec
}
// SyncFailureCreateBulk is the builder for creating many SyncFailure entities in bulk.
type SyncFailureCreateBulk struct {
config
err error
builders []*SyncFailureCreate
}
// Save creates the SyncFailure entities in the database.
func (_c *SyncFailureCreateBulk) Save(ctx context.Context) ([]*SyncFailure, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*SyncFailure, 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.(*SyncFailureMutation)
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 *SyncFailureCreateBulk) SaveX(ctx context.Context) []*SyncFailure {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *SyncFailureCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *SyncFailureCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}