【menu】更新antdv需要的一个获取所有菜单接口

pull/3/head
fengshuonan 2021-01-07 18:41:12 +08:00
parent d5d598631d
commit e2e1a15d10
12 changed files with 240 additions and 137 deletions

View File

@ -26,9 +26,4 @@ public class SimpleRoleInfo {
*/
private String roleCode;
/**
* 10-20-30-40-50-
*/
private Integer dataScopeType;
}

View File

@ -0,0 +1,57 @@
package cn.stylefeng.roses.kernel.system.pojo.menu.antd;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
import lombok.Data;
import java.util.List;
/**
*
*
* @author majianguo
* @date 2021/1/7 15:18
*/
@Data
public class AntdSysMenuResponse {
/**
*
*/
private Long menuId;
/**
* idid-1
*/
private Long menuParentId;
/**
*
*/
private String menuName;
/**
* URL/menuantd vue
*/
private String antdvRouter;
/**
* antdvue
*/
private String antdvPath;
/**
* antd vue
*/
private String antdvIcon;
/**
*
*/
private List children;
/**
* 访
*/
private List<SimpleRoleInfo> roles;
}

View File

@ -1,97 +0,0 @@
package cn.stylefeng.roses.kernel.system.pojo.menu.response;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractTreeNode;
import lombok.Data;
import java.util.List;
/**
*
*
* @author majianguo
* @date 2021/1/7 15:18
*/
@Data
public class SysMenuResponse implements AbstractTreeNode {
/**
*
*/
private Long menuId;
/**
* idid-1
*/
private Long menuParentId;
/**
* id
*/
private String menuPids;
/**
*
*/
private String menuName;
/**
*
*/
private String appCode;
/**
* Y-N-
*/
private String visible;
/**
* URL/menuantd vue
*/
private String antdvRouter;
/**
* antd vue
*/
private String antdvComponent;
/**
* antd vue
*/
private String antdvIcon;
/**
* 1-2-antd vue
*/
private Integer antdvLinkOpenType;
/**
*
*/
private String antdvLinkUrl;
/**
*
*/
private List children;
/**
* 访
*/
private List<SimpleRoleInfo> roles;
@Override
public String getNodeId() {
return menuId.toString();
}
@Override
public String getNodeParentId() {
return menuParentId.toString();
}
@Override
public void setChildrenNodes(List childrenNodes) {
this.children = childrenNodes;
}
}

View File

@ -1,5 +1,7 @@
package cn.stylefeng.roses.kernel.menu.modular.controller;
import cn.stylefeng.roses.kernel.menu.modular.factory.AntdMenusFactory;
import cn.stylefeng.roses.kernel.menu.modular.pojo.AntdvMenuItem;
import cn.stylefeng.roses.kernel.menu.modular.service.SysMenuService;
import cn.stylefeng.roses.kernel.resource.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.resource.api.annotation.GetResource;
@ -7,7 +9,7 @@ import cn.stylefeng.roses.kernel.resource.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
@ -143,15 +145,16 @@ public class SysMenuController {
}
/**
*
* antd vue
*
* @author majianguo
* @date 2021/1/7 15:17
*/
@GetResource(name = "获取菜单列表(包含菜单可以被那些角色访问)", path = "/sysMenu/getSystemAllMenus", requiredPermission = false)
public ResponseData getSystemAllMenus() {
List<SysMenuResponse> sysMenuResponses = sysMenuService.getSystemAllMenus();
return new SuccessResponseData(sysMenuResponses);
@GetResource(name = "获取系统所有菜单适用于登录后获取左侧菜单适配antd vue版本", path = "/sysMenu/getSystemAllMenusAntdv", requiredPermission = false)
public ResponseData getSystemAllMenusAntdv() {
List<AntdSysMenuResponse> sysMenuResponses = sysMenuService.getSystemAllMenusAntdv();
List<AntdvMenuItem> totalMenus = AntdMenusFactory.createTotalMenus(sysMenuResponses);
return new SuccessResponseData(totalMenus);
}
}

View File

@ -101,10 +101,10 @@ public class SysMenu extends BaseEntity implements AbstractTreeNode {
private String antdvRouter;
/**
* antd vue
* antdvue
*/
@TableField("antdv_component")
private String antdvComponent;
@TableField("antdv_path")
private String antdvPath;
/**
* antd vue
@ -112,6 +112,12 @@ public class SysMenu extends BaseEntity implements AbstractTreeNode {
@TableField("antdv_icon")
private String antdvIcon;
/**
* antd vue
*/
@TableField("antdv_component")
private String antdvComponent;
/**
* 1-2-antd vue
*/

View File

@ -1,9 +1,14 @@
package cn.stylefeng.roses.kernel.menu.modular.factory;
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
import cn.stylefeng.roses.kernel.menu.modular.pojo.AntdvMenuItem;
import cn.stylefeng.roses.kernel.menu.modular.pojo.AuthorityItem;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
import java.util.ArrayList;
import java.util.List;
@ -16,6 +21,50 @@ import java.util.List;
*/
public class AntdMenusFactory {
/**
* antdv
*
* @author fengshuonan
* @date 2021/1/7 18:17
*/
public static List<AntdvMenuItem> createTotalMenus(List<AntdSysMenuResponse> antdSysMenuResponses) {
ArrayList<AntdvMenuItem> antdvMenuItems = new ArrayList<>(antdSysMenuResponses.size());
// 实体转化
for (AntdSysMenuResponse antdSysMenuResponse : antdSysMenuResponses) {
AntdvMenuItem antdvMenuItem = new AntdvMenuItem();
// 填充id pid name用于构建树
antdvMenuItem.setMenuId(antdSysMenuResponse.getMenuId());
antdvMenuItem.setMenuParentId(antdSysMenuResponse.getMenuParentId());
antdvMenuItem.setName(antdSysMenuResponse.getMenuName());
// 填充路由等信息
antdvMenuItem.setRouter(antdSysMenuResponse.getAntdvRouter());
antdvMenuItem.setIcon(antdSysMenuResponse.getAntdvIcon());
antdvMenuItem.setPath(antdSysMenuResponse.getAntdvPath());
// 填充哪个角色绑定了这个菜单
List<SimpleRoleInfo> roles = antdSysMenuResponse.getRoles();
AuthorityItem authorityItem = new AuthorityItem();
if (roles != null) {
ArrayList<String> auths = new ArrayList<>();
for (SimpleRoleInfo role : roles) {
auths.add(role.getRoleCode());
}
authorityItem.setPermission(auths);
authorityItem.setRole(auths);
antdvMenuItem.setAuthority(authorityItem);
}
antdvMenuItems.add(antdvMenuItem);
}
// 构造菜单树
return new DefaultTreeBuildFactory<AntdvMenuItem>().doTreeBuild(antdvMenuItems);
}
/**
* vue antd admin
*

View File

@ -1,7 +1,7 @@
package cn.stylefeng.roses.kernel.menu.modular.mapper;
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;
@ -15,10 +15,12 @@ import java.util.List;
public interface SysMenuMapper extends BaseMapper<SysMenu> {
/**
*
* antd vue
*
* @return
* @author majianguo
* @date 2021/1/7 15:27
*/
List<SysMenuResponse> getSystemAllMenus();
List<AntdSysMenuResponse> getSystemAllMenus();
}

View File

@ -2,46 +2,35 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.stylefeng.roses.kernel.menu.modular.mapper.SysMenuMapper">
<resultMap id="systemMenuAndRole" type="cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse">
<resultMap id="systemMenuAndRole" type="cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse">
<id column="menu_id" property="menuId"/>
<result column="menu_parent_id" property="menuParentId"/>
<result column="menu_pids" property="menuPids"/>
<result column="menu_name" property="menuName"/>
<result column="app_code" property="appCode"/>
<result column="visible" property="visible"/>
<result column="antdv_router" property="antdvRouter"/>
<result column="antdv_component" property="antdvComponent"/>
<result column="antdv_path" property="antdvPath"/>
<result column="antdv_icon" property="antdvIcon"/>
<result column="antdv_link_open_type" property="antdvLinkOpenType"/>
<result column="antdv_link_url" property="antdvLinkUrl"/>
<collection property="roles" ofType="cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo">
<id column="role_id" property="roleId"/>
<result column="role_name" property="roleName"/>
<result column="role_code" property="roleCode"/>
<result column="data_scope_type" property="dataScopeType"/>
</collection>
</resultMap>
<select id="getSystemAllMenus" resultMap="systemMenuAndRole">
SELECT sm.menu_id,
sm.menu_parent_id,
sm.menu_pids,
sm.menu_name,
sm.app_code,
sm.visible,
sm.antdv_router,
sm.antdv_component,
sm.antdv_path,
sm.antdv_icon,
sm.antdv_link_open_type,
sm.antdv_link_url,
sr.role_id,
sr.role_name,
sr.role_code,
sr.data_scope_type
sr.role_code
FROM sys_menu sm
LEFT JOIN sys_role_menu srm ON sm.menu_id = srm.menu_id
LEFT JOIN sys_role sr ON srm.role_id = sr.role_id
WHERE sm.del_flag = 'N'
AND sm.status_flag = 1
</select>
</mapper>

View File

@ -0,0 +1,72 @@
package cn.stylefeng.roses.kernel.menu.modular.pojo;
import cn.stylefeng.roses.kernel.rule.abstracts.AbstractTreeNode;
import lombok.Data;
import java.util.List;
/**
* antdv
*
* @author fengshuonan
* @date 2021/1/7 18:09
*/
@Data
public class AntdvMenuItem implements AbstractTreeNode {
/**
*
*/
private Long menuId;
/**
* idid-1
*/
private Long menuParentId;
/**
*
*/
private String router;
/**
*
*/
private String icon;
/**
*
*/
private String path;
/**
*
*/
private String name;
/**
*
*/
private AuthorityItem authority;
/**
*
*/
private List<AntdvMenuItem> children;
@Override
public String getNodeId() {
return menuId.toString();
}
@Override
public String getNodeParentId() {
return menuParentId.toString();
}
@Override
public void setChildrenNodes(List childrenNodes) {
this.children = childrenNodes;
}
}

View File

@ -0,0 +1,26 @@
package cn.stylefeng.roses.kernel.menu.modular.pojo;
import lombok.Data;
import java.util.List;
/**
*
*
* @author fengshuonan
* @date 2021/1/7 18:16
*/
@Data
public class AuthorityItem {
/**
*
*/
private List<String> permission;
/**
*
*/
private List<String> role;
}

View File

@ -27,9 +27,9 @@ package cn.stylefeng.roses.kernel.menu.modular.service;
import cn.stylefeng.roses.kernel.menu.modular.entity.SysMenu;
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
import cn.stylefeng.roses.kernel.system.pojo.menu.other.MenuSelectTreeNode;
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import com.baomidou.mybatisplus.extension.service.IService;
@ -163,10 +163,12 @@ public interface SysMenuService extends IService<SysMenu> {
List<MenuSelectTreeNode> treeForGrant(SysMenuRequest sysMenuRequest);
/**
*
* antd vue
*
* @return
* @author majianguo
* @date 2021/1/7 15:24
*/
List<SysMenuResponse> getSystemAllMenus();
List<AntdSysMenuResponse> getSystemAllMenusAntdv();
}

View File

@ -52,9 +52,9 @@ import cn.stylefeng.roses.kernel.system.exception.enums.SysMenuExceptionEnum;
import cn.stylefeng.roses.kernel.system.exception.enums.SysUserExceptionEnum;
import cn.stylefeng.roses.kernel.system.pojo.menu.SysMenuRequest;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdIndexMenuTreeNode;
import cn.stylefeng.roses.kernel.system.pojo.menu.antd.AntdSysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.menu.layui.LayuiAppIndexMenus;
import cn.stylefeng.roses.kernel.system.pojo.menu.other.MenuSelectTreeNode;
import cn.stylefeng.roses.kernel.system.pojo.menu.response.SysMenuResponse;
import cn.stylefeng.roses.kernel.system.pojo.ztree.ZTreeNode;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -288,9 +288,8 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
}
@Override
public List<SysMenuResponse> getSystemAllMenus() {
List<SysMenuResponse> responses = this.baseMapper.getSystemAllMenus();
return new DefaultTreeBuildFactory<SysMenuResponse>().doTreeBuild(responses);
public List<AntdSysMenuResponse> getSystemAllMenusAntdv() {
return this.baseMapper.getSystemAllMenus();
}
@Override