ruifeng_liu 3 anni fa
parent
commit
e41c93a9e6

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

@@ -97,5 +97,22 @@ class IndexController extends Controller {
     const data = await this.service.patentUserIndex(this.ctx.query);
     this.ctx.ok({ data });
   }
+
+  // 我的申请
+  async getMyApply() {
+    const data = await this.service.getMyApply(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+  // 获取我的专利
+  async getMyPatent() {
+    const data = await this.service.getMyPatent(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+  // 获取我的交易信息
+  async getMyTransaction() {
+    const data = await this.service.getMyTransaction(this.ctx.query);
+    this.ctx.ok({ data });
+  }
+
 }
 module.exports = CrudController(IndexController, meta);

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

@@ -18,4 +18,9 @@ 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}/getMyApply`, controller[index][target].getMyApply);
+  router.get(target, `${profix}${vision}/${index}/${target}/getMyPatent`, controller[index][target].getMyPatent);
+  router.get(target, `${profix}${vision}/${index}/${target}/getMyTransaction`, controller[index][target].getMyTransaction);
+
 };

+ 41 - 47
app/service/statistics/index.js

@@ -382,53 +382,47 @@ class IndexService extends CrudService {
   }
 
   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',
-        },
-      },
-      { $match: { 'report.0': { $exists: true } } },
-      { $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 };
-    // 发明,使用新型,其他
-    let invent = 0,
-      practical = 0,
-      other = 0,
-      patent = {};
-    let user = await this.personalModel.findById(id);
-    if (!user) user = await this.organizationModel.findById(id);
-    if (user) {
-      const { name } = user;
-      const query = {};
-      if (name) query.$or = [{ inventor: new RegExp(name) }, { apply_personal: new RegExp(name) }];
-      invent = await this.patentModel.count({ type: '发明', ...query });
-      practical = await this.patentModel.count({ type: '实用新型', ...query });
-      other = await this.patentModel.count({ $and: [{ type: { $ne: '实用新型' } }, { type: { $ne: '发明' } }], ...query });
-    }
-    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 };
+    const patentExamine = this.ctx.service.patent.patentexamine;
+    const unread = await patentExamine.count({ id, is_read: false });
+    return { unread };
+  }
+
+  /**
+   * 我的申请
+   * @param {String} param0 id
+   */
+  async getMyApply({ id }) {
+    const papply = this.ctx.patent.patentapply;
+    const apply = await papply.count({ status: [ '0', '1', '-1', '2' ], user_id: id });
+    const palysis = this.ctx.patent.patentanalysis;
+    const analysis = await palysis.count({ status: [ '0', '-1' ], user_id: id });
+    const paccess = this.ctx.patent.patentassess;
+    const access = await paccess.count({ status: [ '0', '-1' ], user_id: id });
+    return { apply, analysis, access };
+  }
+
+  /**
+   * 获取我的专利
+   * @param {String} param0 id
+   */
+  async getMyPatent({ id }) {
+    const patentInfo = this.ctx.patent.patentinfo;
+    const information = await patentInfo.count({ user_id: [ id ] });
+    const patentEarly = this.ctx.patent.patentearly;
+    const early = await patentEarly.count({ user_id: [ id ] });
+    return { information, early };
+  }
+
+  /**
+   * 获取我的交易信息
+   * @param {String} param0 id
+   */
+  async getMyTransaction({ id }) {
+    const patentTrans = this.ctx.patent.patenttrans;
+    const trans1 = await patentTrans.count({ type: '转让', user_id: id });
+    const trans2 = await patentTrans.count({ type: '合作', user_id: id });
+    const trans3 = await patentTrans.count({ type: '招商', user_id: id });
+    return { trans1, trans2, trans3 };
   }
 }