TenantController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package edu.travel.tenant.web;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import edu.travel.resp.BaseResponse;
  6. import edu.travel.resp.PageResponse;
  7. import edu.travel.tenant.dto.AssignRolesOrMenus;
  8. import edu.travel.tenant.dto.EduTenantPageDto;
  9. import edu.travel.tenant.entity.EduTenant;
  10. import edu.travel.tenant.entity.SysMenu;
  11. import edu.travel.tenant.entity.SysRole;
  12. import edu.travel.tenant.service.ITenantService;
  13. import edu.travel.web.BaseController;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.security.core.context.SecurityContextHolder;
  16. import org.springframework.web.bind.annotation.*;
  17. import java.util.List;
  18. @RestController
  19. @RequestMapping("/tenant")
  20. public class TenantController extends BaseController<EduTenant> {
  21. @Autowired
  22. private ITenantService tenantService;
  23. @GetMapping("/getTenantByPhoneNumber")
  24. // @PreAuthorize("hasRole('超级管理员')")
  25. public BaseResponse<EduTenant> getTenantByPhoneNumber() {
  26. EduTenant principal = (EduTenant)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  27. EduTenant list = tenantService.getTenantByPhoneNumber(principal.getTenantPhone());
  28. return PageResponse.out(200,"success",list);
  29. }
  30. /**
  31. * 新增用户
  32. * @param tenant
  33. * @return
  34. */
  35. @PostMapping("/addTenant")
  36. // @PreAuthorize("hasRole('超级管理员')")
  37. public BaseResponse<Boolean> addTenant(EduTenant tenant) {
  38. tenantService.addTenant(tenant);
  39. return PageResponse.out(200,"success",true);
  40. }
  41. /**
  42. * 通过ids删除用户
  43. * @param ids
  44. * @return
  45. */
  46. @PostMapping("/deleteTenantByIds")
  47. // @PreAuthorize("hasRole('超级管理员')")
  48. public BaseResponse<Boolean> deleteTenant(List<Long> ids) {
  49. tenantService.deleteByIds(ids);
  50. return PageResponse.out(200,"success",true);
  51. }
  52. /**
  53. * 修改用户信息
  54. * @param tenant
  55. * @return
  56. */
  57. @PostMapping("/updateTenantById")
  58. // @PreAuthorize("hasRole('超级管理员')")
  59. public BaseResponse<Boolean> updateTenant(EduTenant tenant) {
  60. tenantService.updateTenant(tenant);
  61. return PageResponse.out(200,"success",true);
  62. }
  63. /**
  64. * 通过id查询用户信息
  65. * @param id
  66. * @return
  67. */
  68. @GetMapping("/getTenantById")
  69. // @PreAuthorize("hasRole('超级管理员')")
  70. public BaseResponse<EduTenant> getTenantById(Long id) {
  71. EduTenant tenant = tenantService.getTenantById(id);
  72. return PageResponse.out(200,"success",tenant);
  73. }
  74. /**
  75. * 获取用户分页列表
  76. * @param tenantDto
  77. * @return
  78. */
  79. @GetMapping("/getTenantPageList")
  80. // @PreAuthorize("hasRole('超级管理员')")
  81. public BaseResponse<List<EduTenant>> getTenantList(EduTenantPageDto tenantDto) {
  82. IPage<EduTenant> page = new Page<>(tenantDto.getPageNum(), tenantDto.getPageSize());
  83. IPage<EduTenant> tenantIPage = tenantService.page(page, new LambdaQueryWrapper<EduTenant>().eq(EduTenant::getDeleteFlag, 0));
  84. return PageResponse.out(200,"success",tenantIPage.getRecords(),(int)tenantIPage.getTotal(),(int)tenantIPage.getSize()) ;
  85. }
  86. /**
  87. * 根据用户id获取用户角色列表(未分页)
  88. * @return
  89. */
  90. @GetMapping("/getRoleListByUserId")
  91. // @PreAuthorize("hasRole('超级管理员')")
  92. public BaseResponse<List<SysRole>> getRoleListByUserId() {
  93. EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  94. List<SysRole> roleList = tenantService.getRoleListByUserId(principal);
  95. return PageResponse.out(200,"success",roleList);
  96. }
  97. /**
  98. * 根据用户id获取用户菜单列表(未分页)
  99. * @return
  100. */
  101. @GetMapping("/getMenuListByUserId")
  102. // @PreAuthorize("hasRole('超级管理员')")
  103. public BaseResponse<List<SysMenu>> getMenuList() {
  104. EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  105. List<SysMenu> menuList = tenantService.getMenuList(principal);
  106. return PageResponse.out(200,"success",menuList);
  107. }
  108. /**
  109. * 根据用户id给用户分配角色(可以多个角色)
  110. * @param assignRolesOrMenus
  111. * @return
  112. */
  113. @PostMapping("/assignRolesToUser")
  114. // @PreAuthorize("hasRole('超级管理员')")
  115. public BaseResponse<Boolean> assignRolesToUser(@RequestBody AssignRolesOrMenus assignRolesOrMenus) {
  116. EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  117. tenantService.assignRolesToUser(assignRolesOrMenus);
  118. return PageResponse.out(200,"success",true);
  119. }
  120. }