feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -60,7 +60,7 @@ func (s *Service) SubmitAgv(ctx context.Context, req AgvSubmitRequest, operator
|
||||
}
|
||||
source := req.SourceDock
|
||||
if source == "" {
|
||||
source = "DOCK21"
|
||||
source = "JBT21" // T7(2026-11-03 拍板):库房接驳台统一 JBT21
|
||||
}
|
||||
// 目标字段复用语义为 AGV 点位编码(position_code)
|
||||
groups := map[string][]AgvSubmitRow{}
|
||||
@@ -209,16 +209,40 @@ func (s *Service) LoadCallForDispatch(ctx context.Context, requestNo string) (*e
|
||||
return mr, nil
|
||||
}
|
||||
|
||||
// DispatchAgvForCall 叫料完成备料后由 MES 业务自动触发(免弹窗,用户拍板三层机制第一层):
|
||||
// 生成「空车前往装货点(DOCK21)」段(kind=GO_LOAD)并自动下发——空车移动不需人工确认。
|
||||
// AGV 到位后 status=ARRIVED(到位待令),库管在 WMS 叫料队列/MES AGV 页点「确认装车并送货」
|
||||
// 才生成重载运输段(TRANSPORT)发往工位接驳台;卸货点再经「卸货完成并放行」后才空车回充。
|
||||
// 失败仅记日志/预警(best-effort),不阻断叫料完成备料的响应。
|
||||
// DispatchCallAgv 库管人工派车(2026-11-03 定论:废除「备料完成自动派车」):
|
||||
// 库管在 WMS 叫料队列对已发货(SHIPPED)的叫料单点「送货」→ 下发「空车前往装货点」段(GO_LOAD)。
|
||||
// 防重:同一叫料单存在未终态 GO_LOAD 段时拒绝重复派车。
|
||||
func (s *Service) DispatchCallAgv(ctx context.Context, requestNo, operator string) error {
|
||||
mr, err := s.ctx.EntClient.MaterialRequest.Query().
|
||||
Where(materialrequest.RequestNo(requestNo)).Only(ctx)
|
||||
if err != nil || mr == nil {
|
||||
return errors.New("叫料单不存在")
|
||||
}
|
||||
if mr.Status != "SHIPPED" {
|
||||
return errors.New("仅已发货(SHIPPED)的叫料单可派车(请先完成备料)")
|
||||
}
|
||||
if !mr.NeedAgv || mr.TargetDock == "" {
|
||||
return errors.New("该叫料单无需 AGV 配送")
|
||||
}
|
||||
exist, _ := s.ctx.EntClient.AgvTask.Query().
|
||||
Where(agvtask.BizNo(requestNo), agvtask.KindEQ("GO_LOAD"),
|
||||
agvtask.StatusNotIn("9", "5", "FAILED")).Count(ctx)
|
||||
if exist > 0 {
|
||||
return errors.New("该叫料单已派车(存在执行中的空车段),请勿重复派车")
|
||||
}
|
||||
return s.DispatchAgvForCall(ctx, mr, operator)
|
||||
}
|
||||
|
||||
// DispatchAgvForCall 叫料派车(2026-11-03 定论修订:废除自动派车,改为库管人工触发):
|
||||
// 由库管在 WMS 叫料队列点「送货」(DispatchCallAgv)调用——生成「空车前往装货点(JBT21)」段
|
||||
//(kind=GO_LOAD)并下发。AGV 到位后 status=ARRIVED(到位待令),库管点「确认装车并送货」
|
||||
// 才生成重载运输段(TRANSPORT)发往工位接驳台;卸货点再经「卸货完成并放行」后空车回充。
|
||||
// 失败仅记日志/预警(best-effort),不阻断调用方响应。
|
||||
func (s *Service) DispatchAgvForCall(ctx context.Context, mr *ent.MaterialRequest, operator string) error {
|
||||
if mr == nil || !mr.NeedAgv || mr.TargetDock == "" {
|
||||
return nil
|
||||
}
|
||||
// 装货点=库房接驳台 DOCK21;停用禁派(按派车失败口径落预警,由人工改派或恢复接驳台)。
|
||||
// 装货点=库房接驳台 JBT21;停用禁派(按派车失败口径落预警,由人工改派或恢复接驳台)。
|
||||
if d, derr := s.ctx.EntClient.Dock.Query().Where(dock.DockCodeEQ(dockStoreCode)).First(ctx); derr == nil && d != nil && d.Status == "DISABLED" {
|
||||
err := fmt.Errorf("库房接驳台 %s 已停用,自动派车拒绝(请恢复接驳台或人工配送)", dockStoreCode)
|
||||
if alertErr := s.CreateAlert(ctx, "agv_dispatch_fail", "警告", mr.RequestNo,
|
||||
@@ -362,11 +386,15 @@ func (s *Service) RefreshAgvTasks(ctx context.Context) (int, error) {
|
||||
}
|
||||
changed := 0
|
||||
for _, t := range list {
|
||||
st, qerr := s.ctx.Agv.QueryTask(ctx, t.HikTaskCode)
|
||||
st, agvCode, qerr := s.ctx.Agv.QueryTask(ctx, t.HikTaskCode)
|
||||
if qerr != nil {
|
||||
continue
|
||||
}
|
||||
upd := s.ctx.EntClient.AgvTask.UpdateOneID(t.ID)
|
||||
// 2026-11-04 载货台账绑定:RCS 分车后回写 agv_code(空则跳过,不改既有值)
|
||||
if agvCode != "" && agvCode != t.AgvCode {
|
||||
upd.SetAgvCode(agvCode)
|
||||
}
|
||||
switch st {
|
||||
case "9": // 已结束(到位)
|
||||
// 2026-11-03 三层机制:到位后视段类型分流——空车回充段(auto_end)直接结束;
|
||||
@@ -506,7 +534,8 @@ func (s *Service) AgvMode() map[string]any {
|
||||
// ApplyAgvCallback RCS-Lite SPI 回调(文档 2.2.1 任务执行通知):按 taskCode 匹配任务,按 method 更新状态。
|
||||
// method: start 任务开始 / outbin 走出储位 / end 任务结束 / cancel 任务单取消。
|
||||
// RCS 数字状态:1 已创建 / 2 执行中 / 5 取消完成 / 9 已结束。
|
||||
func (s *Service) ApplyAgvCallback(ctx context.Context, taskCode, method string) error {
|
||||
// robotCode(文档 2.2.1 必填 AGV 编号)用于绑定任务与载货台账(2026-11-04 载货状态补做)。
|
||||
func (s *Service) ApplyAgvCallback(ctx context.Context, taskCode, method, robotCode string) error {
|
||||
if taskCode == "" {
|
||||
return errors.New("缺少 taskCode")
|
||||
}
|
||||
@@ -534,6 +563,10 @@ func (s *Service) ApplyAgvCallback(ctx context.Context, taskCode, method string)
|
||||
status = "2"
|
||||
}
|
||||
upd := s.ctx.EntClient.AgvTask.UpdateOneID(t.ID).SetStatus(status)
|
||||
// 2026-11-04 载货台账绑定:回调携带 robotCode 时回写任务 agv_code
|
||||
if robotCode != "" && robotCode != t.AgvCode {
|
||||
upd.SetAgvCode(robotCode)
|
||||
}
|
||||
if arrived {
|
||||
upd.SetArrivedAt(time.Now().Unix())
|
||||
}
|
||||
@@ -584,7 +617,7 @@ func (s *Service) notifyDeliveredOnArrival(ctx context.Context, t *ent.AgvTask)
|
||||
// 确认装车(车背托盘离开装货点)→ 装货点 hasPallet=false;确认卸货(托盘上台)→ 卸货点 hasPallet=true。
|
||||
|
||||
const (
|
||||
dockStoreCode = "DOCK21" // 库房接驳台(装货点/空托盘回收终点)
|
||||
dockStoreCode = "JBT21" // 库房接驳台(装货点/空托盘回收终点;T7 2026-11-03 统一 JBT21)
|
||||
agvChargePoint = "AGV-CHARGE01" // 充电位(seed 纯点位,is_dock=false)
|
||||
)
|
||||
|
||||
@@ -606,6 +639,10 @@ func (s *Service) dispatchAgvSegment(ctx context.Context, in agvSegInput) (strin
|
||||
if in.Target == "" {
|
||||
return "", fmt.Errorf("缺少目标点位")
|
||||
}
|
||||
// 2026-11-04 载货防撞硬拒(B3):AGV 载货=true 且 目标接驳台有托盘(台账/PLC 传感器)→ 拒派
|
||||
if err := s.guardLoadedAgvVsTarget(ctx, in.Target); err != nil {
|
||||
return "", err
|
||||
}
|
||||
taskNo := "AGV" + strings.ToUpper(uuid.NewString()[:10])
|
||||
chain := in.ChainNo
|
||||
if chain == "" {
|
||||
@@ -662,6 +699,8 @@ func (s *Service) ConfirmLoadAndGo(ctx context.Context, taskNo, nextDock, operat
|
||||
}
|
||||
// 装车动作写库:装货点托盘被背走
|
||||
s.setDockPalletByCode(ctx, t.TargetDock, false, "", chainRefOf(t))
|
||||
// 2026-11-04 载货台账(B1):取货确认 → 该车置「有托盘」
|
||||
s.setAgvLoadedState(ctx, t.AgvCode, true, "AUTO_LOAD", operator)
|
||||
// 本段结束
|
||||
s.ctx.EntClient.AgvTask.UpdateOneID(t.ID).SetStatus("9").Exec(ctx)
|
||||
_, derr := s.dispatchAgvSegment(ctx, agvSegInput{
|
||||
@@ -687,6 +726,8 @@ func (s *Service) ConfirmUnloadRelease(ctx context.Context, taskNo, operator str
|
||||
}
|
||||
// 卸货动作写库:托盘上台
|
||||
s.setDockPalletByCode(ctx, t.TargetDock, true, chainRefOf(t), chainRefOf(t))
|
||||
// 2026-11-04 载货台账(B1):卸货确认 → 该车置「空车」
|
||||
s.setAgvLoadedState(ctx, t.AgvCode, false, "AUTO_UNLOAD", operator)
|
||||
s.ctx.EntClient.AgvTask.UpdateOneID(t.ID).SetStatus("9").Exec(ctx)
|
||||
// 出库单回写已送达(CALL 链)
|
||||
if t.BizType == "CALL" {
|
||||
@@ -741,7 +782,9 @@ func (s *Service) FreeDispatch(ctx context.Context, source, target, operator str
|
||||
|
||||
// DispatchPalletRecovery 托盘回收(WMS 托盘工作台触发,业务自动触发免弹窗):
|
||||
// 空车前往指定工位接驳台(GO_LOAD,装货点=有托盘的接驳台)→ 到位待令 → 库管确认装车 →
|
||||
// 运输段送回库房 DOCK21 → 到位待令 → 确认卸货(空托盘上台)→ 空车自动回充。
|
||||
// 运输段送回库房 JBT21 → 到位待令 → 确认卸货(空托盘上台)→ 空车自动回充。
|
||||
// 2026-11-04 定稿(Q5):JBT21 无空位(有托盘/在途任务占用)不派车——拉回来的托盘没地方放,
|
||||
// 前端按钮已禁用,此处后端兜底拒绝。
|
||||
func (s *Service) DispatchPalletRecovery(ctx context.Context, dockCode, operator string) error {
|
||||
d, err := s.ctx.EntClient.Dock.Query().Where(dock.DockCodeEQ(dockCode)).First(ctx)
|
||||
if err != nil || d == nil {
|
||||
@@ -753,6 +796,10 @@ func (s *Service) DispatchPalletRecovery(ctx context.Context, dockCode, operator
|
||||
if !d.HasPallet {
|
||||
return fmt.Errorf("接驳台 %s 台账无托盘,无需回收(请先现场核实)", dockCode)
|
||||
}
|
||||
// JBT21 空位校验(2026-11-04 定稿 Q5):无空位提示并拒绝
|
||||
if free, reason := s.Jbt21Free(ctx); !free {
|
||||
return fmt.Errorf("库房接驳台 %s 暂无空位:%s。请先卸走库房接驳台上的托盘后再派车", dockStoreCode, reason)
|
||||
}
|
||||
_, err = s.dispatchAgvSegment(ctx, agvSegInput{
|
||||
Kind: "GO_LOAD", BizType: "PALLET", BizNo: dockCode,
|
||||
Source: "", Target: dockCode, Operator: operator,
|
||||
|
||||
Reference in New Issue
Block a user