sysDeptController.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict';
  2. const Controller = require('../extend/baseController');
  3. class SysDeptController extends Controller {
  4. tag() {
  5. return this.ctx.service.sysDeptService;
  6. }
  7. async addDeptAndPerson() {
  8. const { ctx } = this;
  9. const query = ctx.request.body;
  10. delete query._id;
  11. const result = await this.tag()
  12. .addDeptAndPerson(query);
  13. if (result) {
  14. ctx.error(result);
  15. } else {
  16. ctx.success();
  17. }
  18. }
  19. async updateDeptAndPerson() {
  20. const { ctx, service } = this;
  21. const query = ctx.request.body;
  22. const { id } = query;
  23. delete query.id;
  24. const result = await service.sysDeptService.updateDeptAndPerson(id, query);
  25. if (result) {
  26. ctx.error(result);
  27. } else {
  28. ctx.success();
  29. }
  30. }
  31. async deleteWithSub() {
  32. const { ctx } = this;
  33. const query = ctx.query;
  34. const { id } = query;
  35. const result = await this.tag()
  36. .deleteWithSub(id);
  37. if (result) {
  38. ctx.error(result);
  39. } else {
  40. ctx.success();
  41. }
  42. }
  43. async listSortAsc() {
  44. const { ctx } = this;
  45. ctx.setOrder();
  46. const result = await this.tag()
  47. .list(ctx.query);
  48. ctx.success(result);
  49. }
  50. async listSortAscWithUser() {
  51. const { ctx } = this;
  52. const query = ctx.query;
  53. const user = ctx.user;
  54. ctx.setOrder();
  55. if (user.role._id != this.app.config.defaultAdminRoleId) {
  56. if (user[ 'dept' + query.level ]) {
  57. ctx.query._id = this.app.mongoose.Types.ObjectId(user[ 'dept' + query.level ]._id);
  58. }
  59. }
  60. const result = await this.tag()
  61. .list(query);
  62. ctx.success(result);
  63. }
  64. async listForPageSortWithUser() {
  65. const { ctx, service } = this;
  66. const query = ctx.query;
  67. const user = ctx.user;
  68. query.deptId = user.dept._id;
  69. query.level = user.dept.level;
  70. query.roleId = user.role._id;
  71. ctx.setOrder();
  72. const result = await service.sysDeptService.listForPageSortWithUser(query);
  73. ctx.success(result);
  74. }
  75. async orderChange() {
  76. const { ctx, service } = this;
  77. const query = ctx.query;
  78. const { id, type } = query;
  79. const result = await service.sysDeptService.orderChange(id, type);
  80. if (result) {
  81. ctx.error(result);
  82. } else {
  83. ctx.success();
  84. }
  85. }
  86. async findLink() {
  87. const { ctx, service } = this;
  88. const query = ctx.query;
  89. const result = await service.sysDeptService.findLink(query);
  90. ctx.logic(result);
  91. }
  92. }
  93. module.exports = SysDeptController;