Skip to content

Commit

Permalink
refactor(全局接口): 替换 HasPermisson 表达式 ,简化接口权限判断表达式
Browse files Browse the repository at this point in the history
feat(全局):

@hasPermission("XXX")
@PreAuthorize("@pms.hasPermission('XXX')")
  • Loading branch information
lltx committed Jul 15, 2024
1 parent 144bfa2 commit c8d4eeb
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.pig4cloud.pig.admin.service.SysOauthClientDetailsService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
Expand All @@ -36,7 +37,6 @@
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -94,7 +94,7 @@ public R getOauthClientDetailsPage(@ParameterObject Page page,
*/
@SysLog("添加终端")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_client_add')")
@HasPermission("sys_client_add")
public R add(@Valid @RequestBody SysOauthClientDetails clientDetails) {
return R.ok(clientDetailsService.saveClient(clientDetails));
}
Expand All @@ -106,7 +106,7 @@ public R add(@Valid @RequestBody SysOauthClientDetails clientDetails) {
*/
@SysLog("删除终端")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys_client_del')")
@HasPermission("sys_client_del")
public R removeById(@RequestBody Long[] ids) {
clientDetailsService.removeBatchByIds(CollUtil.toList(ids));
return R.ok();
Expand All @@ -119,7 +119,7 @@ public R removeById(@RequestBody Long[] ids) {
*/
@SysLog("编辑终端")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_client_edit')")
@HasPermission("sys_client_edit")
public R update(@Valid @RequestBody SysOauthClientDetails clientDetails) {
return R.ok(clientDetailsService.updateClientById(clientDetails));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
import com.pig4cloud.pig.admin.service.SysDeptService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -90,7 +90,7 @@ public R getTree(String deptName) {
*/
@SysLog("添加部门")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_dept_add')")
@HasPermission("sys_dept_add")
public R save(@Valid @RequestBody SysDept sysDept) {
return R.ok(sysDeptService.save(sysDept));
}
Expand All @@ -102,7 +102,7 @@ public R save(@Valid @RequestBody SysDept sysDept) {
*/
@SysLog("删除部门")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('sys_dept_del')")
@HasPermission("sys_dept_del")
public R removeById(@PathVariable Long id) {
return R.ok(sysDeptService.removeDeptById(id));
}
Expand All @@ -114,7 +114,7 @@ public R removeById(@PathVariable Long id) {
*/
@SysLog("编辑部门")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_dept_edit')")
@HasPermission("sys_dept_edit")
public R update(@Valid @RequestBody SysDept sysDept) {
sysDept.setUpdateTime(LocalDateTime.now());
return R.ok(sysDeptService.updateById(sysDept));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.pig4cloud.pig.common.core.constant.CacheConstants;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -39,7 +40,6 @@
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -114,7 +114,7 @@ public R<List<SysDictItem>> getDictByType(@PathVariable String type) {
*/
@SysLog("添加字典")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_dict_add')")
@HasPermission("sys_dict_add")
public R save(@Valid @RequestBody SysDict sysDict) {
sysDictService.save(sysDict);
return R.ok(sysDict);
Expand All @@ -127,7 +127,7 @@ public R save(@Valid @RequestBody SysDict sysDict) {
*/
@SysLog("删除字典")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys_dict_del')")
@HasPermission("sys_dict_del")
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
public R removeById(@RequestBody Long[] ids) {
return R.ok(sysDictService.removeDictByIds(ids));
Expand All @@ -140,7 +140,7 @@ public R removeById(@RequestBody Long[] ids) {
*/
@PutMapping
@SysLog("修改字典")
@PreAuthorize("@pms.hasPermission('sys_dict_edit')")
@HasPermission("sys_dict_edit")
public R updateById(@Valid @RequestBody SysDict sysDict) {
return sysDictService.updateDict(sysDict);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.pig4cloud.pig.admin.service.SysFileService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.pig.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
Expand All @@ -36,7 +37,6 @@
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -77,7 +77,7 @@ public R getSysFilePage(@ParameterObject Page page, @ParameterObject SysFile sys
@Operation(summary = "通过id删除文件管理", description = "通过id删除文件管理")
@SysLog("删除文件管理")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys_file_del')")
@HasPermission("sys_file_del")
public R removeById(@RequestBody Long[] ids) {
for (Long id : ids) {
sysFileService.deleteFile(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.pig4cloud.pig.admin.api.entity.SysLog;
import com.pig4cloud.pig.admin.service.SysLogService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
Expand All @@ -33,7 +34,6 @@
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -72,7 +72,7 @@ public R getLogPage(@ParameterObject Page page, @ParameterObject SysLogDTO sysLo
* @return success/false
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys_log_del')")
@HasPermission("sys_log_del")
public R removeByIds(@RequestBody Long[] ids) {
return R.ok(sysLogService.removeBatchByIds(CollUtil.toList(ids)));
}
Expand All @@ -95,7 +95,7 @@ public R save(@Valid @RequestBody SysLog sysLog) {
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('sys_log_export')")
@HasPermission("sys_log_export")
public List<SysLog> export(SysLogDTO sysLog) {
return sysLogService.getList(sysLog);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import com.pig4cloud.pig.admin.service.SysMenuService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.pig.common.security.util.SecurityUtils;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
Expand Down Expand Up @@ -102,7 +102,7 @@ public R getById(@PathVariable Long id) {
*/
@SysLog("新增菜单")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_menu_add')")
@HasPermission("sys_menu_add")
public R save(@Valid @RequestBody SysMenu sysMenu) {
sysMenuService.save(sysMenu);
return R.ok(sysMenu);
Expand All @@ -115,7 +115,7 @@ public R save(@Valid @RequestBody SysMenu sysMenu) {
*/
@SysLog("删除菜单")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('sys_menu_del')")
@HasPermission("sys_menu_del")
public R removeById(@PathVariable Long id) {
return sysMenuService.removeMenuById(id);
}
Expand All @@ -127,7 +127,7 @@ public R removeById(@PathVariable Long id) {
*/
@SysLog("更新菜单")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_menu_edit')")
@HasPermission("sys_menu_edit")
public R update(@Valid @RequestBody SysMenu sysMenu) {
return R.ok(sysMenuService.updateMenuById(sysMenu));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.pig4cloud.pig.admin.service.SysPostService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -34,7 +35,6 @@
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -72,7 +72,7 @@ public R<List<SysPost>> listPosts() {
*/
@Operation(description = "分页查询", summary = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('sys_post_view')")
@HasPermission("sys_post_view")
public R getSysPostPage(@ParameterObject Page page, @ParameterObject SysPost sysPost) {
return R.ok(sysPostService.page(page, Wrappers.<SysPost>lambdaQuery()
.like(StrUtil.isNotBlank(sysPost.getPostName()), SysPost::getPostName, sysPost.getPostName())));
Expand All @@ -85,7 +85,7 @@ public R getSysPostPage(@ParameterObject Page page, @ParameterObject SysPost sys
*/
@Operation(description = "通过id查询", summary = "通过id查询")
@GetMapping("/details/{postId}")
@PreAuthorize("@pms.hasPermission('sys_post_view')")
@HasPermission("sys_post_view")
public R getById(@PathVariable("postId") Long postId) {
return R.ok(sysPostService.getById(postId));
}
Expand All @@ -97,7 +97,7 @@ public R getById(@PathVariable("postId") Long postId) {
*/
@Operation(description = "查询角色信息", summary = "查询角色信息")
@GetMapping("/details")
@PreAuthorize("@pms.hasPermission('sys_post_view')")
@HasPermission("sys_post_view")
public R getDetails(SysPost query) {
return R.ok(sysPostService.getOne(Wrappers.query(query), false));
}
Expand All @@ -110,7 +110,7 @@ public R getDetails(SysPost query) {
@Operation(description = "新增岗位信息表", summary = "新增岗位信息表")
@SysLog("新增岗位信息表")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_post_add')")
@HasPermission("sys_post_add")
public R save(@RequestBody SysPost sysPost) {
return R.ok(sysPostService.save(sysPost));
}
Expand All @@ -123,7 +123,7 @@ public R save(@RequestBody SysPost sysPost) {
@Operation(description = "修改岗位信息表", summary = "修改岗位信息表")
@SysLog("修改岗位信息表")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_post_edit')")
@HasPermission("sys_post_edit")
public R updateById(@RequestBody SysPost sysPost) {
return R.ok(sysPostService.updateById(sysPost));
}
Expand All @@ -136,7 +136,7 @@ public R updateById(@RequestBody SysPost sysPost) {
@Operation(description = "通过id删除岗位信息表", summary = "通过id删除岗位信息表")
@SysLog("通过id删除岗位信息表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys_post_del')")
@HasPermission("sys_post_del")
public R removeById(@RequestBody Long[] ids) {
return R.ok(sysPostService.removeBatchByIds(CollUtil.toList(ids)));
}
Expand All @@ -147,7 +147,7 @@ public R removeById(@RequestBody Long[] ids) {
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('sys_post_export')")
@HasPermission("sys_post_export")
public List<PostExcelVO> export() {
return sysPostService.listPost();
}
Expand All @@ -159,7 +159,7 @@ public List<PostExcelVO> export() {
* @return ok fail
*/
@PostMapping("/import")
@PreAuthorize("@pms.hasPermission('sys_post_export')")
@HasPermission("sys_post_export")
public R importRole(@RequestExcel List<PostExcelVO> excelVOList, BindingResult bindingResult) {
return sysPostService.importPost(excelVOList, bindingResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.pig4cloud.pig.admin.service.SysPublicParamService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import com.pig4cloud.pig.common.security.annotation.HasPermission;
import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -33,7 +34,6 @@
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand Down Expand Up @@ -109,7 +109,7 @@ public R getDetail(@ParameterObject SysPublicParam param) {
@Operation(description = "新增公共参数", summary = "新增公共参数")
@SysLog("新增公共参数")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_syspublicparam_add')")
@HasPermission("sys_syspublicparam_add")
public R save(@RequestBody SysPublicParam sysPublicParam) {
return R.ok(sysPublicParamService.save(sysPublicParam));
}
Expand All @@ -122,7 +122,7 @@ public R save(@RequestBody SysPublicParam sysPublicParam) {
@Operation(description = "修改公共参数", summary = "修改公共参数")
@SysLog("修改公共参数")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_syspublicparam_edit')")
@HasPermission("sys_syspublicparam_edit")
public R updateById(@RequestBody SysPublicParam sysPublicParam) {
return sysPublicParamService.updateParam(sysPublicParam);
}
Expand All @@ -135,7 +135,7 @@ public R updateById(@RequestBody SysPublicParam sysPublicParam) {
@Operation(description = "删除公共参数", summary = "删除公共参数")
@SysLog("删除公共参数")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys_syspublicparam_del')")
@HasPermission("sys_syspublicparam_del")
public R removeById(@RequestBody Long[] ids) {
return R.ok(sysPublicParamService.removeParamByIds(ids));
}
Expand All @@ -146,7 +146,7 @@ public R removeById(@RequestBody Long[] ids) {
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('sys_syspublicparam_edit')")
@HasPermission("sys_syspublicparam_edit")
public List<SysPublicParam> export() {
return sysPublicParamService.list();
}
Expand All @@ -157,7 +157,7 @@ public List<SysPublicParam> export() {
*/
@SysLog("同步参数")
@PutMapping("/sync")
@PreAuthorize("@pms.hasPermission('sys_syspublicparam_edit')")
@HasPermission("sys_syspublicparam_edit")
public R sync() {
return sysPublicParamService.syncParamCache();
}
Expand Down
Loading

0 comments on commit c8d4eeb

Please sign in to comment.