From 6bddebafff4d08d4d1c6dbc98931963e8b4eeb21 Mon Sep 17 00:00:00 2001 From: YunaiV <> Date: Wed, 8 Jul 2020 20:21:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=8B=A5=E6=9C=89=E7=9A=84=E8=8F=9C=E5=8D=95=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/src/utils/request.js | 2 +- ...llectionUtil.java => CollectionUtils.java} | 9 +-- .../interceptor/AdminSecurityInterceptor.java | 4 +- .../permission/vo/AdminMenuTreeNodeVO.java | 31 ++++++++ .../convert/permission/ResourceConvert.java | 3 + .../manager/permission/ResourceManager.java | 62 ++++++++++++++- .../rpc/permission/ResourceRpc.java | 11 +++ .../systemservice/rpc/permission/RoleRpc.java | 11 ++- .../mapper/permission/AccountRoleMapper.java | 38 ---------- .../mapper/permission/AdminRoleMapper.java | 37 +++++++++ .../mapper/permission/ResourceMapper.java | 10 +++ .../manager/permission/ResourceManager.java | 22 ++++++ .../manager/permission/RoleManager.java | 11 +++ .../rpc/permission/ResourceRpcImpl.java | 6 ++ .../rpc/permission/RoleRpcImpl.java | 6 ++ .../service/permission/ResourceService.java | 35 +++++++++ .../service/permission/RoleService.java | 35 +++++++++ .../main/resources/mapper/AdminRoleMapper.xml | 2 +- ...rizationGetResourceTreeByAccountIdDTO.java | 22 ------ .../AuthorizationServiceImpl.java | 13 +--- .../authorization/ResourceServiceImpl.java | 25 +------ .../service/authorization/RoleService.java | 39 ---------- .../authorization/RoleServiceImpl.java | 50 ------------- .../admin/AdminsAdminController.java | 65 +--------------- .../AdminsResourceController.java | 30 -------- .../authorization/AdminsRoleController.java | 75 ------------------- .../authorization/AdminsRolePageResponse.java | 26 ------- .../user/UsersOAuth2AuthenticateResponse.java | 50 ------------- 28 files changed, 288 insertions(+), 442 deletions(-) rename common/common-framework/src/main/java/cn/iocoder/common/framework/util/{CollectionUtil.java => CollectionUtils.java} (89%) create mode 100644 management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java delete mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AccountRoleMapper.java create mode 100644 system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourceTreeByAccountIdDTO.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java delete mode 100644 system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java delete mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsRoleController.java delete mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java delete mode 100644 system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/user/UsersOAuth2AuthenticateResponse.java diff --git a/admin-web/src/utils/request.js b/admin-web/src/utils/request.js index f950a3de5..c37056d3d 100644 --- a/admin-web/src/utils/request.js +++ b/admin-web/src/utils/request.js @@ -138,7 +138,7 @@ export default function request(url, option) { // 将登陆的 accessToken 放到 header const loginToken = getLoginToken(); if (loginToken && loginToken.accessToken - && url.indexOf('/system-api/admins/oauth2/username-authenticate') === -1) { // TODO 芋艿,临时这么加,可能不是很优雅 + && url.indexOf('/management-api/passport/login') === -1) { // TODO 芋艿,临时这么加,可能不是很优雅 const headers = { ...newOptions.headers, Authorization: `Bearer ${loginToken.accessToken}`, diff --git a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtils.java similarity index 89% rename from common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java rename to common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtils.java index 2a737e87c..e9d58a44f 100644 --- a/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtil.java +++ b/common/common-framework/src/main/java/cn/iocoder/common/framework/util/CollectionUtils.java @@ -1,12 +1,10 @@ package cn.iocoder.common.framework.util; -import org.springframework.util.CollectionUtils; - import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; -public class CollectionUtil { +public class CollectionUtils { public static boolean isEmpty(Collection collection) { return collection == null || collection.isEmpty(); @@ -43,12 +41,11 @@ public class CollectionUtil { // 暂时没想好名字,先以 2 结尾噶 public static Map> convertMultiMap2(List from, Function keyFunc, Function valueFunc) { - return from.stream().collect(Collectors.groupingBy(keyFunc, - Collectors.mapping(valueFunc, Collectors.toSet()))); + return from.stream().collect(Collectors.groupingBy(keyFunc, Collectors.mapping(valueFunc, Collectors.toSet()))); } public static boolean containsAny(Collection source, Collection candidates) { - return CollectionUtils.containsAny(source, candidates); + return org.springframework.util.CollectionUtils.containsAny(source, candidates); } } diff --git a/common/mall-spring-boot-starter-security-admin/src/main/java/cn/iocoder/mall/security/admin/core/interceptor/AdminSecurityInterceptor.java b/common/mall-spring-boot-starter-security-admin/src/main/java/cn/iocoder/mall/security/admin/core/interceptor/AdminSecurityInterceptor.java index d73876c3a..b5c56f9c5 100644 --- a/common/mall-spring-boot-starter-security-admin/src/main/java/cn/iocoder/mall/security/admin/core/interceptor/AdminSecurityInterceptor.java +++ b/common/mall-spring-boot-starter-security-admin/src/main/java/cn/iocoder/mall/security/admin/core/interceptor/AdminSecurityInterceptor.java @@ -1,7 +1,7 @@ package cn.iocoder.mall.security.admin.core.interceptor; import cn.iocoder.common.framework.enums.UserTypeEnum; -import cn.iocoder.common.framework.util.CollectionUtil; +import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.util.HttpUtil; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.CommonResult; @@ -73,7 +73,7 @@ public class AdminSecurityInterceptor extends HandlerInterceptorAdapter { return; } String[] permissions = requiresPermissions.value(); - if (CollectionUtil.isEmpty(permissions)) { + if (CollectionUtils.isEmpty(permissions)) { return; } // 权限验证 TODO 待完成 diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java new file mode 100644 index 000000000..a08dff77e --- /dev/null +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/controller/permission/vo/AdminMenuTreeNodeVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.mall.managementweb.controller.permission.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +@ApiModel(value = "管理员拥有的菜单树", description = "一般用于首页菜单") +@Data +@Accessors(chain = true) +public class AdminMenuTreeNodeVO { + + @ApiModelProperty(value = "菜单编号", required = true, example = "1") + private Integer id; + @ApiModelProperty(value = "菜单名", required = true, example = "商品管理") + private String name; + @ApiModelProperty(value = "前端路由", required = true, example = "/order/list") + private String route; + @ApiModelProperty(value = "菜单图标", required = true, example = "user") + private String icon; + @ApiModelProperty(value = "父级资源编号", required = true, example = "1", notes = "如果无父资源,则值为 0") + private Integer pid; + + /** + * 子节点数组 + */ + private List children; + +} diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java index 50150cc49..df61e953f 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/convert/permission/ResourceConvert.java @@ -1,5 +1,6 @@ package cn.iocoder.mall.managementweb.convert.permission; +import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; @@ -21,4 +22,6 @@ public interface ResourceConvert { List convertList(List list); + AdminMenuTreeNodeVO convertTreeNode(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO bean); + } diff --git a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java index e6cca6252..7ef9d5bad 100644 --- a/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java +++ b/management-web-app/src/main/java/cn/iocoder/mall/managementweb/manager/permission/ResourceManager.java @@ -1,24 +1,34 @@ package cn.iocoder.mall.managementweb.manager.permission; +import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceCreateDTO; import cn.iocoder.mall.managementweb.controller.permission.dto.ResourceUpdateDTO; +import cn.iocoder.mall.managementweb.controller.permission.vo.AdminMenuTreeNodeVO; import cn.iocoder.mall.managementweb.controller.permission.vo.ResourceVO; import cn.iocoder.mall.managementweb.convert.permission.ResourceConvert; +import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum; +import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; import cn.iocoder.mall.systemservice.rpc.permission.ResourceRpc; +import cn.iocoder.mall.systemservice.rpc.permission.RoleRpc; +import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.config.annotation.Reference; import org.springframework.stereotype.Service; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * 资源 Manager */ @Service +@Slf4j public class ResourceManager { @Reference(version = "${dubbo.consumer.ResourceRpc.version}", validation = "false") private ResourceRpc resourceRpc; + @Reference(version = "${dubbo.consumer.RoleRpc.version}", validation = "false") + private RoleRpc roleRpc; /** * 创建资源 @@ -76,4 +86,54 @@ public class ResourceManager { return ResourceConvert.INSTANCE.convertList(listResourceResult.getData()); } + /** + * 获得管理员的菜单树 + * + * @param adminId 管理员编号 + * @return 菜单树 + */ + public List treeAdminMenu(Integer adminId) { + // 获得管理员拥有的角色编号列表 + CommonResult> listAdminRoleIdsResult = roleRpc.listAdminRoleIds(adminId); + listAdminRoleIdsResult.checkError(); + if (CollectionUtils.isEmpty(listAdminRoleIdsResult.getData())) { + return null; + } + // 获得角色拥有的资源列表 + CommonResult> resourceVOResult = resourceRpc.listRoleResource( + listAdminRoleIdsResult.getData(), ResourceTypeEnum.MENU.getType()); + resourceVOResult.checkError(); + // 构建菜单树 + return this.buildAdminMenuTree(resourceVOResult.getData()); + } + + private List buildAdminMenuTree(List resourceVOs) { + // 排序,保证菜单的有序性 + resourceVOs.sort(Comparator.comparing(cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO::getSort)); + // 构建菜单树 + // 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。 + Map treeNodeMap = new LinkedHashMap<>(); + resourceVOs.forEach(resourceVO -> treeNodeMap.put(resourceVO.getId(), ResourceConvert.INSTANCE.convertTreeNode(resourceVO))); + // 处理父子关系 + treeNodeMap.values().stream() + .filter(node -> !node.getPid().equals(ResourceIdEnum.ROOT.getId())) + .forEach((childNode) -> { + // 获得父节点 + AdminMenuTreeNodeVO parentNode = treeNodeMap.get(childNode.getPid()); + if (parentNode == null) { + log.error("[getResourceTree][resource({}) 找不到父资源({})]", childNode.getId(), childNode.getPid()); + return; + } + if (parentNode.getChildren() == null) { // 初始化 children 数组 + parentNode.setChildren(new ArrayList<>()); + } + // 将自己添加到父节点中 + parentNode.getChildren().add(childNode); + }); + // 获得到所有的根节点 + return treeNodeMap.values().stream() + .filter(node -> node.getPid().equals(ResourceIdEnum.ROOT.getId())) + .collect(Collectors.toList()); + } + } diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java index 2739ea5a5..3e6182c0d 100644 --- a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpc.java @@ -5,6 +5,8 @@ import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; +import javax.validation.constraints.NotNull; +import java.util.Collection; import java.util.List; /** @@ -50,4 +52,13 @@ public interface ResourceRpc { */ CommonResult> listResource(List resourceIds); + /** + * 获得指定角色的资源列表 + * + * @param roleIds 角色编号列表 + * @param type 资源类型 + * @return 资源列表 + */ + CommonResult> listRoleResource(@NotNull(message = "角色编号列表不能为空") Collection roleIds, Integer type); + } diff --git a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java index db23b759a..df5048b94 100644 --- a/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java +++ b/system-service-project/system-service-api/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpc.java @@ -8,6 +8,7 @@ import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleCreateDTO; import cn.iocoder.mall.systemservice.rpc.permission.vo.RoleVO; import java.util.List; +import java.util.Set; /** * 角色 Rpc 接口 @@ -52,7 +53,6 @@ public interface RoleRpc { */ CommonResult> listRole(List roleIds); - /** * 获得角色分页 * @@ -60,4 +60,13 @@ public interface RoleRpc { * @return 角色分页结果 */ CommonResult> pageRole(RolePageDTO pageDTO); + + /** + * 获得管理员拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 角色编号列表 + */ + CommonResult> listAdminRoleIds(Integer adminId); + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AccountRoleMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AccountRoleMapper.java deleted file mode 100644 index 15f72bcec..000000000 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AccountRoleMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -package cn.iocoder.mall.systemservice.dal.mysql.mapper.permission; - -import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.AdminRoleDO; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import org.apache.ibatis.annotations.Param; -import org.springframework.stereotype.Repository; - -import java.util.Collection; -import java.util.List; - -@Repository -public interface AccountRoleMapper extends BaseMapper { - - default List selectByAccountId(Integer accountId) { - return selectList(new QueryWrapper().eq("account_id", accountId)); - } - - default List selectListByAccountIds(Collection accountIds) { - return selectList(new QueryWrapper().in("account_id", accountIds)); - } - - default int deleteByAccountId(Integer accountId) { - return delete(new QueryWrapper().eq("account_id", accountId)); - } - - default int deleteByRoleId(Integer roleId) { - return delete(new QueryWrapper().eq("role_id", roleId)); - } - - /** - * 批量插入。因为 MyBaits Plus 的批量插入是基于 Service 实现,所以只好写 XML - * - * @param accountRoleDOs 数组 - */ - int insertList(@Param("accountRoleDOs") List accountRoleDOs); - -} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java new file mode 100644 index 000000000..acf51ad37 --- /dev/null +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/AdminRoleMapper.java @@ -0,0 +1,37 @@ +package cn.iocoder.mall.systemservice.dal.mysql.mapper.permission; + +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.AdminRoleDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface AdminRoleMapper extends BaseMapper { + + default List selectByAdminId(Integer adminId) { + return selectList(new QueryWrapper().eq("admin_id", adminId)); + } + +// default List selectListByAccountIds(Collection accountIds) { +// return selectList(new QueryWrapper().in("account_id", accountIds)); +// } +// +// default int deleteByAccountId(Integer accountId) { +// return delete(new QueryWrapper().eq("account_id", accountId)); +// } +// +// default int deleteByRoleId(Integer roleId) { +// return delete(new QueryWrapper().eq("role_id", roleId)); +// } + + /** + * 批量插入。因为 MyBaits Plus 的批量插入是基于 Service 实现,所以只好写 XML + * + * @param accountRoleDOs 数组 + */ + int insertList(@Param("accountRoleDOs") List accountRoleDOs); + +} diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/ResourceMapper.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/ResourceMapper.java index e3f2a7079..37082147f 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/ResourceMapper.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/dal/mysql/mapper/permission/ResourceMapper.java @@ -16,6 +16,16 @@ public interface ResourceMapper extends BaseMapper { return selectOne(new QueryWrapper().eq("permission", permission)); } + /** + * 查询指定类型的资源列表 + * + * @param type 资源类型,允许空 + * @return 资源列表 + */ + default List selectListByType(Integer type) { + return selectList(new QueryWrapperX().eqIfPresent("type", type)); + } + default ResourceDO selectByPidAndName(Integer pid, String name) { return selectOne(new QueryWrapperX().eqIfPresent("pid", pid) .eqIfPresent("name", name)); diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java index 3a387bd11..97c72880a 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/ResourceManager.java @@ -5,10 +5,12 @@ import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceCreateDTO; import cn.iocoder.mall.systemservice.rpc.permission.dto.ResourceUpdateDTO; import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; import cn.iocoder.mall.systemservice.service.permission.ResourceService; +import cn.iocoder.mall.systemservice.service.permission.RoleService; import cn.iocoder.mall.systemservice.service.permission.bo.ResourceBO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Collection; import java.util.List; /** @@ -19,6 +21,8 @@ public class ResourceManager { @Autowired private ResourceService resourceService; + @Autowired + private RoleService roleService; /** * 创建资源 @@ -71,4 +75,22 @@ public class ResourceManager { return ResourceConvert.INSTANCE.convertList02(resourceBOs); } + /** + * 获得指定角色的资源列表 + * + * @param roleIds 角色编号列表 + * @param type 资源类型,允许空 + * @return 资源列表 + */ + public List listRoleResource(Collection roleIds, Integer type) { + List resourceBOs; + // 判断是否为超管。若是超管,默认有所有权限 + if (roleService.hasSuperAdmin(roleIds)) { + resourceBOs = resourceService.listResourceByType(type); + } else { + resourceBOs = resourceService.listRoleResourceByType(roleIds, type); + } + return ResourceConvert.INSTANCE.convertList02(resourceBOs); + } + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java index 5804224c7..00fd17315 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/manager/permission/RoleManager.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; +import java.util.Set; /** * 角色 Manager @@ -84,4 +85,14 @@ public class RoleManager { return RoleConvert.INSTANCE.convertPage(pageResultBO); } + /** + * 获得管理员拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 角色编号列表 + */ + public Set listAdminRoleIds(Integer adminId) { + return roleService.listAdminRoleIds(adminId); + } + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java index 6ad6b340e..997607cdd 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/ResourceRpcImpl.java @@ -8,6 +8,7 @@ import cn.iocoder.mall.systemservice.rpc.permission.vo.ResourceVO; import org.apache.dubbo.config.annotation.Service; import org.springframework.beans.factory.annotation.Autowired; +import java.util.Collection; import java.util.List; import static cn.iocoder.common.framework.vo.CommonResult.success; @@ -48,4 +49,9 @@ public class ResourceRpcImpl implements ResourceRpc { return success(resourceManager.listResource(resourceIds)); } + @Override + public CommonResult> listRoleResource(Collection roleIds, Integer type) { + return success(resourceManager.listRoleResource(roleIds, type)); + } + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java index b7cead32b..fee1e5a96 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/rpc/permission/RoleRpcImpl.java @@ -11,6 +11,7 @@ import org.apache.dubbo.config.annotation.Service; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; +import java.util.Set; import static cn.iocoder.common.framework.vo.CommonResult.success; @@ -55,4 +56,9 @@ public class RoleRpcImpl implements RoleRpc { return success(roleManager.pageRole(pageDTO)); } + @Override + public CommonResult> listAdminRoleIds(Integer adminId) { + return success(roleManager.listAdminRoleIds(adminId)); + } + } diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java index 17fe4d1ec..7c9bcfa73 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/ResourceService.java @@ -1,9 +1,12 @@ package cn.iocoder.mall.systemservice.service.permission; +import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.mall.systemservice.convert.permission.ResourceConvert; import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.ResourceDO; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleResourceDO; import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.ResourceMapper; +import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleResourceMapper; import cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum; import cn.iocoder.mall.systemservice.enums.permission.ResourceIdEnum; import cn.iocoder.mall.systemservice.enums.permission.ResourceTypeEnum; @@ -15,6 +18,8 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; +import java.util.Collection; +import java.util.Collections; import java.util.List; import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*; @@ -28,6 +33,8 @@ public class ResourceService { @Autowired private ResourceMapper resourceMapper; + @Autowired + private RoleResourceMapper roleResourceMapper; /** * 创建资源 @@ -112,6 +119,34 @@ public class ResourceService { return ResourceConvert.INSTANCE.convertList(resourceDOs); } + /** + * 获得指定类型的资源列表 + * + * @param type 资源类型,允许空 + * @return 资源列表 + */ + public List listResourceByType(Integer type) { + List resourceDOs = resourceMapper.selectListByType(type); + return ResourceConvert.INSTANCE.convertList(resourceDOs); + } + + /** + * 获得角色拥有的资源列表 + * + * @param roleIds 角色编号 + * @param type 资源类型,允许空 + * @return 资源列表 + */ + public List listRoleResourceByType(Collection roleIds, Integer type) { + List roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds); + if (CollectionUtils.isEmpty(roleResourceDOs)) { + return Collections.emptyList(); + } + List resourceDOs = resourceMapper.selectListByIdsAndType( + CollectionUtils.convertSet(roleResourceDOs, RoleResourceDO::getResourceId), type); + return ResourceConvert.INSTANCE.convertList(resourceDOs); + } + /** * 校验父资源是否合法 * diff --git a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java index 34d69e438..5f2f6cf7b 100644 --- a/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java +++ b/system-service-project/system-service-app/src/main/java/cn/iocoder/mall/systemservice/service/permission/RoleService.java @@ -1,10 +1,14 @@ package cn.iocoder.mall.systemservice.service.permission; +import cn.iocoder.common.framework.util.CollectionUtils; import cn.iocoder.common.framework.util.ServiceExceptionUtil; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.systemservice.convert.permission.RoleConvert; +import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.AdminRoleDO; import cn.iocoder.mall.systemservice.dal.mysql.dataobject.permission.RoleDO; +import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.AdminRoleMapper; import cn.iocoder.mall.systemservice.dal.mysql.mapper.permission.RoleMapper; +import cn.iocoder.mall.systemservice.enums.permission.RoleCodeEnum; import cn.iocoder.mall.systemservice.enums.permission.RoleTypeEnum; import cn.iocoder.mall.systemservice.service.permission.bo.RoleBO; import cn.iocoder.mall.systemservice.service.permission.bo.RoleCreateBO; @@ -17,7 +21,9 @@ import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; import javax.validation.Valid; +import java.util.Collection; import java.util.List; +import java.util.Set; import static cn.iocoder.mall.systemservice.enums.SystemErrorCodeEnum.*; @@ -30,6 +36,8 @@ public class RoleService { @Autowired private RoleMapper roleMapper; + @Autowired + private AdminRoleMapper adminRoleMapper; /** * 创建角色 @@ -151,4 +159,31 @@ public class RoleService { } } + /** + * 获得管理员拥有的角色编号列表 + * + * @param adminId 管理员编号 + * @return 角色编号列表 + */ + public Set listAdminRoleIds(Integer adminId) { + List adminRoleDOs = adminRoleMapper.selectByAdminId(adminId); + return CollectionUtils.convertSet(adminRoleDOs, AdminRoleDO::getRoleId); + } + + /** + * 判断角色是否有超级管理员 + * + * @param roleIds 角色编号列表 + * @return 是否有超级管理员 + */ + public boolean hasSuperAdmin(Collection roleIds) { + List roleDOs = roleMapper.selectBatchIds(roleIds); + for (RoleDO roleDO : roleDOs) { + if (RoleCodeEnum.SUPER_ADMIN.getCode().equals(roleDO.getCode())) { + return true; + } + } + return false; + } + } diff --git a/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml b/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml index dd2492cc3..bd085ecff 100644 --- a/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml +++ b/system-service-project/system-service-app/src/main/resources/mapper/AdminRoleMapper.xml @@ -1,6 +1,6 @@ - + INSERT INTO account_role ( diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourceTreeByAccountIdDTO.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourceTreeByAccountIdDTO.java deleted file mode 100644 index c1bea98e4..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/dto/authorization/AuthorizationGetResourceTreeByAccountIdDTO.java +++ /dev/null @@ -1,22 +0,0 @@ -package cn.iocoder.mall.system.biz.dto.authorization; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotNull; - -/** - * 授权模块 - 获得账号所拥有的资源树 DTO - */ -@Data -@Accessors(chain = true) -public class AuthorizationGetResourceTreeByAccountIdDTO { - - @NotNull(message = "账号编号不能为空") - private Integer accountId; - /** - * 资源类型 - */ - private Integer type; - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java index d45b244a2..0115b3f14 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/AuthorizationServiceImpl.java @@ -122,18 +122,7 @@ public class AuthorizationServiceImpl implements AuthorizationService { return Collections.emptyList(); } Set roleIds = CollectionUtil.convertSet(accountRoleDOs, AccountRoleDO::getRoleId); - // 判断是否为超管。若是超管,默认有所有权限 - if (roleService.hasSuperAdmin(roleIds)) { - return resourceService.getResourceTree(new ResourceGetTreeDTO().setType(getResourcesByAccountIdDTO.getType())); - } - // 查询角色拥有的资源关联数据 - List roleResourceDOs = roleResourceMapper.selectListByRoleIds(roleIds); - if (CollectionUtil.isEmpty(roleResourceDOs)) { - return Collections.emptyList(); - } - Set resourceIds = CollectionUtil.convertSet(roleResourceDOs, RoleResourceDO::getResourceId); - // 查询对应资源树 - return resourceService.getResourceTree(new ResourceGetTreeDTO().setIds(resourceIds).setType(getResourcesByAccountIdDTO.getType())); + } @Override diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java index f10768f22..18e4b7d5e 100644 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java +++ b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/ResourceServiceImpl.java @@ -53,30 +53,7 @@ public class ResourceServiceImpl implements ResourceService { // 获得对应的资源列表 List resourceDOs = resourceMapper.selectListByIdsAndType(getTreeDTO.getIds(), getTreeDTO.getType()); // 拼装成树 - // 使用 LinkedHashMap 的原因,是为了排序 。实际也可以用 Stream API ,就是太丑了。 - Map treeNodeMap = new LinkedHashMap<>(); - resourceDOs.stream().sorted(Comparator.comparing(ResourceDO::getSort)) - .forEach(resourceDO -> treeNodeMap.put(resourceDO.getId(), ResourceConvert.INSTANCE.convertTreeNode(resourceDO))); - // 处理父子关系 - treeNodeMap.values().stream() - .filter(node -> !node.getNode().getPid().equals(ResourceIdEnum.ROOT.getId())) - .forEach((childNode) -> { - // 获得父节点 - ResourceTreeNodeBO parentNode = treeNodeMap.get(childNode.getNode().getPid()); - if (parentNode == null) { - log.error("[getResourceTree][resource({}) 找不到父资源({})]", childNode.getNode().getId(), childNode.getNode().getPid()); - return; - } - if (parentNode.getChildren() == null) { // 初始化 children 数组 - parentNode.setChildren(new ArrayList<>()); - } - // 将自己添加到父节点中 - parentNode.getChildren().add(childNode); - }); - // 获得到所有的根节点 - return treeNodeMap.values().stream() - .filter(node -> node.getNode().getPid().equals(ResourceIdEnum.ROOT.getId())) - .collect(Collectors.toList()); + } } diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java deleted file mode 100644 index cb7cfcf4b..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleService.java +++ /dev/null @@ -1,39 +0,0 @@ -package cn.iocoder.mall.system.biz.service.authorization; - -import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleDeleteDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleGetListDTO; - -import java.util.Collection; -import java.util.List; - -/** - * 角色模块 - Service 接口 - */ -public interface RoleService { - - RoleBO getRole(Integer id); - - List getRoleList(RoleGetListDTO getListDTO); - - PageResult getRolePage(RolePageDTO pageDTO); - - /** - * 判断指定角色是否包含超级管理员角色 - * - * @param ids 角色编号数组 - * @return 是否有超级管理员角色 - */ - boolean hasSuperAdmin(Collection ids); - - Integer addRole(RoleAddDTO roleAddDTO); - - void updateRole(RoleUpdateDTO roleUpdateDTO); - - void deleteRole(RoleDeleteDTO roleDeleteDTO); - -} diff --git a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java b/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java deleted file mode 100644 index 2138e417f..000000000 --- a/system/system-biz/src/main/java/cn/iocoder/mall/system/biz/service/authorization/RoleServiceImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.mall.system.biz.service.authorization; - -import cn.iocoder.common.framework.util.ServiceExceptionUtil; -import cn.iocoder.common.framework.util.StringUtils; -import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.mybatis.enums.DeletedStatusEnum; -import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; -import cn.iocoder.mall.system.biz.convert.authorization.RoleConvert; -import cn.iocoder.mall.system.biz.dao.authorization.RoleMapper; -import cn.iocoder.mall.system.biz.dataobject.authorization.RoleDO; -import cn.iocoder.mall.system.biz.dto.authorization.*; -import cn.iocoder.mall.system.biz.enums.SystemErrorCodeEnum; -import cn.iocoder.mall.system.biz.enums.authorization.RoleCodeEnum; -import cn.iocoder.mall.system.biz.enums.authorization.RoleTypeEnum; -import cn.iocoder.mall.system.biz.event.authorization.ResourceDeleteEvent; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.Collection; -import java.util.Date; -import java.util.List; - -@Service -public class RoleServiceImpl implements RoleService { - - @Autowired - private ApplicationEventPublisher eventPublisher; - - @Autowired - private RoleMapper roleMapper; - - @Override - public PageResult getRolePage(RolePageDTO pageDTO) { - return RoleConvert.INSTANCE.convertPage(roleMapper.selectPage(pageDTO)); - } - - @Override - public boolean hasSuperAdmin(Collection ids) { - List roleDOs = roleMapper.selectBatchIds(ids); - for (RoleDO roleDO : roleDOs) { - if (RoleCodeEnum.SUPER_ADMIN.getCode().equals(roleDO.getCode())) { - return true; - } - } - return false; - } - -} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java index 73db2e86c..766c57b15 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/admin/AdminsAdminController.java @@ -22,69 +22,6 @@ import org.springframework.web.bind.annotation.RestController; @Api(tags = "管理员 - 管理员 API") public class AdminsAdminController { - @Autowired - private AdminService adminService; - - @GetMapping("/page") - @RequiresPermissions("system:admin:page") - @ApiOperation(value = "管理员分页") - public CommonResult> page(AdminsAdminPageRequest request) { - // 查询管理员分页 - AdminPageDTO pageDTO = AdminsAdminConvert.INSTANCE.convert(request); - PageResult adminPageBO = adminService.getAdminPage(pageDTO); - PageResult adminPageResponse = AdminsAdminConvert.INSTANCE.convertPage(adminPageBO); - if (adminPageResponse.getList().isEmpty()) { - return CommonResult.success(adminPageResponse); - } - // 拼接角色数据 - - - // TODO 拼接部门数据 - - // 拼接结果 -// if (!resultPage.getList().isEmpty()) { -// // 查询角色数组 -// Map> roleMap = adminService.getAdminRolesMap(CollectionUtil.convertList(resultPage.getList(), AdminBO::getId)); -// resultPage.getList().forEach(admin -> admin.setRoles(AdminConvert.INSTANCE.convertAdminVORoleList(roleMap.get(admin.getId())))); -// -// // 查询对应部门 -// List deptmentBOS = deptmentService.getAllDeptments(); -// Map deptNameMap = deptmentBOS.stream().collect(Collectors.toMap(d->d.getId(), d->d.getName())); -// //管理员所在部门被删后,变成未分配状态 -// deptNameMap.put(0, "未分配"); -// resultPage.getList().forEach(admin->{ -// admin.setDeptment(new AdminVO.Deptment(admin.getDeptmentId(), deptNameMap.get(admin.getDeptmentId()))); -// }); -// } - - return CommonResult.success(adminPageResponse); - } - -// @PostMapping("/add") -// @ApiOperation(value = "创建管理员") -// public CommonResult add(AdminAddDTO adminAddDTO) { -// return success(adminService.addAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminAddDTO)); -// } -// -// @PostMapping("/update") -// @ApiOperation(value = "更新管理员") -// public CommonResult update(AdminUpdateDTO adminUpdateDTO) { -// return success(adminService.updateAdmin(AdminSecurityContextHolder.getContext().getAdminId(), adminUpdateDTO)); -// } -// -// @PostMapping("/update_status") -// @ApiOperation(value = "更新管理员状态") -// public CommonResult updateStatus(AdminUpdateStatusDTO adminUpdateStatusDTO) { -// return success(adminService.updateAdminStatus(AdminSecurityContextHolder.getContext().getAdminId(), adminUpdateStatusDTO)); -// } -// -// @PostMapping("/delete") -// @ApiOperation(value = "删除管理员") -// @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1") -// public CommonResult delete(@RequestParam("id") Integer id) { -// return success(adminService.deleteAdmin(AdminSecurityContextHolder.getContext().getAdminId(), id)); -// } -// // @GetMapping("/role_list") // @ApiOperation(value = "指定管理员拥有的角色列表") // @ApiImplicitParam(name = "id", value = "管理员编号", required = true, example = "1") @@ -99,7 +36,7 @@ public class AdminsAdminController { // result.forEach(adminRoleVO -> adminRoleVO.setAssigned(adminRoleIdSet.contains(adminRoleVO.getId()))); // return success(result); // } -// + // @PostMapping("/assign_role") // @ApiOperation(value = "分配给管理员角色") // public CommonResult assignRole(AdminAssignRoleDTO adminAssignRoleDTO) { diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java index 9245ef3d0..2e78e610b 100644 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java +++ b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsResourceController.java @@ -38,34 +38,4 @@ public class AdminsResourceController { return CommonResult.success(AdminsResourceConvert.INSTANCE.convertList(resourceTreeNodeBOs)); } - @PostMapping("/add") - @ApiOperation(value = "创建资源", notes = "例如说,菜单资源,按钮资源") - @RequiresPermissions("system:resource:add") - public CommonResult add(AdminsResourceAddRequest request) { - ResourceAddDTO addDTO = AdminsResourceConvert.INSTANCE.convert(request) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - return CommonResult.success(resourceService.addResource(addDTO)); - } - - @PostMapping("/update") - @ApiOperation(value = "更新资源") - @RequiresPermissions("system:resource:update") - public CommonResult update(AdminsResourceUpdateRequest request) { - ResourceUpdateDTO updateDTO = AdminsResourceConvert.INSTANCE.convert(request) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - resourceService.updateResource(updateDTO); - return CommonResult.success(true); - } - - @PostMapping("/delete") - @ApiOperation(value = "删除资源") - @ApiImplicitParam(name = "id", value = "资源编号", required = true, example = "1") - @RequiresPermissions("system:resource:delete") - public CommonResult delete(@RequestParam("id") Integer id) { - ResourceDeleteDTO deleteDTO = new ResourceDeleteDTO().setId(id) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - resourceService.deleteResource(deleteDTO); - return CommonResult.success(true); - } - } diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsRoleController.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsRoleController.java deleted file mode 100644 index 4398ca43a..000000000 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/controller/authorization/AdminsRoleController.java +++ /dev/null @@ -1,75 +0,0 @@ -package cn.iocoder.mall.system.rest.controller.authorization; - -import cn.iocoder.common.framework.enums.MallConstants; -import cn.iocoder.common.framework.vo.CommonResult; -import cn.iocoder.common.framework.vo.PageResult; -import cn.iocoder.mall.security.core.annotation.RequiresPermissions; -import cn.iocoder.mall.security.core.context.AdminSecurityContextHolder; -import cn.iocoder.mall.system.biz.bo.authorization.RoleBO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleAddDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleDeleteDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RolePageDTO; -import cn.iocoder.mall.system.biz.dto.authorization.RoleUpdateDTO; -import cn.iocoder.mall.system.biz.service.authorization.RoleService; -import cn.iocoder.mall.system.rest.convert.authorization.AdminsRoleConvert; -import cn.iocoder.mall.system.rest.request.authorization.AdminsRoleAddRequest; -import cn.iocoder.mall.system.rest.request.authorization.AdminsRolePageRequest; -import cn.iocoder.mall.system.rest.request.authorization.AdminsRoleUpdateRequest; -import cn.iocoder.mall.system.rest.response.authorization.AdminsRolePageResponse; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiOperation; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping(MallConstants.ROOT_PATH_ADMIN + "/role") -@Api(tags = "管理员 - 角色 API") -public class AdminsRoleController { - - @Autowired - private RoleService roleService; - - @GetMapping("/page") - @ApiOperation(value = "角色分页") - @RequiresPermissions("system:role:page") - public CommonResult> page(AdminsRolePageRequest request) { - RolePageDTO pageDTO = AdminsRoleConvert.INSTANCE.convert(request); - PageResult pageResult = roleService.getRolePage(pageDTO); - return CommonResult.success(AdminsRoleConvert.INSTANCE.convertPage(pageResult)); - } - - @PostMapping("/add") - @ApiOperation(value = "创建角色") - @RequiresPermissions("system:role:add") - public CommonResult add(AdminsRoleAddRequest request) { - RoleAddDTO addDTO = AdminsRoleConvert.INSTANCE.convert(request) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - return CommonResult.success(roleService.addRole(addDTO)); - } - - @PostMapping("/update") - @ApiOperation(value = "更新角色") - @RequiresPermissions("system:role:update") - public CommonResult update(AdminsRoleUpdateRequest request) { - RoleUpdateDTO updateDTO = AdminsRoleConvert.INSTANCE.convert(request) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - roleService.updateRole(updateDTO); - return CommonResult.success(true); - } - - @PostMapping("/delete") - @ApiOperation(value = "删除角色") - @RequiresPermissions("system:role:delete") - @ApiImplicitParam(name = "id", value = "角色编号", required = true, example = "1") - public CommonResult delete(@RequestParam("id") Integer id) { - RoleDeleteDTO deleteDTO = new RoleDeleteDTO().setId(id) - .setAdminId(AdminSecurityContextHolder.getAdminId()); - roleService.deleteRole(deleteDTO); - return CommonResult.success(true); - } - - - - -} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java deleted file mode 100644 index 90b3d6d6b..000000000 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/authorization/AdminsRolePageResponse.java +++ /dev/null @@ -1,26 +0,0 @@ -package cn.iocoder.mall.system.rest.response.authorization; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -@ApiModel("管理员 - 角色模块 - 分页列表 Response") -@Data -@Accessors(chain = true) -public class AdminsRolePageResponse { - - @ApiModelProperty(value = "角色编号", required = true, example = "1") - private Integer id; - @ApiModelProperty(value = "角色名字", required = true, example = "管理员") - private String name; - @ApiModelProperty(value = "角色编码", example = "SUPER_ADMIN") - private String code; - @ApiModelProperty(value = "角色类型", required = true, example = "1-系统角色; 2-内置角色") - private Integer type; - @ApiModelProperty(value = "创建时间", required = true) - private Date createTime; - -} diff --git a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/user/UsersOAuth2AuthenticateResponse.java b/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/user/UsersOAuth2AuthenticateResponse.java deleted file mode 100644 index 069e33d36..000000000 --- a/system/system-rest/src/main/java/cn/iocoder/mall/system/rest/response/user/UsersOAuth2AuthenticateResponse.java +++ /dev/null @@ -1,50 +0,0 @@ -package cn.iocoder.mall.system.rest.response.user; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.experimental.Accessors; - -import java.util.Date; - -@ApiModel("用户 - OAuth2 模块 - 认证响应") -@Data -@Accessors(chain = true) -public class UsersOAuth2AuthenticateResponse { - - @Data - public static class Token { - - @ApiModelProperty(value = "access token", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") - private String accessToken; - - @ApiModelProperty(value = "refresh token", required = true, example = "001e8f49b20e47f7b3a2de774497cd50") - private String refreshToken; - - @ApiModelProperty(value = "过期时间", required = true) - private Date expiresTime; - - } - - @Data - public static class User { - - @ApiModelProperty(value = "管理员编号", required = true, example = "1") - private Integer id; - - @ApiModelProperty(value = "昵称", required = true, example = "小王") - private String nickname; - - } - - /** - * TODO 晚点测试下 swagger 的表现 - */ - private User user; - - /** - * TODO 晚点测试下 swagger 的表现 - */ - private Token token; - -}