package com.ningdatech.pmapi.organization.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ningdatech.pmapi.organization.mapper.DingEmployeeInfoMapper;
import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo;
import com.ningdatech.pmapi.organization.service.IDingEmployeeInfoService;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Lierbao
 * @since 2023-02-11
 */
@Service
public class DingEmployeeInfoServiceImpl extends ServiceImpl<DingEmployeeInfoMapper, DingEmployeeInfo> implements IDingEmployeeInfoService {

    @Override
    public List<String> getEmployeesOrgCodeList(List<String> employeeCodeList) {
        if (CollUtil.isEmpty(employeeCodeList)) {
            return new ArrayList<>();
        }
        List<DingEmployeeInfo> dingEmployeeInfoList = this.list(Wrappers.lambdaQuery(DingEmployeeInfo.class).in(DingEmployeeInfo::getEmployeeCode, employeeCodeList));
        List<String> orgCodeList = dingEmployeeInfoList.stream().map(DingEmployeeInfo::getOrganizationCode).distinct().collect(Collectors.toList());
        return orgCodeList;
    }

    @Override
    public List<DingEmployeeInfo> getEmployeeList(List<String> employeeCodeList) {
        if (CollUtil.isEmpty(employeeCodeList)) {
            return new ArrayList<>();
        }
        List<DingEmployeeInfo> dingEmployeeInfoList = this.list(Wrappers.lambdaQuery(DingEmployeeInfo.class)
                .in(DingEmployeeInfo::getEmployeeCode, employeeCodeList));
        return dingEmployeeInfoList;
    }
}
