mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-07-09 22:44:13 +08:00
add the feature when visiting LAUNCH_BOSS_SITE recommend, save job info
This commit is contained in:
88
packages/sqlite-plugin/src/handlers.ts
Normal file
88
packages/sqlite-plugin/src/handlers.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import { DataSource } from "typeorm";
|
||||
import { BossActiveStatusRecord } from "./entity/BossActiveStatusRecord";
|
||||
import { BossInfo } from "./entity/BossInfo";
|
||||
import { CompanyInfo } from "./entity/CompanyInfo";
|
||||
import { JobInfo } from "./entity/JobInfo";
|
||||
import { parseCompanyScale, parseSalary } from "./utils/parser";
|
||||
|
||||
export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
||||
const { bossInfo, brandComInfo, jobInfo } = _jobInfo;
|
||||
|
||||
//#region boss
|
||||
const boss = new BossInfo();
|
||||
boss.encryptBossId = jobInfo.encryptUserId;
|
||||
boss.encryptCompanyId = brandComInfo.encryptBrandId;
|
||||
boss.name = bossInfo.name;
|
||||
boss.title = bossInfo.title;
|
||||
boss.date = new Date();
|
||||
const bossInfoRepository = ds.getRepository(BossInfo);
|
||||
await bossInfoRepository.save(boss);
|
||||
//#endregion
|
||||
|
||||
//#region company
|
||||
const company = new CompanyInfo();
|
||||
company.encryptCompanyId = brandComInfo.encryptBrandId;
|
||||
company.brandName = brandComInfo.brandName;
|
||||
company.name = brandComInfo.customerBrandName;
|
||||
company.industryName = brandComInfo.industryName;
|
||||
company.stageName = brandComInfo.stageName;
|
||||
const companyScale = parseCompanyScale(brandComInfo.scaleName);
|
||||
company.scaleLow = companyScale[0];
|
||||
company.scaleHigh = companyScale[1];
|
||||
|
||||
const companyInfoRepository = ds.getRepository(CompanyInfo);
|
||||
await companyInfoRepository.save(company);
|
||||
//#endregion
|
||||
|
||||
//#region job
|
||||
const job = new JobInfo();
|
||||
const jobSalary = parseSalary(jobInfo.salaryDesc);
|
||||
const jobUpdatePayload: JobInfo = {
|
||||
address: jobInfo.address,
|
||||
degreeName: jobInfo.degreeName,
|
||||
description: jobInfo.postDescription,
|
||||
encryptBossId: jobInfo.encryptUserId,
|
||||
encryptCompanyId: brandComInfo.encryptBrandId,
|
||||
encryptJobId: jobInfo.encryptId,
|
||||
jobName: jobInfo.jobName,
|
||||
positionName: jobInfo.positionName,
|
||||
experienceName: jobInfo.experienceName,
|
||||
salaryHigh: jobSalary.high,
|
||||
salaryLow: jobSalary.low,
|
||||
salaryMonth: jobSalary.month,
|
||||
};
|
||||
|
||||
Object.assign(job, jobUpdatePayload);
|
||||
|
||||
const jobInfoRepository = ds.getRepository(JobInfo);
|
||||
await jobInfoRepository.save(job);
|
||||
//#endregion
|
||||
|
||||
//#region save boss active status
|
||||
// look up if the lastActiveStatus of the newest one is equal to the current one.
|
||||
// if equal, just update the updateDate
|
||||
// else insert a new record
|
||||
|
||||
const bossActiveStatusRecord = new BossActiveStatusRecord();
|
||||
bossActiveStatusRecord.encryptBossId = boss.encryptBossId;
|
||||
bossActiveStatusRecord.updateDate = new Date();
|
||||
bossActiveStatusRecord.lastActiveStatus = bossInfo.activeTimeDesc;
|
||||
|
||||
const bossActiveStatusRecordRepository = ds.getRepository(
|
||||
BossActiveStatusRecord
|
||||
);
|
||||
const existNewestRecordByBossId =
|
||||
await bossActiveStatusRecordRepository.findOne({
|
||||
where: { encryptBossId: boss.encryptBossId },
|
||||
order: { updateDate: "DESC" },
|
||||
});
|
||||
if (
|
||||
existNewestRecordByBossId &&
|
||||
existNewestRecordByBossId.lastActiveStatus === bossInfo.activeTimeDesc
|
||||
) {
|
||||
bossActiveStatusRecord.id = existNewestRecordByBossId.id;
|
||||
}
|
||||
await bossActiveStatusRecordRepository.save(bossActiveStatusRecord);
|
||||
//#endregion
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user