zs 2 gadi atpakaļ
vecāks
revīzija
55d35e041e

+ 1 - 0
src/config/config.default.ts

@@ -33,6 +33,7 @@ export default {
     export_path: 'D:\\temp\\export',
     export_dir: 'export',
     patentInfo_dir: 'patentInfo',
+    file_type: 'export',
     domain: 'http://broadcast.waityou24.cn',
   },
   rabbitmq: {

+ 1 - 0
src/config/config.local.ts

@@ -53,6 +53,7 @@ export default {
     export_path: 'D:\\temp\\export',
     export_dir: 'export',
     patentInfo_dir: 'patentInfo',
+    file_type: 'export',
     domain: 'http://broadcast.waityou24.cn',
   },
   rabbitmq: {

+ 1 - 0
src/config/config.prod.ts

@@ -53,6 +53,7 @@ export default {
     export_path: 'D:\\temp\\export',
     export_dir: 'export',
     patentInfo_dir: 'patentInfo',
+    file_type: 'export',
     domain: 'http://broadcast.waityou24.cn',
   },
   rabbitmq: {

+ 2 - 1
src/controller/patent.controller.ts

@@ -19,6 +19,7 @@ import {
   UDTO_patent,
   UVAO_patent,
   ImportDTO,
+  ExportDTO,
 } from '../interface/patent.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
@@ -86,7 +87,7 @@ export class PatentController extends BaseController {
 
   @Post('/export')
   @Validate()
-  async export(@Body() body: any) {
+  async export(@Body() body: ExportDTO) {
     const result = await this.service.export(body);
     return result;
   }

+ 14 - 0
src/interface/patent.interface.ts

@@ -321,3 +321,17 @@ export class ImportDTO {
   @Rule(RuleType['string']().empty(''))
   'code': string = undefined;
 }
+export class ExportDTO {
+  @ApiProperty({ description: 'file', example: [] })
+  @Rule(RuleType['array']().empty(''))
+  'file': Array<any> = undefined;
+  @ApiProperty({ description: '条件', example: '' })
+  @Rule(RuleType['string']().empty(''))
+  'filter': string = undefined;
+  @ApiProperty({ description: '开始条数', example: '' })
+  @Rule(RuleType['string']().empty(''))
+  'start_num': string = undefined;
+  @ApiProperty({ description: '结束条数', example: '' })
+  @Rule(RuleType['string']().empty(''))
+  'end_num': string = undefined;
+}

+ 33 - 19
src/service/patent.service.ts

@@ -19,6 +19,8 @@ const compressing = require('compressing');
 import * as fs from 'node:fs';
 import * as Path from 'node:path';
 const sep = Path.sep;
+import { Types } from 'mongoose';
+const ObjectId = Types.ObjectId;
 type modelType = ReturnModelType<typeof Patent>;
 @Provide()
 export class PatentService extends BaseService<modelType> {
@@ -187,15 +189,17 @@ export class PatentService extends BaseService<modelType> {
         const has_data = await this.model.count({
           create_number: obj.create_number,
         });
-        let res;
+        const res = await this.model.findOne({
+          create_number: obj.create_number,
+        });
         if (has_data === 0) {
-          res = await this.model.create(obj);
+          await this.model.create(obj);
         } else {
-          await this.model.updateOne({ create_number: obj.create_number }, obj);
-          res = await this.model.findOne({ create_number: obj.create_number });
+          await this.model.updateOne(new ObjectId(res._id), obj);
+          // res = await this.model.findOne({ create_number: obj.create_number });
         }
-        // 处理警告
-        if (res.term === '1') this.dealData([res]);
+        // // 处理警告
+        // if (res.term === '1') this.dealData([res]);
       } catch (error) {
         allNotice.push(`申请号 为${create_number} 的 专利信息 创建失败!`);
         continue;
@@ -203,10 +207,14 @@ export class PatentService extends BaseService<modelType> {
     }
   }
   // 导出
-  async export({ missionid, query }) {
-    const path = `${this.root_path}${sep}${this.file_type}${sep}${
-      this.patentInfo_dir
-    }${new Date().getTime()}`;
+  async export(query) {
+    const termList: any = await this.adminAxios.get(
+      'dictData?type=patent_term'
+    );
+    const typeList: any = await this.adminAxios.get(
+      'dictData?type=patent_type'
+    );
+    const path = `${this.root_path}${sep}${this.file_type}`;
     if (!path) {
       throw new ServiceError(
         '服务端没有设置存储路径',
@@ -240,9 +248,9 @@ export class PatentService extends BaseService<modelType> {
           const d = list[k];
           const arr = [];
           for (const m of meta) {
-            const { key } = m;
-            if (key === 'img_url') {
-              const value = d[key];
+            const { model } = m;
+            if (model === 'file') {
+              const value = d[model];
               // 需要图片占列,否则会窜位置
               arr.push('');
               if (_.isArray(value)) {
@@ -261,7 +269,13 @@ export class PatentService extends BaseService<modelType> {
                     sheet.addImage(imgId, sheetRange);
                 }
               }
-            } else arr.push(d[key]);
+            } else if (model === 'type') {
+              const data = typeList.data.find(i => i.value === d[model]);
+              arr.push(data.label);
+            } else if (model === 'term') {
+              const data = termList.data.find(i => i.value === d[model]);
+              arr.push(data.label);
+            } else arr.push(d[model]);
           }
           sheet.addRow(arr);
         }
@@ -278,7 +292,7 @@ export class PatentService extends BaseService<modelType> {
           const data = {
             progress,
             status: '1',
-            id: missionid,
+            // id: missionid,
             remark: '组织数据生成excel中...',
           };
           await this.sendToMQ(data);
@@ -289,7 +303,7 @@ export class PatentService extends BaseService<modelType> {
         const data = {
           progress: 0,
           status: '-1',
-          id: missionid,
+          // id: missionid,
           remark: '组织数据进入excel失败',
         };
         this.sendToMQ(data);
@@ -300,7 +314,7 @@ export class PatentService extends BaseService<modelType> {
       const data = {
         progress: 98,
         status: '1',
-        id: missionid,
+        // id: missionid,
         remark: '正在打包',
       };
       this.sendToMQ(data);
@@ -322,7 +336,7 @@ export class PatentService extends BaseService<modelType> {
         progress: 100,
         status: '2',
         uri: downloadPath,
-        id: missionid,
+        // id: missionid,
         remark: '打包成功',
       };
       this.sendToMQ(data);
@@ -330,7 +344,7 @@ export class PatentService extends BaseService<modelType> {
       const data = {
         progress: 0,
         status: '-2',
-        id: missionid,
+        // id: missionid,
         remark: '打包失败',
       };
       this.sendToMQ(data);