chen před 4 roky
rodič
revize
a77fd79834
1 změnil soubory, kde provedl 116 přidání a 12 odebrání
  1. 116 12
      app/service/intelligentDocking.js

+ 116 - 12
app/service/intelligentDocking.js

@@ -167,8 +167,8 @@ class IntelligentDockingService extends CrudService {
     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([
+    const total = await this.model.countDocuments(query);
+    const result = await this.model.aggregate([
       { $match: query },
       { $project:
           {
@@ -222,14 +222,6 @@ class IntelligentDockingService extends CrudService {
             as: 'dictionary',
           },
       },
-      // { $lookup:
-      //     {
-      //       from: 'dictionary',
-      //       localField: 'when',
-      //       foreignField: 'code',
-      //       as: 'when',
-      //     },
-      // },
       { $lookup:
           {
             from: 'intelligent_follow',
@@ -238,12 +230,124 @@ class IntelligentDockingService extends CrudService {
             as: 'follow',
           },
       },
-      { $unwind: '$company' },
+      { $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 } },
-      // { $unwind: { path: '$when', preserveNullAndEmptyArrays: true } },
       { $project:
           {
             ensure_id: 1,