497 lines
16 KiB
Go
497 lines
16 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_mes/ent/workpieceprocess"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// WorkpieceProcessCreate is the builder for creating a WorkpieceProcess entity.
|
|
type WorkpieceProcessCreate struct {
|
|
config
|
|
mutation *WorkpieceProcessMutation
|
|
hooks []Hook
|
|
}
|
|
|
|
// SetSn sets the "sn" field.
|
|
func (_c *WorkpieceProcessCreate) SetSn(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetSn(v)
|
|
return _c
|
|
}
|
|
|
|
// SetProcessCode sets the "processCode" field.
|
|
func (_c *WorkpieceProcessCreate) SetProcessCode(v int) *WorkpieceProcessCreate {
|
|
_c.mutation.SetProcessCode(v)
|
|
return _c
|
|
}
|
|
|
|
// SetStationNo sets the "stationNo" field.
|
|
func (_c *WorkpieceProcessCreate) SetStationNo(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetStationNo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableStationNo(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetStationNo(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetOrderNo sets the "orderNo" field.
|
|
func (_c *WorkpieceProcessCreate) SetOrderNo(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetOrderNo(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOrderNo sets the "orderNo" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableOrderNo(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetOrderNo(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetProcessName sets the "processName" field.
|
|
func (_c *WorkpieceProcessCreate) SetProcessName(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetProcessName(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableProcessName sets the "processName" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableProcessName(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetProcessName(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_c *WorkpieceProcessCreate) SetStatus(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetStatus(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableStatus(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetStatus(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetOperator sets the "operator" field.
|
|
func (_c *WorkpieceProcessCreate) SetOperator(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetOperator(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableOperator sets the "operator" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableOperator(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetOperator(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetResult sets the "result" field.
|
|
func (_c *WorkpieceProcessCreate) SetResult(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetResult(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableResult sets the "result" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableResult(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetResult(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetStartedAt sets the "startedAt" field.
|
|
func (_c *WorkpieceProcessCreate) SetStartedAt(v time.Time) *WorkpieceProcessCreate {
|
|
_c.mutation.SetStartedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableStartedAt sets the "startedAt" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableStartedAt(v *time.Time) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetStartedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetEndedAt sets the "endedAt" field.
|
|
func (_c *WorkpieceProcessCreate) SetEndedAt(v time.Time) *WorkpieceProcessCreate {
|
|
_c.mutation.SetEndedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableEndedAt sets the "endedAt" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableEndedAt(v *time.Time) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetEndedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetRemark sets the "remark" field.
|
|
func (_c *WorkpieceProcessCreate) SetRemark(v string) *WorkpieceProcessCreate {
|
|
_c.mutation.SetRemark(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableRemark(v *string) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetRemark(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetCreatedAt sets the "createdAt" field.
|
|
func (_c *WorkpieceProcessCreate) SetCreatedAt(v time.Time) *WorkpieceProcessCreate {
|
|
_c.mutation.SetCreatedAt(v)
|
|
return _c
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
|
func (_c *WorkpieceProcessCreate) SetNillableCreatedAt(v *time.Time) *WorkpieceProcessCreate {
|
|
if v != nil {
|
|
_c.SetCreatedAt(*v)
|
|
}
|
|
return _c
|
|
}
|
|
|
|
// SetID sets the "id" field.
|
|
func (_c *WorkpieceProcessCreate) SetID(v int) *WorkpieceProcessCreate {
|
|
_c.mutation.SetID(v)
|
|
return _c
|
|
}
|
|
|
|
// Mutation returns the WorkpieceProcessMutation object of the builder.
|
|
func (_c *WorkpieceProcessCreate) Mutation() *WorkpieceProcessMutation {
|
|
return _c.mutation
|
|
}
|
|
|
|
// Save creates the WorkpieceProcess in the database.
|
|
func (_c *WorkpieceProcessCreate) Save(ctx context.Context) (*WorkpieceProcess, error) {
|
|
_c.defaults()
|
|
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
|
}
|
|
|
|
// SaveX calls Save and panics if Save returns an error.
|
|
func (_c *WorkpieceProcessCreate) SaveX(ctx context.Context) *WorkpieceProcess {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *WorkpieceProcessCreate) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *WorkpieceProcessCreate) 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 *WorkpieceProcessCreate) defaults() {
|
|
if _, ok := _c.mutation.StationNo(); !ok {
|
|
v := workpieceprocess.DefaultStationNo
|
|
_c.mutation.SetStationNo(v)
|
|
}
|
|
if _, ok := _c.mutation.OrderNo(); !ok {
|
|
v := workpieceprocess.DefaultOrderNo
|
|
_c.mutation.SetOrderNo(v)
|
|
}
|
|
if _, ok := _c.mutation.ProcessName(); !ok {
|
|
v := workpieceprocess.DefaultProcessName
|
|
_c.mutation.SetProcessName(v)
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
v := workpieceprocess.DefaultStatus
|
|
_c.mutation.SetStatus(v)
|
|
}
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
|
v := workpieceprocess.DefaultOperator
|
|
_c.mutation.SetOperator(v)
|
|
}
|
|
if _, ok := _c.mutation.Result(); !ok {
|
|
v := workpieceprocess.DefaultResult
|
|
_c.mutation.SetResult(v)
|
|
}
|
|
if _, ok := _c.mutation.Remark(); !ok {
|
|
v := workpieceprocess.DefaultRemark
|
|
_c.mutation.SetRemark(v)
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
v := workpieceprocess.DefaultCreatedAt()
|
|
_c.mutation.SetCreatedAt(v)
|
|
}
|
|
}
|
|
|
|
// check runs all checks and user-defined validators on the builder.
|
|
func (_c *WorkpieceProcessCreate) check() error {
|
|
if _, ok := _c.mutation.Sn(); !ok {
|
|
return &ValidationError{Name: "sn", err: errors.New(`ent: missing required field "WorkpieceProcess.sn"`)}
|
|
}
|
|
if v, ok := _c.mutation.Sn(); ok {
|
|
if err := workpieceprocess.SnValidator(v); err != nil {
|
|
return &ValidationError{Name: "sn", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.sn": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.ProcessCode(); !ok {
|
|
return &ValidationError{Name: "processCode", err: errors.New(`ent: missing required field "WorkpieceProcess.processCode"`)}
|
|
}
|
|
if _, ok := _c.mutation.StationNo(); !ok {
|
|
return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "WorkpieceProcess.stationNo"`)}
|
|
}
|
|
if v, ok := _c.mutation.StationNo(); ok {
|
|
if err := workpieceprocess.StationNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "stationNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.stationNo": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.OrderNo(); !ok {
|
|
return &ValidationError{Name: "orderNo", err: errors.New(`ent: missing required field "WorkpieceProcess.orderNo"`)}
|
|
}
|
|
if v, ok := _c.mutation.OrderNo(); ok {
|
|
if err := workpieceprocess.OrderNoValidator(v); err != nil {
|
|
return &ValidationError{Name: "orderNo", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.orderNo": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.ProcessName(); !ok {
|
|
return &ValidationError{Name: "processName", err: errors.New(`ent: missing required field "WorkpieceProcess.processName"`)}
|
|
}
|
|
if v, ok := _c.mutation.ProcessName(); ok {
|
|
if err := workpieceprocess.ProcessNameValidator(v); err != nil {
|
|
return &ValidationError{Name: "processName", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.processName": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Status(); !ok {
|
|
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "WorkpieceProcess.status"`)}
|
|
}
|
|
if v, ok := _c.mutation.Status(); ok {
|
|
if err := workpieceprocess.StatusValidator(v); err != nil {
|
|
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.status": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Operator(); !ok {
|
|
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "WorkpieceProcess.operator"`)}
|
|
}
|
|
if v, ok := _c.mutation.Operator(); ok {
|
|
if err := workpieceprocess.OperatorValidator(v); err != nil {
|
|
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.operator": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Result(); !ok {
|
|
return &ValidationError{Name: "result", err: errors.New(`ent: missing required field "WorkpieceProcess.result"`)}
|
|
}
|
|
if v, ok := _c.mutation.Result(); ok {
|
|
if err := workpieceprocess.ResultValidator(v); err != nil {
|
|
return &ValidationError{Name: "result", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.result": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.Remark(); !ok {
|
|
return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "WorkpieceProcess.remark"`)}
|
|
}
|
|
if v, ok := _c.mutation.Remark(); ok {
|
|
if err := workpieceprocess.RemarkValidator(v); err != nil {
|
|
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.remark": %w`, err)}
|
|
}
|
|
}
|
|
if _, ok := _c.mutation.CreatedAt(); !ok {
|
|
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "WorkpieceProcess.createdAt"`)}
|
|
}
|
|
if v, ok := _c.mutation.ID(); ok {
|
|
if err := workpieceprocess.IDValidator(v); err != nil {
|
|
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "WorkpieceProcess.id": %w`, err)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_c *WorkpieceProcessCreate) sqlSave(ctx context.Context) (*WorkpieceProcess, 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 *WorkpieceProcessCreate) createSpec() (*WorkpieceProcess, *sqlgraph.CreateSpec) {
|
|
var (
|
|
_node = &WorkpieceProcess{config: _c.config}
|
|
_spec = sqlgraph.NewCreateSpec(workpieceprocess.Table, sqlgraph.NewFieldSpec(workpieceprocess.FieldID, field.TypeInt))
|
|
)
|
|
if id, ok := _c.mutation.ID(); ok {
|
|
_node.ID = id
|
|
_spec.ID.Value = id
|
|
}
|
|
if value, ok := _c.mutation.Sn(); ok {
|
|
_spec.SetField(workpieceprocess.FieldSn, field.TypeString, value)
|
|
_node.Sn = value
|
|
}
|
|
if value, ok := _c.mutation.ProcessCode(); ok {
|
|
_spec.SetField(workpieceprocess.FieldProcessCode, field.TypeInt, value)
|
|
_node.ProcessCode = value
|
|
}
|
|
if value, ok := _c.mutation.StationNo(); ok {
|
|
_spec.SetField(workpieceprocess.FieldStationNo, field.TypeString, value)
|
|
_node.StationNo = value
|
|
}
|
|
if value, ok := _c.mutation.OrderNo(); ok {
|
|
_spec.SetField(workpieceprocess.FieldOrderNo, field.TypeString, value)
|
|
_node.OrderNo = value
|
|
}
|
|
if value, ok := _c.mutation.ProcessName(); ok {
|
|
_spec.SetField(workpieceprocess.FieldProcessName, field.TypeString, value)
|
|
_node.ProcessName = value
|
|
}
|
|
if value, ok := _c.mutation.Status(); ok {
|
|
_spec.SetField(workpieceprocess.FieldStatus, field.TypeString, value)
|
|
_node.Status = value
|
|
}
|
|
if value, ok := _c.mutation.Operator(); ok {
|
|
_spec.SetField(workpieceprocess.FieldOperator, field.TypeString, value)
|
|
_node.Operator = value
|
|
}
|
|
if value, ok := _c.mutation.Result(); ok {
|
|
_spec.SetField(workpieceprocess.FieldResult, field.TypeString, value)
|
|
_node.Result = value
|
|
}
|
|
if value, ok := _c.mutation.StartedAt(); ok {
|
|
_spec.SetField(workpieceprocess.FieldStartedAt, field.TypeTime, value)
|
|
_node.StartedAt = &value
|
|
}
|
|
if value, ok := _c.mutation.EndedAt(); ok {
|
|
_spec.SetField(workpieceprocess.FieldEndedAt, field.TypeTime, value)
|
|
_node.EndedAt = &value
|
|
}
|
|
if value, ok := _c.mutation.Remark(); ok {
|
|
_spec.SetField(workpieceprocess.FieldRemark, field.TypeString, value)
|
|
_node.Remark = value
|
|
}
|
|
if value, ok := _c.mutation.CreatedAt(); ok {
|
|
_spec.SetField(workpieceprocess.FieldCreatedAt, field.TypeTime, value)
|
|
_node.CreatedAt = value
|
|
}
|
|
return _node, _spec
|
|
}
|
|
|
|
// WorkpieceProcessCreateBulk is the builder for creating many WorkpieceProcess entities in bulk.
|
|
type WorkpieceProcessCreateBulk struct {
|
|
config
|
|
err error
|
|
builders []*WorkpieceProcessCreate
|
|
}
|
|
|
|
// Save creates the WorkpieceProcess entities in the database.
|
|
func (_c *WorkpieceProcessCreateBulk) Save(ctx context.Context) ([]*WorkpieceProcess, error) {
|
|
if _c.err != nil {
|
|
return nil, _c.err
|
|
}
|
|
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
|
nodes := make([]*WorkpieceProcess, 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.(*WorkpieceProcessMutation)
|
|
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 *WorkpieceProcessCreateBulk) SaveX(ctx context.Context) []*WorkpieceProcess {
|
|
v, err := _c.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return v
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_c *WorkpieceProcessCreateBulk) Exec(ctx context.Context) error {
|
|
_, err := _c.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_c *WorkpieceProcessCreateBulk) ExecX(ctx context.Context) {
|
|
if err := _c.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|