From 1d8858edafd9e4840f120e570e89a7370fe9eab9 Mon Sep 17 00:00:00 2001 From: jzfai <869653722@qq.com> Date: Wed, 13 Dec 2023 15:19:22 +0800 Subject: [PATCH] fix:the menu permission issue --- .../hugo/admin/controller/RbacController.java | 1 - .../admin/controller/SysMenuController.java | 11 ++++ .../hugo/admin/service/SysMenuService.java | 52 +++++++++++++++++-- .../controller/ConfigSaveController.java | 15 ++++-- .../controller/GeneratorController.java | 2 +- .../controller/TemplateFileController.java | 17 ++++-- .../top/hugo/generator/dto/ConfigSaveDto.java | 5 ++ .../hugo/generator/dto/TemplateChangeDto.java | 7 ++- .../hugo/generator/dto/TemplateFileDto.java | 4 ++ .../top/hugo/generator/vo/ConfigSaveVo.java | 5 ++ .../src/main/resources/mapper/RbacMapper.xml | 12 +++-- 11 files changed, 114 insertions(+), 17 deletions(-) diff --git a/hugo-admin-service/src/main/java/top/hugo/admin/controller/RbacController.java b/hugo-admin-service/src/main/java/top/hugo/admin/controller/RbacController.java index a6e807d..62c0cf8 100644 --- a/hugo-admin-service/src/main/java/top/hugo/admin/controller/RbacController.java +++ b/hugo-admin-service/src/main/java/top/hugo/admin/controller/RbacController.java @@ -97,7 +97,6 @@ public R> getUserInfo(Integer platformId) { */ @GetMapping("getMenu") public R> getMenu(Integer platformId) { - List menus = rbacService.selectMenuByUserId(LoginHelper.getUserId(), platformId); return R.ok(menus); } diff --git a/hugo-admin-service/src/main/java/top/hugo/admin/controller/SysMenuController.java b/hugo-admin-service/src/main/java/top/hugo/admin/controller/SysMenuController.java index a3a9ed1..ed228f0 100644 --- a/hugo-admin-service/src/main/java/top/hugo/admin/controller/SysMenuController.java +++ b/hugo-admin-service/src/main/java/top/hugo/admin/controller/SysMenuController.java @@ -97,6 +97,17 @@ public R remove(@PathVariable Long[] sysMenuIds) { return R.result(sysMenuService.deleteSysMenuByIds(sysMenuIds)); } + + /** + * 删除单个sysMenu + * + * @param sysMenuId sysMenuID + */ + @DeleteMapping("/{sysMenuId}") + public R remove(@PathVariable Long sysMenuId) { + return R.result(sysMenuService.deleteSysMenuById(sysMenuId)); + } + /** * 获取sysMenu选择框列表 */ diff --git a/hugo-admin-service/src/main/java/top/hugo/admin/service/SysMenuService.java b/hugo-admin-service/src/main/java/top/hugo/admin/service/SysMenuService.java index 869dcfa..4001b69 100644 --- a/hugo-admin-service/src/main/java/top/hugo/admin/service/SysMenuService.java +++ b/hugo-admin-service/src/main/java/top/hugo/admin/service/SysMenuService.java @@ -6,12 +6,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import top.hugo.admin.entity.SysMenu; import top.hugo.admin.mapper.SysMenuMapper; import top.hugo.admin.query.SysMenuQuery; import top.hugo.admin.vo.SysMenuVo; import top.hugo.domain.TableDataInfo; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -86,8 +88,10 @@ public SysMenu selectSysMenuById(Long sysMenuId) { * @param sysMenuId 平台ID * @return 结果 */ - + @Transactional(rollbackFor = Exception.class) public int deleteSysMenuById(Long sysMenuId) { + ArrayList childrenIdListByMeuId = getChildrenIdListByMeuId(sysMenuId); + sysMenuMapper.deleteBatchIds(childrenIdListByMeuId); return sysMenuMapper.deleteById(sysMenuId); } @@ -107,8 +111,9 @@ public int deleteSysMenuByIds(Long[] sysMenuIds) { * @param sysMenu 平台信息 * @return 结果 */ - public int insertSysMenu(SysMenu sysMenu) { + + return sysMenuMapper.insert(sysMenu); } @@ -119,9 +124,50 @@ public int insertSysMenu(SysMenu sysMenu) { * @param sysMenu 平台信息 * @return 结果 */ - + @Transactional(rollbackFor = Exception.class) public int updateSysMenu(SysMenu sysMenu) { + //如果是父级菜单统一设置状态 + ArrayList childrenIdList = getChildrenIdList(sysMenu.getMenuId(), sysMenu.getStatus()); + if (childrenIdList.size() > 0) { + sysMenuMapper.updateBatchById(childrenIdList); + } return sysMenuMapper.updateById(sysMenu); } + + /* + * 查询该memuId下的所有子元素 + * */ + public ArrayList getChildrenIdList(Long menuId, String status) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper(); + lqw.eq(SysMenu::getParentId, menuId); + ArrayList menuList = new ArrayList<>(); + List sysMenus = sysMenuMapper.selectList(lqw); + if (sysMenus.size() > 0) { + sysMenus.forEach(f -> { + f.setStatus(status); + menuList.add(f); + getChildrenIdList(f.getMenuId(), status); + }); + } + return menuList; + } + + + /* + * 查询该memuId下的所有子元素id + * */ + public ArrayList getChildrenIdListByMeuId(Long menuId) { + LambdaQueryWrapper lqw = new LambdaQueryWrapper(); + lqw.eq(SysMenu::getParentId, menuId); + ArrayList menuList = new ArrayList<>(); + List sysMenus = sysMenuMapper.selectList(lqw); + if (sysMenus.size() > 0) { + sysMenus.forEach(f -> { + menuList.add(f.getMenuId()); + getChildrenIdListByMeuId(f.getMenuId()); + }); + } + return menuList; + } } \ No newline at end of file diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/controller/ConfigSaveController.java b/hugo-admin-service/src/main/java/top/hugo/generator/controller/ConfigSaveController.java index 145cade..fe308ed 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/controller/ConfigSaveController.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/controller/ConfigSaveController.java @@ -35,9 +35,9 @@ public class ConfigSaveController { * @return */ @GetMapping("/listPage") - public R> list(@Validated ConfigSaveQuery configSave) { + public TableDataInfo list(@Validated ConfigSaveQuery configSave) { TableDataInfo list = configSaveService.selectPageConfigSaveList(configSave); - return R.ok(list); + return list; } /** @@ -82,6 +82,13 @@ public R edit(@Validated @RequestBody ConfigSaveDto configSaveDto) { return R.result(configSaveService.updateConfigSave(configSave)); } + + @DeleteMapping("/{configSaveIds}") + public R remove(@PathVariable Long configSaveIds) { + return R.result(configSaveService.deleteConfigSaveById(configSaveIds)); + } + + /** * 删除configSave * @@ -89,8 +96,8 @@ public R edit(@Validated @RequestBody ConfigSaveDto configSaveDto) { */ //@SaCheckPermission("system:configSave:remove") //@Log(title = "configSave管理", businessType = BusinessType.DELETE) - @DeleteMapping("/{configSaveIds}") - public R remove(@PathVariable Long[] configSaveIds) { + @DeleteMapping("deleteBatchIds") + public R remove(@RequestBody Long[] configSaveIds) { return R.result(configSaveService.deleteConfigSaveByIds(configSaveIds)); } diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/controller/GeneratorController.java b/hugo-admin-service/src/main/java/top/hugo/generator/controller/GeneratorController.java index 6ce6b0b..0e7d51e 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/controller/GeneratorController.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/controller/GeneratorController.java @@ -27,7 +27,7 @@ @Validated @RequiredArgsConstructor @RestController -@RequestMapping("/generator") +@RequestMapping("/generator/templateFile") public class GeneratorController { private final GeneratorService generatorService; diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/controller/TemplateFileController.java b/hugo-admin-service/src/main/java/top/hugo/generator/controller/TemplateFileController.java index d5e6076..1cfcde6 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/controller/TemplateFileController.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/controller/TemplateFileController.java @@ -27,16 +27,16 @@ @RestController @RequestMapping("/generator/templateFile") public class TemplateFileController { - + private final TemplateFileService templateFileService; /** * 获取templateFile列表(分页) */ @GetMapping("/listPage") - public R> list(@Validated TemplateFileQuery templateFile) { + public TableDataInfo list(@Validated TemplateFileQuery templateFile) { TableDataInfo list = templateFileService.selectPageTemplateFileList(templateFile); - return R.ok(list); + return list; } /** @@ -81,6 +81,17 @@ public R edit(@Validated @RequestBody TemplateFileDto templateFileDto) { return R.result(templateFileService.updateTemplateFile(templateFile)); } + + /** + * 删除templateFile + * + * @param templateFileId templateFileID串 + */ + @DeleteMapping("deleteById/{templateFileId}") + public R deleteTemplateFileById(@PathVariable Long templateFileId) { + return R.result(templateFileService.deleteTemplateFileById(templateFileId)); + } + /** * 删除templateFile * diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/dto/ConfigSaveDto.java b/hugo-admin-service/src/main/java/top/hugo/generator/dto/ConfigSaveDto.java index 3907127..fdf2223 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/dto/ConfigSaveDto.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/dto/ConfigSaveDto.java @@ -22,4 +22,9 @@ public class ConfigSaveDto { */ @NotBlank(message = "name不能为空") private String name; + + /** + * id + */ + private Integer id; } \ No newline at end of file diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateChangeDto.java b/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateChangeDto.java index bd7f659..948c6d9 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateChangeDto.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateChangeDto.java @@ -1,10 +1,13 @@ package top.hugo.generator.dto; import lombok.Data; -import top.hugo.generator.entity.TemplateFile; @Data -public class TemplateChangeDto extends TemplateFile { +public class TemplateChangeDto { private String fileName; private String code; + /** + * id + */ + private Integer id; } diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateFileDto.java b/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateFileDto.java index 07cfd91..2e38e5c 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateFileDto.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/dto/TemplateFileDto.java @@ -19,4 +19,8 @@ public class TemplateFileDto { * 文件存储名 */ private String name; + /** + * id + */ + private Integer id; } \ No newline at end of file diff --git a/hugo-admin-service/src/main/java/top/hugo/generator/vo/ConfigSaveVo.java b/hugo-admin-service/src/main/java/top/hugo/generator/vo/ConfigSaveVo.java index 5b13784..2d1f7d1 100644 --- a/hugo-admin-service/src/main/java/top/hugo/generator/vo/ConfigSaveVo.java +++ b/hugo-admin-service/src/main/java/top/hugo/generator/vo/ConfigSaveVo.java @@ -24,4 +24,9 @@ public class ConfigSaveVo implements Serializable { */ @ExcelProperty(value = "配置名称") private String name; + + /** + * 配置名称 + */ + private Integer id; } diff --git a/hugo-admin-service/src/main/resources/mapper/RbacMapper.xml b/hugo-admin-service/src/main/resources/mapper/RbacMapper.xml index 8d96595..7f29877 100644 --- a/hugo-admin-service/src/main/resources/mapper/RbacMapper.xml +++ b/hugo-admin-service/src/main/resources/mapper/RbacMapper.xml @@ -13,15 +13,21 @@