sysDeptController.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. 'use strict';
  2. const Controller = require('../extend/baseController');
  3. const moment = require('moment/moment');
  4. class SysDeptController extends Controller {
  5. tag() {
  6. return this.ctx.service.sysDeptService;
  7. }
  8. async addDeptAndPerson() {
  9. const { ctx } = this;
  10. const query = ctx.request.body;
  11. delete query._id;
  12. const result = await this.tag()
  13. .addDeptAndPerson(query);
  14. if (result) {
  15. ctx.error(result);
  16. } else {
  17. ctx.success();
  18. }
  19. }
  20. async updateDeptAndPerson() {
  21. const { ctx, service } = this;
  22. const query = ctx.request.body;
  23. const { id } = query;
  24. delete query.id;
  25. const result = await service.sysDeptService.updateDeptAndPerson(id, query);
  26. if (result) {
  27. ctx.error(result);
  28. } else {
  29. ctx.success();
  30. }
  31. }
  32. // 数据迁移
  33. async dataMigration() {
  34. const { ctx, service } = this;
  35. const query = ctx.request.body;
  36. const { id } = query;
  37. delete query.id;
  38. const result = await service.sysDeptService.dataMigration(id, query);
  39. if (result) {
  40. ctx.error(result);
  41. } else {
  42. ctx.success();
  43. }
  44. }
  45. // 迁移数据查询
  46. async listDept() {
  47. const { ctx } = this;
  48. ctx.setOrder();
  49. const result = await this.tag().listDept(ctx.query);
  50. ctx.success(result);
  51. }
  52. async deleteWithSub() {
  53. const { ctx } = this;
  54. const query = ctx.query;
  55. const { id } = query;
  56. const result = await this.tag()
  57. .deleteWithSub(id);
  58. if (result) {
  59. ctx.error(result);
  60. } else {
  61. ctx.success();
  62. }
  63. }
  64. async listSortAsc() {
  65. const { ctx } = this;
  66. ctx.setOrder();
  67. const result = await this.tag()
  68. .list(ctx.query);
  69. ctx.success(result);
  70. }
  71. async listSortAscWithUser() {
  72. const { ctx } = this;
  73. const query = ctx.query;
  74. const user = ctx.user;
  75. ctx.setOrder();
  76. if (user.role._id != this.app.config.defaultAdminRoleId) {
  77. if (user[ 'dept' + query.level ]) {
  78. ctx.query._id = this.app.mongoose.Types.ObjectId(user[ 'dept' + query.level ]._id);
  79. }
  80. }
  81. const result = await this.tag()
  82. .list(query);
  83. ctx.success(result);
  84. }
  85. async listForPageSortWithUser() {
  86. const { ctx, service } = this;
  87. const query = ctx.query;
  88. const user = ctx.user;
  89. query.deptId = user.dept._id;
  90. query.level = user.dept.level;
  91. query.roleId = user.role._id;
  92. ctx.setOrder();
  93. const result = await service.sysDeptService.listForPageSortWithUser(query);
  94. ctx.success(result);
  95. }
  96. async orderChange() {
  97. const { ctx, service } = this;
  98. const query = ctx.query;
  99. const { id, type } = query;
  100. const result = await service.sysDeptService.orderChange(id, type);
  101. if (result) {
  102. ctx.error(result);
  103. } else {
  104. ctx.success();
  105. }
  106. }
  107. async findLink() {
  108. const { ctx, service } = this;
  109. const query = ctx.query;
  110. const result = await service.sysDeptService.findLink(query);
  111. ctx.logic(result);
  112. }
  113. async managerPayByDept5() {
  114. const { ctx } = this;
  115. const { model } = this.ctx;
  116. const query = ctx.request.body;
  117. if (!query.useDay) {
  118. ctx.error('请输入使用期限!');
  119. return;
  120. }
  121. const today = moment(Date.now()).format('YYYY-MM-DD');
  122. const nowTime = moment(Date.now()).format('YYYY-MM-DD HH:mm:ss');
  123. const afterTime = moment(Date.now()).add(query.useDay, 'day').format('YYYY-MM-DD HH:mm:ss');// 意思是10分钟以前
  124. const user = ctx.user;
  125. query.dept1 = user.dept1;
  126. query.dept2 = user.dept2;
  127. query.dept3 = user.dept3;
  128. query.dept4 = user.dept4;
  129. query.dept5 = user.dept5;
  130. query.userid = user._id;
  131. query.startTime = nowTime;
  132. query.endTime = afterTime;
  133. query.status = 1;
  134. if (user.role._id != this.app.config.defaultManagerRoleId) {
  135. ctx.error('当前系统仅支持社区/村级管理员享受服务,如有其他需求请联系管理员!');
  136. return;
  137. }
  138. const result = await model.SysDeptPayModel.create(query);
  139. ctx.success(result);
  140. }
  141. async managerPayByDept5List() {
  142. const { ctx } = this;
  143. const { model } = this.ctx;
  144. const query = ctx.request.body;
  145. const user = ctx.user;
  146. // query.userid = user._id;
  147. query.dept5 = user.dept5;
  148. query.status = 1;
  149. const result = await model.SysDeptPayModel.find(query).count();
  150. ctx.success(result);
  151. }
  152. }
  153. module.exports = SysDeptController;