Files
bj_power/bj_power_mes/ent/stationshift_create.go
T
SunYF 42bcf395d2 feat: AGV三段链安全机制、补料/损耗/下班闭环、接驳台左右互换
AGV 调度:
- 任务重构为 GO_LOAD/TRANSPORT/EMPTY_RETURN/FREE 三段链,到位即停(ARRIVED)需人工确认装卸
- 自由调度单点步进,每段强制弹"请确保路径畅通无杂物";托盘回收独立工作台
- 接驳台 PLC 传感器检测到托盘即自动卸货放行,传感器故障由人工按钮兜底(无轮询)
- 车辆状态只读展示(海康3.1.7 queryAgvStatus),调度仍由 RCS 负责

物料闭环:
- 补料管理(SHORTAGE):工位申请 + 主管审批调增叫料池额度,与借料/差异补发三轨并行
- 损耗台账(loss_ledger):退料实际 < 理论必填原因、后审核,工单不记损耗
- 退料强制指定左/右接驳台,WMS 库管可代工位退料

下班闭环:
- 工位终端自检接驳台剩余物料后下班;库管收货 + 托盘拉走后事件驱动自动结班
- 退出登录未下班仅作安全提示(不强制拦截、不新增责任审批)

接驳台左右按操作员朝向建模(dock.side 字段),废除"奇左偶右"隐式约定;
看板标签 / seed / 迁移补丁 / 布局文档统一为中文左/右。

产线布局说明:C1 前线头 AGV 点、C15 后线尾 AGV 点、外部 O1/O2/O3 散点,
清理修订痕迹为最终态描述。
2026-11-03 18:29:31 +08:00

378 lines
11 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/stationshift"
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// StationShiftCreate is the builder for creating a StationShift entity.
type StationShiftCreate struct {
config
mutation *StationShiftMutation
hooks []Hook
}
// SetStationNo sets the "stationNo" field.
func (_c *StationShiftCreate) SetStationNo(v int) *StationShiftCreate {
_c.mutation.SetStationNo(v)
return _c
}
// SetOperator sets the "operator" field.
func (_c *StationShiftCreate) SetOperator(v string) *StationShiftCreate {
_c.mutation.SetOperator(v)
return _c
}
// SetNillableOperator sets the "operator" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableOperator(v *string) *StationShiftCreate {
if v != nil {
_c.SetOperator(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *StationShiftCreate) SetStatus(v string) *StationShiftCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableStatus(v *string) *StationShiftCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetStartAt sets the "startAt" field.
func (_c *StationShiftCreate) SetStartAt(v int64) *StationShiftCreate {
_c.mutation.SetStartAt(v)
return _c
}
// SetNillableStartAt sets the "startAt" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableStartAt(v *int64) *StationShiftCreate {
if v != nil {
_c.SetStartAt(*v)
}
return _c
}
// SetEndApplyAt sets the "endApplyAt" field.
func (_c *StationShiftCreate) SetEndApplyAt(v int64) *StationShiftCreate {
_c.mutation.SetEndApplyAt(v)
return _c
}
// SetNillableEndApplyAt sets the "endApplyAt" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableEndApplyAt(v *int64) *StationShiftCreate {
if v != nil {
_c.SetEndApplyAt(*v)
}
return _c
}
// SetClosedAt sets the "closedAt" field.
func (_c *StationShiftCreate) SetClosedAt(v int64) *StationShiftCreate {
_c.mutation.SetClosedAt(v)
return _c
}
// SetNillableClosedAt sets the "closedAt" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableClosedAt(v *int64) *StationShiftCreate {
if v != nil {
_c.SetClosedAt(*v)
}
return _c
}
// SetRemark sets the "remark" field.
func (_c *StationShiftCreate) SetRemark(v string) *StationShiftCreate {
_c.mutation.SetRemark(v)
return _c
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableRemark(v *string) *StationShiftCreate {
if v != nil {
_c.SetRemark(*v)
}
return _c
}
// SetCreatedAt sets the "createdAt" field.
func (_c *StationShiftCreate) SetCreatedAt(v time.Time) *StationShiftCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
func (_c *StationShiftCreate) SetNillableCreatedAt(v *time.Time) *StationShiftCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// Mutation returns the StationShiftMutation object of the builder.
func (_c *StationShiftCreate) Mutation() *StationShiftMutation {
return _c.mutation
}
// Save creates the StationShift in the database.
func (_c *StationShiftCreate) Save(ctx context.Context) (*StationShift, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *StationShiftCreate) SaveX(ctx context.Context) *StationShift {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *StationShiftCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *StationShiftCreate) 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 *StationShiftCreate) defaults() {
if _, ok := _c.mutation.Operator(); !ok {
v := stationshift.DefaultOperator
_c.mutation.SetOperator(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := stationshift.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.StartAt(); !ok {
v := stationshift.DefaultStartAt
_c.mutation.SetStartAt(v)
}
if _, ok := _c.mutation.EndApplyAt(); !ok {
v := stationshift.DefaultEndApplyAt
_c.mutation.SetEndApplyAt(v)
}
if _, ok := _c.mutation.ClosedAt(); !ok {
v := stationshift.DefaultClosedAt
_c.mutation.SetClosedAt(v)
}
if _, ok := _c.mutation.Remark(); !ok {
v := stationshift.DefaultRemark
_c.mutation.SetRemark(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := stationshift.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *StationShiftCreate) check() error {
if _, ok := _c.mutation.StationNo(); !ok {
return &ValidationError{Name: "stationNo", err: errors.New(`ent: missing required field "StationShift.stationNo"`)}
}
if _, ok := _c.mutation.Operator(); !ok {
return &ValidationError{Name: "operator", err: errors.New(`ent: missing required field "StationShift.operator"`)}
}
if v, ok := _c.mutation.Operator(); ok {
if err := stationshift.OperatorValidator(v); err != nil {
return &ValidationError{Name: "operator", err: fmt.Errorf(`ent: validator failed for field "StationShift.operator": %w`, err)}
}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "StationShift.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := stationshift.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "StationShift.status": %w`, err)}
}
}
if _, ok := _c.mutation.StartAt(); !ok {
return &ValidationError{Name: "startAt", err: errors.New(`ent: missing required field "StationShift.startAt"`)}
}
if _, ok := _c.mutation.EndApplyAt(); !ok {
return &ValidationError{Name: "endApplyAt", err: errors.New(`ent: missing required field "StationShift.endApplyAt"`)}
}
if _, ok := _c.mutation.ClosedAt(); !ok {
return &ValidationError{Name: "closedAt", err: errors.New(`ent: missing required field "StationShift.closedAt"`)}
}
if v, ok := _c.mutation.Remark(); ok {
if err := stationshift.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "StationShift.remark": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "StationShift.createdAt"`)}
}
return nil
}
func (_c *StationShiftCreate) sqlSave(ctx context.Context) (*StationShift, 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 *StationShiftCreate) createSpec() (*StationShift, *sqlgraph.CreateSpec) {
var (
_node = &StationShift{config: _c.config}
_spec = sqlgraph.NewCreateSpec(stationshift.Table, sqlgraph.NewFieldSpec(stationshift.FieldID, field.TypeInt))
)
if value, ok := _c.mutation.StationNo(); ok {
_spec.SetField(stationshift.FieldStationNo, field.TypeInt, value)
_node.StationNo = value
}
if value, ok := _c.mutation.Operator(); ok {
_spec.SetField(stationshift.FieldOperator, field.TypeString, value)
_node.Operator = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(stationshift.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.StartAt(); ok {
_spec.SetField(stationshift.FieldStartAt, field.TypeInt64, value)
_node.StartAt = value
}
if value, ok := _c.mutation.EndApplyAt(); ok {
_spec.SetField(stationshift.FieldEndApplyAt, field.TypeInt64, value)
_node.EndApplyAt = value
}
if value, ok := _c.mutation.ClosedAt(); ok {
_spec.SetField(stationshift.FieldClosedAt, field.TypeInt64, value)
_node.ClosedAt = value
}
if value, ok := _c.mutation.Remark(); ok {
_spec.SetField(stationshift.FieldRemark, field.TypeString, value)
_node.Remark = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(stationshift.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
return _node, _spec
}
// StationShiftCreateBulk is the builder for creating many StationShift entities in bulk.
type StationShiftCreateBulk struct {
config
err error
builders []*StationShiftCreate
}
// Save creates the StationShift entities in the database.
func (_c *StationShiftCreateBulk) Save(ctx context.Context) ([]*StationShift, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*StationShift, 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.(*StationShiftMutation)
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 {
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 *StationShiftCreateBulk) SaveX(ctx context.Context) []*StationShift {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *StationShiftCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *StationShiftCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}