mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-11 10:00:34 +08:00
fix salary assert method
This commit is contained in:
@@ -39,6 +39,7 @@ import {
|
||||
import { parseSalary } from "@geekgeekrun/sqlite-plugin/dist/utils/parser"
|
||||
import { waitForSageTimeOrJustContinue } from './sage-time.mjs'
|
||||
import cityGroupData from './cityGroup.mjs'
|
||||
import { hasIntersection } from '@geekgeekrun/utils/number.mjs';
|
||||
const flattedCityList = []
|
||||
;(cityGroupData?.zpData?.cityGroup ?? []).forEach(it => {
|
||||
const firstChar = it.firstChar
|
||||
@@ -986,20 +987,24 @@ async function toRecommendPage (hooks) {
|
||||
function checkIfSalarySuit(salaryDesc) {
|
||||
const salaryData = parseSalary(salaryDesc)
|
||||
if (expectSalaryCalculateWay === SalaryCalculateWay.MONTH_SALARY) {
|
||||
if (expectSalaryHigh && salaryData.high > expectSalaryHigh) {
|
||||
return false
|
||||
let ourSalaryInterval = [expectSalaryLow ?? null, expectSalaryHigh ?? null]
|
||||
if (ourSalaryInterval.every(it => !isNaN(parseFloat(it)))) {
|
||||
ourSalaryInterval = ourSalaryInterval.sort((a, b) => a - b)
|
||||
}
|
||||
if (expectSalaryLow && salaryData.high < expectSalaryLow) {
|
||||
return false
|
||||
}
|
||||
} else if (expectSalaryCalculateWay === SalaryCalculateWay.ANNUAL_PACKAGE) {
|
||||
const theirSalaryInterval = [salaryData.low ?? null, salaryData.high ?? null]
|
||||
return hasIntersection(theirSalaryInterval, ourSalaryInterval)
|
||||
}
|
||||
else if (expectSalaryCalculateWay === SalaryCalculateWay.ANNUAL_PACKAGE) {
|
||||
const salaryDataMonth = salaryData.month || 12
|
||||
if (expectSalaryHigh && (salaryData.high * salaryDataMonth) / 10 > expectSalaryHigh) {
|
||||
return false
|
||||
}
|
||||
if (expectSalaryLow && (salaryData.high * salaryDataMonth) / 10 < expectSalaryLow) {
|
||||
return false
|
||||
let ourSalaryInterval = [expectSalaryLow ?? null, expectSalaryHigh ?? null]
|
||||
if (ourSalaryInterval.every(it => !isNaN(parseFloat(it)))) {
|
||||
ourSalaryInterval = ourSalaryInterval.sort((a, b) => a - b)
|
||||
}
|
||||
const theirSalaryInterval = [salaryData.low ?? null, salaryData.high ?? null].map(
|
||||
it =>
|
||||
it === null ? null : (it * salaryDataMonth / 10)
|
||||
)
|
||||
return hasIntersection(theirSalaryInterval, ourSalaryInterval)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export const expectSalaryCalculateWayOption = [
|
||||
value: SalaryCalculateWay.MONTH_SALARY
|
||||
},
|
||||
{
|
||||
name: '“年包”(单位为 万元 - 即“W”)',
|
||||
name: '总包(单位为 万元 - 即“W”)',
|
||||
value: SalaryCalculateWay.ANNUAL_PACKAGE
|
||||
}
|
||||
]
|
||||
|
||||
16
packages/utils/number.mjs
Normal file
16
packages/utils/number.mjs
Normal file
@@ -0,0 +1,16 @@
|
||||
export function hasIntersection(interval1, interval2) {
|
||||
// 通用函数:将区间标准化,null转换为对应的无穷大
|
||||
const normalizeInterval = (interval) => {
|
||||
const [start, end] = interval;
|
||||
return [
|
||||
[null, undefined].includes(start) ? -Infinity : start,
|
||||
[null, undefined].includes(end) ? Infinity : end
|
||||
];
|
||||
};
|
||||
|
||||
const [norm1Start, norm1End] = normalizeInterval(interval1);
|
||||
const [norm2Start, norm2End] = normalizeInterval(interval2);
|
||||
|
||||
// 判断交集
|
||||
return Math.max(norm1Start, norm2Start) <= Math.min(norm1End, norm2End);
|
||||
}
|
||||
Reference in New Issue
Block a user