package com.ozs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ozs.entity.BaseUser;
import com.ozs.mapper.BaseUserMapper;
import com.ozs.service.BaseUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author Administrator
 */
@Service
public class BaseUserServiceImpl extends ServiceImpl<BaseUserMapper, BaseUser> implements BaseUserService {
    @Autowired
    private BaseUserMapper baseUserMapper;

    @Override
    public Set<String> getUserIdList(String createBy, Long deptId) {
        Set<String> set = new HashSet<>();
        // 根据create_by、data_permission=1(本人)
        Set<String> set1 = baseUserMapper.getUserIdList(createBy);
        set.addAll(set1);
        // 根据 dept_id（本部门）data_permission=2
        Set<String> set2 = baseUserMapper.getUserIdByDeptId(deptId);
        set.addAll(set2);
        // 根据 dept_id(本部门及下级部门数据) data_permission=3
        // 获取部门数据
        List<Long> deptList = baseUserMapper.getDeptId(deptId);
        // 获取用户列表
        Set<String> set3 = baseUserMapper.getUserIdByDeptIds(deptList);
        set.addAll(set3);
        // 本人及本级部门数据 data_permission=4
        Set<String> set4 = baseUserMapper.getUserIdByDeptIdAndUserId(createBy, deptId);
        set.addAll(set4);
        // 本人及本部门及下级部门数据 data_permission=5
        // 获取本人
        Set<String> setUser = baseUserMapper.getUserIdListBy5(createBy);
        // 获取部门数据
        List<Long> deptList5 = baseUserMapper.getDeptId(deptId);
        // 获取用户列表
        Set<String> setUsers = baseUserMapper.getUserIdByDeptIdsBy5(deptList5);
        Set<String> set5 = new HashSet<>();
        set5.addAll(setUser);
        set5.addAll(setUsers);
        set.addAll(set5);
        // 全部 data_permission=6
        Set<String> set6 = baseUserMapper.getUserIdList6();
        set.addAll(set6);
        return set;
    }

    @Override
    public BaseUser getUser(String userId) {
        return baseUserMapper.getUser(userId);
    }
    @Override
    public BaseUser getUserById(Long id) {
        return baseUserMapper.getUserById(id);
    }

    @Override
    public BaseUser getUserName(String userName) {
        return baseUserMapper.getUserName(userName);
    }

    @Override
    public List<String> getRoleName(String userId) {
        return baseUserMapper.getRoleName(userId);
    }

    @Override
    public List<String> getUserListAll() {
        List<String> userIdsList = baseUserMapper.getUserListAll();
        return userIdsList;
    }
}
