| | |
| | | menu.setMenuType(menu.getId() == null ? 1 : menu.getMenuType()); |
| | | } |
| | | boolean isRoot = menu.getPid() == null || menu.getPid() == 0L; |
| | | if (menu.getMenuType() == 2) { |
| | | if (isRoot) { |
| | | throw new BusinessException("按钮类型只能建在菜单类型下级"); |
| | | if (menu.getId() != null && !isRoot && menu.getId().equals(menu.getPid())) { |
| | | throw new BusinessException("上级菜单不能选择当前菜单"); |
| | | } |
| | | SysMenu parent = null; |
| | | if (!isRoot) { |
| | | parent = menuMapper.selectById(menu.getPid()); |
| | | if (parent == null) { |
| | | throw new BusinessException("上级菜单不存在"); |
| | | } |
| | | SysMenu parent = menuMapper.selectById(menu.getPid()); |
| | | if (menu.getId() != null && isMenuDescendant(menu.getPid(), menu.getId())) { |
| | | throw new BusinessException("上级菜单不能选择当前菜单的下级"); |
| | | } |
| | | } |
| | | if (menu.getMenuType() == 2) { |
| | | if (parent == null || parent.getMenuType() == null || parent.getMenuType() != 1) { |
| | | throw new BusinessException("按钮类型只能建在菜单类型下级"); |
| | | } |
| | |
| | | } |
| | | menu.setUrl(null); |
| | | menu.setIcon(null); |
| | | } else if (!isRoot) { |
| | | SysMenu parent = menuMapper.selectById(menu.getPid()); |
| | | if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) { |
| | | throw new BusinessException("按钮类型下级不能再建菜单"); |
| | | } |
| | | } else if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) { |
| | | throw new BusinessException("按钮类型下级不能再建菜单"); |
| | | } |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | menu.setUpdateTime(now); |
| | |
| | | menuMapper.updateById(menu); |
| | | } |
| | | return menuMapper.selectById(menu.getId()); |
| | | } |
| | | |
| | | private boolean isMenuDescendant(Long candidateId, Long ancestorId) { |
| | | Long cursor = candidateId; |
| | | int guard = 0; |
| | | while (cursor != null && cursor != 0L && guard++ < 64) { |
| | | if (cursor.equals(ancestorId)) { |
| | | return true; |
| | | } |
| | | SysMenu current = menuMapper.selectById(cursor); |
| | | cursor = current == null ? null : current.getPid(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | if (!StringUtils.hasText(xNo)) { |
| | | return productTreeRoots(); |
| | | } |
| | | List<ProductNode> rootNodes = productNodeMapper.selectList(Wrappers.<ProductNode>lambdaQuery() |
| | | .and(wrapper -> wrapper.isNull(ProductNode::getParentId).or().eq(ProductNode::getParentId, 0L)) |
| | | .orderByAsc(ProductNode::getSortNo).orderByAsc(ProductNode::getId)); |
| | | List<ProductNode> sideNodes = productNodeMapper.selectList(Wrappers.<ProductNode>lambdaQuery() |
| | | .in(ProductNode::getLayer, Arrays.asList("side", "SIDE")) |
| | | .eq(ProductNode::getName, xNo.trim()) |
| | | .orderByAsc(ProductNode::getSortNo).orderByAsc(ProductNode::getId)); |
| | | Map<Long, ProductNode> roots = uniqueProductNodes(rootNodes); |
| | | Map<Long, ProductNode> sides = uniqueProductNodes(sideNodes); |
| | | Set<Long> branchIds = new HashSet<>(); |
| | | branchIds.addAll(roots.keySet()); |
| | | branchIds.addAll(sides.keySet()); |
| | | Map<Long, Map<String, Object>> rootRows = new LinkedHashMap<>(); |
| | | for (ProductNode root : sortProductNodes(roots.values())) { |
| | | rootRows.put(root.getId(), mapProduct(root, branchIds)); |
| | | } |
| | | for (ProductNode side : sortProductNodes(sides.values())) { |
| | | ProductNode root = findProductRoot(side); |
| | | Map<String, Object> rootRow = root == null ? null : rootRows.get(root.getId()); |
| | | if (rootRow != null) { |
| | | children(rootRow).add(mapProduct(side, branchIds)); |
| | | } |
| | | } |
| | | return new ArrayList<>(rootRows.values()); |
| | | return mapProductTreeNodes(sideNodes, Collections.emptySet()); |
| | | } |
| | | |
| | | public List<String> productXNumbers() { |