Browse Source

Merge branch 'master' of http://git.cc-lotus.info/financial_platform/service-financial

wq 4 years ago
parent
commit
9b487877ac
1 changed files with 214 additions and 1 deletions
  1. 214 1
      app/service/intelligentDocking.js

+ 214 - 1
app/service/intelligentDocking.js

@@ -168,6 +168,219 @@ class IntelligentDockingService extends CrudService {
     const limit = Number.parseInt(data.limit) || 10;
 
     const total = await this.model.countDocuments(query);
+    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: 'intelligent_follow',
+            localField: 'xqId',
+            foreignField: 'intelligentId',
+            as: 'follow',
+          },
+      },
+      { $unwind: { path: '$company', preserveNullAndEmptyArrays: true } },
+      { $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:
+          {
+            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 };
+  }
+
+  // 金控端查询列表
+  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:
@@ -274,7 +487,7 @@ class IntelligentDockingService extends CrudService {
       { $limit: limit },
       { $sort: { time: -1 } },
     ]);
-    return { result, total };
+    return { result, total: total.length };
   }
 
   // 拒绝接口