From 7d3040d4c742af5e13f7327e7397a0524c1ffdec Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期三, 21 二月 2024 16:06:31 +0800 Subject: [PATCH] # --- zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/MenuController.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 47 insertions(+), 4 deletions(-) diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/MenuController.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/MenuController.java index a5db7c6..1335746 100644 --- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/MenuController.java +++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/MenuController.java @@ -1,6 +1,7 @@ package com.zy.asrs.wcs.system.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zy.asrs.framework.common.Cools; import com.zy.asrs.framework.common.R; @@ -11,15 +12,14 @@ import com.zy.asrs.wcs.system.entity.Menu; import com.zy.asrs.wcs.system.service.MenuService; import com.zy.asrs.wcs.utils.ExcelUtil; +import com.zy.asrs.wcs.utils.NodeUtils; +import com.zy.asrs.wcs.utils.Utils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; @RestController @RequestMapping("/api") @@ -43,6 +43,15 @@ } @PreAuthorize("hasAuthority('system:menu:list')") + @PostMapping("/menu/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)); + } + + @PreAuthorize("hasAuthority('system:menu:list')") @GetMapping("/menu/{id}") public R get(@PathVariable("id") Long id) { return R.ok().add(menuService.getById(id)); @@ -52,6 +61,24 @@ @OperationLog("娣诲姞鑿滃崟") @PostMapping("/menu/save") public R save(@RequestBody Menu menu) { + if (menu.getParentId() != null && menu.getParentId() > 0) { + Menu parent = menuService.getById(menu.getParentId()); + if (parent != null) { + menu.setParentName(parent.getName()); + } + } else { + menu.setParentId(0L); + } + + NodeUtils nodeUtils = new NodeUtils(); + nodeUtils.generatePath0(item -> menuService.getById(item.getParentId()), menu, Menu::getId, Menu::getName, Menu::getParentId); + menu.setPath(nodeUtils.path.toString()); + menu.setPathName(nodeUtils.pathName.toString()); + + menu.setCreateBy(getLoginUserId()); + menu.setCreateTime(new Date()); + menu.setUpdateBy(getLoginUserId()); + menu.setUpdateTime(new Date()); if (!menuService.save(menu)) { return R.error("娣诲姞澶辫触"); } @@ -62,6 +89,22 @@ @OperationLog("淇敼鑿滃崟") @PostMapping("/menu/update") public R update(@RequestBody Menu menu) { + if (menu.getParentId() != null && menu.getParentId() > 0) { + Menu parent = menuService.getById(menu.getParentId()); + if (parent != null) { + menu.setParentName(parent.getName()); + } + } else { + menu.setParentId(0L); + } + + NodeUtils nodeUtils = new NodeUtils(); + nodeUtils.generatePath0(item -> menuService.getById(item.getParentId()), menu, Menu::getId, Menu::getName, Menu::getParentId); + menu.setPath(nodeUtils.path.toString()); + menu.setPathName(nodeUtils.pathName.toString()); + + menu.setUpdateBy(getLoginUserId()); + menu.setUpdateTime(new Date()); if (!menuService.updateById(menu)) { return R.error("淇敼澶辫触"); } -- Gitblit v1.9.1