Procházet zdrojové kódy

info去掉调试;warning修改

ruifeng_liu před 3 roky
rodič
revize
3a17a60e3c
2 změnil soubory, kde provedl 103 přidání a 88 odebrání
  1. 0 1
      app/service/patent/patentinfo.js
  2. 103 87
      app/service/patent/patentwarning.js

+ 0 - 1
app/service/patent/patentinfo.js

@@ -83,7 +83,6 @@ class PatentinfoService extends CrudService {
     const query = { 'inventor.user_id': { $in: pids } };
     if (status) query.status = status;
     if (term) query.term = term;
-    console.log(query);
     const data = await this.model
       .find(query)
       .skip(parseInt(skip))

+ 103 - 87
app/service/patent/patentwarning.js

@@ -36,92 +36,94 @@ class PatentwarningService extends CrudService {
       throw new BusinessError(ErrorCode.FILE_FAULT, '解压失败');
     }
     // 修改,多个专利:需要扫描下解压后的文件夹,然后循环处理下面所有的内容
-    const tempDirRootPath = `${uncompressFilePath}${sep}${fileName}`;
+    const tempDirRootPath = `${uncompressFilePath}${sep}`;
     const tempDir = await fs.readdirSync(tempDirRootPath);
     const errorList = [];
     for (const tempDirPath of tempDir) {
       const thisDirPath = `${tempDirRootPath}${sep}${tempDirPath}`;
       const patentNumber = tempDirPath;
-      // 找到
-      let filePaths = [];
       try {
-        filePaths = await this.findFileNameLoop(thisDirPath);
-      } catch (error) {
-        errorList.push({ key: patentNumber, word: '解析文件具体位置失败' });
-        continue;
-      }
-      if (filePaths.length <= 0) {
-        errorList.push({ key: patentNumber, word: '未找到文件' });
-        continue;
-      }
-      const xmlPath = filePaths.find(f => f.includes('.xml'));
-      if (!xmlPath) {
-        errorList.push({ key: patentNumber, word: '未找到xml文件' });
-        continue;
+        // 找到
+        let filePaths = [];
+        try {
+          filePaths = await this.findFileNameLoop(thisDirPath);
+        } catch (error) {
+          errorList.push({ key: patentNumber, word: '解析文件具体位置失败' });
+          continue;
+        }
+        if (filePaths.length <= 0) {
+          errorList.push({ key: patentNumber, word: '未找到文件' });
+          continue;
+        }
+        const xmlPath = filePaths.find(f => f.includes('.xml'));
+        if (!xmlPath) {
+          errorList.push({ key: patentNumber, word: '未找到xml文件' });
+          continue;
         // throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到xml文件');
-      }
-      let create_number;
-      try {
-        create_number = await this.dealXml(xmlPath);
-      } catch (error) {
-        errorList.push({ key: patentNumber, word: '解析申请号失败' });
-        continue;
+        }
+        let xmlData;
+        try {
+          xmlData = await this.dealXml(xmlPath);
+        } catch (error) {
+          errorList.push({ key: patentNumber, word: '解析xml数据中的 申请号 和 专利名称 失败' });
+          continue;
         // throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
-      }
-      if (!create_number) {
-        errorList.push({ key: patentNumber, word: '未找到申请号' });
-        continue;
+        }
+        if (!xmlData) {
+          errorList.push({ key: patentNumber, word: '未找到xml的数据' });
+          continue;
         // throw new BusinessError(ErrorCode.FILE_FAULT, '未找到申请号');
-      }
-      let result;
-      try {
-        result = await this.getPatentFromInfo(create_number);
-      } catch (error) {
-        errorList.push({ key: patentNumber, word: '查询专利信息失败' });
-        continue;
-        // throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
-      }
-      // 再找
-      if (!result) {
+        }
+        let result;
         try {
-          result = await this.getPatentFromApply(create_number);
+          result = await this.getPatent(xmlData);
         } catch (error) {
-          errorList.push({ key: patentNumber, word: '查询申请信息失败' });
+          errorList.push({ key: patentNumber, word: '查询专利信息失败' });
           continue;
+        // throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
         }
-      }
-      // 找不到就算了,弹回去了
-      if (!result) {
-        errorList.push({ key: patentNumber, word: '未通过申请号找到指定专利' });
-        continue;
+        // 找不到就算了,弹回去了
+        if (!result || !_.get(result, 'patent')) {
+          errorList.push({ key: patentNumber, word: '未通过 申请号 或 专利名称 找到指定专利' });
+          continue;
         // throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未通过申请号找到指定专利');
-      }
-      let warningData;
-      try {
-        warningData = await this.getWarningData(result);
-      } catch (error) {
-        errorList.push({ key: patentNumber, word: '组织专利信息警告数据失败' });
-        continue;
-        // throw new BusinessError(ErrorCode.SERVICE_FAULT, '组织专利信息警告数据失败');
-      }
-      const tifPaths = filePaths.filter(f => f.includes('.tif'));
-      let lastResult;
-      if (tifPaths && tifPaths.length > 0) {
+        }
+        const patent = _.get(result, 'patent');
+        let warningData;
         try {
-          lastResult = await this.toUploadTif(warningData, tifPaths);
+          warningData = await this.getWarningData(patent);
         } catch (error) {
-          errorList.push({ key: patentNumber, word: '存储数据失败' });
+          errorList.push({ key: patentNumber, word: '组织专利信息警告数据失败' });
           continue;
+        // throw new BusinessError(ErrorCode.SERVICE_FAULT, '组织专利信息警告数据失败');
         }
-      }
-      if (lastResult) {
+        const tifPaths = filePaths.filter(f => f.includes('.tif'));
+        if (tifPaths && tifPaths.length > 0) {
+          try {
+            await this.toUploadTif(warningData, tifPaths);
+          } catch (error) {
+            errorList.push({ key: patentNumber, word: '存储数据失败' });
+            continue;
+          }
+        }
+        // 查看是否需要更改申请号
+        const needChange = _.get(result, 'needChange');
+        if (needChange) {
+          try {
+            await this.patentApply.updateOne({ _id: patent._id }, patent);
+          } catch (error) {
+            errorList.push({ key: patentNumber, word: 'xml申请号同步至专利申请号失败' });
+            continue;
+          }
+        }
+      } finally {
         try {
-          await this.dirDelete(`${uncompressFilePath}`);
+          await this.dirDelete(`${thisDirPath}`);
         } catch (error) {
-          errorList.push({ key: patentNumber, word: '清除缓存失败' });
-          continue;
+          this.ctx.logger.error('清除缓存失败');
         }
       }
+
     }
     if (errorList.length > 0) return errorList;
     return 'ok';
@@ -203,44 +205,56 @@ class PatentwarningService extends CrudService {
     if (_.get(patent, 'id'))object.patent_id = _.get(patent, 'id');
     if (_.get(patent, 'name'))object.patent_name = _.get(patent, 'name');
     // 找人的信息
-    let userIds = _.get(patent, 'user_id', _.get(patent, 'inventor'));
-    if (!userIds) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到专利的发明人');
-    if (!_.isArray(userIds)) userIds = [ userIds ];
-    userIds = userIds.map(i => ObjectId(i));
-    const users = await this.personalModel.find({ _id: userIds });
+    const users = _.get(patent, 'inventor');
     const arr = [];
     for (const user of users) {
-      if (!_.get(user, '_id') || !_.get(user, 'name')) continue;
-      const { _id, name } = user;
+      if (!_.get(user, 'user_id') || !_.get(user, 'name')) continue;
+      const { user_id, name } = user;
       const obj = _.cloneDeep(object);
-      obj.to_id = _id;
+      obj.to_id = user_id;
       obj.to_name = name;
       arr.push(obj);
     }
+    console.log(arr);
     return arr;
 
   }
 
   /**
-   * 在patentApply表中找指定的专利
-   * @param {String} create_number 专利的申请号
+   * 在patentApply/patentInfo表中找指定的专利
+   * @param {Object} object xml的数据
    */
-  async getPatentFromApply(create_number) {
-    const res = await this.patentApply.findOne({ create_number });
-    return res;
+  async getPatent(object) {
+    const { name, create_number } = object;
+    let res;
+    let needChange = false;
+    res = await this.patentApply.findOne({ create_number });
+    // 如果在申请中,使用名称找到,则之后需要将该数据的专利号改为xml中的专利号
+    if (!res) {
+      res = await this.patentApply.findOne({ name });
+      needChange = true;
+    }
+    if (!res) {
+      res = await this.patentInfo.findOne({ create_number });
+    }
+    if (!res) {
+      res = await this.patentInfo.findOne({ name });
+    }
+    const returnObject = {};
+    if (res) {
+      if (needChange) {
+        res.create_number = create_number;
+        returnObject.needChange = needChange;
+      }
+      returnObject.patent = res;
+      return returnObject;
+    }
+    return null;
   }
 
-  /**
-   * 在patentInfo表中找指定的专利
-   * @param {String} create_number 专利的申请号
-   */
-  async getPatentFromInfo(create_number) {
-    const res = await this.patentInfo.findOne({ create_number });
-    return res;
-  }
 
   /**
-   * 根据路径找到xml,再找到该xml的申请号
+   * 根据路径找到xml,再找到该xml的申请号和专利名称
    * @param {String} filePath xml的文件路径
    */
   async dealXml(filePath) {
@@ -250,7 +264,9 @@ class PatentwarningService extends CrudService {
     str = str.toString();
     const json = fxp.parse(str);
     const create_number = _.get(json, 'data-bus.TONGZHISXJ.SHUXINGXX.SHENQINGH');
-    return create_number;
+    const name = _.get(json, 'data-bus.TONGZHISXJ.SHUXINGXX.FAMINGMC');
+    if (!name) return null;
+    return { name, create_number };
   }
 
   /**