mirror of
https://github.com/geekgeekrun/geekgeekrun.git
synced 2026-05-06 20:02:47 +08:00
save autoStartupChatRecordId, chatStartupFrom in ChatStartupLog
This commit is contained in:
11
packages/sqlite-plugin/src/entity/AutoStartChatRunRecord.ts
Normal file
11
packages/sqlite-plugin/src/entity/AutoStartChatRunRecord.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { requireTypeorm } from "../utils/module-loader";
|
||||
const { Entity, Column, PrimaryGeneratedColumn } = requireTypeorm();
|
||||
|
||||
@Entity()
|
||||
export class AutoStartChatRunRecord {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
date: Date;
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
import { requireTypeorm } from "../utils/module-loader";
|
||||
const { Entity, Column, PrimaryGeneratedColumn } = requireTypeorm()
|
||||
|
||||
export enum ChatStartupFrom {
|
||||
AutoFromRecommendList = null,
|
||||
ManuallyFromRecommendList = 1
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class ChatStartupLog {
|
||||
@PrimaryGeneratedColumn()
|
||||
@@ -14,4 +19,14 @@ export class ChatStartupLog {
|
||||
|
||||
@Column()
|
||||
date: Date;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
chatStartupFrom?: ChatStartupFrom;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
autoStartupChatRecordId?: number;
|
||||
}
|
||||
|
||||
@@ -238,7 +238,12 @@ export async function saveJobInfoFromRecommendPage(ds: DataSource, _jobInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
export async function saveChatStartupRecord(ds: DataSource, _jobInfo, { encryptUserId }) {
|
||||
export async function saveChatStartupRecord(
|
||||
ds: DataSource,
|
||||
_jobInfo,
|
||||
{ encryptUserId },
|
||||
{ autoStartupChatRecordId = undefined, chatStartupFrom = undefined } = {}
|
||||
) {
|
||||
const { jobInfo } = _jobInfo;
|
||||
|
||||
//#region chat-startup-log
|
||||
@@ -247,6 +252,8 @@ export async function saveChatStartupRecord(ds: DataSource, _jobInfo, { encryptU
|
||||
date: new Date(),
|
||||
encryptCurrentUserId: encryptUserId,
|
||||
encryptJobId: jobInfo.encryptId,
|
||||
autoStartupChatRecordId,
|
||||
chatStartupFrom
|
||||
}
|
||||
Object.assign(chatStartupLog, chatStartupLogPayload)
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@ import { requireTypeorm } from "./utils/module-loader";
|
||||
|
||||
import { BossInfo } from "./entity/BossInfo";
|
||||
import { BossInfoChangeLog } from "./entity/BossInfoChangeLog";
|
||||
import { ChatStartupLog } from './entity/ChatStartupLog';
|
||||
import { ChatStartupFrom, ChatStartupLog } from './entity/ChatStartupLog';
|
||||
import { CompanyInfoChangeLog } from "./entity/CompanyInfoChangeLog";
|
||||
import { CompanyInfo } from "./entity/CompanyInfo";
|
||||
import { JobInfo } from "./entity/JobInfo";
|
||||
import { JobInfoChangeLog } from "./entity/JobInfoChangeLog";
|
||||
import { BossActiveStatusRecord } from "./entity/BossActiveStatusRecord";
|
||||
import { UserInfo } from "./entity/UserInfo";
|
||||
import { AutoStartChatRunRecord } from './entity/AutoStartChatRunRecord';
|
||||
import { VChatStartupLog } from "./entity/VChatStartupLog";
|
||||
import { VBossLibrary } from "./entity/VBossLibrary";
|
||||
import { VJobLibrary } from "./entity/VJobLibrary";
|
||||
@@ -19,6 +20,8 @@ import { VCompanyLibrary } from "./entity/VCompanyLibrary"
|
||||
import sqlite3 from 'sqlite3';
|
||||
import * as cliHighlight from 'cli-highlight';
|
||||
import { saveChatStartupRecord, saveJobInfoFromRecommendPage } from "./handlers";
|
||||
import { UpdateChatStartupLogTable1729182577167 } from "./migrations/1729182577167-UpdateChatStartupLogTable";
|
||||
|
||||
Boolean(cliHighlight);
|
||||
|
||||
export function initDb(dbFilePath) {
|
||||
@@ -40,17 +43,23 @@ export function initDb(dbFilePath) {
|
||||
JobInfoChangeLog,
|
||||
BossActiveStatusRecord,
|
||||
UserInfo,
|
||||
AutoStartChatRunRecord,
|
||||
VChatStartupLog,
|
||||
VBossLibrary,
|
||||
VJobLibrary,
|
||||
VCompanyLibrary
|
||||
],
|
||||
migrations: [
|
||||
UpdateChatStartupLogTable1729182577167
|
||||
],
|
||||
migrationsRun: true
|
||||
});
|
||||
return appDataSource.initialize();
|
||||
}
|
||||
|
||||
export default class SqlitePlugin {
|
||||
initPromise: Promise<DataSource>;
|
||||
runRecordId: number;
|
||||
|
||||
constructor(dbFilePath) {
|
||||
this.initPromise = initDb(dbFilePath);
|
||||
@@ -59,6 +68,20 @@ export default class SqlitePlugin {
|
||||
userInfo = null
|
||||
|
||||
apply(hooks) {
|
||||
hooks.daemonInitialized.tapPromise(
|
||||
"SqlitePlugin",
|
||||
async () => {
|
||||
const ds = await this.initPromise;
|
||||
|
||||
const autoStartChatRunRecord = new AutoStartChatRunRecord();
|
||||
autoStartChatRunRecord.date = new Date();
|
||||
|
||||
const autoStartChatRunRecordRepository = ds.getRepository(AutoStartChatRunRecord)
|
||||
const result = await autoStartChatRunRecordRepository.save(autoStartChatRunRecord);
|
||||
|
||||
this.runRecordId = result.id;
|
||||
}
|
||||
);
|
||||
hooks.userInfoResponse.tapPromise(
|
||||
"SqlitePlugin",
|
||||
async (userInfoResponse) => {
|
||||
@@ -85,9 +108,12 @@ export default class SqlitePlugin {
|
||||
await saveJobInfoFromRecommendPage(ds, _jobInfo);
|
||||
});
|
||||
|
||||
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo) => {
|
||||
hooks.newChatStartup.tapPromise("SqlitePlugin", async (_jobInfo, { chatStartupFrom = ChatStartupFrom.AutoFromRecommendList } = {}) => {
|
||||
const ds = await this.initPromise;
|
||||
return await saveChatStartupRecord(ds, _jobInfo, this.userInfo);
|
||||
return await saveChatStartupRecord(ds, _jobInfo, this.userInfo, {
|
||||
autoStartupChatRecordId: this.runRecordId,
|
||||
chatStartupFrom
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
const dropViewSql = `DROP VIEW IF EXISTS "v_chat_startup_log"`;
|
||||
|
||||
export class UpdateChatStartupLogTable1729182577167 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(dropViewSql);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(dropViewSql);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as path from 'node:path';
|
||||
import type typeormType from 'typeorm'
|
||||
import type TypeormType from 'typeorm'
|
||||
const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE)
|
||||
const isUiDev = process.env.NODE_ENV === 'development'
|
||||
|
||||
export function requireTypeorm () {
|
||||
export function requireTypeorm (): typeof TypeormType {
|
||||
const importResult = require('typeorm')
|
||||
return importResult
|
||||
}
|
||||
Reference in New Issue
Block a user