lrf 2 年之前
父節點
當前提交
61ad582a30
共有 3 個文件被更改,包括 29 次插入24 次删除
  1. 4 2
      app/controller/patent/.cpcimporterror.js
  2. 2 0
      app/model/patent/cpcimporterror.js
  3. 23 22
      app/service/patent/patentwarning.js

+ 4 - 2
app/controller/patent/.cpcimporterror.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ['key', 'word', 'filepath', 'time'],
+    requestBody: ['key', 'word', 'filepath', 'time', 'name', 'create_number'],
   },
   destroy: {
     params: ['!id'],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ['!id'],
-    requestBody: ['key', 'word', 'filepath', 'time'],
+    requestBody: ['key', 'word', 'filepath', 'time', 'name', 'create_number'],
   },
   show: {
     parameters: {
@@ -20,6 +20,8 @@ module.exports = {
     parameters: {
       query: {
         key: 'key',
+        name: 'name',
+        create_number: 'create_number',
         'time@start': 'time@start',
         'time@end': 'time@end',
         'meta.createdAt@start': 'meta.createdAt@start',

+ 2 - 0
app/model/patent/cpcimporterror.js

@@ -4,6 +4,8 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 交底书表
 const cpcimporterror = {
   key: { type: String }, // 专利信息
+  name: { type: String }, // 专利信息名称
+  create_number: { type: String }, //专利号
   word: { type: String }, // 错误信息
   filepath: { type: String }, // 导入的zip包路径(绝对)
   time: { type: String }, // 时间

+ 23 - 22
app/service/patent/patentwarning.js

@@ -51,7 +51,7 @@ class PatentwarningService extends CrudService {
         try {
           filePaths = await this.findFileNameLoop(thisDirPath);
         } catch (error) {
-          errorList.push({ key: patentNumber, word: '解析文件位于服务器的绝对路径失败', error });
+          errorList.push({ key: patentNumber, word: '格式不对', error });
           continue;
         }
         if (filePaths.length <= 0) {
@@ -59,21 +59,22 @@ class PatentwarningService extends CrudService {
           continue;
         }
         // 2021-10-16 修改: 取出第一层的xml文件,即:路径最短的;除文件名外,字符串长度最小的
-        let xmlPaths = filePaths.filter(f => f.includes('.xml'));
+        let xmlPaths = filePaths.filter((f) => f.includes('.xml'));
         if (xmlPaths.length > 0) {
           // 去掉文件名
-          xmlPaths = xmlPaths.map(i => {
+          xmlPaths = xmlPaths.map((i) => {
             const arr = i.split(sep);
             arr.pop();
             const obj = { dir: arr.join(sep), fullPath: i };
             return obj;
           });
-          // 按路径字符串长度排序
-          xmlPaths = xmlPaths.sort((a, b) => {
-            const anum = a.dir.length;
-            const bnum = b.dir.length;
-            return anum - bnum;
-          });
+          // // 按路径字符串长度排序
+          // xmlPaths = xmlPaths.sort((a, b) => {
+          //   const anum = a.fullPath.length;
+          //   const bnum = b.fullPath.length;
+          //   return anum - bnum;
+          // });
+          xmlPaths = xmlPaths.filter((f) => f.fullPath.includes('list.xml'));
         }
         const xmlPath = _.get(_.head(xmlPaths), 'fullPath');
         if (!xmlPath) {
@@ -85,7 +86,7 @@ class PatentwarningService extends CrudService {
         try {
           xmlData = await this.dealXml(xmlPath);
         } catch (error) {
-          errorList.push({ key: patentNumber, word: `解析xml数据中的 申请号 和 专利名称 失败 于:${xmlPath}` });
+          errorList.push({ key: patentNumber, word: `解析xml数据中的 申请号 和 专利名称 失败 于:${xmlPath}`, ...xmlData });
           continue;
           // throw new BusinessError(ErrorCode.SERVICE_FAULT, '解析申请号失败');
         }
@@ -103,7 +104,7 @@ class PatentwarningService extends CrudService {
           // 2022-09-02 修改为在数组中查询,所以下面所有关于result的处理都需要变成数组的处理
           result = await this.getPatent(xmlData);
         } catch (error) {
-          errorList.push({ key: patentNumber, word: '查询专利信息失败' });
+          errorList.push({ key: patentNumber, word: '查询专利信息失败', ...xmlData });
           continue;
           // throw new BusinessError(ErrorCode.SERVICE_FAULT, '查询专利信息失败');
         }
@@ -111,7 +112,7 @@ class PatentwarningService extends CrudService {
         // 2022-09-02 数组处理模式 ↑
         const patents = _.get(result, 'patent');
         if (!patents || patents.length <= 0) {
-          errorList.push({ key: patentNumber, word: '未通过 申请号 或 专利名称 找到指定专利' });
+          errorList.push({ key: patentNumber, word: '未通过 申请号 或 专利名称 找到指定专利', ...xmlData });
           continue;
         }
 
@@ -121,16 +122,16 @@ class PatentwarningService extends CrudService {
           try {
             warningData = await this.getWarningData(patent);
           } catch (error) {
-            errorList.push({ key: patentNumber, word: '组织专利信息警告数据失败' });
+            errorList.push({ key: patentNumber, word: '组织专利信息警告数据失败', ...xmlData });
             continue;
             // throw new BusinessError(ErrorCode.SERVICE_FAULT, '组织专利信息警告数据失败');
           }
-          const tifPaths = filePaths.filter(f => f.includes('.tif'));
+          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: '存储数据失败' });
+              errorList.push({ key: patentNumber, word: '存储数据失败', ...xmlData });
               continue;
             }
           }
@@ -144,7 +145,7 @@ class PatentwarningService extends CrudService {
       }
     }
     // 2022-09-05 将错误信息添加到表中
-    errorList = errorList.map(i => ({ ...i, filepath: uri, time: moment().format('YYYY-MM-DD HH:mm:ss') }));
+    errorList = errorList.map((i) => ({ ...i, filepath: uri, time: moment().format('YYYY-MM-DD HH:mm:ss') }));
     await this.cpcErrorMsg.insertMany(errorList);
     if (errorList.length > 0) return errorList;
     return 'ok';
@@ -238,11 +239,11 @@ class PatentwarningService extends CrudService {
         arr.push(obj);
       }
       // 2021-11-18 添加,user,mech,admin,agentmech是否存在,如果存在,也添加预警信息
-      const list = [ 'user', 'mech', 'admin', 'agentmech' ];
-      const suffix = [ 'id', 'name' ];
+      const list = ['user', 'mech', 'admin', 'agentmech'];
+      const suffix = ['id', 'name'];
       for (const prefix of list) {
-        const marr = suffix.map(i => `${prefix}_${i}`);
-        const r = marr.every(i => _.get(patent, i));
+        const marr = suffix.map((i) => `${prefix}_${i}`);
+        const r = marr.every((i) => _.get(patent, i));
         if (r) {
           const obj = _.cloneDeep(object);
           for (const key of suffix) {
@@ -283,7 +284,7 @@ class PatentwarningService extends CrudService {
     }
     const listPI = await this.patentInfo.find({ $or: [{ create_number }, { name }] });
 
-    res = [ ...listPA, ...listPI ];
+    res = [...listPA, ...listPI];
     const returnObject = {};
     if (res.length > 0) {
       returnObject.patent = JSON.parse(JSON.stringify(res));
@@ -354,7 +355,7 @@ class PatentwarningService extends CrudService {
         result.push(curPath);
       }
     }
-    result = result.filter(f => f.includes('.tif') || f.includes('.xml'));
+    result = result.filter((f) => f.includes('.tif') || f.includes('.xml'));
     return result;
   }