diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 0c2be8c..264c5f8 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -168,7 +168,6 @@ async function toRecommendPage (hooks) { ) : jobListData.findIndex( it => !blockBossNotNewChat.has(it.encryptBossId) ) - debugger let hasReachLastPage = false @@ -283,6 +282,8 @@ async function toRecommendPage (hooks) { await sleepWithRandomDelay(2000) } const jobData = await page.evaluate('document.querySelector(".job-detail-box").__vue__.data') + // save the job detail info + await hooks.jobDetailIsGetFromRecommendList?.promise(jobData) const startChatButtonInnerHTML = await page.evaluate('document.querySelector(".job-detail-box .op-btn.op-btn-chat")?.innerHTML.trim()') if (startChatButtonInnerHTML === '立即沟通') { diff --git a/packages/sqlite-plugin/src/index.ts b/packages/sqlite-plugin/src/index.ts index 5181b61..9eec959 100644 --- a/packages/sqlite-plugin/src/index.ts +++ b/packages/sqlite-plugin/src/index.ts @@ -74,7 +74,7 @@ export default class SqlitePlugin { } ); - hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => { + hooks.jobDetailIsGetFromRecommendList.tapPromise("SqlitePlugin", async (_jobInfo) => { console.log(_jobInfo); const ds = await this.initPromise; @@ -130,6 +130,31 @@ export default class SqlitePlugin { 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 + }); + + hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => { + const { jobInfo } = _jobInfo; + //#region chat-startup-log const chatStartupLog = new ChatStartupLog() const chatStartupLogPayload: Partial = { @@ -139,6 +164,7 @@ export default class SqlitePlugin { } Object.assign(chatStartupLog, chatStartupLogPayload) + const ds = await this.initPromise; const chatStartupLogRepository = ds.getRepository(ChatStartupLog); await chatStartupLogRepository.save(chatStartupLog); //#endregion diff --git a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts index 74adbaf..6338d47 100644 --- a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts +++ b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts @@ -83,6 +83,7 @@ const runAutoChat = async () => { pageLoaded: new SyncHook(), cookieWillSet: new SyncHook(['cookies']), userInfoResponse: new AsyncSeriesHook(['userInfo']), + jobDetailIsGetFromRecommendList: new AsyncSeriesHook(['userInfo']), newChatWillStartup: new AsyncSeriesHook(['positionInfoDetail']), newChatStartup: new AsyncSeriesHook(['positionInfoDetail']), noPositionFoundForCurrentJob: new SyncHook(),