All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nebula.boxes.mould.fetcher.TotalFirmRecruitDataLoader Maven / Gradle / Ivy

The newest version!
package com.nebula.boxes.mould.fetcher;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import com.nebula.boxes.mould.entity.Recruit;
import com.nebula.boxes.mould.service.IRecruitService;
import com.netflix.graphql.dgs.DgsDataLoader;
import com.spring.boxes.dollar.enums.EnableEnum;
import com.spring.boxes.dollar.enums.YesOrNoEnum;
import com.spring.boxes.dollar.support.ContextAwarePoolExecutor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.dataloader.BatchLoaderEnvironment;
import org.dataloader.MappedBatchLoaderWithContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.stream.Collectors;

/**
 * 按照企业统计职位总数 DataLoader
 */
@Slf4j
@Service
@DgsDataLoader(name = "totalFirmRecruitDataLoader")
public class TotalFirmRecruitDataLoader implements MappedBatchLoaderWithContext {

    @Autowired
    private IRecruitService recruitService;

    @Autowired
    private ContextAwarePoolExecutor contextAwarePoolExecutor;

    @Override
    public CompletionStage> load(Set keys, BatchLoaderEnvironment batchLoaderEnvironment) {
        return CompletableFuture.supplyAsync(() -> {
            Map total = Maps.newHashMap();
            List firmIds = CollectionUtils.emptyIfNull(keys)
                    .stream()
                    .filter(e -> e > 0)
                    .collect(Collectors.toList());
            if (CollectionUtils.isEmpty(firmIds)) {
                return total;
            }
            QueryWrapper wp = new QueryWrapper<>();
            wp.select("firm_id", "count(0) as total");
            wp.lambda().eq(Recruit::getEnabled, EnableEnum.ENABLED.getValue()).eq(Recruit::getOnline, YesOrNoEnum.YES.getValue()).in(Recruit::getFirmId, firmIds);
            wp.groupBy("firm_id").orderByDesc("total");
            List> groupList = recruitService.listMaps(wp);
            if (CollectionUtils.isEmpty(groupList)) {
                return total;
            }
            for (Map map : groupList) {
                total.put(MapUtils.getLongValue(map, "firm_id", 0), MapUtils.getLongValue(map, "total", 0));
            }
            return total;
        }, contextAwarePoolExecutor);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy