Skip to content

Commit

Permalink
ref: 适配最新的 @hasPermission 注解
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx authored Jul 20, 2024
1 parent f284d66 commit 0d5cf20
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
32 changes: 30 additions & 2 deletions multiple/主子Contoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import ${package}.${moduleName}.entity.${ClassName}Entity;
import ${package}.${moduleName}.entity.${ChildClassName}Entity;
import ${package}.${moduleName}.service.${ClassName}Service;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
#if($isSpringBoot3)
import ${package}.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
#else
import org.springframework.security.access.prepost.PreAuthorize;
import org.springdoc.api.annotations.ParameterObject;
#end
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -58,7 +59,11 @@ public class ${ClassName}Controller {
*/
@Operation(summary = "分页查询" , description = "分页查询" )
@GetMapping("/page" )
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_view")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
#end
public R get${ClassName}Page(@ParameterObject Page page, @ParameterObject ${ClassName}Entity ${className}) {
LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
#foreach ($field in $queryList)
Expand Down Expand Up @@ -100,7 +105,11 @@ public class ${ClassName}Controller {
*/
@Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
@GetMapping("/details" )
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_view")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
#end
public R getDetails(@ParameterObject ${ClassName}Entity ${className}) {
return R.ok(${className}Service.listDeep(Wrappers.query(${className})));
}
Expand All @@ -113,7 +122,11 @@ public R getDetails(@ParameterObject ${ClassName}Entity ${className}) {
@Operation(summary = "新增${tableComment}" , description = "新增${tableComment}" )
@SysLog("新增${tableComment}" )
@PostMapping
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_add")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_add')" )
#end
public R save(@RequestBody ${ClassName}Entity ${className}) {
return R.ok(${className}Service.saveDeep(${className}));
}
Expand All @@ -126,7 +139,11 @@ public R save(@RequestBody ${ClassName}Entity ${className}) {
@Operation(summary = "修改${tableComment}" , description = "修改${tableComment}" )
@SysLog("修改${tableComment}" )
@PutMapping
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_edit")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_edit')" )
#end
public R updateById(@RequestBody ${ClassName}Entity ${className}) {
return R.ok(${className}Service.updateDeep(${className}));
}
Expand All @@ -139,7 +156,11 @@ public R updateById(@RequestBody ${ClassName}Entity ${className}) {
@Operation(summary = "通过id删除${tableComment}" , description = "通过id删除${tableComment}" )
@SysLog("通过id删除${tableComment}" )
@DeleteMapping
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_del")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )
#end
public R removeById(@RequestBody ${pk.attrType}[] ids) {
return R.ok(${className}Service.removeDeep(ids));
}
Expand All @@ -152,7 +173,11 @@ public R removeById(@RequestBody ${pk.attrType}[] ids) {
@Operation(summary = "通过id删除${tableComment}子表数据" , description = "通过id删除${tableComment}子表数据" )
@SysLog("通过id删除${tableComment}子表数据" )
@DeleteMapping("/child")
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_del")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )
#end
public R removeChild(@RequestBody ${pk.attrType}[] ids) {
return R.ok(${className}Service.removeChild(ids));
}
Expand All @@ -165,8 +190,11 @@ public R removeChild(@RequestBody ${pk.attrType}[] ids) {
*/
@ResponseExcel
@GetMapping("/export")
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_export")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_export')" )
public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {
#end public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {
return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));
}
}
28 changes: 27 additions & 1 deletion single/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#end
import ${package}.${moduleName}.entity.${ClassName}Entity;
import ${package}.${moduleName}.service.${ClassName}Service;
import org.springframework.security.access.prepost.PreAuthorize;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
#if($isSpringBoot3)
import ${package}.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
#else
import org.springframework.security.access.prepost.PreAuthorize;
import org.springdoc.api.annotations.ParameterObject;
#end
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -58,7 +60,11 @@ public class ${ClassName}Controller {
*/
@Operation(summary = "分页查询" , description = "分页查询" )
@GetMapping("/page" )
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_view")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
#end
public R get${ClassName}Page(@ParameterObject Page page, @ParameterObject ${ClassName}Entity ${className}) {
LambdaQueryWrapper<${ClassName}Entity> wrapper = Wrappers.lambdaQuery();
#foreach ($field in $queryList)
Expand Down Expand Up @@ -100,7 +106,11 @@ public class ${ClassName}Controller {
*/
@Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
@GetMapping("/details" )
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_view")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_view')" )
#end
public R getDetails(@ParameterObject ${ClassName}Entity ${className}) {
return R.ok(${className}Service.list(Wrappers.query(${className})));
}
Expand All @@ -113,7 +123,11 @@ public R getDetails(@ParameterObject ${ClassName}Entity ${className}) {
@Operation(summary = "新增${tableComment}" , description = "新增${tableComment}" )
@SysLog("新增${tableComment}" )
@PostMapping
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_add")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_add')" )
#end
public R save(@RequestBody ${ClassName}Entity ${className}) {
return R.ok(${className}Service.save(${className}));
}
Expand All @@ -126,7 +140,11 @@ public R save(@RequestBody ${ClassName}Entity ${className}) {
@Operation(summary = "修改${tableComment}" , description = "修改${tableComment}" )
@SysLog("修改${tableComment}" )
@PutMapping
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_edit")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_edit')" )
#end
public R updateById(@RequestBody ${ClassName}Entity ${className}) {
return R.ok(${className}Service.updateById(${className}));
}
Expand All @@ -139,7 +157,11 @@ public R updateById(@RequestBody ${ClassName}Entity ${className}) {
@Operation(summary = "通过id删除${tableComment}" , description = "通过id删除${tableComment}" )
@SysLog("通过id删除${tableComment}" )
@DeleteMapping
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_del")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_del')" )
#end
public R removeById(@RequestBody ${pk.attrType}[] ids) {
return R.ok(${className}Service.removeBatchByIds(CollUtil.toList(ids)));
}
Expand All @@ -153,7 +175,11 @@ public R removeById(@RequestBody ${pk.attrType}[] ids) {
*/
@ResponseExcel
@GetMapping("/export")
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_export")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_export')" )
#end
public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {
return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));
}
Expand Down

0 comments on commit 0d5cf20

Please sign in to comment.