Browse Source

对接关注

chen 5 years ago
parent
commit
3f74056293
2 changed files with 56 additions and 223 deletions
  1. 0 222
      app/service/intelligentDocking.js
  2. 56 1
      app/service/intelligentFollow.js

+ 0 - 222
app/service/intelligentDocking.js

@@ -235,11 +235,6 @@ class IntelligentDockingService extends CrudService {
       { $unwind: { path: '$institution', preserveNullAndEmptyArrays: true } },
       { $unwind: { path: '$finance_claims', preserveNullAndEmptyArrays: true } },
       { $unwind: { path: '$dictionary', preserveNullAndEmptyArrays: true } },
-
-      // { $unwind: '$company', preserveNullAndEmptyArrays: true },
-      // { $unwind: '$institution', preserveNullAndEmptyArrays: true },
-      // { $unwind: '$finance_claims', preserveNullAndEmptyArrays: true },
-      // { $unwind: '$dictionary', preserveNullAndEmptyArrays: true },
       { $unwind: { path: '$follow', preserveNullAndEmptyArrays: true } },
       { $project:
           {
@@ -285,223 +280,6 @@ class IntelligentDockingService extends CrudService {
     return { result, total };
   }
 
-  // 金控端查询列表
-  async jinkongList(data) {
-    const query = {};
-    if (data.id) { // 单查  对接需求id
-      query._id = ObjectId(data.id);
-    }
-    if (data.jg_id) { // 金融机构ID
-      query.jg_id = data.jg_id;
-    }
-    if (data.uid) { // 企业ID
-      query.uid = data.uid;
-    }
-    if (data.cid) { // 产品id
-      query.cid = data.cid;
-    }
-    if (data.status) { // 状态
-      query.status = data.status;
-    }
-    const skip = Number.parseInt(data.skip) || 1;
-    const limit = Number.parseInt(data.limit) || 10;
-
-    // const total = await this.model.countDocuments(query);
-    const total = await this.model.aggregate([
-      { $match: query },
-      { $project:
-          {
-            ensure_id: 1,
-            person: 1,
-            money: 1,
-            claims_min_term: 1,
-            claims_max_term: 1,
-            mongey_min_rate: 1,
-            mongey_max_rate: 1,
-            when: 1,
-            refuse_times: 1,
-            additional_information: 1,
-            status: 1,
-            jg_id: { $toObjectId: '$jg_id' },
-            cid: { $toObjectId: '$cid' },
-            uid: '$uid',
-            xqId: { $toString: '$_id' },
-            time: '$meta.createdAt',
-          },
-      },
-      { $lookup:
-          {
-            from: 'institution',
-            localField: 'jg_id',
-            foreignField: '_id',
-            as: 'institution',
-          },
-      },
-      { $lookup:
-          {
-            from: 't_finance_claims',
-            localField: 'cid',
-            foreignField: '_id',
-            as: 'finance_claims',
-          },
-      },
-      { $lookup:
-          {
-            from: 'dictionary',
-            localField: 'ensure_id',
-            foreignField: 'code',
-            as: 'dictionary',
-          },
-      },
-      { $lookup:
-          {
-            from: 'intelligent_follow',
-            localField: 'xqId',
-            foreignField: 'intelligentId',
-            as: 'follow',
-          },
-      },
-      { $unwind: '$institution' },
-      { $unwind: '$finance_claims' },
-      { $unwind: '$dictionary' },
-      { $unwind: { path: '$follow', preserveNullAndEmptyArrays: true } },
-      { $project:
-          {
-            ensure_id: 1,
-            person: 1,
-            money: 1,
-            claims_min_term: 1,
-            claims_max_term: 1,
-            mongey_min_rate: 1,
-            mongey_max_rate: 1,
-            when: 1,
-            refuse_times: 1,
-            additional_information: 1,
-            status: 1,
-            creditStatus: '$follow.creditStatus',
-            jg_id: { $toObjectId: '$jg_id' },
-            cid: { $toObjectId: '$cid' },
-            uid: '$uid',
-            xqId: { $toString: '$_id' },
-            time: '$meta.createdAt',
-            company: '$company',
-            institution: '$institution',
-            finance_claims: '$finance_claims',
-            dictionary: '$dictionary',
-            follow: '$follow',
-          },
-      },
-      { $sort: { time: -1 } },
-    ]);
-    const result = await this.model.aggregate([
-      { $match: query },
-      { $project:
-          {
-            ensure_id: 1,
-            person: 1,
-            money: 1,
-            claims_min_term: 1,
-            claims_max_term: 1,
-            mongey_min_rate: 1,
-            mongey_max_rate: 1,
-            when: 1,
-            refuse_times: 1,
-            additional_information: 1,
-            status: 1,
-            jg_id: { $toObjectId: '$jg_id' },
-            cid: { $toObjectId: '$cid' },
-            uid: '$uid',
-            xqId: { $toString: '$_id' },
-            time: '$meta.createdAt',
-          },
-      },
-      { $lookup:
-          {
-            from: 'company_identify',
-            localField: 'uid',
-            foreignField: 'uid',
-            as: 'company',
-          },
-      },
-      { $lookup:
-          {
-            from: 'institution',
-            localField: 'jg_id',
-            foreignField: '_id',
-            as: 'institution',
-          },
-      },
-      { $lookup:
-          {
-            from: 't_finance_claims',
-            localField: 'cid',
-            foreignField: '_id',
-            as: 'finance_claims',
-          },
-      },
-      { $lookup:
-          {
-            from: 'dictionary',
-            localField: 'ensure_id',
-            foreignField: 'code',
-            as: 'dictionary',
-          },
-      },
-      // { $lookup:
-      //     {
-      //       from: 'dictionary',
-      //       localField: 'when',
-      //       foreignField: 'code',
-      //       as: 'when',
-      //     },
-      // },
-      { $lookup:
-          {
-            from: 'intelligent_follow',
-            localField: 'xqId',
-            foreignField: 'intelligentId',
-            as: 'follow',
-          },
-      },
-      { $unwind: '$company' },
-      { $unwind: '$institution' },
-      { $unwind: '$finance_claims' },
-      { $unwind: '$dictionary' },
-      { $unwind: { path: '$follow', preserveNullAndEmptyArrays: true } },
-      // { $unwind: { path: '$when', preserveNullAndEmptyArrays: true } },
-      { $project:
-          {
-            ensure_id: 1,
-            person: 1,
-            money: 1,
-            claims_min_term: 1,
-            claims_max_term: 1,
-            mongey_min_rate: 1,
-            mongey_max_rate: 1,
-            when: 1,
-            refuse_times: 1,
-            additional_information: 1,
-            status: 1,
-            creditStatus: '$follow.creditStatus',
-            jg_id: { $toObjectId: '$jg_id' },
-            cid: { $toObjectId: '$cid' },
-            uid: '$uid',
-            xqId: { $toString: '$_id' },
-            time: '$meta.createdAt',
-            company: '$company',
-            institution: '$institution',
-            finance_claims: '$finance_claims',
-            dictionary: '$dictionary',
-            follow: '$follow',
-          },
-      },
-      { $skip: (skip - 1) * limit },
-      { $limit: limit },
-      { $sort: { time: -1 } },
-    ]);
-    return { result, total: total.length };
-  }
-
   // 拒绝接口
   async refuse(data) {
     const { intelligentId, guanzhuid, userid, reason } = data;// intelligentId, userid, reason 需求id,银行id,拒绝理由

+ 56 - 1
app/service/intelligentFollow.js

@@ -49,6 +49,9 @@ class IntelligentFollowService extends CrudService {
   // 关注列表
   async getFollowList(data) {
     const match = {};
+    if (data.followId) { // 关注表id
+      match._id = ObjectId(data.followId);
+    }
     if (data.userid) { // 金融机构ID---客户经理
       match.uuid = data.userid;
     }
@@ -73,6 +76,7 @@ class IntelligentFollowService extends CrudService {
             sxhowlong: 1,
             sxcplilue: 1,
             savetime: '$meta.createdAt',
+            time: '$meta.createdAt',
           },
       },
       { $lookup: {
@@ -81,9 +85,60 @@ class IntelligentFollowService extends CrudService {
         foreignField: '_id',
         as: 'intelligent' } },
       { $unwind: '$intelligent' },
+
+      { $project:
+          {
+            intelligentId: 1,
+            uuid: 1,
+            creditStatus: 1,
+            credit_money: 1,
+            sxcpname: 1,
+            sxhowlong: 1,
+            sxcplilue: 1,
+            time: 1,
+            savetime: '$meta.createdAt',
+            intelligent: '$intelligent',
+            jg_id: { $toObjectId: '$intelligent.jg_id' },
+            cid: { $toObjectId: '$intelligent.cid' },
+            uid: '$intelligent.uid',
+            ensure_id: '$intelligent.ensure_id',
+          },
+      },
+      { $lookup:
+              {
+                from: 'company_identify',
+                localField: 'uid',
+                foreignField: 'uid',
+                as: 'company',
+              },
+      },
+      { $lookup:
+              {
+                from: 'institution',
+                localField: 'jg_id',
+                foreignField: '_id',
+                as: 'institution',
+              },
+      },
+      { $lookup:
+              {
+                from: 't_finance_claims',
+                localField: 'cid',
+                foreignField: '_id',
+                as: 'finance_claims',
+              },
+      },
+      { $lookup:
+              {
+                from: 'dictionary',
+                localField: 'ensure_id',
+                foreignField: 'code',
+                as: 'dictionary',
+              },
+      },
       { $skip: (skip - 1) * limit },
       { $limit: limit },
-      { $sort: { savetime: -1 } },
+      { $sort: { time: -1 } },
     ]);
     const newres = { res, total };
     return newres;