package com.hz.pm.api.gov.helper;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hz.pm.api.expert.entity.ExpertGovBusinessStrip;
import com.hz.pm.api.gov.entity.BelongOrg;
import com.hz.pm.api.gov.service.IBelongOrgService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

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

/**
 * @author liuxinxin
 * @date 2023/4/21 下午2:07
 */

@Component
@RequiredArgsConstructor
public class GovBusinessStripHelper {

    private final IBelongOrgService iBelongOrgService;

    public List<ExpertGovBusinessStrip> assemblerBusinessStripInfoList(List<String> businessStripCodeList) {
        List<ExpertGovBusinessStrip> businessStripInfoList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(businessStripCodeList)) {
            Map<String, String> codeNameMap = iBelongOrgService.list(Wrappers
                            .lambdaQuery(BelongOrg.class).in(BelongOrg::getOrgCode, businessStripCodeList))
                    .stream().collect(Collectors.toMap(BelongOrg::getOrgCode, BelongOrg::getOrgName));

            businessStripCodeList.forEach(r -> {
                ExpertGovBusinessStrip businessStripInfo = new ExpertGovBusinessStrip();
                businessStripInfo.setBusinessStripCode(r);
                businessStripInfo.setBusinessStripName(codeNameMap.get(r));
                businessStripInfoList.add(businessStripInfo);
            });
        }
        return businessStripInfoList;
    }

}
