diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/GovRoleMenuDao.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/GovRoleMenuDao.java index dc0559acb3..d7aeb80836 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/GovRoleMenuDao.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/GovRoleMenuDao.java @@ -11,6 +11,7 @@ package com.epmet.dao; import com.epmet.commons.mybatis.dao.BaseDao; import com.epmet.entity.GovRoleMenuEntity; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -28,6 +29,14 @@ public interface GovRoleMenuDao extends BaseDao { */ List getMenuIdList(String roleId); + /** + * Desc: 根据角色IDs,获取菜单IDs列表 + * @param roleIds + * @author zxc + * @date 2022/7/12 14:45 + */ + List getMenuIdsList(@Param("ids") List roleIds); + /** * 根据角色id,删除角色菜单关系 * @param roleId 角色id diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/GovMenuEntity.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/GovMenuEntity.java index fcb8a5fa38..9c1c3922ed 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/GovMenuEntity.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/GovMenuEntity.java @@ -66,4 +66,10 @@ public class GovMenuEntity extends BaseEpmetEntity { */ private Integer showFlag; + /** + * 筛选使用,跟角色菜单匹配上为true + */ + @TableField(exist = false) + private Boolean roleStatus = false; + } diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java index 2dbb4abe05..d7e78dcdf7 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java @@ -30,6 +30,9 @@ import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.HttpContextUtils; import com.epmet.commons.tools.utils.TreeUtils; import com.epmet.dao.GovMenuDao; +import com.epmet.dao.GovRoleDao; +import com.epmet.dao.GovRoleMenuDao; +import com.epmet.dao.GovRoleUserDao; import com.epmet.dto.GovMenuDTO; import com.epmet.entity.GovMenuEntity; import com.epmet.enums.MenuTypeEnum; @@ -45,6 +48,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.*; +import java.util.stream.Collectors; /** * 菜单管理 @@ -67,6 +71,12 @@ public class GovMenuServiceImpl extends BaseServiceImpl page(Map params) { @@ -218,7 +228,7 @@ public class GovMenuServiceImpl extends BaseServiceImpl getCustomerMenuList(String customerId, Integer type, String tableName) { - List govMenuDTOS = govCustomerMenuRedis.getCustomerMenuList(customerId,type,tableName); + private List getCustomerMenuList(String customerId, Integer type, String tableName,String userId) { + /*List govMenuDTOS = govCustomerMenuRedis.getCustomerMenuList(customerId,type,tableName); if (!CollectionUtils.isEmpty(govMenuDTOS)){ return govMenuDTOS; - } + }*/ List menuList = baseDao.getCustomerMenuList(customerId, type, HttpContextUtils.getLanguage(),tableName); - List dtoList = ConvertUtils.sourceToTarget(menuList, GovMenuDTO.class); - govMenuDTOS = TreeUtils.buildTree(dtoList); - govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS,tableName); + disposeGovMenu(menuList,userId); + Map> groupByStatus = menuList.stream().collect(Collectors.groupingBy(GovMenuEntity::getRoleStatus)); + List dtoList = ConvertUtils.sourceToTarget(CollectionUtils.isEmpty(groupByStatus.get(true)) ? new ArrayList<>() : groupByStatus.get(true), GovMenuDTO.class); + List govMenuDTOS = TreeUtils.buildTree(dtoList); +// govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS,tableName); return govMenuDTOS; } + public void disposeGovMenu(List menuList,String userId){ + List roleIdList = govRoleUserDao.getRoleIdList(userId); + if (CollectionUtils.isEmpty(roleIdList)){ + menuList = new ArrayList<>(); + return; + } + List menuIdsList = govRoleMenuDao.getMenuIdsList(roleIdList); + if (CollectionUtils.isEmpty(menuIdsList)){ + menuList = new ArrayList<>(); + return; + } + for (String id : menuIdsList) { + for (GovMenuEntity m : menuList) { + if (m.getId().equals(id)){ + m.setRoleStatus(true); + } + } + } + } + @Override public Set getUserPermissions(TokenDto tokenDto) { //用户权限列表 diff --git a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/GovRoleMenuDao.xml b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/GovRoleMenuDao.xml index 862679b5de..38864a7bfe 100644 --- a/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/GovRoleMenuDao.xml +++ b/epmet-module/gov-access/gov-access-server/src/main/resources/mapper/GovRoleMenuDao.xml @@ -7,6 +7,16 @@ select menu_id from gov_role_menu where role_id = #{value} + + update gov_role_menu set del_flag = 1 where del_flag = 0 and role_id in