asd123a20 3 rokov pred
rodič
commit
b4f0c9abd7

+ 6 - 0
service-gateway/config/importandexport.js

@@ -25,4 +25,10 @@ module.exports = [
     issuer: [ 'naf' ],
     log: false,
   },
+  {
+    url: '/api/importandexport/handle/exportsDownload',
+    jwt: false,
+    issuer: [ 'naf' ],
+    log: false,
+  },
 ];

+ 4 - 0
service-import-export/app/controller/handle.js

@@ -20,6 +20,10 @@ class HandleController extends Controller {
     const res = await this.ctx.service.handle.template(this.ctx.query);
     this.ctx.body = res;
   }
+  async exportsDownload() {
+    const res = await this.ctx.service.handle.exportsDownload(this.ctx.query);
+    this.ctx.body = res;
+  }
 }
 
 module.exports = HandleController;

+ 1 - 0
service-import-export/app/router.js

@@ -10,4 +10,5 @@ module.exports = app => {
   router.post('/api/importandexport/handle/exports', controller.handle.export);
   router.get('/api/importandexport/handle/template', controller.handle.template);
   router.get('/api/importandexport/handle/progressed', controller.handle.progressed);
+  router.get('/api/importandexport/handle/exportsDownload', controller.handle.exportsDownload);
 };

+ 22 - 19
service-import-export/app/service/exports.js

@@ -6,30 +6,33 @@ class ExportsService extends Service {
   async exportsuser({ filter, skip, ids, _this }) {
     const key = Object.keys(filter);
     if (key.length > 0) return await _this.ctx.model.User.find({ ...filter }).skip(skip * 10).limit(10);
-    let list = await Promise.all(
-      ids.map(async e => {
-        const res = await _this.ctx.model.User.findOne({ _id: e });
-        if (res) return res;
-      })
-    );
-    list = list.filter(e => e !== undefined);
-    return list;
+    if (ids) {
+      let list = await Promise.all(
+        ids.map(async e => {
+          const res = await _this.ctx.model.User.findOne({ _id: e });
+          if (res) return res;
+        })
+      );
+      list = list.filter(e => e !== undefined);
+      return list;
+    }
+    return await _this.ctx.model.User.find().skip(skip * 10).limit(10);
   }
   // vip导出
   async exportsvip({ filter, skip, ids, _this }) {
     const key = Object.keys(filter);
     if (key.length > 0) return await _this.ctx.model.Vip.find({ ...filter }).skip(skip * 10).limit(10);
-    let list = await Promise.all(
-      ids.map(async e => {
-        const res = await _this.ctx.model.Vip.findOne({ _id: e });
-        if (res) {
-          const data = await this.convert({ data: res });
-          return data;
-        }
-      })
-    );
-    list = list.filter(e => e !== undefined);
-    return list;
+    if (ids) {
+      let list = await Promise.all(
+        ids.map(async e => {
+          const res = await _this.ctx.model.User.findOne({ _id: e });
+          if (res) return res;
+        })
+      );
+      list = list.filter(e => e !== undefined);
+      return list;
+    }
+    return await _this.ctx.model.User.find().skip(skip * 10).limit(10);
   }
   // 数据转换函数
   async convert({ data }) {

+ 7 - 4
service-import-export/app/service/handle.js

@@ -42,21 +42,24 @@ class HandleService extends Service {
         const data = `{ "${i}": { "$regex": "${filters[i]}" } }`;
         filter.$or.push(JSON.parse(data));
       }
-      // 获取查询总数函数
-      const totalfun = this.ctx.service.total[`total${type}`];
-      // 赋值总数
-      total = await totalfun({ ...filter, _this: this });
     }
+    // 获取查询总数函数
+    const totalfun = this.ctx.service.total[`total${type}`];
+    // 赋值总数
+    total = await totalfun({ ...filter, _this: this });
+    console.log(total);
     // 获取查询函数
     const fun = this.ctx.service.exports[`exports${type}`];
     // 计算页数
     const pages = Math.ceil(total / 10);
+    console.log(pages);
     // 此处调用创建文件
     const file = await this.establishFile({ taskId, type, fileType });
     if (file === 'success') {
       for (let i = 0; i < pages; i++) {
         // 进度
         const progress = (i + 1) / pages * 100;
+        console.log(taskId, ':', progress);
         // 更新进度
         await this.ctx.service.progress.updateProgress({ taskId, progress, type });
         // 调用查询数据函数

+ 2 - 0
service-import-export/app/service/progress.js

@@ -17,7 +17,9 @@ class HandleService extends Service {
   }
   // 查询进度
   async progressed({ taskId }) {
+    console.log(taskId);
     const res = await this.progressModel.findOne({ taskId });
+    console.log(res);
     return { errcode: 0, errmsg: '', data: res };
   }
 }

+ 3 - 1
service-import-export/app/service/total.js

@@ -4,7 +4,9 @@ const Service = require('egg').Service;
 class TotalService extends Service {
   // 用户 总数
   async totaluser({ filter, _this }) {
-    return await _this.ctx.model.User.estimatedDocumentCount({ ...filter });
+    const res = await _this.ctx.model.User.estimatedDocumentCount({ ...filter });
+    console.log(res, 'res');
+    return res;
   }
   // vip 总数
   async totalvip({ filter, _this }) {