|
@@ -18,6 +18,8 @@ import edu.travel.resp.PageResponse;
|
|
|
import edu.travel.tenant.TenantRemoteController;
|
|
|
import edu.travel.tenant.entity.EduTenant;
|
|
|
import edu.travel.tenant.entity.SysRole;
|
|
|
+import edu.travel.tenant.entity.SysUserRole;
|
|
|
+import edu.travel.tenant.service.ISysUserRoleService;
|
|
|
import edu.travel.tenant.service.ITenantService;
|
|
|
import edu.travel.web.BaseController;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,15 +28,18 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/user")
|
|
|
-public class TenantController extends BaseController<EduTenant> implements TenantRemoteController {
|
|
|
+public class TenantController extends BaseController<EduTenant> {
|
|
|
@Autowired
|
|
|
private ITenantService tenantService;
|
|
|
+ @Autowired
|
|
|
+ private ISysUserRoleService sysUserRoleService;
|
|
|
|
|
|
@GetMapping("/getTenantByPhoneNumber")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<EduTenantVo> getTenantByPhoneNumber() {
|
|
|
EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
EduTenant tenant = tenantService.getTenantByPhoneNumber(principal.getTenantPhone());
|
|
@@ -49,7 +54,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/addTenant")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<EduTenantVo> addTenant(@RequestBody AddOrUpdateTenantDto addOrUpdateTenantDto) {
|
|
|
EduTenant eduTenant = tenantService.addTenant(addOrUpdateTenantDto);
|
|
|
return PageResponse.out(200, "success", BeanUtil.copyProperties(eduTenant, EduTenantVo.class));
|
|
@@ -62,7 +67,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/deleteTenantByIds")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> deleteTenant(@RequestBody List<Long> ids) {
|
|
|
// List<Long> list = ids.get("ids");
|
|
|
HashSet<Long> set = new HashSet<>(ids);
|
|
@@ -77,7 +82,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/deleteTenantById")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> deleteTenant(Long id) {
|
|
|
Set<Long> list = new HashSet<>();
|
|
|
list.add(id);
|
|
@@ -92,7 +97,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/updateTenantById")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> updateTenant(@RequestBody AddOrUpdateTenantDto addOrUpdateTenantDto) {
|
|
|
tenantService.updateTenant(addOrUpdateTenantDto);
|
|
|
return PageResponse.out(200, "success", true);
|
|
@@ -105,7 +110,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/getTenantById")
|
|
|
-// @PreAuthorize("hasRole('超级管理员')")
|
|
|
+//// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<EduTenantVo> getTenantById(Long id) {
|
|
|
EduTenant tenant = tenantService.getTenantById(id);
|
|
|
EduTenantVo eduTenantVo = BeanUtil.copyProperties(tenant, EduTenantVo.class);
|
|
@@ -118,7 +123,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/getLoginTenantInfo")
|
|
|
-// @PreAuthorize("hasRole('超级管理员')")
|
|
|
+//// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<EduTenantVo> getLoginTenantInfo() {
|
|
|
EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
EduTenant tenant = tenantService.getTenantById(principal.getId());
|
|
@@ -134,8 +139,8 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/getTenantPageList")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
- public BaseResponse<List<EduTenantVo>> getTenantList(EduTenantPageDto tenantDto) {
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
+ public BaseResponse<List<EduTenantVo>> getTenantList( EduTenantPageDto tenantDto) {
|
|
|
|
|
|
IPage<EduTenant> page = new Page<>(tenantDto.getPageNum(), tenantDto.getPageSize());
|
|
|
|
|
@@ -144,8 +149,21 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
.eq(tenantDto.getId() != null, EduTenant::getId, tenantDto.getId())
|
|
|
.like(tenantDto.getTenantName() != null && !tenantDto.getTenantName().isEmpty(), EduTenant::getTenantName, tenantDto.getTenantName());
|
|
|
IPage<EduTenant> tenantIPage = tenantService.dictMapPage(page, queryWrapper);
|
|
|
-
|
|
|
List<EduTenantVo> eduTenantVos = BeanUtil.copyToList(tenantIPage.getRecords(), EduTenantVo.class);
|
|
|
+ List<String> userIds = eduTenantVos.stream().map(EduTenantVo::getId).collect(Collectors.toList());
|
|
|
+ List<SysUserRole> roleList = sysUserRoleService.list(new LambdaQueryWrapper<SysUserRole>()
|
|
|
+ .in(SysUserRole::getUserId, userIds));
|
|
|
+ Map<Long, List<Long>> userRolesMap = roleList.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ SysUserRole::getUserId,
|
|
|
+ Collectors.mapping(SysUserRole::getRoleId, Collectors.toList())
|
|
|
+ ));
|
|
|
+ eduTenantVos.forEach(eduTenantVo -> {
|
|
|
+ List<Long> roleIds = userRolesMap.get(eduTenantVo.getId());
|
|
|
+ if (roleIds != null) {
|
|
|
+ eduTenantVo.setRoleIdList(roleIds);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
return PageResponse.out(200, "success", eduTenantVos, (int) tenantIPage.getTotal(), (int) tenantIPage.getSize());
|
|
|
}
|
|
@@ -156,7 +174,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/getRoleListByUserId")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<List<SysRoleVo>> getRoleListByUserId() {
|
|
|
EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
List<SysRole> roleList = tenantService.getRoleListByUserId(principal);
|
|
@@ -171,7 +189,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/assignRolesToUser")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> assignRolesToUser(@RequestBody AssignRolesOrMenusDto assignRolesOrMenusDto) {
|
|
|
EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
tenantService.assignRolesToUser(assignRolesOrMenusDto, principal);
|
|
@@ -185,7 +203,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("updateRolesToUser")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> updateRolesToUser(@RequestBody AssignRolesOrMenusDto assignRolesOrMenusDto) {
|
|
|
EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
tenantService.updateRolesToUser(assignRolesOrMenusDto, principal);
|
|
@@ -198,7 +216,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/getTenantInfoRoleListMenuTree")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<AdminInfoRoleMenuVo> getTenantInfoRoleListMenuTree() {
|
|
|
EduTenant principal = (EduTenant) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
EduTenant tenant = tenantService.getTenantById(principal.getId());
|
|
@@ -220,7 +238,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/disableTenantById")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> disableTenantById(Long id) {
|
|
|
Assert.isTrue(ObjectUtil.isNotEmpty(id), "请选择用户");
|
|
|
Set<Long> list = new HashSet<>();
|
|
@@ -236,7 +254,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/enableTenantById")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> enableTenantById(Long id) {
|
|
|
Assert.isTrue(ObjectUtil.isNotEmpty(id), "请选择用户");
|
|
|
Set<Long> list = new HashSet<>();
|
|
@@ -252,7 +270,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/enableTenantByIds")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> enableTenantByIds(@RequestBody List<Long> ids) {
|
|
|
tenantService.enableTenantByIds(new HashSet<>(ids));
|
|
|
return PageResponse.out(200, "success", true);
|
|
@@ -265,7 +283,7 @@ public class TenantController extends BaseController<EduTenant> implements Tena
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/disableTenantByIds")
|
|
|
- @PreAuthorize("hasRole('超级管理员')")
|
|
|
+// @PreAuthorize("hasRole('超级管理员')")
|
|
|
public BaseResponse<Boolean> disableTenantByIds(@RequestBody List<Long> ids) {
|
|
|
tenantService.disableTenantByIds(new HashSet<>(ids));
|
|
|
return PageResponse.out(200, "success", true);
|