ソースを参照

专利信息导入:如果该申请号有专利,则不需要进库也不需要报错.略过处理

lrf 3 年 前
コミット
c4913dee6d
1 ファイル変更58 行追加57 行削除
  1. 58 57
      app/service/patent/patentinfo.js

+ 58 - 57
app/service/patent/patentinfo.js

@@ -10,6 +10,7 @@ const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const { trimData } = require('naf-core').Util;
 const { ObjectId } = require('mongoose').Types;
+const { has } = require('lodash');
 
 // 专利信息
 class PatentinfoService extends CrudService {
@@ -38,8 +39,7 @@ class PatentinfoService extends CrudService {
 
   async query(query, { skip = 0, limit = 0 }) {
     const newquery = await this.resetCode(query);
-    const res = await this.model.find(newquery).skip(parseInt(skip)).limit(parseInt(limit))
-      .sort({ create_date: -1 });
+    const res = await this.model.find(newquery).skip(parseInt(skip)).limit(parseInt(limit)).sort({ create_date: -1 });
     return res;
   }
   async count(query) {
@@ -76,7 +76,7 @@ class PatentinfoService extends CrudService {
     let ids = [];
     if (code) {
       const plist = await this.personalModel.find({ code });
-      ids = plist.map(i => i._id);
+      ids = plist.map((i) => i._id);
       if (ids.length > 0) {
         newquery['inventor.user_id'] = { $in: ids };
         delete newquery.code;
@@ -92,12 +92,11 @@ class PatentinfoService extends CrudService {
     assert(code, '缺少机构信息');
     let pids = await this.personalModel.find({ code }, { _id: 1 });
     if (pids.length <= 0) return { data: [], total: 0 };
-    pids = pids.map(i => i._id);
+    pids = pids.map((i) => i._id);
     const query = { 'inventor.user_id': { $in: pids } };
     if (status) query.status = status;
     if (term) query.term = term;
-    const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit))
-      .sort({ 'meta.createdAt': -1 });
+    const data = await this.model.find(query).skip(parseInt(skip)).limit(parseInt(limit)).sort({ 'meta.createdAt': -1 });
     const total = await this.model.count(query);
     return { data, total };
   }
@@ -115,7 +114,7 @@ class PatentinfoService extends CrudService {
     const allNotice = [];
     const sheetImageInfo = sheet.getImages();
     const imgids = _.compact(
-      sheetImageInfo.map(i => {
+      sheetImageInfo.map((i) => {
         const { imageId, range } = i;
         const row = _.get(range, 'tl.nativeRow');
         if (row) return { row, imageId };
@@ -125,7 +124,7 @@ class PatentinfoService extends CrudService {
       if (rindex !== 1) {
         // 组织数据,图片的索引和行索引不一致,准确的说是:图片索引比行索引少1
         // 原因:图片在工作簿中获取,按照1,2,3...顺序排序,但是行的第一行是表头(当前文件),所以当前行数需要减掉表头那一行
-        const imgid = imgids.find(f => f.row === rindex - 1);
+        const imgid = imgids.find((f) => f.row === rindex - 1);
         const img_url = [];
         if (imgid) {
           img_url.push({
@@ -162,47 +161,50 @@ class PatentinfoService extends CrudService {
           lose_date = moment(row.getCell(27).value).format('YYYY-MM-DD') || undefined,
           examine_date = moment(row.getCell(28).value).format('YYYY-MM-DD') || undefined,
           invention_design = row.getCell(29).value || undefined;
-        const obj = {
-          create_number,
-          create_date,
-          success_number,
-          success_date,
-          inventor,
-          agent,
-          agent_personal,
-          abstract,
-          address,
-          name,
-          apply_personal,
-          term,
-          type,
-          img_url,
-          number,
-          origin,
-          user_id: [],
-          // 新增专利数据属性2021-09-06
-          nationality,
-          ipc_type,
-          onlegal_status,
-          legal_status,
-          law_date,
-          on_obligee,
-          apply_address,
-          apply_other,
-          law_num,
-          first_opendate,
-          empower_date,
-          lose_date,
-          examine_date,
-          invention_design,
-        };
-
-        // 此处添加判断条件,不限制则不需要加,直接放过即可
-        const { result, notice } = this.tocheckData(obj);
-        if (result) {
-          arr.push(obj);
-        } else {
-          allNotice.push(notice);
+        // 2021-11-15 添加申请号的验证,如果有该申请号的专利,则不需要进库,也不需要报错
+        const has_data = await this.model.count({ create_number });
+        if (!has_data) {
+          const obj = {
+            create_number,
+            create_date,
+            success_number,
+            success_date,
+            inventor,
+            agent,
+            agent_personal,
+            abstract,
+            address,
+            name,
+            apply_personal,
+            term,
+            type,
+            img_url,
+            number,
+            origin,
+            user_id: [],
+            // 新增专利数据属性2021-09-06
+            nationality,
+            ipc_type,
+            onlegal_status,
+            legal_status,
+            law_date,
+            on_obligee,
+            apply_address,
+            apply_other,
+            law_num,
+            first_opendate,
+            empower_date,
+            lose_date,
+            examine_date,
+            invention_design,
+          };
+          // 此处添加判断条件,不限制则不需要加,直接放过即可
+          const { result, notice } = this.tocheckData(obj);
+          if (result) {
+            arr.push(obj);
+          } else {
+            allNotice.push(notice);
+          }
         }
       }
     });
@@ -212,21 +214,21 @@ class PatentinfoService extends CrudService {
     for (const i of arr) {
       const { inventor } = i;
       const midList = inventor.split(/[,;/]/);
-      nameList = [ ...nameList, ...midList ];
+      nameList = [...nameList, ...midList];
     }
-    nameList = nameList.map(i => _.trim(i));
+    nameList = nameList.map((i) => _.trim(i));
     const l1 = await this.personalModel.find({ name: nameList });
     const l2 = await this.organizationModel.find({ name: nameList });
     // 查出来的所有人
-    const nList = [ ...l1, ...l2 ];
+    const nList = [...l1, ...l2];
     for (const i of arr) {
       const { inventor } = i;
       let midNameList = inventor.split(/[,;/]/);
-      midNameList = midNameList.map(i => _.trim(i));
+      midNameList = midNameList.map((i) => _.trim(i));
       const iList = [];
       if (!_.isArray(i.user_id)) i.inventor = iList;
       for (const name of midNameList) {
-        const rList = nList.filter(f => f.name === name);
+        const rList = nList.filter((f) => f.name === name);
         if (rList && rList.length > 0) {
           for (const r of rList) {
             iList.push({ user_id: r._id, name: r.name });
@@ -452,8 +454,7 @@ class PatentinfoService extends CrudService {
     if (empower_sort === '0') {
       sort = 'asc';
     }
-    const data = await this.model.find(newQuery).sort({ empower_date: sort }).skip(parseInt(skip))
-      .limit(parseInt(limit));
+    const data = await this.model.find(newQuery).sort({ empower_date: sort }).skip(parseInt(skip)).limit(parseInt(limit));
     const total = await this.model.count(newQuery);
     return { data, total };
   }
@@ -500,7 +501,7 @@ class PatentinfoService extends CrudService {
   async dealCode(code) {
     let pids = await this.personalModel.find({ code }, { _id: 1 });
     if (pids.length <= 0) return { data: [], total: 0 };
-    pids = pids.map(i => i._id);
+    pids = pids.map((i) => i._id);
     const query = { 'inventor.user_id': { $in: pids } };
     return query;
   }