package com.pj.project.re_role_menu;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author Mechrevo
 * @Date 2023 07 25 17 30
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class MethodRoleMenuService {

    @Autowired
    private ReRoleMenuMapper reRoleMenuMapper;

    /** 获取该权限的集合 */
    public List<Long> getPerList(Long roleId){
        if (roleId == null)throw new RuntimeException("职务不能为空!");
        //查询该职务下属权限
        List<ReRoleMenu> reRoleMenus = reRoleMenuMapper.selectList
                (new LambdaQueryWrapper<ReRoleMenu>().eq(ReRoleMenu::getAppRoleId, roleId));
        //使用stream过滤出权限
        List<Long> perList = reRoleMenus.stream().map(ReRoleMenu::getId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
        //创建返回值集合
//        List<Long> perList = new ArrayList<>();
//        //遍历集合封装数据
//        reRoleMenus.forEach(item -> {
//            perList.add(item.getId());
//        });
        return perList;
    }

}
