Skip to content

Let's use AI to Earn!

feat: 自动进程模块

yikaJasonMicd20fe41c93c5
diff --git a/electron/main/app.ts b/electron/main/app.ts
index dbd0ec7d..64f10241 100644
--- a/electron/main/app.ts
+++ b/electron/main/app.ts
@@ -1,7 +1,7 @@
/*
* @Author: nevin
* @Date: 2025-01-24 16:33:22
- * @LastEditTime: 2025-02-20 22:11:44
+ * @LastEditTime: 2025-03-18 20:53:15
* @LastEditors: nevin
* @Description:
*/
@@ -17,6 +17,7 @@ import { ToolsModule } from './tools/module';
import { AppController } from './controller';
import { AppService } from './service';
import { ReplyModule } from './reply/module';
+import { AutoRunModule } from './autoRun/module';
@Module({
imports: [
@@ -28,6 +29,7 @@ import { ReplyModule } from './reply/module';
DataCenterModule,
TestModule,
ReplyModule,
+ AutoRunModule,
],
controllers: [AppController],
providers: [AppService],
diff --git a/electron/main/autoRun/comment.ts b/electron/main/autoRun/comment.ts
new file mode 100644
index 00000000..8500f0bb
--- /dev/null
+++ b/electron/main/autoRun/comment.ts
@@ -0,0 +1,27 @@
+/*
+ * @Author: nevin
+ * @Date: 2025-01-21 21:12:52
+ * @LastEditTime: 2025-02-21 21:13:19
+ * @LastEditors: nevin
+ * @Description:
+ */
+import { store } from '../../global/store';
+import { IUserStore } from '@/store/user';
+import { IUserInfo } from '@/api/types/user-t';
+import { StoreKey } from '../../../src/utils/StroeEnum';
+
+// 完整的响应数据接口
+interface ResponseData {
+ state: IUserStore;
+ version: number;
+}
+
+export function getUserInfo(): IUserInfo {
+ const res: ResponseData = JSON.parse(store.get(StoreKey.User));
+ return res.state.userInfo!;
+}
+
+export function getUserToken() {
+ const res: ResponseData = JSON.parse(store.get(StoreKey.User));
+ return res.state.token;
+}
diff --git a/electron/main/autoRun/controller.ts b/electron/main/autoRun/controller.ts
new file mode 100644
index 00000000..bdba5fb0
--- /dev/null
+++ b/electron/main/autoRun/controller.ts
@@ -0,0 +1,86 @@
+/*
+ * @Author: nevin
+ * @Date: 2025-01-20 22:02:54
+ * @LastEditTime: 2025-03-18 20:53:55
+ * @LastEditors: nevin
+ * @Description: autoRun AutoRun
+ */
+import { Controller, Icp, Inject } from '../core/decorators';
+import { AutoRunService } from './service';
+
+@Controller()
+export class AutoRunController {
+ @Inject(AutoRunService)
+ private readonly autoRunService!: AutoRunService;
+
+ /**
+ * 创建进程
+ */
+ @Icp('ICP_AUTO_RUN_CREATE')
+ async createAutoRun(event: Electron.IpcMainInvokeEvent, data: any) {
+ const autoRun = await this.autoRunService.createAutoRun(data);
+
+ return autoRun;
+ }
+
+ /**
+ * 进程列表
+ */
+ @Icp('ICP_AUTO_RUN_LIST')
+ async getAutoRunList(event: Electron.IpcMainInvokeEvent) {
+ const list = await this.autoRunService.findAutoRunList({});
+
+ return list;
+ }
+
+ /**
+ * 更新进程状态
+ */
+ @Icp('ICP_AUTO_RUN_STATUS')
+ async updateAutoRunStatus(
+ event: Electron.IpcMainInvokeEvent,
+ data: { id: number; status: number },
+ ) {
+ const { id, status } = data;
+ const autoRun = await this.autoRunService.updateAutoRunStatus(id, status);
+
+ return autoRun;
+ }
+
+ /**
+ * 创建进程记录
+ */
+ @Icp('ICP_AUTO_RUN_RECORD_CREATE')
+ async createAutoRunRecord(event: Electron.IpcMainInvokeEvent, data: any) {
+ const autoRunRecord = await this.autoRunService.createAutoRunRecord(data);
+
+ return autoRunRecord;
+ }
+
+ /**
+ * 更新进程记录状态
+ */
+ @Icp('ICP_AUTO_RUN_RECORD_STATUS')
+ async updateAutoRunRecordStatus(
+ event: Electron.IpcMainInvokeEvent,
+ data: { id: number; status: number },
+ ) {
+ const { id, status } = data;
+ const autoRun = await this.autoRunService.updateAutoRunRecordStatus(
+ id,
+ status,
+ );
+
+ return autoRun;
+ }
+
+ /**
+ * 获取进程记录列表
+ */
+ @Icp('ICP_AUTO_RUN_RECORD_LIST')
+ async getCommentList(event: Electron.IpcMainInvokeEvent): Promise<any> {
+ const list = await this.autoRunService.findAutoRunRecordList({});
+
+ return list;
+ }
+}
diff --git a/electron/main/autoRun/module.ts b/electron/main/autoRun/module.ts
new file mode 100644
index 00000000..e2d648f7
--- /dev/null
+++ b/electron/main/autoRun/module.ts
@@ -0,0 +1,16 @@
+/*
+ * @Author: nevin
+ * @Date: 2025-01-24 16:35:59
+ * @LastEditTime: 2025-03-18 19:50:10
+ * @LastEditors: nevin
+ * @Description: autoRun AutoRun 自动脚本
+ */
+import { Module } from '../core/decorators';
+import { AutoRunController } from './controller';
+import { AutoRunService } from './service';
+
+@Module({
+ controllers: [AutoRunController],
+ providers: [AutoRunService],
+})
+export class AutoRunModule {}
diff --git a/electron/main/autoRun/service.ts b/electron/main/autoRun/service.ts
new file mode 100644
index 00000000..48e4449d
--- /dev/null
+++ b/electron/main/autoRun/service.ts
@@ -0,0 +1,64 @@
+/*
+ * @Author: nevin
+ * @Date: 2025-01-24 17:10:35
+ * @LastEditors: nevin
+ * @Description: autoRun AutoRun
+ */
+import { Injectable } from '../core/decorators';
+import { AutoRunModel, AutoRunStatus } from '../../db/models/autoRun';
+import {
+ AutoRunRecordModel,
+ AutoRunRecordStatus,
+} from '../../db/models/autoRunRecord';
+import { Repository } from 'typeorm';
+import { AppDataSource } from '../../db';
+
+@Injectable()
+export class AutoRunService {
+ private autoRunRepository: Repository<AutoRunModel>;
+ private autoRunRecordRepository: Repository<AutoRunRecordModel>;
+
+ constructor() {
+ this.autoRunRepository = AppDataSource.getRepository(AutoRunModel);
+ this.autoRunRecordRepository =
+ AppDataSource.getRepository(AutoRunRecordModel);
+ }
+
+ // 创建进程
+ async createAutoRun(data: AutoRunModel) {
+ return await this.autoRunRepository.save(data);
+ }
+
+ // 查询进程列表
+ async findAutoRunList(data: Partial<AutoRunModel>) {
+ return await this.autoRunRepository.find({
+ where: data,
+ });
+ }
+
+ // 更新进程状态
+ async updateAutoRunStatus(id: number, status: AutoRunStatus) {
+ return await this.autoRunRepository.update(id, {
+ status,
+ });
+ }
+
+ // 创建进程记录
+ async createAutoRunRecord(data: AutoRunRecordModel) {
+ return await this.autoRunRecordRepository.save(data);
+ }
+
+ // 查询进程记录列表
+ async findAutoRunRecordList(data: Partial<AutoRunRecordModel>) {
+ return await this.autoRunRecordRepository.find({
+ where: data,
+ });
+ }
+
+ // 更新进程记录状态
+ async updateAutoRunRecordStatus(id: number, status: AutoRunRecordStatus) {
+ return await this.autoRunRecordRepository.update(id, {
+ status,
+ });
+ }
+}