修改6
This commit is contained in:
@@ -111,7 +111,7 @@ class MatchService
|
|||||||
*/
|
*/
|
||||||
private function getUserResumeFromDb(int $userId): array
|
private function getUserResumeFromDb(int $userId): array
|
||||||
{
|
{
|
||||||
// 获取用户基本信息
|
// 1. 获取用户基本信息(t_user表)
|
||||||
$user = Db::name('t_user')->where('uid', $userId)->find();
|
$user = Db::name('t_user')->where('uid', $userId)->find();
|
||||||
if (empty($user)) {
|
if (empty($user)) {
|
||||||
return [];
|
return [];
|
||||||
@@ -122,140 +122,130 @@ class MatchService
|
|||||||
$user = $user->toArray();
|
$user = $user->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 获取用户简历信息(t_user_curriculum_vitae表)
|
||||||
|
// 尝试使用uid或user_id字段
|
||||||
|
$curriculumVitae = null;
|
||||||
|
try {
|
||||||
|
$curriculumVitae = Db::name('t_user_curriculum_vitae')
|
||||||
|
->where('uid', $userId)
|
||||||
|
->find();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 如果uid字段不存在,尝试user_id字段
|
||||||
|
try {
|
||||||
|
$curriculumVitae = Db::name('t_user_curriculum_vitae')
|
||||||
|
->where('user_id', $userId)
|
||||||
|
->find();
|
||||||
|
} catch (\Exception $e2) {
|
||||||
|
// 如果都不存在,curriculumVitae保持为null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转换为数组
|
||||||
|
if (is_object($curriculumVitae)) {
|
||||||
|
$curriculumVitae = $curriculumVitae->toArray();
|
||||||
|
} elseif ($curriculumVitae === null) {
|
||||||
|
$curriculumVitae = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 获取用户教育经历(t_user_education表)
|
||||||
|
// 尝试使用uid或user_id字段
|
||||||
|
$educations = [];
|
||||||
|
try {
|
||||||
|
$educations = Db::name('t_user_education')
|
||||||
|
->where('uid', $userId)
|
||||||
|
->order('education_level desc') // 按学历等级降序,最高学历在前
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 如果uid字段不存在,尝试user_id字段
|
||||||
|
try {
|
||||||
|
$educations = Db::name('t_user_education')
|
||||||
|
->where('user_id', $userId)
|
||||||
|
->order('education_level desc')
|
||||||
|
->select()
|
||||||
|
->toArray();
|
||||||
|
} catch (\Exception $e2) {
|
||||||
|
// 如果都不存在,educations保持为空数组
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 构建简历数据结构
|
// 构建简历数据结构
|
||||||
$resume = [
|
$resume = [
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
'birth_date' => $user['birth_date'] ?? '',
|
// 从用户表获取基本信息
|
||||||
'gender' => $user['gender'] ?? '',
|
'birth_date' => $user['birth_date'] ?? $curriculumVitae['birth_date'] ?? '',
|
||||||
'ethnicity' => $user['ethnicity'] ?? '',
|
'gender' => $user['gender'] ?? $curriculumVitae['gender'] ?? '',
|
||||||
'political_status' => $user['political_status'] ?? '',
|
'ethnicity' => $user['ethnicity'] ?? $curriculumVitae['ethnicity'] ?? '',
|
||||||
'work_experience' => $user['work_experience'] ?? '',
|
'political_status' => $user['political_status'] ?? $curriculumVitae['political_status'] ?? '',
|
||||||
|
// 从简历表获取工作经历等信息
|
||||||
|
'work_experience' => $curriculumVitae['work_experience'] ?? $user['work_experience'] ?? '',
|
||||||
|
// 教育经历从t_user_education表获取
|
||||||
'education' => []
|
'education' => []
|
||||||
];
|
];
|
||||||
|
|
||||||
// 获取教育经历(假设有教育经历表,表名可能是 t_user_education 或类似)
|
// 处理教育经历数据,确保字段名正确
|
||||||
// 先尝试常见的表名
|
foreach ($educations as $education) {
|
||||||
$educationTables = ['t_user_education', 'user_education', 't_education', 'education'];
|
$resume['education'][] = [
|
||||||
$educations = [];
|
'education_level' => $education['education_level'] ?? $education['education'] ?? '',
|
||||||
|
'degree' => $education['degree'] ?? '',
|
||||||
foreach ($educationTables as $tableName) {
|
'majors_name' => $education['majors_name'] ?? $education['major'] ?? $education['major_name'] ?? '',
|
||||||
try {
|
'school_name' => $education['school_name'] ?? $education['school'] ?? '',
|
||||||
$educations = Db::name($tableName)->where('user_id', $userId)->select()->toArray();
|
'graduation_date' => $education['graduation_date'] ?? '',
|
||||||
if (!empty($educations)) {
|
];
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// 表不存在,继续尝试下一个
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有找到教育经历表,尝试从用户表的JSON字段获取
|
|
||||||
if (empty($educations) && isset($user['education'])) {
|
|
||||||
$educationData = is_string($user['education']) ? json_decode($user['education'], true) : $user['education'];
|
|
||||||
if (is_array($educationData)) {
|
|
||||||
$educations = $educationData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$resume['education'] = $educations;
|
|
||||||
|
|
||||||
return $resume;
|
return $resume;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据库快速过滤岗位
|
* 从数据库获取所有岗位(用于匹配)
|
||||||
* @param array $resume 简历信息
|
* @param array $resume 简历信息(用于可选的快速过滤)
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function filterPositionsFromDb(array $resume): array
|
private function filterPositionsFromDb(array $resume): array
|
||||||
{
|
{
|
||||||
$query = Db::name('no_notice_position')
|
// 获取所有未删除的岗位(no_notice_position表)
|
||||||
->whereNull('deleted_at'); // 排除已删除的岗位
|
// 注意:根据用户要求,需要匹配所有岗位,所以这里不做严格过滤
|
||||||
|
// 只排除已删除的岗位,其他过滤在详细匹配时进行
|
||||||
|
$query = Db::name('no_notice_position');
|
||||||
|
|
||||||
// 计算年龄
|
// 排除已删除的岗位(如果表中有deleted_at字段)
|
||||||
$age = 0;
|
// 使用where条件,如果字段不存在,SQL会报错,但我们可以通过查询表结构来判断
|
||||||
if (!empty($resume['birth_date'])) {
|
// 为了安全,先尝试查询,如果失败则查询所有记录
|
||||||
$age = $this->calculateAge($resume['birth_date']);
|
try {
|
||||||
|
// 尝试添加deleted_at条件
|
||||||
|
$query->whereNull('deleted_at');
|
||||||
|
$positions = $query->select()->toArray();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 如果字段不存在或其他错误,查询所有记录
|
||||||
|
$query = Db::name('no_notice_position');
|
||||||
|
$positions = $query->select()->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 学历过滤(如果简历有学历信息)
|
// 解析JSON字段,构建position_require结构
|
||||||
if (!empty($resume['education'])) {
|
|
||||||
$highestEducation = $this->getHighestEducation($resume['education']);
|
|
||||||
$educationLevel = $highestEducation['education_level'] ?? '';
|
|
||||||
|
|
||||||
// 学历等级映射
|
|
||||||
$educationLevels = [
|
|
||||||
'普通本科' => 3,
|
|
||||||
'本科' => 3,
|
|
||||||
'大学本科' => 3,
|
|
||||||
'本科学历' => 3,
|
|
||||||
'硕士研究生' => 4,
|
|
||||||
'硕士' => 4,
|
|
||||||
'研究生' => 4,
|
|
||||||
'博士研究生' => 5,
|
|
||||||
'博士' => 5,
|
|
||||||
];
|
|
||||||
|
|
||||||
$actualLevel = $educationLevels[$educationLevel] ?? 0;
|
|
||||||
|
|
||||||
// 学历要求过滤:岗位要求的学历等级 <= 简历实际学历等级
|
|
||||||
// 这里简化处理,实际可以根据数据库中的具体值调整
|
|
||||||
if ($actualLevel >= 3) {
|
|
||||||
// 如果是本科及以上,可以匹配"本科"、"本科及以上"等要求
|
|
||||||
// 使用数组形式的 where 条件,这是 ThinkPHP 的标准用法
|
|
||||||
$query->where([
|
|
||||||
['education_require', 'like', '%本科%'],
|
|
||||||
['education_require', 'like', '%硕士%'],
|
|
||||||
['education_require', 'like', '%博士%'],
|
|
||||||
['education_require', '=', ''],
|
|
||||||
], 'or');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 年龄过滤(年龄要求是文本格式,如"18周岁以上、35周岁以下")
|
|
||||||
// 这里先不过滤,在详细匹配时再检查,因为文本格式难以用SQL精确匹配
|
|
||||||
// 如果需要优化,可以在数据库中添加 age_min 和 age_max 字段
|
|
||||||
|
|
||||||
// 性别过滤
|
|
||||||
if (!empty($resume['gender'])) {
|
|
||||||
$query->where([
|
|
||||||
['sex_require', '=', '不限制'],
|
|
||||||
['sex_require', '=', $resume['gender']],
|
|
||||||
['sex_require', '=', ''],
|
|
||||||
], 'or');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取过滤后的岗位
|
|
||||||
$positions = $query->select()->toArray();
|
|
||||||
|
|
||||||
// 解析JSON字段
|
|
||||||
foreach ($positions as &$position) {
|
foreach ($positions as &$position) {
|
||||||
|
// 处理position_other_require字段(可能是JSON格式)
|
||||||
|
$otherRequire = [];
|
||||||
if (!empty($position['position_other_require'])) {
|
if (!empty($position['position_other_require'])) {
|
||||||
$otherRequire = is_string($position['position_other_require'])
|
if (is_string($position['position_other_require'])) {
|
||||||
? json_decode($position['position_other_require'], true)
|
$otherRequire = json_decode($position['position_other_require'], true) ?: [];
|
||||||
: $position['position_other_require'];
|
} else {
|
||||||
|
$otherRequire = $position['position_other_require'];
|
||||||
// 将JSON数据合并到position_require中
|
}
|
||||||
$position['position_require'] = [
|
|
||||||
'学历要求' => $position['education_require'] ?? '',
|
|
||||||
'学位要求' => $position['degree_require'] ?? '',
|
|
||||||
'年龄要求' => $position['age_require'] ?? '',
|
|
||||||
'性别要求' => $position['sex_require'] ?? '',
|
|
||||||
'专业(学科)类别' => $otherRequire['专业(学科)类别'] ?? '',
|
|
||||||
'专业-本科' => $otherRequire['专业-本科'] ?? '',
|
|
||||||
'专业-硕士' => $otherRequire['专业-硕士'] ?? '',
|
|
||||||
'其他资格条件' => $otherRequire['其他资格条件'] ?? '',
|
|
||||||
'专业资格条件' => $otherRequire['专业资格条件'] ?? '',
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$position['position_require'] = [
|
|
||||||
'学历要求' => $position['education_require'] ?? '',
|
|
||||||
'学位要求' => $position['degree_require'] ?? '',
|
|
||||||
'年龄要求' => $position['age_require'] ?? '',
|
|
||||||
'性别要求' => $position['sex_require'] ?? '',
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建统一的position_require结构
|
||||||
|
$position['position_require'] = [
|
||||||
|
'学历要求' => $position['education_require'] ?? '',
|
||||||
|
'学位要求' => $position['degree_require'] ?? '',
|
||||||
|
'年龄要求' => $position['age_require'] ?? '',
|
||||||
|
'性别要求' => $position['sex_require'] ?? '',
|
||||||
|
'专业(学科)类别' => $otherRequire['专业(学科)类别'] ?? '',
|
||||||
|
'专业-本科' => $otherRequire['专业-本科'] ?? '',
|
||||||
|
'专业-硕士' => $otherRequire['专业-硕士'] ?? '',
|
||||||
|
'其他资格条件' => $otherRequire['其他资格条件'] ?? '',
|
||||||
|
'专业资格条件' => $otherRequire['专业资格条件'] ?? '',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $positions;
|
return $positions;
|
||||||
|
|||||||
Reference in New Issue
Block a user