| New file |
| | |
| | | package com.vincent.rsf.server.manager.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.vincent.rsf.common.utils.Utils; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.annotation.OperationLog; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.KeyValVo; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.common.utils.NodeUtils; |
| | | import com.vincent.rsf.server.manager.entity.MenuPda; |
| | | import com.vincent.rsf.server.manager.service.MenuPdaService; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import com.vincent.rsf.server.system.entity.Menu; |
| | | 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.*; |
| | | |
| | | @RestController |
| | | public class MenuPdaController extends BaseController { |
| | | |
| | | @Autowired |
| | | private MenuPdaService menuPdaService; |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @PostMapping("/menuPda/page") |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<MenuPda, BaseParam> pageParam = new PageParam<>(baseParam, MenuPda.class); |
| | | return R.ok().add(menuPdaService.page(pageParam, pageParam.buildWrapper(true))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @PostMapping("/menuPda/list") |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(menuPdaService.list()); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @PostMapping({"/menuPda/many/{ids}", "/menuPdas/many/{ids}"}) |
| | | public R many(@PathVariable Long[] ids) { |
| | | return R.ok().add(menuPdaService.listByIds(Arrays.asList(ids))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @GetMapping("/menuPda/{id}") |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(menuPdaService.getById(id)); |
| | | } |
| | | |
| | | // @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)); |
| | | List<MenuPda> menuList = menuPdaService.list(new LambdaQueryWrapper<MenuPda>().orderByAsc(MenuPda::getSort)); |
| | | 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); |
| | | } |
| | | return R.ok().add(treeData); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:menu:save')") |
| | | @OperationLog("Save Menu") |
| | | @PostMapping("/menuPda/save") |
| | | public R save(@RequestBody MenuPda menu) { |
| | | if (menu.getParentId() != null && menu.getParentId() > 0) { |
| | | MenuPda parent = menuPdaService.getById(menu.getParentId()); |
| | | if (parent != null) { |
| | | menu.setParentName(parent.getName()); |
| | | } |
| | | } else { |
| | | menu.setParentId(0L); |
| | | } |
| | | |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), menu, MenuPda::getId, MenuPda::getName, MenuPda::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 (!menuPdaService.save(menu)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | | return R.ok("Save Success").add(menu); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:menu:update')") |
| | | @OperationLog("Update Menu") |
| | | @PostMapping("/menuPda/update") |
| | | public R update(@RequestBody MenuPda menu) { |
| | | if (menu.getParentId() != null && menu.getParentId() > 0) { |
| | | MenuPda parent = menuPdaService.getById(menu.getParentId()); |
| | | if (parent != null) { |
| | | menu.setParentName(parent.getName()); |
| | | } |
| | | } else { |
| | | menu.setParentId(0L); |
| | | } |
| | | |
| | | NodeUtils nodeUtils = new NodeUtils(); |
| | | nodeUtils.generatePath0(item -> menuPdaService.getById(item.getParentId()), menu, MenuPda::getId, MenuPda::getName, MenuPda::getParentId); |
| | | menu.setPath(nodeUtils.path.toString()); |
| | | menu.setPathName(nodeUtils.pathName.toString()); |
| | | |
| | | menu.setUpdateBy(getLoginUserId()); |
| | | menu.setUpdateTime(new Date()); |
| | | if (!menuPdaService.updateById(menu)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | return R.ok("Update Success").add(menu); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:remove')") |
| | | @OperationLog("Delete PDA权限") |
| | | @PostMapping("/menuPda/remove/{ids}") |
| | | public R remove(@PathVariable Long[] ids) { |
| | | if (!menuPdaService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("Delete Fail"); |
| | | } |
| | | return R.ok("Delete Success").add(ids); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @PostMapping("/menuPda/query") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<MenuPda> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(MenuPda::getName, condition); |
| | | } |
| | | menuPdaService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('manager:menuPda:list')") |
| | | @PostMapping("/menuPda/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(menuPdaService.list(), MenuPda.class), response); |
| | | } |
| | | |
| | | } |