- 客户识别面板两态化:已识别折叠为摘要条 +「修改客户」入口,前端管控复用编辑窗头级谓词 - 新增 rebind_confirmed_customer 链路:守卫→更新 resolution 行→审计→手动重冻结,改后重新生成 Excel - 守卫保证仅在无发货通知/Excel 产物时可改,匹配与门禁零触碰、无失效连锁 - 路由引擎/建单资格/编辑窗服务同步适配,errors 补充改绑错误码四语言 - 同步客户面板测试、确认对话框与四语言文案,落设计与实施计划文档
182 lines
13 KiB
Markdown
182 lines
13 KiB
Markdown
# 确认客户改绑(Customer Rebind)实施计划
|
||
|
||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||
|
||
**Goal:** 已确认订单在产生发货通知/Excel 之前,允许用户在订单复核工作台的客户识别面板上直接修改确认客户(改绑),改后重新冻结快照并重新生成 Excel。
|
||
|
||
**Architecture:** 客户识别面板两态化(未识别=现状流程;已识别=默认折叠摘要条+「修改客户」),前端管控复用编辑窗头级谓词;后端新增 `rebind_confirmed_customer` 一条链(守卫→更新 resolution 行→审计→手动重冻结),匹配/门禁零触碰——守卫保证仅在无 Excel 产物时可改,无失效连锁。
|
||
|
||
**Tech Stack:** Flask + SQLAlchemy 2.0(后端);Vue 3 + TypeScript + Vue I18n 四语言(前端)。
|
||
|
||
**Spec:** `docs/superpowers/specs/2026-10-13-customer-rebind-design.md`
|
||
|
||
## Global Constraints
|
||
|
||
- 🚫 禁止自动 commit;任务以 `git add <具体文件>` 收尾(工作区有他人并行 WIP)。
|
||
- 🌍 前端新增文案四语言(zh-CN/zh-TW/en/th)同步;chat.json 用精确子串编辑,禁 PowerShell 改写。
|
||
- 🧷 冻结契约:`evidence_json` 与 `identity_rule_set_checksum` 必须保持非空(`order_freeze_service._confirmed_ordering_customer` 校验,:274-287);`freeze_order_snapshot(mode='manual')` 必须传 `actor_id`。
|
||
- ⚠️ 匹配/门禁状态零改动:本能力不触碰 `export.py`、`post_ot_fulfillment_wave_service.py`、门禁 gate 行。
|
||
- 📝 新函数含 Args/Returns docstring;测试有断言意图注释(§5.4)。
|
||
- 后端测试:`cd backend && ./.venv/Scripts/python.exe -m pytest <file> -q`;前端 vitest 可用 + `npm run build`。
|
||
|
||
---
|
||
|
||
### Task 1: 后端改绑服务 + API
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/shipping_notice/customer_resolution_service.py`(新增 `rebind_confirmed_customer`)
|
||
- Modify: `backend/app/api/workspace/shipping_notice.py`(新增 rebind 端点,模式对齐同文件 `order-review-cases/<case_no>/line-fulfillment/decide` 路由 :2163-2194)
|
||
- Test: `backend/tests/test_customer_resolution_rebind.py`(新建;夹具对齐既有客户确认相关测试的构造,执行者按文件内/相邻测试文件现状取用)
|
||
|
||
**Interfaces:**
|
||
- Consumes: `resolution_for_task(task)`(本服务既有);`editable_scope(order_task)['header']`(`order_edit_window_service.py:121`);`freeze_order_snapshot(task, actor_id, expected_order_data_version, freeze_mode='manual')`(`order_freeze_service.py`)。
|
||
- Produces: `rebind_confirmed_customer(*, task, new_customer_id, actor_id, reason=None) -> dict`(返回 {'resolution': 行, 'snapshot': 重冻结快照});API `POST .../order-review-cases/<case_no>/customer/rebind`。
|
||
|
||
- [ ] **Step 1: 写失败测试**
|
||
|
||
```python
|
||
def test_rebind_updates_confirmed_customer_and_refreezes_snapshot():
|
||
"""改绑必须更新确认结果并按新客户重冻结快照(客户 ODM 白名单随新客户生效)。"""
|
||
# 夹具:已确认 resolution(status='confirmed', confirmed_customer_id=旧客户, evidence_json 非空)
|
||
# + 已冻结快照 + 无 Export Artifact/无活动 Attempt(editable_scope.header=True)。
|
||
result = rebind_confirmed_customer(
|
||
task=task, new_customer_id=int(new_customer.id), actor_id=int(user.id), reason='选错客户',
|
||
)
|
||
# 断言意图:确认结果与快照客户同步改绑;审计与 evidence_json 记录原客户(可追溯)。
|
||
assert result['resolution'].confirmed_customer_id == int(new_customer.id)
|
||
assert result['snapshot'].customer_id == int(new_customer.id)
|
||
assert result['resolution'].evidence_json['rebind']['previous_customer_id'] == int(old_customer.id)
|
||
assert result['resolution'].identity_rule_set_checksum # 冻结契约:保持非空
|
||
|
||
|
||
def test_rebind_rejects_when_export_artifact_exists():
|
||
"""已产生 Excel(header 不可编辑)时改绑必须 409,且确认结果不被改动。"""
|
||
# 夹具:同上,但给任一通知造 Export Artifact(对齐既有 artifact 测试构造)。
|
||
with pytest.raises(ConflictError) as exc:
|
||
rebind_confirmed_customer(task=task, new_customer_id=int(new_customer.id), actor_id=int(user.id))
|
||
# 断言意图:A 管控 fail-closed;错误码可前端定位。
|
||
assert exc.value.code == 'SHIPPING.CUSTOMER_REBIND_BLOCKED'
|
||
assert resolution_row.confirmed_customer_id == int(old_customer.id)
|
||
|
||
|
||
def test_rebind_rejects_same_customer_and_unknown_customer():
|
||
"""同客户重复改绑与不存在/停用客户都必须 409/404,不产生副作用。"""
|
||
```
|
||
|
||
(夹具构造对齐仓库内既有客户确认测试;断言语义以三段注释为准。)
|
||
|
||
- [ ] **Step 2: 确认失败**
|
||
|
||
Run: `cd backend && ./.venv/Scripts/python.exe -m pytest tests/test_customer_resolution_rebind.py -q`
|
||
Expected: FAIL(函数不存在)
|
||
|
||
- [ ] **Step 3: 实现**
|
||
|
||
`rebind_confirmed_customer` 顺序:
|
||
1. `resolution = resolution_for_task(task)`;`status != 'confirmed'` → ConflictError(提示走识别确认流程)。
|
||
2. `editable_scope(task)['header']` 非 True → ConflictError `SHIPPING.CUSTOMER_REBIND_BLOCKED`(details 标注 excel_exists / active_attempt)。
|
||
3. 新客户存在且启用(ShippingCustomer 查询)且 ≠ `resolution.confirmed_customer_id`,否则 404/409。
|
||
4. `previous = resolution.confirmed_customer_id`;更新 id;`evidence_json = {**evidence_json, 'rebind': {...previous, new, actor_id, reason, utcnow}}`;flush。
|
||
5. 审计(事件类型对齐 `progress_audit_contract` 既有集合,执行者核对后选用;before/after 客户 + reason)。
|
||
6. `freeze_order_snapshot(task, actor_id=actor_id, expected_order_data_version=int(task.order_data_version or 1), freeze_mode='manual')`;返回 resolution + 新快照。
|
||
|
||
API 端点:校验登录与 case 归属(对齐 decide 端点的守卫风格),`actor_id` 取当前用户,调用服务,返回刷新 case 投影(复用既有序列化 helper)。
|
||
|
||
- [ ] **Step 4: 确认通过 + 回归**
|
||
|
||
```bash
|
||
cd backend && ./.venv/Scripts/python.exe -m pytest tests/test_customer_resolution_rebind.py tests/test_shipping_notice_ui_state.py -q
|
||
```
|
||
(ui_state 已知基线失败 2 个不算。)另跑一个冻结相关套件确认零回归:`pytest tests/test_shipping_order_edit_window.py -q`。
|
||
|
||
- [ ] **Step 5: Stage**
|
||
|
||
```bash
|
||
git add backend/app/services/shipping_notice/customer_resolution_service.py backend/app/api/workspace/shipping_notice.py backend/tests/test_customer_resolution_rebind.py
|
||
```
|
||
|
||
---
|
||
|
||
### Task 2: 前端面板两态化 + 修改客户弹窗
|
||
|
||
**Files:**
|
||
- Modify: `frontend/src/features/chat/components/shipping-review/ReviewCustomerResolutionPanel.vue`(两态化:resolved → 折叠摘要条;新增修改客户流程,复用既有 `searchCustomers` 与客户选择组件)
|
||
- Modify: `frontend/src/features/chat/views/ShippingOrderReviewView.vue`(面板 props:传入 `:rebind-allowed`(`formalEditWindow?.header === true`,:466 formalEditWindow)与禁用原因;渲染条件 `v-if="!activeCase.customer_resolution?.resolved"` 改为始终渲染并交由面板内部分态)
|
||
- Modify: `frontend/src/features/chat/api/shipping.api.ts`(新增 `rebindWorkspaceShippingOrderReviewCustomer(caseNo, { customer_id, reason })`)
|
||
- Modify: `frontend/src/locales/{zh-CN,zh-TW,en,th}/chat.json`(新键,见 Task 3)
|
||
- Test: `frontend/src/features/chat/components/shipping-review/ReviewCustomerResolutionPanel.spec.ts`(新建/扩展,对齐既有面板 spec 写法)
|
||
|
||
**Interfaces:**
|
||
- Consumes: Task 1 API;`formalEditWindow`(view :466);面板既有 `searchCustomers`(:111)与 `refreshed` emit。
|
||
- Produces: 面板 props `rebindAllowed: boolean`;emit `refreshed`(复用)。
|
||
|
||
- [ ] **Step 1: spec 断言先行**
|
||
|
||
```typescript
|
||
// 断言意图:已识别态默认折叠为摘要条(状态徽标+客户名),不默认展开详情;
|
||
// 「修改客户」按钮在 rebindAllowed=false 时禁用。
|
||
it('renders collapsed summary with customer name when resolved', ...)
|
||
it('disables rebind button when rebindAllowed is false and shows reason', ...)
|
||
it('submits rebind with selected customer and emits refreshed', ...)
|
||
```
|
||
|
||
(按该文件/相邻面板 spec 的 mount 与查询写法落地;先跑确认失败。)
|
||
|
||
- [ ] **Step 2: 实现面板两态**
|
||
|
||
- `resolved=true`:渲染折叠条——`已确认` 徽标 + `resolution` 中的标准客户名(现有字段)+ chevron(展开显示既有识别详情,**无 ODM 范围**)+ 「修改客户」按钮(`:disabled="!rebindAllowed"` + tooltip 用禁用原因 i18n 键)。
|
||
- 修改客户流程:打开复用的客户搜索选择(`searchCustomers`)→ 选定 → 影响确认弹窗(i18n 文案见 Task 3)→ `rebindWorkspaceShippingOrderReviewCustomer` → 成功 toast("客户已更新,可回通知准备重新生成 Excel")→ `emit('refreshed')`。
|
||
- `resolved=false`:原样。
|
||
|
||
- [ ] **Step 3: 视图接线**
|
||
|
||
`ShippingOrderReviewView.vue:6008` 的 `v-if` 改为始终渲染该面板(resolved 与否由面板分态);补 props `:rebind-allowed="formalEditWindow?.header === true"`;`@refreshed="handleReviewGateDataRefreshed"` 既有。
|
||
|
||
- [ ] **Step 4: 验收**
|
||
|
||
```bash
|
||
cd frontend && npx vitest run src/features/chat/components/shipping-review/ && npm run build
|
||
```
|
||
|
||
- [ ] **Step 5: Stage**
|
||
|
||
```bash
|
||
git add frontend/src/features/chat/components/shipping-review/ReviewCustomerResolutionPanel.vue frontend/src/features/chat/components/shipping-review/ReviewCustomerResolutionPanel.spec.ts frontend/src/features/chat/views/ShippingOrderReviewView.vue frontend/src/features/chat/api/shipping.api.ts frontend/src/locales/zh-CN/chat.json frontend/src/locales/zh-TW/chat.json frontend/src/locales/en/chat.json frontend/src/locales/th/chat.json
|
||
```
|
||
|
||
---
|
||
|
||
### Task 3: i18n 四语言
|
||
|
||
**Files:**
|
||
- Modify: 四语言 `chat.json` 的 `shippingOrderReview` 域内(建议 `customerResolution` 邻近块)
|
||
|
||
**Interfaces:** Produces 键:`rebindButton`(修改客户)、`rebindDisabledExcelExists`(禁用原因)、`rebindConfirmTitle`、`rebindConfirmImpact`、`rebindSuccessToast`(文案含"可回通知准备重新生成 Excel")、`rebindFailedToast`。
|
||
|
||
- [ ] 四语言值:
|
||
|
||
| 键 | zh-CN | zh-TW | en | th |
|
||
| --- | --- | --- | --- | --- |
|
||
| rebindButton | 修改客户 | 修改客戶 | Change customer | เปลี่ยนลูกค้า |
|
||
| rebindDisabledExcelExists | 已产生发货通知/Excel,请先走撤销流程 | 已產生發貨通知/Excel,請先走撤銷流程 | Notice/Excel already generated — undo it first | มีการแจ้งเตือน/Excel แล้ว โปรดยกเลิกก่อน |
|
||
| rebindConfirmTitle | 确认修改客户 | 確認修改客戶 | Confirm customer change | ยืนยันการเปลี่ยนลูกค้า |
|
||
| rebindConfirmImpact | 将更新订单客户并重新冻结订单快照;已生成的发货通知/Excel 需重新生成 | 將更新訂單客戶並重新凍結訂單快照;已產生的發貨通知/Excel 需重新生成 | The order customer will be updated and the snapshot re-frozen; generated notice/Excel must be regenerated | ลูกค้าจะถูกอัปเดตและ snapshot จะถูก freeze ใหม่ |
|
||
| rebindSuccessToast | 客户已更新,可回通知准备重新生成 Excel | 客戶已更新,可回通知準備重新產生 Excel | Customer updated — regenerate the Excel in notice preparation | อัปเดตลูกค้าแล้ว สร้าง Excel ใหม่ได้ |
|
||
| rebindFailedToast | 客户修改失败 | 客戶修改失敗 | Failed to change customer | เปลี่ยนลูกค้าไม่สำเร็จ |
|
||
|
||
- [ ] JSON 合法性校验(node 解析四文件);`git add` 四文件。
|
||
|
||
---
|
||
|
||
### Task 4: 文档 + 回归
|
||
|
||
- [ ] `docs/features/shipping-notice/technical.md` 文末追加「确认客户改绑(2026-10-13)」(守卫/链路/边界备忘——已放行证据不重算);`docs/funclist.md` 加 1 行。
|
||
- [ ] 回归:后端 `pytest tests/test_customer_resolution_rebind.py tests/test_shipping_order_edit_window.py tests/test_shipping_notice_ui_state.py -q`(ui_state 2 个基线失败除外);前端 vitest 面板 spec + `npm run build`。
|
||
- [ ] 人工冒烟:本地复现单(SORC-336EB5E5D6D84CBE)——折叠条显示;客户 15 补 ODM 或改绑到维护了 581 的客户;回通知准备重新生成 Excel 成功。
|
||
|
||
## Self-Review
|
||
|
||
- 规格覆盖:两态化/折叠/无 ODM 展示 → Task 2;管控 A → Task 1 守卫 + Task 2 按钮禁用;改绑链 → Task 1;审计/追溯 → Step 3.5;边界 → spec §4 + Task 4 文档。
|
||
- 占位符:夹具构造与事件类型对齐项已给出现有锚点(文件:行)与断言语义,属执行者对齐指引。
|
||
- 类型一致:`rebind_confirmed_customer` 签名、API 路径、`rebindAllowed` prop、i18n 键名前后一致。
|