package com.qianwen.smartman.modules.system.controller;
|
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.validation.Valid;
|
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import com.qianwen.core.boot.ctrl.BladeController;
|
import com.qianwen.core.cache.utils.CacheUtil;
|
import com.qianwen.core.log.annotation.ApiLog;
|
import com.qianwen.core.mp.support.Condition;
|
import com.qianwen.core.scanner.modular.annotation.GetResource;
|
import com.qianwen.core.scanner.modular.annotation.PostResource;
|
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
|
import com.qianwen.core.secure.BladeUser;
|
import com.qianwen.core.secure.annotation.PreAuth;
|
import com.qianwen.core.tenant.annotation.NonDS;
|
import com.qianwen.core.tool.api.R;
|
import com.qianwen.core.tool.utils.Func;
|
import com.qianwen.smartman.common.cache.RegionCache;
|
import com.qianwen.smartman.common.cache.SysCache;
|
import com.qianwen.smartman.common.constant.ExtCacheConstant;
|
import com.qianwen.smartman.modules.system.entity.Role;
|
import com.qianwen.smartman.modules.system.service.IRoleService;
|
import com.qianwen.smartman.modules.system.vo.GrantVO;
|
import com.qianwen.smartman.modules.system.vo.RoleVO;
|
import com.qianwen.smartman.modules.system.wrapper.RoleWrapper;
|
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import springfox.documentation.annotations.ApiIgnore;
|
|
@Api(value = "角色", tags = {"角色"})
|
@RestController
|
@ApiResource({"blade-system/role"})
|
@NonDS
|
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/system/controller/RoleController.class */
|
public class RoleController extends BladeController {
|
private final IRoleService roleService;
|
|
|
public RoleController(final IRoleService roleService) {
|
this.roleService = roleService;
|
}
|
|
@ApiOperationSupport(order = 1)
|
@ApiLog("角色详情")
|
@GetResource({"/detail"})
|
@ApiOperation(value = "详情", notes = "传入role")
|
public R<RoleVO> detail(Role role) {
|
Role detail = (Role) this.roleService.getOne(Condition.getQueryWrapper(role));
|
return R.data(RoleWrapper.build().entityVO(detail));
|
}
|
|
@ApiOperationSupport(order = 2)
|
@ApiImplicitParams({@ApiImplicitParam(name = "roleName", value = "参数名称", paramType = "query", dataType = "string"), @ApiImplicitParam(name = "roleAlias", value = "角色别名", paramType = "query", dataType = "string")})
|
@ApiLog("角色列表")
|
@GetResource({"/list"})
|
@ApiOperation(value = "列表", notes = "传入role")
|
public R<List<RoleVO>> list(@RequestParam @ApiIgnore Map<String, Object> role, BladeUser bladeUser) {
|
QueryWrapper<Role> queryWrapper = Condition.getQueryWrapper(role, Role.class);
|
List<Role> list = this.roleService.list(!bladeUser.getTenantId().equals("000000") ? queryWrapper.lambda()
|
.eq(Role::getTenantId, bladeUser.getTenantId()).orderByAsc(Role::getSort) : queryWrapper
|
.lambda().orderByAsc(Role::getSort));
|
/*
|
List<Role> list = this.roleService.list(!bladeUser.getTenantId().equals("000000") ? (Wrapper) ((LambdaQueryWrapper) queryWrapper.lambda().eq((v0) -> {
|
return v0.getTenantId();
|
}, bladeUser.getTenantId())).orderByAsc((v0) -> {
|
return v0.getSort();
|
}) : (Wrapper) queryWrapper.lambda().orderByAsc((v0) -> {
|
return v0.getSort();
|
}));*/
|
return R.data(RoleWrapper.build().listNodeVO(list));
|
}
|
|
@ApiOperationSupport(order = 3)
|
@ApiLog("获取角色树形结构")
|
@GetResource({"/tree"})
|
@ApiOperation(value = "树形结构", notes = "树形结构")
|
public R<List<RoleVO>> tree(String tenantId, BladeUser bladeUser) {
|
List<RoleVO> tree = this.roleService.tree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()));
|
return R.data(tree);
|
}
|
|
@ApiOperationSupport(order = 4)
|
@ApiLog("获取指定角色树形结构")
|
@GetResource({"/tree-by-id"})
|
@ApiOperation(value = "树形结构", notes = "树形结构")
|
public R<List<RoleVO>> treeById(Long roleId, BladeUser bladeUser) {
|
Role role = SysCache.getRole(roleId);
|
List<RoleVO> tree = this.roleService.tree(Func.notNull(role) ? role.getTenantId() : bladeUser.getTenantId());
|
return R.data(tree);
|
}
|
|
@ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
|
@PostResource({"/submit"})
|
@ApiLog("新增或修改角色")
|
@ApiOperation(value = "新增或修改", notes = "传入role")
|
@PreAuth
|
public R<Role> submit(@Valid @RequestBody Role role) {
|
CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
|
return R.data(this.roleService.submit(role));
|
}
|
|
@ApiOperationSupport(order = 6)
|
@PostResource({"/remove"})
|
@ApiLog("删除角色")
|
@ApiOperation(value = "删除", notes = "传入ids")
|
@Transactional(rollbackFor = {Exception.class})
|
@PreAuth
|
public R remove(@RequestParam @ApiParam(value = "主键集合", required = true) String ids) {
|
CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
|
|
this.roleService.remove(Wrappers.<Role>lambdaQuery().in(Role::getParentId, Func.toLongList(ids)));
|
/*
|
this.roleService.remove((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getParentId();
|
}, Func.toLongList(ids)));*/
|
return R.status(this.roleService.removeByIds(Func.toLongList(ids)));
|
}
|
|
@ApiOperationSupport(order = 7)
|
@PostResource({"/grant"})
|
@ApiLog("设置角色权限")
|
@ApiOperation(value = "权限设置", notes = "传入roleId集合以及menuId集合")
|
@PreAuth
|
public R grant(@RequestBody GrantVO grantVO) {
|
CacheUtil.clear("blade:sys", ExtCacheConstant.TENANT_MODE);
|
boolean temp = this.roleService.grant(grantVO.getRoleIds(), grantVO.getMenuIds(), grantVO.getDataScopeIds(), grantVO.getApiScopeIds());
|
return R.status(temp);
|
}
|
|
@ApiOperationSupport(order = 8)
|
@GetResource({"/select"})
|
@ApiOperation(value = "下拉数据源", notes = "传入id集合")
|
public R<List<Role>> select(String roleId) {
|
List<Role> list = this.roleService.list(Wrappers.<Role>lambdaQuery().in(Role::getId, Func.toLongList(roleId)).orderByAsc(Role::getSort));
|
/*
|
List<Role> list = this.roleService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getId();
|
}, Func.toLongList(roleId))).orderByAsc((v0) -> {
|
return v0.getSort();
|
}));*/
|
return R.data(list);
|
}
|
}
|