package com.community.huiju.service.impl;

import com.community.huiju.dao.*;
import com.community.huiju.dto.RoleDTO;
import com.community.huiju.model.TaSysRole;
import com.community.huiju.model.ToSysRole;
import com.community.huiju.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 角色业务
 * @author weiximei
 */
@Service("iRoleService")
public class RoleService implements IRoleService {

    @Autowired
    private ToSysMenuMapper toSysMenuMapper;

    @Autowired
    private ToSysRoleMapper toSysRoleMapper;

    @Autowired
    private ToSysRoleMenuMapper toSysRoleMenuMapper;

    @Autowired
    private ToSysUserRoleMapper toSysUserRoleMapper;

    @Autowired
    private ToUserMapper toUserMapper;

    @Autowired
    private TaSysRoleMapper taSysRoleMapper;

    @Override
    public List<RoleDTO> getWebUserRoleByUserId(Integer userId) {
        List<RoleDTO> roleDTOList = new ArrayList<>();
        List<ToSysRole> roles = toSysRoleMapper.selectRoleByUserId(userId);
        roleDTOList = roles.stream()
                .map(e-> new RoleDTO(e.getId(),e.getRoleName()))
                .collect(Collectors.toList());
        return roleDTOList;
    }

    @Override
    public List<RoleDTO> getAppUserRoleByUserId(Integer userId) {
        List<RoleDTO> roleDTOList = new ArrayList<>();
        List<TaSysRole> roles = taSysRoleMapper.selectRoleByUserId(userId);
        roleDTOList = roles.stream()
                .map(e-> new RoleDTO(e.getId(),e.getRoleName()))
                .collect(Collectors.toList());
        return roleDTOList;
    }
}
