调试
This commit is contained in:
@@ -45,6 +45,8 @@ class MatchService
|
||||
// 1. 从数据库获取用户简历信息
|
||||
$resume = $this->getUserResumeFromDb($userId);
|
||||
if (empty($resume)) {
|
||||
// 记录调试信息
|
||||
error_log("获取用户简历失败 - 用户ID: {$userId}");
|
||||
return [
|
||||
'list' => [],
|
||||
'pagination' => [
|
||||
@@ -52,35 +54,67 @@ class MatchService
|
||||
'page_size' => $pageSize,
|
||||
'total' => 0,
|
||||
'total_pages' => 0
|
||||
],
|
||||
'debug' => [
|
||||
'error' => '用户不存在或简历信息为空',
|
||||
'user_id' => $userId
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// 2. 数据库快速过滤岗位
|
||||
// 2. 从数据库获取所有岗位
|
||||
$filteredPositions = $this->filterPositionsFromDb($resume);
|
||||
|
||||
// 记录调试信息
|
||||
error_log("获取到岗位数量: " . count($filteredPositions) . ", 用户ID: {$userId}");
|
||||
|
||||
if (empty($filteredPositions)) {
|
||||
return [
|
||||
'list' => [],
|
||||
'pagination' => [
|
||||
'page' => $page,
|
||||
'page_size' => $pageSize,
|
||||
'total' => 0,
|
||||
'total_pages' => 0
|
||||
],
|
||||
'debug' => [
|
||||
'error' => '未找到任何岗位',
|
||||
'user_id' => $userId,
|
||||
'positions_count' => 0
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
// 3. 计算匹配度
|
||||
$results = [];
|
||||
$zeroScoreCount = 0;
|
||||
foreach ($filteredPositions as $position) {
|
||||
try {
|
||||
$score = $this->calculateMatchScore($position, $resume);
|
||||
|
||||
if ($score == 0) {
|
||||
$zeroScoreCount++;
|
||||
}
|
||||
|
||||
if ($filterZero && $score == 0) {
|
||||
continue; // 过滤0分岗位
|
||||
}
|
||||
|
||||
$results[] = [
|
||||
'position_id' => $position['id'],
|
||||
'position_id' => $position['id'] ?? 0,
|
||||
'match_score' => $score,
|
||||
'position' => $position
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
// 如果计算出错,记录错误但继续处理其他岗位
|
||||
error_log("计算匹配度失败 - 岗位ID: {$position['id']}, 错误: " . $e->getMessage());
|
||||
error_log("计算匹配度失败 - 岗位ID: " . ($position['id'] ?? 'unknown') . ", 错误: " . $e->getMessage());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 记录调试信息
|
||||
error_log("匹配完成 - 总岗位数: " . count($filteredPositions) . ", 有效结果数: " . count($results) . ", 0分岗位数: {$zeroScoreCount}, filter_zero: " . ($filterZero ? 'true' : 'false'));
|
||||
|
||||
// 4. 按匹配度降序排序
|
||||
usort($results, function($a, $b) {
|
||||
return $b['match_score'] - $a['match_score'];
|
||||
@@ -100,6 +134,12 @@ class MatchService
|
||||
'total' => $total,
|
||||
'total_pages' => $totalPages,
|
||||
'has_more' => $page < $totalPages
|
||||
],
|
||||
'debug' => [
|
||||
'total_positions' => count($filteredPositions),
|
||||
'zero_score_count' => $zeroScoreCount,
|
||||
'filter_zero' => $filterZero,
|
||||
'result_count' => $total
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -112,8 +152,21 @@ class MatchService
|
||||
private function getUserResumeFromDb(int $userId): array
|
||||
{
|
||||
// 1. 获取用户基本信息(t_user表)
|
||||
// 尝试不同的主键字段名
|
||||
$user = null;
|
||||
try {
|
||||
$user = Db::name('t_user')->where('uid', $userId)->find();
|
||||
} catch (\Exception $e) {
|
||||
// 如果uid字段不存在,尝试id字段
|
||||
try {
|
||||
$user = Db::name('t_user')->where('id', $userId)->find();
|
||||
} catch (\Exception $e2) {
|
||||
error_log("查询用户失败 - 用户ID: {$userId}, 错误: " . $e2->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($user)) {
|
||||
error_log("用户不存在 - 用户ID: {$userId}");
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -216,10 +269,17 @@ class MatchService
|
||||
// 尝试添加deleted_at条件
|
||||
$query->whereNull('deleted_at');
|
||||
$positions = $query->select()->toArray();
|
||||
error_log("从no_notice_position表获取到 " . count($positions) . " 个岗位(已排除deleted_at)");
|
||||
} catch (\Exception $e) {
|
||||
// 如果字段不存在或其他错误,查询所有记录
|
||||
try {
|
||||
$query = Db::name('no_notice_position');
|
||||
$positions = $query->select()->toArray();
|
||||
error_log("从no_notice_position表获取到 " . count($positions) . " 个岗位(无deleted_at字段)");
|
||||
} catch (\Exception $e2) {
|
||||
error_log("查询岗位失败: " . $e2->getMessage());
|
||||
$positions = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 解析JSON字段,构建position_require结构
|
||||
|
||||
Reference in New Issue
Block a user