feat(config): 南京公共资源交易中心

This commit is contained in:
2025-12-15 18:15:05 +08:00
parent 6fc9748009
commit 02e3728c5e
373 changed files with 227 additions and 216925 deletions

View File

@@ -9,12 +9,6 @@ function toggleDateRange() {
document.getElementById('normalFields').style.display = useDateRange ? 'none' : 'block';
}
function toggleDetailDateRange() {
const useDetailDateRange = document.getElementById('useDetailDateRange').checked;
document.getElementById('detailDateRangeFields').style.display = useDetailDateRange ? 'block' : 'none';
document.getElementById('detailNormalFields').style.display = useDetailDateRange ? 'none' : 'block';
}
function switchTab(tabName) {
// 隐藏所有标签内容
document.querySelectorAll('.tab-content').forEach(content => {
@@ -30,7 +24,6 @@ function switchTab(tabName) {
}
async function fetchList(pageNum) {
const url = document.getElementById('listUrl').value;
const page = pageNum || parseInt(document.getElementById('listPage').value) || 1;
const loading = document.getElementById('listLoading');
const results = document.getElementById('listResults');
@@ -44,7 +37,7 @@ async function fetchList(pageNum) {
pagination.style.display = 'none';
try {
const response = await fetch(`${API_BASE}/list?url=${encodeURIComponent(url)}&page=${page}`);
const response = await fetch(`${API_BASE}/list?page=${page}`);
const data = await response.json();
if (data.success) {
@@ -94,127 +87,11 @@ function displayList(items, container) {
${items.map((item, index) => `
<div class="list-item">
<h3>${index + 1}. ${item.title}</h3>
<div class="meta">标段编号: ${item.bidNo}</div>
<div class="meta">标段名称: ${item.bidName}</div>
<div class="meta">发布日期: ${item.date}</div>
<a href="${item.href}" target="_blank">查看详情 →</a>
</div>
`).join('')}
</div>
`;
container.innerHTML = html;
}
async function fetchDetails() {
const useDetailDateRange = document.getElementById('useDetailDateRange').checked;
const loading = document.getElementById('detailLoading');
const results = document.getElementById('detailResults');
loading.classList.add('active');
results.innerHTML = '';
try {
let listData;
if (useDetailDateRange) {
// 时间范围模式
const startDate = document.getElementById('detailStartDate').value;
const endDate = document.getElementById('detailEndDate').value;
const maxPages = parseInt(document.getElementById('detailMaxPages').value);
if (!startDate && !endDate) {
results.innerHTML = '<div class="error">请至少填写开始日期或结束日期</div>';
loading.classList.remove('active');
return;
}
const dateRangeResponse = await fetch(`${API_BASE}/list-daterange`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ startDate, endDate, maxPages })
});
listData = await dateRangeResponse.json();
} else {
// 普通模式 - 按数量采集多页
const url = document.getElementById('detailUrl').value;
const limit = parseInt(document.getElementById('detailLimit').value);
// 采集多页直到获得足够数量
const allItems = [];
let page = 1;
const maxPagesToFetch = Math.ceil(limit / 10) + 1; // 假设每页约10条
while (allItems.length < limit && page <= maxPagesToFetch) {
const listResponse = await fetch(`${API_BASE}/list?url=${encodeURIComponent(url)}&page=${page}`);
const pageData = await listResponse.json();
if (!pageData.success) {
if (allItems.length === 0) {
results.innerHTML = `<div class="error">错误: ${pageData.error}</div>`;
loading.classList.remove('active');
return;
}
break;
}
if (pageData.data.length === 0) {
break;
}
allItems.push(...pageData.data);
page++;
// 如果还需要更多数据且未到达上限,稍作延迟
if (allItems.length < limit && page <= maxPagesToFetch) {
await new Promise(resolve => setTimeout(resolve, 500));
}
}
listData = { success: true, data: allItems };
}
if (!listData.success) {
results.innerHTML = `<div class="error">错误: ${listData.error}</div>`;
return;
}
// 采集详情
const limit = useDetailDateRange ? listData.data.length : parseInt(document.getElementById('detailLimit').value);
const detailResponse = await fetch(`${API_BASE}/details`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ items: listData.data, limit })
});
const detailData = await detailResponse.json();
if (detailData.success) {
displayDetails(detailData.data, results);
} else {
results.innerHTML = `<div class="error">错误: ${detailData.error}</div>`;
}
} catch (error) {
results.innerHTML = `<div class="error">请求失败: ${error.message}</div>`;
} finally {
loading.classList.remove('active');
}
}
function displayDetails(items, container) {
const html = `
<div style="max-height: 380px; overflow-y: auto;">
<h3 style="margin-bottom: 15px;">采集了 ${items.length} 条详情</h3>
${items.map((item, index) => `
<div class="list-item">
<h3>${index + 1}. ${item.title}</h3>
<div class="meta">发布日期: ${item.date}</div>
${item.detail ? `
<div class="meta">发布时间: ${item.detail.publishTime || '未知'}</div>
${item.detail.budget ? `
<span class="budget">${item.detail.budget.amount}${item.detail.budget.unit}</span>
` : '<div class="meta">未找到预算信息</div>'}
` : '<div class="error">采集失败</div>'}
<br><a href="${item.href}" target="_blank">查看原文 →</a>
<span class="budget">${item.budget.amount}${item.budget.unit}</span>
${item.href ? `<br><a href="${item.href}" target="_blank">查看详情 →</a>` : ''}
</div>
`).join('')}
</div>
@@ -256,13 +133,12 @@ async function generateReport() {
});
} else {
// 普通模式
const url = document.getElementById('reportUrl').value;
const limit = parseInt(document.getElementById('reportLimit').value);
response = await fetch(`${API_BASE}/report`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url, limit, threshold })
body: JSON.stringify({ limit, threshold })
});
}
@@ -310,11 +186,11 @@ function displayReport(report, container) {
${report.projects.map((project, index) => `
<div class="list-item">
<h3>${index + 1}. ${project.title}</h3>
<div class="meta">标段编号: ${project.bidNo || '-'}</div>
<div class="meta">标段名称: ${project.bidName || '-'}</div>
<div class="meta">发布日期: ${project.date}</div>
<div class="meta">发布时间: ${project.publish_time}</div>
<span class="budget">${project.budget.amount}${project.budget.unit}</span>
<div class="meta" style="margin-top: 8px;">金额描述: ${project.budget.text}</div>
<br><a href="${project.url}" target="_blank">查看详情 →</a>
${project.url ? `<br><a href="${project.url}" target="_blank">查看详情 →</a>` : ''}
</div>
`).join('')}
`}
@@ -341,7 +217,7 @@ async function exportReport() {
// 标题
paragraphs.push(
new Paragraph({
text: '南京公共工程建设项目报告',
text: '南京公共资源交易平台 - 招标公告报告',
heading: HeadingLevel.HEADING_1,
alignment: AlignmentType.CENTER,
spacing: { after: 200 }
@@ -419,6 +295,20 @@ async function exportReport() {
// 项目详情
paragraphs.push(
new Paragraph({
children: [
new TextRun({ text: '标段编号: ', bold: true }),
new TextRun({ text: project.bidNo || '-' })
],
spacing: { after: 50 }
}),
new Paragraph({
children: [
new TextRun({ text: '标段名称: ', bold: true }),
new TextRun({ text: project.bidName || '-' })
],
spacing: { after: 50 }
}),
new Paragraph({
children: [
new TextRun({ text: '发布日期: ', bold: true }),
@@ -428,14 +318,7 @@ async function exportReport() {
}),
new Paragraph({
children: [
new TextRun({ text: '发布时间: ', bold: true }),
new TextRun({ text: project.publish_time })
],
spacing: { after: 50 }
}),
new Paragraph({
children: [
new TextRun({ text: '预算金额: ', bold: true }),
new TextRun({ text: '合同估算价: ', bold: true }),
new TextRun({ text: `${project.budget.amount}${project.budget.unit}` })
],
spacing: { after: 50 }
@@ -443,14 +326,7 @@ async function exportReport() {
new Paragraph({
children: [
new TextRun({ text: '链接: ', bold: true }),
new TextRun({ text: project.url, color: '0000FF' })
],
spacing: { after: 50 }
}),
new Paragraph({
children: [
new TextRun({ text: '金额描述: ', bold: true }),
new TextRun({ text: project.budget.text })
new TextRun({ text: project.url || '-', color: '0000FF' })
],
spacing: { after: 100 }
})
@@ -539,21 +415,20 @@ async function testEmailConfig() {
summary: {
total_count: 1,
filtered_count: 1,
threshold: '50万元',
total_amount: '100.00万元',
threshold: '1000万元',
total_amount: '10000.00万元',
generated_at: new Date().toISOString()
},
projects: [{
bidNo: 'TEST001',
title: '这是一封测试邮件',
bidName: '测试标段',
date: new Date().toLocaleDateString('zh-CN'),
publish_time: new Date().toLocaleString('zh-CN'),
budget: {
amount: 100,
unit: '万元',
text: '测试金额',
originalUnit: '万元'
amount: 10000,
unit: '万元'
},
url: 'https://gjzx.nanjing.gov.cn'
url: 'https://njggzy.nanjing.gov.cn'
}]
};
@@ -722,7 +597,7 @@ async function loadSchedulerConfig() {
document.getElementById('schedulerEnabled').checked = config.scheduler.enabled || false;
const cronTime = config.scheduler.cronTime || '0 9 * * *';
document.getElementById('schedulerCronInput').value = cronTime;
document.getElementById('schedulerThresholdInput').value = config.scheduler.threshold || 100000;
document.getElementById('schedulerThresholdInput').value = config.scheduler.threshold || 10000;
document.getElementById('schedulerDescription').value = config.scheduler.description || '';
// 时间段配置
@@ -801,7 +676,6 @@ function updateCustomCron() {
document.addEventListener('DOMContentLoaded', function() {
loadEmailConfig();
loadSchedulerConfig();
loadLLMConfig();
// 添加自定义时间输入框的事件监听
const customHour = document.getElementById('customHour');
@@ -909,7 +783,7 @@ async function saveSchedulerConfig() {
// 立即测试运行定时任务
async function testSchedulerNow() {
if (!confirm('确定要立即执行定时任务吗?\n\n这将采集本月大于阈值的项目并发送邮件,可能需要几分钟时间。')) {
if (!confirm('确定要立即执行定时任务吗?\n\n这将采集选定时间段内大于阈值的项目并发送邮件,可能需要几分钟时间。')) {
return;
}
@@ -960,162 +834,3 @@ function showSchedulerStatus(message, type) {
}, 3000);
}
}
// ========== LLM 配置功能 ==========
// 加载 LLM 配置
async function loadLLMConfig() {
try {
const response = await fetch(`${API_BASE}/config`);
const data = await response.json();
if (data.success && data.data && data.data.llm) {
const llmConfig = data.data.llm;
document.getElementById('llmEnabled').checked = llmConfig.enabled || false;
document.getElementById('llmApiKey').value = llmConfig.apiKey || '';
document.getElementById('llmBaseUrl').value = llmConfig.baseUrl || 'https://dashscope.aliyuncs.com/compatible-mode/v1';
document.getElementById('llmModel').value = llmConfig.model || 'qwen-turbo';
}
// 更新状态显示
await updateLLMStatus();
} catch (error) {
console.error('加载 LLM 配置失败:', error);
}
}
// 更新 LLM 状态显示
async function updateLLMStatus() {
try {
const response = await fetch(`${API_BASE}/llm/status`);
const data = await response.json();
if (data.success && data.data) {
const status = data.data;
// 更新运行状态
let statusText, statusColor;
if (status.enabled) {
statusText = '✓ 已启用';
statusColor = '#28a745';
} else if (status.configured) {
statusText = '○ 已配置但未启用';
statusColor = '#ffc107';
} else {
statusText = '✗ 未配置';
statusColor = '#dc3545';
}
document.getElementById('llmRunningStatus').innerHTML = `<span style="color: ${statusColor}">${statusText}</span>`;
// 更新模型名称
document.getElementById('llmModelName').textContent = status.model || '-';
}
} catch (error) {
console.error('获取 LLM 状态失败:', error);
document.getElementById('llmRunningStatus').innerHTML = '<span style="color: #dc3545">获取状态失败</span>';
}
}
// 保存 LLM 配置
async function saveLLMConfig() {
const llmConfig = {
enabled: document.getElementById('llmEnabled').checked,
apiKey: document.getElementById('llmApiKey').value,
baseUrl: document.getElementById('llmBaseUrl').value || 'https://dashscope.aliyuncs.com/compatible-mode/v1',
model: document.getElementById('llmModel').value || 'qwen-turbo'
};
// 验证必填项
if (llmConfig.enabled && !llmConfig.apiKey) {
showLLMStatus('启用 AI 功能需要填写 API Key', 'error');
return;
}
showLLMStatus('正在保存配置...', 'info');
try {
// 先获取现有配置
const configResponse = await fetch(`${API_BASE}/config`);
const configData = await configResponse.json();
if (!configData.success) {
showLLMStatus('获取配置失败', 'error');
return;
}
// 合并配置
const fullConfig = {
...configData.data,
llm: llmConfig
};
// 保存配置
const response = await fetch(`${API_BASE}/config`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(fullConfig)
});
const data = await response.json();
if (data.success) {
showLLMStatus('配置已保存!', 'success');
await updateLLMStatus();
} else {
showLLMStatus(`保存失败: ${data.error}`, 'error');
}
} catch (error) {
showLLMStatus(`请求失败: ${error.message}`, 'error');
}
}
// 测试 LLM 连接
async function testLLMConnection() {
showLLMStatus('正在测试连接...', 'info');
try {
const response = await fetch(`${API_BASE}/llm/test`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
});
const data = await response.json();
if (data.success && data.data.success) {
showLLMStatus(`连接成功! 模型: ${data.data.model}, 响应: ${data.data.reply}`, 'success');
} else {
showLLMStatus(`连接失败: ${data.data?.error || data.error || '未知错误'}`, 'error');
}
} catch (error) {
showLLMStatus(`请求失败: ${error.message}`, 'error');
}
}
// 显示 LLM 配置状态
function showLLMStatus(message, type) {
const statusDiv = document.getElementById('llmConfigStatus');
const bgColors = {
success: '#d4edda',
error: '#f8d7da',
info: '#d1ecf1'
};
const textColors = {
success: '#155724',
error: '#721c24',
info: '#0c5460'
};
statusDiv.innerHTML = `
<div style="background: ${bgColors[type]}; color: ${textColors[type]}; padding: 15px; border-radius: 8px;">
${message}
</div>
`;
// 5秒后自动隐藏成功消息
if (type === 'success') {
setTimeout(() => {
statusDiv.innerHTML = '';
}, 5000);
}
}