user.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import BaseController from '../../base';
  2. import { AdminRoute } from '../../../decorator/router_register';
  3. import { CreateUserDto, InfoUserDto, DeleteUserDto, QueryUserDto, UpdateUserDto } from '../../../dto/admin/sys/user';
  4. export default class SysUserController extends BaseController {
  5. /**
  6. * @api {post} /admin/sys/user/add 新增系统用户
  7. * @apiGroup 系统用户
  8. * @apiUse Auth
  9. * @apiUse BaseRes
  10. * @apiUse Page
  11. * @apiParam {Number} departmentId 部门编号
  12. * @apiParam {String} name 管理员名称
  13. * @apiParam {String} username 用户名
  14. * @apiParam {String} nickName 别名
  15. * @apiParam {Number[]} roles 关联角色编号列表,最多三个
  16. * @apiParam {String} remark 用户备注
  17. * @apiParam {String} email 邮箱
  18. * @apiParam {String} phone 手机
  19. * @apiParam {Number} status 状态
  20. */
  21. @AdminRoute('/sys/user/add', 'post')
  22. async add() {
  23. const dto = await this.ctx.validate<CreateUserDto>(CreateUserDto);
  24. const result = await this.service.admin.sys.user.add(dto);
  25. if (result) {
  26. this.res();
  27. } else {
  28. this.res({ code: 10001 });
  29. }
  30. }
  31. /**
  32. * @api {post} /admin/sys/user/info 获取系统用户信息
  33. * @apiGroup 系统用户
  34. * @apiUse Auth
  35. * @apiUse BaseRes
  36. * @apiUse Page
  37. * @apiParam {Number} id 用户编号
  38. * @apiSuccess {SysUser} data 用户列表
  39. */
  40. @AdminRoute('/sys/user/info', 'get')
  41. async info() {
  42. const dto = await this.ctx.validate<InfoUserDto>(InfoUserDto, this.getQuery());
  43. const user = await this.service.admin.sys.user.info(parseInt(dto.userId));
  44. this.res({
  45. data: user,
  46. });
  47. }
  48. /**
  49. * @api {post} /admin/sys/user/delete 删除用户列表
  50. * @apiGroup 系统用户
  51. * @apiUse Auth
  52. * @apiUse BaseRes
  53. * @apiUse Page
  54. * @apiParam {Number[]} userIds 用户编号列表
  55. * @apiSuccess {SysUser} data 用户列表
  56. */
  57. @AdminRoute('/sys/user/delete', 'post')
  58. async delete() {
  59. const dto = await this.ctx.validate<DeleteUserDto>(DeleteUserDto);
  60. await this.service.admin.sys.user.delete(dto.userIds);
  61. await this.service.admin.sys.user.multiForbidden(dto.userIds);
  62. this.res();
  63. }
  64. /**
  65. * @api {get} /admin/sys/user/page 获取系统用户列表
  66. * @apiGroup 系统用户
  67. * @apiUse Auth
  68. * @apiUse BaseRes
  69. * @apiUse Page
  70. * @apiParam {Number} departmentId 部门编号
  71. * @apiSuccess {SysUser[]} data.list 用户列表
  72. */
  73. @AdminRoute('/sys/user/page', 'get')
  74. async page() {
  75. // console.log(this.getQuery(), this.getParams(), this.getBody());
  76. const dto = await this.ctx.validate<QueryUserDto>(QueryUserDto, this.getQuery());
  77. // dto.departmentId=-1;
  78. this.res({
  79. data: {
  80. list: await this.service.admin.sys.user.page(this.ctx.token.uid, -1, dto.current - 1, dto.pageSize),
  81. pagination: {
  82. total: await this.service.admin.sys.user.count(this.ctx.token.uid, -1),
  83. page: dto.current,
  84. size: dto.pageSize,
  85. },
  86. },
  87. });
  88. }
  89. /**
  90. * @api {post} /admin/sys/user/update 更新系统用户信息
  91. * @apiGroup 系统用户
  92. * @apiUse Auth
  93. * @apiUse BaseRes
  94. * @apiUse Page
  95. * @apiParam {Number} departmentId 部门编号
  96. * @apiParam {String} name 管理员名称
  97. * @apiParam {String} username 用户名
  98. * @apiParam {String} nickName 别名
  99. * @apiParam {Number[]} roles 关联角色编号列表,最多三个
  100. * @apiParam {String} remark 用户备注
  101. * @apiParam {String} email 邮箱
  102. * @apiParam {String} phone 手机
  103. * @apiParam {Number} status 状态
  104. * @apiParam {Number} id 用户编号
  105. */
  106. @AdminRoute('/sys/user/update', 'post')
  107. async update() {
  108. const dto = await this.ctx.validate<UpdateUserDto>(UpdateUserDto);
  109. await this.service.admin.sys.user.update(dto);
  110. await this.service.admin.sys.menu.refreshPerms(dto.id);
  111. this.res();
  112. }
  113. }