diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index ef1b0bb..e7a2d75 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -1288,6 +1288,7 @@ export async function mainLoop (hooks) { expectCityNotMatchStrategy, blockJobNotSuit, blockBossNotActive, + blockBossNotNewChat }) await toRecommendPage(hooks) // goto search diff --git a/packages/sqlite-plugin/src/handlers.ts b/packages/sqlite-plugin/src/handlers.ts index fcda892..38ebf0d 100644 --- a/packages/sqlite-plugin/src/handlers.ts +++ b/packages/sqlite-plugin/src/handlers.ts @@ -333,9 +333,33 @@ export async function getNotSuitMarkRecordsInLastSomeDays (ds: DataSource, days const result = await repo.findBy({ date: Raw(alias => `DATE(${alias}) >= DATE('${ new Date( - Number(new Date()) - 7 * 24 * 60 * 60 * 1000 + Number(new Date()) - days * 24 * 60 * 60 * 1000 ).toISOString() }')`) }) return result } + +export async function getChatStartupRecordsInLastSomeDays (ds: DataSource, days = 0) { + const repo = ds.getRepository(ChatStartupLog) + const result = await repo.findBy({ + date: Raw(alias => `DATE(${alias}) >= DATE('${ + new Date( + Number(new Date()) - days * 24 * 60 * 60 * 1000 + ).toISOString() + }')`) + }) + return result +} + +export async function getBossIdsByJobIds (ds: DataSource, jobIds: string[] = []) { + const repo = ds.getRepository(JobInfo) + const result = await repo.find({ + where: jobIds.map( + id => ({ + encryptJobId: id + }) + ) + }) + return result +} diff --git a/packages/sqlite-plugin/src/index.ts b/packages/sqlite-plugin/src/index.ts index 21860cc..324c57f 100644 --- a/packages/sqlite-plugin/src/index.ts +++ b/packages/sqlite-plugin/src/index.ts @@ -23,7 +23,14 @@ import { ChatMessageRecord } from './entity/ChatMessageRecord' import { LlmModelUsageRecord } from './entity/LlmModelUsageRecord' import sqlite3 from 'sqlite3'; -import { saveChatStartupRecord, saveJobInfoFromRecommendPage, saveMarkAsNotSuitRecord, getNotSuitMarkRecordsInLastSomeDays } from "./handlers"; +import { + saveChatStartupRecord, + saveJobInfoFromRecommendPage, + saveMarkAsNotSuitRecord, + getNotSuitMarkRecordsInLastSomeDays, + getChatStartupRecordsInLastSomeDays, + getBossIdsByJobIds +} from "./handlers"; import { UpdateChatStartupLogTable1729182577167 } from "./migrations/1729182577167-UpdateChatStartupLogTable"; import minimist from 'minimist' import { UpdateBossInfoTable1732032381304 } from "./migrations/1732032381304-UpdateBossInfoTable"; @@ -111,6 +118,7 @@ export default class SqlitePlugin { expectCityNotMatchStrategy, blockJobNotSuit, blockBossNotActive, + blockBossNotNewChat }) => { if ( jobNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_LOCAL || @@ -118,7 +126,7 @@ export default class SqlitePlugin { expectCityNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_LOCAL ) { const ds = await this.initPromise; - const last7DayMarkRecords = (await getNotSuitMarkRecordsInLastSomeDays(ds, 7) ?? []); + const last7DayMarkRecords = (await getNotSuitMarkRecordsInLastSomeDays(ds, 7)) ?? []; if ( jobNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_LOCAL || jobNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_BOSS @@ -163,6 +171,12 @@ export default class SqlitePlugin { id => blockJobNotSuit.add(id) ) } + const last30DayChatStartupRecords = (await getChatStartupRecordsInLastSomeDays(ds, 30)) ?? []; + const chattedJobIds = last30DayChatStartupRecords.map(it => it.encryptJobId) + const chattedBossIds = ((await getBossIdsByJobIds(ds, chattedJobIds)) ?? []).map(it => it.encryptBossId) + for (const id of chattedBossIds) { + blockBossNotNewChat.add(id) + } } } );