feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -117,27 +117,87 @@ func (s *Service) CreateQtyReport(ctx context.Context, req QtyReportReq) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ErrReturnForceConfirm 哨兵错误(拍板2 2026-11-04):PLC 离线时退料拦截只作提示和警戒,
|
||||
// 人工可强行确认退料。handler 据此(errors.Is)返回业务码 2409,前端弹风险提示二次确认。
|
||||
// 2026-11-04 撤除包:撤「未使用」归类——退料数量允许手填/可改,以库管实际录入为准。
|
||||
var ErrReturnForceConfirm = errors.New("工位传感器不可读(PLC 离线),无法确认工件已完工;如现场确认物料已离开工位,可强行退料")
|
||||
|
||||
// CheckReturnStationClear 退料前置检查(N5 + 拍板2 2026-11-04):
|
||||
// - PLC 可读:无托盘 → (false, nil) 正常放行(按实际消耗算,不标「未使用」);
|
||||
// 有托盘 → 硬拒"工件未完工,不允许退料"(工件在工位消耗未定,强行不适用——拍板2 仅放开 PLC 离线场景);
|
||||
// - PLC 不可读(未接入/离线)→ (true, nil):不再一律拒绝,调用方未确认强行前以
|
||||
// ErrReturnForceConfirm 拦截(业务码 2409),前端弹风险提示,人工确认后带 forceConfirm 重提放行。
|
||||
func (s *Service) CheckReturnStationClear(ctx context.Context, stationNo int) (needForce bool, err error) {
|
||||
if stationNo <= 0 {
|
||||
return false, errors.New("缺少工位号,无法校验工件完工状态")
|
||||
}
|
||||
if s.ctx.PLC == nil || s.ctx.PLC.Get() == nil {
|
||||
return true, nil
|
||||
}
|
||||
has, rerr := s.ctx.PLC.QueryStationPallet(ctx, stationNo)
|
||||
if rerr != nil {
|
||||
return true, nil // PLC 离线:拦截降级为提示+警戒,人工可强行确认
|
||||
}
|
||||
if has {
|
||||
return false, errors.New("工件未完工,不允许退料")
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// StationReturnMaterial 工位退料回库房:落事件日志 + 调 WMS 预建待确认退库单。
|
||||
// returnDock(2026-11-03 拍板)= 退料接驳台(必填,AGV 从该接驳台拉货)。
|
||||
// 退库单在 WMS 侧由库管确认收货后库存加回(链路封闭,问题记录 L491)。
|
||||
func (s *Service) StationReturnMaterial(ctx context.Context, orderNo string, stationNo int, sn, materialCode, materialName, spec, reason, operator, unit string, qty int, returnDock string) error {
|
||||
// returnDock(2026-11-03 拍板)= 退料接驳台(必填,退料托盘放置位置)。
|
||||
// lossReason(2026-11-04 拍板)= 损耗原因(巡检退料一律必填,随退库单落 WMS loss_reason 可查)。
|
||||
// transportMode(2026-11-04 定稿)= 运输方式 agv/manual(必填):agv=传感器检测到接驳台有托盘且
|
||||
// 库房接驳台有空位时自动派车拉运(库管不点派车);manual=无 AGV,人工搬运,退料单照常等库管收货。
|
||||
// 退库单在 WMS 侧由库管确认收货后库存加回(库管确认=物料进出库动作,不覆盖派车)。
|
||||
// N5(2026-11-04 拍板)+ 拍板2:提交前校验工位传感器——无托盘正常退料;
|
||||
// PLC 离线时拦截降级为提示,forceConfirm=true(前端弹风险提示后人工确认)方可放行;
|
||||
// 传感器有托盘(工件在工位)始终硬拒,强行确认不适用。
|
||||
// 2026-11-04 撤除包:撤「未使用」标记——退料数量允许手填/可改,以库管实际录入为准。
|
||||
func (s *Service) StationReturnMaterial(ctx context.Context, orderNo string, stationNo int, sn, materialCode, materialName, spec, reason, operator, unit string, qty int, returnDock, lossReason, transportMode string, forceConfirm bool) error {
|
||||
if stationNo <= 0 || materialCode == "" || qty <= 0 {
|
||||
return errors.New("工位号、物料编码、退库数量必填")
|
||||
}
|
||||
if returnDock == "" {
|
||||
return errors.New("退料必须指定接驳台(左/右)")
|
||||
}
|
||||
if transportMode != "agv" && transportMode != "manual" {
|
||||
return errors.New("运输方式必选(AGV / 人工)")
|
||||
}
|
||||
needForce, gerr := s.CheckReturnStationClear(ctx, stationNo)
|
||||
if gerr != nil {
|
||||
return gerr
|
||||
}
|
||||
if needForce && !forceConfirm {
|
||||
return ErrReturnForceConfirm
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "station.return_material", orderNo, operator, "return_order",
|
||||
materialCode, "工位退料回库房", map[string]any{"stationNo": stationNo, "qty": qty, "reason": reason, "returnDock": returnDock})
|
||||
materialCode, "工位退料回库房", map[string]any{"stationNo": stationNo, "qty": qty, "reason": reason, "returnDock": returnDock, "lossReason": lossReason, "transportMode": transportMode})
|
||||
// 调 WMS 内部 API 预建退库单(失败降级:记录日志但不阻断工位操作)
|
||||
if s.ctx.Wms != nil {
|
||||
if err := s.ctx.Wms.CreateReturnOrder(ctx, orderNo, sn, materialCode, materialName, spec, reason, operator, stationNo, qty, unit, "", returnDock); err != nil {
|
||||
if err := s.ctx.Wms.CreateReturnOrder(ctx, orderNo, sn, materialCode, materialName, spec, reason, operator, stationNo, qty, unit, "", returnDock, lossReason, transportMode); err != nil {
|
||||
return fmt.Errorf("通知 WMS 建退库单失败:%w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListStationReturnOrders 工位终端「我的退料单」列表(WMS 数据转发;PENDING 可取消)。
|
||||
func (s *Service) ListStationReturnOrders(ctx context.Context, stationNo int) ([]map[string]any, error) {
|
||||
if s.ctx.Wms == nil {
|
||||
return nil, errors.New("WMS 未连接")
|
||||
}
|
||||
return s.ctx.Wms.StationReturnList(ctx, stationNo)
|
||||
}
|
||||
|
||||
// CancelStationReturn 工位取消自己发起的 PENDING 退料单(转发 WMS 校验 stationNo 归属后取消)。
|
||||
func (s *Service) CancelStationReturn(ctx context.Context, returnNo string, stationNo int, operator, reason string) error {
|
||||
if s.ctx.Wms == nil {
|
||||
return errors.New("WMS 未连接")
|
||||
}
|
||||
return s.ctx.Wms.CancelReturnOrder(ctx, returnNo, stationNo, operator, reason)
|
||||
}
|
||||
|
||||
// ============ 一键生成工序间检验记录(P0-4) ============
|
||||
|
||||
// InterProcessInspection 工序间检验记录汇总项
|
||||
|
||||
Reference in New Issue
Block a user