|
@@ -2,13 +2,13 @@ package com.sf.admin.controller;
|
|
|
|
|
|
import com.sf.admin.dto.CommonResult;
|
|
import com.sf.admin.dto.CommonResult;
|
|
import com.sf.admin.entity.UmsRole;
|
|
import com.sf.admin.entity.UmsRole;
|
|
|
|
+import com.sf.admin.service.IUmsAdminRoleRelationService;
|
|
import com.sf.admin.service.IUmsRoleService;
|
|
import com.sf.admin.service.IUmsRoleService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -24,11 +24,36 @@ import java.util.List;
|
|
public class UmsRoleController {
|
|
public class UmsRoleController {
|
|
|
|
|
|
private final IUmsRoleService roleService;
|
|
private final IUmsRoleService roleService;
|
|
|
|
+ private final IUmsAdminRoleRelationService adminRoleRelationService;
|
|
|
|
|
|
|
|
+ // 角色列表
|
|
// http://localhost:8099/admin-api/role/listAll
|
|
// http://localhost:8099/admin-api/role/listAll
|
|
@GetMapping("/role/listAll")
|
|
@GetMapping("/role/listAll")
|
|
- public CommonResult<List<UmsRole>> listAll(){
|
|
|
|
|
|
+ public CommonResult<List<UmsRole>> listAll() {
|
|
List<UmsRole> umsRoles = roleService.list();
|
|
List<UmsRole> umsRoles = roleService.list();
|
|
return CommonResult.success(umsRoles);
|
|
return CommonResult.success(umsRoles);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 根据用户id获取角色
|
|
|
|
+ // http://localhost:8099/admin-api/admin/role/3
|
|
|
|
+ @GetMapping("/admin/role/{id}")
|
|
|
|
+ public CommonResult<List<UmsRole>> getRolesByAdminId(@PathVariable("id") Long adminId) {
|
|
|
|
+ List<UmsRole> roles = adminRoleRelationService.getRolesByUserId(adminId);
|
|
|
|
+ return CommonResult.success(roles);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 分配角色
|
|
|
|
+ // http://localhost:8099/admin-api/admin/role/update
|
|
|
|
+ @PostMapping("/admin/role/update")
|
|
|
|
+ public CommonResult updateRole(
|
|
|
|
+ @RequestParam("adminId") Long adminId, @RequestParam("roleIds") String roleIds) {
|
|
|
|
+ String[] roleIdArr = roleIds.split(",");
|
|
|
|
+ List<Long> roleIdList = Arrays.stream(roleIdArr).map(
|
|
|
|
+ roleId -> Long.parseLong(roleId)).toList();
|
|
|
|
+ // 将用户和多个角色相关联
|
|
|
|
+ adminRoleRelationService.updateRole(adminId, roleIdList);
|
|
|
|
+ return CommonResult.success(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|