package com.storlead.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.storlead.user.mapper.JobMapper;
import com.storlead.user.pojo.entity.JobEntity;
import com.storlead.user.pojo.entity.UserEntity;
import com.storlead.user.service.IJobService;
import com.storlead.user.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class JobServiceImpl extends ServiceImpl<JobMapper, JobEntity> implements IJobService {

    @Resource
    private IUserService userService;
    @Override
    public Map<Long, JobEntity> getJobMap(Collection<UserEntity> users) {
//        if (CollectionUtils.isEmpty(userIdList)){
//            return null;
//        }
//        Collection<UserEntity> users = userService.listByIds(userIdList);
        if (CollectionUtils.isEmpty(users)){
            return null;
        }
        List<Long> jobIdList = users.stream().map(e -> e.getJobId()).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(users)){
            return null;
        }
        Collection<JobEntity> jobs = listByIds(jobIdList);
        if (!CollectionUtils.isEmpty(jobs)){
            Map<Long, JobEntity> jobMap = jobs.stream().collect(Collectors.toMap(JobEntity::getId, jobEntity -> jobEntity));
            return jobMap;
        }
        return null;
    }
}
