6 changed files with 554 additions and 23 deletions
-
100system/src/main/java/com/storeroom/modules/system/controller/DeptController.java
-
81system/src/main/java/com/storeroom/modules/system/controller/DictController.java
-
83system/src/main/java/com/storeroom/modules/system/controller/DictDetailController.java
-
129system/src/main/java/com/storeroom/modules/system/controller/MenuController.java
-
138system/src/main/java/com/storeroom/modules/system/controller/RoleController.java
-
46system/src/main/java/com/storeroom/modules/system/controller/UserController.java
@ -0,0 +1,100 @@ |
|||||
|
package com.storeroom.modules.system.controller; |
||||
|
|
||||
|
|
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.exception.constant.ResponseStatus; |
||||
|
import com.storeroom.modules.system.domain.Dept; |
||||
|
import com.storeroom.modules.system.service.DeptService; |
||||
|
import com.storeroom.modules.system.service.dto.DeptDto; |
||||
|
import com.storeroom.modules.system.service.dto.DeptQueryCriteria; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import com.storeroom.utils.PageUtil; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
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.util.*; |
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "系统:部门管理") |
||||
|
@RequestMapping("/api/dept") |
||||
|
public class DeptController { |
||||
|
|
||||
|
private final DeptService deptService; |
||||
|
private static final String ENTITY_NAME = "dept"; |
||||
|
|
||||
|
@ApiOperation("导出部门数据") |
||||
|
@GetMapping(value = "/download") |
||||
|
//@PreAuthorize("@el.check('dept:list')") |
||||
|
public void exportDept(HttpServletResponse response, DeptQueryCriteria criteria) throws Exception { |
||||
|
deptService.download(deptService.queryAll(criteria, false), response); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询部门") |
||||
|
@GetMapping |
||||
|
//@PreAuthorize("@el.check('user:list','dept:list')") |
||||
|
public ApiResponse<Object> queryDept(DeptQueryCriteria criteria) throws Exception { |
||||
|
List<DeptDto> deptDtos = deptService.queryAll(criteria, true); |
||||
|
return ApiResponse.success(PageUtil.toPage(deptDtos, deptDtos.size())); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询部门:根据ID获取同级与上级数据") |
||||
|
@PostMapping("/superior") |
||||
|
//@PreAuthorize("@el.check('user:list','dept:list')") |
||||
|
public ApiResponse<Object> getDeptSuperior(@RequestBody List<Long> ids) { |
||||
|
Set<DeptDto> deptDtos = new LinkedHashSet<>(); |
||||
|
for (Long id : ids) { |
||||
|
DeptDto deptDto = deptService.findById(id); |
||||
|
List<DeptDto> depts = deptService.getSuperior(deptDto, new ArrayList<>()); |
||||
|
deptDtos.addAll(depts); |
||||
|
} |
||||
|
return ApiResponse.success(deptService.buildTree(new ArrayList<>(deptDtos))); |
||||
|
} |
||||
|
|
||||
|
//@Log("新增部门") |
||||
|
@ApiOperation("新增部门") |
||||
|
@PostMapping |
||||
|
//@PreAuthorize("@el.check('dept:add')") |
||||
|
public ApiResponse<Object> createDept(@Validated @RequestBody Dept resources){ |
||||
|
if (resources.getId() != null) { |
||||
|
throw new BaseException("A new "+ ENTITY_NAME +" cannot already have an ID"); |
||||
|
} |
||||
|
deptService.create(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
//@Log("修改部门") |
||||
|
@ApiOperation("修改部门") |
||||
|
@PutMapping |
||||
|
//@PreAuthorize("@el.check('dept:edit')") |
||||
|
public ApiResponse<Object> updateDept(@Validated(Dept.Update.class) @RequestBody Dept resources){ |
||||
|
deptService.update(resources); |
||||
|
return ApiResponse.success(HttpStatus.NO_CONTENT); |
||||
|
} |
||||
|
|
||||
|
//@Log("删除部门") |
||||
|
@ApiOperation("删除部门") |
||||
|
@DeleteMapping |
||||
|
//@PreAuthorize("@el.check('dept:del')") |
||||
|
public ApiResponse<Object> deleteDept(@RequestBody Set<Long> ids){ |
||||
|
Set<DeptDto> deptDtos = new HashSet<>(); |
||||
|
for (Long id : ids) { |
||||
|
List<Dept> deptList = deptService.findByPid(id); |
||||
|
deptDtos.add(deptService.findById(id)); |
||||
|
if(CollectionUtil.isNotEmpty(deptList)){ |
||||
|
deptDtos = deptService.getDeleteDepts(deptList, deptDtos); |
||||
|
} |
||||
|
} |
||||
|
// 验证是否被角色或用户关联 |
||||
|
deptService.verification(deptDtos); |
||||
|
deptService.delete(deptDtos); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
} |
@ -0,0 +1,81 @@ |
|||||
|
package com.storeroom.modules.system.controller; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.exception.constant.ResponseStatus; |
||||
|
import com.storeroom.modules.system.domain.Dict; |
||||
|
import com.storeroom.modules.system.service.DictService; |
||||
|
import com.storeroom.modules.system.service.dto.DictQueryCriteria; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
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.Set; |
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "系统:字典管理") |
||||
|
@RequestMapping("/api/dict") |
||||
|
public class DictController { |
||||
|
|
||||
|
private final DictService dictService; |
||||
|
private static final String ENTITY_NAME = "dict"; |
||||
|
|
||||
|
@ApiOperation("导出字典数据") |
||||
|
@GetMapping(value = "/download") |
||||
|
//@PreAuthorize("@el.check('dict:list')") |
||||
|
public void exportDict(HttpServletResponse response, DictQueryCriteria criteria) throws IOException { |
||||
|
dictService.download(dictService.queryAll(criteria), response); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询字典") |
||||
|
@GetMapping(value = "/all") |
||||
|
//@PreAuthorize("@el.check('dict:list')") |
||||
|
public ApiResponse<Object> queryAllDict(){ |
||||
|
return ApiResponse.success(dictService.queryAll(new DictQueryCriteria())); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询字典") |
||||
|
@GetMapping |
||||
|
//@PreAuthorize("@el.check('dict:list')") |
||||
|
public ApiResponse<Object> queryDict(DictQueryCriteria resources, Pageable pageable){ |
||||
|
return ApiResponse.success(dictService.queryAll(resources,pageable)); |
||||
|
} |
||||
|
|
||||
|
//@Log("新增字典") |
||||
|
@ApiOperation("新增字典") |
||||
|
@PostMapping |
||||
|
//@PreAuthorize("@el.check('dict:add')") |
||||
|
public ApiResponse<Object> createDict(@Validated @RequestBody Dict resources){ |
||||
|
if (resources.getId() != null) { |
||||
|
throw new BaseException("A new "+ ENTITY_NAME +" cannot already have an ID"); |
||||
|
} |
||||
|
dictService.create(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
//@Log("修改字典") |
||||
|
@ApiOperation("修改字典") |
||||
|
@PutMapping |
||||
|
//@PreAuthorize("@el.check('dict:edit')") |
||||
|
public ApiResponse<Object> updateDict(@Validated(Dict.Update.class) @RequestBody Dict resources){ |
||||
|
dictService.update(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
//@Log("删除字典") |
||||
|
@ApiOperation("删除字典") |
||||
|
@DeleteMapping |
||||
|
//@PreAuthorize("@el.check('dict:del')") |
||||
|
public ApiResponse<Object> deleteDict(@RequestBody Set<Long> ids){ |
||||
|
dictService.delete(ids); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
package com.storeroom.modules.system.controller; |
||||
|
|
||||
|
|
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.exception.constant.ResponseStatus; |
||||
|
import com.storeroom.modules.system.domain.DictDetail; |
||||
|
import com.storeroom.modules.system.service.DictDetailService; |
||||
|
import com.storeroom.modules.system.service.dto.DictDetailDto; |
||||
|
import com.storeroom.modules.system.service.dto.DictDetailQueryCriteria; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.data.domain.Sort; |
||||
|
import org.springframework.data.web.PageableDefault; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
import org.springframework.http.ResponseEntity; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "系统:字典详情管理") |
||||
|
@RequestMapping("/api/dictDetail") |
||||
|
public class DictDetailController { |
||||
|
|
||||
|
private final DictDetailService dictDetailService; |
||||
|
private static final String ENTITY_NAME = "dictDetail"; |
||||
|
|
||||
|
@ApiOperation("查询字典详情") |
||||
|
@GetMapping |
||||
|
public ResponseEntity<Object> queryDictDetail(DictDetailQueryCriteria criteria, |
||||
|
@PageableDefault(sort = {"dictSort"}, direction = Sort.Direction.ASC) Pageable pageable){ |
||||
|
return new ResponseEntity<>(dictDetailService.queryAll(criteria,pageable), HttpStatus.OK); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询多个字典详情") |
||||
|
@GetMapping(value = "/map") |
||||
|
public ResponseEntity<Object> getDictDetailMaps(@RequestParam String dictName){ |
||||
|
String[] names = dictName.split("[,,]"); |
||||
|
Map<String, List<DictDetailDto>> dictMap = new HashMap<>(16); |
||||
|
for (String name : names) { |
||||
|
dictMap.put(name, dictDetailService.getDictByName(name)); |
||||
|
} |
||||
|
return new ResponseEntity<>(dictMap, HttpStatus.OK); |
||||
|
} |
||||
|
|
||||
|
// @Log("新增字典详情") |
||||
|
@ApiOperation("新增字典详情") |
||||
|
@PostMapping |
||||
|
//@PreAuthorize("@el.check('dict:add')") |
||||
|
public ApiResponse<Object> createDictDetail(@Validated @RequestBody DictDetail resources){ |
||||
|
if (resources.getId() != null) { |
||||
|
throw new BaseException("A new "+ ENTITY_NAME +" cannot already have an ID"); |
||||
|
} |
||||
|
dictDetailService.create(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
//@Log("修改字典详情") |
||||
|
@ApiOperation("修改字典详情") |
||||
|
@PutMapping |
||||
|
//@PreAuthorize("@el.check('dict:edit')") |
||||
|
public ApiResponse<Object> updateDictDetail(@Validated(DictDetail.Update.class) @RequestBody DictDetail resources){ |
||||
|
dictDetailService.update(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
// @Log("删除字典详情") |
||||
|
@ApiOperation("删除字典详情") |
||||
|
@DeleteMapping(value = "/{id}") |
||||
|
// @PreAuthorize("@el.check('dict:del')") |
||||
|
public ApiResponse<Object> deleteDictDetail(@PathVariable Long id){ |
||||
|
dictDetailService.delete(id); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
} |
@ -0,0 +1,129 @@ |
|||||
|
package com.storeroom.modules.system.controller; |
||||
|
|
||||
|
|
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.exception.constant.ResponseStatus; |
||||
|
import com.storeroom.modules.system.domain.Menu; |
||||
|
import com.storeroom.modules.system.service.MenuService; |
||||
|
import com.storeroom.modules.system.service.dto.MenuDto; |
||||
|
import com.storeroom.modules.system.service.dto.MenuQueryCriteria; |
||||
|
import com.storeroom.modules.system.service.mapstruct.MenuMapper; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import com.storeroom.utils.PageUtil; |
||||
|
import com.storeroom.utils.SecurityUtils; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
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.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "系统:菜单管理") |
||||
|
@RequestMapping("/api/menus") |
||||
|
public class MenuController { |
||||
|
|
||||
|
private final MenuService menuService; |
||||
|
private final MenuMapper menuMapper; |
||||
|
private static final String ENTITY_NAME = "menu"; |
||||
|
|
||||
|
@ApiOperation("导出菜单数据") |
||||
|
@GetMapping(value = "/download") |
||||
|
//@PreAuthorize("@el.check('menu:list')") |
||||
|
public void exportMenu(HttpServletResponse response, MenuQueryCriteria criteria) throws Exception { |
||||
|
menuService.download(menuService.queryAll(criteria, false), response); |
||||
|
} |
||||
|
|
||||
|
@GetMapping(value = "/build") |
||||
|
@ApiOperation("获取前端所需菜单") |
||||
|
public ApiResponse<Object> buildMenus(){ |
||||
|
List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId()); |
||||
|
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList); |
||||
|
return ApiResponse.success(menuService.buildMenus(menuDtos)); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("返回全部的菜单") |
||||
|
@GetMapping(value = "/lazy") |
||||
|
//@PreAuthorize("@el.check('menu:list','roles:list')") |
||||
|
public ApiResponse<Object> queryAllMenu(@RequestParam Long pid){ |
||||
|
return ApiResponse.success(menuService.getMenus(pid)); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID") |
||||
|
@GetMapping(value = "/child") |
||||
|
// @PreAuthorize("@el.check('menu:list','roles:list')") |
||||
|
public ApiResponse<Object> childMenu(@RequestParam Long id){ |
||||
|
Set<Menu> menuSet = new HashSet<>(); |
||||
|
List<MenuDto> menuList = menuService.getMenus(id); |
||||
|
menuSet.add(menuService.findOne(id)); |
||||
|
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet); |
||||
|
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet()); |
||||
|
return ApiResponse.success(ids); |
||||
|
} |
||||
|
|
||||
|
@GetMapping |
||||
|
@ApiOperation("查询菜单") |
||||
|
//@PreAuthorize("@el.check('menu:list')") |
||||
|
public ApiResponse<Object> queryMenu(MenuQueryCriteria criteria) throws Exception { |
||||
|
List<MenuDto> menuDtoList = menuService.queryAll(criteria, true); |
||||
|
return ApiResponse.success(PageUtil.toPage(menuDtoList, menuDtoList.size())); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询菜单:根据ID获取同级与上级数据") |
||||
|
@PostMapping("/superior") |
||||
|
// @PreAuthorize("@el.check('menu:list')") |
||||
|
public ApiResponse<Object> getMenuSuperior(@RequestBody List<Long> ids) { |
||||
|
Set<MenuDto> menuDtos = new LinkedHashSet<>(); |
||||
|
if(CollectionUtil.isNotEmpty(ids)){ |
||||
|
for (Long id : ids) { |
||||
|
MenuDto menuDto = menuService.findById(id); |
||||
|
menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>())); |
||||
|
} |
||||
|
return ApiResponse.success(menuService.buildTree(new ArrayList<>(menuDtos))); |
||||
|
} |
||||
|
return ApiResponse.success(menuService.getMenus(null)); |
||||
|
} |
||||
|
|
||||
|
//@Log("新增菜单") |
||||
|
@ApiOperation("新增菜单") |
||||
|
@PostMapping |
||||
|
// @PreAuthorize("@el.check('menu:add')") |
||||
|
public ApiResponse<Object> createMenu(@Validated @RequestBody Menu resources){ |
||||
|
if (resources.getId() != null) { |
||||
|
throw new BaseException("A new "+ ENTITY_NAME +" cannot already have an ID"); |
||||
|
} |
||||
|
menuService.create(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
//@Log("修改菜单") |
||||
|
@ApiOperation("修改菜单") |
||||
|
@PutMapping |
||||
|
//@PreAuthorize("@el.check('menu:edit')") |
||||
|
public ApiResponse<Object> updateMenu(@Validated(Menu.Update.class) @RequestBody Menu resources){ |
||||
|
menuService.update(resources); |
||||
|
return ApiResponse.success(ResponseStatus.SUCCESS); |
||||
|
} |
||||
|
|
||||
|
// @Log("删除菜单") |
||||
|
@ApiOperation("删除菜单") |
||||
|
@DeleteMapping |
||||
|
//@PreAuthorize("@el.check('menu:del')") |
||||
|
public ApiResponse<Object> deleteMenu(@RequestBody Set<Long> ids){ |
||||
|
Set<Menu> menuSet = new HashSet<>(); |
||||
|
for (Long id : ids) { |
||||
|
List<MenuDto> menuList = menuService.getMenus(id); |
||||
|
menuSet.add(menuService.findOne(id)); |
||||
|
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet); |
||||
|
} |
||||
|
menuService.delete(menuSet); |
||||
|
return ApiResponse.success(HttpStatus.OK); |
||||
|
} |
||||
|
} |
@ -0,0 +1,138 @@ |
|||||
|
package com.storeroom.modules.system.controller; |
||||
|
|
||||
|
|
||||
|
import cn.hutool.core.lang.Dict; |
||||
|
import com.storeroom.exception.BaseException; |
||||
|
import com.storeroom.modules.system.domain.Role; |
||||
|
import com.storeroom.modules.system.service.RoleService; |
||||
|
import com.storeroom.modules.system.service.dto.RoleDto; |
||||
|
import com.storeroom.modules.system.service.dto.RoleQueryCriteria; |
||||
|
import com.storeroom.modules.system.service.dto.RoleSmallDto; |
||||
|
import com.storeroom.utils.ApiResponse; |
||||
|
import com.storeroom.utils.SecurityUtils; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.http.HttpStatus; |
||||
|
import org.springframework.http.ResponseEntity; |
||||
|
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; |
||||
|
import java.util.List; |
||||
|
import java.util.Set; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
|
||||
|
@RestController |
||||
|
@RequiredArgsConstructor |
||||
|
@Api(tags = "系统:角色管理") |
||||
|
@RequestMapping("/api/roles") |
||||
|
public class RoleController { |
||||
|
|
||||
|
private final RoleService roleService; |
||||
|
|
||||
|
private static final String ENTITY_NAME="role"; |
||||
|
|
||||
|
@ApiOperation("获取单个role") |
||||
|
@GetMapping(value = "/{id}") |
||||
|
@PreAuthorize("@el.check('roles:list')") |
||||
|
public ApiResponse<Object> findRoleById(@PathVariable Long id){ |
||||
|
return ApiResponse.success(roleService.findById(id)); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("导出角色数据") |
||||
|
@GetMapping(value = "/download") |
||||
|
//@PreAuthorize("@el.check('role:list')") |
||||
|
public void exportRole(HttpServletResponse response, RoleQueryCriteria criteria) throws IOException { |
||||
|
roleService.download(roleService.queryAll(criteria), response); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("返回全部的角色") |
||||
|
@GetMapping(value = "/all") |
||||
|
//@PreAuthorize("@el.check('roles:list','user:add','user:edit')") |
||||
|
public ApiResponse<Object> queryAllRole(){ |
||||
|
return ApiResponse.success(roleService.queryAll()); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("查询角色") |
||||
|
@GetMapping |
||||
|
//@PreAuthorize("@el.check('roles:list')") |
||||
|
public ApiResponse<Object> queryRole(RoleQueryCriteria criteria, Pageable pageable){ |
||||
|
return ApiResponse.success(roleService.queryAll(criteria,pageable)); |
||||
|
} |
||||
|
|
||||
|
@ApiOperation("获取用户级别") |
||||
|
@GetMapping(value = "/level") |
||||
|
public ApiResponse<Object> getRoleLevel(){ |
||||
|
return ApiResponse.success(Dict.create().set("level", getLevels(null))); |
||||
|
} |
||||
|
|
||||
|
// @Log("新增角色") |
||||
|
@ApiOperation("新增角色") |
||||
|
@PostMapping |
||||
|
// @PreAuthorize("@el.check('roles:add')") |
||||
|
public ResponseEntity<Object> createRole(@Validated @RequestBody Role resources){ |
||||
|
if (resources.getId() != null) { |
||||
|
throw new BaseException("A new "+ ENTITY_NAME +" cannot already have an ID"); |
||||
|
} |
||||
|
getLevels(resources.getLevel()); |
||||
|
roleService.create(resources); |
||||
|
return new ResponseEntity<>(HttpStatus.CREATED); |
||||
|
} |
||||
|
|
||||
|
//@Log("修改角色") |
||||
|
@ApiOperation("修改角色") |
||||
|
@PutMapping |
||||
|
//@PreAuthorize("@el.check('roles:edit')") |
||||
|
public ApiResponse<Object> updateRole(@Validated(Role.Update.class) @RequestBody Role resources){ |
||||
|
getLevels(resources.getLevel()); |
||||
|
roleService.update(resources); |
||||
|
return ApiResponse.success(HttpStatus.NO_CONTENT); |
||||
|
} |
||||
|
|
||||
|
//@Log("修改角色菜单") |
||||
|
@ApiOperation("修改角色菜单") |
||||
|
@PutMapping(value = "/menu") |
||||
|
//@PreAuthorize("@el.check('roles:edit')") |
||||
|
public ApiResponse<Object> updateRoleMenu(@RequestBody Role resources){ |
||||
|
RoleDto role = roleService.findById(resources.getId()); |
||||
|
getLevels(role.getLevel()); |
||||
|
roleService.updateMenu(resources,role); |
||||
|
return ApiResponse.success(HttpStatus.NO_CONTENT); |
||||
|
} |
||||
|
|
||||
|
//@Log("删除角色") |
||||
|
@ApiOperation("删除角色") |
||||
|
@DeleteMapping |
||||
|
//@PreAuthorize("@el.check('roles:del')") |
||||
|
public ApiResponse<Object> deleteRole(@RequestBody Set<Long> ids){ |
||||
|
for (Long id : ids) { |
||||
|
RoleDto role = roleService.findById(id); |
||||
|
getLevels(role.getLevel()); |
||||
|
} |
||||
|
// 验证是否被用户关联 |
||||
|
roleService.verification(ids); |
||||
|
roleService.delete(ids); |
||||
|
return ApiResponse.success(HttpStatus.OK); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取用户的角色级别 |
||||
|
* @return / |
||||
|
*/ |
||||
|
private int getLevels(Integer level){ |
||||
|
List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
||||
|
int min = Collections.min(levels); |
||||
|
if(level != null){ |
||||
|
if(level < min){ |
||||
|
throw new BaseException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level); |
||||
|
} |
||||
|
} |
||||
|
return min; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue