diff --git a/src/api/ai/auditContent/index.ts b/src/api/ai/auditContent/index.ts index b3eb587..2b1ffb2 100644 --- a/src/api/ai/auditContent/index.ts +++ b/src/api/ai/auditContent/index.ts @@ -47,6 +47,51 @@ export async function exportLeaderListTable(data: { return Promise.reject(new Error('导出失败')); } +/** + * 生成支出情况表 + */ +export async function generateExpenseTable(data: { + kbIds?: string; + libraryIds?: string; + projectLibrary?: string; + history?: string; + suggestion?: string; + docList?: any[]; + fileList?: any[]; +}) { + const res = await request.post>( + MODULES_API_URL + '/ai/auditContent1/generateExpenseTable', + data + ); + + if (res.data.code === 0) { + return res.data; + } + return Promise.reject(new Error(res.data.message)); +} + +/** + * 导出支出情况表到Excel + */ +export async function exportExpenseTable(data: { + data?: any[]; + companyName?: string; + auditTime?: string; +}) { + const res = await request.post( + MODULES_API_URL + '/ai/auditContent1/exportExpenseTable', + data, + { + responseType: 'blob' + } + ); + + if (res.status === 200) { + return res.data; + } + return Promise.reject(new Error('导出失败')); +} + /** * 生成八项规定对比分析表 */ diff --git a/src/views/pwl/pwlProject/components/data/table1Columns.ts b/src/views/pwl/pwlProject/components/data/table1Columns.ts index 5e08f8d..43a3779 100644 --- a/src/views/pwl/pwlProject/components/data/table1Columns.ts +++ b/src/views/pwl/pwlProject/components/data/table1Columns.ts @@ -305,50 +305,103 @@ export const columns1 = [ } ]; +// 修改 columns2 的定义 export const columns2 = [ { - title: '内容', - dataIndex: '', - key: '', - align: 'center' + title: '支出类型', + dataIndex: 'expenseType', + key: 'expenseType', + align: 'center', + width: 120 }, { - title: '2020年', - dataIndex: '', - key: '', - align: 'center' + title: '年份', + dataIndex: 'year', + key: 'year', + align: 'center', + width: 100 }, { - title: '2021年', - dataIndex: '', - key: '', - align: 'center' + title: '决算报表数(元)', + dataIndex: 'finalStatementAmount', + key: 'finalStatementAmount', + align: 'center', + width: 150 }, { - title: '2022年', - dataIndex: '', - key: '', - align: 'center' + title: '年初预算数(元)', + dataIndex: 'initialBudgetAmount', + key: 'initialBudgetAmount', + align: 'center', + width: 150 }, { - title: '2023年', - dataIndex: '', - key: '', - align: 'center' + title: '增减情况(%)', + dataIndex: 'changePercentage', + key: 'changePercentage', + align: 'center', + width: 120 + }, + { + title: '占年初预算比例(%)', + dataIndex: 'budgetRatio', + key: 'budgetRatio', + align: 'center', + width: 120 + }, + { + title: '备注', + dataIndex: 'remark', + key: 'remark', + align: 'center', + width: 150 + }, + { + title: '数据来源', + dataIndex: 'dataSource', + key: 'dataSource', + align: 'center', + width: 180 }, { title: '工作底稿索引', dataIndex: 'workPaperIndex', key: 'workPaperIndex', align: 'center', - width: 140, + width: 200, ellipsis: true }, { title: '操作', key: 'action', align: 'center', - width: 140 + width: 100 + } +]; + +// 添加示例数据 +export const columns2Data = [ + { + expenseType: '公务接待', + year: '2020', + finalStatementAmount: '150,000.00', + initialBudgetAmount: '120,000.00', + changePercentage: '25.0%', + budgetRatio: '125.0%', + remark: '超预算25%,主要原因为接待任务增加', + dataSource: '2020年度部门决算报表', + workPaperIndex: ['《2020年度部门决算报表》', '《2020年预算执行情况分析》'] + }, + { + expenseType: '出国', + year: '2020', + finalStatementAmount: '80,000.00', + initialBudgetAmount: '100,000.00', + changePercentage: '-20.0%', + budgetRatio: '80.0%', + remark: '受疫情影响,出国任务减少', + dataSource: '2020年度部门决算报表', + workPaperIndex: ['《2020年度部门决算报表》'] } ]; diff --git a/src/views/pwl/pwlProject/components/reportContent.vue b/src/views/pwl/pwlProject/components/reportContent.vue index ef90611..c505af7 100644 --- a/src/views/pwl/pwlProject/components/reportContent.vue +++ b/src/views/pwl/pwlProject/components/reportContent.vue @@ -191,6 +191,18 @@ 导出八项规定 + + + + 导出支出表 + { + const section = navigationItems.value[0]; + if (!section.data || section.data.length === 0) { + message.warning('没有可导出的支出情况数据'); + return; + } + + exportingExpense.value = true; + try { + // 构建导出数据 + const exportData = { + data: section.data, + companyName: form.name || '未知公司', + auditTime: form.expirationTime || '未知时间' + }; + + const blob = await exportExpenseTable(exportData); + + // 创建下载链接 + const url = window.URL.createObjectURL(new Blob([blob])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute( + 'download', + `支出情况表_${form.name || '未知公司'}.xlsx` + ); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + window.URL.revokeObjectURL(url); + + message.success('支出情况表导出成功'); + } catch (error: any) { + console.error('导出支出情况表失败:', error); + message.error('导出失败: ' + (error.message || '未知错误')); + } finally { + exportingExpense.value = false; + } + }; + /* 导出领导班子名单表格 */ const handleExportLeaderListTable = async () => { const section = navigationItems.value[0]; @@ -1030,6 +1087,72 @@ } }; + // 添加支出情况表生成方法 + const generateExpenseContent = async () => { + const section: any = navigationItems.value[0]; + section.generating = true; + + // 构建history + const history = section.data && section.data.length > 0 + ? JSON.stringify(section.data, null, 2) + : ''; + + // 获取用户输入的建议 + const suggestion = section.suggestion || ''; + + console.log('生成支出情况表参数:', { + kbIds: props.data?.kbId, + libraryIds: props.data?.libraryIds, + projectLibrary: props.data?.projectLibrary, + history: history ? `历史数据(${section.data.length}条)` : '无', + suggestion: suggestion || '无', + docList: checkedDirKeys.value, + fileList: selectedFileKeys.value + }); + + try { + // 构建请求参数对象 + const requestData = { + kbIds: props.data?.kbId || '', + libraryIds: props.data?.libraryIds || '', + projectLibrary: props.data?.projectLibrary || '', + history: history, + suggestion: suggestion, + docList: checkedDirKeys.value, + fileList: selectedFileKeys.value + }; + + // 调用支出情况表生成接口 + const result = await generateExpenseTable(requestData); + + console.log('支出情况表接口返回结果:', result); + + if (result.code === 0 && result.data && result.data.success) { + const tableData = mapExpenseData(result.data.data); + + // 保存到支出情况表数据 + expenseTableData.value = tableData; + section.data = tableData; + + // 生成成功后清空建议输入框 + section.suggestion = ''; + + message.success(`成功生成 ${tableData.length} 条支出情况记录`); + } else { + const errorMsg = result.data?.error || result.message || '生成失败'; + throw new Error(errorMsg); + } + } catch (error: any) { + console.error('生成支出情况表失败:', error); + message.error('生成失败: ' + (error.message || '未知错误')); + } finally { + section.generating = false; + } + }; + + + + // 领导班子名单生成方法 const generateLeaderListContent = async () => { const section: any = navigationItems.value[0]; @@ -1270,10 +1393,10 @@ section.columns = table1Columns.columns3; section.data = eightRegTableData.value || table1Columns.columns3Data || []; section.generateMethod = generateContent1; - } else { + } else if (title === '决策支出表') { section.columns = table1Columns.columns2; - section.data = decisionTableData.value || []; - section.generateMethod = generateDecisionContent; + section.data = expenseTableData.value || table1Columns.columns2Data || []; + section.generateMethod = generateExpenseContent; } }; @@ -1437,6 +1560,61 @@ })); }; + // 添加支出情况表数据映射函数 + const mapExpenseData = (data: any[]) => { + console.log('原始支出情况数据:', data); + + if (!data || !Array.isArray(data)) { + console.warn('支出情况数据为空或不是数组'); + return []; + } + + const mappedData = data.map((item, index) => { + console.log(`处理第${index}条支出记录:`, item); + + // 确保workPaperIndex是数组格式 + let workPaperIndex = item.workPaperIndex || []; + if (!Array.isArray(workPaperIndex)) { + workPaperIndex = [workPaperIndex]; + } + + // 格式化金额显示(添加千分位逗号) + const formatAmount = (amount) => { + if (!amount) return '0.00'; + // 如果是字符串且包含逗号,直接返回 + if (typeof amount === 'string' && amount.includes(',')) { + return amount; + } + // 转换为数字并格式化 + const num = parseFloat(amount); + if (isNaN(num)) return '0.00'; + return num.toLocaleString('zh-CN', { + minimumFractionDigits: 2, + maximumFractionDigits: 2 + }); + }; + + const mappedItem = { + key: index, + expenseType: item.expenseType || '', + year: item.year || '', + finalStatementAmount: formatAmount(item.finalStatementAmount), + initialBudgetAmount: formatAmount(item.initialBudgetAmount), + changePercentage: item.changePercentage || '0.0%', + budgetRatio: item.budgetRatio || '0.0%', + remark: item.remark || '', + dataSource: item.dataSource || '', + workPaperIndex: workPaperIndex + }; + + console.log(`映射后的第${index}条支出记录:`, mappedItem); + return mappedItem; + }); + + console.log('最终映射的支出情况数据:', mappedData); + return mappedData; + }; + // 领导班子名单数据映射函数 const mapLeaderListData = (data: any[]) => { console.log('原始领导班子数据:', data); @@ -1477,7 +1655,7 @@ }; // 应用历史记录数据到指定章节 - const applyHistoryData = (sectionIndex: number, data: any[], dataType: 'tripleOne' | 'decisionTable' | 'eightReg' | 'leaderList') => { + const applyHistoryData = (sectionIndex: number, data: any[], dataType: 'tripleOne' | 'decisionTable' | 'eightReg' | 'leaderList' | 'expense') => { const section = navigationItems.value[sectionIndex]; if (dataType === 'tripleOne') { @@ -1521,6 +1699,16 @@ section.columns = table1Columns.columns1; section.data = [...tableData]; } + } else if (dataType === 'expense') { + const tableData = mapExpenseData(data); + section.data = tableData; + expenseTableData.value = tableData; + + // 强制刷新当前显示的表格 + if (table1Title.value === '决策支出表') { + section.columns = table1Columns.columns2; + section.data = [...tableData]; + } } }; @@ -1535,6 +1723,8 @@ currentInterfaceName.value = '/api/ai/auditContent1/generateEightRegTable'; } else if (table1Title.value === '领导班子名单') { currentInterfaceName.value = '/api/ai/auditContent1/generateLeaderListTable'; + } else if (table1Title.value === '决策支出表') { + currentInterfaceName.value = '/api/ai/auditContent1/generateExpenseTable'; } } else if (sectionIndex === 2) { // 审计内容3章节 if (table3Title.value === '三重一大') { @@ -1565,6 +1755,9 @@ } else if (record.interfaceName === '/api/ai/auditContent1/generateLeaderListTable') { applyHistoryData(0, responseData.data, 'leaderList'); message.success('已应用选择的领导班子名单历史记录'); + } else if (record.interfaceName === '/api/ai/auditContent1/generateExpenseTable') { + applyHistoryData(0, responseData.data, 'expense'); + message.success('已应用选择的支出情况表历史记录'); } else if (record.interfaceName === '/api/ai/auditContent3/generateTripleOneTable') { applyHistoryData(2, responseData.data, 'tripleOne'); message.success('已应用选择的三重一大历史记录');