lrf %!s(int64=3) %!d(string=hai) anos
pai
achega
e3f1600fa6
Modificáronse 1 ficheiros con 12 adicións e 17 borrados
  1. 12 17
      app/service/patent/patentinfo.js

+ 12 - 17
app/service/patent/patentinfo.js

@@ -132,24 +132,12 @@ class PatentinfoService extends CrudService {
         arr.push(obj);
       }
     });
-    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;
+      const { result, notice } = this.tocheckData(obj);
+      if (!result) {
+        allNotice.push(notice);
       }
     }
-    arr = arr.filter((f) => !f.no_deal);
-
     if (allNotice.length > 0) return allNotice;
     let nameList = [];
     for (const i of arr) {
@@ -178,8 +166,15 @@ class PatentinfoService extends CrudService {
       }
       i.inventor = iList;
     }
-    const res = await this.model.insertMany(arr);
-    return res;
+    // 根据申请号做添加/修改
+    for (const obj of arr) {
+      let has_data = await this.model.count({ create_number: obj.create_number });
+      if (!has_data) {
+        await this.model.create(obj);
+      } else {
+        await this.model.updateOne({ create_number: obj.create_number }, obj);
+      }
+    }
   }
   async toExport({ user }) {
     const data = {