Files
bj_power/bj_power_wms/ent/zone_create.go
T
SunYF a2afd2f6dc feat: 五项目业务实现并对接完成
- MES(B): 工单/BOM/备料/工序字典/PLC下发/拧紧/扫码报工/半成品/AGV/追溯逻辑,WMS与海康RCS客户端,看板Redis缓存API(概览/设备/进度/报警/趋势)+SSE
- WMS(C): JWT滑动续签、Excel导入、盘点、内部API、种子数据、独立Postgres配置
- WMS客户端(E): Go网关8891反向代理+内嵌Vue3十页
- 工位终端(D): SQLite本地缓存+模拟拧紧源+内嵌Vue3页面
- Dashboard(A): 看板数据改接MES内部缓存API,SSE实时刷新+vite代理
- 清理各项目球形磨遗留代码,新增部署手册.md
2026-08-27 19:50:57 +08:00

677 lines
18 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/zone"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ZoneCreate is the builder for creating a Zone entity.
type ZoneCreate struct {
config
mutation *ZoneMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetZoneCode sets the "zone_code" field.
func (_c *ZoneCreate) SetZoneCode(v string) *ZoneCreate {
_c.mutation.SetZoneCode(v)
return _c
}
// SetZoneName sets the "zone_name" field.
func (_c *ZoneCreate) SetZoneName(v string) *ZoneCreate {
_c.mutation.SetZoneName(v)
return _c
}
// SetDescription sets the "description" field.
func (_c *ZoneCreate) SetDescription(v string) *ZoneCreate {
_c.mutation.SetDescription(v)
return _c
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_c *ZoneCreate) SetNillableDescription(v *string) *ZoneCreate {
if v != nil {
_c.SetDescription(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *ZoneCreate) SetCreatedAt(v int64) *ZoneCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ZoneCreate) SetNillableCreatedAt(v *int64) *ZoneCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// Mutation returns the ZoneMutation object of the builder.
func (_c *ZoneCreate) Mutation() *ZoneMutation {
return _c.mutation
}
// Save creates the Zone in the database.
func (_c *ZoneCreate) Save(ctx context.Context) (*Zone, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ZoneCreate) SaveX(ctx context.Context) *Zone {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ZoneCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ZoneCreate) 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 *ZoneCreate) defaults() {
if _, ok := _c.mutation.CreatedAt(); !ok {
v := zone.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ZoneCreate) check() error {
if _, ok := _c.mutation.ZoneCode(); !ok {
return &ValidationError{Name: "zone_code", err: errors.New(`ent: missing required field "Zone.zone_code"`)}
}
if _, ok := _c.mutation.ZoneName(); !ok {
return &ValidationError{Name: "zone_name", err: errors.New(`ent: missing required field "Zone.zone_name"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Zone.created_at"`)}
}
return nil
}
func (_c *ZoneCreate) sqlSave(ctx context.Context) (*Zone, 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
}
id := _spec.ID.Value.(int64)
_node.ID = int(id)
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *ZoneCreate) createSpec() (*Zone, *sqlgraph.CreateSpec) {
var (
_node = &Zone{config: _c.config}
_spec = sqlgraph.NewCreateSpec(zone.Table, sqlgraph.NewFieldSpec(zone.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.ZoneCode(); ok {
_spec.SetField(zone.FieldZoneCode, field.TypeString, value)
_node.ZoneCode = value
}
if value, ok := _c.mutation.ZoneName(); ok {
_spec.SetField(zone.FieldZoneName, field.TypeString, value)
_node.ZoneName = value
}
if value, ok := _c.mutation.Description(); ok {
_spec.SetField(zone.FieldDescription, field.TypeString, value)
_node.Description = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(zone.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Zone.Create().
// SetZoneCode(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.ZoneUpsert) {
// SetZoneCode(v+v).
// }).
// Exec(ctx)
func (_c *ZoneCreate) OnConflict(opts ...sql.ConflictOption) *ZoneUpsertOne {
_c.conflict = opts
return &ZoneUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Zone.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *ZoneCreate) OnConflictColumns(columns ...string) *ZoneUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &ZoneUpsertOne{
create: _c,
}
}
type (
// ZoneUpsertOne is the builder for "upsert"-ing
// one Zone node.
ZoneUpsertOne struct {
create *ZoneCreate
}
// ZoneUpsert is the "OnConflict" setter.
ZoneUpsert struct {
*sql.UpdateSet
}
)
// SetZoneCode sets the "zone_code" field.
func (u *ZoneUpsert) SetZoneCode(v string) *ZoneUpsert {
u.Set(zone.FieldZoneCode, v)
return u
}
// UpdateZoneCode sets the "zone_code" field to the value that was provided on create.
func (u *ZoneUpsert) UpdateZoneCode() *ZoneUpsert {
u.SetExcluded(zone.FieldZoneCode)
return u
}
// SetZoneName sets the "zone_name" field.
func (u *ZoneUpsert) SetZoneName(v string) *ZoneUpsert {
u.Set(zone.FieldZoneName, v)
return u
}
// UpdateZoneName sets the "zone_name" field to the value that was provided on create.
func (u *ZoneUpsert) UpdateZoneName() *ZoneUpsert {
u.SetExcluded(zone.FieldZoneName)
return u
}
// SetDescription sets the "description" field.
func (u *ZoneUpsert) SetDescription(v string) *ZoneUpsert {
u.Set(zone.FieldDescription, v)
return u
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *ZoneUpsert) UpdateDescription() *ZoneUpsert {
u.SetExcluded(zone.FieldDescription)
return u
}
// ClearDescription clears the value of the "description" field.
func (u *ZoneUpsert) ClearDescription() *ZoneUpsert {
u.SetNull(zone.FieldDescription)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *ZoneUpsert) SetCreatedAt(v int64) *ZoneUpsert {
u.Set(zone.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *ZoneUpsert) UpdateCreatedAt() *ZoneUpsert {
u.SetExcluded(zone.FieldCreatedAt)
return u
}
// AddCreatedAt adds v to the "created_at" field.
func (u *ZoneUpsert) AddCreatedAt(v int64) *ZoneUpsert {
u.Add(zone.FieldCreatedAt, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.Zone.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *ZoneUpsertOne) UpdateNewValues() *ZoneUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Zone.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *ZoneUpsertOne) Ignore() *ZoneUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *ZoneUpsertOne) DoNothing() *ZoneUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the ZoneCreate.OnConflict
// documentation for more info.
func (u *ZoneUpsertOne) Update(set func(*ZoneUpsert)) *ZoneUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&ZoneUpsert{UpdateSet: update})
}))
return u
}
// SetZoneCode sets the "zone_code" field.
func (u *ZoneUpsertOne) SetZoneCode(v string) *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.SetZoneCode(v)
})
}
// UpdateZoneCode sets the "zone_code" field to the value that was provided on create.
func (u *ZoneUpsertOne) UpdateZoneCode() *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.UpdateZoneCode()
})
}
// SetZoneName sets the "zone_name" field.
func (u *ZoneUpsertOne) SetZoneName(v string) *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.SetZoneName(v)
})
}
// UpdateZoneName sets the "zone_name" field to the value that was provided on create.
func (u *ZoneUpsertOne) UpdateZoneName() *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.UpdateZoneName()
})
}
// SetDescription sets the "description" field.
func (u *ZoneUpsertOne) SetDescription(v string) *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.SetDescription(v)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *ZoneUpsertOne) UpdateDescription() *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.UpdateDescription()
})
}
// ClearDescription clears the value of the "description" field.
func (u *ZoneUpsertOne) ClearDescription() *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.ClearDescription()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *ZoneUpsertOne) SetCreatedAt(v int64) *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *ZoneUpsertOne) AddCreatedAt(v int64) *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *ZoneUpsertOne) UpdateCreatedAt() *ZoneUpsertOne {
return u.Update(func(s *ZoneUpsert) {
s.UpdateCreatedAt()
})
}
// Exec executes the query.
func (u *ZoneUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for ZoneCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *ZoneUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *ZoneUpsertOne) ID(ctx context.Context) (id int, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *ZoneUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// ZoneCreateBulk is the builder for creating many Zone entities in bulk.
type ZoneCreateBulk struct {
config
err error
builders []*ZoneCreate
conflict []sql.ConflictOption
}
// Save creates the Zone entities in the database.
func (_c *ZoneCreateBulk) Save(ctx context.Context) ([]*Zone, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Zone, 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.(*ZoneMutation)
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}
spec.OnConflict = _c.conflict
// 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 {
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 *ZoneCreateBulk) SaveX(ctx context.Context) []*Zone {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ZoneCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ZoneCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Zone.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.ZoneUpsert) {
// SetZoneCode(v+v).
// }).
// Exec(ctx)
func (_c *ZoneCreateBulk) OnConflict(opts ...sql.ConflictOption) *ZoneUpsertBulk {
_c.conflict = opts
return &ZoneUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Zone.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *ZoneCreateBulk) OnConflictColumns(columns ...string) *ZoneUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &ZoneUpsertBulk{
create: _c,
}
}
// ZoneUpsertBulk is the builder for "upsert"-ing
// a bulk of Zone nodes.
type ZoneUpsertBulk struct {
create *ZoneCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Zone.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *ZoneUpsertBulk) UpdateNewValues() *ZoneUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Zone.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *ZoneUpsertBulk) Ignore() *ZoneUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *ZoneUpsertBulk) DoNothing() *ZoneUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the ZoneCreateBulk.OnConflict
// documentation for more info.
func (u *ZoneUpsertBulk) Update(set func(*ZoneUpsert)) *ZoneUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&ZoneUpsert{UpdateSet: update})
}))
return u
}
// SetZoneCode sets the "zone_code" field.
func (u *ZoneUpsertBulk) SetZoneCode(v string) *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.SetZoneCode(v)
})
}
// UpdateZoneCode sets the "zone_code" field to the value that was provided on create.
func (u *ZoneUpsertBulk) UpdateZoneCode() *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.UpdateZoneCode()
})
}
// SetZoneName sets the "zone_name" field.
func (u *ZoneUpsertBulk) SetZoneName(v string) *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.SetZoneName(v)
})
}
// UpdateZoneName sets the "zone_name" field to the value that was provided on create.
func (u *ZoneUpsertBulk) UpdateZoneName() *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.UpdateZoneName()
})
}
// SetDescription sets the "description" field.
func (u *ZoneUpsertBulk) SetDescription(v string) *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.SetDescription(v)
})
}
// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *ZoneUpsertBulk) UpdateDescription() *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.UpdateDescription()
})
}
// ClearDescription clears the value of the "description" field.
func (u *ZoneUpsertBulk) ClearDescription() *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.ClearDescription()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *ZoneUpsertBulk) SetCreatedAt(v int64) *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *ZoneUpsertBulk) AddCreatedAt(v int64) *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *ZoneUpsertBulk) UpdateCreatedAt() *ZoneUpsertBulk {
return u.Update(func(s *ZoneUpsert) {
s.UpdateCreatedAt()
})
}
// Exec executes the query.
func (u *ZoneUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ZoneCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for ZoneCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *ZoneUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}