import { Body, Controller, Del, Get, Inject, Param, Post, Query, } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { PatentService } from '../service/patent.service'; import { CDTO_patent, CVO_patent, FVO_patent, // QDTO_patent, QVO_patent, UDTO_patent, UVAO_patent, ImportDTO, ExportDTO, updateUserDTO, } from '../interface/patent.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; import { RedisService } from '@midwayjs/redis'; @ApiTags(['e专利']) @Controller('/patent') export class PatentController extends BaseController { @Inject() service: PatentService; @Inject() redisService: RedisService; @Post('/') @Validate() @ApiResponse({ type: CVO_patent }) async create(@Body() data: CDTO_patent) { const dbData = await this.service.create(data); const result = new CVO_patent(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_patent }) async query(@Query() filter: any) { const list = await this.service.beforeQuery(filter); const data = []; for (const i of list.data) { const newData = new QVO_patent(i); data.push(newData); } const total = list.total; return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_patent }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_patent(data); return result; } @Get('/findFromQueue') async findFromQueue() { const result = await this.redisService.get('file'); return result || {}; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_patent }) async update(@Param('id') id: string, @Body() body: UDTO_patent) { 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'; } @Post('/import') @Validate() async import(@Body() body: ImportDTO) { const result = await this.service.import(body); return result; } @Post('/export') @Validate() async export(@Body() body: ExportDTO) { const result = await this.service.export(body); return result; } @Post('/updateUser') @Validate() async updateUser(@Body() body: updateUserDTO) { const result = await this.service.updateUser(body); return result; } @Post('/deleteMany') @Validate() async deleteManys(@Body() body: updateUserDTO) { const result = await this.service.deleteManys(body); return result; } @Get('/deletion') @Validate() async deletion() { const result = await this.service.deletion(); return result; } 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.'); } }