393 lines
11 KiB
Go
393 lines
11 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/eventlog"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// EventLogCreate is the builder for creating a EventLog entity.
|
|
type EventLogCreate struct {
|
|
config
|
|
mutation *EventLogMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetEventType sets the "eventType" field.
|
|
func (_c *EventLogCreate) SetEventType(v string) *EventLogCreate {
|
|
_c.mutation.SetEventType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetWorkOrderNo sets the "workOrderNo" field.
|
|
func (_c *EventLogCreate) SetWorkOrderNo(v string) *EventLogCreate {
|
|
_c.mutation.SetWorkOrderNo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableWorkOrderNo sets the "workOrderNo" field if the given value is not nil.
|
|
func (_c *EventLogCreate) SetNillableWorkOrderNo(v *string) *EventLogCreate {
|
|
if v != nil {
|
|
_c.SetWorkOrderNo(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_c *EventLogCreate) SetOperator(v string) *EventLogCreate {
|
|
_c.mutation.SetOperator(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_c *EventLogCreate) SetNillableOperator(v *string) *EventLogCreate {
|
|
if v != nil {
|
|
_c.SetOperator(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetEntityType sets the "entityType" field.
|
|
func (_c *EventLogCreate) SetEntityType(v string) *EventLogCreate {
|
|
_c.mutation.SetEntityType(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEntityType sets the "entityType" field if the given value is not nil.
|
|
func (_c *EventLogCreate) SetNillableEntityType(v *string) *EventLogCreate {
|
|
if v != nil {
|
|
_c.SetEntityType(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetEntityId sets the "entityId" field.
|
|
func (_c *EventLogCreate) SetEntityId(v string) *EventLogCreate {
|
|
_c.mutation.SetEntityId(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEntityId sets the "entityId" field if the given value is not nil.
|
|
func (_c *EventLogCreate) SetNillableEntityId(v *string) *EventLogCreate {
|
|
if v != nil {
|
|
_c.SetEntityId(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetDescription sets the "description" field.
|
|
func (_c *EventLogCreate) SetDescription(v string) *EventLogCreate {
|
|
_c.mutation.SetDescription(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
|
func (_c *EventLogCreate) SetNillableDescription(v *string) *EventLogCreate {
|
|
if v != nil {
|
|
_c.SetDescription(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetPayload sets the "payload" field.
|
|
func (_c *EventLogCreate) SetPayload(v map[string]interface{}) *EventLogCreate {
|
|
_c.mutation.SetPayload(v)
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "createdAt" field.
|
|
func (_c *EventLogCreate) SetCreatedAt(v time.Time) *EventLogCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
|
func (_c *EventLogCreate) SetNillableCreatedAt(v *time.Time) *EventLogCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *EventLogCreate) SetID(v int) *EventLogCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the EventLogMutation object of the builder.
|
|
func (_c *EventLogCreate) Mutation() *EventLogMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the EventLog in the database.
|
|
func (_c *EventLogCreate) Save(ctx context.Context) (*EventLog, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *EventLogCreate) SaveX(ctx context.Context) *EventLog {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *EventLogCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *EventLogCreate) 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 *EventLogCreate) defaults() {
|
|
if _, ok := _c.mutation.WorkOrderNo(); !ok {
|
|
v := eventlog.DefaultWorkOrderNo
|
|
_c.mutation.SetWorkOrderNo(v)
|
|
}
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
|
v := eventlog.DefaultOperator
|
|
_c.mutation.SetOperator(v)
|
|
}
|
|
if _, ok := _c.mutation.EntityType(); !ok {
|
|
v := eventlog.DefaultEntityType
|
|
_c.mutation.SetEntityType(v)
|
|
}
|
|
if _, ok := _c.mutation.EntityId(); !ok {
|
|
v := eventlog.DefaultEntityId
|
|
_c.mutation.SetEntityId(v)
|
|
}
|
|
if _, ok := _c.mutation.Description(); !ok {
|
|
v := eventlog.DefaultDescription
|
|
_c.mutation.SetDescription(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := eventlog.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *EventLogCreate) check() error {
|
|
if _, ok := _c.mutation.EventType(); !ok {
|
|
return &ValidationError{Name: "eventType", err: errors.New(`ent: missing required field "EventLog.eventType"`)}
|
|
}
|
|
if v, ok := _c.mutation.EventType(); ok {
|
|
if err := eventlog.EventTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "eventType", err: fmt.Errorf(`ent: validator failed for field "EventLog.eventType": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.WorkOrderNo(); !ok {
|
|
return &ValidationError{Name: "workOrderNo", err: errors.New(`ent: missing required field "EventLog.workOrderNo"`)}
|
|
}
|
|
if v, ok := _c.mutation.WorkOrderNo(); ok {
|
|
if err := eventlog.WorkOrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "workOrderNo", err: fmt.Errorf(`ent: validator failed for field "EventLog.workOrderNo": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
|
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "EventLog.operator"`)}
|
|
}
|
|
if v, ok := _c.mutation.Operator(); ok {
|
|
if err := eventlog.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "EventLog.operator": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.EntityType(); !ok {
|
|
return &ValidationError{Name: "entityType", err: errors.New(`ent: missing required field "EventLog.entityType"`)}
|
|
}
|
|
if v, ok := _c.mutation.EntityType(); ok {
|
|
if err := eventlog.EntityTypeValidator(v); err != nil {
|
|
return &ValidationError{Name: "entityType", err: fmt.Errorf(`ent: validator failed for field "EventLog.entityType": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.EntityId(); !ok {
|
|
return &ValidationError{Name: "entityId", err: errors.New(`ent: missing required field "EventLog.entityId"`)}
|
|
}
|
|
if v, ok := _c.mutation.EntityId(); ok {
|
|
if err := eventlog.EntityIdValidator(v); err != nil {
|
|
return &ValidationError{Name: "entityId", err: fmt.Errorf(`ent: validator failed for field "EventLog.entityId": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Description(); !ok {
|
|
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "EventLog.description"`)}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "EventLog.createdAt"`)}
|
|
}
|
|
if v, ok := _c.mutation.ID(); ok {
|
|
if err := eventlog.IDValidator(v); err != nil {
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "EventLog.id": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *EventLogCreate) sqlSave(ctx context.Context) (*EventLog, 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 *EventLogCreate) createSpec() (*EventLog, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &EventLog{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(eventlog.Table, sqlgraph.NewFieldSpec(eventlog.FieldID, field.TypeInt))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.EventType(); ok {
|
|
_spec.SetField(eventlog.FieldEventType, field.TypeString, value)
|
|
_node.EventType = value
|
|
}
|
|
if value, ok := _c.mutation.WorkOrderNo(); ok {
|
|
_spec.SetField(eventlog.FieldWorkOrderNo, field.TypeString, value)
|
|
_node.WorkOrderNo = value
|
|
}
|
|
if value, ok := _c.mutation.Operator(); ok {
|
|
_spec.SetField(eventlog.FieldOperator, field.TypeString, value)
|
|
_node.Operator = value
|
|
}
|
|
if value, ok := _c.mutation.EntityType(); ok {
|
|
_spec.SetField(eventlog.FieldEntityType, field.TypeString, value)
|
|
_node.EntityType = value
|
|
}
|
|
if value, ok := _c.mutation.EntityId(); ok {
|
|
_spec.SetField(eventlog.FieldEntityId, field.TypeString, value)
|
|
_node.EntityId = value
|
|
}
|
|
if value, ok := _c.mutation.Description(); ok {
|
|
_spec.SetField(eventlog.FieldDescription, field.TypeString, value)
|
|
_node.Description = value
|
|
}
|
|
if value, ok := _c.mutation.Payload(); ok {
|
|
_spec.SetField(eventlog.FieldPayload, field.TypeJSON, value)
|
|
_node.Payload = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(eventlog.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// EventLogCreateBulk is the builder for creating many EventLog entities in bulk.
|
|
type EventLogCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*EventLogCreate
|
|
}
|
|
|
|
// Save creates the EventLog entities in the database.
|
|
func (_c *EventLogCreateBulk) Save(ctx context.Context) ([]*EventLog, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*EventLog, 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.(*EventLogMutation)
|
|
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 *EventLogCreateBulk) SaveX(ctx context.Context) []*EventLog {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *EventLogCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *EventLogCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|