feat(shipping-notice): 添加订单文档 Profile 盲测集和样本管理功能,支持创建、执行和批准盲测,增强订单冻结和库存核验功能
This commit is contained in:
1 parent
c35223d49d
commit
abd8fc1e16
98 files changed
+4629
-528
No files matched your search
@@ -3,7 +3,7 @@
|
||||
* 用途:验证建批 Chat Turn payload 包含幂等键与会话映射。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildShippingCreateBatchFromIntakesTurn, buildShippingCreateBatchTurn } from './shippingTurnActions';
|
||||
import { buildShippingCreateBatchFromIntakesTurn, buildShippingCreateBatchTurn, resolveShippingChatTurn } from './shippingTurnActions';
|
||||
|
||||
describe('shippingTurnActions', () => {
|
||||
it('buildShippingCreateBatchTurn includes idempotency_key in payload', () => {
|
||||
@@ -32,4 +32,12 @@ describe('shippingTurnActions', () => {
|
||||
expect(turn.payload.intake_nos).toEqual(['SNI-001']);
|
||||
expect(turn.payload.candidate_nos).toEqual(['SNC-001', 'SNC-003']);
|
||||
});
|
||||
|
||||
it('maps freeze_order only with the version shown to the user', () => {
|
||||
expect(resolveShippingChatTurn('freeze_order', 'sn-freeze-001')).toBeNull();
|
||||
expect(resolveShippingChatTurn('freeze_order', 'sn-freeze-001', { expectedOrderDataVersion: 7 })).toEqual({
|
||||
actionType: 'shipping.freeze_order',
|
||||
payload: { task_no: 'SN-FREEZE-001', expected_order_data_version: 7 },
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -21,7 +21,7 @@ export interface ShippingChatTurnSpec {
|
||||
export function resolveShippingChatTurn(
|
||||
actionId: string,
|
||||
taskNo: string,
|
||||
extra?: { sourceCode?: string },
|
||||
extra?: { sourceCode?: string; expectedOrderDataVersion?: number },
|
||||
): ShippingChatTurnSpec | null {
|
||||
const normalizedTaskNo = String(taskNo || '').trim().toUpperCase();
|
||||
if (!normalizedTaskNo) return null;
|
||||
@@ -36,6 +36,16 @@ export function resolveShippingChatTurn(
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case 'freeze_order':
|
||||
const expectedOrderDataVersion = extra?.expectedOrderDataVersion;
|
||||
if (!Number.isInteger(expectedOrderDataVersion) || !expectedOrderDataVersion || expectedOrderDataVersion < 1) return null;
|
||||
return {
|
||||
actionType: 'shipping.freeze_order',
|
||||
payload: {
|
||||
task_no: normalizedTaskNo,
|
||||
expected_order_data_version: expectedOrderDataVersion,
|
||||
},
|
||||
};
|
||||
case 'generate_excel':
|
||||
return { actionType: 'shipping.generate_excel', payload: { task_no: normalizedTaskNo } };
|
||||
case 'retry_upload':
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
import { buildShippingSubmitDecisionTurn, buildShippingTurnRefs } from './shippingTurnActions';
|
||||
import { reportShippingDebugEvent } from './shippingDebugReporter';
|
||||
import { uploadFileAsset } from '@/shared/api/file-assets.api';
|
||||
import type { StartChatTurnOptions } from '../types/chat-turn.types';
|
||||
import type { ChatMessage, ChatSessionItem } from '../types/chat.types';
|
||||
import type { ComputedRef, Ref } from 'vue';
|
||||
@@ -57,6 +58,30 @@ export function createShippingDecisionHandlers(ctx: ShippingDecisionContext) {
|
||||
void ctx.refreshShippingActions();
|
||||
};
|
||||
|
||||
/**
|
||||
* 在 Chat 操作中选择并上传人工货代回执,返回当前用户私有的 FileAsset 编号。
|
||||
* 取消选择不会提交“已手工上传”动作,确保后端的证据门禁没有绕过路径。
|
||||
*/
|
||||
const selectManualUploadEvidence = () => new Promise<File | null>((resolve) => {
|
||||
const picker = document.createElement('input');
|
||||
picker.type = 'file';
|
||||
picker.accept = 'image/*,.pdf';
|
||||
picker.style.display = 'none';
|
||||
document.body.appendChild(picker);
|
||||
let settled = false;
|
||||
const finish = (file: File | null) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
picker.remove();
|
||||
resolve(file);
|
||||
};
|
||||
picker.addEventListener('change', () => finish(picker.files?.[0] || null), { once: true });
|
||||
picker.addEventListener('cancel', () => finish(null), { once: true });
|
||||
// 部分浏览器不会触发 cancel;窗口重新获得焦点后仍未选择文件即视为取消。
|
||||
window.addEventListener('focus', () => setTimeout(() => finish(picker.files?.[0] || null), 0), { once: true });
|
||||
picker.click();
|
||||
});
|
||||
|
||||
/**
|
||||
* 提交发货人工决策,经 Chat Turn 统一 SSE 返回。
|
||||
*/
|
||||
@@ -108,12 +133,18 @@ export function createShippingDecisionHandlers(ctx: ShippingDecisionContext) {
|
||||
manualUploadInFlightTaskIds.add(normalizedTaskId);
|
||||
const userText = (displayText || '我已在货代系统完成上传').trim();
|
||||
try {
|
||||
const evidenceFile = await selectManualUploadEvidence();
|
||||
if (!evidenceFile) {
|
||||
ctx.msg.warning('请先选择货代上传截图或回执文件');
|
||||
return false;
|
||||
}
|
||||
const evidence = await uploadFileAsset(evidenceFile);
|
||||
const ok = await ctx.startChatTurn({
|
||||
agentId: ctx.currentAgentId.value,
|
||||
inputType: 'action',
|
||||
displayText: userText,
|
||||
actionType: 'shipping.mark_manual_uploaded',
|
||||
payload: { task_no: normalizedTaskId },
|
||||
payload: { task_no: normalizedTaskId, evidence_asset_no: evidence.asset_no },
|
||||
refs: buildShippingTurnRefs(normalizedTaskId, ctx.getActiveShippingBatchNo()),
|
||||
hooks: {
|
||||
onAssistantMessageFinished: async (assistantMsg) => {
|
||||
|
||||
@@ -101,6 +101,23 @@ describe('useChatShippingMenuHandler', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('reads the displayed order version before freezing through Chat Turn', async () => {
|
||||
getWorkspaceShippingTask.mockResolvedValue({ order_data_version: 9 });
|
||||
const ctx = createContext();
|
||||
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
||||
|
||||
await handleShippingMenuAction(
|
||||
{ id: 'freeze_order', label: '冻结订单', message: '冻结已复核订单' },
|
||||
undefined,
|
||||
{ taskId: 'sn-freeze-901' },
|
||||
);
|
||||
|
||||
expect(ctx.startChatTurn).toHaveBeenCalledWith(expect.objectContaining({
|
||||
actionType: 'shipping.freeze_order',
|
||||
payload: { task_no: 'SN-FREEZE-901', expected_order_data_version: 9 },
|
||||
}));
|
||||
});
|
||||
|
||||
it('passes explicit taskId into inventory picker actions', async () => {
|
||||
const ctx = createContext();
|
||||
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
|
||||
|
||||
@@ -90,7 +90,7 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
const runShippingActionTurn = async (
|
||||
action: ShippingActionButton | { id?: string; message: string; label?: string },
|
||||
taskId: string,
|
||||
extra?: { sourceCode?: string },
|
||||
extra?: { sourceCode?: string; expectedOrderDataVersion?: number },
|
||||
) => {
|
||||
const actionId = String(action.id || '').trim();
|
||||
const turnSpec = resolveShippingChatTurn(actionId, taskId, extra);
|
||||
@@ -153,6 +153,7 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
}
|
||||
|
||||
const chatTurnActionIds = new Set([
|
||||
'freeze_order',
|
||||
'generate_excel',
|
||||
'retry_upload',
|
||||
'match_inventory',
|
||||
@@ -171,6 +172,17 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
}
|
||||
try {
|
||||
let sourceCode = '';
|
||||
let expectedOrderDataVersion: number | undefined;
|
||||
if (action.id === 'freeze_order') {
|
||||
const detail = await getWorkspaceShippingTask(taskId);
|
||||
const version = Number(detail.order_data_version);
|
||||
if (!Number.isInteger(version) || version < 1) {
|
||||
ctx.msg.warning(ctx.t('chat.shippingNoticeRefreshRequired'));
|
||||
if (chatMsg) chatMsg.shipping_actions_used = false;
|
||||
return;
|
||||
}
|
||||
expectedOrderDataVersion = version;
|
||||
}
|
||||
if (action.id === 'confirm_inventory_source') {
|
||||
sourceCode = String((action as { source_code?: unknown }).source_code || '').trim().toUpperCase();
|
||||
if (!sourceCode) {
|
||||
@@ -193,7 +205,7 @@ export function createShippingMenuHandlers(ctx: ShippingMenuHandlerContext) {
|
||||
await runShippingActionTurn(
|
||||
{ ...action, message: displayMessage },
|
||||
taskId,
|
||||
sourceCode ? { sourceCode } : undefined,
|
||||
sourceCode ? { sourceCode } : { expectedOrderDataVersion },
|
||||
);
|
||||
} catch (e: unknown) {
|
||||
ctx.msg.warning(e instanceof Error ? e.message : '操作失败');
|
||||
|
||||
Reference in new issue
Block a user