package com.hz.pm.api.fiscal.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hz.pm.api.fiscal.entity.CompanyFiscalCode;
import com.hz.pm.api.fiscal.mapper.NdCompanyFiscalCodeMapper;
import com.hz.pm.api.fiscal.service.ICompanyFiscalCodeService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Lierbao
 * @since 2023-02-10
 */
@Service

public class CompanyFiscalCodeServiceImpl extends ServiceImpl<NdCompanyFiscalCodeMapper, CompanyFiscalCode> implements ICompanyFiscalCodeService {


    @Override
    public CompanyFiscalCode getByOrgCode(String orgCode) {
        if (StringUtils.isBlank(orgCode)) {
            return null;
        }
        return this.getOne(Wrappers.lambdaQuery(CompanyFiscalCode.class)
                .eq(CompanyFiscalCode::getOrganizationCode, orgCode));

    }

    @Override
    public Map<String, String> getByOrgFiscalCodeMap(List<String> orgCodeList) {
        if (CollUtil.isNotEmpty(orgCodeList)) {
            return Collections.emptyMap();
        }
        List<CompanyFiscalCode> companyFiscalCodeList = this.list(Wrappers.lambdaQuery(CompanyFiscalCode.class)
                .in(CompanyFiscalCode::getOrganizationCode, orgCodeList));

        return companyFiscalCodeList.stream()
                .collect(Collectors.toMap(CompanyFiscalCode::getOrganizationCode, CompanyFiscalCode::getFiscalCode));
    }
}
