package com.mosty.common.core.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.common.core.business.entity.SysRoleMenu;
import com.mosty.common.core.business.service.SysRoleMenuService;
import com.mosty.common.core.business.mapper.SysRoleMenuMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

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

/**
* @author li
* @description 针对表【sys_role_menu(角色和菜单关联表)】的数据库操作Service实现
* @createDate 2022-02-12 16:53:18
*/
@Service
@AllArgsConstructor
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

    @Override
    public List<SysRoleMenu> listByRoleIds(Set<Long> rolesSet) {
        List<SysRoleMenu> list = this.list(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getRoleId, rolesSet));
        return list;
    }

    @Override
    public Set<Long> listByMenuId(Long menuId) {
        List<SysRoleMenu> list = this.list(new LambdaQueryWrapper<SysRoleMenu>().in(SysRoleMenu::getMenuId, menuId));
        if (!list.isEmpty()){
            return list.stream().map(SysRoleMenu::getRoleId).collect(Collectors.toSet());
        }
        return null;
    }
}




