mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-09-07 00:17:17 +08:00
insert JobChangeLog to db
This commit is contained in:
@@ -7,6 +7,7 @@ import { parseCompanyScale, parseSalary } from "./utils/parser";
|
|||||||
import { ChatStartupLog } from "./entity/ChatStartupLog";
|
import { ChatStartupLog } from "./entity/ChatStartupLog";
|
||||||
import { BossInfoChangeLog } from "./entity/BossInfoChangeLog";
|
import { BossInfoChangeLog } from "./entity/BossInfoChangeLog";
|
||||||
import { CompanyInfoChangeLog } from "./entity/CompanyInfoChangeLog";
|
import { CompanyInfoChangeLog } from "./entity/CompanyInfoChangeLog";
|
||||||
|
import { JobInfoChangeLog } from "./entity/JobInfoChangeLog";
|
||||||
|
|
||||||
function getBossInfoIfIsEqual (savedOne, currentOne) {
|
function getBossInfoIfIsEqual (savedOne, currentOne) {
|
||||||
if (savedOne === currentOne) {
|
if (savedOne === currentOne) {
|
||||||
@@ -46,6 +47,55 @@ function getCompanyInfoIfIsEqual (savedOne, currentOne) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanMultiLineTextForCompare (input: string) {
|
||||||
|
return input
|
||||||
|
// 去掉连续空行
|
||||||
|
.replace(/\n\s*\n+/g, '\n')
|
||||||
|
// 去掉连续的空白字符
|
||||||
|
.replace(/\s+/g, ' ')
|
||||||
|
// 去掉每行开头、结尾的空白字符
|
||||||
|
.replace(/^\s+|\s+$/gm, '');
|
||||||
|
}
|
||||||
|
function getJobInfoIfIsEqual (savedOne, currentOne) {
|
||||||
|
if (savedOne === currentOne) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
(savedOne !== null && currentOne === null) ||
|
||||||
|
(savedOne === null && currentOne !== null)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ([
|
||||||
|
'encryptUserId',
|
||||||
|
'invalidStatus',
|
||||||
|
'jobName',
|
||||||
|
'positionName',
|
||||||
|
'locationName',
|
||||||
|
'experienceName',
|
||||||
|
'degreeName',
|
||||||
|
'salaryDesc',
|
||||||
|
'payTypeDesc',
|
||||||
|
'address',
|
||||||
|
'jobStatusDesc'
|
||||||
|
].some(key => savedOne[key] !== currentOne[key])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
cleanMultiLineTextForCompare(savedOne.postDescription?.trim() ?? '') !==
|
||||||
|
cleanMultiLineTextForCompare(currentOne.postDescription?.trim() ?? '')
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
[...currentOne.showSkills ?? []].sort().join('-') !==
|
||||||
|
[...savedOne.showSkills ?? []].sort().join('-')
|
||||||
|
) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
||||||
const { bossInfo, brandComInfo, jobInfo } = _jobInfo;
|
const { bossInfo, brandComInfo, jobInfo } = _jobInfo;
|
||||||
|
|
||||||
@@ -116,6 +166,25 @@ export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region job
|
//#region job
|
||||||
|
const jobInfoChangeLogRepository = ds.getRepository(JobInfoChangeLog);
|
||||||
|
let lastSavedJobInfo
|
||||||
|
try {
|
||||||
|
lastSavedJobInfo = JSON.parse((await jobInfoChangeLogRepository.findOne({
|
||||||
|
where: { encryptJobId: jobInfo.encryptId },
|
||||||
|
order: { updateTime: "DESC" },
|
||||||
|
})).dataAsJson);
|
||||||
|
} catch {
|
||||||
|
lastSavedJobInfo = null
|
||||||
|
}
|
||||||
|
const isJobInfoEqual = getJobInfoIfIsEqual(lastSavedJobInfo, jobInfo)
|
||||||
|
if (!isJobInfoEqual) {
|
||||||
|
const changeLog = new JobInfoChangeLog()
|
||||||
|
changeLog.dataAsJson = JSON.stringify(jobInfo)
|
||||||
|
changeLog.encryptJobId = jobInfo.encryptId
|
||||||
|
changeLog.updateTime = new Date()
|
||||||
|
await jobInfoChangeLogRepository.save(changeLog)
|
||||||
|
}
|
||||||
|
|
||||||
const job = new JobInfo();
|
const job = new JobInfo();
|
||||||
const jobSalary = parseSalary(jobInfo.salaryDesc);
|
const jobSalary = parseSalary(jobInfo.salaryDesc);
|
||||||
const jobUpdatePayload: JobInfo = {
|
const jobUpdatePayload: JobInfo = {
|
||||||
|
|||||||
Reference in New Issue
Block a user