Selaa lähdekoodia

导出任务管理

lrf 7 kuukautta sitten
vanhempi
commit
6bf12f1819

+ 34 - 5
src/controller/asyncExport.controller.ts

@@ -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);

+ 35 - 0
src/service/exportMission.service.ts

@@ -4,15 +4,50 @@ import { Repository } from 'typeorm';
 import { ExportMission } from '../entity/exportMission.entity';
 import { ExportMission } from '../entity/exportMission.entity';
 import { BaseServiceV2 } from '../frame/BaseServiceV2';
 import { BaseServiceV2 } from '../frame/BaseServiceV2';
 import Axios from 'axios';
 import Axios from 'axios';
+import { cloneDeep, get, head, isArray } from 'lodash';
+import { User } from '../entity/system/user.entity';
+import { Admin } from '../entity/system/admin.entity';
 
 
 @Provide()
 @Provide()
 export class ExportMissionService extends BaseServiceV2 {
 export class ExportMissionService extends BaseServiceV2 {
   @InjectEntityModel(ExportMission)
   @InjectEntityModel(ExportMission)
   model: Repository<ExportMission>;
   model: Repository<ExportMission>;
 
 
+  @InjectEntityModel(User)
+  user: Repository<User>;
+  @InjectEntityModel(Admin)
+  admin: Repository<Admin>;
+
   @Config('modulesConfig.mq')
   @Config('modulesConfig.mq')
   mqServiceHttpPrefix: any;
   mqServiceHttpPrefix: any;
 
 
+  async dealData(data) {
+    let list = [];
+    const returnData = [];
+    const isArr = isArray(data);
+    if (isArr) list = data;
+    else list.push(data);
+    for (const i of list) {
+      const obj = cloneDeep(i)
+      const { user_type, user } = i;
+      let model;
+      if (user_type === 'ADMIN') {
+        obj.user_type_name = '管理员';
+        model = this.admin;
+      } else if (user_type === 'USER') {
+        obj.user_type_name = '用户';
+        model = this.user;
+      }
+      if (!model) continue;
+      const userInfo = await model.createQueryBuilder().where(`"id" =:id`, { id: user }).getOne();
+      if (!userInfo) continue;
+      obj.user_name = get(userInfo, 'nick_name');
+      returnData.push(obj)
+    }
+    if (isArr) return returnData;
+    else return head(returnData);
+  }
+
   /**
   /**
    * 发送mq消息
    * 发送mq消息
    * @param id 任务id
    * @param id 任务id

+ 9 - 0
src/service/initData/initSystemData.service.ts

@@ -813,6 +813,15 @@ export class InitSystemDataService {
           },
           },
         ],
         ],
       },
       },
+      {
+        name: '导出任务',
+        order_num: 997,
+        path: '/export/index',
+        type: '1',
+        is_default: '0',
+        is_use: '0',
+        route_name: 'export',
+      },
       {
       {
         name: '站内消息',
         name: '站内消息',
         order_num: 998,
         order_num: 998,