-- 角色表
CREATE TABLE `vip_boss_role` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键,自增',
`name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '角色名称',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态【0、启用、1、禁用】',
`shop_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '对应商户 ID',
`account_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '账号类型,1-主账号;2-操作员账号;3-子账号;4-管理员账号',
`remark` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='oem角色表';
-- 菜单表
CREATE TABLE `vip_boss_menu` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`pid` bigint(20) NOT NULL DEFAULT '0' COMMENT '父节点id',
`name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '菜单名称',
`code` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '资源唯一业务编码',
`type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '类型:0:菜单,1:功能;2:隐藏菜单',
`sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序',
`url` varchar(500) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'URL地址',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态【0、启用、1、禁用】',
`icon` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '菜单图标',
`remark` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '备注',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uniq_code` (`code`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='boss菜单表';
-- 角色菜单表
CREATE TABLE `vip_boss_role_menu` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`role_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '角色id',
`menu_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '菜单id',
`is_deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否删除(0:未删除 1:已删除)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uniq_role_menu_id` (`role_id`,`menu_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=462 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='boss角色菜单关联表';
-- 用户角色表
CREATE TABLE `vip_boss_account_role` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键,自增',
`account_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '用户ID',
`role_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '角色ID',
`is_deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否删除(0:未删除 1:已删除)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uniq_user_role_id` (`account_id`,`role_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='boss用户角色关联表';
public List<BossMenuPermissionDto> getAllEnableMenuList(Integer accountType) {
List<BossMenuPermissionDto> list = Lists.newArrayList();
VipBossMenuDto condition = new VipBossMenuDto();
condition.setStatus(BossEnableOrDisableEnum.ENABLE.getVal());
// 查询可用的菜单
List<VipBossMenuDto> menuList = query(condition);
if (CollectionUtilsExt.isNotEmpty(menuList)) {
ArrayList<String> temp = Lists.newArrayList();
String permissionMenu = AppConfig.BOSS_PERMOSSION_MENU;
if (StringUtilsExt.isNotBlank(permissionMenu)) {
String[] strArray = AppConfig.BOSS_PERMOSSION_MENU.split(",");
Collections.addAll(temp, strArray);
}
//权限菜单是否展示
boolean hideMenu = false;
if (accountType != null && VipAccountTypeEnum.OPERATION.getVal() == accountType && CollectionUtilsExt.isNotEmpty(temp)) {
hideMenu = true;
}
// 一级菜单 key为id
Map<Long, BossMenuPermissionDto> rootMenuMap = Maps.newHashMap();
// 二级菜单与一级菜单对应关系 key为父节点
Map<Long, List<BossMenuPermissionDto>> nextMenuMap = Maps.newHashMap();
// 三级功能点 key为父节点
Map<Long, List<BossMenuPermissionDto>> permissionMenuMap = Maps.newHashMap();
for (VipBossMenuDto p : menuList) {
if (hideMenu && temp.contains(p.getCode())) {
continue;
}
BossMenuPermissionDto dto = new BossMenuPermissionDto();
dto.setId(p.getId());
dto.setName(p.getName());
dto.setType(p.getType());
dto.setCode(p.getCode());
dto.setSort(p.getSort());
dto.setPath(p.getUrl());
if (MenuTypeEnum.FUNCTION.getVal().equals(p.getType())) {
// 功能
if (permissionMenuMap.containsKey(p.getPid())) {
permissionMenuMap.get(p.getPid()).add(dto);
} else {
List<BossMenuPermissionDto> permissionMenuList = Lists.newArrayList();
permissionMenuList.add(dto);
permissionMenuMap.put(p.getPid(), permissionMenuList);
}
} else {
// 菜单
if (StringUtilsExt.isNotEmpty(p.getPid())) {
// 二级菜单
if (nextMenuMap.containsKey(p.getPid())) {
nextMenuMap.get(p.getPid()).add(dto);
} else {
List<BossMenuPermissionDto> nextMenuList = Lists.newArrayList();
nextMenuList.add(dto);
nextMenuMap.put(p.getPid(), nextMenuList);
}
} else {
// 一级菜单
rootMenuMap.put(p.getId(), dto);
}
}
}
for (Map.Entry<Long, List<BossMenuPermissionDto>> entry : nextMenuMap.entrySet()) {
// 将功能与二级菜单合并
for (BossMenuPermissionDto nextMenuDto : entry.getValue()) {
if (permissionMenuMap.containsKey(nextMenuDto.getId())) {
nextMenuDto.setChildren(permissionMenuMap.get(nextMenuDto.getId()));
}
}
// 将二级菜单与一级合并
if (rootMenuMap.containsKey(entry.getKey())) {
rootMenuMap.get(entry.getKey()).setChildren(entry.getValue());
}
}
for (Map.Entry<Long, BossMenuPermissionDto> entry : rootMenuMap.entrySet()) {
// 将功能与一级菜单合并
if (permissionMenuMap.containsKey(entry.getKey())) {
if (entry.getValue().getChildren() == null) {
entry.getValue().setChildren(permissionMenuMap.get(entry.getKey()));
} else {
entry.getValue().getChildren().addAll(permissionMenuMap.get(entry.getKey()));
}
}
}
list = Lists.newArrayList(rootMenuMap.values());
Collections.sort(list, (BossMenuPermissionDto a, BossMenuPermissionDto b) -> a.getSort().compareTo(b.getSort()));
list.forEach(p -> {
if (CollectionUtilsExt.isNotEmpty(p.getChildren())) {
Collections.sort(p.getChildren(), (BossMenuPermissionDto a, BossMenuPermissionDto b) -> a.getSort().compareTo(b.getSort()));
p.getChildren().forEach(m -> {
if (CollectionUtilsExt.isNotEmpty(m.getChildren())) {
Collections.sort(m.getChildren(), (BossMenuPermissionDto a, BossMenuPermissionDto b) -> a.getSort().compareTo(b.getSort()));
} else {
m.setType(VipMenuTypeEnum.FUNCTION.getVal());
}
});
} else {
p.setType(VipMenuTypeEnum.FUNCTION.getVal());
}
});
}
return list;
}