package com.lightinit.hsdataplatformresdir.impl;

import com.lightinit.hsdataplatformresdir.entity.PermissionModule;
import com.lightinit.hsdataplatformresdir.entity.SentryRoleAction;
import com.lightinit.hsdataplatformresdir.mapper.RoleModuleMapper;
import com.lightinit.hsdataplatformresdir.service.IShiroPermissionsService;
import com.lightinit.hsdataplatformresdir.service.admin.IRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * Created by Mr.Yao on 2017/11/8.
 */
@Service
public class ShiroPermissionsServiceImpl implements IShiroPermissionsService {
    @Autowired
    private RoleModuleMapper roleModuleMapper;
    @Autowired
    private IRolePermissionService rolePermissionService;

    @Override
    public List<SentryRoleAction> selectSentryRoleAction(List<String> roles) {
        return rolePermissionService.getAllRolePermissions().stream().filter(q -> roles.contains(q.getRolecode())).collect(Collectors.toList());
    }
    @Override
    public List<SentryRoleAction> selectSentryRoleAction(String code,List<String> roles) {
        return rolePermissionService.getAllRolePermissions().stream().filter(q -> roles.contains(q.getRolecode())).collect(Collectors.toList());
    }
    @Override
    public List<PermissionModule> findAll() {
        return roleModuleMapper.selectByPermissionMenu();
    }
}
