| | |
| | | */ |
| | | package org.springblade.modules.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.common.cache.SysCache; |
| | | import org.springblade.common.constant.CommonConstant; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.BladeUser; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | |
| | | private final static Integer MENU_CATEGORY = 1; |
| | | |
| | | @Resource |
| | | private IUserHouseLabelService iUserHouseLabelService; |
| | | private final IUserHouseLabelService iUserHouseLabelService; |
| | | |
| | | @Override |
| | | public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) { |
| | | if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) { |
| | | parentId = null; |
| | | } |
| | | return baseMapper.lazyList(parentId, param); |
| | | List<MenuVO> menuVOS = baseMapper.lazyList(parentId, param); |
| | | for (MenuVO menuVO : menuVOS) { |
| | | if (StringUtils.isNotBlank(menuVO.getLabelStr())) { |
| | | List<List<String>> lists = (List<List<String>>) JSON.parse(menuVO.getLabelStr()); |
| | | menuVO.setLabelList(lists); |
| | | } |
| | | } |
| | | return menuVOS; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) { |
| | | parentId = null; |
| | | } |
| | | return baseMapper.lazyMenuList(parentId, param); |
| | | List<MenuVO> menuVOS = baseMapper.lazyList(parentId, param); |
| | | for (MenuVO menuVO : menuVOS) { |
| | | if (StringUtils.isNotBlank(menuVO.getLabelStr())) { |
| | | List<List<String>> lists = (List<List<String>>) JSON.parse(menuVO.getLabelStr()); |
| | | menuVO.setLabelList(lists); |
| | | } |
| | | } |
| | | return menuVOS; |
| | | } |
| | | |
| | | public static final List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5, 6, 11, null); |
| | | public static final List<Integer> list2 = Arrays.asList(1, 11, null); |
| | | |
| | | /** |
| | | * apache测试方法 |
| | | */ |
| | | public static void main(String[] args) { |
| | | System.out.println("交集:" + CollectionUtils.intersection(list1, list2)); // 交集 |
| | | System.out.println("补集:" + CollectionUtils.disjunction(list1, list2)); // 补集 |
| | | System.out.println("并集:" + CollectionUtils.union(list1, list2)); // 并集 |
| | | System.out.println("list1的差集:" + CollectionUtils.subtract(list1, list2)); // list1的差集 |
| | | System.out.println("list2的差集:" + CollectionUtils.subtract(list2, list1)); // list2的差集 |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param roleId |
| | | * @param topMenuId |
| | | * @param labelType |
| | | * @param menuType |
| | | * @param roleName |
| | | * @param houseCode |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType) { |
| | | public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType, Integer menuType, String roleName,String houseCode) { |
| | | if (StringUtil.isBlank(roleId)) { |
| | | return null; |
| | | } |
| | | List<Menu> allMenus = baseMapper.allMenu(); |
| | | List<Menu> allMenus = baseMapper.selectList(Wrappers.<Menu>lambdaQuery().eq(Menu::getCategory, 1).eq(Menu::getMenuType, menuType)); |
| | | List<Menu> roleMenus; |
| | | // 超级管理员并且不是顶部菜单请求则返回全部菜单 |
| | | if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) { |
| | |
| | | } |
| | | // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单 |
| | | else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) { |
| | | roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId))); |
| | | UserHouseLabelDTO userHouseLabelDTO = new UserHouseLabelDTO(); |
| | | userHouseLabelDTO.setUserId(AuthUtil.getUserId()); |
| | | userHouseLabelDTO.setLableType(labelType); |
| | | List<Integer> integers = iUserHouseLabelService.selectUserLabelList(userHouseLabelDTO); |
| | | Iterator<Menu> iterator = roleMenus.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Menu next = iterator.next(); |
| | | if (!next.getParentId().equals(0)) { |
| | | if (StringUtils.isNotBlank(next.getLabelId())) { |
| | | String[] split = next.getLabelId().split(","); |
| | | List<Integer> integerList = Arrays.stream(split).map(Integer::valueOf).collect(Collectors.toList()); |
| | | Collection<? extends Serializable> union = CollectionUtils.intersection(integerList, integers); |
| | | if (union.size() == 0) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId), menuType)); |
| | | // 1:居民,居民需要通过人的标签来显示取保候审 |
| | | if (CommonConstant.RESIDENT.equals(roleName)) { |
| | | extracted(labelType, roleMenus,houseCode); |
| | | } |
| | | } |
| | | // 顶部菜单请求返回对应角色权限菜单 |
| | | else { |
| | | // 角色配置对应菜单 |
| | | List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId)); |
| | | List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId), menuType); |
| | | // 反向递归角色菜单所有父级 |
| | | List<Menu> routes = new LinkedList<>(roleIdMenus); |
| | | roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu)); |
| | |
| | | } |
| | | |
| | | return buildRoutes(allMenus, roleMenus); |
| | | } |
| | | |
| | | /** |
| | | * 房屋的时候才通过人的标签过滤 |
| | | * |
| | | * @param roleMenus |
| | | * @param labelType |
| | | */ |
| | | private void extracted(Integer labelType, List<Menu> roleMenus,String houseCode) { |
| | | UserHouseLabelDTO userHouseLabelDTO = new UserHouseLabelDTO(); |
| | | userHouseLabelDTO.setUserId(AuthUtil.getUserId()); |
| | | userHouseLabelDTO.setLableType(labelType); |
| | | userHouseLabelDTO.setHouseCode(houseCode); |
| | | List<Integer> integers = iUserHouseLabelService.selectUserLabelList(userHouseLabelDTO); |
| | | Iterator<Menu> iterator = roleMenus.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Menu next = iterator.next(); |
| | | if (!next.getParentId().equals(0)) { |
| | | if (StringUtils.isNotBlank(next.getLabelId())) { |
| | | String[] split = next.getLabelId().split(","); |
| | | List<Integer> integerList = Arrays.stream(split).map(Integer::valueOf).collect(Collectors.toList()); |
| | | Collection<? extends Serializable> union = CollectionUtils.intersection(integerList, integers); |
| | | if (union.size() == 0) { |
| | | iterator.remove(); |
| | | |
| | | // 场所的时候,删除取保候审 |
| | | } else if (CommonConstant.NUMBER_TWO.equals(labelType)) { |
| | | if (next.getName().trim().equals("取保监居")) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } else { |
| | | if (next.getName().trim().equals("取保监居")) { |
| | | iterator.remove(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean submit(Menu menu) { |
| | | public boolean submit(MenuDTO menu) { |
| | | LambdaQueryWrapper<Menu> menuQueryWrapper = Wrappers.lambdaQuery(); |
| | | if (menu.getId() == null) { |
| | | menuQueryWrapper.eq(Menu::getCode, menu.getCode()).or( |
| | | wrapper -> wrapper.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) |
| | | ); |
| | | } else { |
| | | menuQueryWrapper.ne(Menu::getId, menu.getId()).eq(Menu::getIsDeleted,0).and( |
| | | menuQueryWrapper.ne(Menu::getId, menu.getId()).eq(Menu::getIsDeleted, 0).and( |
| | | wrapper -> wrapper.eq(Menu::getCode, menu.getCode()).or( |
| | | o -> o.eq(Menu::getName, menu.getName()).eq(Menu::getCategory, MENU_CATEGORY) |
| | | ) |
| | |
| | | throw new ServiceException("父节点只可选择菜单类型!"); |
| | | } |
| | | } |
| | | menu.setLabelStr(JSON.toJSONString(menu.getLabelList())); |
| | | List<List<String>> labelList = menu.getLabelList(); |
| | | StringBuffer stringBuffer = new StringBuffer(); |
| | | for (List<String> strings : labelList) { |
| | | stringBuffer.append(strings.get(strings.size() - 1)).append(","); |
| | | } |
| | | menu.setLabelId(stringBuffer.toString()); |
| | | menu.setIsDeleted(BladeConstant.DB_NOT_DELETED); |
| | | return saveOrUpdate(menu); |
| | | } |