patent.controller.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {
  2. Body,
  3. Controller,
  4. Del,
  5. Get,
  6. Inject,
  7. Param,
  8. Post,
  9. Query,
  10. } from '@midwayjs/decorator';
  11. import { BaseController } from 'free-midway-component';
  12. import { PatentService } from '../service/patent.service';
  13. import {
  14. CDTO_patent,
  15. CVO_patent,
  16. FVO_patent,
  17. // QDTO_patent,
  18. QVO_patent,
  19. UDTO_patent,
  20. UVAO_patent,
  21. ImportDTO,
  22. ExportDTO,
  23. updateUserDTO,
  24. } from '../interface/patent.interface';
  25. import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
  26. import { Validate } from '@midwayjs/validate';
  27. import { RedisService } from '@midwayjs/redis';
  28. @ApiTags(['e专利'])
  29. @Controller('/patent')
  30. export class PatentController extends BaseController {
  31. @Inject()
  32. service: PatentService;
  33. @Inject()
  34. redisService: RedisService;
  35. @Post('/')
  36. @Validate()
  37. @ApiResponse({ type: CVO_patent })
  38. async create(@Body() data: CDTO_patent) {
  39. const dbData = await this.service.create(data);
  40. const result = new CVO_patent(dbData);
  41. return result;
  42. }
  43. @Get('/')
  44. @ApiQuery({ name: 'query' })
  45. @ApiResponse({ type: QVO_patent })
  46. async query(@Query() filter: any) {
  47. const list = await this.service.beforeQuery(filter);
  48. const data = [];
  49. for (const i of list.data) {
  50. const newData = new QVO_patent(i);
  51. data.push(newData);
  52. }
  53. const total = list.total;
  54. return { data, total };
  55. }
  56. @Get('/:id')
  57. @ApiResponse({ type: FVO_patent })
  58. async fetch(@Param('id') id: string) {
  59. const data = await this.service.fetch(id);
  60. const result = new FVO_patent(data);
  61. return result;
  62. }
  63. @Get('/findFromQueue')
  64. async findFromQueue() {
  65. const result = await this.redisService.get('file');
  66. return result || {};
  67. }
  68. @Post('/:id')
  69. @Validate()
  70. @ApiResponse({ type: UVAO_patent })
  71. async update(@Param('id') id: string, @Body() body: UDTO_patent) {
  72. const result = await this.service.updateOne(id, body);
  73. return result;
  74. }
  75. @Del('/:id')
  76. @Validate()
  77. async delete(@Param('id') id: string) {
  78. await this.service.delete(id);
  79. return 'ok';
  80. }
  81. @Post('/import')
  82. @Validate()
  83. async import(@Body() body: ImportDTO) {
  84. const result = await this.service.import(body);
  85. return result;
  86. }
  87. @Post('/export')
  88. @Validate()
  89. async export(@Body() body: ExportDTO) {
  90. const result = await this.service.export(body);
  91. return result;
  92. }
  93. @Post('/updateUser')
  94. @Validate()
  95. async updateUser(@Body() body: updateUserDTO) {
  96. const result = await this.service.updateUser(body);
  97. return result;
  98. }
  99. @Post('/deleteMany')
  100. @Validate()
  101. async deleteManys(@Body() body: updateUserDTO) {
  102. const result = await this.service.deleteManys(body);
  103. return result;
  104. }
  105. @Get('/deletion')
  106. @Validate()
  107. async deletion() {
  108. const result = await this.service.deletion();
  109. return result;
  110. }
  111. async createMany(...args: any[]) {
  112. throw new Error('Method not implemented.');
  113. }
  114. async updateMany(...args: any[]) {
  115. throw new Error('Method not implemented.');
  116. }
  117. async deleteMany(...args: any[]) {
  118. throw new Error('Method not implemented.');
  119. }
  120. }