This commit is contained in:
杨志
2026-01-20 18:08:06 +08:00
parent 169b44740d
commit b458e63245
3 changed files with 28 additions and 9 deletions

View File

@@ -366,10 +366,10 @@ class Crawler extends BaseController
$item = $info;
}
// 计算竞争比
// 计算竞争比(格式:招聘人数:审核通过人数)
$zprs = isset($item['zprs']) ? intval($item['zprs']) : 0;
$bkrs = isset($item['bkrs']) ? intval($item['bkrs']) : 0;
$competitionRatio = $zprs > 0 ? ($bkrs / $zprs) : 0;
$competitionRatio = $zprs > 0 && $bkrs > 0 ? $zprs . ':' . $bkrs : ($zprs > 0 ? $zprs . ':0' : '0:0');
$result = [
'sbmc' => $item['sbmc'] ?? '', // 省份
@@ -379,7 +379,7 @@ class Crawler extends BaseController
'zwdm' => $item['zwdm'] ?? $zwdm, // 职位代码
'zprs' => $zprs, // 招聘人数
'bkrs' => $bkrs, // 审核通过人数
'competition_ratio' => number_format($competitionRatio, 2), // 竞争比
'competition_ratio' => $competitionRatio, // 竞争比(格式:招聘人数:审核通过人数)
];
return json([

View File

@@ -175,10 +175,10 @@ class CrawlerService
$item = $info;
}
// 计算竞争比
// 计算竞争比(格式:招聘人数:审核通过人数)
$zprs = isset($item['zprs']) ? intval($item['zprs']) : 0;
$bkrs = isset($item['bkrs']) ? intval($item['bkrs']) : 0;
$competitionRatio = $zprs > 0 ? ($bkrs / $zprs) : 0;
$competitionRatio = $zprs > 0 && $bkrs > 0 ? $zprs . ':' . $bkrs : ($zprs > 0 ? $zprs . ':0' : '0:0');
$results[] = [
'sbmc' => $item['sbmc'] ?? '', // 省份
@@ -188,7 +188,7 @@ class CrawlerService
'zwdm' => $item['zwdm'] ?? $zwdm, // 职位代码
'zprs' => $zprs, // 招聘人数
'bkrs' => $bkrs, // 审核通过人数
'competition_ratio' => number_format($competitionRatio, 2), // 竞争比
'competition_ratio' => $competitionRatio, // 竞争比(格式:招聘人数:审核通过人数)
];
}

View File

@@ -298,7 +298,7 @@
<div class="form-section">
<h2>职位信息结果</h2>
<div class="action-buttons" style="margin-bottom: 15px;">
<button class="btn btn-secondary" onclick="exportCsv()">导出CSV</button>
<button class="btn btn-secondary" id="export-btn" onclick="exportCsv()" disabled>导出CSV</button>
</div>
<div id="result-message"></div>
<div class="table-container" id="result-table" style="display: none;">
@@ -326,6 +326,7 @@
// 复用同一个aa确保selectPosition与getPositionTree的Referer一致
let lastAa = '';
let lastResults = [];
let isCrawling = false; // 爬取状态标志
// 获取地区选项
function getDsdmOptions() {
@@ -538,7 +539,7 @@
<td>${item.zwdm || ''}</td>
<td>${item.zprs || 0}</td>
<td>${item.bkrs || 0}</td>
<td>${item.competition_ratio || '0.00'}</td>
<td>${item.competition_ratio || '0:0'}</td>
`;
tbody.appendChild(tr);
}
@@ -599,6 +600,11 @@
return;
}
// 开始爬取,禁用导出按钮
isCrawling = true;
document.getElementById('export-btn').disabled = true;
document.getElementById('export-btn').textContent = '爬取中...';
// 清空旧数据
lastResults = [];
const tbody = document.getElementById('data-table-body');
@@ -615,6 +621,10 @@
if (listResp.code !== 1 || !Array.isArray(listResp.data) || listResp.data.length === 0) {
showMessage('result-message', listResp.msg || '未获取到职位代码', 'error');
// 爬取失败,恢复按钮状态
isCrawling = false;
document.getElementById('export-btn').disabled = false;
document.getElementById('export-btn').textContent = '导出CSV';
return;
}
@@ -645,10 +655,19 @@
}
showMessage('result-message', `完成,共 ${lastResults.length} 条成功,失败 ${codes.length - lastResults.length}`, 'success');
// 爬取完成,启用导出按钮
isCrawling = false;
document.getElementById('export-btn').disabled = false;
document.getElementById('export-btn').textContent = '导出CSV';
}
// 导出CSV
function exportCsv() {
if (isCrawling) {
showMessage('result-message', '爬取进行中,请等待完成后再导出', 'error');
return;
}
if (!lastResults || lastResults.length === 0) {
showMessage('result-message', '暂无数据可导出', 'error');
return;
@@ -664,7 +683,7 @@
item.zwdm || '',
item.zprs || 0,
item.bkrs || 0,
item.competition_ratio || '0.00'
item.competition_ratio || '0:0'
];
lines.push(row.map(v => `"${String(v).replace(/"/g, '""')}"`).join(','));
});