urgencyController.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. 'use strict';
  2. const Controller = require('../extend/baseController');
  3. class UrgencyController extends Controller {
  4. tag() {
  5. return this.ctx.service.urgencyService;
  6. }
  7. async list() {
  8. const { ctx } = this;
  9. const user = ctx.user;
  10. ctx.query.userid = user._id;
  11. ctx.setOrder('createTime', true); // 倒序
  12. const result = await this.tag().list(ctx.query);
  13. ctx.success(result);
  14. }
  15. // 分页查询
  16. async listForPage() {
  17. const { ctx, service } = this;
  18. const user = ctx.user;
  19. const level = user.dept.level;
  20. // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept
  21. if (!ctx.query.dept1) {
  22. delete ctx.query.dept1;
  23. }
  24. if (!ctx.query.dept2) {
  25. delete ctx.query.dept2;
  26. }
  27. if (!ctx.query.dept3) {
  28. delete ctx.query.dept3;
  29. }
  30. if (!ctx.query.dept4) {
  31. delete ctx.query.dept4;
  32. }
  33. if (!ctx.query.dept5) {
  34. delete ctx.query.dept5;
  35. }
  36. delete ctx.query.deptId;
  37. // admin的dept 存在冲突,所以它不需要结合
  38. if (user.role._id != this.app.config.defaultAdminRoleId) {
  39. ctx.query['dept' + level] = user.dept._id;
  40. }
  41. // 判断如果当前是采集员看数据的话 只能看他自己
  42. if (user.role._id + '' == this.app.config.defaultUserRoleId) {
  43. ctx.query.userName = user.loginName;
  44. }
  45. const result = await service.urgencyService.listForPage(ctx.query);
  46. ctx.success(result);
  47. }
  48. async urgencyFirst() {
  49. const { ctx, service } = this;
  50. const user = ctx.user;
  51. const level = user.dept.level;
  52. // 判断当前的dept权限 和传入的5级权限 不能超过当前人dept
  53. if (!ctx.query.dept1) {
  54. delete ctx.query.dept1;
  55. }
  56. if (!ctx.query.dept2) {
  57. delete ctx.query.dept2;
  58. }
  59. if (!ctx.query.dept3) {
  60. delete ctx.query.dept3;
  61. }
  62. if (!ctx.query.dept4) {
  63. delete ctx.query.dept4;
  64. }
  65. if (!ctx.query.dept5) {
  66. delete ctx.query.dept5;
  67. }
  68. delete ctx.query.deptId;
  69. // admin的dept 存在冲突,所以它不需要结合
  70. if (user.role._id != this.app.config.defaultAdminRoleId) {
  71. ctx.query['dept' + level] = user.dept._id;
  72. }
  73. const result = await service.urgencyService.urgencyFirst(ctx.query);
  74. ctx.success(result);
  75. }
  76. }
  77. module.exports = UrgencyController;