Browse Source

根据角色返回菜单

master
zxc 3 years ago
parent
commit
94e6cb5350
  1. 9
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/dao/GovRoleMenuDao.java
  2. 6
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/entity/GovMenuEntity.java
  3. 46
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/GovMenuServiceImpl.java
  4. 10
      epmet-module/gov-access/gov-access-server/src/main/resources/mapper/GovRoleMenuDao.xml

9
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<GovRoleMenuEntity> {
*/
List<String> getMenuIdList(String roleId);
/**
* Desc: 根据角色IDs获取菜单IDs列表
* @param roleIds
* @author zxc
* @date 2022/7/12 14:45
*/
List<String> getMenuIdsList(@Param("ids") List<String> roleIds);
/**
* 根据角色id删除角色菜单关系
* @param roleId 角色id

6
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;
}

46
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<GovMenuDao, GovMenuEntit
private GovLanguageService govLanguageService;
@Autowired
private GovCustomerMenuService govCustomerMenuService;
@Autowired
private GovRoleDao govRoleDao;
@Autowired
private GovRoleMenuDao govRoleMenuDao;
@Autowired
private GovRoleUserDao govRoleUserDao;
@Override
public PageData<GovMenuDTO> page(Map<String, Object> params) {
@ -218,7 +228,7 @@ public class GovMenuServiceImpl extends BaseServiceImpl<GovMenuDao, GovMenuEntit
// PC端 每个客户的菜单信息,不放入缓存,每次登陆重新查询。
// 或者 你可以选择,在给每个客户 配置可见菜单的时候, 在saveCustomerMenu方法中,增加更新缓存的逻辑
tableName = getTableName(tableName);
return getCustomerMenuList(tokenDto.getCustomerId(), MenuTypeEnum.MENU.value(),tableName);
return getCustomerMenuList(tokenDto.getCustomerId(), MenuTypeEnum.MENU.value(),tableName,tokenDto.getUserId());
}
/**
@ -231,18 +241,40 @@ public class GovMenuServiceImpl extends BaseServiceImpl<GovMenuDao, GovMenuEntit
* @Author zhangyong
* @Date 15:51 2021-03-16
**/
private List<GovMenuDTO> getCustomerMenuList(String customerId, Integer type, String tableName) {
List<GovMenuDTO> govMenuDTOS = govCustomerMenuRedis.getCustomerMenuList(customerId,type,tableName);
private List<GovMenuDTO> getCustomerMenuList(String customerId, Integer type, String tableName,String userId) {
/*List<GovMenuDTO> govMenuDTOS = govCustomerMenuRedis.getCustomerMenuList(customerId,type,tableName);
if (!CollectionUtils.isEmpty(govMenuDTOS)){
return govMenuDTOS;
}
}*/
List<GovMenuEntity> menuList = baseDao.getCustomerMenuList(customerId, type, HttpContextUtils.getLanguage(),tableName);
List<GovMenuDTO> dtoList = ConvertUtils.sourceToTarget(menuList, GovMenuDTO.class);
govMenuDTOS = TreeUtils.buildTree(dtoList);
govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS,tableName);
disposeGovMenu(menuList,userId);
Map<Boolean, List<GovMenuEntity>> groupByStatus = menuList.stream().collect(Collectors.groupingBy(GovMenuEntity::getRoleStatus));
List<GovMenuDTO> dtoList = ConvertUtils.sourceToTarget(CollectionUtils.isEmpty(groupByStatus.get(true)) ? new ArrayList<>() : groupByStatus.get(true), GovMenuDTO.class);
List<GovMenuDTO> govMenuDTOS = TreeUtils.buildTree(dtoList);
// govCustomerMenuRedis.setCustomerMenuList(customerId,type,govMenuDTOS,tableName);
return govMenuDTOS;
}
public void disposeGovMenu(List<GovMenuEntity> menuList,String userId){
List<String> roleIdList = govRoleUserDao.getRoleIdList(userId);
if (CollectionUtils.isEmpty(roleIdList)){
menuList = new ArrayList<>();
return;
}
List<String> 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<String> getUserPermissions(TokenDto tokenDto) {
//用户权限列表

10
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}
</select>
<select id="getMenuIdsList" resultType="java.lang.String">
select menu_id from gov_role_menu
where del_flag = 0
and role_id in (
<foreach collection="ids" item="id" separator=",">
#{id}
</foreach>
)
</select>
<update id="deleteByRoleIds">
update gov_role_menu set del_flag = 1 where del_flag = 0 and role_id in
<foreach item="roleId" collection="array" open="(" separator="," close=")">

Loading…
Cancel
Save