wangzhibo
2026-07-16 bac4362a0b7726d38a23d38f0d7913f2c2bab262
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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));
  }
}