diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java index 38a6c0d33a..e62ed4b7ce 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/Constant.java @@ -35,6 +35,10 @@ public interface Constant { * 菜单根节点标识 */ Long MENU_ROOT = 0L; + /** + * 菜单根节点标识 + */ + String OPER_MENU_ROOT = "0"; /** * 部门根节点标识 */ diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/TreeUtils.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/TreeUtils.java index b78c8317ef..4272d9cfc6 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/TreeUtils.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/TreeUtils.java @@ -40,6 +40,23 @@ public class TreeUtils { return treeList; } + /** + * 根据pid,构建树节点 + */ + public static List buildTree(List treeNodes, String pid) { + //pid不能为空 + AssertUtils.isNull(pid, "pid"); + + List treeList = new ArrayList<>(); + for(T treeNode : treeNodes) { + if (pid.equals(treeNode.getPid())) { + treeList.add(findChildren(treeNodes, treeNode)); + } + } + + return treeList; + } + /** * 查找子节点 */ @@ -52,6 +69,18 @@ public class TreeUtils { return rootNode; } + /** + * 查找子节点 + */ + private static T findChildren(List treeNodes, T rootNode) { + for(T treeNode : treeNodes) { + if(rootNode.getId().equals(treeNode.getPid())) { + rootNode.getChildren().add(findChildren(treeNodes, treeNode)); + } + } + return rootNode; + } + /** * 构建树节点 */ diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/controller/OperMenuController.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/controller/OperMenuController.java index b8af4cade1..8f4a61e1c5 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/controller/OperMenuController.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/controller/OperMenuController.java @@ -1,6 +1,7 @@ package com.epmet.controller; import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.ExcelUtils; @@ -48,18 +49,18 @@ public class OperMenuController { } @PostMapping - public Result save(@RequestBody OperMenuDTO dto){ + public Result save(@RequestBody OperMenuDTO dto, @LoginUser TokenDto tokenDto){ //效验数据 ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); - operMenuService.save(dto); + operMenuService.save(dto,tokenDto); return new Result(); } @PutMapping - public Result update(@RequestBody OperMenuDTO dto){ + public Result update(@RequestBody OperMenuDTO dto, @LoginUser TokenDto tokenDto){ //效验数据 ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); - operMenuService.update(dto); + operMenuService.update(dto,tokenDto); return new Result(); } @@ -71,12 +72,40 @@ public class OperMenuController { return new Result(); } + @DeleteMapping("{id}") + public Result delete(@PathVariable("id") String id, @LoginUser TokenDto tokenDto){ + //效验数据 + AssertUtils.isNull(id, "id"); + + //判断是否有子菜单或按钮 + List list = operMenuService.getListPid(id); + if(list.size() > 0){ + return new Result().error(ErrorCode.SUB_MENU_EXIST); + } + + operMenuService.delete(id, tokenDto); + + return new Result(); + } + @GetMapping("export") public void export(@RequestParam Map params, HttpServletResponse response) throws Exception { List list = operMenuService.list(params); ExcelUtils.exportExcelToTarget(response, null, list, OperMenuExcel.class); } + /** + * 获取菜单列表 + * @param type 类型 + * @return Result> + */ + @GetMapping("list") + public Result> list(Integer type){ + List list = operMenuService.getMenuList(type); + + return new Result>().ok(list); + } + /** * 导航 * @param tokenDto token diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperMenuRedis.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperMenuRedis.java index d86846c7d8..f1b568f33a 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperMenuRedis.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperMenuRedis.java @@ -38,8 +38,9 @@ public class OperMenuRedis { @Autowired private RedisUtils redisUtils; - public void delete(Object[] ids) { - + public void delete(String userId, String app, String client) { + redisUtils.deleteByPattern(RedisKeys.getUserMenuNavKey(userId, app, client, HttpContextUtils.getLanguage())); + redisUtils.delete(RedisKeys.getUserPermissionsKey(userId, app, client)); } public void set(){ diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperResourceRedis.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperResourceRedis.java index 4c79c26170..68ea39a15e 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperResourceRedis.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/redis/OperResourceRedis.java @@ -17,6 +17,7 @@ package com.epmet.redis; +import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -32,8 +33,10 @@ public class OperResourceRedis { @Autowired private RedisUtils redisUtils; - public void delete(Object[] ids) { + public void delete() { + String key = RedisKeys.getSysResourceKey(); + redisUtils.delete(key); } public void set(){ diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperLanguageService.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperLanguageService.java index 366c48bd0b..0f0ad555bc 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperLanguageService.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperLanguageService.java @@ -92,4 +92,14 @@ public interface OperLanguageService extends BaseService { * @date 2020-03-18 */ void delete(String[] ids); + + /** + * 保存或更新 + * @param tableName 表名 + * @param tableId 表主键 + * @param fieldName 字段名 + * @param fieldValue 字段值 + * @param language 语言 + */ + void saveOrUpdate(String tableName, String tableId, String fieldName, String fieldValue, String language); } \ No newline at end of file diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperMenuService.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperMenuService.java index efa9eebb4d..9025ce4dd5 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperMenuService.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperMenuService.java @@ -75,7 +75,7 @@ public interface OperMenuService extends BaseService { * @author generator * @date 2020-03-18 */ - void save(OperMenuDTO dto); + void save(OperMenuDTO dto, TokenDto tokenDto); /** * 默认更新 @@ -85,7 +85,7 @@ public interface OperMenuService extends BaseService { * @author generator * @date 2020-03-18 */ - void update(OperMenuDTO dto); + void update(OperMenuDTO dto, TokenDto tokenDto); /** * 批量删除 @@ -97,6 +97,15 @@ public interface OperMenuService extends BaseService { */ void delete(String[] ids); + /** + * 删除 + * + * @param id id + * @author generator + * @date 2020-03-18 + */ + void delete(String id, TokenDto tokenDto); + /** * 用户菜单列表 * @@ -106,6 +115,13 @@ public interface OperMenuService extends BaseService { */ List getUserMenuList(TokenDto tokenDto, Integer type); + /** + * 菜单列表 + * + * @param type 菜单类型 + */ + List getMenuList(Integer type); + /** * 用户菜单导航 * @param tokenDto 用户信息 @@ -119,4 +135,10 @@ public interface OperMenuService extends BaseService { * @return java.util.Set */ Set getUserPermissions(TokenDto tokenDto); + + /** + * 根据父菜单,查询子菜单 + * @param pid 父菜单ID + */ + List getListPid(String pid); } \ No newline at end of file diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperResourceService.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperResourceService.java index 1433da0ac6..815250f1d4 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperResourceService.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperResourceService.java @@ -20,6 +20,7 @@ package com.epmet.service; import com.epmet.commons.mybatis.service.BaseService; import com.epmet.commons.tools.page.PageData; import com.epmet.dto.OperResourceDTO; +import com.epmet.dto.result.MenuResourceDTO; import com.epmet.entity.OperResourceEntity; import java.util.List; @@ -92,4 +93,12 @@ public interface OperResourceService extends BaseService { * @date 2020-03-18 */ void delete(String[] ids); + + /** + * 保存菜单资源 + * @param menuId 菜单ID + * @param menuName 菜单名称 + * @param resourceList 资源列表 + */ + void saveMenuResource(String menuId, String menuName, List resourceList); } \ No newline at end of file diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperRoleMenuService.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperRoleMenuService.java index 50d3e452ac..84cfe6d996 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperRoleMenuService.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/OperRoleMenuService.java @@ -116,4 +116,10 @@ public interface OperRoleMenuService extends BaseService { * @param roleIds */ void deleteByRoleIds(String[] roleIds); + + /** + * 根据菜单id,删除角色菜单关系 + * @param menuId 菜单id + */ + void deleteByMenuId(String menuId); } \ No newline at end of file diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperLanguageServiceImpl.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperLanguageServiceImpl.java index 3ff21c04c1..ee486aa224 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperLanguageServiceImpl.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperLanguageServiceImpl.java @@ -101,4 +101,21 @@ public class OperLanguageServiceImpl extends BaseServiceImpl page(Map params) { @@ -91,16 +104,39 @@ public class OperMenuServiceImpl extends BaseServiceImpl getUserMenuList(TokenDto tokenDto, Integer type) { List menuList; @@ -128,6 +176,15 @@ public class OperMenuServiceImpl extends BaseServiceImpl getMenuList(Integer type) { + List menuList = baseDao.getMenuList(type, HttpContextUtils.getLanguage()); + + List dtoList = ConvertUtils.sourceToTarget(menuList, OperMenuDTO.class); + + return TreeUtils.buildTree(dtoList, Constant.OPER_MENU_ROOT); + } + @Override public List getUserMenuNavList(TokenDto tokenDto) { List menuList = operMenuRedis.getUserMenuNavList(tokenDto.getUserId(), tokenDto.getApp(), tokenDto.getClient()); @@ -171,4 +228,15 @@ public class OperMenuServiceImpl extends BaseServiceImpl getListPid(String pid) { + List menuList = baseDao.getListPid(pid); + + return ConvertUtils.sourceToTarget(menuList, OperMenuDTO.class); + } + + private void saveLanguage(String tableId, String fieldName, String fieldValue){ + operLanguageService.saveOrUpdate("oper_menu", tableId, fieldName, fieldValue, HttpContextUtils.getLanguage()); + } + } \ No newline at end of file diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperResourceServiceImpl.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperResourceServiceImpl.java index 89abe6aae8..70f2965c7f 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperResourceServiceImpl.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperResourceServiceImpl.java @@ -17,15 +17,19 @@ package com.epmet.service.impl; +import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.page.PageData; +import com.epmet.commons.tools.security.enums.ResourceAuthEnum; import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.dao.OperResourceDao; import com.epmet.dto.OperResourceDTO; +import com.epmet.dto.result.MenuResourceDTO; import com.epmet.entity.OperResourceEntity; +import com.epmet.enums.MenuFlagEnum; import com.epmet.redis.OperResourceRedis; import com.epmet.service.OperResourceService; import org.apache.commons.lang3.StringUtils; @@ -101,4 +105,32 @@ public class OperResourceServiceImpl extends BaseServiceImpl resourceList) { + //先删除菜单资源关系 + baseDao.deleteByCode(menuId+""); + + //删除缓存 + operResourceRedis.delete(); + + //菜单没有一个资源的情况 + if(CollUtil.isEmpty(resourceList)){ + return ; + } + + //保存菜单资源关系 + for(MenuResourceDTO dto : resourceList){ + OperResourceEntity entity = new OperResourceEntity(); + entity.setResourceCode(menuId+""); + entity.setResourceName(menuName); + entity.setResourceUrl(dto.getResourceUrl()); + entity.setResourceMethod(dto.getResourceMethod()); + entity.setAuthLevel(ResourceAuthEnum.PERMISSIONS_AUTH.value()); + entity.setMenuFlag(MenuFlagEnum.YES.value()); + + //保存 + insert(entity); + } + } + } \ No newline at end of file diff --git a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperRoleMenuServiceImpl.java b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperRoleMenuServiceImpl.java index d179b6245e..0897d62367 100644 --- a/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperRoleMenuServiceImpl.java +++ b/epmet-module/oper-access/oper-access-server/src/main/java/com/epmet/service/impl/OperRoleMenuServiceImpl.java @@ -142,4 +142,9 @@ public class OperRoleMenuServiceImpl extends BaseServiceImpl getWrapper(Map params){ String id = (String)params.get(FieldConstant.ID_HUMP); - + String name = (String)params.get(FieldConstant.NAME_HUMP); QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); + wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id).like(StringUtils.isNotBlank(name), FieldConstant.NAME, name); return wrapper; }