ruifeng_liu преди 3 години
родител
ревизия
ad8e32bce5
променени са 1 файла, в които са добавени 28 реда и са изтрити 5 реда
  1. 28 5
      app/service/patent/patentwarning.js

+ 28 - 5
app/service/patent/patentwarning.js

@@ -32,13 +32,36 @@ class PatentwarningService extends CrudService {
       throw new BusinessError(ErrorCode.FILE_FAULT, '只接收压缩格式为zip的压缩包');
     }
     // 解压
-    await compressing.zip.uncompress(uri, `${uncompressFilePath}`);
+    try {
+      await compressing.zip.uncompress(uri, `${uncompressFilePath}`);
+    } catch (error) {
+      throw new BusinessError(ErrorCode.FILE_FAULT, '解压失败');
+    }
     // 找到
-    const filePaths = await this.findFileNameLoop(uncompressFilePath, fileName);
+    let filePaths = [];
+    try {
+      filePaths = await this.findFileNameLoop(uncompressFilePath, fileName);
+    } catch (error) {
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析文件具体位置失败');
+    }
+    if (filePaths.length <= 0) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到文件');
+    }
     const xmlPath = filePaths.find(f => f.includes('.xml'));
-    const create_number = await this.dealXml(xmlPath);
+    if (!xmlPath) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到xml文件');
+    let create_number;
+    try {
+      create_number = await this.dealXml(xmlPath);
+    } catch (error) {
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
+    }
     if (!create_number) throw new BusinessError(ErrorCode.FILE_FAULT, '未找到申请号');
-    let result = await this.getPatentFromInfo(create_number);
+    let result;
+    try {
+      result = await this.getPatentFromInfo(create_number);
+    } catch (error) {
+      throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
+    }
     // 再找
     if (!result) result = await this.getPatentFromApply(create_number);
     // 找不到就算了,弹回去了
@@ -121,6 +144,7 @@ class PatentwarningService extends CrudService {
    * @param {Object} patent 专利
    */
   async getWarningData(patent) {
+    console.log(patent);
     const object = {};
     if (_.get(patent, 'create_number'))object.create_number = _.get(patent, 'create_number');
     if (_.get(patent, 'id'))object.patent_id = _.get(patent, 'id');
@@ -166,7 +190,6 @@ class PatentwarningService extends CrudService {
    * @param {String} filePath xml的文件路径
    */
   async dealXml(filePath) {
-    console.log(filePath);
     const buffer = await fs.readFileSync(filePath);
     let str = encoding.convert(buffer, 'UTF8', 'GBK');
     if (!str) throw new BusinessError(ErrorCode.FILE_FAULT, '读取xml文件失败');