feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -274,7 +274,8 @@ func (s *Service) recomputePoolStations(ctx context.Context, stationNos []int) (
|
||||
if fm.MaterialCode == "" {
|
||||
continue
|
||||
}
|
||||
need := int(math.Ceil(float64(q) * fm.UnitQty * (1 + fm.LossRate/100)))
|
||||
// R7(2026-11-03 拍板):备料量=工单需求×单台用量,不预放折损率;损耗走补料审批(shortage)
|
||||
need := int(math.Ceil(float64(q) * fm.UnitQty))
|
||||
if need <= 0 {
|
||||
continue
|
||||
}
|
||||
@@ -799,7 +800,7 @@ func (s *Service) RequestReturn(ctx context.Context, requestNo string, stationNo
|
||||
}
|
||||
if s.ctx.Wms != nil {
|
||||
if werr := s.ctx.Wms.CreateReturnOrder(ctx, "", "", mr.MaterialCode, mr.MaterialName, "",
|
||||
"叫料单退库", operator, mr.StationNo, int(mr.ReqQty), mr.Unit, requestNo, mr.TargetDock); werr != nil {
|
||||
"叫料单退库", operator, mr.StationNo, int(mr.ReqQty), mr.Unit, requestNo, mr.TargetDock, "", "agv"); werr != nil {
|
||||
return fmt.Errorf("通知 WMS 建退库单失败:%w", werr)
|
||||
}
|
||||
}
|
||||
@@ -889,21 +890,18 @@ func (s *Service) CompleteCall(ctx context.Context, requestNo string, sentQty fl
|
||||
completeDesc, map[string]any{"stationNo": locked.StationNo, "materialCode": locked.MaterialCode,
|
||||
"reqQty": locked.ReqQty, "sentQty": actual, "outboundNo": outboundNo})
|
||||
s.notifyDashboard()
|
||||
// AGV 三段链(2026-11-03 三层机制):完成备料=托盘已备好在库房接驳台 → 写台账(hasPallet=true),
|
||||
// 再业务自动触发「空车前往装货点」段(免人工确认);到位后进 ARRIVED 待库管「确认装车并送货」。
|
||||
// AGV 三段链(2026-11-03 定论修订):完成备料=托盘已备好在库房接驳台 → 仅写台账(hasPallet=true)。
|
||||
// 废除「备料完成自动派车」:库管在 WMS 叫料队列点「送货」(DispatchCallAgv)人工触发才下发空车段。
|
||||
if locked.NeedAgv && locked.TargetDock != "" {
|
||||
s.setDockPalletByCode(ctx, dockStoreCode, true, requestNo, requestNo)
|
||||
if derr := s.DispatchAgvForCall(ctx, locked, operator); derr != nil {
|
||||
s.ctx.EventLog.Write(ctx, "agv.dispatch.fail", "", operator, "material_request", requestNo,
|
||||
"叫料完成备料自动派车失败", map[string]any{"err": derr.Error()})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConfirmReturn 仓库确认收回(退库闭环终点):RETURNING → RETURNED,
|
||||
// 退库量=实发量(整单退);池子已发 −退库量(额度回补)。
|
||||
func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string) error {
|
||||
// 按库管实收量回补(R18 2026-11-03 拍板:实收<应退为收货差异,按实收回补额度;
|
||||
// 差异落「待核」,不自动进损耗台账——以库管真实核算为准,核实为损耗后由主管走损耗登记挂工单)。
|
||||
func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string, receiveQty, receiveDiff float64, receiveNote string) error {
|
||||
mr, err := s.ctx.EntClient.MaterialRequest.Query().
|
||||
Where(materialrequest.RequestNo(requestNo)).Only(ctx)
|
||||
if err != nil || mr == nil {
|
||||
@@ -913,6 +911,15 @@ func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string)
|
||||
return errors.New("仅退库中的叫料单可确认收回")
|
||||
}
|
||||
ret := mr.SentQty // 整单退:退库量=实发量
|
||||
if receiveQty > 0 {
|
||||
if receiveQty > mr.SentQty {
|
||||
return fmt.Errorf("实收数量 %v 不能大于应退数量 %v", receiveQty, mr.SentQty)
|
||||
}
|
||||
ret = receiveQty
|
||||
}
|
||||
if receiveDiff <= 0 { // 未传差异时按应退-实收自算
|
||||
receiveDiff = mr.SentQty - ret
|
||||
}
|
||||
tx, terr := s.ctx.EntClient.Tx(ctx)
|
||||
if terr != nil {
|
||||
return terr
|
||||
@@ -950,7 +957,8 @@ func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string)
|
||||
}
|
||||
}
|
||||
if _, uerr := tx.MaterialRequest.UpdateOneID(locked.ID).
|
||||
SetStatus("RETURNED").SetReturnedQty(ret).Save(ctx); uerr != nil {
|
||||
SetStatus("RETURNED").SetReturnedQty(ret).
|
||||
SetReceiveQty(ret).SetReceiveDiff(receiveDiff).SetReceiveNote(receiveNote).Save(ctx); uerr != nil {
|
||||
return uerr
|
||||
}
|
||||
if cerr := tx.Commit(); cerr != nil {
|
||||
@@ -958,12 +966,16 @@ func (s *Service) ConfirmReturn(ctx context.Context, requestNo, operator string)
|
||||
}
|
||||
committed = true
|
||||
returnDesc := "仓库确认收回,叫料单关闭"
|
||||
if receiveDiff > 0 {
|
||||
returnDesc = fmt.Sprintf("仓库确认收回:实收 %v/应退 %v,收货差异 %v(待核,不自动进损耗台账)", ret, mr.SentQty, receiveDiff)
|
||||
}
|
||||
if d := borrowDetail(back, locked.StationNo, locked.MaterialCode); d != "" {
|
||||
returnDesc = "操作人[" + operator + "] 确认收回(含借料回补)," + d
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "call.return_confirm", "", operator, "material_request", requestNo,
|
||||
returnDesc, map[string]any{"stationNo": locked.StationNo,
|
||||
"materialCode": locked.MaterialCode, "returnedQty": ret})
|
||||
"materialCode": locked.MaterialCode, "returnedQty": ret,
|
||||
"receiveQty": ret, "receiveDiff": receiveDiff, "receiveNote": receiveNote})
|
||||
// 事件驱动收口:退料收货后检查 CLOSING 班次可否置 CLOSED(下班闭环,2026-11-03)
|
||||
s.maybeCloseShifts(ctx)
|
||||
s.notifyDashboard()
|
||||
|
||||
Reference in New Issue
Block a user