feat(chat): 优化发货相关消息处理逻辑
- 在列出聊天消息时,过滤掉类型为'shipping-parse-review'的消息 - 移除不再使用的shippingConversationTaskIdCache - 更新发货决策处理逻辑,简化保存消息的参数 - 添加发货动作按钮刷新时的任务定位优先级逻辑 - 移除解析复核消息的展示逻辑,统一处理到轻量工作台 - 增加单元测试,验证发货动作按钮刷新时的任务定位优先级
This commit is contained in:
1 parent
9f5493185d
commit
6a0a51313f
18 files changed
+1230
-199
No files matched your search
@@ -6,8 +6,6 @@
|
||||
*/
|
||||
import {
|
||||
addWorkspaceShippingNoticeLine,
|
||||
getShippingChatActions,
|
||||
getWorkspaceShippingTask,
|
||||
removeWorkspaceShippingNoticeLine,
|
||||
updateWorkspaceShippingNoticeFields,
|
||||
updateWorkspaceShippingNoticeLine,
|
||||
@@ -16,7 +14,6 @@ import {
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { getShippingParseReviewPayload } from './shippingParseReview';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ShippingParseReviewPayload } from '../types/shipping.types';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
export interface ShippingParseReviewContext {
|
||||
@@ -28,27 +25,6 @@ export interface ShippingParseReviewContext {
|
||||
msg: { warning: (text: string) => void };
|
||||
}
|
||||
|
||||
/** 由任务详情与 checkpoint 构建 parse_review 卡片 payload。 */
|
||||
function buildParseReviewPayload(
|
||||
taskId: string,
|
||||
detail: Awaited<ReturnType<typeof getWorkspaceShippingTask>>,
|
||||
checkpoint: string,
|
||||
): ShippingParseReviewPayload {
|
||||
return {
|
||||
taskId,
|
||||
checkpoint,
|
||||
header: {
|
||||
customer_name: detail.customer_name ?? null,
|
||||
customer_code: detail.customer_code ?? null,
|
||||
ship_to: detail.ship_to ?? null,
|
||||
po_number: detail.po_number ?? null,
|
||||
required_date: detail.required_date ?? null,
|
||||
},
|
||||
lines: Array.isArray(detail.lines) ? detail.lines : [],
|
||||
saving: false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发货通知 parse review 卡片处理器。
|
||||
*
|
||||
@@ -70,48 +46,12 @@ export function createShippingParseReviewHandlers(ctx: ShippingParseReviewContex
|
||||
}
|
||||
};
|
||||
|
||||
const upsertParseReviewMessage = async (payload: ShippingParseReviewPayload) => {
|
||||
const normalized = String(payload.taskId || '').trim().toUpperCase();
|
||||
const existing = ctx.messages.value.find((msg) => {
|
||||
const current = getShippingParseReviewPayload(msg);
|
||||
return current?.taskId?.trim().toUpperCase() === normalized;
|
||||
});
|
||||
if (existing) {
|
||||
existing.content = `请确认或修订以下解析结果。\n任务编号:${normalized}`;
|
||||
existing.payload = payload;
|
||||
existing.local_only = true;
|
||||
return;
|
||||
}
|
||||
const reviewMsg: ChatMessage = {
|
||||
role: 'assistant',
|
||||
type: 'shipping-parse-review',
|
||||
content: `请确认或修订以下解析结果。\n任务编号:${normalized}`,
|
||||
payload,
|
||||
local_id: ctx.newLocalMessageId('shipping-parse-review'),
|
||||
local_only: true,
|
||||
};
|
||||
ctx.messages.value.push(reviewMsg);
|
||||
await ctx.saveLocalMessageToBackend(reviewMsg);
|
||||
};
|
||||
|
||||
const syncShippingParseReviewCard = async (taskId?: string): Promise<boolean> => {
|
||||
const normalized = String(taskId || ctx.resolvedShippingTaskId.value || '').trim().toUpperCase();
|
||||
if (!normalized) return false;
|
||||
try {
|
||||
const [detail, actions] = await Promise.all([
|
||||
getWorkspaceShippingTask(normalized),
|
||||
getShippingChatActions(normalized),
|
||||
]);
|
||||
const checkpoint = String(actions.checkpoint || '').trim();
|
||||
if (checkpoint !== 'parse_review') {
|
||||
removeParseReviewMessageForTask(normalized);
|
||||
return false;
|
||||
}
|
||||
await upsertParseReviewMessage(buildParseReviewPayload(normalized, detail, checkpoint));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
// 解析复核表单不再作为聊天历史消息展示;当前步骤操作统一放到轻量工作台/动作按钮中。
|
||||
removeParseReviewMessageForTask(normalized);
|
||||
return false;
|
||||
};
|
||||
|
||||
const updateShippingParseReviewHeader = async (
|
||||
|
||||
Reference in new issue
Block a user