Compare commits

..

4 Commits

Author SHA1 Message Date
e3766b86be ```
All checks were successful
Deploy Vue App / build-and-deploy (push) Successful in 12s
feat(public): 实现docx库按需加载并优化邮件配置存储逻辑

将Word导出功能中的docx库从静态引入改为按需动态加载,提升页面初始加载性能。
同时重构邮件配置功能,支持将配置保存至服务器并与localStorage保持同步备份。
此外,在页面初始化时并行加载各项配置以提高整体加载效率。
```
2025-12-16 19:08:38 +08:00
ed03bd2032 ```
All checks were successful
Deploy Vue App / build-and-deploy (push) Successful in 13s
build(workflow): 更新部署流程以支持代码拉取和依赖安装

修改了 Gitea 工作流配置文件,调整部署步骤顺序:
- 添加代码检出步骤
- 增加服务停止操作
- 实现源码拷贝功能
- 改进依赖安装与服务重启逻辑

同时修正 YAML 文件中的引号使用问题,确保分支名称正确解析。
```
2025-12-16 09:43:53 +08:00
fb70356f5d ```
All checks were successful
Deploy Vue App / build-and-deploy (push) Successful in 8s
ci(deploy): 更新部署分支为南京公共资源交易中心

将 Gitea 工作流中的触发分支从 master 更新为南京公共资源交易中心,
以确保代码变更能够正确部署到指定环境。
```
2025-12-16 09:33:20 +08:00
f2c856ab05 ```
feat(scheduler): 更新定时任务配置以支持中标与招标分别设置阈值

将原先单一的 threshold 配置项拆分为 winningThreshold 和 bidThreshold,
分别用于控制中标公示和招标公告的金额筛选条件。同时调整了默认值及描述信息,
使配置更清晰灵活。

此外,更新了定时任务状态展示逻辑,支持显示两个独立的阈值及其单位转换(万元/亿元)。
当阈值为 0 时显示“不筛选”,提高用户理解度。

配置文件 config.json 中相关字段已同步修改,并调整了时间范围字段 timeRange 的默认值。
```
2025-12-15 21:06:10 +08:00
7 changed files with 1717 additions and 163 deletions

View File

@@ -3,7 +3,7 @@ name: Deploy Vue App
# 触发条件:推送到 master 分支时执行
on:
push:
branches: ['master']
branches: ["南京公共资源交易中心"]
env:
IP: 106.15.181.192
@@ -13,11 +13,20 @@ jobs:
# 运行在已注册的 runner 上(确保 runner 标签匹配,默认无标签可省略)
runs-on: [test]
steps:
# 步骤 4部署到服务器
- name: Deploy to server
# 步骤 1拉取代码
- name: Checkout code
uses: https://gitee.com/skr2005/checkout@v4
# 步骤 2停止服务
- name: Stop service
run: net stop tool-node
# 步骤 3拷贝源码到目标目录
- name: Copy source to target
run: xcopy /E /I /Y "${{ github.workspace }}\*" "D:\tools\tool-node\"
# 步骤 4安装依赖并启动服务
- name: Install and start service
run: |
cd D:\tools\tool-node
npm install
git pull
net stop tool-node
net start tool-node

View File

@@ -1,10 +1,11 @@
{
"scheduler": {
"enabled": false,
"enabled": true,
"cronTime": "0 9 * * *",
"threshold": 100000,
"description": "每天9点采集当日大于10亿的项目",
"timeRange": "today"
"winningThreshold": 0,
"bidThreshold": 0,
"description": "每天9点采集当日项目",
"timeRange": "thisMonth"
},
"email": {
"smtpHost": "smtp.qq.com",

View File

@@ -90,7 +90,7 @@ function displayList(items, container) {
<div class="meta">标段编号: ${item.bidNo}</div>
<div class="meta">标段名称: ${item.bidName}</div>
<div class="meta">发布日期: ${item.date}</div>
<span class="budget">${item.budget.amount}${item.budget.unit}</span>
<span class="budget">${item.winningBid.amount}${item.winningBid.unit}</span>
${item.href ? `<br><a href="${item.href}" target="_blank">查看详情 →</a>` : ''}
</div>
`).join('')}
@@ -189,7 +189,7 @@ function displayReport(report, container) {
<div class="meta">标段编号: ${project.bidNo || '-'}</div>
<div class="meta">标段名称: ${project.bidName || '-'}</div>
<div class="meta">发布日期: ${project.date}</div>
<span class="budget">${project.budget.amount}${project.budget.unit}</span>
<span class="budget">${project.winningBid.amount}${project.winningBid.unit}</span>
${project.url ? `<br><a href="${project.url}" target="_blank">查看详情 →</a>` : ''}
</div>
`).join('')}
@@ -202,11 +202,35 @@ function displayReport(report, container) {
async function exportReport() {
if (!currentReport) return;
// 检查docx库是否加载
// 按需动态加载docx库
if (!window.docx) {
alert('Word导出库正在加载中,请稍后再试...');
try {
// 显示加载提示
const loadingMsg = document.createElement('div');
loadingMsg.textContent = '正在加载导出库...';
loadingMsg.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:#fff;padding:20px;border-radius:8px;box-shadow:0 4px 12px rgba(0,0,0,0.15);z-index:9999;';
document.body.appendChild(loadingMsg);
// 动态加载docx库
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/docx@7.8.2/build/index.js';
script.onload = resolve;
script.onerror = () => {
// 降级到unpkg
script.src = 'https://unpkg.com/docx@7.8.2/build/index.js';
script.onload = resolve;
script.onerror = reject;
};
document.head.appendChild(script);
});
document.body.removeChild(loadingMsg);
} catch (error) {
alert('导出库加载失败,请检查网络连接后重试');
return;
}
}
const report = currentReport;
const { Document, Packer, Paragraph, TextRun, HeadingLevel, AlignmentType } = window.docx;
@@ -319,7 +343,7 @@ async function exportReport() {
new Paragraph({
children: [
new TextRun({ text: '合同估算价: ', bold: true }),
new TextRun({ text: `${project.budget.amount}${project.budget.unit}` })
new TextRun({ text: `${project.winningBid.amount}${project.winningBid.unit}` })
],
spacing: { after: 50 }
}),
@@ -356,8 +380,8 @@ async function exportReport() {
// ========== 邮件功能 ==========
// 保存邮件配置到localStorage
function saveEmailConfig() {
// 保存邮件配置到服务器
async function saveEmailConfig() {
const config = {
smtpHost: document.getElementById('smtpHost').value,
smtpPort: parseInt(document.getElementById('smtpPort').value) || 587,
@@ -367,18 +391,95 @@ function saveEmailConfig() {
};
// 验证配置
if (!config.smtpHost || !config.smtpUser || !config.smtpPass || !config.recipients) {
showEmailStatus('请填写所有必填项', 'error');
if (!config.smtpHost || !config.smtpUser || !config.recipients) {
showEmailStatus('请填写SMTP服务器、发件人邮箱和收件人', 'error');
return;
}
// 保存到localStorage
// 如果密码为空,可能是要保持原密码不变
const smtpPassInput = document.getElementById('smtpPass');
if (!config.smtpPass && smtpPassInput.placeholder.includes('已配置')) {
// 使用占位符表示保持原密码
config.smtpPass = '***已配置***';
} else if (!config.smtpPass) {
showEmailStatus('请填写SMTP密码', 'error');
return;
}
showEmailStatus('正在保存配置...', 'info');
try {
// 先获取当前服务器配置
const getResponse = await fetch(`${API_BASE}/config`);
const getData = await getResponse.json();
let fullConfig = { email: config };
// 如果服务器有其他配置(如scheduler),保留它们
if (getData.success && getData.data) {
fullConfig = {
...getData.data,
email: config
};
}
// 保存到服务器
const saveResponse = await fetch(`${API_BASE}/config`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(fullConfig)
});
const saveData = await saveResponse.json();
if (saveData.success) {
// 同时保存到localStorage作为备份
localStorage.setItem('emailConfig', JSON.stringify(config));
showEmailStatus('邮件配置已保存', 'success');
showEmailStatus('邮件配置已保存到服务器', 'success');
} else {
showEmailStatus(`保存失败: ${saveData.error}`, 'error');
}
} catch (error) {
showEmailStatus(`保存失败: ${error.message}`, 'error');
}
}
// 从localStorage加载邮件配置
function loadEmailConfig() {
// 从服务器加载邮件配置
async function loadEmailConfig() {
try {
// 从服务器获取配置
const response = await fetch(`${API_BASE}/config`);
const data = await response.json();
if (data.success && data.data && data.data.email) {
const config = data.data.email;
document.getElementById('smtpHost').value = config.smtpHost || '';
document.getElementById('smtpPort').value = config.smtpPort || 587;
document.getElementById('smtpUser').value = config.smtpUser || '';
// 如果密码是占位符,保持输入框为空或显示占位符
document.getElementById('smtpPass').value = config.smtpPass === '***已配置***' ? '' : (config.smtpPass || '');
if (config.smtpPass === '***已配置***') {
document.getElementById('smtpPass').placeholder = '***已配置*** (留空保持不变)';
}
document.getElementById('recipients').value = config.recipients || '';
// 同时保存到localStorage作为备份
localStorage.setItem('emailConfig', JSON.stringify(config));
} else {
// 如果服务器没有配置,尝试从localStorage加载
const configStr = localStorage.getItem('emailConfig');
if (configStr) {
const config = JSON.parse(configStr);
document.getElementById('smtpHost').value = config.smtpHost || '';
document.getElementById('smtpPort').value = config.smtpPort || 587;
document.getElementById('smtpUser').value = config.smtpUser || '';
document.getElementById('smtpPass').value = config.smtpPass || '';
document.getElementById('recipients').value = config.recipients || '';
}
}
} catch (error) {
console.error('从服务器加载邮件配置失败:', error);
// 失败时尝试从localStorage加载
const configStr = localStorage.getItem('emailConfig');
if (configStr) {
try {
@@ -389,7 +490,8 @@ function loadEmailConfig() {
document.getElementById('smtpPass').value = config.smtpPass || '';
document.getElementById('recipients').value = config.recipients || '';
} catch (e) {
console.error('加载邮件配置失败:', e);
console.error('从localStorage加载邮件配置失败:', e);
}
}
}
}
@@ -597,7 +699,8 @@ 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 || 10000;
document.getElementById('schedulerWinningThresholdInput').value = config.scheduler.winningThreshold !== undefined ? config.scheduler.winningThreshold : 10000;
document.getElementById('schedulerBidThresholdInput').value = config.scheduler.bidThreshold !== undefined ? config.scheduler.bidThreshold : 0;
document.getElementById('schedulerDescription').value = config.scheduler.description || '';
// 时间段配置
@@ -674,8 +777,13 @@ function updateCustomCron() {
}
document.addEventListener('DOMContentLoaded', function() {
loadEmailConfig();
loadSchedulerConfig();
// 并行加载配置,提高加载速度
Promise.all([
loadEmailConfig().catch(err => console.error('加载邮件配置失败:', err)),
loadSchedulerConfig().catch(err => console.error('加载定时任务配置失败:', err))
]).then(() => {
console.log('配置加载完成');
});
// 添加自定义时间输入框的事件监听
const customHour = document.getElementById('customHour');
@@ -705,8 +813,20 @@ async function updateSchedulerStatus() {
// 更新执行计划
if (status.config) {
document.getElementById('schedulerCronTime').textContent = cronToFriendlyText(status.config.cronTime);
const thresholdBillion = (status.config.threshold / 10000).toFixed(1);
document.getElementById('schedulerThreshold').textContent = `${status.config.threshold}万元 (${thresholdBillion}亿)`;
const winningThreshold = status.config.winningThreshold;
if (winningThreshold === 0) {
document.getElementById('schedulerWinningThreshold').textContent = '不筛选';
} else {
const winningBillion = (winningThreshold / 10000).toFixed(1);
document.getElementById('schedulerWinningThreshold').textContent = `${winningThreshold}万元 (${winningBillion}亿)`;
}
const bidThreshold = status.config.bidThreshold;
if (bidThreshold === 0) {
document.getElementById('schedulerBidThreshold').textContent = '不筛选';
} else {
const bidBillion = (bidThreshold / 10000).toFixed(1);
document.getElementById('schedulerBidThreshold').textContent = `${bidThreshold}万元 (${bidBillion}亿)`;
}
}
}
} catch (error) {
@@ -719,7 +839,8 @@ async function saveSchedulerConfig() {
const schedulerConfig = {
enabled: document.getElementById('schedulerEnabled').checked,
cronTime: document.getElementById('schedulerCronInput').value,
threshold: parseInt(document.getElementById('schedulerThresholdInput').value),
winningThreshold: parseInt(document.getElementById('schedulerWinningThresholdInput').value),
bidThreshold: parseInt(document.getElementById('schedulerBidThresholdInput').value),
description: document.getElementById('schedulerDescription').value,
timeRange: document.getElementById('schedulerTimeRange').value
};
@@ -834,3 +955,306 @@ function showSchedulerStatus(message, type) {
}, 3000);
}
}
// ========== 招标公告列表功能 ==========
let currentBidListPage = 1;
// 获取招标公告列表
async function fetchBidList(pageNum) {
const page = pageNum || parseInt(document.getElementById('bidListPage').value) || 1;
const loading = document.getElementById('bidListLoading');
const results = document.getElementById('bidListResults');
const pagination = document.getElementById('bidListPagination');
currentBidListPage = page;
document.getElementById('bidListPage').value = page;
loading.classList.add('active');
results.innerHTML = '';
pagination.style.display = 'none';
try {
const response = await fetch(`${API_BASE}/bid-announce/list?page=${page}`);
const data = await response.json();
if (data.success) {
displayBidList(data.data, results);
updateBidListPagination(page, data.data.length > 0);
} else {
results.innerHTML = `<div class="error">错误: ${data.error}</div>`;
}
} catch (error) {
results.innerHTML = `<div class="error">请求失败: ${error.message}</div>`;
} finally {
loading.classList.remove('active');
}
}
function goToBidListPage(page) {
if (page < 1) return;
fetchBidList(page);
}
function updateBidListPagination(page, hasData) {
const pagination = document.getElementById('bidListPagination');
const currentPageSpan = document.getElementById('bidCurrentPage');
const prevBtn = document.getElementById('bidPrevPage');
const firstBtn = document.getElementById('bidFirstPage');
const nextBtn = document.getElementById('bidNextPage');
if (hasData) {
pagination.style.display = 'flex';
currentPageSpan.textContent = page;
prevBtn.disabled = page <= 1;
firstBtn.disabled = page <= 1;
nextBtn.disabled = !hasData;
}
}
function displayBidList(items, container) {
if (items.length === 0) {
container.innerHTML = '<p>没有找到招标公告</p>';
return;
}
const html = `
<div class="simple-list">
<h3 style="margin-bottom: 15px; color: #e67e22;">找到 ${items.length} 条招标公告</h3>
${items.map((item, index) => `
<div class="list-item" style="border-left-color: #e67e22;">
<h3>${index + 1}. ${item.title}</h3>
<div class="meta">发布日期: ${item.date}</div>
${item.href ? `<a href="${item.href}" target="_blank" style="color: #e67e22;">查看详情 →</a>` : ''}
</div>
`).join('')}
</div>
`;
container.innerHTML = html;
}
// ========== 综合报告功能 ==========
let currentWinningReport = null;
let currentBidReport = null;
// 初始化报告日期
function initReportDates() {
const today = new Date();
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
document.getElementById('startDate').value = firstDayOfMonth.toISOString().split('T')[0];
document.getElementById('endDate').value = today.toISOString().split('T')[0];
}
// 生成综合报告(同时包含中标和招标)
async function generateCombinedReport() {
const startDate = document.getElementById('startDate').value;
const endDate = document.getElementById('endDate').value;
const maxPages = parseInt(document.getElementById('maxPages').value) || 10;
const winningThreshold = parseFloat(document.getElementById('reportThreshold').value) * 10000 || 0; // 转换为元
const bidThreshold = parseFloat(document.getElementById('bidReportThreshold').value) * 10000 || 0;
if (!startDate && !endDate) {
alert('请至少填写开始日期或结束日期');
return;
}
const loading = document.getElementById('reportLoading');
const loadingText = document.getElementById('reportLoadingText');
const results = document.getElementById('reportResults');
const sendBtn = document.getElementById('sendEmailBtn');
loading.classList.add('active');
results.innerHTML = '';
sendBtn.style.display = 'none';
try {
// 1. 先获取中标报告
loadingText.textContent = '正在采集中标公示...';
const winningResponse = await fetch(`${API_BASE}/report-daterange`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ startDate, endDate, threshold: winningThreshold, maxPages })
});
const winningData = await winningResponse.json();
// 2. 再获取招标报告
loadingText.textContent = '正在采集招标公告...';
const bidResponse = await fetch(`${API_BASE}/bid-announce/report`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ startDate, endDate, maxPages, threshold: bidThreshold })
});
const bidData = await bidResponse.json();
// 3. 显示综合报告
if (winningData.success && bidData.success) {
currentWinningReport = winningData.data;
currentBidReport = bidData.data;
displayCombinedReport(winningData.data, bidData.data, results);
sendBtn.style.display = 'inline-block';
} else {
let errorMsg = '';
if (!winningData.success) errorMsg += `中标报告错误: ${winningData.error}\n`;
if (!bidData.success) errorMsg += `招标报告错误: ${bidData.error}`;
results.innerHTML = `<div class="error">${errorMsg}</div>`;
}
} catch (error) {
results.innerHTML = `<div class="error">请求失败: ${error.message}</div>`;
} finally {
loading.classList.remove('active');
loadingText.textContent = '正在生成报告...';
}
}
// 显示综合报告
function displayCombinedReport(winningReport, bidReport, container) {
const html = `
<!-- 中标公示部分 -->
<div class="summary" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);">
<h2>中标公示报告</h2>
<div class="stat">
<div class="stat-label">总项目数</div>
<div class="stat-value">${winningReport.summary.total_count}</div>
</div>
<div class="stat">
<div class="stat-label">符合条件</div>
<div class="stat-value">${winningReport.summary.filtered_count}</div>
</div>
<div class="stat">
<div class="stat-label">总金额</div>
<div class="stat-value">${winningReport.summary.total_amount}</div>
</div>
<div class="stat">
<div class="stat-label">阈值</div>
<div class="stat-value">${winningReport.summary.threshold}</div>
</div>
</div>
${winningReport.projects.length === 0 ? '<p style="color: #999; margin-bottom: 20px;">暂无符合条件的中标项目</p>' : `
<h3 style="margin-bottom: 15px;">中标项目列表 (${winningReport.projects.length} 条)</h3>
<div class="simple-list" style="margin-bottom: 30px;">
${winningReport.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>
<span class="budget">${project.winningBid.amount}${project.winningBid.unit}</span>
${project.url ? `<br><a href="${project.url}" target="_blank">查看详情 →</a>` : ''}
</div>
`).join('')}
</div>
`}
<!-- 招标公告部分 -->
<div class="summary" style="background: linear-gradient(135deg, #e67e22 0%, #d35400 100%); margin-top: 30px;">
<h2>招标公告报告</h2>
<div class="stat">
<div class="stat-label">总公告数量</div>
<div class="stat-value">${bidReport.summary.total_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">有金额信息</div>
<div class="stat-value">${bidReport.summary.has_amount_count || bidReport.summary.filtered_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">金额阈值</div>
<div class="stat-value">${bidReport.summary.threshold || '无'}</div>
</div>
<div class="stat">
<div class="stat-label">合同估算总额</div>
<div class="stat-value">${bidReport.summary.total_amount}</div>
</div>
</div>
${bidReport.projects.length === 0 ? '<p style="color: #999;">暂无符合条件的招标项目</p>' : `
<h3 style="margin-bottom: 15px; color: #e67e22;">招标项目详情 (${bidReport.projects.length} 条)</h3>
<div class="simple-list">
${bidReport.projects.map((item, index) => `
<div class="list-item" style="border-left-color: #e67e22;">
<h3>${index + 1}. ${item.title}</h3>
<div class="meta">发布日期: ${item.date}</div>
${item.bidCode ? `<div class="meta">标段编码: ${item.bidCode}</div>` : ''}
${item.tenderee ? `<div class="meta">招标人: ${item.tenderee}</div>` : ''}
${item.duration ? `<div class="meta">工期: ${item.duration} 日历天</div>` : ''}
${item.estimatedAmount ? `
<span class="budget" style="background: #e67e22;">合同估算价: ${item.estimatedAmount.amountWan} 万元</span>
` : ''}
<br><a href="${item.url}" target="_blank" style="color: #e67e22;">查看详情 →</a>
</div>
`).join('')}
</div>
`}
`;
container.innerHTML = html;
}
// 发送综合报告邮件
async function sendCombinedReportByEmail() {
if (!currentWinningReport && !currentBidReport) {
alert('请先生成报告');
return;
}
// 从localStorage获取邮件配置
const emailConfigStr = localStorage.getItem('emailConfig');
if (!emailConfigStr) {
alert('请先在"邮件配置"页面配置邮件服务器信息');
return;
}
let emailConfig;
try {
emailConfig = JSON.parse(emailConfigStr);
} catch (e) {
alert('邮件配置解析失败,请重新配置');
return;
}
if (!emailConfig.smtpHost || !emailConfig.smtpUser || !emailConfig.smtpPass || !emailConfig.recipients) {
alert('邮件配置不完整,请检查SMTP服务器、用户名、密码和收件人');
return;
}
if (!confirm(`确定要将综合报告发送到以下邮箱吗?\n\n${emailConfig.recipients}`)) {
return;
}
const sendBtn = document.getElementById('sendEmailBtn');
const originalText = sendBtn.textContent;
sendBtn.disabled = true;
sendBtn.textContent = '正在发送...';
try {
const response = await fetch(`${API_BASE}/send-combined-email`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
emailConfig,
winningReport: currentWinningReport,
bidReport: currentBidReport
})
});
const data = await response.json();
if (data.success) {
alert('综合报告邮件发送成功!');
} else {
alert(`邮件发送失败: ${data.error}`);
}
} catch (error) {
alert(`请求失败: ${error.message}`);
} finally {
sendBtn.disabled = false;
sendBtn.textContent = originalText;
}
}
// 页面加载时初始化报告日期
document.addEventListener('DOMContentLoaded', function() {
initReportDates();
});

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>南京公共资源交易平台 - 合同估算价采集工具</title>
<title>南京公共资源交易平台 - 中标价格采集工具</title>
<style>
* {
margin: 0;
@@ -329,11 +329,12 @@
<div class="container">
<div class="header">
<h1>南京公共资源交易平台</h1>
<p>房建市政招标公告 - 合同估算价采集工具</p>
<p>交通水务中标结果公示 - 中标价格采集工具</p>
</div>
<div class="tabs">
<button class="tab active" onclick="switchTab('list')">公告列表</button>
<button class="tab active" onclick="switchTab('list')">中标公示</button>
<button class="tab" onclick="switchTab('bidAnnounce')">招标公告</button>
<button class="tab" onclick="switchTab('report')">生成报告</button>
<button class="tab" onclick="switchTab('scheduler')">定时任务</button>
<button class="tab" onclick="switchTab('email')">邮件配置</button>
@@ -363,16 +364,37 @@
</div>
</div>
<!-- 生成报-->
<div id="report" class="tab-content">
<!-- 招标公-->
<div id="bidAnnounce" class="tab-content">
<h2 style="margin-bottom: 20px; color: #e67e22;">交通水务招标公告</h2>
<p style="color: #666; margin-bottom: 20px;">浏览招标公告列表</p>
<div class="form-group">
<div class="checkbox-wrapper" onclick="document.getElementById('useDateRange').click();">
<input type="checkbox" id="useDateRange" onchange="toggleDateRange()" onclick="event.stopPropagation();">
<label for="useDateRange">按时间范围采集</label>
<label>页码 (第1页为最新公告)</label>
<input type="number" id="bidListPage" value="1" min="1" max="300">
</div>
<button class="btn" onclick="fetchBidList()" style="background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);">获取招标列表</button>
<div id="bidListLoading" class="loading">
<div class="spinner"></div>
<p>正在获取招标公告列表...</p>
</div>
<div id="bidListResults" class="results"></div>
<div id="bidListPagination" class="pagination" style="display:none;">
<button onclick="goToBidListPage(1)" id="bidFirstPage" style="border-color: #e67e22; color: #e67e22;">首页</button>
<button onclick="goToBidListPage(currentBidListPage - 1)" id="bidPrevPage" style="border-color: #e67e22; color: #e67e22;">上一页</button>
<span class="page-info"><span id="bidCurrentPage">1</span></span>
<button onclick="goToBidListPage(currentBidListPage + 1)" id="bidNextPage" style="border-color: #e67e22; color: #e67e22;">下一页</button>
</div>
</div>
<div id="dateRangeFields" style="display:none;">
<!-- 生成报告 -->
<div id="report" class="tab-content">
<h2 style="margin-bottom: 20px; color: #667eea;">生成综合报告</h2>
<p style="color: #666; margin-bottom: 20px;">同时采集中标公示和招标公告,生成综合报告</p>
<div class="form-group">
<label>开始日期</label>
<input type="date" id="startDate">
@@ -385,27 +407,21 @@
<label>最大采集页数</label>
<input type="number" id="maxPages" value="10" min="1" max="50">
</div>
</div>
<div id="normalFields">
<div class="form-group">
<label>采集数量</label>
<input type="number" id="reportLimit" value="50" min="1" max="200">
<label>中标金额阈值 (万元) - 只显示大于此金额的中标项目0表示不筛选</label>
<input type="number" id="reportThreshold" value="10000" min="0" step="100">
</div>
</div>
<div class="form-group">
<label>金额阈值 (万元) - 只显示大于此金额的项目</label>
<input type="number" id="reportThreshold" value="100000" min="0" step="100">
<label>招标金额阈值 (万元) - 只显示大于此金额的招标项目0表示不筛选</label>
<input type="number" id="bidReportThreshold" value="0" min="0" step="100">
</div>
<button class="btn" onclick="generateReport()">生成报告</button>
<button class="btn export-btn" onclick="exportReport()" id="exportBtn" style="display:none;">导出Word</button>
<button class="btn" onclick="sendReportByEmail()" id="sendEmailBtn" style="display:none; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">发送邮件</button>
<button class="btn" onclick="generateCombinedReport()">生成综合报告</button>
<button class="btn" onclick="sendCombinedReportByEmail()" id="sendEmailBtn" style="display:none; background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);">发送邮件</button>
<div id="reportLoading" class="loading">
<div class="spinner"></div>
<p>正在生成报告...</p>
<p id="reportLoadingText">正在生成报告...</p>
</div>
<div id="reportResults" class="results"></div>
@@ -429,8 +445,12 @@
<div style="font-size: 20px; font-weight: bold; margin-top: 5px;" id="schedulerCronTime">-</div>
</div>
<div>
<div style="opacity: 0.9; font-size: 14px;">金额阈值</div>
<div style="font-size: 20px; font-weight: bold; margin-top: 5px;" id="schedulerThreshold">-</div>
<div style="opacity: 0.9; font-size: 14px;">中标阈值</div>
<div style="font-size: 20px; font-weight: bold; margin-top: 5px;" id="schedulerWinningThreshold">-</div>
</div>
<div>
<div style="opacity: 0.9; font-size: 14px;">招标阈值</div>
<div style="font-size: 20px; font-weight: bold; margin-top: 5px;" id="schedulerBidThreshold">-</div>
</div>
</div>
</div>
@@ -493,13 +513,21 @@
</div>
<div class="form-group">
<label>金额阈值 (万元)</label>
<input type="number" id="schedulerThresholdInput" value="100000" min="0" step="1000">
<label>中标金额阈值 (万元) - 只采集大于此金额的中标公示</label>
<input type="number" id="schedulerWinningThresholdInput" value="100000" min="0" step="1000">
<small style="color: #666; display: block; margin-top: 5px;">
10亿 = 100000万元 | 5亿 = 50000万元 | 1亿 = 10000万元
</small>
</div>
<div class="form-group">
<label>招标金额阈值 (万元) - 只采集大于此金额的招标公告0表示不筛选</label>
<input type="number" id="schedulerBidThresholdInput" value="0" min="0" step="1000">
<small style="color: #666; display: block; margin-top: 5px;">
设为0时不筛选金额只要有合同估算价的招标公告都会采集
</small>
</div>
<div class="form-group">
<label>任务描述 (可选)</label>
<input type="text" id="schedulerDescription" placeholder="例如: 每天9点采集大于1亿的项目">
@@ -514,10 +542,10 @@
<div style="margin-top: 30px; padding: 20px; background: #fff3cd; border-radius: 8px; border-left: 4px solid #ffc107;">
<h3 style="margin-top: 0; color: #856404;">使用说明</h3>
<ul style="line-height: 1.8; color: #856404;">
<li><strong>数据来源:</strong> 南京公共资源交易平台 - 房建市政招标公告</li>
<li><strong>采集内容:</strong> 标段编号、项目名称、标段名称、合同估算价、发布日期</li>
<li><strong>筛选条件:</strong> 只保留合同估算价大于设定阈值的项目</li>
<li><strong>邮件发送:</strong> 自动将筛选结果生成HTML报告并发送到配置的邮箱</li>
<li><strong>数据来源:</strong> 南京公共资源交易平台 - 交通水务中标公示 + 招标公告</li>
<li><strong>中标采集:</strong> 标段编号、项目名称、标段名称、中标价格、中标日期(按中标阈值筛选)</li>
<li><strong>招标采集:</strong> 项目名称、标段编码、招标人、合同估算价、工期按招标阈值筛选0表示不筛选</li>
<li><strong>邮件发送:</strong> 自动将中标+招标综合报告生成HTML邮件并发送到配置的邮箱</li>
</ul>
</div>
</div>
@@ -573,7 +601,7 @@
</div>
</div>
<script src="https://unpkg.com/docx@7.8.2/build/index.js"></script>
<script src="app.js"></script>
<!-- docx库已改为按需加载,只在用户点击导出时才加载,提升首屏加载速度 -->
<script src="app.js" defer></script>
</body>
</html>

View File

@@ -21,7 +21,7 @@ export async function sendReportEmail(emailConfig, report) {
const info = await transporter.sendMail({
from: `"公告采集系统" <${emailConfig.smtpUser}>`,
to: emailConfig.recipients,
subject: `采购公告分析报告 - ${new Date().toLocaleDateString('zh-CN')}`,
subject: `交通水务中标结果报告 - ${new Date().toLocaleDateString('zh-CN')}`,
html: htmlContent,
});
@@ -35,6 +35,523 @@ export async function sendReportEmail(emailConfig, report) {
}
}
// 发送招标公告报告邮件
export async function sendBidAnnounceReportEmail(emailConfig, report) {
try {
const transporter = nodemailer.createTransport({
host: emailConfig.smtpHost,
port: emailConfig.smtpPort || 587,
secure: emailConfig.smtpPort === 465,
auth: {
user: emailConfig.smtpUser,
pass: emailConfig.smtpPass,
},
});
const htmlContent = generateBidAnnounceReportHtml(report);
const info = await transporter.sendMail({
from: `"公告采集系统" <${emailConfig.smtpUser}>`,
to: emailConfig.recipients,
subject: `交通水务招标公告报告 - ${new Date().toLocaleDateString('zh-CN')}`,
html: htmlContent,
});
return {
success: true,
messageId: info.messageId,
};
} catch (error) {
console.error('发送招标公告邮件失败:', error);
throw new Error(`邮件发送失败: ${error.message}`);
}
}
// 生成招标公告报告HTML
function generateBidAnnounceReportHtml(report) {
const { summary, projects } = report;
return `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>交通水务招标公告报告</title>
<style>
body {
font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 900px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
border-radius: 8px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #e67e22;
border-bottom: 3px solid #e67e22;
padding-bottom: 10px;
margin-bottom: 20px;
}
.summary {
background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
color: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 30px;
}
.summary h2 {
margin-top: 0;
margin-bottom: 15px;
font-size: 18px;
}
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 15px;
}
.stat {
background: rgba(255,255,255,0.15);
padding: 12px;
border-radius: 6px;
}
.stat-label {
font-size: 13px;
opacity: 0.9;
margin-bottom: 5px;
}
.stat-value {
font-size: 20px;
font-weight: bold;
}
.project-list {
margin-top: 20px;
}
.project-item {
background: #f9f9f9;
border-left: 4px solid #e67e22;
padding: 15px;
margin-bottom: 15px;
border-radius: 4px;
}
.project-item h3 {
color: #333;
margin: 0 0 10px 0;
font-size: 15px;
line-height: 1.4;
}
.project-meta {
color: #666;
font-size: 13px;
margin: 5px 0;
}
.amount {
display: inline-block;
background: #e67e22;
color: white;
padding: 4px 12px;
border-radius: 4px;
font-weight: bold;
margin-top: 8px;
font-size: 14px;
}
.project-link {
color: #e67e22;
text-decoration: none;
font-size: 12px;
word-break: break-all;
}
.footer {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #e0e0e0;
color: #999;
font-size: 12px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h1>南京公共资源交易平台 - 交通水务招标公告报告</h1>
<div class="summary">
<h2>报告摘要</h2>
<div class="stat-grid">
<div class="stat">
<div class="stat-label">总公告数量</div>
<div class="stat-value">${summary.total_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">有金额信息</div>
<div class="stat-value">${summary.has_amount_count || summary.filtered_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">符合筛选</div>
<div class="stat-value">${summary.filtered_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">金额阈值</div>
<div class="stat-value">${summary.threshold || '无'}</div>
</div>
<div class="stat">
<div class="stat-label">合同估算总额</div>
<div class="stat-value">${summary.total_amount}</div>
</div>
</div>
${summary.date_range ? `
<div style="margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.2);">
<div class="stat-label">时间范围</div>
<div style="font-size: 14px; margin-top: 5px;">
${summary.date_range.startDate || '不限'}${summary.date_range.endDate || '不限'}
</div>
</div>
` : ''}
</div>
<h2>招标项目详情</h2>
<div class="project-list">
${projects.length === 0 ? '<p style="color: #999; text-align: center; padding: 20px;">暂无符合条件的项目</p>' : ''}
${projects.map((project, index) => `
<div class="project-item">
<h3>${index + 1}. ${project.title}</h3>
<div class="project-meta">
<strong>发布日期:</strong> ${project.date}
${project.bidCode ? ` | <strong>标段编码:</strong> ${project.bidCode}` : ''}
</div>
${project.tenderee ? `
<div class="project-meta">
<strong>招标人:</strong> ${project.tenderee}
${project.duration ? ` | <strong>工期:</strong> ${project.duration}日历天` : ''}
</div>
` : ''}
${project.estimatedAmount ? `
<div class="amount">
合同估算价: ${project.estimatedAmount.amountWan} 万元
</div>
` : ''}
<div style="margin-top: 10px;">
<a href="${project.url}" class="project-link" target="_blank">${project.url}</a>
</div>
</div>
`).join('')}
</div>
<div class="footer">
<p>报告生成时间: ${new Date(summary.generated_at).toLocaleString('zh-CN')}</p>
<p>本报告由公告采集系统自动生成</p>
</div>
</div>
</body>
</html>
`;
}
// 发送综合报告邮件(中标+招标)
export async function sendCombinedReportEmail(emailConfig, winningReport, bidReport) {
try {
const transporter = nodemailer.createTransport({
host: emailConfig.smtpHost,
port: emailConfig.smtpPort || 587,
secure: emailConfig.smtpPort === 465,
auth: {
user: emailConfig.smtpUser,
pass: emailConfig.smtpPass,
},
});
const htmlContent = generateCombinedReportHtml(winningReport, bidReport);
const info = await transporter.sendMail({
from: `"公告采集系统" <${emailConfig.smtpUser}>`,
to: emailConfig.recipients,
subject: `交通水务综合报告 - ${new Date().toLocaleDateString('zh-CN')}`,
html: htmlContent,
});
return {
success: true,
messageId: info.messageId,
};
} catch (error) {
console.error('发送综合邮件失败:', error);
throw new Error(`邮件发送失败: ${error.message}`);
}
}
// 生成综合报告HTML中标+招标)
function generateCombinedReportHtml(winningReport, bidReport) {
return `
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>交通水务综合报告</title>
<style>
body {
font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 900px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
border-radius: 8px;
padding: 30px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
border-bottom: 3px solid #667eea;
padding-bottom: 10px;
margin-bottom: 30px;
text-align: center;
}
.section {
margin-bottom: 40px;
}
.section-title {
font-size: 20px;
font-weight: bold;
margin-bottom: 15px;
padding: 10px 15px;
border-radius: 6px;
}
.section-title.winning {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.section-title.bid {
background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
color: white;
}
.summary {
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
.summary.winning {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.summary.bid {
background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
color: white;
}
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 15px;
}
.stat {
background: rgba(255,255,255,0.15);
padding: 10px;
border-radius: 6px;
}
.stat-label {
font-size: 12px;
opacity: 0.9;
margin-bottom: 5px;
}
.stat-value {
font-size: 18px;
font-weight: bold;
}
.project-list {
margin-top: 15px;
}
.project-item {
background: #f9f9f9;
padding: 12px;
margin-bottom: 10px;
border-radius: 4px;
}
.project-item.winning {
border-left: 4px solid #667eea;
}
.project-item.bid {
border-left: 4px solid #e67e22;
}
.project-item h3 {
color: #333;
margin: 0 0 8px 0;
font-size: 14px;
line-height: 1.4;
}
.project-meta {
color: #666;
font-size: 12px;
margin: 3px 0;
}
.amount {
display: inline-block;
color: white;
padding: 3px 10px;
border-radius: 4px;
font-weight: bold;
margin-top: 6px;
font-size: 13px;
}
.amount.winning {
background: #667eea;
}
.amount.bid {
background: #e67e22;
}
.project-link {
text-decoration: none;
font-size: 11px;
word-break: break-all;
}
.project-link.winning {
color: #667eea;
}
.project-link.bid {
color: #e67e22;
}
.footer {
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid #e0e0e0;
color: #999;
font-size: 12px;
text-align: center;
}
.no-data {
color: #999;
text-align: center;
padding: 20px;
font-style: italic;
}
</style>
</head>
<body>
<div class="container">
<h1>南京公共资源交易平台 - 交通水务综合报告</h1>
${bidReport ? `
<!-- 招标公告部分 -->
<div class="section">
<div class="section-title bid">招标公告</div>
<div class="summary bid">
<div class="stat-grid">
<div class="stat">
<div class="stat-label">总公告数量</div>
<div class="stat-value">${bidReport.summary.total_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">有金额信息</div>
<div class="stat-value">${bidReport.summary.has_amount_count || bidReport.summary.filtered_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">符合筛选</div>
<div class="stat-value">${bidReport.summary.filtered_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">金额阈值</div>
<div class="stat-value">${bidReport.summary.threshold || '无'}</div>
</div>
<div class="stat">
<div class="stat-label">合同估算总额</div>
<div class="stat-value">${bidReport.summary.total_amount}</div>
</div>
</div>
${bidReport.summary.date_range ? `
<div style="margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.2); font-size: 13px;">
时间范围: ${bidReport.summary.date_range.startDate || '不限'}${bidReport.summary.date_range.endDate || '不限'}
</div>
` : ''}
</div>
<div class="project-list">
${bidReport.projects.length === 0 ? '<p class="no-data">暂无符合条件的招标项目</p>' : ''}
${bidReport.projects.map((project, index) => `
<div class="project-item bid">
<h3>${index + 1}. ${project.title}</h3>
<div class="project-meta"><strong>发布日期:</strong> ${project.date}</div>
${project.bidCode ? `<div class="project-meta"><strong>标段编码:</strong> ${project.bidCode}</div>` : ''}
${project.tenderee ? `<div class="project-meta"><strong>招标人:</strong> ${project.tenderee}</div>` : ''}
${project.duration ? `<div class="project-meta"><strong>工期:</strong> ${project.duration}日历天</div>` : ''}
${project.estimatedAmount ? `
<div class="amount bid">合同估算价: ${project.estimatedAmount.amountWan} 万元</div>
` : ''}
<div style="margin-top: 8px;">
<a href="${project.url}" class="project-link bid" target="_blank">${project.url}</a>
</div>
</div>
`).join('')}
</div>
</div>
` : ''}
${winningReport ? `
<!-- 中标公示部分 -->
<div class="section">
<div class="section-title winning">中标结果公示</div>
<div class="summary winning">
<div class="stat-grid">
<div class="stat">
<div class="stat-label">总项目数</div>
<div class="stat-value">${winningReport.summary.total_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">符合条件</div>
<div class="stat-value">${winningReport.summary.filtered_count} 条</div>
</div>
<div class="stat">
<div class="stat-label">金额阈值</div>
<div class="stat-value">${winningReport.summary.threshold}</div>
</div>
<div class="stat">
<div class="stat-label">总金额</div>
<div class="stat-value">${winningReport.summary.total_amount}</div>
</div>
</div>
${winningReport.summary.date_range ? `
<div style="margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.2); font-size: 13px;">
时间范围: ${winningReport.summary.date_range.startDate || '不限'}${winningReport.summary.date_range.endDate || '不限'}
</div>
` : ''}
</div>
<div class="project-list">
${winningReport.projects.length === 0 ? '<p class="no-data">暂无符合条件的中标项目</p>' : ''}
${winningReport.projects.map((project, index) => `
<div class="project-item winning">
<h3>${index + 1}. ${project.title}</h3>
<div class="project-meta"><strong>中标日期:</strong> ${project.date}</div>
${project.bidNo ? `<div class="project-meta"><strong>标段编号:</strong> ${project.bidNo}</div>` : ''}
${project.winningBid ? `
<div class="amount winning">中标金额: ${project.winningBid.amount.toFixed(2)} ${project.winningBid.unit}</div>
` : ''}
<div style="margin-top: 8px;">
<a href="${project.url}" class="project-link winning" target="_blank">${project.url}</a>
</div>
</div>
`).join('')}
</div>
</div>
` : ''}
<div class="footer">
<p>报告生成时间: ${new Date().toLocaleString('zh-CN')}</p>
<p>本报告由公告采集系统自动生成</p>
</div>
</div>
</body>
</html>
`;
}
// 生成HTML格式的报告
function generateReportHtml(report) {
const { summary, projects } = report;
@@ -45,7 +562,7 @@ function generateReportHtml(report) {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>采购公告分析报告</title>
<title>交通水务中标结果报告</title>
<style>
body {
font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
@@ -147,7 +664,7 @@ function generateReportHtml(report) {
</head>
<body>
<div class="container">
<h1>南京公共工程建设中心 - 采购公告分析报告</h1>
<h1>南京公共资源交易平台 - 交通水务中标结果报告</h1>
<div class="summary">
<h2>报告摘要</h2>
@@ -186,15 +703,17 @@ function generateReportHtml(report) {
<div class="project-item">
<h3>${index + 1}. ${project.title}</h3>
<div class="project-meta">
<strong>发布日期:</strong> ${project.date}
${project.publish_time ? ` | <strong>发布时间:</strong> ${project.publish_time}` : ''}
<strong>中标日期:</strong> ${project.date}
</div>
${project.budget ? `
${project.winningBid ? `
<div class="budget">
中标金额: ${project.winningBid.amount.toFixed(2)} ${project.winningBid.unit}
</div>
` : (project.budget ? `
<div class="budget">
预算金额: ${project.budget.amount.toFixed(2)} ${project.budget.unit}
${project.budget.originalUnit !== project.budget.unit ? ` (原始: ${project.budget.originalUnit})` : ''}
</div>
` : ''}
` : '')}
<div style="margin-top: 10px;">
<a href="${project.url}" class="project-link" target="_blank">${project.url}</a>
</div>

View File

@@ -5,7 +5,7 @@ import { dirname, join } from 'path';
import axios from 'axios';
import * as cheerio from 'cheerio';
import iconv from 'iconv-lite';
import { sendReportEmail } from './emailService.js';
import { sendCombinedReportEmail } from './emailService.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
@@ -62,8 +62,11 @@ function getDateRangeByType(timeRange) {
return { startDate, endDate };
}
// 南京市公共资源交易平台 - 房建市政招标公告
const BASE_URL = 'https://njggzy.nanjing.gov.cn/njweb/fjsz/068001/068001002/';
// 南京市公共资源交易平台 - 交通水务中标结果公示
const BASE_URL = 'https://njggzy.nanjing.gov.cn/njweb/jtsw/069008/';
// 南京市公共资源交易平台 - 交通水务招标公告
const BID_ANNOUNCE_BASE_URL = 'https://njggzy.nanjing.gov.cn/njweb/jtsw/069001/';
const http = axios.create({
responseType: 'arraybuffer',
@@ -90,12 +93,12 @@ async function fetchHtml(url) {
function getPageUrl(pageIndex) {
if (pageIndex === 1) {
return `${BASE_URL}moreinfo.html`;
return `${BASE_URL}moreinfosl3.html`;
}
return `${BASE_URL}${pageIndex}.html`;
}
// 解析列表页HTML提取招标信息
// 解析列表页HTML提取中标结果信息
function parseList(html) {
const $ = cheerio.load(html);
const items = [];
@@ -108,8 +111,8 @@ function parseList(html) {
const bidNo = $(cells[0]).find('p').attr('title') || $(cells[0]).find('p').text().trim();
const projectName = $(cells[1]).find('p').attr('title') || $(cells[1]).find('p').text().trim();
const bidName = $(cells[2]).find('p').attr('title') || $(cells[2]).find('p').text().trim();
const estimatedPrice = $(cells[3]).find('p').text().trim();
const publishDate = $(cells[4]).find('p').text().trim();
const winningPrice = $(cells[3]).find('p').text().trim(); // 中标价格
const winningDate = $(cells[4]).find('p').text().trim(); // 中标日期
const onclick = $row.attr('onclick') || '';
const hrefMatch = onclick.match(/window\.open\(['"]([^'"]+)['"]\)/);
@@ -121,20 +124,20 @@ function parseList(html) {
}
}
if (!/^\d{4}-\d{2}-\d{2}$/.test(publishDate)) return;
if (!/^\d{4}-\d{2}-\d{2}$/.test(winningDate)) return;
const price = parseFloat(estimatedPrice);
const price = parseFloat(winningPrice);
if (isNaN(price)) return;
items.push({
bidNo,
title: projectName,
bidName,
budget: {
winningBid: { // 中标金额
amount: price,
unit: '万元'
},
date: publishDate,
date: winningDate,
href
});
}
@@ -210,17 +213,177 @@ async function fetchListByDateRange(startDate, endDate, maxPages = 50) {
return allItems;
}
// ========== 招标公告采集函数 ==========
// 获取招标公告分页URL
function getBidAnnouncePageUrl(pageIndex) {
if (pageIndex === 1) {
return `${BID_ANNOUNCE_BASE_URL}moreinfo5dc.html`;
}
return `${BID_ANNOUNCE_BASE_URL}${pageIndex}.html`;
}
// 解析招标公告列表页HTML
function parseBidAnnounceList(html) {
const $ = cheerio.load(html);
const items = [];
$('li.ewb-info-item2').each((_, row) => {
const $row = $(row);
const onclick = $row.attr('onclick') || '';
const hrefMatch = onclick.match(/window\.open\(['"]([^'"]+)['"]\)/);
if (!hrefMatch) return;
let href = hrefMatch[1];
if (href.startsWith('/')) {
href = `https://njggzy.nanjing.gov.cn${href}`;
}
const $titleP = $row.find('.ewb-info-num2').first().find('p');
const title = $titleP.attr('title') || $titleP.text().trim();
const $dateP = $row.find('.ewb-info-num2').last().find('p');
const dateText = $dateP.text().trim();
const dateMatch = dateText.match(/\d{4}-\d{2}-\d{2}/);
const date = dateMatch ? dateMatch[0] : '';
if (title && date) {
items.push({
title,
date,
href,
estimatedAmount: null
});
}
});
return items;
}
// 解析招标公告详情页,获取合同估算价
async function fetchBidAnnounceDetail(url) {
try {
const html = await fetchHtml(url);
const $ = cheerio.load(html);
const bodyText = $('body').text();
const amountMatch = bodyText.match(/合同估算价[:]\s*([\d,]+\.?\d*)\s*元/);
let estimatedAmount = null;
if (amountMatch) {
const amountStr = amountMatch[1].replace(/,/g, '');
estimatedAmount = parseFloat(amountStr);
}
const bidCodeMatch = bodyText.match(/标段编码[:]\s*([A-Za-z0-9\-]+)/);
const bidCode = bidCodeMatch ? bidCodeMatch[1] : null;
const tendereeMatch = bodyText.match(/招标人[为是][:]?\s*([^\s,,。]+)/);
const tenderee = tendereeMatch ? tendereeMatch[1] : null;
const durationMatch = bodyText.match(/计划工期[:]\s*(\d+)\s*日历天/);
const duration = durationMatch ? parseInt(durationMatch[1]) : null;
return { estimatedAmount, bidCode, tenderee, duration, url };
} catch (error) {
console.error(`获取招标详情失败 ${url}: ${error.message}`);
return { estimatedAmount: null, url };
}
}
// 按时间范围采集招标公告
async function fetchBidAnnounceByDateRange(startDate, endDate, maxPages = 20) {
const allItems = [];
let shouldContinue = true;
let pageIndex = 1;
console.log(`开始采集招标公告: ${startDate || '不限'}${endDate || '不限'}`);
while (shouldContinue && pageIndex <= maxPages) {
const pageUrl = getBidAnnouncePageUrl(pageIndex);
console.log(`正在采集招标公告第 ${pageIndex} 页: ${pageUrl}`);
try {
const html = await fetchHtml(pageUrl);
const items = parseBidAnnounceList(html);
if (items.length === 0) {
console.log(`${pageIndex} 页没有数据,停止采集`);
break;
}
let hasItemsInRange = false;
let allItemsBeforeRange = true;
for (const item of items) {
if (isDateInRange(item.date, startDate, endDate)) {
allItems.push(item);
hasItemsInRange = true;
allItemsBeforeRange = false;
} else if (startDate && new Date(item.date) < new Date(startDate)) {
allItemsBeforeRange = allItemsBeforeRange && true;
} else {
allItemsBeforeRange = false;
}
}
if (allItemsBeforeRange && startDate) {
console.log(`${pageIndex} 页所有项目都早于起始日期,停止采集`);
shouldContinue = false;
}
console.log(`${pageIndex} 页找到 ${items.length} 条,符合条件 ${hasItemsInRange ? '有' : '无'}`);
pageIndex++;
if (shouldContinue && pageIndex <= maxPages) {
await new Promise(resolve => setTimeout(resolve, 500));
}
} catch (err) {
console.error(`采集第 ${pageIndex} 页失败: ${err.message}`);
break;
}
}
console.log(`总共采集了 ${pageIndex - 1} 页,找到 ${allItems.length} 条符合条件的招标公告`);
// 获取详情(合同估算价)
if (allItems.length > 0) {
console.log(`开始获取 ${allItems.length} 条招标公告的详情...`);
for (let i = 0; i < allItems.length; i++) {
const item = allItems[i];
console.log(`获取详情 ${i + 1}/${allItems.length}: ${item.title.substring(0, 30)}...`);
const detail = await fetchBidAnnounceDetail(item.href);
item.estimatedAmount = detail.estimatedAmount;
item.bidCode = detail.bidCode;
item.tenderee = detail.tenderee;
item.duration = detail.duration;
if (i < allItems.length - 1) {
await new Promise(resolve => setTimeout(resolve, 300));
}
}
console.log('招标公告详情获取完成');
}
return allItems;
}
// 定时任务执行函数
async function executeScheduledTask(config) {
try {
console.log('========================================');
console.log('定时任务开始执行');
console.log('定时任务开始执行(综合采集)');
console.log('执行时间:', new Date().toLocaleString('zh-CN'));
console.log('========================================');
const timeRange = config.scheduler.timeRange || 'thisMonth';
const { startDate, endDate } = getDateRangeByType(timeRange);
const threshold = config.scheduler.threshold || 10000; // 默认1亿(10000万元)
const winningThreshold = config.scheduler.winningThreshold !== undefined ? config.scheduler.winningThreshold : 10000; // 中标阈值,默认1亿(10000万元)
const bidThreshold = config.scheduler.bidThreshold !== undefined ? config.scheduler.bidThreshold : 0; // 招标阈值默认0(不筛选)
const timeRangeNames = {
'today': '今日',
@@ -229,65 +392,110 @@ async function executeScheduledTask(config) {
};
console.log(`采集时间段: ${timeRangeNames[timeRange] || '本月'}`);
console.log(`采集时间范围: ${startDate}${endDate}`);
console.log(`金额阈值: ${threshold}万元 (${(threshold / 10000).toFixed(2)}亿元)`);
console.log(`中标金额阈值: ${winningThreshold}万元 (${(winningThreshold / 10000).toFixed(2)}亿元)`);
console.log(`招标金额阈值: ${bidThreshold}万元 ${bidThreshold === 0 ? '(不筛选)' : `(${(bidThreshold / 10000).toFixed(2)}亿元)`}`);
// 采集列表(直接包含合同估算价)
const items = await fetchListByDateRange(startDate, endDate, 50);
// ========== 1. 采集中标公示 ==========
console.log('\n========== 采集中标公示 ==========');
const winningItems = await fetchListByDateRange(startDate, endDate, 50);
if (items.length === 0) {
console.log('暂无公告数据');
return;
}
// 筛选大于阈值的项目
const filtered = items.filter((item) => {
return item.budget && item.budget.amount > threshold;
// 筛选大于阈值的中标项目
const winningFiltered = winningItems.filter((item) => {
return item.winningBid && item.winningBid.amount > winningThreshold;
});
console.log('========================================');
console.log(`筛选结果: 找到 ${filtered.length} 个大于 ${threshold}万元 的项目`);
if (filtered.length === 0) {
console.log('暂无符合条件的大额项目');
return;
}
// 计算总金额
const total = filtered.reduce(
(sum, item) => sum + (item.budget?.amount || 0),
const winningTotal = winningFiltered.reduce(
(sum, item) => sum + (item.winningBid?.amount || 0),
0
);
// 生成报告
const report = {
console.log(`中标公示: 采集 ${winningItems.length} 条,符合阈值 ${winningFiltered.length}`);
// 生成中标报告
const winningReport = {
summary: {
total_count: items.length,
filtered_count: filtered.length,
threshold: `${threshold}万元`,
total_amount: `${total.toFixed(2)}万元`,
total_count: winningItems.length,
filtered_count: winningFiltered.length,
threshold: `${winningThreshold}万元`,
total_amount: `${winningTotal.toFixed(2)}万元`,
generated_at: new Date().toISOString(),
date_range: { startDate, endDate },
},
projects: filtered.map((item) => ({
projects: winningFiltered.map((item) => ({
bidNo: item.bidNo,
title: item.title,
bidName: item.bidName,
date: item.date,
budget: item.budget,
winningBid: item.winningBid,
url: item.href,
})),
};
// 发送邮件
// ========== 2. 采集招标公告 ==========
console.log('\n========== 采集招标公告 ==========');
const bidItems = await fetchBidAnnounceByDateRange(startDate, endDate, 20);
// 筛选招标项目根据阈值筛选阈值为0时不筛选只要求有金额
const bidFiltered = bidItems.filter(item => {
if (!item.estimatedAmount) return false;
if (bidThreshold === 0) return true; // 阈值为0时不筛选
return item.estimatedAmount / 10000 > bidThreshold; // 估算价是元,阈值是万元,需要转换
});
const bidTotal = bidFiltered.reduce(
(sum, item) => sum + (item.estimatedAmount || 0),
0
);
console.log(`招标公告: 采集 ${bidItems.length} 条,有金额 ${bidFiltered.length}`);
// 生成招标报告
const bidReport = {
summary: {
total_count: bidItems.length,
filtered_count: bidFiltered.length,
has_amount_count: bidFiltered.length,
threshold: bidThreshold === 0 ? '无' : `${bidThreshold}万元`,
total_amount: `${(bidTotal / 10000).toFixed(2)}万元`,
total_amount_yuan: bidTotal,
generated_at: new Date().toISOString(),
date_range: { startDate, endDate },
report_type: '招标公告'
},
projects: bidFiltered.map((item) => ({
title: item.title,
bidCode: item.bidCode,
tenderee: item.tenderee,
date: item.date,
duration: item.duration,
estimatedAmount: item.estimatedAmount ? {
amount: item.estimatedAmount,
amountWan: (item.estimatedAmount / 10000).toFixed(2),
unit: '元'
} : null,
url: item.href,
})),
};
// ========== 3. 检查是否有数据需要发送 ==========
if (winningFiltered.length === 0 && bidFiltered.length === 0) {
console.log('\n========================================');
console.log('暂无符合条件的项目,不发送邮件');
console.log('========================================');
console.log('正在发送邮件报告...');
return;
}
// ========== 4. 发送综合邮件 ==========
console.log('\n========================================');
console.log('正在发送综合报告邮件...');
const emailConfig = config.email;
const result = await sendReportEmail(emailConfig, report);
const result = await sendCombinedReportEmail(emailConfig, winningReport, bidReport);
console.log('邮件发送成功!');
console.log('收件人:', emailConfig.recipients);
console.log('MessageId:', result.messageId);
console.log(`内容: 中标公示 ${winningFiltered.length} 条,招标公告 ${bidFiltered.length}`);
console.log('========================================');
console.log('定时任务执行完成');
console.log('========================================');
@@ -328,7 +536,8 @@ export function initScheduler() {
console.log('========================================');
console.log('定时任务已启动');
console.log('执行计划:', cronTime);
console.log('金额阈值:', config.scheduler.threshold, '万元');
console.log('中标阈值:', config.scheduler.winningThreshold, '万元');
console.log('招标阈值:', config.scheduler.bidThreshold, '万元', config.scheduler.bidThreshold === 0 ? '(不筛选)' : '');
console.log('收件人:', config.email.recipients);
console.log('========================================');
@@ -380,7 +589,8 @@ export function getSchedulerStatus() {
config: config ? {
enabled: config.scheduler?.enabled || false,
cronTime: config.scheduler?.cronTime || '0 9 * * *',
threshold: config.scheduler?.threshold || 10000,
winningThreshold: config.scheduler?.winningThreshold !== undefined ? config.scheduler.winningThreshold : 10000,
bidThreshold: config.scheduler?.bidThreshold !== undefined ? config.scheduler.bidThreshold : 0,
timeRange: config.scheduler?.timeRange || 'thisMonth',
} : null,
};

View File

@@ -4,8 +4,9 @@ import cors from 'cors';
import axios from 'axios';
import * as cheerio from 'cheerio';
import iconv from 'iconv-lite';
import { sendReportEmail } from './emailService.js';
import { sendReportEmail, sendBidAnnounceReportEmail, sendCombinedReportEmail } from './emailService.js';
import { initScheduler, runTaskNow, reloadScheduler, getSchedulerStatus } from './scheduler.js';
import { log } from 'console';
const app = express();
const PORT = process.env.PORT || 5000;
@@ -14,17 +15,29 @@ app.use(cors());
app.use(express.json());
app.use(express.static('public'));
// 南京市公共资源交易平台 - 房建市政招标公告
const BASE_URL = 'https://njggzy.nanjing.gov.cn/njweb/fjsz/068001/068001002/';
// 南京市公共资源交易平台 - 交通水务中标结果公示
const BASE_URL = 'https://njggzy.nanjing.gov.cn/njweb/jtsw/069008/';
// 获取分页URL
// 南京市公共资源交易平台 - 交通水务招标公告
const BID_ANNOUNCE_BASE_URL = 'https://njggzy.nanjing.gov.cn/njweb/jtsw/069001/';
// 获取分页URL (实际数据在moreinfosl3.html中分页为2.html, 3.html...)
function getPageUrl(pageIndex) {
if (pageIndex === 1) {
return `${BASE_URL}moreinfo.html`;
return `${BASE_URL}moreinfosl3.html`;
}
return `${BASE_URL}${pageIndex}.html`;
}
// 获取招标公告分页URL
// 数据通过AJAX加载第1页是 moreinfo5dc.html第2页起是 2.html, 3.html...
function getBidAnnouncePageUrl(pageIndex) {
if (pageIndex === 1) {
return `${BID_ANNOUNCE_BASE_URL}moreinfo5dc.html`;
}
return `${BID_ANNOUNCE_BASE_URL}${pageIndex}.html`;
}
// 检查日期是否在范围内
function isDateInRange(dateStr, startDate, endDate) {
if (!dateStr) return false;
@@ -117,12 +130,12 @@ async function fetchHtml(url) {
return html;
}
// 解析列表页HTML提取招标信息
// 解析列表页HTML提取中标结果信息
function parseList(html) {
const $ = cheerio.load(html);
const items = [];
// 解析南京公共资源交易平台的列表结构
// 解析南京公共资源交易平台的列表结构(交通水务中标结果公示)
// <li class="ewb-info-item2 clearfix" onclick="window.open('详情URL');">
$('li.ewb-info-item2').each((_, row) => {
const $row = $(row);
@@ -133,8 +146,8 @@ function parseList(html) {
const bidNo = $(cells[0]).find('p').attr('title') || $(cells[0]).find('p').text().trim();
const projectName = $(cells[1]).find('p').attr('title') || $(cells[1]).find('p').text().trim();
const bidName = $(cells[2]).find('p').attr('title') || $(cells[2]).find('p').text().trim();
const estimatedPrice = $(cells[3]).find('p').text().trim();
const publishDate = $(cells[4]).find('p').text().trim();
const winningPrice = $(cells[3]).find('p').text().trim(); // 中标价格
const winningDate = $(cells[4]).find('p').text().trim(); // 中标日期
// 从onclick提取详情链接
const onclick = $row.attr('onclick') || '';
@@ -149,21 +162,21 @@ function parseList(html) {
}
// 验证日期格式 (YYYY-MM-DD)
if (!/^\d{4}-\d{2}-\d{2}$/.test(publishDate)) return;
if (!/^\d{4}-\d{2}-\d{2}$/.test(winningDate)) return;
// 解析合同估算价
const price = parseFloat(estimatedPrice);
// 解析中标价格
const price = parseFloat(winningPrice);
if (isNaN(price)) return;
items.push({
bidNo, // 标段编号
title: projectName, // 项目名称
bidName, // 标段名称
budget: {
winningBid: { // 中标金额
amount: price,
unit: '万元'
},
date: publishDate,
date: winningDate, // 中标日期
href
});
}
@@ -172,6 +185,175 @@ function parseList(html) {
return items;
}
// 解析招标公告列表页HTML
function parseBidAnnounceList(html) {
const $ = cheerio.load(html);
const items = [];
// 解析南京公共资源交易平台的招标公告列表结构
// <li class="ewb-info-item2 clearfix" onclick="window.open('...');">
$('li.ewb-info-item2').each((_, row) => {
const $row = $(row);
const onclick = $row.attr('onclick') || '';
// 提取详情链接
const hrefMatch = onclick.match(/window\.open\(['"]([^'"]+)['"]\)/);
if (!hrefMatch) return;
let href = hrefMatch[1];
if (href.startsWith('/')) {
href = `https://njggzy.nanjing.gov.cn${href}`;
}
// 获取标题从p标签的title属性或文本
const $titleP = $row.find('.ewb-info-num2').first().find('p');
const title = $titleP.attr('title') || $titleP.text().trim();
// 获取日期
const $dateP = $row.find('.ewb-info-num2').last().find('p');
const dateText = $dateP.text().trim();
const dateMatch = dateText.match(/\d{4}-\d{2}-\d{2}/);
const date = dateMatch ? dateMatch[0] : '';
if (title && date) {
items.push({
title,
date,
href,
estimatedAmount: null
});
}
});
return items;
}
// 解析招标公告详情页,获取合同估算价
async function fetchBidAnnounceDetail(url) {
try {
const html = await fetchHtml(url);
const $ = cheerio.load(html);
// 获取页面全部文本
const bodyText = $('body').text();
// 查找合同估算价 (格式如: 合同估算价4,300,000.00 元)
const amountMatch = bodyText.match(/合同估算价[:]\s*([\d,]+\.?\d*)\s*元/);
let estimatedAmount = null;
if (amountMatch) {
// 去掉逗号,转换为数字(单位:元)
const amountStr = amountMatch[1].replace(/,/g, '');
estimatedAmount = parseFloat(amountStr);
}
// 获取标段编码
const bidCodeMatch = bodyText.match(/标段编码[:]\s*([A-Za-z0-9\-]+)/);
const bidCode = bidCodeMatch ? bidCodeMatch[1] : null;
// 获取招标人
const tendereeMatch = bodyText.match(/招标人[为是][:]?\s*([^\s,,。]+)/);
const tenderee = tendereeMatch ? tendereeMatch[1] : null;
// 获取计划工期
const durationMatch = bodyText.match(/计划工期[:]\s*(\d+)\s*日历天/);
const duration = durationMatch ? parseInt(durationMatch[1]) : null;
return {
estimatedAmount,
bidCode,
tenderee,
duration,
url
};
} catch (error) {
console.error(`获取招标详情失败 ${url}: ${error.message}`);
return { estimatedAmount: null, url };
}
}
// 按时间范围采集招标公告
async function fetchBidAnnounceByDateRange(startDate, endDate, maxPages = 20, fetchDetails = true) {
const allItems = [];
let shouldContinue = true;
let pageIndex = 1;
console.log(`开始采集招标公告: ${startDate || '不限'}${endDate || '不限'}`);
while (shouldContinue && pageIndex <= maxPages) {
const pageUrl = getBidAnnouncePageUrl(pageIndex);
console.log(`正在采集招标公告第 ${pageIndex} 页: ${pageUrl}`);
try {
const html = await fetchHtml(pageUrl);
const items = parseBidAnnounceList(html);
if (items.length === 0) {
console.log(`${pageIndex} 页没有数据,停止采集`);
break;
}
let hasItemsInRange = false;
let allItemsBeforeRange = true;
for (const item of items) {
if (isDateInRange(item.date, startDate, endDate)) {
allItems.push(item);
hasItemsInRange = true;
allItemsBeforeRange = false;
} else if (startDate && new Date(item.date) < new Date(startDate)) {
allItemsBeforeRange = allItemsBeforeRange && true;
} else {
allItemsBeforeRange = false;
}
}
if (allItemsBeforeRange && startDate) {
console.log(`${pageIndex} 页所有项目都早于起始日期,停止采集`);
shouldContinue = false;
}
console.log(`${pageIndex} 页找到 ${items.length} 条,符合条件 ${hasItemsInRange ? '有' : '无'}`);
pageIndex++;
if (shouldContinue && pageIndex <= maxPages) {
await new Promise(resolve => setTimeout(resolve, 500));
}
} catch (err) {
console.error(`采集第 ${pageIndex} 页失败: ${err.message}`);
break;
}
}
console.log(`总共采集了 ${pageIndex - 1} 页,找到 ${allItems.length} 条符合条件的招标公告`);
// 如果需要获取详情(合同估算价)
if (fetchDetails && allItems.length > 0) {
console.log(`开始获取 ${allItems.length} 条招标公告的详情...`);
for (let i = 0; i < allItems.length; i++) {
const item = allItems[i];
console.log(`获取详情 ${i + 1}/${allItems.length}: ${item.title.substring(0, 30)}...`);
const detail = await fetchBidAnnounceDetail(item.href);
item.estimatedAmount = detail.estimatedAmount;
item.bidCode = detail.bidCode;
item.tenderee = detail.tenderee;
item.duration = detail.duration;
// 添加延迟避免请求过快
if (i < allItems.length - 1) {
await new Promise(resolve => setTimeout(resolve, 300));
}
}
console.log('详情获取完成');
}
return allItems;
}
// API 路由
// 获取列表
@@ -180,6 +362,7 @@ app.get('/api/list', async (req, res) => {
const page = parseInt(req.query.page) || 1;
const pageUrl = getPageUrl(page);
const html = await fetchHtml(pageUrl);
const items = parseList(html);
res.json({ success: true, data: items, page });
@@ -238,11 +421,11 @@ app.post('/api/report', async (req, res) => {
// 按阈值筛选
const filtered = results.filter((item) => {
return item.budget && item.budget.amount > threshold;
return item.winningBid && item.winningBid.amount > threshold;
});
const total = filtered.reduce(
(sum, item) => sum + (item.budget?.amount || 0),
(sum, item) => sum + (item.winningBid?.amount || 0),
0
);
@@ -259,7 +442,7 @@ app.post('/api/report', async (req, res) => {
title: item.title,
bidName: item.bidName,
date: item.date,
budget: item.budget,
winningBid: item.winningBid,
url: item.href,
})),
};
@@ -297,11 +480,11 @@ app.post('/api/report-daterange', async (req, res) => {
// 按阈值筛选
const filtered = items.filter((item) => {
return item.budget && item.budget.amount > threshold;
return item.winningBid && item.winningBid.amount > threshold;
});
const total = filtered.reduce(
(sum, item) => sum + (item.budget?.amount || 0),
(sum, item) => sum + (item.winningBid?.amount || 0),
0
);
@@ -319,7 +502,7 @@ app.post('/api/report-daterange', async (req, res) => {
title: item.title,
bidName: item.bidName,
date: item.date,
budget: item.budget,
winningBid: item.winningBid,
url: item.href,
})),
};
@@ -330,6 +513,186 @@ app.post('/api/report-daterange', async (req, res) => {
}
});
// ========== 招标公告相关API ==========
// 获取招标公告列表(简单列表,按页码)
app.get('/api/bid-announce/list', async (req, res) => {
try {
const page = parseInt(req.query.page) || 1;
const pageUrl = getBidAnnouncePageUrl(page);
const html = await fetchHtml(pageUrl);
const items = parseBidAnnounceList(html);
res.json({ success: true, data: items, page });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
// 获取招标公告列表(按时间范围)
app.post('/api/bid-announce/list', async (req, res) => {
try {
const { startDate, endDate, maxPages = 20, fetchDetails = false } = req.body;
const items = await fetchBidAnnounceByDateRange(startDate, endDate, maxPages, fetchDetails);
res.json({ success: true, data: items });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
// 生成招标公告报告(含金额统计)
app.post('/api/bid-announce/report', async (req, res) => {
try {
const { startDate, endDate, threshold = 0, maxPages = 20 } = req.body;
// 采集招标公告(包含详情)
const items = await fetchBidAnnounceByDateRange(startDate, endDate, maxPages, true);
if (items.length === 0) {
return res.json({
success: true,
data: {
summary: {
total_count: 0,
filtered_count: 0,
threshold: threshold > 0 ? `${threshold}` : '无',
total_amount: '0.00元',
generated_at: new Date().toISOString(),
date_range: { startDate, endDate },
report_type: '招标公告'
},
projects: [],
},
});
}
// 按阈值筛选(阈值单位为元)
const filtered = threshold > 0
? items.filter(item => item.estimatedAmount && item.estimatedAmount >= threshold)
: items.filter(item => item.estimatedAmount);
// 计算总金额
const total = filtered.reduce((sum, item) => sum + (item.estimatedAmount || 0), 0);
const report = {
summary: {
total_count: items.length,
filtered_count: filtered.length,
has_amount_count: items.filter(i => i.estimatedAmount).length,
threshold: threshold > 0 ? `${(threshold / 10000).toFixed(2)}万元` : '无',
total_amount: `${(total / 10000).toFixed(2)}万元`,
total_amount_yuan: total,
generated_at: new Date().toISOString(),
date_range: { startDate, endDate },
report_type: '招标公告'
},
projects: filtered.map((item) => ({
title: item.title,
bidCode: item.bidCode,
tenderee: item.tenderee,
date: item.date,
duration: item.duration,
estimatedAmount: item.estimatedAmount ? {
amount: item.estimatedAmount,
amountWan: (item.estimatedAmount / 10000).toFixed(2),
unit: '元'
} : null,
url: item.href,
})),
};
res.json({ success: true, data: report });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
});
// 发送招标公告报告邮件
app.post('/api/bid-announce/send-email', async (req, res) => {
try {
const { emailConfig, report } = req.body;
if (!emailConfig || !emailConfig.smtpHost || !emailConfig.smtpUser || !emailConfig.smtpPass) {
return res.status(400).json({
success: false,
error: '邮件配置不完整,请填写SMTP服务器、用户名和密码',
});
}
if (!emailConfig.recipients || emailConfig.recipients.trim() === '') {
return res.status(400).json({
success: false,
error: '请至少指定一个收件人',
});
}
if (!report) {
return res.status(400).json({
success: false,
error: '没有可发送的报告数据',
});
}
// 使用招标公告专用的邮件发送
const result = await sendBidAnnounceReportEmail(emailConfig, report);
res.json({
success: true,
message: '招标公告报告邮件发送成功',
messageId: result.messageId,
});
} catch (error) {
console.error('发送招标公告邮件API错误:', error);
res.status(500).json({
success: false,
error: error.message,
});
}
});
// 发送综合报告邮件(中标+招标)
app.post('/api/send-combined-email', async (req, res) => {
try {
const { emailConfig, winningReport, bidReport } = req.body;
if (!emailConfig || !emailConfig.smtpHost || !emailConfig.smtpUser || !emailConfig.smtpPass) {
return res.status(400).json({
success: false,
error: '邮件配置不完整,请填写SMTP服务器、用户名和密码',
});
}
if (!emailConfig.recipients || emailConfig.recipients.trim() === '') {
return res.status(400).json({
success: false,
error: '请至少指定一个收件人',
});
}
if (!winningReport && !bidReport) {
return res.status(400).json({
success: false,
error: '没有可发送的报告数据',
});
}
// 发送综合邮件
const result = await sendCombinedReportEmail(emailConfig, winningReport, bidReport);
res.json({
success: true,
message: '综合报告邮件发送成功',
messageId: result.messageId,
});
} catch (error) {
console.error('发送综合邮件API错误:', error);
res.status(500).json({
success: false,
error: error.message,
});
}
});
// 发送报告邮件
app.post('/api/send-email', async (req, res) => {
try {