statistics.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. // 统计
  7. class StatisticsService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'statistics');
  10. this.httpUtil = this.ctx.service.util.httpUtil;
  11. this.project = this.app.config.project;
  12. }
  13. async users() {
  14. // 需要访问两个地方,1个是正常9201的main中的service,另一个是9101的live中的统计
  15. const url1 = `${this.project.main}/statistics/users`;
  16. const url2 = `${this.project.live}/api/live/v0/statistics/index/orgCount`; // 带条件就直接写
  17. let obj = {};
  18. const res1 = await this.httpUtil.$get(url1);
  19. if (res1.errcode === 0) {
  20. obj = res1;
  21. } else {
  22. obj = res1;
  23. return obj;
  24. }
  25. const res2 = await this.httpUtil.$get(url2);
  26. if (res2.errcode === 0) {
  27. obj.data.push({ name: '企业用户', value: res2.data });
  28. } else {
  29. obj = res2;
  30. return obj;
  31. }
  32. return obj;
  33. }
  34. async policyApply() {
  35. const url = `${this.project.live}/api/live/v0/statistics/index/pac`;
  36. return await this.httpUtil.$get(url);
  37. }
  38. }
  39. module.exports = StatisticsService;