|
@@ -1,11 +1,13 @@
|
|
-import { Controller, Post, Body, Inject } from '@midwayjs/core';
|
|
|
|
|
|
+import { Controller, Post, Body, Inject, Get, Query } from '@midwayjs/core';
|
|
import { Context } from '@midwayjs/koa';
|
|
import { Context } from '@midwayjs/koa';
|
|
-import { get, omit } from 'lodash';
|
|
|
|
|
|
+import { get, isObject, omit, pick } from 'lodash';
|
|
import { ErrorCode, ServiceError } from '../error/service.error';
|
|
import { ErrorCode, ServiceError } from '../error/service.error';
|
|
import { ExportMissionService } from '../service/exportMission.service';
|
|
import { ExportMissionService } from '../service/exportMission.service';
|
|
import { AsyncExportService } from '../service/asyncExport.service';
|
|
import { AsyncExportService } from '../service/asyncExport.service';
|
|
-
|
|
|
|
-@Controller('/asyncExport')
|
|
|
|
|
|
+import { ApiTags } from '@midwayjs/swagger';
|
|
|
|
+const namePrefix = '导出任务';
|
|
|
|
+@ApiTags(['导出任务'])
|
|
|
|
+@Controller('/asyncExport', { tagName: namePrefix })
|
|
export class AsyncExportController {
|
|
export class AsyncExportController {
|
|
@Inject()
|
|
@Inject()
|
|
ctx: Context;
|
|
ctx: Context;
|
|
@@ -14,7 +16,34 @@ export class AsyncExportController {
|
|
@Inject()
|
|
@Inject()
|
|
aeService: AsyncExportService;
|
|
aeService: AsyncExportService;
|
|
|
|
|
|
- @Post('/')
|
|
|
|
|
|
+ @Get('/')
|
|
|
|
+ async query(@Query() query: object) {
|
|
|
|
+ const qobj: any = omit(query, ['skip', 'limit']);
|
|
|
|
+ const others = pick(query, ['skip', 'limit']);
|
|
|
|
+ const userInfo = get(this.ctx, 'user');
|
|
|
|
+ if (!userInfo || !get(userInfo, 'id')) throw new ServiceError(ErrorCode.NOT_LOGIN);
|
|
|
|
+ const user = get(userInfo, 'id');
|
|
|
|
+ const is_super = get(userInfo, 'is_super');
|
|
|
|
+ if (is_super !== '0') {
|
|
|
|
+ const role = get(user, 'role', []);
|
|
|
|
+ const isAdmin = role.find(f => f === 'Admin');
|
|
|
|
+ let user_type = '';
|
|
|
|
+ if (isAdmin) user_type = 'ADMIN';
|
|
|
|
+ else user_type = 'USER';
|
|
|
|
+ qobj.user = user;
|
|
|
|
+ qobj.user_type = user_type;
|
|
|
|
+ }
|
|
|
|
+ const { data, total } = await this.missionService.query(qobj, others);
|
|
|
|
+ const nd = await this.missionService.dealData(data);
|
|
|
|
+ return { data: nd, total };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Post('/reExecute', { routerName: `重执行${namePrefix}` })
|
|
|
|
+ async reExecute(@Body('id') id: number) {
|
|
|
|
+ await this.missionService.toSendMq(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Post('/', { routerName: `创建${namePrefix}` })
|
|
async index(@Body() body: object) {
|
|
async index(@Body() body: object) {
|
|
const user = get(this.ctx, 'user');
|
|
const user = get(this.ctx, 'user');
|
|
if (!user || !get(user, 'id')) throw new ServiceError(ErrorCode.NOT_LOGIN);
|
|
if (!user || !get(user, 'id')) throw new ServiceError(ErrorCode.NOT_LOGIN);
|