From d473652b8a9284b8598f24b95922bbd5b608874b Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Tue, 26 Aug 2025 21:34:34 +0800
Subject: [PATCH] Merge branch 'master' into xin
---
oying-system/src/main/java/com/oying/modules/system/rest/RoleController.java | 43 +++++++++++++++++++++++--------------------
1 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/oying-system/src/main/java/com/oying/modules/system/rest/RoleController.java b/oying-system/src/main/java/com/oying/modules/system/rest/RoleController.java
index fd62232..c002f31 100644
--- a/oying-system/src/main/java/com/oying/modules/system/rest/RoleController.java
+++ b/oying-system/src/main/java/com/oying/modules/system/rest/RoleController.java
@@ -3,6 +3,7 @@
import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.oying.modules.system.domain.Role;
+import com.oying.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -17,6 +18,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
+
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collections;
@@ -41,8 +43,8 @@
@ApiOperation("获取单个role")
@GetMapping(value = "/{id}")
@PreAuthorize("@el.check('roles:list')")
- public ResponseEntity<Role> findRoleById(@PathVariable Long id){
- return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
+ public ResponseEntity<Object> findRoleById(@PathVariable Long id) {
+ return new ResponseEntity<>(R.success(roleService.findById(id)), HttpStatus.OK);
}
@ApiOperation("导出角色数据")
@@ -55,63 +57,63 @@
@ApiOperation("返回全部的角色")
@GetMapping(value = "/all")
@PreAuthorize("@el.check('roles:list','user:add','user:edit')")
- public ResponseEntity<List<Role>> queryAllRole(){
- return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
+ public ResponseEntity<Object> queryAllRole() {
+ return new ResponseEntity<>(R.success(roleService.queryAll()), HttpStatus.OK);
}
@ApiOperation("查询角色")
@GetMapping
@PreAuthorize("@el.check('roles:list')")
- public ResponseEntity<PageResult<Role>> queryRole(RoleQueryCriteria criteria){
+ public ResponseEntity<Object> queryRole(RoleQueryCriteria criteria) {
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
- return new ResponseEntity<>(roleService.queryAll(criteria, page),HttpStatus.OK);
+ return new ResponseEntity<>(R.success(roleService.queryAll(criteria, page)), HttpStatus.OK);
}
@ApiOperation("获取用户级别")
@GetMapping(value = "/level")
- public ResponseEntity<Object> getRoleLevel(){
- return new ResponseEntity<>(Dict.create().set("level", getLevels(null)),HttpStatus.OK);
+ public ResponseEntity<Object> getRoleLevel() {
+ return new ResponseEntity<>(R.success(Dict.create().set("level", getLevels(null))), HttpStatus.OK);
}
@Log("新增角色")
@ApiOperation("新增角色")
@PostMapping
@PreAuthorize("@el.check('roles:add')")
- public ResponseEntity<Object> createRole(@Validated @RequestBody Role resources){
+ public ResponseEntity<Object> createRole(@Validated @RequestBody Role resources) {
if (resources.getId() != null) {
- throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
+ throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID");
}
getLevels(resources.getLevel());
roleService.create(resources);
- return new ResponseEntity<>(HttpStatus.CREATED);
+ return new ResponseEntity<>(R.success(), HttpStatus.CREATED);
}
@Log("修改角色")
@ApiOperation("修改角色")
@PutMapping
@PreAuthorize("@el.check('roles:edit')")
- public ResponseEntity<Object> updateRole(@Validated(Role.Update.class) @RequestBody Role resources){
+ public ResponseEntity<Object> updateRole(@Validated(Role.Update.class) @RequestBody Role resources) {
getLevels(resources.getLevel());
roleService.update(resources);
- return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT);
}
@Log("修改角色菜单")
@ApiOperation("修改角色菜单")
@PutMapping(value = "/menu")
@PreAuthorize("@el.check('roles:edit')")
- public ResponseEntity<Object> updateRoleMenu(@RequestBody Role resources){
+ public ResponseEntity<Object> updateRoleMenu(@RequestBody Role resources) {
Role role = roleService.getById(resources.getId());
getLevels(role.getLevel());
roleService.updateMenu(resources);
- return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT);
}
@Log("删除角色")
@ApiOperation("删除角色")
@DeleteMapping
@PreAuthorize("@el.check('roles:del')")
- public ResponseEntity<Object> deleteRole(@RequestBody Set<Long> ids){
+ public ResponseEntity<Object> deleteRole(@RequestBody Set<Long> ids) {
for (Long id : ids) {
Role role = roleService.getById(id);
getLevels(role.getLevel());
@@ -119,18 +121,19 @@
// 验证是否被用户关联
roleService.verification(ids);
roleService.delete(ids);
- return new ResponseEntity<>(HttpStatus.OK);
+ return new ResponseEntity<>(R.success(), HttpStatus.OK);
}
/**
* 获取用户的角色级别
+ *
* @return /
*/
- private int getLevels(Integer level){
+ private int getLevels(Integer level) {
List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(Role::getLevel).collect(Collectors.toList());
int min = Collections.min(levels);
- if(level != null){
- if(level < min){
+ if (level != null) {
+ if (level < min) {
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
}
}
--
Gitblit v1.9.3