statisticsController.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. const moment = require('moment');
  4. class StatisticsController extends Controller {
  5. // 1. 采集数据图
  6. async statistics() {
  7. const { ctx, service } = this;
  8. const user = ctx.user;
  9. const level = user.dept.level;
  10. const query = ctx.query;
  11. if (query.level == '5') {
  12. ctx.error('已经是最后一级了');
  13. return;
  14. }
  15. if (query.deptFid && query.level) {
  16. query.deptLevel = parseInt(query.level) + 1;
  17. } else {
  18. query.level = level;
  19. query.deptLevel = query.level;
  20. if (user.role._id != this.app.config.defaultAdminRoleId) {
  21. query.deptId = user.dept._id;
  22. }
  23. }
  24. const statisticsResult = await service.statisticsService.statistics(query);
  25. ctx.success(statisticsResult[0]);
  26. }
  27. // 自主上报 五级地区查询
  28. async ownerDept() {
  29. const { ctx } = this;
  30. const params = {};
  31. const query = ctx.query;
  32. if (query.fid) {
  33. params.fid = query.fid;
  34. } else {
  35. params.level = '1';
  36. }
  37. const statisticsResult = await ctx.model.SysDeptModel.find(params);
  38. ctx.success(statisticsResult);
  39. }
  40. async user() {
  41. const { ctx, service } = this;
  42. const user = ctx.user;
  43. const level = user.dept.level;
  44. const query = ctx.query;
  45. if (query.level == '5') {
  46. ctx.error('已经是最后一级了');
  47. return;
  48. }
  49. if (query.deptFid && query.level) {
  50. query.deptLevel = parseInt(query.level) + 1;
  51. } else {
  52. query.level = level;
  53. query.deptLevel = query.level;
  54. if (user.role._id != this.app.config.defaultAdminRoleId) {
  55. query.deptId = user.dept._id;
  56. }
  57. }
  58. const statisticsResult = await service.statisticsService.user(query);
  59. ctx.success(statisticsResult[0]);
  60. }
  61. async info() {
  62. const { ctx, service } = this;
  63. const user = ctx.user;
  64. const level = user.dept.level;
  65. const query = ctx.query;
  66. if (query.level == '5') {
  67. ctx.error('已经是最后一级了');
  68. return;
  69. }
  70. if (query.deptFid && query.level) {
  71. query.deptLevel = parseInt(query.level) + 1;
  72. } else {
  73. query.level = level;
  74. query.deptLevel = query.level;
  75. if (user.role._id != this.app.config.defaultAdminRoleId) {
  76. query.deptId = user.dept._id;
  77. }
  78. }
  79. const statisticsResult = await service.statisticsService.info(query);
  80. ctx.success(statisticsResult[0]);
  81. }
  82. async oldType() {
  83. const { ctx, service } = this;
  84. const user = ctx.user;
  85. const level = user.dept.level;
  86. const query = ctx.query;
  87. if (query.level == '5') {
  88. ctx.error('已经是最后一级了');
  89. return;
  90. }
  91. if (query.deptFid && query.level) {
  92. query.deptLevel = parseInt(query.level) + 1;
  93. } else {
  94. query.level = level;
  95. query.deptLevel = query.level;
  96. if (user.role._id != this.app.config.defaultAdminRoleId) {
  97. query.deptId = user.dept._id;
  98. }
  99. }
  100. const statisticsResult = await service.statisticsService.oldType(query);
  101. ctx.success(statisticsResult[0]);
  102. }
  103. // 2. 吉林省全县区74个审核成功统计图表 优化
  104. async dept3() {
  105. const { ctx, service } = this;
  106. const statisticsResult = await service.statisticsService.dept3();
  107. ctx.success(statisticsResult);
  108. }
  109. // // 吉林省全县区74个审核成功统计图表
  110. // async dept3Statistics() {
  111. // const { ctx, service } = this;
  112. // const statisticsResult = await service.statisticsService.dept3Statistics();
  113. // ctx.success(statisticsResult);
  114. // }
  115. // 3. 地区积分统计图
  116. async deptValues() {
  117. const { ctx, service } = this;
  118. const user = ctx.user;
  119. const level = user.dept.level;
  120. const query = ctx.query;
  121. if (query.level == '5') {
  122. ctx.error('已经是最后一级了');
  123. return;
  124. }
  125. if (query.deptFid && query.level) {
  126. query.deptLevel = parseInt(query.level) + 1;
  127. } else {
  128. query.level = level;
  129. query.deptLevel = query.level;
  130. if (user.role._id != this.app.config.defaultAdminRoleId) {
  131. query.deptId = user.dept._id;
  132. }
  133. }
  134. const deptValuesList = await service.statisticsService.deptValues(query);
  135. ctx.success(deptValuesList);
  136. }
  137. // 4. 个人积分统计图,优化版
  138. async oneValues() {
  139. const { ctx, service } = this;
  140. const user = ctx.user;
  141. const level = user.dept.level;
  142. // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept
  143. if (!ctx.query.dept1) {
  144. delete ctx.query.dept1;
  145. }
  146. if (!ctx.query.dept2) {
  147. delete ctx.query.dept2;
  148. }
  149. if (!ctx.query.dept3) {
  150. delete ctx.query.dept3;
  151. }
  152. if (!ctx.query.dept4) {
  153. delete ctx.query.dept4;
  154. }
  155. if (!ctx.query.dept5) {
  156. delete ctx.query.dept5;
  157. }
  158. delete ctx.query.deptId;
  159. // admin的dept 存在冲突,所以它不需要结合
  160. if (user.role._id != this.app.config.defaultAdminRoleId) {
  161. ctx.query['dept' + level] = user.dept._id;
  162. }
  163. // 判断如果当前是采集员看数据的话 只能看他自己
  164. if (user.role._id + '' == this.app.config.defaultUserRoleId) {
  165. ctx.query.cjname = user.loginName;
  166. }
  167. const result = await service.statisticsService.userValues(ctx.query);
  168. ctx.success(result);
  169. }
  170. // // 个人积分统计图
  171. // async userValues() {
  172. // const { ctx, service } = this;
  173. // const user = ctx.user;
  174. // const level = user.dept.level;
  175. // // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept
  176. // if (!ctx.query.dept1) {
  177. // delete ctx.query.dept1;
  178. // }
  179. // if (!ctx.query.dept2) {
  180. // delete ctx.query.dept2;
  181. // }
  182. // if (!ctx.query.dept3) {
  183. // delete ctx.query.dept3;
  184. // }
  185. // if (!ctx.query.dept4) {
  186. // delete ctx.query.dept4;
  187. // }
  188. // if (!ctx.query.dept5) {
  189. // delete ctx.query.dept5;
  190. // }
  191. // delete ctx.query.deptId;
  192. // // admin的dept 存在冲突,所以它不需要结合
  193. // if (user.role._id != this.app.config.defaultAdminRoleId) {
  194. // ctx.query['dept' + level] = user.dept._id;
  195. // }
  196. //
  197. // // 判断如果当前是采集员看数据的话 只能看他自己
  198. // if (user.role._id + '' == this.app.config.defaultUserRoleId) {
  199. // ctx.query.cjname = user.loginName;
  200. // }
  201. //
  202. // const result = await service.statisticsService.userValues(ctx.query);
  203. // ctx.success(result);
  204. // }
  205. // 5. 探访类别分布图
  206. async visitDeptStatistics() {
  207. const { ctx, service } = this;
  208. const user = ctx.user;
  209. const level = user.dept.level;
  210. const query = ctx.query;
  211. if (query.level == '5') {
  212. ctx.error('已经是最后一级了');
  213. return;
  214. }
  215. if (query.deptFid && query.level) {
  216. query.deptLevel = parseInt(query.level) + 1;
  217. } else {
  218. query.level = level;
  219. query.deptLevel = query.level;
  220. if (user.role._id != this.app.config.defaultAdminRoleId) {
  221. query.deptId = user.dept._id;
  222. }
  223. }
  224. const deptValuesList = await service.statisticsService.visitDeptOldType(query);
  225. ctx.success(deptValuesList);
  226. }
  227. // 6. 探访县区分布图
  228. async visitDept3Statistics() {
  229. const { ctx, service } = this;
  230. const query = ctx.query;
  231. const statisticsResult = await service.statisticsService.visitDept3Statistics(query);
  232. ctx.success(statisticsResult);
  233. }
  234. // 紧急需求统计
  235. async urgency() {
  236. const { ctx, service } = this;
  237. const user = ctx.user;
  238. const level = user.dept.level;
  239. const query = ctx.query;
  240. if (query.level == '5') {
  241. ctx.error('已经是最后一级了');
  242. return;
  243. }
  244. if (query.deptFid && query.level) {
  245. query.deptLevel = parseInt(query.level) + 1;
  246. } else {
  247. query.level = level;
  248. query.deptLevel = query.level;
  249. if (user.role._id != this.app.config.defaultAdminRoleId) {
  250. query.deptId = user.dept._id;
  251. }
  252. }
  253. const statisticsResult = await service.statisticsService.urgencyStatistics(query);
  254. ctx.success(statisticsResult[0]);
  255. }
  256. }
  257. module.exports = StatisticsController;