lrf před 3 roky
rodič
revize
76c983a984

+ 9 - 4
app/controller/statistics/index.js

@@ -77,12 +77,11 @@ class IndexController extends Controller {
     this.ctx.ok({ data });
   }
 
-
   async dockProduct() {
     const query = this.ctx.query;
-    const arr = [ 'skip', 'limit', 'dock_id' ];
+    const arr = ['skip', 'limit', 'dock_id'];
     for (const key in query) {
-      const r = arr.find(f => f === key);
+      const r = arr.find((f) => f === key);
       if (!r) {
         query[`productList.${key}`] = query[key];
         delete query[key];
@@ -98,6 +97,12 @@ class IndexController extends Controller {
     this.ctx.ok({ data });
   }
 
-
+  /**
+   * 根据申请人统计,申请人所在的专利信息数量
+   */
+  async patentInfoByApplyPerson() {
+    const data = await this.service.patentInfoByApplyPerson();
+    this.ctx.ok({ data });
+  }
 }
 module.exports = CrudController(IndexController, meta);

+ 1 - 1
app/router/statistics/index.js

@@ -18,6 +18,6 @@ module.exports = app => {
   router.get(target, `${profix}${vision}/${index}/${target}/pac`, controller[index][target].policyApplyCount);
   router.get(target, `${profix}${vision}/${index}/${target}/declare`, controller[index][target].declare);
   router.get(target, `${profix}${vision}/${index}/${target}/patentUserIndex`, controller[index][target].patentUserIndex);
-
+  router.get(target, `${profix}${vision}/${index}/${target}/patentInfoByApplyPerson`, controller[index][target].patentInfoByApplyPerson);
 
 };

+ 46 - 25
app/service/statistics/index.js

@@ -38,13 +38,13 @@ class IndexService extends CrudService {
     for (const i of res) {
       const { _id, value } = i;
       const unitList = this.patentUnitList();
-      const unit = unitList.find(f => (_id && _id.includes(f.name)) || f.name.includes(_id));
+      const unit = unitList.find((f) => (_id && _id.includes(f.name)) || f.name.includes(_id));
       if (unit) {
         // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
         const { name } = unit;
-        const arrItem = arr.find(f => f.name === name);
+        const arrItem = arr.find((f) => f.name === name);
         if (arrItem) {
-          const index = arr.findIndex(f => f.name === name);
+          const index = arr.findIndex((f) => f.name === name);
           arr[index] = { name, value: (arrItem.value || 0) + value };
         } else {
           arr.push({ name, value });
@@ -53,7 +53,7 @@ class IndexService extends CrudService {
         other.value += value;
       }
     }
-    arr = _.orderBy(arr, [ 'value' ], [ 'desc' ]);
+    arr = _.orderBy(arr, ['value'], ['desc']);
     arr.push(other);
     return arr;
   }
@@ -93,13 +93,13 @@ class IndexService extends CrudService {
     for (const i of res) {
       const { _id, value } = i;
       const unitList = this.expertList();
-      const unit = unitList.find(f => (_id && _id.includes(f.name)) || f.name.includes(_id));
+      const unit = unitList.find((f) => (_id && _id.includes(f.name)) || f.name.includes(_id));
       if (unit) {
         // 说明是需要单拎出来的数据,现查arr中是否有该单位:有=>数字合并;没有=>创建条目
         const { name, sort } = unit;
-        const arrItem = arr.find(f => f.name === name);
+        const arrItem = arr.find((f) => f.name === name);
         if (arrItem) {
-          const index = arr.findIndex(f => f.name === name);
+          const index = arr.findIndex((f) => f.name === name);
           arr[index] = { ...arr[index], value: (arrItem.value || 0) + value };
         } else {
           arr.push({ name, value, sort });
@@ -108,11 +108,11 @@ class IndexService extends CrudService {
         other.value += value;
       }
     }
-    arr = _.orderBy(arr, [ 'sort' ], [ 'asc' ]);
+    arr = _.orderBy(arr, ['sort'], ['asc']);
     arr.push(other);
     // 换名
-    arr.map(i => {
-      const r = this.expertList().find(f => f.name === i.name);
+    arr.map((i) => {
+      const r = this.expertList().find((f) => f.name === i.name);
       if (r && r.alias) i.name = r.alias;
       return i;
     });
@@ -154,7 +154,7 @@ class IndexService extends CrudService {
       value: surveys,
     });
     const trans = await this.tranModel.aggregate([
-      { $match: { status: { $in: [ '0', '1', '3' ] } } },
+      { $match: { status: { $in: ['0', '1', '3'] } } },
       {
         $group: {
           _id: '$status',
@@ -165,7 +165,7 @@ class IndexService extends CrudService {
     arr.push({
       name: '正在洽谈',
       value: _.get(
-        trans.find(f => f._id === '0'),
+        trans.find((f) => f._id === '0'),
         'value',
         0
       ),
@@ -173,7 +173,7 @@ class IndexService extends CrudService {
     arr.push({
       name: '达成意向',
       value: _.get(
-        trans.find(f => f._id === '1'),
+        trans.find((f) => f._id === '1'),
         'value',
         0
       ),
@@ -181,7 +181,7 @@ class IndexService extends CrudService {
     arr.push({
       name: '对接完成',
       value: _.get(
-        trans.find(f => f._id === '3'),
+        trans.find((f) => f._id === '3'),
         'value',
         0
       ),
@@ -237,7 +237,7 @@ class IndexService extends CrudService {
     console.log(tyjb);
     // 洽谈合作 达成意向 交易完成
     const trans = await this.tranModel.aggregate([
-      { $match: { status: { $in: [ '0', '1', '3' ] } } },
+      { $match: { status: { $in: ['0', '1', '3'] } } },
       {
         $group: {
           _id: '$status',
@@ -246,17 +246,17 @@ class IndexService extends CrudService {
       },
     ]);
     const qthz = _.get(
-      trans.find(f => f._id === '0'),
+      trans.find((f) => f._id === '0'),
       'value',
       0
     );
     const dcyx = _.get(
-      trans.find(f => f._id === '1'),
+      trans.find((f) => f._id === '1'),
       'value',
       0
     );
     const jywc = _.get(
-      trans.find(f => f._id === '3'),
+      trans.find((f) => f._id === '3'),
       'value',
       0
     );
@@ -340,7 +340,7 @@ class IndexService extends CrudService {
     const obj = [];
     for (const i of meta) {
       const { key, name } = i;
-      const r = list.find(f => f._id === key);
+      const r = list.find((f) => f._id === key);
       if (r) {
         obj.push({ name, value: r.count });
       } else {
@@ -361,7 +361,7 @@ class IndexService extends CrudService {
       else userQuery[key] = query[key];
     }
     const publics = [{ $match: userQuery }, { $project: { productList: 1, _id: 0 } }, { $unwind: '$productList' }, { $match: productQuery }];
-    const data = await this.ctx.model.Dock.DockUser.aggregate([ ...publics, { $skip: parseInt(skip) }, { $limit: parseInt(limit) }]).replaceRoot('productList');
+    const data = await this.ctx.model.Dock.DockUser.aggregate([...publics, { $skip: parseInt(skip) }, { $limit: parseInt(limit) }]).replaceRoot('productList');
     let total = await this.ctx.model.Dock.DockUser.aggregate([
       ...publics,
       {
@@ -388,24 +388,24 @@ class IndexService extends CrudService {
     // 专利申请
     const papply = this.ctx.model.Patent.Patentapply;
     const apply = await papply.count({
-      status: [ '0', '1', '-1', '2', '3', '4', '-4', '5', '-5', '6', '-6', '7' ],
+      status: ['0', '1', '-1', '2', '3', '4', '-4', '5', '-5', '6', '-6', '7'],
       user_id: id,
     });
     // 查询检索
     const palysis = this.ctx.model.Patent.Patentanalysis;
-    const analysis = await palysis.count({ status: [ '0', '1', '-1', '2' ], user_id: id });
+    const analysis = await palysis.count({ status: ['0', '1', '-1', '2'], user_id: id });
     // 价值评估
     const paccess = this.ctx.model.Patent.Patentassess;
-    const access = await paccess.count({ status: [ '0', '1', '-1', '2' ], user_id: id });
+    const access = await paccess.count({ status: ['0', '1', '-1', '2'], user_id: id });
     // 专利信息
     const patentInfo = this.ctx.model.Patent.Patentinfo;
     const information = await patentInfo.count({ user_id: { $elemMatch: { user_id: id } } });
     // 专利维权
     const patentsafeg = this.ctx.model.Patent.Patentsafeg;
-    const safeg = await patentsafeg.count({ status: [ '0', '1', '2' ], user_id: id });
+    const safeg = await patentsafeg.count({ status: ['0', '1', '2'], user_id: id });
     // 专利预警
     const patentEarly = this.ctx.model.Patent.Patentearly;
-    const early = await patentEarly.count({ user_id: { $elemMatch: { $in: [ ObjectId(id) ] } } });
+    const early = await patentEarly.count({ user_id: { $elemMatch: { $in: [ObjectId(id)] } } });
     // 专利交易
     const patentTrans = this.ctx.model.Patent.Patenttrans;
     const trans1 = await patentTrans.count({ type: '转让', user_id: id });
@@ -420,6 +420,27 @@ class IndexService extends CrudService {
       transaction: { trans1, trans2, trans3, trans4, trans5 },
     };
   }
+
+  /**
+   * 根据申请人统计,申请人所在的专利信息数量
+   */
+  async patentInfoByApplyPerson() {
+    const pImodel = this.ctx.model.Patent.Patentinfo;
+    const data = await pImodel.find({}, { apply_personal: 1 });
+    if (data.length <= 0) {
+      return '未找到专利信息相关数据';
+    }
+    let nameList = data.map((i) => i.apply_personal).map((i) => i.split(';'));
+    nameList = _.uniq(_.flattenDeep(nameList).map((i) => _.trim(i)));
+    const arr = [];
+    for (const i of nameList) {
+      const reg = new RegExp(i);
+      const query = { apply_personal: reg };
+      const num = await pImodel.count(query);
+      arr.push({ name: i, num });
+    }
+    return arr;
+  }
 }
 
 module.exports = IndexService;

+ 3 - 37
test/test.js

@@ -2,42 +2,8 @@
 
 const moment = require('moment');
 const _ = require('lodash');
-
+const { app, mock, assert } = require('egg-mock/bootstrap');
 describe('test/test.js', () => {
-  const create_date = '2020-05-18';
-  const limitMonth = 3;
-  const today = '2022-03-19';
-  // 取专利日期
-  const month = moment(create_date).format('MM-DD');
-  // // 取得当前年份
-  const nowYear = moment().format('YYYY');
-  // // 当前年份+一年
-  const afterYear = moment(nowYear).add(1, 'year').format('YYYY');
-  // // 开始时间(先组合日期,减去三个月)
-  const nowDate = afterYear + '-' + month;
-  const start = moment(nowDate).subtract(limitMonth, 'months').format('YYYY-MM-DD');
-  // 结束时间
-  const end = afterYear + '-' + month;
-  const r = moment(today).isBetween(start, end, null, '[]');
-  console.log(`${start} - ${end}`);
-  console.log(r);
-  if (r) {
-    // 结束日期 和 今天 差的天数
-    const day = moment(end).diff(moment(today), 'days');
-    console.log(`今天和最后一天相差天数:${day}`);
-    // 是否发送的变量
-    let dr = false;
-    if (moment().format('YYYY-MM-DD') === start) {
-      // 第一天发送
-      dr = true;
-    } else {
-      // 差10天就发
-      const dur = 10;
-      // 判断是不是整数.整数就发送
-      dr = _.isInteger(_.floor(_.divide(day, dur)));
-    }
-
-
-  }
-
+  const meta = require('../app/public/patent/infoExport');
+  console.log(meta());
 });