guhongwei 3 years ago
parent
commit
d9aee94666
1 changed files with 20 additions and 18 deletions
  1. 20 18
      app/service/patent/patentinfo.js

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

@@ -39,7 +39,8 @@ class PatentinfoService extends CrudService {
 
   async query(query, { skip = 0, limit = 0, projection }) {
     const newquery = await this.resetCode(query);
-    const res = await this.model.find(newquery, projection).skip(parseInt(skip)).limit(parseInt(limit)).sort({ create_date: -1 });
+    const res = await this.model.find(newquery, projection).skip(parseInt(skip)).limit(parseInt(limit))
+      .sort({ create_date: -1 });
     return res;
   }
   async count(query) {
@@ -56,9 +57,9 @@ class PatentinfoService extends CrudService {
     let arr = [];
     if (pid) {
       const plist = await this.adminModel.find({ pid, role: '2' }, { _id: 1, deptname: 1 });
-      arr = plist.map((i) => i.deptname);
+      arr = plist.map(i => i.deptname);
       if (arr.length > 0) {
-        newquery['first_apply'] = arr;
+        newquery.first_apply = arr;
         delete newquery.pid;
       }
     }
@@ -71,7 +72,7 @@ class PatentinfoService extends CrudService {
       delete newquery.key_word;
     }
     if (single_inventor) {
-      newquery['inventor.name'] = { $in: [single_inventor] };
+      newquery['inventor.name'] = { $in: [ single_inventor ] };
       delete newquery.single_inventor;
     }
     return newquery;
@@ -133,7 +134,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 };
@@ -149,7 +150,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({
@@ -158,7 +159,7 @@ class PatentinfoService extends CrudService {
         }
         // 根据meta整理数据
         // 需要日期转换的字段
-        const dateColumnArray = ['create_date', 'success_date', 'law_date', 'first_opendate', 'empower_date', 'lose_date', 'examine_date'];
+        const dateColumnArray = [ 'create_date', 'success_date', 'law_date', 'first_opendate', 'empower_date', 'lose_date', 'examine_date' ];
         let obj = { img_url };
         for (const m of meta) {
           const { key, index } = m;
@@ -188,7 +189,7 @@ class PatentinfoService extends CrudService {
         const { first_inventor, create_number } = obj;
         try {
           let person = await this.personalModel.findOne({ code, phone: first_inventor });
-          let user_id = {};
+          const user_id = {};
           // 有用户,直接取id,没有用户;创建用户,取id;
           if (person) {
             user_id.user_id = person._id || person.id;
@@ -211,7 +212,7 @@ class PatentinfoService extends CrudService {
               user_id.name = person.name;
             }
           }
-          obj.user_id = [JSON.parse(JSON.stringify(user_id))];
+          obj.user_id = [ JSON.parse(JSON.stringify(user_id)) ];
         } catch (error) {
           allNotice.push(`${create_number} 的 第一发明人用户 创建失败!`);
           continue;
@@ -233,7 +234,7 @@ class PatentinfoService extends CrudService {
           res = await this.model.find({ create_number: obj.create_number });
         }
         // 处理警告
-        this.ctx.service.patent.patentearly.dealData([res]);
+        if (res.trem === '有效') this.ctx.service.patent.patentearly.dealData([ res ]);
       } catch (error) {
         allNotice.push(`申请号 为${create_number} 的 专利信息 创建失败!`);
         continue;
@@ -278,7 +279,7 @@ class PatentinfoService extends CrudService {
       projection[key] = 1;
     }
     // 将数据分割,否则容易直接把js堆栈干满了,服务就炸了
-    const head = meta.map((i) => i.header);
+    const head = meta.map(i => i.header);
     for (let i = 0; i < total; i = i + this.export_limit) {
       try {
         const workbook = new Excel.Workbook();
@@ -316,7 +317,7 @@ class PatentinfoService extends CrudService {
         skip = skip + this.export_limit;
         // 生成excel
         const filename = `专利信息导出结果(${i + 1}-${i + this.export_limit}).xlsx`;
-        let filePath = `${path}${sep}${filename}`;
+        const filePath = `${path}${sep}${filename}`;
         console.log(filePath);
         await workbook.xlsx.writeFile(filePath);
 
@@ -365,7 +366,7 @@ class PatentinfoService extends CrudService {
         fs.mkdirSync(exportPath);
       }
       await compressing.zip.compressDir(path, `${exportPath}${sep}${zipName}`);
-      let downloadPath = `/files/${this.export_dir}/${zipName}`;
+      const downloadPath = `/files/${this.export_dir}/${zipName}`;
       const data = {
         progress: 100,
         status: '2',
@@ -415,7 +416,7 @@ class PatentinfoService extends CrudService {
     }
     console.log(`${_.get(data, 'progress') || '失败'} %`);
     const ch = await this.ctx.mq.conn.createChannel();
-    const queue = `mission/return`;
+    const queue = 'mission/return';
     await ch.assertQueue(queue, { durable: false });
     await ch.sendToQueue(queue, Buffer.from(JSON.stringify(data)));
     await ch.close();
@@ -496,7 +497,8 @@ 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 };
   }
@@ -543,7 +545,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;
   }
@@ -577,9 +579,9 @@ class PatentinfoService extends CrudService {
     if (!user_id || !_.isArray(user_id)) {
       throw new BusinessError(ErrorCode.DATA_INVALID, '用户信息参数错误');
     }
-    const data = await this.model.find({ _id: patentData.map((i) => ObjectId(i)) });
+    const data = await this.model.find({ _id: patentData.map(i => ObjectId(i)) });
     for (const i of data) {
-      i.user_id = _.uniqBy([...i.user_id, ...user_id], 'user_id');
+      i.user_id = _.uniqBy([ ...i.user_id, ...user_id ], 'user_id');
       await i.save();
     }
   }