| | |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @PostMapping({"/menuPda/many/{ids}", "/menuPdas/many/{ids}"}) |
| | | @PostMapping({ "/menuPda/many/{ids}", "/menuPdas/many/{ids}" }) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(menuPdaService.listByIds(Arrays.asList(ids))); |
| | | } |
| | |
| | | return R.ok().add(menuPdaService.getById(id)); |
| | | } |
| | | |
| | | // @PreAuthorize("hasAuthority('system:menu:list')") |
| | | // @PreAuthorize("hasAuthority('system:menu:list')") |
| | | @PostMapping("/menuPda/tree") |
| | | public R tree(@RequestBody Map<String, Object> map) { |
| | | // PageParam<Menu, BaseParam> param = new PageParam<>(buildParam(map, BaseParam.class), Menu.class); |
| | | // QueryWrapper<Menu> wrapper = param.buildWrapper(true, queryWrapper -> queryWrapper.orderByAsc("sort")); |
| | | // List<Menu> menus = menuService.list(wrapper); |
| | | // return R.ok().add(Utils.toTreeData(menus, 0L, Menu::getParentId, Menu::getId, Menu::setChildren)); |
| | | // PageParam<Menu, BaseParam> param = new PageParam<>(buildParam(map, |
| | | // BaseParam.class), Menu.class); |
| | | // QueryWrapper<Menu> wrapper = param.buildWrapper(true, queryWrapper -> |
| | | // queryWrapper.orderByAsc("sort")); |
| | | // List<Menu> menus = menuService.list(wrapper); |
| | | // return R.ok().add(Utils.toTreeData(menus, 0L, Menu::getParentId, Menu::getId, |
| | | // Menu::setChildren)); |
| | | List<MenuPda> menuList = menuPdaService.list(new LambdaQueryWrapper<MenuPda>().orderByAsc(MenuPda::getSort)); |
| | | List<MenuPda> treeData = Utils.toTreeData(menuList, 0L, MenuPda::getParentId, MenuPda::getId, MenuPda::setChildren); |
| | | List<MenuPda> treeData = Utils.toTreeData(menuList, 0L, MenuPda::getParentId, MenuPda::getId, |
| | | MenuPda::setChildren); |
| | | if (!Cools.isEmpty(map.get("condition"))) { |
| | | Utils.treeRemove(treeData, String.valueOf(map.get("condition")), MenuPda::getName, MenuPda::getChildren); |
| | | Utils.treeRemove(treeData, String.valueOf(map.get("condition")), MenuPda::getName, MenuPda::getChildren); |
| | |
| | | @OperationLog("Save Menu") |
| | | @PostMapping("/menuPda/save") |
| | | public R save(@RequestBody MenuPda menu) { |
| | | MenuPda parent = null; |
| | | if (menu.getParentId() != null && menu.getParentId() > 0) { |
| | | MenuPda parent = menuPdaService.getById(menu.getParentId()); |
| | | parent = menuPdaService.getById(menu.getParentId()); |
| | | if (parent != null) { |
| | | menu.setParentName(parent.getName()); |
| | | } |
| | |
| | | } |
| | | |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), menu, MenuPda::getId, MenuPda::getName, MenuPda::getParentId); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), menu, MenuPda::getId, |
| | | MenuPda::getName, MenuPda::getParentId); |
| | | menu.setPath(nodeUtils.path.toString()); |
| | | menu.setPathName(nodeUtils.pathName.toString()); |
| | | |
| | |
| | | if (!menuPdaService.save(menu)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | | |
| | | // 如果是第二级菜单(parent的parentId为0,且当前菜单是菜单类型),自动创建reset和submit按钮 |
| | | if (parent != null && parent.getParentId() != null && parent.getParentId() == 0L |
| | | && (menu.getType() == null || menu.getType() == MenuPda.TYPE_MENU)) { |
| | | createButtonForMenu(menu, "reset", "重置", 1); |
| | | createButtonForMenu(menu, "submit", "提交", 2); |
| | | } |
| | | |
| | | return R.ok("Save Success").add(menu); |
| | | } |
| | | |
| | | /** |
| | | * 为菜单创建按钮 |
| | | */ |
| | | private void createButtonForMenu(MenuPda parentMenu, String code, String name, int sort) { |
| | | MenuPda button = new MenuPda(); |
| | | button.setName(name); |
| | | button.setParentId(parentMenu.getId()); |
| | | button.setParentName(parentMenu.getName()); |
| | | button.setRoute(code); |
| | | button.setType(MenuPda.TYPE_BTN); |
| | | button.setSort(sort); |
| | | button.setStatus(1); |
| | | button.setDeleted(0); |
| | | button.setTenantId(parentMenu.getTenantId()); |
| | | |
| | | // 生成路径 |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), button, MenuPda::getId, |
| | | MenuPda::getName, MenuPda::getParentId); |
| | | button.setPath(nodeUtils.path.toString()); |
| | | button.setPathName(nodeUtils.pathName.toString()); |
| | | |
| | | button.setCreateBy(getLoginUserId()); |
| | | button.setCreateTime(new Date()); |
| | | button.setUpdateBy(getLoginUserId()); |
| | | button.setUpdateTime(new Date()); |
| | | |
| | | menuPdaService.save(button); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:menu:update')") |
| | |
| | | } |
| | | |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), menu, MenuPda::getId, MenuPda::getName, MenuPda::getParentId); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), menu, MenuPda::getId, |
| | | MenuPda::getName, MenuPda::getParentId); |
| | | menu.setPath(nodeUtils.path.toString()); |
| | | menu.setPathName(nodeUtils.pathName.toString()); |
| | | |
| | |
| | | wrapper.like(MenuPda::getName, condition); |
| | | } |
| | | menuPdaService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | ); |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName()))); |
| | | return R.ok().add(vos); |
| | | } |
| | | |