|
@@ -7,9 +7,12 @@ import com.xiaoan.common.util.ResultJson;
|
|
import com.xiaoan.dao.backend.RoleRepository;
|
|
import com.xiaoan.dao.backend.RoleRepository;
|
|
import com.xiaoan.dao.backend.UserRepository;
|
|
import com.xiaoan.dao.backend.UserRepository;
|
|
import com.xiaoan.domain.backend.DepartmentEntity;
|
|
import com.xiaoan.domain.backend.DepartmentEntity;
|
|
|
|
+import com.xiaoan.domain.backend.ResourceEntity;
|
|
import com.xiaoan.domain.backend.RoleEntity;
|
|
import com.xiaoan.domain.backend.RoleEntity;
|
|
import com.xiaoan.domain.dto.request.RoleRequest;
|
|
import com.xiaoan.domain.dto.request.RoleRequest;
|
|
|
|
+import com.xiaoan.service.backend.ResourceService;
|
|
import com.xiaoan.service.backend.RoleService;
|
|
import com.xiaoan.service.backend.RoleService;
|
|
|
|
+import com.xiaoan.service.backend.dto.ResourceTree;
|
|
import com.xiaoan.web.aop.WebControllerLog;
|
|
import com.xiaoan.web.aop.WebControllerLog;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -26,6 +29,7 @@ import springfox.documentation.annotations.ApiIgnore;
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
import tk.mybatis.mapper.entity.Condition;
|
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@@ -38,13 +42,18 @@ import java.util.List;
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("api/manage/role")
|
|
@RequestMapping("api/manage/role")
|
|
@Transactional
|
|
@Transactional
|
|
-@RequiresRoles("admin") //需要admin角色才可以访问此controller
|
|
|
|
|
|
+//@RequiresRoles("admin") //需要admin角色才可以访问此controller
|
|
public class RoleController extends BaseController {
|
|
public class RoleController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private RoleService roleService;
|
|
private RoleService roleService;
|
|
|
|
|
|
- @WebControllerLog(description = "角色权限-查询列表")
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ResourceService resourceService;
|
|
|
|
+
|
|
|
|
+// @RequiresPermissions(logical = Logical.AND, value = {"view", "edit"})
|
|
|
|
+ @RequiresPermissions("admin:role:list")
|
|
|
|
+ @WebControllerLog(description = "角色权限-查询列表")
|
|
@ApiOperation("分页获取角色列表/搜索")
|
|
@ApiOperation("分页获取角色列表/搜索")
|
|
@PostMapping("list")
|
|
@PostMapping("list")
|
|
public ResultJson list(@RequestBody PageDto param){
|
|
public ResultJson list(@RequestBody PageDto param){
|
|
@@ -63,14 +72,29 @@ public class RoleController extends BaseController {
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, result);
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @ApiOperation("获取资源")
|
|
|
|
+ @GetMapping("find/resource")
|
|
|
|
+ public ResultJson findResource() throws Exception {
|
|
|
|
+ List<ResourceTree> listTree = resourceService.getTree();
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, listTree);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("查询角色信息")
|
|
@ApiOperation("查询角色信息")
|
|
@GetMapping("detail/{id}")
|
|
@GetMapping("detail/{id}")
|
|
- public ResultJson detail(@PathVariable Long id){
|
|
|
|
|
|
+ public ResultJson detail(@PathVariable Long id) throws Exception {
|
|
RoleEntity roleEntity = roleService.findById(id);
|
|
RoleEntity roleEntity = roleService.findById(id);
|
|
- return new ResultJson(MsgCode.SUCCESS_CODE, roleEntity);
|
|
|
|
|
|
+
|
|
|
|
+ HashMap<Object, Object> resultMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+ List<ResourceTree> permission = resourceService.getResourcesTreeByRolePermission(id);
|
|
|
|
+
|
|
|
|
+ resultMap.put("role", roleEntity);
|
|
|
|
+ resultMap.put("permission", permission);
|
|
|
|
+
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, resultMap);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -102,51 +126,63 @@ public class RoleController extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * 角色直接从数据库管理,因为前端不做资源管理,所以不提供新增、修改、删除,只提供查询
|
|
|
|
- */
|
|
|
|
-// @ApiOperation("新增或修改角色信息")
|
|
|
|
-// @PostMapping("save")
|
|
|
|
-// public ResultJson save(@RequestBody RoleRequest param){
|
|
|
|
-// RoleEntity roleEntity = roleService.findById(param.getId());
|
|
|
|
-//
|
|
|
|
-// int n = 0;
|
|
|
|
-//
|
|
|
|
-// if (roleEntity == null) {
|
|
|
|
-// roleEntity = new RoleEntity();
|
|
|
|
-// // 保存的时候,如果有id,会出错
|
|
|
|
-// param.setId(null);
|
|
|
|
-// BeanUtils.copyProperties(param, roleEntity);
|
|
|
|
-// n = roleService.save(roleEntity);
|
|
|
|
-//
|
|
|
|
-// } else {
|
|
|
|
-// BeanUtils.copyProperties(param, roleEntity);
|
|
|
|
-// roleEntity.setUpdateTime(new Date());
|
|
|
|
-// n = roleService.update(roleEntity);
|
|
|
|
-//
|
|
|
|
-// // 每次修改,删除角色资源表信息,重新添加
|
|
|
|
-// roleService.deleteRoleResource(param.getId());
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// if (n >= 0){
|
|
|
|
-// if (param.getResources() != null){
|
|
|
|
-// for (long i : param.getResources()) {
|
|
|
|
-// roleService.saveRoleResource(roleEntity.getId(), i);
|
|
|
|
-// }
|
|
|
|
-// return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// return new ResultJson(MsgCode.ERROR_CODE, MsgCode.ERROR_MSG);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// @ApiOperation("删除角色")
|
|
|
|
-// @GetMapping("delete/{id}")
|
|
|
|
-// public ResultJson delete(@PathVariable Long id){
|
|
|
|
-// roleService.deleteById(id);
|
|
|
|
-//// roleService.deleteRoleResource(id);
|
|
|
|
-// return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
|
|
+ @WebControllerLog(description = "角色权限-新增/修改")
|
|
|
|
+ @RequiresPermissions(value="admin:role:add")
|
|
|
|
+ @ApiOperation("新增或修改角色信息")
|
|
|
|
+ @PostMapping("save")
|
|
|
|
+ public ResultJson save(@RequestBody RoleRequest param){
|
|
|
|
+
|
|
|
|
+ RoleEntity roleEntity = null;
|
|
|
|
+ int n = 0;
|
|
|
|
+
|
|
|
|
+ if (param.getId() == null) {
|
|
|
|
+ roleEntity = new RoleEntity();
|
|
|
|
+ BeanUtils.copyProperties(param, roleEntity);
|
|
|
|
+ n = roleService.save(roleEntity);
|
|
|
|
+ } else {
|
|
|
|
+ roleEntity = roleService.findById(param.getId());
|
|
|
|
+ if (roleEntity == null) {
|
|
|
|
+ return new ResultJson(MsgCode.FAILURE_CODE_3002, MsgCode.FAILURE_MSG_3002);
|
|
|
|
+ }
|
|
|
|
+ BeanUtils.copyProperties(param, roleEntity);
|
|
|
|
+ roleEntity.setUpdateTime(new Date());
|
|
|
|
+ n = roleService.update(roleEntity);
|
|
|
|
+
|
|
|
|
+ // 每次修改,删除角色资源表信息,重新添加
|
|
|
|
+ roleService.deleteRoleResource(param.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加权限
|
|
|
|
+ if (n >= 0){
|
|
|
|
+ if (param.getResources() != null){
|
|
|
|
+ for (long i : param.getResources()) {
|
|
|
|
+ roleService.saveRoleResource(roleEntity.getId(), i);
|
|
|
|
+ }
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return new ResultJson(MsgCode.ERROR_CODE, MsgCode.ERROR_MSG);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @WebControllerLog(description = "角色权限-角色删除")
|
|
|
|
+ @RequiresPermissions("admin:role:remove")
|
|
|
|
+ @ApiOperation("删除角色")
|
|
|
|
+ @GetMapping("delete/{id}")
|
|
|
|
+ public ResultJson delete(@PathVariable Long id){
|
|
|
|
+ roleService.deleteById(id);
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @WebControllerLog(description = "角色权限-多角色删除")
|
|
|
|
+ @RequiresPermissions("admin:role:remove")
|
|
|
|
+ @ApiOperation("多角色删除")
|
|
|
|
+ @GetMapping("delete/all/{ids}")
|
|
|
|
+ public ResultJson delete(@PathVariable String ids){
|
|
|
|
+ roleService.deleteByIds(ids);
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|