update
This commit is contained in:
@@ -248,6 +248,75 @@ class Crawler extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动获取全部职位代码并返回职位详情(无需手动勾选)
|
||||
*/
|
||||
public function fetchAllPositions()
|
||||
{
|
||||
try {
|
||||
$dsdm = $this->request->param('dsdm', '');
|
||||
$examid = $this->request->param('examid', '');
|
||||
$bmid = $this->request->param('bmid', '');
|
||||
$userid = $this->request->param('userid', '');
|
||||
$aa = $this->request->param('aa', '');
|
||||
$cookiesParam = $this->request->param('cookies', '');
|
||||
|
||||
if (empty($dsdm) || empty($examid) || empty($bmid) || empty($userid) || empty($aa)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '请填写examid、bmid、userid、dsdm,并先获取地区选项生成aa',
|
||||
]);
|
||||
}
|
||||
|
||||
if (empty($cookiesParam)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '请填写Cookie数据',
|
||||
]);
|
||||
}
|
||||
|
||||
$cookies = is_string($cookiesParam) ? json_decode($cookiesParam, true) : $cookiesParam;
|
||||
if (json_last_error() !== JSON_ERROR_NONE || empty($cookies)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => 'Cookie数据格式错误,请检查JSON格式',
|
||||
]);
|
||||
}
|
||||
|
||||
$service = new CrawlerService();
|
||||
$treeData = $service->getPositionTree($dsdm, $examid, $bmid, $userid, (string)$aa, $cookies);
|
||||
|
||||
$zwdmList = [];
|
||||
if (is_array($treeData)) {
|
||||
foreach ($treeData as $item) {
|
||||
if (isset($item['CODE']) && !empty($item['CODE'])) {
|
||||
$zwdmList[] = $item['CODE'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($zwdmList)) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '未获取到职位代码',
|
||||
]);
|
||||
}
|
||||
|
||||
$results = $service->batchGetPositionInfo($zwdmList, $examid, $cookies);
|
||||
|
||||
return json([
|
||||
'code' => 1,
|
||||
'data' => $results,
|
||||
'msg' => '获取成功',
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'msg' => '获取失败: ' . $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取职位详细信息
|
||||
*/
|
||||
|
||||
@@ -22,3 +22,4 @@ Route::post('crawler/getDsdmOptions', 'crawler/getDsdmOptions');
|
||||
Route::post('crawler/getZwdmList', 'crawler/getZwdmList');
|
||||
Route::post('crawler/getPositionInfo', 'crawler/getPositionInfo');
|
||||
Route::post('crawler/batchGetPositionInfo', 'crawler/batchGetPositionInfo');
|
||||
Route::post('crawler/fetchAllPositions', 'crawler/fetchAllPositions');
|
||||
@@ -344,6 +344,7 @@
|
||||
<script>
|
||||
// 复用同一个aa,确保selectPosition与getPositionTree的Referer一致
|
||||
let lastAa = '';
|
||||
let lastResults = [];
|
||||
|
||||
// 获取地区选项
|
||||
function getDsdmOptions() {
|
||||
@@ -522,6 +523,7 @@
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.code === 1) {
|
||||
lastResults = data.data;
|
||||
displayResults(data.data);
|
||||
showMessage('result-message', `成功获取 ${data.data.length} 条职位信息`, 'success');
|
||||
} else {
|
||||
@@ -563,6 +565,82 @@
|
||||
|
||||
document.getElementById('result-table').style.display = 'block';
|
||||
}
|
||||
|
||||
// 自动抓取全部职位代码并获取详情
|
||||
function autoFetchAllPositions() {
|
||||
const dsdm = document.getElementById('dsdm').value;
|
||||
const examid = document.getElementById('examid').value.trim();
|
||||
const bmid = document.getElementById('bmid').value.trim();
|
||||
const userid = document.getElementById('userid').value.trim();
|
||||
const cookieData = buildCookiesPayload('result-message');
|
||||
const aa = lastAa || Date.now().toString();
|
||||
|
||||
if (!dsdm) {
|
||||
showMessage('result-message', '请先选择地区', 'error');
|
||||
return;
|
||||
}
|
||||
if (!examid || !bmid || !userid) {
|
||||
showMessage('result-message', '请先填写examid、bmid和userid', 'error');
|
||||
return;
|
||||
}
|
||||
if (!cookieData) {
|
||||
return;
|
||||
}
|
||||
|
||||
showMessage('result-message', '正在自动抓取全部职位,请稍候...', 'info');
|
||||
|
||||
fetch('/crawler/fetchAllPositions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `dsdm=${encodeURIComponent(dsdm)}&examid=${encodeURIComponent(examid)}&bmid=${encodeURIComponent(bmid)}&userid=${encodeURIComponent(userid)}&aa=${encodeURIComponent(aa)}&cookies=${encodeURIComponent(JSON.stringify(cookieData))}`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.code === 1) {
|
||||
lastResults = data.data;
|
||||
displayResults(data.data);
|
||||
showMessage('result-message', `成功获取 ${data.data.length} 条职位信息`, 'success');
|
||||
} else {
|
||||
showMessage('result-message', data.msg || '获取失败', 'error');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
showMessage('result-message', '请求失败: ' + error.message, 'error');
|
||||
});
|
||||
}
|
||||
|
||||
// 导出CSV
|
||||
function exportCsv() {
|
||||
if (!lastResults || lastResults.length === 0) {
|
||||
showMessage('result-message', '暂无数据可导出', 'error');
|
||||
return;
|
||||
}
|
||||
const headers = ['省份','地区','招聘单位/用人司局','职位名称','职位代码','招聘人数','审核通过人数','竞争比'];
|
||||
const lines = [headers.join(',')];
|
||||
lastResults.forEach(item => {
|
||||
const row = [
|
||||
item.sbmc || '',
|
||||
item.dsmc || '',
|
||||
item.zpdwmc || '',
|
||||
item.zwmc || '',
|
||||
item.zwdm || '',
|
||||
item.zprs || 0,
|
||||
item.bkrs || 0,
|
||||
item.competition_ratio || '0.00'
|
||||
];
|
||||
lines.push(row.map(v => `"${String(v).replace(/"/g, '""')}"`).join(','));
|
||||
});
|
||||
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8;' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = 'positions.csv';
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
showMessage('result-message', '已导出CSV', 'success');
|
||||
}
|
||||
|
||||
// 显示消息
|
||||
function showMessage(containerId, message, type) {
|
||||
|
||||
Reference in New Issue
Block a user