mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-11 18:09:50 +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;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import "reflect-metadata";
|
||||
import { type DataSource } from "typeorm";
|
||||
import { parseCompanyScale, parseSalary } from "./utils/parser";
|
||||
import { requireTypeorm } from "./utils/module-loader";
|
||||
|
||||
import { BossInfo } from "./entity/BossInfo";
|
||||
@@ -16,6 +15,7 @@ import { VChatStartupLog } from "./entity/VChatStartupLog";
|
||||
|
||||
import sqlite3 from 'sqlite3';
|
||||
import * as cliHighlight from 'cli-highlight';
|
||||
import { saveJobInfoFromRecommendPage } from "./handlers";
|
||||
Boolean(cliHighlight);
|
||||
|
||||
export function initDb(dbFilePath) {
|
||||
@@ -75,81 +75,8 @@ export default class SqlitePlugin {
|
||||
);
|
||||
|
||||
hooks.jobDetailIsGetFromRecommendList.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
||||
console.log(_jobInfo);
|
||||
const ds = await this.initPromise;
|
||||
|
||||
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
|
||||
saveJobInfoFromRecommendPage(ds, _jobInfo);
|
||||
});
|
||||
|
||||
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
||||
|
||||
Reference in New Issue
Block a user