lrf402788946 il y a 4 ans
Parent
commit
5e31451b47
3 fichiers modifiés avec 24 ajouts et 16 suppressions
  1. 1 1
      app/service/dock/patent.js
  2. 3 3
      app/service/users/expert.js
  3. 20 12
      app/service/util/util.js

+ 1 - 1
app/service/dock/patent.js

@@ -15,7 +15,7 @@ class PatentService extends CrudService {
     super(ctx, 'patent');
     this.model = this.ctx.model.Patent;
 
-    this.root_path = process.env.NODE_ENV === 'development' ? '/usr/local/workspace/export/' : _.get(this.ctx.app.config.export, 'root_path');
+    this.root_path = process.env.NODE_ENV === 'development' ? 'E:\\exportFile' : _.get(this.ctx.app.config.export, 'root_path');
     this.file_type = '';
     if (!fs.existsSync(`${this.root_path}${this.file_type}`)) {
       // 如果不存在文件夹,就创建

+ 3 - 3
app/service/users/expert.js

@@ -11,7 +11,7 @@ class ExpertService extends CrudService {
     this.model = this.ctx.model.Expert;
   }
 
-  async query(condition, { skip = 0, limit = 10 } = {}) {
+  async query({ skip = 0, limit = 10, ...condition } = {}) {
     const { code, status } = condition;
     const query = {};
     if (code) query.code = code;
@@ -29,8 +29,8 @@ class ExpertService extends CrudService {
       },
       { $unwind: '$expert' },
       { $match: query },
-      { $skip: skip },
-      { $limit: limit },
+      { $skip: parseInt(skip) },
+      { $limit: parseInt(limit) },
     ]);
     data = data.map(i => {
       const { expert, ...info } = _.omit(i, [ '_id' ]);

+ 20 - 12
app/service/util/util.js

@@ -2,24 +2,32 @@
 const _ = require('lodash');
 const moment = require('moment');
 const { CrudService } = require('naf-framework-mongoose/lib/service');
-
+const fs = require('fs');
 class UtilService extends CrudService {
   constructor(ctx) {
     super(ctx);
     this.mq = this.ctx.mq;
   }
   async utilMethod(query, body) {
-    const res = await this.ctx.model.Dock.aggregate([
-      {
-        $lookup: {
-          from: 'dock_pw',
-          localField: '_id',
-          foreignField: 'dock_id',
-          as: 'pw',
-        },
-      },
-    ]);
-    return res;
+    const path = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\live_news_roadshow.json';
+    let text = await fs.readFileSync(path, { encoding: 'utf-8' });
+    text = JSON.parse(text);
+    for (const obj of text) {
+      const { dock_id } = obj;
+      if (dock_id) { obj.dock_id = { $oid: dock_id }; }
+    }
+    await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\live_news_roadshow-rewrite.json', JSON.stringify(text));
+    // const eupath = 'C:\\Users\\liuruifeng\\Desktop\\temp\\export\\expert,s_user.json';
+    // let eutext = await fs.readFileSync(eupath, { encoding: 'utf-8' });
+    // eutext = JSON.parse(eutext);
+    // console.log(eutext.length);
+    // for (const obj of text) {
+    //   if (_.isObject(obj.password)) continue;
+    //   const { password } = obj;
+    //   obj.password = { secret: password, mech: 'plain', createdAt: { $date: '2020-09-27T07:48:05.643Z' }, updatedAt: { $date: '2020-09-27T07:48:05.643Z' } };
+    // }
+    // await fs.writeFileSync('C:\\Users\\liuruifeng\\Desktop\\temp\\export\\role-5-rewrite.json', JSON.stringify(text));
+
   }
 
   dealQuery(query) {