| | |
| | | sales_customer_profile_list: '客户档案', |
| | | sales_quotation_list: '销售报价', |
| | | sales_ledger_list: '销售台账', |
| | | sales_return_list: '销售退货', |
| | | sales_return_list: '销售退款/回款记录', |
| | | sales_customer_interaction_list: '客户往来', |
| | | sales_shipping_list: '发货台账', |
| | | sales_dashboard: '销售指标统计', |
| | |
| | | } |
| | | const purchaseTypeLabelMap = { |
| | | purchase_material_rank: '采购物料金额排行', |
| | | purchase_stats: '采购统计', |
| | | purchase_pending_payment_list: '待付款采购单' |
| | | } |
| | | const financialStructuredTypeSet = new Set([ |
| | |
| | | stockQty: '库存量' |
| | | } |
| | | Object.assign(structuredFieldLabelMap, { |
| | | refundId: '退款/回款单号', |
| | | collectionNumber: '收款单号', |
| | | collectionAmount: '收款金额', |
| | | actualAmount: '收款金额(兼容)', |
| | | customerId: '客户ID', |
| | | salesLedgerId: '销售台账ID', |
| | | projectName: '项目名称', |
| | | receiptPaymentDate: '收付款日期', |
| | | receiptPaymentAmount: '收付款金额', |
| | | receiptPaymentType: '收付款类型', |
| | | registrant: '登记人', |
| | | returnAmount: '回款金额汇总', |
| | | totalReceiptAmount: '收款总额', |
| | | customerCount: '客户数', |
| | | paidAmount: '已付款金额', |
| | | contractAmount: '合同金额', |
| | | paymentCount: '付款笔数', |
| | | invoiceCount: '发票笔数', |
| | | paymentAmount: '付款金额', |
| | | invoiceAmount: '发票金额', |
| | | customerName: '客户名称', |
| | | riskLevel: '风险等级', |
| | | riskScore: '风险评分', |
| | |
| | | return items.filter(item => isPlainObject(item)) |
| | | } |
| | | |
| | | const normalizeSalesReturnListItems = (items = []) => { |
| | | return normalizeSalesListItems(items).map((item) => { |
| | | const collectionAmount = item.collectionAmount ?? item.actualAmount |
| | | const collectionNumber = item.collectionNumber || item.refundId || '' |
| | | return { |
| | | ...item, |
| | | refundId: item.refundId || collectionNumber, |
| | | collectionNumber, |
| | | collectionAmount: collectionAmount ?? 0, |
| | | actualAmount: item.actualAmount ?? collectionAmount ?? 0 |
| | | } |
| | | }) |
| | | } |
| | | |
| | | const normalizeSalesTypeListItems = (type = '', items = []) => { |
| | | if (type === 'sales_return_list') { |
| | | return normalizeSalesReturnListItems(items) |
| | | } |
| | | return normalizeSalesListItems(items) |
| | | } |
| | | |
| | | const inferSalesColumnsByType = (type = '', listItems = []) => { |
| | | const columns = inferSalesColumns(listItems) |
| | | if (type === 'sales_return_list') { |
| | | return columns.filter(column => column !== 'actualAmount') |
| | | } |
| | | return columns |
| | | } |
| | | |
| | | const buildSalesStructuredData = (parsedData) => { |
| | | const type = String(parsedData?.type || '') |
| | | if (!salesStructuredTypeSet.has(type)) return null |
| | | |
| | | const rawData = isPlainObject(parsedData?.data) ? parsedData.data : {} |
| | | const listItems = normalizeSalesListItems(rawData.items) |
| | | const listItems = normalizeSalesTypeListItems(type, rawData.items) |
| | | const topCustomers = normalizeSalesListItems(rawData.topCustomers) |
| | | const contractTrend = normalizeSalesListItems(rawData.contractTrend) |
| | | |
| | |
| | | type, |
| | | summaryEntries: normalizeManufacturingSummaryEntries(parsedData?.summary), |
| | | listItems, |
| | | columns: inferSalesColumns(listItems), |
| | | columns: inferSalesColumnsByType(type, listItems), |
| | | topCustomers, |
| | | topCustomerColumns: inferSalesColumns(topCustomers), |
| | | contractTrend, |
| | |
| | | if (parsedData.type === 'sales_customer_churn_risk') return '已为您生成客户流失风险分析。' |
| | | if (parsedData.type === 'sales_collection_quote_strategy') return '已为您生成回款与报价策略建议。' |
| | | if (parsedData.type === 'sales_dashboard') return '已为您生成销售指标统计。' |
| | | if (parsedData.type === 'sales_return_list') return '已返回销售退款/回款记录。' |
| | | if (parsedData.type === 'sales_customer_interaction_list') return '已返回客户往来数据。' |
| | | return '已返回销售查询结果。' |
| | | } |
| | | if (manufacturingStructuredTypeSet.has(parsedData.type)) { |
| | |
| | | if (String(parsedData.type || '').startsWith('purchase_')) return '已返回采购查询结果。' |
| | | if (parsedData.charts && Object.keys(parsedData.charts).length > 0) return '已为您生成分析图表。' |
| | | return '正在为您展示分析结果...' |
| | | } |
| | | |
| | | const resolveStructuredDescription = (parsedData) => { |
| | | if (!parsedData) return '' |
| | | if (parsedData.action === 'confirm_required') { |
| | | return getPurchaseConfirmDescription(parsedData) |
| | | } |
| | | |
| | | const description = String(parsedData.description || '').trim() |
| | | if (!description) return '' |
| | | |
| | | if (parsedData.type === 'sales_customer_interaction_list') { |
| | | if (description === 'no_customer_interactions') return '该时间范围暂无客户往来记录。' |
| | | if (description === 'ok') return '已返回客户往来数据。' |
| | | } |
| | | |
| | | if (description === 'ok' || description === 'success') { |
| | | return getStructuredFallbackText(parsedData) |
| | | } |
| | | |
| | | return description |
| | | } |
| | | |
| | | const buildPurchaseMaterialRankCharts = (parsedData) => { |
| | |
| | | display = '' |
| | | } |
| | | |
| | | if (parsed.description) { |
| | | display = parsed.action === 'confirm_required' |
| | | ? getPurchaseConfirmDescription(parsed) |
| | | : parsed.description |
| | | const resolvedDescription = resolveStructuredDescription(parsed) |
| | | if (resolvedDescription) { |
| | | display = resolvedDescription |
| | | } |
| | | |
| | | if (!display) { |
| | |
| | | display = '' |
| | | } |
| | | |
| | | if (parsed.description) { |
| | | display = parsed.action === 'confirm_required' |
| | | ? getPurchaseConfirmDescription(parsed) |
| | | : parsed.description |
| | | const resolvedDescription = resolveStructuredDescription(parsed) |
| | | if (resolvedDescription) { |
| | | display = resolvedDescription |
| | | } |
| | | |
| | | if (!display) { |