zs 1 year ago
parent
commit
718044eedc

+ 89 - 0
src/controller/download.controller.ts

@@ -0,0 +1,89 @@
+import {
+  Body,
+  Controller,
+  Del,
+  Get,
+  Inject,
+  Param,
+  Post,
+  Query,
+} from '@midwayjs/decorator';
+import { BaseController } from 'free-midway-component';
+import { DownloadService } from '../service/download.service';
+import {
+  CDTO_download,
+  CVO_download,
+  FVO_download,
+  QDTO_download,
+  QVO_download,
+  UDTO_download,
+  UVAO_download,
+} from '../interface/download.interface';
+import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
+import { Validate } from '@midwayjs/validate';
+@ApiTags(['下载记录表'])
+@Controller('/download')
+export class DownloadController extends BaseController {
+  @Inject()
+  service: DownloadService;
+
+  @Post('/')
+  @Validate()
+  @ApiResponse({ type: CVO_download })
+  async create(@Body() data: CDTO_download) {
+    const dbData = await this.service.create(data);
+    const result = new CVO_download(dbData);
+    return result;
+  }
+  @Get('/')
+  @ApiQuery({ name: 'query' })
+  @ApiResponse({ type: QVO_download })
+  async query(
+    @Query() filter: QDTO_download,
+    @Query('skip') skip: number,
+    @Query('limit') limit: number
+  ) {
+    const list = await this.service.query(filter, { skip, limit });
+    const data = [];
+    for (const i of list) {
+      const newData = new QVO_download(i);
+      data.push(newData);
+    }
+    const total = await this.service.count(filter);
+    return { data, total };
+  }
+
+  @Get('/:id')
+  @ApiResponse({ type: FVO_download })
+  async fetch(@Param('id') id: string) {
+    const data = await this.service.fetch(id);
+    const result = new FVO_download(data);
+    return result;
+  }
+
+  @Post('/:id')
+  @Validate()
+  @ApiResponse({ type: UVAO_download })
+  async update(@Param('id') id: string, @Body() body: UDTO_download) {
+    const result = await this.service.updateOne(id, body);
+    return result;
+  }
+
+  @Del('/:id')
+  @Validate()
+  async delete(@Param('id') id: string) {
+    await this.service.delete(id);
+    return 'ok';
+  }
+  async createMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async updateMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+
+  async deleteMany(...args: any[]) {
+    throw new Error('Method not implemented.');
+  }
+}

+ 0 - 9
src/controller/patent.controller.ts

@@ -64,15 +64,6 @@ export class PatentController extends BaseController {
     return result;
   }
 
-  @Get('/findFromQueue')
-  async findFromQueue() {
-    const uri = await this.redisService.get('uri');
-    const remark = await this.redisService.get('remark');
-    const progress = await this.redisService.get('progress');
-    const result = { uri, remark, progress };
-    return result || {};
-  }
-
   @Post('/:id')
   @Validate()
   @ApiResponse({ type: UVAO_patent })

+ 21 - 0
src/entity/download.entity.ts

@@ -0,0 +1,21 @@
+import { modelOptions, prop } from '@typegoose/typegoose';
+import { BaseModel } from 'free-midway-component';
+@modelOptions({
+  schemaOptions: { collection: 'download' },
+})
+export class Download extends BaseModel {
+  @prop({ required: false, index: false, zh: '下载进度' })
+  progress: string;
+  @prop({ required: false, index: false, zh: '下载时间' })
+  create_time: string;
+  @prop({ required: false, index: false, zh: '文件路径' })
+  uri: string;
+  @prop({ required: false, index: false, zh: '状态' })
+  status: string;
+  @prop({ required: false, index: false, zh: '导出文件名称' })
+  title: string;
+  @prop({ required: false, index: true, zh: '导出用户' })
+  user: string;
+  @prop({ required: false, index: true, zh: '备注' })
+  remark: string;
+}

+ 93 - 0
src/interface/download.interface.ts

@@ -0,0 +1,93 @@
+import { Rule, RuleType } from '@midwayjs/validate';
+import { ApiProperty } from '@midwayjs/swagger';
+import { SearchBase } from 'free-midway-component';
+import get = require('lodash/get');
+const dealVO = (cla, data) => {
+  for (const key in cla) {
+    const val = get(data, key);
+    if (val || val === 0) cla[key] = val;
+  }
+};
+export class FVO_download {
+  constructor(data: object) {
+    dealVO(this, data);
+  }
+  @ApiProperty({ description: '数据id' })
+  _id: string = undefined;
+  @ApiProperty({ description: '下载进度' })
+  'progress': string = undefined;
+  @ApiProperty({ description: '下载时间' })
+  'create_time': string = undefined;
+  @ApiProperty({ description: '文件路径' })
+  'uri': string = undefined;
+  @ApiProperty({ description: '状态' })
+  'status': string = undefined;
+  @ApiProperty({ description: '导出文件名称' })
+  'title': string = undefined;
+  @ApiProperty({ description: '导出用户' })
+  'user': string = undefined;
+  @ApiProperty({ description: '备注' })
+  'remark': string = undefined;
+}
+
+export class QDTO_download extends SearchBase {
+  constructor() {
+    const like_prop = [];
+    const props = ['user'];
+    const mapping = [];
+    super({ like_prop, props, mapping });
+  }
+  @ApiProperty({ description: '导出用户' })
+  'user': string = undefined;
+}
+
+export class QVO_download extends FVO_download {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class CDTO_download {
+  @ApiProperty({ description: '下载进度' })
+  @Rule(RuleType['string']().empty(''))
+  'progress': string = undefined;
+  @ApiProperty({ description: '下载时间' })
+  @Rule(RuleType['string']().empty(''))
+  'create_time': string = undefined;
+  @ApiProperty({ description: '文件路径' })
+  @Rule(RuleType['string']().empty(''))
+  'uri': string = undefined;
+  @ApiProperty({ description: '状态' })
+  @Rule(RuleType['string']().empty(''))
+  'status': string = undefined;
+  @ApiProperty({ description: '导出文件名称' })
+  @Rule(RuleType['string']().empty(''))
+  'title': string = undefined;
+  @ApiProperty({ description: '导出用户' })
+  @Rule(RuleType['string']().empty(''))
+  'user': string = undefined;
+  @ApiProperty({ description: '备注' })
+  @Rule(RuleType['string']().empty(''))
+  'remark': string = undefined;
+}
+
+export class CVO_download extends FVO_download {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}
+
+export class UDTO_download extends CDTO_download {
+  @ApiProperty({ description: '数据id' })
+  @Rule(RuleType['string']().empty(''))
+  _id: string = undefined;
+}
+
+export class UVAO_download extends FVO_download {
+  constructor(data: object) {
+    super(data);
+    dealVO(this, data);
+  }
+}

+ 11 - 0
src/service/download.service.ts

@@ -0,0 +1,11 @@
+import { Provide } from '@midwayjs/decorator';
+import { InjectEntityModel } from '@midwayjs/typegoose';
+import { ReturnModelType } from '@typegoose/typegoose';
+import { BaseService } from 'free-midway-component';
+import { Download } from '../entity/download.entity';
+type modelType = ReturnModelType<typeof Download>;
+@Provide()
+export class DownloadService extends BaseService<modelType> {
+  @InjectEntityModel(Download)
+  model: modelType;
+}

+ 8 - 7
src/service/patent.service.ts

@@ -8,6 +8,7 @@ import {
 } from 'free-midway-component';
 import { Patent } from '../entity/patent.entity';
 import { PatentWarning } from '../entity/patentWarning.entity';
+import { Download } from '../entity/download.entity';
 import { HttpServiceFactory, HttpService } from '@midwayjs/axios';
 import { Config, InjectClient } from '@midwayjs/core';
 import { RabbitmqService } from './util/rabbitmq';
@@ -31,6 +32,9 @@ export class PatentService extends BaseService<modelType> {
   @InjectEntityModel(PatentWarning)
   PatentModel: ReturnModelType<typeof PatentWarning>;
 
+  @InjectEntityModel(Download)
+  downloadModel: ReturnModelType<typeof Download>;
+
   @InjectClient(HttpServiceFactory, 'Axios')
   Axios: HttpService;
 
@@ -238,9 +242,6 @@ export class PatentService extends BaseService<modelType> {
   }
   // 导出
   async export(query) {
-    this.redisService.del('uri');
-    this.redisService.del('remark');
-    this.redisService.del('progress');
     const termList: any = await this.adminAxios.get(
       'dictData?type=patent_term'
     );
@@ -466,10 +467,10 @@ export class PatentService extends BaseService<modelType> {
     ) {
       data.progress = 100;
     }
-    this.redisService.set('uri', data.uri || '');
-    this.redisService.set('remark', data.remark);
-    this.redisService.set('progress', data.progress);
-    // console.log(`${_.get(data, 'progress') || '失败'} %`);
+    data.title = '专利信息文件';
+    data.user = this.ctx.user?._id || '';
+    data.create_time = moment().format('YYYY-MM-DD HH:mm:ss');
+    await this.downloadModel.create(data);
     await this.rabbitmqService.connect();
     await this.rabbitmqService.sendToQueue('tasks', data);
     await this.rabbitmqService.close();