All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.github.javaclub.base.web.SysRoleController Maven / Gradle / Ivy
package com.github.javaclub.base.web;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.github.javaclub.base.annotation.SysLog;
import com.github.javaclub.base.annotation.WithApiResult;
import com.github.javaclub.base.domain.SysRole;
import com.github.javaclub.base.domain.query.SysRoleQuery;
import com.github.javaclub.base.service.SysMenuService;
import com.github.javaclub.base.service.SysRoleService;
import com.github.javaclub.sword.BizException;
import com.github.javaclub.sword.core.BizObjects;
import com.github.javaclub.sword.domain.QueryResult;
import com.github.javaclub.sword.web.PageResultSet;
import com.github.javaclub.toolbox.enumtype.ActionType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
@RestController
@RequestMapping("/sys/role")
@AllArgsConstructor
@Api(tags = "管理端: 角色管理")
@WithApiResult
public class SysRoleController {
private final SysRoleService sysRoleService;
private final SysMenuService sysMenuService;
@PostMapping("/page")
@PreAuthorize("@pms.hasPermission('sys:role:page')")
@ApiOperation(value = "角色列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true)
})
public PageResultSet page(@RequestBody SysRoleQuery query) {
QueryResult qr = sysRoleService.findListWithCount(query);
if (!qr.isSuccess()) {
throw new BizException("查询列表失败!");
}
return PageResultSet.build(query.getPageNo(), query.getPageSize(), qr.getTotalCount(), qr.getEntry());
}
@GetMapping("/list")
@PreAuthorize("@pms.hasPermission('sys:role:list')")
@ApiOperation(value = "所有角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true)
})
public List list() {
return sysRoleService.list();
}
@GetMapping("/info")
@PreAuthorize("@pms.hasPermission('sys:role:info')")
@ApiOperation(value = "角色信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true),
@ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "query", dataType = "long", required = true)
})
public SysRole info(Long roleId) {
SysRole role = sysRoleService.getById((Long) BizObjects.requireNotNullGtZero(roleId, "角色ID参数错误!"));
//查询角色对应的菜单
List menuList = sysMenuService.listMenuIdByRoleId(roleId);
role.setMenuIdList(menuList);
return role;
}
@SysLog(value = "新增角色", actionType = ActionType.ADD)
@PostMapping("/add")
@PreAuthorize("@pms.hasPermission('sys:role:add')")
@ApiOperation(value = "新增角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true)
})
public Boolean add(@RequestBody SysRole role) {
sysRoleService.saveRoleAndRoleMenu(role);
return true;
}
@SysLog(value = "修改角色", actionType = ActionType.UPDATE)
@PostMapping("/update")
@PreAuthorize("@pms.hasPermission('sys:role:update')")
@ApiOperation(value = "修改角色")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true)
})
public Boolean update(@RequestBody SysRole role) {
sysRoleService.updateRoleAndRoleMenu(role);
return true;
}
@PostMapping("/delete")
@ApiOperation(value = "删除操作")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true),
@ApiImplicitParam(name = "roleId", value = "角色ID", paramType = "query", dataType = "long", required = true)
})
@PreAuthorize("@pms.hasPermission('sys:role:delete')")
@SysLog(value = "删除角色", actionType = ActionType.DELETE)
public Boolean delete(Long roleId) {
BizObjects.requireNotNullGtZero(roleId, "角色ID参数错误!");
sysRoleService.removeById(roleId);
return true;
}
@PostMapping("/deleteByIds")
@ApiOperation(value = "批量删除")
@ApiImplicitParams({
@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true)
})
@PreAuthorize("@pms.hasPermission('sys:role:batch_delete')")
@SysLog(value = "批量删除角色", actionType = ActionType.BATCH_DELETE)
public Boolean deleteByIds(@RequestBody Long[] roleIds) {
BizObjects.requireTrue(BizObjects.isNotEmpty(roleIds), "请求参数不能为空!");
sysRoleService.deleteBatch(roleIds);
return true;
}
}