This commit is contained in:
张成
2025-12-12 16:38:48 +08:00
parent 130167acc9
commit 4686a24522
10 changed files with 14626 additions and 50 deletions

View File

@@ -772,20 +772,57 @@ class JobManager {
}
/**
* 解析期望薪资
* @param {string} expectedSalary - 期望薪资描述
* @returns {number|null} 期望薪资数值(元)
* 解析期望薪资(返回平均值)
* @param {string} expectedSalary - 期望薪资描述(如 "20-30K"、"5000-6000元/月"
* @returns {number|null} 期望薪资数值(元),如果是范围则返回平均值
*/
parse_expected_salary(expectedSalary) {
if (!expectedSalary) return null;
// 匹配数字+K格式(如20K
const match = expectedSalary.match(/(\d+)[kK千]/);
if (match) {
return parseInt(match[1]) * 1000;
// 1. 匹配K格式范围20-30K
const kRangeMatch = expectedSalary.match(/(\d+)[-~](\d+)[kK千]/);
if (kRangeMatch) {
const min = parseInt(kRangeMatch[1]) * 1000;
const max = parseInt(kRangeMatch[2]) * 1000;
return (min + max) / 2; // 返回平均值
}
// 匹配纯数字20000
// 2. 匹配单个K值25K
const kMatch = expectedSalary.match(/(\d+)[kK千]/);
if (kMatch) {
return parseInt(kMatch[1]) * 1000;
}
// 3. 匹配元/月格式范围5000-6000元/月
const yuanRangeMatch = expectedSalary.match(/(\d+)[-~](\d+)[元万]/);
if (yuanRangeMatch) {
const min = parseInt(yuanRangeMatch[1]);
const max = parseInt(yuanRangeMatch[2]);
if (expectedSalary.includes('万')) {
return ((min + max) / 2) * 10000;
} else {
return (min + max) / 2; // 返回平均值
}
}
// 4. 匹配单个元/月值5000元/月
const yuanMatch = expectedSalary.match(/(\d+)[元万]/);
if (yuanMatch) {
const value = parseInt(yuanMatch[1]);
if (expectedSalary.includes('万')) {
return value * 10000;
} else {
return value;
}
}
// 5. 匹配纯数字范围20000-30000
const numRangeMatch = expectedSalary.match(/(\d+)[-~](\d+)/);
if (numRangeMatch) {
return (parseInt(numRangeMatch[1]) + parseInt(numRangeMatch[2])) / 2; // 返回平均值
}
// 6. 匹配纯数字20000
const numMatch = expectedSalary.match(/(\d+)/);
if (numMatch) {
return parseInt(numMatch[1]);
@@ -834,28 +871,64 @@ class JobManager {
/**
* 解析薪资范围
* @param {string} salaryDesc - 薪资描述(如 "15-25K·14薪"
* @returns {object} 薪资范围 { min, max }
* @param {string} salaryDesc - 薪资描述(如 "15-25K·14薪"、"5000-6000元/月"
* @returns {object} 薪资范围 { min, max },单位:元
*/
parse_salary_range(salaryDesc) {
if (!salaryDesc) return { min: 0, max: 0 };
// 匹配常见格式15-25K, 15K-25K, 15-25k·14薪
const match = salaryDesc.match(/(\d+)[-~](\d+)[kK]/);
if (match) {
// 1. 匹配K格式40-60K, 30-40K·18薪忽略后面的薪数
const kMatch = salaryDesc.match(/(\d+)[-~](\d+)[kK]/);
if (kMatch) {
return {
min: parseInt(match[1]) * 1000,
max: parseInt(match[2]) * 1000
min: parseInt(kMatch[1]) * 1000,
max: parseInt(kMatch[2]) * 1000
};
}
// 匹配单个25K
const singleMatch = salaryDesc.match(/(\d+)[kK]/);
if (singleMatch) {
const value = parseInt(singleMatch[1]) * 1000;
// 2. 匹配单个K25K
const singleKMatch = salaryDesc.match(/(\d+)[kK]/);
if (singleKMatch) {
const value = parseInt(singleKMatch[1]) * 1000;
return { min: value, max: value };
}
// 3. 匹配元/月格式5000-6000元/月
const yuanMatch = salaryDesc.match(/(\d+)[-~](\d+)[元万]/);
if (yuanMatch) {
const min = parseInt(yuanMatch[1]);
const max = parseInt(yuanMatch[2]);
// 判断单位(万或元)
if (salaryDesc.includes('万')) {
return {
min: min * 10000,
max: max * 10000
};
} else {
return { min, max };
}
}
// 4. 匹配单个元/月值5000元/月
const singleYuanMatch = salaryDesc.match(/(\d+)[元万]/);
if (singleYuanMatch) {
const value = parseInt(singleYuanMatch[1]);
if (salaryDesc.includes('万')) {
return { min: value * 10000, max: value * 10000 };
} else {
return { min: value, max: value };
}
}
// 5. 匹配纯数字格式20000-30000
const numMatch = salaryDesc.match(/(\d+)[-~](\d+)/);
if (numMatch) {
return {
min: parseInt(numMatch[1]),
max: parseInt(numMatch[2])
};
}
return { min: 0, max: 0 };
}