up
This commit is contained in:
@@ -340,54 +340,9 @@ class Crawler extends BaseController
|
|||||||
|
|
||||||
$treeData = $service->getPositionTree($dsdm, $examid, $bmid, $userid, (string)$aa, $cookies);
|
$treeData = $service->getPositionTree($dsdm, $examid, $bmid, $userid, (string)$aa, $cookies);
|
||||||
|
|
||||||
// 若接口返回包装结构 { "data": [...] } / { "tree": [...] } 则取内层节点数组
|
$zwdmList = is_array($treeData)
|
||||||
if (is_array($treeData) && isset($treeData['data']) && is_array($treeData['data'])) {
|
? $service->collectPositionCodesExcludingNocheck($treeData)
|
||||||
$treeData = $treeData['data'];
|
: [];
|
||||||
}
|
|
||||||
if (is_array($treeData) && isset($treeData['tree']) && is_array($treeData['tree'])) {
|
|
||||||
$treeData = $treeData['tree'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$zwdmList = [];
|
|
||||||
$isNocheck = function ($node) {
|
|
||||||
if (isset($node['nocheck'])) {
|
|
||||||
$v = $node['nocheck'];
|
|
||||||
if ($v === true || $v === 'true' || $v === 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isset($node['noCheck'])) {
|
|
||||||
$v = $node['noCheck'];
|
|
||||||
if ($v === true || $v === 'true' || $v === 1) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
$collectCodes = function (array $nodes) use (&$collectCodes, &$zwdmList, $isNocheck) {
|
|
||||||
foreach ($nodes as $item) {
|
|
||||||
if (!is_array($item)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// 跳过包含 nocheck: true 的节点(如分组节点,不参与爬取)
|
|
||||||
if ($isNocheck($item)) {
|
|
||||||
if (!empty($item['children']) && is_array($item['children'])) {
|
|
||||||
$collectCodes($item['children']);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isset($item['CODE']) && $item['CODE'] !== '') {
|
|
||||||
$zwdmList[] = $item['CODE'];
|
|
||||||
}
|
|
||||||
if (!empty($item['children']) && is_array($item['children'])) {
|
|
||||||
$collectCodes($item['children']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (is_array($treeData)) {
|
|
||||||
$collectCodes($treeData);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($zwdmList)) {
|
if (empty($zwdmList)) {
|
||||||
return json([
|
return json([
|
||||||
|
|||||||
@@ -165,6 +165,37 @@ class CrawlerService
|
|||||||
return $data ?: [];
|
return $data ?: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从职位树数据中收集可爬取的职位代码(排除 nocheck: true 的节点)
|
||||||
|
* 接口返回扁平数组 [ { CODE, TITLE, nocheck?, ... }, ... ]
|
||||||
|
* @param array $treeData getPositionTree 的返回值(可为裸数组或包装结构)
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function collectPositionCodesExcludingNocheck(array $treeData): array
|
||||||
|
{
|
||||||
|
$codes = [];
|
||||||
|
$nodes = $treeData;
|
||||||
|
if (isset($treeData['data']) && is_array($treeData['data'])) {
|
||||||
|
$nodes = $treeData['data'];
|
||||||
|
} elseif (isset($treeData['tree']) && is_array($treeData['tree'])) {
|
||||||
|
$nodes = $treeData['tree'];
|
||||||
|
}
|
||||||
|
foreach ($nodes as $item) {
|
||||||
|
if (!is_array($item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 有 nocheck 且为真(true / "true" / 1)则跳过;避免把字符串 "false" 当真理
|
||||||
|
$nocheck = $item['nocheck'] ?? $item['noCheck'] ?? null;
|
||||||
|
if ($nocheck === true || $nocheck === 1 || (is_string($nocheck) && strtolower($nocheck) === 'true')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isset($item['CODE']) && $item['CODE'] !== '') {
|
||||||
|
$codes[] = $item['CODE'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $codes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取职位详细信息
|
* 获取职位详细信息
|
||||||
* @param string $zwdm 职位代码
|
* @param string $zwdm 职位代码
|
||||||
|
|||||||
Reference in New Issue
Block a user