From 2651de6541f99d106141bf9952344aed5169320c Mon Sep 17 00:00:00 2001 From: snowgitea Date: Wed, 1 Jul 2026 17:57:22 +0800 Subject: [PATCH] chore: src/modules/task/controller/admin/info.ts --- src/modules/task/controller/admin/info.ts | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/modules/task/controller/admin/info.ts diff --git a/src/modules/task/controller/admin/info.ts b/src/modules/task/controller/admin/info.ts new file mode 100644 index 0000000..21f6044 --- /dev/null +++ b/src/modules/task/controller/admin/info.ts @@ -0,0 +1,59 @@ +import { Body, Get, Inject, Post, Provide, Query } from '@midwayjs/core'; +import { CoolController, BaseController } from '@cool-midway/core'; +import { TaskInfoEntity } from '../../entity/info'; +import { TaskInfoService } from '../../service/info'; + +/** + * 任务 + */ +@Provide() +@CoolController({ + api: ['add', 'delete', 'update', 'info', 'page'], + entity: TaskInfoEntity, + service: TaskInfoService, + before: ctx => { + ctx.request.body.limit = ctx.request.body.repeatCount; + }, + pageQueryOp: { + fieldEq: ['status', 'type'], + }, +}) +export class TaskInfoController extends BaseController { + @Inject() + taskInfoService: TaskInfoService; + + /** + * 手动执行一次 + */ + @Post('/once', { summary: '执行一次' }) + async once(@Body('id') id: number) { + await this.taskInfoService.once(id); + this.ok(); + } + + /** + * 暂停任务 + */ + @Post('/stop', { summary: '停止' }) + async stop(@Body('id') id: number) { + await this.taskInfoService.stop(id); + this.ok(); + } + + /** + * 开始任务 + */ + @Post('/start', { summary: '开始' }) + async start(@Body('id') id: number, @Body('type') type: number) { + await this.taskInfoService.start(id, type); + this.ok(); + } + + /** + * 日志 + */ + @Get('/log', { summary: '日志' }) + async log(@Query() params: any) { + return this.ok(await this.taskInfoService.log(params)); + } +}