|
@@ -16,6 +16,7 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
+import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Sort;
|
|
@@ -37,23 +38,14 @@ import java.util.List;
|
|
|
@RestController
|
|
|
@RequestMapping("api/manage/role")
|
|
|
@Transactional
|
|
|
-//@RequiresRoles("admin") //需要admin角色才可以访问此controller
|
|
|
+@RequiresRoles("admin") //需要admin角色才可以访问此controller
|
|
|
public class RoleController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private RoleService roleService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private RoleRepository roleRepository;
|
|
|
-
|
|
|
- @WebControllerLog(description = "角色权限-查询列表")
|
|
|
+ @WebControllerLog(description = "角色权限-查询列表")
|
|
|
@ApiOperation("分页获取角色列表/搜索")
|
|
|
-// @PostMapping("list")
|
|
|
-// public ResultJson list(@RequestBody RoleRequest param){
|
|
|
-// PageInfo<RoleEntity> pageInfo = roleService.findAll(param.getPageNum(), param.getPageSize());
|
|
|
-// return new ResultJson(MsgCode.SUCCESS_CODE, pageInfo);
|
|
|
-// }
|
|
|
-
|
|
|
@PostMapping("list")
|
|
|
public ResultJson list(@RequestBody PageDto param){
|
|
|
Condition condition = new Condition(RoleEntity.class);
|
|
@@ -63,7 +55,7 @@ public class RoleController extends BaseController {
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, pageInfo);
|
|
|
}
|
|
|
|
|
|
-// @RequiresRoles("admin")
|
|
|
+
|
|
|
@ApiOperation("获取角色")
|
|
|
@GetMapping("find")
|
|
|
public ResultJson find(){
|
|
@@ -71,64 +63,8 @@ public class RoleController extends BaseController {
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, result);
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("新增或修改角色信息")
|
|
|
- @PostMapping("save")
|
|
|
- public ResultJson save(@RequestBody RoleRequest param){
|
|
|
-// RoleEntity roleEntity = null;
|
|
|
-// int n = 0;
|
|
|
-// if (param.getId() != null) {
|
|
|
-// roleEntity = roleService.findById(param.getId());
|
|
|
-// if(roleEntity == null){
|
|
|
-// return new ResultJson(MsgCode.FAILURE_CODE_6001, MsgCode.FAILURE_MSG_6001);
|
|
|
-// }
|
|
|
-// // 每次修改,删除角色资源表信息,重新添加
|
|
|
-// roleService.deleteRoleResource(param.getId());
|
|
|
-//
|
|
|
-// BeanUtils.copyProperties(param, roleEntity);
|
|
|
-// n = roleService.update(roleEntity);
|
|
|
-// }else {
|
|
|
-// roleEntity = new RoleEntity();
|
|
|
-//
|
|
|
-// BeanUtils.copyProperties(param, roleEntity);
|
|
|
-// roleEntity.setUpdateTime(new Date());
|
|
|
-//
|
|
|
-//
|
|
|
-// n = roleService.save(roleEntity);
|
|
|
-// }
|
|
|
-
|
|
|
- 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("detail/{id}")
|
|
@@ -137,13 +73,6 @@ public class RoleController extends BaseController {
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, roleEntity);
|
|
|
}
|
|
|
|
|
|
- @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);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 测试权限用
|
|
@@ -173,6 +102,52 @@ 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);
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
|
|
|
|