lrf402788946 4 rokov pred
rodič
commit
edaaf2f803

+ 33 - 8
app/controller/request.js

@@ -1,7 +1,7 @@
 'use strict';
 const Controller = require('egg').Controller;
 const { CrudController } = require('naf-framework-mongoose/lib/controller');
-
+const dealList = require('../util/deal-list');
 // 请求处理
 class RequestController extends Controller {
   constructor(ctx) {
@@ -10,13 +10,38 @@ class RequestController extends Controller {
     this.httpUtil = this.ctx.service.util.httpUtil;
   }
   async index() {
-    const { url, body, method } = this.util.analyzeUrl();
-    // query和url已经合并,没有query了,所以直接body,get方法第二个位置不需要了,也不会传值来(传来就是找茬)
-    // create,post,delete都有可能传,而且第二个位置都是body
-    const res = await this.httpUtil[`$${method}`](url, body);
-    // TODO,此处应该设置再处理名单,若在名单中,则继续处理数据,否则透传
-    this.ctx.body = res;
-    // this.ctx.ok();
+    const r = this.checkList();
+    if (r) {
+      // 纯人工处理
+      const { service, method } = r;
+      const res = await this.ctx.service[service][method]();
+      this.ctx.body = res;
+    } else {
+      const { url, body, method } = this.util.analyzeUrl();
+      // query和url已经合并,没有query了,所以直接body,get方法第二个位置不需要了,也不会传值来(传来就是找茬)
+      // create,post,delete都有可能传,而且第二个位置都是body
+      const res = await this.httpUtil[`$${method}`](url, body);
+      // TODO,此处应该设置再处理名单,若在名单中,则继续处理数据,否则透传
+      this.ctx.body = res;
+      // this.ctx.ok();
+    }
+
+  }
+
+  /**
+   * 检查是否是纯人工处理路由
+   */
+  checkList() {
+    const { url } = this.ctx.request;
+    let obj;
+    for (const i of dealList) {
+      const { uri, service, method } = i;
+      if (url.includes(uri)) {
+        obj = { service, method };
+        break;
+      }
+    }
+    return obj;
   }
 }
 module.exports = CrudController(RequestController, {});

+ 43 - 0
app/service/statistics.js

@@ -0,0 +1,43 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 统计
+class StatisticsService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'statistics');
+    this.httpUtil = this.ctx.service.util.httpUtil;
+    this.project = this.app.config.project;
+  }
+
+  async users() {
+    // 需要访问两个地方,1个是正常9201的main中的service,另一个是9101的live中的统计
+    const url1 = `${this.project.main}/statistics/users`;
+    const url2 = `${this.project.live}/api/live/v0/statistics/index/orgCount`; // 带条件就直接写
+    let obj = {};
+    const res1 = await this.httpUtil.$get(url1);
+    if (res1.errcode === 0) {
+      obj = res1;
+    } else {
+      obj = res1;
+      return obj;
+    }
+    const res2 = await this.httpUtil.$get(url2);
+    if (res2.errcode === 0) {
+      obj.data.push({ name: '企业用户', value: res2.data });
+    } else {
+      obj = res2;
+      return obj;
+    }
+    return obj;
+  }
+
+  async policyApply() {
+    const url = `${this.project.live}/api/live/v0/statistics/index/pac`;
+    return await this.httpUtil.$get(url);
+  }
+}
+
+module.exports = StatisticsService;

+ 5 - 0
app/util/deal-list.js

@@ -0,0 +1,5 @@
+'use strict';
+module.exports = [
+  { uri: '/statistics/user', service: 'statistics', method: 'users' },
+  { uri: '/statistics/data', service: 'statistics', method: 'policyApply' },
+];

+ 6 - 5
config/config.default.js

@@ -34,15 +34,16 @@ module.exports = appInfo => {
     },
   };
   config.security = {
-    csrf: {
-      enable: false,
-      type: 'ctoken',
-      useSession: true,
-    },
+    // csrf: {
+    //   enable: false,
+    //   type: 'ctoken',
+    //   useSession: true,
+    // },
   };
 
   config.project = {
     main: 'http://127.0.0.1:9201',
+    live: 'http://127.0.0.1:9101',
   };
 
   return {