lrf402788946 3 лет назад
Родитель
Сommit
02c098ef5f

+ 6 - 0
app/controller/statistics/index.js

@@ -91,5 +91,11 @@ class IndexController extends Controller {
     const data = await this.service.dockProduct(query);
     this.ctx.ok(data);
   }
+
+  // 专利运营用户首页统计
+  async patentUserIndex() {
+    const data = await this.service.patentUserIndex(this.ctx.query);
+    this.ctx.ok(data);
+  }
 }
 module.exports = CrudController(IndexController, meta);

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

@@ -17,4 +17,5 @@ module.exports = app => {
   router.get(target, `${profix}${vision}/${index}/${target}/orgCount`, controller[index][target].orgCount);
   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);
 };

+ 38 - 0
app/service/statistics/index.js

@@ -380,6 +380,44 @@ class IndexService extends CrudService {
     }
     return { data, total };
   }
+
+  async patentUserIndex({ id }) {
+    const disclosure = this.ctx.model.Patent.Disclosure;
+    // 预评估:预评估报告的数据数量,申请中:所有的数据
+    const condition = [
+      { $match: { user_id: ObjectId(id) } },
+      {
+        $lookup: {
+          from: 'disclosure_report',
+          localField: '_id',
+          foreignField: 'disclosure_id',
+          as: 'report',
+        },
+      },
+      { $group: { _id: '', total: { $sum: 1 } } },
+    ];
+    const r1 = await disclosure.aggregate(condition);
+    const report = _.get(_.head(r1), 'total', 0);
+    const havehand = await disclosure.count({ user_id: ObjectId(id) });
+    const apply = { report, havehand };
+    // 发明,使用新型,其他
+    const invent = await disclosure.count({ user_id: ObjectId(id), type: '发明' });
+    const practical = await disclosure.count({ user_id: ObjectId(id), type: '使用新型' });
+    const other = await disclosure.count({ user_id: ObjectId(id), $and: [{ type: { $ne: '使用新型' } }, { type: { $ne: '发明' } }] });
+    const patent = { invent, practical, other };
+    // 消息:未读,已读,通知(所有)
+    const noticeModel = this.ctx.model.Patent.Notice;
+    const unread = await noticeModel.count({ to: ObjectId(id), is_read: false });
+    const read = await noticeModel.count({ to: ObjectId(id), is_read: true });
+    const notice = await noticeModel.count({ to: ObjectId(id) });
+    const message = { unread, read, notice };
+    // TODO 交易: 许可, 转移,质押
+    const permit = 0;
+    const transfer = 0;
+    const pledge = 0;
+    const deal = { permit, transfer, pledge };
+    return { apply, patent, message, deal };
+  }
 }
 
 module.exports = IndexService;