package com.ningdatech.pmapi.expert.assembler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ningdatech.pmapi.expert.entity.ExpertMetaApply;
import com.ningdatech.pmapi.expert.entity.ExpertUserFullInfo;
import com.ningdatech.pmapi.meta.model.bo.RegionContainsBO;

import java.util.List;

/**
 * @author liuxinxin
 * @date 2022/8/10 下午5:36
 */

public class RegionWrapperAssembler {

    public static void expertUserFullInfoRegionContainsWrapperAssembler(LambdaQueryWrapper<ExpertUserFullInfo> wrapperQuery, List<RegionContainsBO> containsRegionList) {
        for (RegionContainsBO regionContainsBO : containsRegionList) {
            List<String> containsRegionCodeList = regionContainsBO.getContainsRegionCodeList();
            Integer parentRegionTreeLevel = regionContainsBO.getParentRegionTreeLevel();
            if (CollectionUtils.isNotEmpty(containsRegionCodeList)) {
                wrapperQuery.and(wrapper -> wrapper.in(ExpertUserFullInfo::getRegionCode, containsRegionCodeList)
                        .ge(ExpertUserFullInfo::getRegionLevel, parentRegionTreeLevel));
            }
        }
    }

    public static void expertMetaApplyRegionContainsWrapperAssembler(LambdaQueryWrapper<ExpertMetaApply> wrapperQuery, List<RegionContainsBO> containsRegionList) {
        for (RegionContainsBO regionContainsBO : containsRegionList) {
            List<String> containsRegionCodeList = regionContainsBO.getContainsRegionCodeList();
            Integer parentRegionTreeLevel = regionContainsBO.getParentRegionTreeLevel();
            if (CollectionUtils.isNotEmpty(containsRegionCodeList)) {
                wrapperQuery.and(wrapper -> wrapper.in(ExpertMetaApply::getRegionCode, containsRegionCodeList)
                        .ge(ExpertMetaApply::getRegionLevel, parentRegionTreeLevel));
            }
        }
    }
}
