Files
syops/frontend/src/features/chat/shipping/shippingIntents.ts
T
hugo 1b6483a4ea feat(shipping-notice,receipt-report): 新增收料报表功能并优化发货通知流程
清理废弃的shipping xfa ocr automark相关代码和job配置
新增收料报表管理的前端页面、路由和侧边栏入口
新增后端收料报表配置接口、数据库模型和RPA脚本
优化发货通知流程的重试策略,将shipping相关job默认不自动重试
移除废弃的库存源确认相关逻辑,更新流程门禁规则
重构订单模板的值适配器模块,新增坐标OCR值适配器
清理前端shipping菜单和action的废弃选项
更新相关文档和测试用例,调整.gitignore忽略规则
2026-08-20 20:23:10 +08:00

73 lines
2.6 KiB
TypeScript

/**
* features/chat/shipping/shippingIntents.ts
* 用途:发货聊天用户输入意图识别,供 handleSend 前置拦截。
* 依赖:shippingMenu.resolveShippingNumericChoice、types/shipping.types。
* 逻辑:useChatShippingSendHandler 调用;覆盖手工上传、库存上传、Excel 生成/下载与切票。
*/
import type { ShippingMenuAction } from '../types/shipping.types';
export interface ShippingTaskSwitchIntent {
mode: 'next' | 'prev' | 'task';
taskNo?: string;
}
/**
* 从自然语言文本解析库存列映射(part_number / reservation_id / available_qty → Excel 列名)。
*/
export function isShippingManualUploadIntent(text: string): boolean {
const normalized = text.trim();
if (!normalized) return false;
return [
/已在货代系统手工上传/,
/已手工上传/,
/手工上传完成/,
/手动上传完成/,
/货代.*上传完成/,
].some((pattern) => pattern.test(normalized));
}
export function isShippingGenerateExcelIntent(text: string): boolean {
const normalized = text.trim();
if (!normalized) return false;
return [
/^生成发货excel$/i,
/^生成发货\s*excel$/i,
/生成发货.*excel/i,
/生成.*发货.*excel/i,
].some((pattern) => pattern.test(normalized));
}
function normalizeShippingCommandText(text: string): string {
return String(text || '')
.trim()
.replace(/\s+/g, '')
.replace(/[,。!?、,.!?]/g, '')
.toLowerCase();
}
export function isShippingDownloadExcelIntent(text: string): boolean {
const normalized = normalizeShippingCommandText(text);
if (!normalized) return false;
if (!/(excel|xlsx|表格|发货文件|发货单)/i.test(normalized)) return false;
if (/(生成|创建|制作|重新生成|重生成)/.test(normalized)) return false;
return /(下载|获取|取得|拿|打开|查看|导出)/.test(normalized);
}
export function parseShippingTaskSwitchIntent(text: string): ShippingTaskSwitchIntent | null {
const normalized = String(text || '').trim();
if (!normalized) return null;
const taskMatch = normalized.match(/SN-\d{8}-[A-F0-9]{8}/i);
if (taskMatch?.[0] && /(切|切到|切换|goto|go to|switch)/i.test(normalized)) {
return { mode: 'task', taskNo: taskMatch[0].toUpperCase() };
}
if (/^(下一票|下一单|下一个|next)$/i.test(normalized) || /切到下一票/.test(normalized)) {
return { mode: 'next' };
}
if (/^(上一票|上一单|上一个|prev|previous)$/i.test(normalized) || /切到上一票/.test(normalized)) {
return { mode: 'prev' };
}
return null;
}
export type { ShippingMenuAction };