package com.xunmei.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunmei.common.core.utils.StringUtils;
import com.xunmei.system.api.domain.Role;
import com.xunmei.system.mapper.RoleMapper;
import com.xunmei.system.service.IRoleService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Override
    public List<Role> selectRoleList(Role role) {
        return null;
    }

    @Override
    public Set<String> selectRolePermissionByUserId(Long userId) {
        List<Role> roles = baseMapper.selectRolePermissionByUserId(userId);
        Set<String> perms = new HashSet<>();
        for (Role role : roles) {
            if(StringUtils.isNotNull(role)){
                List<String> roleKeys = Arrays.asList(role.getRoleKey().trim().split(","));
                perms.addAll(roleKeys);
            }
        }
        return perms;
    }
}
