feat(shipping_notice): 新增货代订单全流程业务模块及配套基建
本次提交新增货代订单处理全流程的完整业务能力、数据库迁移与测试用例: 1. 统一追加式审计事件体系,支持全链路不可篡改的业务追溯 2. 货代任务撤销、版本替代管控逻辑,规范已上传订单的合规版本更替 3. 订单抽取路由审计、模板自动冻结资格、路由计数等核心业务基建 4. EML订单补充表解析契约与合并逻辑,完善订单补全能力 5. Chatflow只读能力令牌校验机制,保障工具调用安全 6. 人工复核证据校验服务,规范人工审核的证据留存 所有变更均配套完整的单元测试与迁移契约测试,支持受控回退
This commit is contained in:
1 parent
90f77634d6
commit
1f3ecb87b7
128 files changed
+3635
-2074
No files matched your search
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* features/chat/api/chat.api.spec.ts
|
||||
* 用途:验证聊天历史接口适配层不会在 hydrate 过程中丢失用户附件快照。
|
||||
* 依赖:Vitest、mock 后的 shared/api/client 与 auth、chat.api。
|
||||
* 逻辑:覆盖历史消息过滤 shipping-parse-review、恢复订单识别状态时仍保留 attachments。
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { listChatMessages } from './chat.api';
|
||||
|
||||
vi.mock('@/shared/utils/auth', () => ({
|
||||
getAuthHeaders: vi.fn(() => ({ Authorization: 'Bearer test-token' })),
|
||||
}));
|
||||
|
||||
vi.mock('@/shared/api/client', () => ({
|
||||
requestJson: vi.fn(),
|
||||
}));
|
||||
|
||||
import { requestJson } from '@/shared/api/client';
|
||||
|
||||
const requestJsonMock = vi.mocked(requestJson);
|
||||
|
||||
describe('chat.api history hydration', () => {
|
||||
beforeEach(() => {
|
||||
requestJsonMock.mockReset();
|
||||
});
|
||||
|
||||
it('keeps user attachment snapshots while hydrating persisted assistant payload', async () => {
|
||||
requestJsonMock.mockResolvedValue([
|
||||
{
|
||||
role: 'user',
|
||||
content: '',
|
||||
attachments: [{
|
||||
id: 'attachment-only-1',
|
||||
name: 'notice.eml',
|
||||
type: 'document',
|
||||
source: 'shipping_notice',
|
||||
}],
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: '中间态消息',
|
||||
type: 'shipping-parse-review',
|
||||
},
|
||||
{
|
||||
role: 'assistant',
|
||||
content: '订单识别完成',
|
||||
payload: {
|
||||
shipping_order_extraction_state: {
|
||||
status: 'completed',
|
||||
phase: 'result_persisted',
|
||||
message: '已创建 1 个任务',
|
||||
created_count: 1,
|
||||
opened_existing_count: 0,
|
||||
pending_count: 0,
|
||||
non_shipping_count: 0,
|
||||
created_with_missing_fields_count: 0,
|
||||
batch_no: 'SB-HISTORY-001',
|
||||
terminal: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const messages = await listChatMessages('conv-history-1', 24);
|
||||
|
||||
expect(requestJsonMock).toHaveBeenCalledWith(
|
||||
'/api/chat/messages?conversation_id=conv-history-1&agent_id=24',
|
||||
{ headers: { Authorization: 'Bearer test-token' } },
|
||||
);
|
||||
expect(messages).toHaveLength(2);
|
||||
expect(messages[0]).toEqual({
|
||||
role: 'user',
|
||||
content: '',
|
||||
attachments: [{
|
||||
id: 'attachment-only-1',
|
||||
name: 'notice.eml',
|
||||
type: 'document',
|
||||
source: 'shipping_notice',
|
||||
}],
|
||||
});
|
||||
expect(messages[1]?.shipping_order_extraction_state).toMatchObject({
|
||||
status: 'completed',
|
||||
batch_no: 'SB-HISTORY-001',
|
||||
terminal: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -422,6 +422,11 @@ export async function submitWorkspaceShippingDecision(taskNo: string, decision:
|
||||
return assertShippingOk(body);
|
||||
}
|
||||
|
||||
/** 人工复核证据只允许已绑定文档单元格或具名人工输入。 */
|
||||
export type ShippingReviewEvidence =
|
||||
| { evidence_type: 'document_cell'; document_id: number; observation_id: number; page_no: number; table_id: string; cell_id: string }
|
||||
| { evidence_type: 'manual_input'; reason: string };
|
||||
|
||||
/**
|
||||
* 更新发货通知单头字段。
|
||||
* @param taskNo - 发货任务编号
|
||||
@@ -432,18 +437,18 @@ export async function submitWorkspaceShippingDecision(taskNo: string, decision:
|
||||
export async function updateWorkspaceShippingNoticeFields(
|
||||
taskNo: string,
|
||||
fields: Partial<ShippingNoticeHeader>,
|
||||
comment?: string,
|
||||
options?: { expectedOrderDataVersion?: number; idempotencyKey?: string },
|
||||
comment: string | undefined,
|
||||
options: { expectedOrderDataVersion: number; idempotencyKey?: string; evidence: ShippingReviewEvidence; reason: string },
|
||||
) {
|
||||
const body = await requestJson<ShippingDecisionResponse & ShippingApiStatusPayload>(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/update-notice-fields`,
|
||||
jsonPost({
|
||||
fields,
|
||||
...(comment ? { comment } : {}),
|
||||
...(options?.expectedOrderDataVersion != null
|
||||
? { expected_order_data_version: options.expectedOrderDataVersion }
|
||||
: {}),
|
||||
...(options?.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}),
|
||||
expected_order_data_version: options.expectedOrderDataVersion,
|
||||
evidence: options.evidence,
|
||||
reason: options.reason,
|
||||
...(options.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}),
|
||||
}),
|
||||
);
|
||||
return assertShippingOk(body);
|
||||
@@ -479,8 +484,8 @@ export async function updateWorkspaceShippingNoticeLine(
|
||||
taskNo: string,
|
||||
lineIndex: number,
|
||||
patch: Partial<ShippingNoticeLine> & { quantity?: number },
|
||||
comment?: string,
|
||||
options?: { expectedOrderDataVersion?: number; idempotencyKey?: string },
|
||||
comment: string | undefined,
|
||||
options: { expectedOrderDataVersion: number; idempotencyKey?: string; evidence: ShippingReviewEvidence; reason: string },
|
||||
) {
|
||||
const body = await requestJson<ShippingDecisionResponse & ShippingApiStatusPayload>(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/update-notice-line`,
|
||||
@@ -488,10 +493,10 @@ export async function updateWorkspaceShippingNoticeLine(
|
||||
line_index: lineIndex,
|
||||
patch,
|
||||
...(comment ? { comment } : {}),
|
||||
...(options?.expectedOrderDataVersion != null
|
||||
? { expected_order_data_version: options.expectedOrderDataVersion }
|
||||
: {}),
|
||||
...(options?.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}),
|
||||
expected_order_data_version: options.expectedOrderDataVersion,
|
||||
evidence: options.evidence,
|
||||
reason: options.reason,
|
||||
...(options.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}),
|
||||
}),
|
||||
);
|
||||
return assertShippingOk(body);
|
||||
@@ -522,6 +527,7 @@ export async function resolveWorkspaceShippingFieldConflict(
|
||||
expectedConflictVersion?: number;
|
||||
expectedOrderDataVersion?: number;
|
||||
reason?: string;
|
||||
evidence: ShippingReviewEvidence;
|
||||
idempotencyKey?: string;
|
||||
},
|
||||
) {
|
||||
@@ -542,6 +548,7 @@ export async function resolveWorkspaceShippingFieldConflict(
|
||||
? { expected_order_data_version: payload.expectedOrderDataVersion }
|
||||
: {}),
|
||||
...(payload.reason ? { reason: payload.reason } : {}),
|
||||
evidence: payload.evidence,
|
||||
...(payload.idempotencyKey ? { idempotency_key: payload.idempotencyKey } : {}),
|
||||
}),
|
||||
);
|
||||
@@ -557,11 +564,12 @@ export async function resolveWorkspaceShippingFieldConflict(
|
||||
export async function addWorkspaceShippingNoticeLine(
|
||||
taskNo: string,
|
||||
line: Partial<ShippingNoticeLine> & { quantity?: number },
|
||||
comment?: string,
|
||||
comment: string | undefined,
|
||||
options: { expectedOrderDataVersion: number; idempotencyKey?: string; evidence: ShippingReviewEvidence; reason: string },
|
||||
) {
|
||||
const body = await requestJson<ShippingDecisionResponse & ShippingApiStatusPayload>(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/add-notice-line`,
|
||||
jsonPost({ line, ...(comment ? { comment } : {}) }),
|
||||
jsonPost({ line, ...(comment ? { comment } : {}), expected_order_data_version: options.expectedOrderDataVersion, evidence: options.evidence, reason: options.reason, ...(options.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}) }),
|
||||
);
|
||||
return assertShippingOk(body);
|
||||
}
|
||||
@@ -576,11 +584,12 @@ export async function addWorkspaceShippingNoticeLine(
|
||||
export async function removeWorkspaceShippingNoticeLine(
|
||||
taskNo: string,
|
||||
lineIndex: number,
|
||||
comment?: string,
|
||||
comment: string | undefined,
|
||||
options: { expectedOrderDataVersion: number; idempotencyKey?: string; evidence: ShippingReviewEvidence; reason: string },
|
||||
) {
|
||||
const body = await requestJson<ShippingDecisionResponse & ShippingApiStatusPayload>(
|
||||
`/api/workspace/shipping-tasks/${encodeURIComponent(taskNo)}/remove-notice-line`,
|
||||
jsonPost({ line_index: lineIndex, ...(comment ? { comment } : {}) }),
|
||||
jsonPost({ line_index: lineIndex, ...(comment ? { comment } : {}), expected_order_data_version: options.expectedOrderDataVersion, evidence: options.evidence, reason: options.reason, ...(options.idempotencyKey ? { idempotency_key: options.idempotencyKey } : {}) }),
|
||||
);
|
||||
return assertShippingOk(body);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user