浏览代码

导入bug

lrf 3 年之前
父节点
当前提交
9736881204
共有 1 个文件被更改,包括 20 次插入20 次删除
  1. 20 20
      app/service/patent/patentinfo.js

+ 20 - 20
app/service/patent/patentinfo.js

@@ -95,7 +95,7 @@ class PatentinfoService extends CrudService {
     const workbook = new Excel.Workbook();
     await workbook.xlsx.load(file.data);
     const sheet = workbook.getWorksheet(1);
-    const arr = [];
+    let arr = [];
     const allNotice = [];
     const sheetImageInfo = sheet.getImages();
     const imgids = _.compact(
@@ -129,28 +129,28 @@ class PatentinfoService extends CrudService {
           else obj[key] = _.get(row.getCell(index), 'value');
         }
         obj = _.pickBy(obj, _.identity);
-
-        // 2021-11-15 添加申请号的验证,如果有该申请号的专利,则不需要进库,也不需要报错
-        let has_data;
-        this.model.count({ create_number: obj.create_number }).then((res) => {
-          has_data = res;
-        });
-        if (!has_data) {
-          // 此处添加判断条件,不限制则不需要加,直接放过即可
-          const { result, notice } = this.tocheckData(obj);
-          if (result) {
-            arr.push(obj);
-          } else {
-            allNotice.push(notice);
-          }
-        } else {
-          // 如果有该数据,则直接覆盖
-          this.model.updateOne({ create_number: obj.create_number }, obj);
-        }
+        arr.push(obj);
       }
     });
-    if (allNotice.length > 0) return allNotice;
+    console.log('in function:');
+    for (const obj of arr) {
+      // 2021-11-15 添加申请号的验证,如果有该申请号的专利,则不需要进库,也不需要报错
+      let has_data = await this.model.count({ create_number: obj.create_number });
+      if (!has_data) {
+        // 此处添加判断条件,不限制则不需要加,直接放过即可
+        const { result, notice } = this.tocheckData(obj);
+        if (!result) {
+          allNotice.push(notice);
+        }
+      } else {
+        // 如果有该数据,则直接覆盖
+        this.model.updateOne({ create_number: obj.create_number }, obj);
+        obj.no_deal = true;
+      }
+    }
+    arr = arr.filter((f) => !f.no_deal);
 
+    if (allNotice.length > 0) return allNotice;
     let nameList = [];
     for (const i of arr) {
       const { inventor } = i;