Skip to content

Commit

Permalink
feat: company tag for admin home,job page;fix company full name for b…
Browse files Browse the repository at this point in the history
…oss etc...
  • Loading branch information
lastsunday committed Jul 15, 2024
1 parent e55afbc commit 47d7e16
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 74 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# CHANGELOG

## WIP

### ⭐ Added

1. (SidePanel)显示职位信息时,将公司标签也一并显示。(针对主页,职位页)

### 🐛 Fixed

1. (ContentScript)针对某些职位信息公司名不是全称的情况,在查询公司信息时进行补全处理。
2. (SidePanel)Unmounted页面时,清理定时器。

## 1.16.0(2024-07-15)

### ⭐ Added
Expand Down
8 changes: 8 additions & 0 deletions src/common/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export const JobApi = {
return await invoke(this.batchAddOrUpdateJobBrowse.name, jobs);
},

/**
*
* @param {Job[]} jobs
*/
batchAddOrUpdateJob: async function (jobs) {
return await invoke(this.batchAddOrUpdateJob.name, jobs);
},

/**
*
* @param {Job} job
Expand Down
1 change: 1 addition & 0 deletions src/common/data/dto/jobDTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export class JobDTO extends Job{
browseCount;
browseDetailCount;
latestBrowseDetailDatetime;
companyTagDTOList;
}
119 changes: 66 additions & 53 deletions src/contentScript/commonRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { httpFetchGetText } from "../common/api/common";

import { logoBase64 } from "./assets/logo";
import $ from "jquery";
import { CompanyApi, TagApi, AuthApi, UserApi } from "../common/api";
import { CompanyApi, TagApi, AuthApi, UserApi, JobApi } from "../common/api";
import { GithubApi } from "../common/api/github";
import { Company } from "../common/data/domain/company";
import { errorLog, infoLog } from "../common/log";
Expand Down Expand Up @@ -700,60 +700,73 @@ function createCompanyInfo(item, { getCompanyInfoFunction, platform } = {}) {
let quickSearchButtonLoading = document.createElement("div");
quickSearchButtonLoading.className = "__company_info_quick_search_button";
const quickSearchHandle = async (forceSyncData) => {
if (mainChannelDiv.contains(fixValidHummanButton)) {
mainChannelDiv.removeChild(fixValidHummanButton);
}
quickSearchButtonLoading.textContent = `🔎正查询公司全称⌛︎`;
if (mainChannelDiv.contains(quickSearchButton)) {
mainChannelDiv.removeChild(quickSearchButton);
}
mainChannelDiv.appendChild(quickSearchButtonLoading);
let companyName = item.jobCompanyName;
fixValidHummanButton.textContent =
"一直查询失败?点击该按钮去尝试解除人机验证吧!";
if (getCompanyInfoFunction) {
let targetCompanyName = await getCompanyInfoFunction(
item.jobCompanyApiUrl
);
if (targetCompanyName) {
companyName = targetCompanyName;
} else {
fixValidHummanButton.textContent = `找不到【${companyName}】的全称,点击该按钮去看看有没有相关记录`;
}
}
const decode = encodeURIComponent(companyName);
const url = `https://aiqicha.baidu.com/s?q=${decode}`;
fixValidHummanButton.href = url;
otherChannelDiv.replaceChildren();
try {
quickSearchButtonLoading.textContent = `🔎正查询【${companyName}】⌛︎`;
await asyncRenderCompanyInfo(
mainChannelDiv,
companyName,
forceSyncData,
quickSearchHandle
);
mainChannelDiv.removeChild(quickSearchButtonLoading);
if (mainChannelDiv.contains(fixValidHummanButton)) {
mainChannelDiv.removeChild(fixValidHummanButton);
}
quickSearchButtonLoading.textContent = `🔎正查询公司全称⌛︎`;
if (mainChannelDiv.contains(quickSearchButton)) {
mainChannelDiv.removeChild(quickSearchButton);
}
mainChannelDiv.appendChild(quickSearchButtonLoading);
let companyName = item.jobCompanyName;
fixValidHummanButton.textContent =
"一直查询失败?点击该按钮去尝试解除人机验证吧!";
if (getCompanyInfoFunction) {
let targetCompanyName = await getCompanyInfoFunction(
item.jobCompanyApiUrl
);
if (targetCompanyName) {
if (companyNameConvert(companyName) == companyNameConvert(targetCompanyName)) {
infoLog(`company name equal = ${companyName}`);
} else {
companyName = targetCompanyName;
infoLog(`old company name = ${item.jobCompanyName}`);
item.jobCompanyName = companyNameConvert(companyName);
infoLog(`new company name = ${item.jobCompanyName}`);
await JobApi.batchAddOrUpdateJob([item]);
infoLog(`update job.id = ${item.jobId}`);
}
} else {
fixValidHummanButton.textContent = `找不到【${companyName}】的全称,点击该按钮去看看有没有相关记录`;
}
}
const decode = encodeURIComponent(companyName);
const url = `https://aiqicha.baidu.com/s?q=${decode}`;
fixValidHummanButton.href = url;
otherChannelDiv.replaceChildren();
try {
quickSearchButtonLoading.textContent = `🔎正查询【${companyName}】⌛︎`;
await asyncRenderCompanyInfo(
mainChannelDiv,
companyName,
forceSyncData,
quickSearchHandle
);
mainChannelDiv.removeChild(quickSearchButtonLoading);
} catch (e) {
mainChannelDiv.removeChild(quickSearchButtonLoading);
quickSearchButton.textContent = `🔎查询【${companyName}】失败,点击重新查询`;
mainChannelDiv.appendChild(quickSearchButton);
mainChannelDiv.appendChild(fixValidHummanButton);
} finally {
otherChannelDiv.appendChild(createCompanyReputation(companyName));
otherChannelDiv.appendChild(createCompanyTag(companyName));
otherChannelDiv.appendChild(createSearchCompanyLink(companyName));
let companyIdSha256 = genIdFromText(companyName);
let commentWrapperDiv = document.createElement("div");
commentWrapperDiv.className = `__comment_wrapper __${platform}_comment_wrapper`
let companyCommentButton = genCommentTextButton(
commentWrapperDiv,
"查看公司评论💬",
companyName,
companyIdSha256
);
commentWrapperDiv.appendChild(companyCommentButton);
otherChannelDiv.append(commentWrapperDiv);
}
} catch (e) {
mainChannelDiv.removeChild(quickSearchButtonLoading);
quickSearchButton.textContent = `🔎查询【${companyName}】失败,点击重新查询`;
mainChannelDiv.appendChild(quickSearchButton);
mainChannelDiv.appendChild(fixValidHummanButton);
} finally {
otherChannelDiv.appendChild(createCompanyReputation(companyName));
otherChannelDiv.appendChild(createCompanyTag(companyName));
otherChannelDiv.appendChild(createSearchCompanyLink(companyName));
let companyIdSha256 = genIdFromText(companyName);
let commentWrapperDiv = document.createElement("div");
commentWrapperDiv.className = `__comment_wrapper __${platform}_comment_wrapper`
let companyCommentButton = genCommentTextButton(
commentWrapperDiv,
"查看公司评论💬",
companyName,
companyIdSha256
);
commentWrapperDiv.appendChild(companyCommentButton);
otherChannelDiv.append(commentWrapperDiv);
errorLog(e);
}
};
quickSearchButton.onclick = () => {
Expand Down
19 changes: 18 additions & 1 deletion src/offscreen/service/companyTagService.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,24 @@ export const CompanyTagService = {
await _getAllCompanyTagDTOByCompanyId(param)
);
} catch (e) {
postErrorMessage(message, "[worker] getTagById error : " + e.message);
postErrorMessage(message, "[worker] getAllCompanyTagDTOByCompanyId error : " + e.message);
}
},
/**
*
* @param {Message} message
* @param {string[]} param ids
*
* @returns CompanyTagDTO[]
*/
getAllCompanyTagDTOByCompanyIds: async function (message, param) {
try {
postSuccessMessage(
message,
await _getAllCompanyTagDTOByCompanyIds(param)
);
} catch (e) {
postErrorMessage(message, "[worker] getAllCompanyTagDTOByCompanyIds error : " + e.message);
}
},
/**
Expand Down
93 changes: 86 additions & 7 deletions src/offscreen/service/jobService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { Job } from "../../common/data/domain/job";
import { Message } from "../../common/api/message";
import dayjs from "dayjs";
import { JobDTO } from "../../common/data/dto/jobDTO";
import { toHump, convertEmptyStringToNull } from "../../common/utils";
import { toHump, convertEmptyStringToNull, genIdFromText } from "../../common/utils";
import { StatisticJobBrowseDTO } from "../../common/data/dto/statisticJobBrowseDTO";
import { StatisticJobSearchGroupByAvgSalaryDTO } from "../../common/data/dto/statisticJobSearchGroupByAvgSalaryDTO";
import { SearchJobBO } from "../../common/data/bo/searchJobBO";
import { SearchJobDTO } from "../../common/data/dto/searchJobDTO";
import { postSuccessMessage, postErrorMessage } from "../util";
import { getDb, getOne } from "../database";
import { _getAllCompanyTagDTOByCompanyIds } from "./companyTagService";

const JOB_VISIT_TYPE_SEARCH = "SEARCH";
const JOB_VISIT_TYPE_DETAIL = "DETAIL";
Expand All @@ -26,7 +27,7 @@ export const JobService = {
sql: "BEGIN TRANSACTION",
});
for (let i = 0; i < param.length; i++) {
await insertJobAndBrowseHistory(param[i], now);
await insertOrUpdateJobAndBrowseHistory(param[i], now);
}
(await getDb()).exec({
sql: "COMMIT",
Expand All @@ -40,6 +41,32 @@ export const JobService = {
}
},

/**
*
* @param {Message} message
* @param {Job[]} param
*/
batchAddOrUpdateJob: async function (message, param) {
try {
const now = new Date();
(await getDb()).exec({
sql: "BEGIN TRANSACTION",
});
for (let i = 0; i < param.length; i++) {
await _insertOrUpdateJob(param[i], now);
}
(await getDb()).exec({
sql: "COMMIT",
});
postSuccessMessage(message, {});
} catch (e) {
postErrorMessage(
message,
"[worker] batchAddOrUpdateJob error : " + e.message
);
}
},

/**
*
* @param {Message} message
Expand All @@ -51,7 +78,7 @@ export const JobService = {
(await getDb()).exec({
sql: "BEGIN TRANSACTION",
});
insertJobAndBrowseHistory(param, now);
insertOrUpdateJobAndBrowseHistory(param, now);
(await getDb()).exec({
sql: "COMMIT",
});
Expand Down Expand Up @@ -173,7 +200,7 @@ export const JobService = {
rowMode: "object",
resultRows: queryRows,
});

let companyIds = [];
for (let i = 0; i < queryRows.length; i++) {
let item = queryRows[i];
let resultItem = new JobDTO();
Expand All @@ -183,8 +210,21 @@ export const JobService = {
resultItem[key] = item[key];
}
items.push(item);
companyIds.push(genIdFromText(item.jobCompanyName));
}

let companyTagDTOList = await _getAllCompanyTagDTOByCompanyIds(companyIds);
let companyIdAndCompanyTagListMap = new Map();
companyTagDTOList.forEach(item => {
let companyId = item.companyId;
if (!companyIdAndCompanyTagListMap.has(companyId)) {
companyIdAndCompanyTagListMap.set(companyId, []);
}
companyIdAndCompanyTagListMap.get(companyId).push(item);
});
items.forEach(item => {
item.companyTagDTOList = companyIdAndCompanyTagListMap.get(genIdFromText(item.jobCompanyName));
});
let sqlCount = "SELECT COUNT(*) AS total from job";
//count
sqlCount += whereCondition;
Expand Down Expand Up @@ -410,7 +450,12 @@ function genJobSearchWhereConditionSql(param) {
return whereCondition;
}

async function insertJobAndBrowseHistory(param, now) {
async function insertOrUpdateJobAndBrowseHistory(param, now) {
await _insertOrUpdateJob(param, now, { update: false });
await addJobBrowseHistory(param.jobId, now, JOB_VISIT_TYPE_SEARCH);
}

async function _insertOrUpdateJob(param, now, { update = true } = {}) {
let rows = [];
const SQL_JOB_BY_ID = `SELECT job_id,job_platform,job_url,job_name,job_company_name,job_location_name,job_address,job_longitude,job_latitude,job_description,job_degree_name,job_year,job_salary_min,job_salary_max,job_salary_total_month,job_first_publish_datetime,boss_name,boss_company_name,boss_position,create_datetime,update_datetime FROM job WHERE job_id = ?`;
(await getDb()).exec({
Expand All @@ -420,7 +465,42 @@ async function insertJobAndBrowseHistory(param, now) {
resultRows: rows,
});
if (rows.length > 0) {
//skip
if (update) {
const SQL_UPDATE_JOB = `
UPDATE job SET job_platform=$job_platform,job_url=$job_url,job_name=$job_name,job_company_name=$job_company_name,job_location_name=$job_location_name,job_address=$job_address,job_longitude=$job_longitude,job_latitude=$job_latitude,job_description=$job_description,job_degree_name=$job_degree_name,job_year=$job_year,job_salary_min=$job_salary_min,job_salary_max=$job_salary_max,job_salary_total_month=$job_salary_total_month,job_first_publish_datetime=$job_first_publish_datetime,boss_name=$boss_name,boss_company_name=$boss_company_name,boss_position=$boss_position,update_datetime=$update_datetime WHERE job_id = $job_id;
`;
(await getDb()).exec({
sql: SQL_UPDATE_JOB,
bind: {
$job_id: param.jobId,
$job_platform: param.jobPlatform,
$job_url: convertEmptyStringToNull(param.jobUrl),
$job_name: convertEmptyStringToNull(param.jobName),
$job_company_name: convertEmptyStringToNull(param.jobCompanyName),
$job_location_name: convertEmptyStringToNull(param.jobLocationName),
$job_address: convertEmptyStringToNull(param.jobAddress),
$job_longitude: convertEmptyStringToNull(param.jobLongitude),
$job_latitude: convertEmptyStringToNull(param.jobLatitude),
$job_description: convertEmptyStringToNull(param.jobDescription),
$job_degree_name: convertEmptyStringToNull(param.jobDegreeName),
$job_year: convertEmptyStringToNull(param.jobYear),
$job_salary_min: convertEmptyStringToNull(param.jobSalaryMin),
$job_salary_max: convertEmptyStringToNull(param.jobSalaryMax),
$job_salary_total_month: convertEmptyStringToNull(
param.jobSalaryTotalMonth
),
$job_first_publish_datetime: dayjs(
param.jobFirstPublishDatetime
).isValid()
? dayjs(param.jobFirstPublishDatetime).format("YYYY-MM-DD HH:mm:ss")
: null,
$boss_name: convertEmptyStringToNull(param.bossName),
$boss_company_name: convertEmptyStringToNull(param.bossCompanyName),
$boss_position: convertEmptyStringToNull(param.bossPosition),
$update_datetime: dayjs(now).format("YYYY-MM-DD HH:mm:ss"),
},
});
}
} else {
const SQL_INSERT_JOB = `
INSERT INTO job (job_id,job_platform,job_url,job_name,job_company_name,job_location_name,job_address,job_longitude,job_latitude,job_description,job_degree_name,job_year,job_salary_min,job_salary_max,job_salary_total_month,job_first_publish_datetime,boss_name,boss_company_name,boss_position,create_datetime,update_datetime) VALUES ($job_id,$job_platform,$job_url,$job_name,$job_company_name,$job_location_name,$job_address,$job_longitude,$job_latitude,$job_description,$job_degree_name,$job_year,$job_salary_min,$job_salary_max,$job_salary_total_month,$job_first_publish_datetime,$boss_name,$boss_company_name,$boss_position,$create_datetime,$update_datetime)
Expand Down Expand Up @@ -458,7 +538,6 @@ async function insertJobAndBrowseHistory(param, now) {
},
});
}
await addJobBrowseHistory(param.jobId, now, JOB_VISIT_TYPE_SEARCH);
}

async function addJobBrowseHistory(jobId, date, type) {
Expand Down
13 changes: 11 additions & 2 deletions src/sidepanel/views/CompanyTagView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</template>

<script lang="ts" setup>
import { onMounted, ref, computed, reactive, nextTick } from "vue";
import { onMounted, ref, computed, reactive, nextTick, onUnmounted } from "vue";
import { useTransition } from "@vueuse/core";
import { CompanyApi, TagApi } from "../../common/api/index";
import { SearchCompanyTagBO } from "../../common/data/bo/searchCompanyTagBO";
Expand Down Expand Up @@ -191,13 +191,22 @@ const handleCurrentChange = (val: number) => {
search();
};
let refreshIntervalId = null;
onMounted(async () => {
await refreshStatistic();
setInterval(refreshStatistic, 10000);
refreshIntervalId = setInterval(refreshStatistic, 10000);
await loadWhitelist();
search();
});
onUnmounted(() => {
if (refreshIntervalId) {
clearInterval(refreshIntervalId);
refreshIntervalId = null;
}
});
const loadWhitelist = async () => {
let allTags = await TagApi.getAllTag();
let tagItems = [];
Expand Down
Loading

0 comments on commit 47d7e16

Please sign in to comment.