cursor/plans/子任务完成时更新容器位置_cd56e76c.plan.md

59 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: 子任务完成时更新容器位置
overview: 在子任务完成钩子中根据子任务自身类型更新容器位置,调用容器位置绑定/解绑API维护容器与库位关系。
todos: []
---
# 子任务完成时更新容器位置(按子任务类型判定)
## 需求说明
在子任务完成时,根据 **machineTask 的类型** 判定是否更新容器位置:
- **移库子任务**:解绑源库位,绑定目标库位
- **出库子任务**:解绑源库位(并绑定目标库位,若目标库位存在且需落位)
- **入库子任务**:绑定目标库位
## 实现方案
### 1. 修改 `MachineTaskCompletedHook`
**文件**`baoshi-robot/baoshi-robot-core/src/main/java/com/baoshi/robot/core/statemachine/hook/after/MachineTaskCompletedHook.java`
变更点:
- 注入 `CustomLocationContainerRpcApi`
-`execute` 里,当子任务完成时,基于 `machineTask.getType()` 调用位置更新逻辑
- 新增私有方法:
- `updateContainerLocation(MachineTask task)`:根据子任务类型分支
- 入库:只绑定 `targetLocation`
- 出库:解绑 `sourceLocation`,若有 `targetLocation` 且需绑定则绑定
- 移库:解绑 `sourceLocation`,绑定 `targetLocation`
- 封装 DTO 构建与 RPC 调用,异常记日志不影响主流程
### 2. 子任务类型映射
- 移库类:`MachineTaskType.ZS_MOVE`,以及其他明确表示移库的类型(如 HK 系列若存在)
- 出库类:`MachineTaskType.ZS_OUTBOUND`,以及 HK 出库相关类型(如 `HK_PALLET_OUTBOUND_*`、`HK_FIRST_FLOOR_OUTBOUND_WAIT` 等)
- 入库类:`MachineTaskType.ZS_INBOUND``HK_CONVEYOR_INBOUND` 等
### 3. API 调用
- 解绑:`customLocationContainerRpcApi.unbindContainerLocation(containerCode, warehouseId)`
- 绑定:构建 `ContainerBindLocationDTO(warehouseId, dataList[containerCode, locationId])`,调用 `bindContainerLocation`
## 文件变更清单
- 修改:`baoshi-robot/baoshi-robot-core/src/main/java/com/baoshi/robot/core/statemachine/hook/after/MachineTaskCompletedHook.java`
## 流程图
```mermaid
flowchart TD
A[子任务完成] --> B{task.type判定}
B -->|入库| C[绑定 targetLocation]
B -->|出库| D[解绑 sourceLocation]
D --> E{有targetLocation需绑定?}
E -->|是| F[绑定 targetLocation]
E -->|否| H[完成]
B -->|移库| G[