feat(shipping-notice): 新增临时库存管理功能,支持创建会话、获取分析结果及字段映射建议
This commit is contained in:
1 parent
46eb63f5bb
commit
e9bdd81f1a
320 files changed
+28361
-10487
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingUploadPrompt.ts
|
||||
* 用途:库存/通知上传后发给 Dify 的提示语构建与附件类型分类。
|
||||
* 用途:通知上传后提示语构建、文件格式识别与临时库存声明判断。
|
||||
* 依赖:无;useChatShippingUploadHandler 在上传成功后调用。
|
||||
* 逻辑:按 checkpoint 生成不同 follow-up 提示;通知建批后触发 Dify LLM 解析续办。
|
||||
*/
|
||||
@@ -9,40 +9,6 @@ import i18n from '@/i18n';
|
||||
/**
|
||||
* 根据上传 API 响应 checkpoint 生成发给 Agent 的 follow-up 提示语。
|
||||
*/
|
||||
export function buildShippingInventoryUploadPrompt(
|
||||
result: Record<string, unknown> | null | undefined,
|
||||
fileName?: string,
|
||||
): string {
|
||||
const checkpoint = String(result?.checkpoint || '').trim();
|
||||
const hasAlignment = Boolean(result?.data && typeof result.data === 'object'
|
||||
&& (result.data as { field_alignment?: unknown }).field_alignment
|
||||
&& typeof (result.data as { field_alignment?: unknown }).field_alignment === 'object');
|
||||
const suggestOk = Boolean((result?.data as { suggest_ok?: boolean } | undefined)?.suggest_ok);
|
||||
const batchNo = String(
|
||||
(result?.batch_no as string | undefined)
|
||||
|| ((result?.data as { batch_no?: string } | undefined)?.batch_no)
|
||||
|| ((result?.data as { batch?: { batch_no?: string } } | undefined)?.batch?.batch_no)
|
||||
|| '',
|
||||
).trim();
|
||||
const prefix = batchNo
|
||||
? (fileName
|
||||
? String(i18n.global.t('chat.shippingNoticePrompt.inventory.prefixBatchWithFile', { fileName, batchNo }))
|
||||
: String(i18n.global.t('chat.shippingNoticePrompt.inventory.prefixBatch', { batchNo })))
|
||||
: (fileName
|
||||
? String(i18n.global.t('chat.shippingNoticePrompt.inventory.prefixWithFile', { fileName }))
|
||||
: String(i18n.global.t('chat.shippingNoticePrompt.inventory.prefix')));
|
||||
if (checkpoint === 'map_infer') {
|
||||
if (suggestOk) {
|
||||
return String(i18n.global.t('chat.shippingNoticePrompt.inventory.mapInferSuggested', { prefix }));
|
||||
}
|
||||
return String(i18n.global.t('chat.shippingNoticePrompt.inventory.mapInferPending', { prefix }));
|
||||
}
|
||||
if (checkpoint === 'align_review' || hasAlignment) {
|
||||
return String(i18n.global.t('chat.shippingNoticePrompt.inventory.alignReview', { prefix }));
|
||||
}
|
||||
return String(i18n.global.t('chat.shippingNoticePrompt.inventory.default', { prefix }));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据通知建批 API 响应生成发给 Dify 的 follow-up 提示语(触发画布 LLM 抽取 + parse_notice)。
|
||||
*/
|
||||
@@ -94,13 +60,30 @@ export function buildShippingNoticeUploadPrompt(
|
||||
}
|
||||
|
||||
/**
|
||||
* 按扩展名判断附件是库存 Excel 还是发货通知文件。
|
||||
* 判断文件是否为后端当前可受控分析的表格格式。
|
||||
* 格式只是技术能力,不能据此推断文件一定是库存或订单。
|
||||
*/
|
||||
export function classifyShippingUploadFile(
|
||||
export function isShippingSpreadsheetFile(
|
||||
file: File,
|
||||
extractExt: (name: string) => string,
|
||||
): 'inventory' | 'notice' {
|
||||
): boolean {
|
||||
const ext = extractExt(file.name || '').toLowerCase();
|
||||
if (['xlsx', 'xls', 'csv'].includes(ext)) return 'inventory';
|
||||
return 'notice';
|
||||
return ['xlsx', 'xls', 'csv'].includes(ext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断用户是否明确声明当前附件是库存文件。
|
||||
* 仅用于临时库存分支门禁;不能从文件名、表格后缀或模型猜测推导。
|
||||
*/
|
||||
export function isTemporaryInventoryDeclaration(text: string): boolean {
|
||||
const value = String(text || '').trim();
|
||||
if (!value) return false;
|
||||
return [
|
||||
/这是.*库存(?:文件|表|excel|csv)?/i,
|
||||
/(?:请|帮我|麻烦).*(?:分析|解析|识别).*(?:库存|stock)/i,
|
||||
/(?:上传|附件|这个|该).*(?:库存文件|库存表|库存excel|库存csv)/i,
|
||||
/(?:库存文件|库存表|库存excel|库存csv).*(?:分析|解析|识别|使用)/i,
|
||||
/(?:this|the).*(?:is|are).*(?:inventory|stock)/i,
|
||||
/(?:analyse|analyze|parse).*(?:inventory|stock)/i,
|
||||
].some((pattern) => pattern.test(value));
|
||||
}
|
||||
Reference in new issue
Block a user