Files
bj_power/bj_power_wms/ent/deliveryorder_create.go
T
SunYF 1d1dc1bdd8 按模块说明
一、MES — 叫料单扩展(schema + 逻辑)​

material_request 新增字段:packageNo(叫料包号,一次提交=一包)、callDate(叫料日,默认当天)、planBreakdown(jsonb,工单×排产日明细 []CallPlanBreakdown);targetDock 语义降级为"期望接驳台(可空,配送时 WMS 确定实际台)"。
新增 internal/logic/call_plan.go:实时计算「叫料需求明细(工单×排产日×物料)」,派生两类提示(当日剩余未叫 / 跨日量明细),不落库、不拦提交;接驳台空台校验 EnsureStationDocksEmpty、托盘回库 DispatchPalletReturnManual、人工清台 ClearDockLedger、配送单派车 DispatchDeliveryAgv、工位物料明细 StationMaterialDetail。
新增 internal/handler/production/call_pkg.go:8 个 MES 内部端点(X-API-TOKEN 网关),供 WMS 调用——叫料需求明细、按包查单、接驳台状态、托盘回库、人工清台、配送单派车、叫料池原始行、工位物料明细、WMS 代叫料。
internal/handler/production/call.go、internal/logic/call.go、agv.go、qty_report.go、routes_production.go、wmsclient/client.go、db.go 同步接入上述逻辑。
二、WMS — 配送单(新功能,叫料与送料彻底拆开)​

新增 schema/delivery_order.go + delivery_order_item.go 及 ent 生成代码:delivery_order(PENDING→DISPATCHED→DONE / CANCELLED,一单=一次托盘配送)、delivery_order_item(配送物料明细快照:工单/工艺/排产日)。
新增 internal/handler/delivery.go + 路由 + DeliveryOrders.vue 页面(仓储作业 → 配送单)。
mesclient/client.go 扩展:MES 叫料单结构补 packageNo/callDate/workOrderNo/planBreakdown,新增 PoolRow/DockPalletState/DeliveryAgvItem/getJSON 等。
CallQueue.vue:按叫料包展示,新增「代叫料」「建配送单」按钮与对话框;出库单回写所属配送单号(outbound_order 加字段);AGV 派送改由配送单驱动。
三、工位终端 — 叫料体验升级

MaterialPanel.vue:新增「本工位物料明细」卡(工艺物料全集×工位账四数,量为 0 也显示);叫料改为「叫料包」模式(默认当天、可勾选分批、可选其他排产日、期望接驳台可空),新增叫料日选择器、两条提示横幅(当日剩余未叫 / 跨日量明细)、托盘回库按钮。
InspectPanel.vue/Main.vue/OnlinePanel.vue/OfflinePanel.vue/WorkPanel.vue/SyncQueueDialog.vue/api/index.js/internal/handler/line.go/routes.go 同步接入接驳台状态、托盘回库、下班双台空台校验等。
web/static/index.html 构建刷新。
四、文档

案例.md:重写第 5/6/8/9 节与新「配送单」流程,补「模拟模式跳过接驳台校验」说明,库管员菜单加「配送单」;并修正"本单箱体"等措辞歧义。
客户问题.md:同步本轮拍板口径。
五、构建产物 / 同步

多个 MES 前端页面(.vue)随本次改动统一重新构建刷新;ent 生成代码(MES material_request、WMS delivery_order/outbound_order 相关)随 schema 更新重新生成。
2026-11-05 19:18:18 +08:00

1120 lines
34 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/deliveryorder"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// DeliveryOrderCreate is the builder for creating a DeliveryOrder entity.
type DeliveryOrderCreate struct {
config
mutation *DeliveryOrderMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetDeliveryNo sets the "deliveryNo" field.
func (_c *DeliveryOrderCreate) SetDeliveryNo(v string) *DeliveryOrderCreate {
_c.mutation.SetDeliveryNo(v)
return _c
}
// SetPackageNo sets the "packageNo" field.
func (_c *DeliveryOrderCreate) SetPackageNo(v string) *DeliveryOrderCreate {
_c.mutation.SetPackageNo(v)
return _c
}
// SetNillablePackageNo sets the "packageNo" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillablePackageNo(v *string) *DeliveryOrderCreate {
if v != nil {
_c.SetPackageNo(*v)
}
return _c
}
// SetStationNo sets the "stationNo" field.
func (_c *DeliveryOrderCreate) SetStationNo(v int) *DeliveryOrderCreate {
_c.mutation.SetStationNo(v)
return _c
}
// SetNillableStationNo sets the "stationNo" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableStationNo(v *int) *DeliveryOrderCreate {
if v != nil {
_c.SetStationNo(*v)
}
return _c
}
// SetTargetDock sets the "targetDock" field.
func (_c *DeliveryOrderCreate) SetTargetDock(v string) *DeliveryOrderCreate {
_c.mutation.SetTargetDock(v)
return _c
}
// SetNillableTargetDock sets the "targetDock" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableTargetDock(v *string) *DeliveryOrderCreate {
if v != nil {
_c.SetTargetDock(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *DeliveryOrderCreate) SetStatus(v string) *DeliveryOrderCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableStatus(v *string) *DeliveryOrderCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetOperator sets the "operator" field.
func (_c *DeliveryOrderCreate) SetOperator(v string) *DeliveryOrderCreate {
_c.mutation.SetOperator(v)
return _c
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableOperator(v *string) *DeliveryOrderCreate {
if v != nil {
_c.SetOperator(*v)
}
return _c
}
// SetRemark sets the "remark" field.
func (_c *DeliveryOrderCreate) SetRemark(v string) *DeliveryOrderCreate {
_c.mutation.SetRemark(v)
return _c
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableRemark(v *string) *DeliveryOrderCreate {
if v != nil {
_c.SetRemark(*v)
}
return _c
}
// SetAgvTaskNo sets the "agvTaskNo" field.
func (_c *DeliveryOrderCreate) SetAgvTaskNo(v string) *DeliveryOrderCreate {
_c.mutation.SetAgvTaskNo(v)
return _c
}
// SetNillableAgvTaskNo sets the "agvTaskNo" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableAgvTaskNo(v *string) *DeliveryOrderCreate {
if v != nil {
_c.SetAgvTaskNo(*v)
}
return _c
}
// SetCreatedAt sets the "createdAt" field.
func (_c *DeliveryOrderCreate) SetCreatedAt(v time.Time) *DeliveryOrderCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableCreatedAt(v *time.Time) *DeliveryOrderCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updatedAt" field.
func (_c *DeliveryOrderCreate) SetUpdatedAt(v time.Time) *DeliveryOrderCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updatedAt" field if the given value is not nil.
func (_c *DeliveryOrderCreate) SetNillableUpdatedAt(v *time.Time) *DeliveryOrderCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *DeliveryOrderCreate) SetID(v int) *DeliveryOrderCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the DeliveryOrderMutation object of the builder.
func (_c *DeliveryOrderCreate) Mutation() *DeliveryOrderMutation {
return _c.mutation
}
// Save creates the DeliveryOrder in the database.
func (_c *DeliveryOrderCreate) Save(ctx context.Context) (*DeliveryOrder, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *DeliveryOrderCreate) SaveX(ctx context.Context) *DeliveryOrder {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *DeliveryOrderCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *DeliveryOrderCreate) 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 *DeliveryOrderCreate) defaults() {
if _, ok := _c.mutation.PackageNo(); !ok {
v := deliveryorder.DefaultPackageNo
_c.mutation.SetPackageNo(v)
}
if _, ok := _c.mutation.StationNo(); !ok {
v := deliveryorder.DefaultStationNo
_c.mutation.SetStationNo(v)
}
if _, ok := _c.mutation.TargetDock(); !ok {
v := deliveryorder.DefaultTargetDock
_c.mutation.SetTargetDock(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := deliveryorder.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.Operator(); !ok {
v := deliveryorder.DefaultOperator
_c.mutation.SetOperator(v)
}
if _, ok := _c.mutation.Remark(); !ok {
v := deliveryorder.DefaultRemark
_c.mutation.SetRemark(v)
}
if _, ok := _c.mutation.AgvTaskNo(); !ok {
v := deliveryorder.DefaultAgvTaskNo
_c.mutation.SetAgvTaskNo(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := deliveryorder.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := deliveryorder.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *DeliveryOrderCreate) check() error {
if _, ok := _c.mutation.DeliveryNo(); !ok {
return &ValidationError{Name: "deliveryNo", err: errors.New(`ent: missing required field "DeliveryOrder.deliveryNo"`)}
}
if v, ok := _c.mutation.DeliveryNo(); ok {
if err := deliveryorder.DeliveryNoValidator(v); err != nil {
return &ValidationError{Name: "deliveryNo", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.deliveryNo": %w`, err)}
}
}
if _, ok := _c.mutation.PackageNo(); !ok {
return &ValidationError{Name: "packageNo", err: errors.New(`ent: missing required field "DeliveryOrder.packageNo"`)}
}
if v, ok := _c.mutation.PackageNo(); ok {
if err := deliveryorder.PackageNoValidator(v); err != nil {
return &ValidationError{Name: "packageNo", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.packageNo": %w`, err)}
}
}
if _, ok := _c.mutation.StationNo(); !ok {
return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "DeliveryOrder.stationNo"`)}
}
if _, ok := _c.mutation.TargetDock(); !ok {
return &ValidationError{Name: "targetDock", err: errors.New(`ent: missing required field "DeliveryOrder.targetDock"`)}
}
if v, ok := _c.mutation.TargetDock(); ok {
if err := deliveryorder.TargetDockValidator(v); err != nil {
return &ValidationError{Name: "targetDock", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.targetDock": %w`, err)}
}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "DeliveryOrder.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := deliveryorder.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.status": %w`, err)}
}
}
if _, ok := _c.mutation.Operator(); !ok {
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "DeliveryOrder.operator"`)}
}
if v, ok := _c.mutation.Operator(); ok {
if err := deliveryorder.OperatorValidator(v); err != nil {
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.operator": %w`, err)}
}
}
if _, ok := _c.mutation.Remark(); !ok {
return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "DeliveryOrder.remark"`)}
}
if v, ok := _c.mutation.Remark(); ok {
if err := deliveryorder.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.remark": %w`, err)}
}
}
if _, ok := _c.mutation.AgvTaskNo(); !ok {
return &ValidationError{Name: "agvTaskNo", err: errors.New(`ent: missing required field "DeliveryOrder.agvTaskNo"`)}
}
if v, ok := _c.mutation.AgvTaskNo(); ok {
if err := deliveryorder.AgvTaskNoValidator(v); err != nil {
return &ValidationError{Name: "agvTaskNo", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.agvTaskNo": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "DeliveryOrder.createdAt"`)}
}
if v, ok := _c.mutation.ID(); ok {
if err := deliveryorder.IDValidator(v); err != nil {
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "DeliveryOrder.id": %w`, err)}
}
}
return nil
}
func (_c *DeliveryOrderCreate) sqlSave(ctx context.Context) (*DeliveryOrder, 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 *DeliveryOrderCreate) createSpec() (*DeliveryOrder, *sqlgraph.CreateSpec) {
var (
_node = &DeliveryOrder{config: _c.config}
_spec = sqlgraph.NewCreateSpec(deliveryorder.Table, sqlgraph.NewFieldSpec(deliveryorder.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.DeliveryNo(); ok {
_spec.SetField(deliveryorder.FieldDeliveryNo, field.TypeString, value)
_node.DeliveryNo = value
}
if value, ok := _c.mutation.PackageNo(); ok {
_spec.SetField(deliveryorder.FieldPackageNo, field.TypeString, value)
_node.PackageNo = value
}
if value, ok := _c.mutation.StationNo(); ok {
_spec.SetField(deliveryorder.FieldStationNo, field.TypeInt, value)
_node.StationNo = value
}
if value, ok := _c.mutation.TargetDock(); ok {
_spec.SetField(deliveryorder.FieldTargetDock, field.TypeString, value)
_node.TargetDock = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(deliveryorder.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.Operator(); ok {
_spec.SetField(deliveryorder.FieldOperator, field.TypeString, value)
_node.Operator = value
}
if value, ok := _c.mutation.Remark(); ok {
_spec.SetField(deliveryorder.FieldRemark, field.TypeString, value)
_node.Remark = value
}
if value, ok := _c.mutation.AgvTaskNo(); ok {
_spec.SetField(deliveryorder.FieldAgvTaskNo, field.TypeString, value)
_node.AgvTaskNo = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(deliveryorder.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(deliveryorder.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = &value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.DeliveryOrder.Create().
// SetDeliveryNo(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.DeliveryOrderUpsert) {
// SetDeliveryNo(v+v).
// }).
// Exec(ctx)
func (_c *DeliveryOrderCreate) OnConflict(opts ...sql.ConflictOption) *DeliveryOrderUpsertOne {
_c.conflict = opts
return &DeliveryOrderUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.DeliveryOrder.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *DeliveryOrderCreate) OnConflictColumns(columns ...string) *DeliveryOrderUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &DeliveryOrderUpsertOne{
create: _c,
}
}
type (
// DeliveryOrderUpsertOne is the builder for "upsert"-ing
// one DeliveryOrder node.
DeliveryOrderUpsertOne struct {
create *DeliveryOrderCreate
}
// DeliveryOrderUpsert is the "OnConflict" setter.
DeliveryOrderUpsert struct {
*sql.UpdateSet
}
)
// SetDeliveryNo sets the "deliveryNo" field.
func (u *DeliveryOrderUpsert) SetDeliveryNo(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldDeliveryNo, v)
return u
}
// UpdateDeliveryNo sets the "deliveryNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateDeliveryNo() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldDeliveryNo)
return u
}
// SetPackageNo sets the "packageNo" field.
func (u *DeliveryOrderUpsert) SetPackageNo(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldPackageNo, v)
return u
}
// UpdatePackageNo sets the "packageNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdatePackageNo() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldPackageNo)
return u
}
// SetStationNo sets the "stationNo" field.
func (u *DeliveryOrderUpsert) SetStationNo(v int) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldStationNo, v)
return u
}
// UpdateStationNo sets the "stationNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateStationNo() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldStationNo)
return u
}
// AddStationNo adds v to the "stationNo" field.
func (u *DeliveryOrderUpsert) AddStationNo(v int) *DeliveryOrderUpsert {
u.Add(deliveryorder.FieldStationNo, v)
return u
}
// SetTargetDock sets the "targetDock" field.
func (u *DeliveryOrderUpsert) SetTargetDock(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldTargetDock, v)
return u
}
// UpdateTargetDock sets the "targetDock" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateTargetDock() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldTargetDock)
return u
}
// SetStatus sets the "status" field.
func (u *DeliveryOrderUpsert) SetStatus(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateStatus() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldStatus)
return u
}
// SetOperator sets the "operator" field.
func (u *DeliveryOrderUpsert) SetOperator(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldOperator, v)
return u
}
// UpdateOperator sets the "operator" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateOperator() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldOperator)
return u
}
// SetRemark sets the "remark" field.
func (u *DeliveryOrderUpsert) SetRemark(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldRemark, v)
return u
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateRemark() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldRemark)
return u
}
// SetAgvTaskNo sets the "agvTaskNo" field.
func (u *DeliveryOrderUpsert) SetAgvTaskNo(v string) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldAgvTaskNo, v)
return u
}
// UpdateAgvTaskNo sets the "agvTaskNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateAgvTaskNo() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldAgvTaskNo)
return u
}
// SetUpdatedAt sets the "updatedAt" field.
func (u *DeliveryOrderUpsert) SetUpdatedAt(v time.Time) *DeliveryOrderUpsert {
u.Set(deliveryorder.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updatedAt" field to the value that was provided on create.
func (u *DeliveryOrderUpsert) UpdateUpdatedAt() *DeliveryOrderUpsert {
u.SetExcluded(deliveryorder.FieldUpdatedAt)
return u
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (u *DeliveryOrderUpsert) ClearUpdatedAt() *DeliveryOrderUpsert {
u.SetNull(deliveryorder.FieldUpdatedAt)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
// client.DeliveryOrder.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(deliveryorder.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeliveryOrderUpsertOne) UpdateNewValues() *DeliveryOrderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
if _, exists := u.create.mutation.ID(); exists {
s.SetIgnore(deliveryorder.FieldID)
}
if _, exists := u.create.mutation.CreatedAt(); exists {
s.SetIgnore(deliveryorder.FieldCreatedAt)
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.DeliveryOrder.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeliveryOrderUpsertOne) Ignore() *DeliveryOrderUpsertOne {
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 *DeliveryOrderUpsertOne) DoNothing() *DeliveryOrderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeliveryOrderCreate.OnConflict
// documentation for more info.
func (u *DeliveryOrderUpsertOne) Update(set func(*DeliveryOrderUpsert)) *DeliveryOrderUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeliveryOrderUpsert{UpdateSet: update})
}))
return u
}
// SetDeliveryNo sets the "deliveryNo" field.
func (u *DeliveryOrderUpsertOne) SetDeliveryNo(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetDeliveryNo(v)
})
}
// UpdateDeliveryNo sets the "deliveryNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateDeliveryNo() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateDeliveryNo()
})
}
// SetPackageNo sets the "packageNo" field.
func (u *DeliveryOrderUpsertOne) SetPackageNo(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetPackageNo(v)
})
}
// UpdatePackageNo sets the "packageNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdatePackageNo() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdatePackageNo()
})
}
// SetStationNo sets the "stationNo" field.
func (u *DeliveryOrderUpsertOne) SetStationNo(v int) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetStationNo(v)
})
}
// AddStationNo adds v to the "stationNo" field.
func (u *DeliveryOrderUpsertOne) AddStationNo(v int) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.AddStationNo(v)
})
}
// UpdateStationNo sets the "stationNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateStationNo() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateStationNo()
})
}
// SetTargetDock sets the "targetDock" field.
func (u *DeliveryOrderUpsertOne) SetTargetDock(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetTargetDock(v)
})
}
// UpdateTargetDock sets the "targetDock" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateTargetDock() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateTargetDock()
})
}
// SetStatus sets the "status" field.
func (u *DeliveryOrderUpsertOne) SetStatus(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateStatus() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateStatus()
})
}
// SetOperator sets the "operator" field.
func (u *DeliveryOrderUpsertOne) SetOperator(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetOperator(v)
})
}
// UpdateOperator sets the "operator" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateOperator() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateOperator()
})
}
// SetRemark sets the "remark" field.
func (u *DeliveryOrderUpsertOne) SetRemark(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateRemark() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateRemark()
})
}
// SetAgvTaskNo sets the "agvTaskNo" field.
func (u *DeliveryOrderUpsertOne) SetAgvTaskNo(v string) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetAgvTaskNo(v)
})
}
// UpdateAgvTaskNo sets the "agvTaskNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateAgvTaskNo() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateAgvTaskNo()
})
}
// SetUpdatedAt sets the "updatedAt" field.
func (u *DeliveryOrderUpsertOne) SetUpdatedAt(v time.Time) *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updatedAt" field to the value that was provided on create.
func (u *DeliveryOrderUpsertOne) UpdateUpdatedAt() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateUpdatedAt()
})
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (u *DeliveryOrderUpsertOne) ClearUpdatedAt() *DeliveryOrderUpsertOne {
return u.Update(func(s *DeliveryOrderUpsert) {
s.ClearUpdatedAt()
})
}
// Exec executes the query.
func (u *DeliveryOrderUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeliveryOrderCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeliveryOrderUpsertOne) 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 *DeliveryOrderUpsertOne) 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 *DeliveryOrderUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// DeliveryOrderCreateBulk is the builder for creating many DeliveryOrder entities in bulk.
type DeliveryOrderCreateBulk struct {
config
err error
builders []*DeliveryOrderCreate
conflict []sql.ConflictOption
}
// Save creates the DeliveryOrder entities in the database.
func (_c *DeliveryOrderCreateBulk) Save(ctx context.Context) ([]*DeliveryOrder, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*DeliveryOrder, 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.(*DeliveryOrderMutation)
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 && 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 *DeliveryOrderCreateBulk) SaveX(ctx context.Context) []*DeliveryOrder {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *DeliveryOrderCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *DeliveryOrderCreateBulk) 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.DeliveryOrder.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.DeliveryOrderUpsert) {
// SetDeliveryNo(v+v).
// }).
// Exec(ctx)
func (_c *DeliveryOrderCreateBulk) OnConflict(opts ...sql.ConflictOption) *DeliveryOrderUpsertBulk {
_c.conflict = opts
return &DeliveryOrderUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.DeliveryOrder.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *DeliveryOrderCreateBulk) OnConflictColumns(columns ...string) *DeliveryOrderUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &DeliveryOrderUpsertBulk{
create: _c,
}
}
// DeliveryOrderUpsertBulk is the builder for "upsert"-ing
// a bulk of DeliveryOrder nodes.
type DeliveryOrderUpsertBulk struct {
create *DeliveryOrderCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.DeliveryOrder.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// sql.ResolveWith(func(u *sql.UpdateSet) {
// u.SetIgnore(deliveryorder.FieldID)
// }),
// ).
// Exec(ctx)
func (u *DeliveryOrderUpsertBulk) UpdateNewValues() *DeliveryOrderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
for _, b := range u.create.builders {
if _, exists := b.mutation.ID(); exists {
s.SetIgnore(deliveryorder.FieldID)
}
if _, exists := b.mutation.CreatedAt(); exists {
s.SetIgnore(deliveryorder.FieldCreatedAt)
}
}
}))
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.DeliveryOrder.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *DeliveryOrderUpsertBulk) Ignore() *DeliveryOrderUpsertBulk {
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 *DeliveryOrderUpsertBulk) DoNothing() *DeliveryOrderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the DeliveryOrderCreateBulk.OnConflict
// documentation for more info.
func (u *DeliveryOrderUpsertBulk) Update(set func(*DeliveryOrderUpsert)) *DeliveryOrderUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&DeliveryOrderUpsert{UpdateSet: update})
}))
return u
}
// SetDeliveryNo sets the "deliveryNo" field.
func (u *DeliveryOrderUpsertBulk) SetDeliveryNo(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetDeliveryNo(v)
})
}
// UpdateDeliveryNo sets the "deliveryNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateDeliveryNo() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateDeliveryNo()
})
}
// SetPackageNo sets the "packageNo" field.
func (u *DeliveryOrderUpsertBulk) SetPackageNo(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetPackageNo(v)
})
}
// UpdatePackageNo sets the "packageNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdatePackageNo() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdatePackageNo()
})
}
// SetStationNo sets the "stationNo" field.
func (u *DeliveryOrderUpsertBulk) SetStationNo(v int) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetStationNo(v)
})
}
// AddStationNo adds v to the "stationNo" field.
func (u *DeliveryOrderUpsertBulk) AddStationNo(v int) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.AddStationNo(v)
})
}
// UpdateStationNo sets the "stationNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateStationNo() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateStationNo()
})
}
// SetTargetDock sets the "targetDock" field.
func (u *DeliveryOrderUpsertBulk) SetTargetDock(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetTargetDock(v)
})
}
// UpdateTargetDock sets the "targetDock" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateTargetDock() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateTargetDock()
})
}
// SetStatus sets the "status" field.
func (u *DeliveryOrderUpsertBulk) SetStatus(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateStatus() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateStatus()
})
}
// SetOperator sets the "operator" field.
func (u *DeliveryOrderUpsertBulk) SetOperator(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetOperator(v)
})
}
// UpdateOperator sets the "operator" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateOperator() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateOperator()
})
}
// SetRemark sets the "remark" field.
func (u *DeliveryOrderUpsertBulk) SetRemark(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetRemark(v)
})
}
// UpdateRemark sets the "remark" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateRemark() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateRemark()
})
}
// SetAgvTaskNo sets the "agvTaskNo" field.
func (u *DeliveryOrderUpsertBulk) SetAgvTaskNo(v string) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetAgvTaskNo(v)
})
}
// UpdateAgvTaskNo sets the "agvTaskNo" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateAgvTaskNo() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateAgvTaskNo()
})
}
// SetUpdatedAt sets the "updatedAt" field.
func (u *DeliveryOrderUpsertBulk) SetUpdatedAt(v time.Time) *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.SetUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updatedAt" field to the value that was provided on create.
func (u *DeliveryOrderUpsertBulk) UpdateUpdatedAt() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.UpdateUpdatedAt()
})
}
// ClearUpdatedAt clears the value of the "updatedAt" field.
func (u *DeliveryOrderUpsertBulk) ClearUpdatedAt() *DeliveryOrderUpsertBulk {
return u.Update(func(s *DeliveryOrderUpsert) {
s.ClearUpdatedAt()
})
}
// Exec executes the query.
func (u *DeliveryOrderUpsertBulk) 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 DeliveryOrderCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for DeliveryOrderCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *DeliveryOrderUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}