package cn.com.ctop.common.service.impl;

import cn.com.ctop.common.mapper.SysUserMapper;
import cn.com.ctop.common.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @Author: scott
 * @Date: 2018-12-20
 */
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
    @Resource
    private SysUserMapper sysUserMapper;
    @Override
    public List<String> treeUserInfo(String userId) {
        List<SysUser> allList = sysUserMapper.selectAllUser();
        List<SysUser> mulUserList = treeCategoryData(allList, userId);
        List<String> userIds = new ArrayList<>();
        userIds.add(userId);
        mulUserList.forEach(mulUser -> userIds.add(mulUser.getId()));
        return userIds;
    }

    public List<SysUser> treeCategoryData(List<SysUser> allList, String leaderId) {
        List<SysUser> mapList = new ArrayList<>();
        for (SysUser vo : allList) {
            if (leaderId.equals(vo.getLeaderId())){
                mapList.add(vo);
                mapList.addAll(treeCategoryData(allList,vo.getId()));
            }
        }
        return mapList;

    }
}
