sysDeptController.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. // 数据迁移
  32. async dataMigration() {
  33. const { ctx, service } = this;
  34. const query = ctx.request.body;
  35. const { id } = query;
  36. delete query.id;
  37. const result = await service.sysDeptService.dataMigration(id, query);
  38. if (result) {
  39. ctx.error(result);
  40. } else {
  41. ctx.success();
  42. }
  43. }
  44. // 迁移数据查询
  45. async listDept() {
  46. const { ctx } = this;
  47. ctx.setOrder();
  48. const result = await this.tag().listDept(ctx.query);
  49. ctx.success(result);
  50. }
  51. async deleteWithSub() {
  52. const { ctx } = this;
  53. const query = ctx.query;
  54. const { id } = query;
  55. const result = await this.tag()
  56. .deleteWithSub(id);
  57. if (result) {
  58. ctx.error(result);
  59. } else {
  60. ctx.success();
  61. }
  62. }
  63. async listSortAsc() {
  64. const { ctx } = this;
  65. ctx.setOrder();
  66. const result = await this.tag()
  67. .list(ctx.query);
  68. ctx.success(result);
  69. }
  70. async listSortAscWithUser() {
  71. const { ctx } = this;
  72. const query = ctx.query;
  73. const user = ctx.user;
  74. ctx.setOrder();
  75. if (user.role._id != this.app.config.defaultAdminRoleId) {
  76. if (user[ 'dept' + query.level ]) {
  77. ctx.query._id = this.app.mongoose.Types.ObjectId(user[ 'dept' + query.level ]._id);
  78. }
  79. }
  80. const result = await this.tag()
  81. .list(query);
  82. ctx.success(result);
  83. }
  84. async listForPageSortWithUser() {
  85. const { ctx, service } = this;
  86. const query = ctx.query;
  87. const user = ctx.user;
  88. query.deptId = user.dept._id;
  89. query.level = user.dept.level;
  90. query.roleId = user.role._id;
  91. ctx.setOrder();
  92. const result = await service.sysDeptService.listForPageSortWithUser(query);
  93. ctx.success(result);
  94. }
  95. async orderChange() {
  96. const { ctx, service } = this;
  97. const query = ctx.query;
  98. const { id, type } = query;
  99. const result = await service.sysDeptService.orderChange(id, type);
  100. if (result) {
  101. ctx.error(result);
  102. } else {
  103. ctx.success();
  104. }
  105. }
  106. async findLink() {
  107. const { ctx, service } = this;
  108. const query = ctx.query;
  109. const result = await service.sysDeptService.findLink(query);
  110. ctx.logic(result);
  111. }
  112. }
  113. module.exports = SysDeptController;