123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- 'use strict';
- const Controller = require('egg').Controller;
- const moment = require('moment');
- class StatisticsController extends Controller {
- // 1. 采集数据图
- async statistics() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const statisticsResult = await service.statisticsService.statistics(query);
- ctx.success(statisticsResult[0]);
- }
- // 自主上报 五级地区查询
- async ownerDept() {
- const { ctx } = this;
- const params = {};
- const query = ctx.query;
- if (query.fid) {
- params.fid = query.fid;
- } else {
- params.level = '1';
- }
- const statisticsResult = await ctx.model.SysDeptModel.find(params);
- ctx.success(statisticsResult);
- }
- async user() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const statisticsResult = await service.statisticsService.user(query);
- ctx.success(statisticsResult[0]);
- }
- async info() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const statisticsResult = await service.statisticsService.info(query);
- ctx.success(statisticsResult[0]);
- }
- async oldType() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const statisticsResult = await service.statisticsService.oldType(query);
- ctx.success(statisticsResult[0]);
- }
- // 2. 吉林省全县区74个审核成功统计图表 优化
- async dept3() {
- const { ctx, service } = this;
- const statisticsResult = await service.statisticsService.dept3();
- ctx.success(statisticsResult);
- }
- // // 吉林省全县区74个审核成功统计图表
- // async dept3Statistics() {
- // const { ctx, service } = this;
- // const statisticsResult = await service.statisticsService.dept3Statistics();
- // ctx.success(statisticsResult);
- // }
- // 3. 地区积分统计图
- async deptValues() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const deptValuesList = await service.statisticsService.deptValues(query);
- ctx.success(deptValuesList);
- }
- // 4. 个人积分统计图,优化版
- async oneValues() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept
- if (!ctx.query.dept1) {
- delete ctx.query.dept1;
- }
- if (!ctx.query.dept2) {
- delete ctx.query.dept2;
- }
- if (!ctx.query.dept3) {
- delete ctx.query.dept3;
- }
- if (!ctx.query.dept4) {
- delete ctx.query.dept4;
- }
- if (!ctx.query.dept5) {
- delete ctx.query.dept5;
- }
- delete ctx.query.deptId;
- // admin的dept 存在冲突,所以它不需要结合
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- ctx.query['dept' + level] = user.dept._id;
- }
- // 判断如果当前是采集员看数据的话 只能看他自己
- if (user.role._id + '' == this.app.config.defaultUserRoleId) {
- ctx.query.cjname = user.loginName;
- }
- const result = await service.statisticsService.userValues(ctx.query);
- ctx.success(result);
- }
- // // 个人积分统计图
- // async userValues() {
- // const { ctx, service } = this;
- // const user = ctx.user;
- // const level = user.dept.level;
- // // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept
- // if (!ctx.query.dept1) {
- // delete ctx.query.dept1;
- // }
- // if (!ctx.query.dept2) {
- // delete ctx.query.dept2;
- // }
- // if (!ctx.query.dept3) {
- // delete ctx.query.dept3;
- // }
- // if (!ctx.query.dept4) {
- // delete ctx.query.dept4;
- // }
- // if (!ctx.query.dept5) {
- // delete ctx.query.dept5;
- // }
- // delete ctx.query.deptId;
- // // admin的dept 存在冲突,所以它不需要结合
- // if (user.role._id != this.app.config.defaultAdminRoleId) {
- // ctx.query['dept' + level] = user.dept._id;
- // }
- //
- // // 判断如果当前是采集员看数据的话 只能看他自己
- // if (user.role._id + '' == this.app.config.defaultUserRoleId) {
- // ctx.query.cjname = user.loginName;
- // }
- //
- // const result = await service.statisticsService.userValues(ctx.query);
- // ctx.success(result);
- // }
- // 5. 探访类别分布图
- async visitDeptStatistics() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const deptValuesList = await service.statisticsService.visitDeptOldType(query);
- ctx.success(deptValuesList);
- }
- // 6. 探访县区分布图
- async visitDept3Statistics() {
- const { ctx, service } = this;
- const query = ctx.query;
- const statisticsResult = await service.statisticsService.visitDept3Statistics(query);
- ctx.success(statisticsResult);
- }
- // 紧急需求统计
- async urgency() {
- const { ctx, service } = this;
- const user = ctx.user;
- const level = user.dept.level;
- const query = ctx.query;
- if (query.level == '5') {
- ctx.error('已经是最后一级了');
- return;
- }
- if (query.deptFid && query.level) {
- query.deptLevel = parseInt(query.level) + 1;
- } else {
- query.level = level;
- query.deptLevel = query.level;
- if (user.role._id != this.app.config.defaultAdminRoleId) {
- query.deptId = user.dept._id;
- }
- }
- const statisticsResult = await service.statisticsService.urgencyStatistics(query);
- ctx.success(statisticsResult[0]);
- }
- }
- module.exports = StatisticsController;
|