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

com.nebula.boxes.mould.fetcher.loader.ResumeItemDataLoader Maven / Gradle / Ivy

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

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.function.Function;
import java.util.stream.Collectors;

import com.nebula.boxes.mould.entity.ResumeItem;
import com.nebula.boxes.mould.service.IResumeItemService;
import org.apache.commons.collections4.CollectionUtils;
import org.dataloader.BatchLoaderEnvironment;
import org.dataloader.MappedBatchLoaderWithContext;
import org.springframework.beans.factory.annotation.Autowired;
import com.spring.boxes.dollar.support.ContextAwarePoolExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.netflix.graphql.dgs.DgsDataLoader;
import com.spring.boxes.dollar.support.MoreStream;

/**
* 简历-项目经验 DataLoader
*/
@Lazy
@Slf4j
@Service
@DgsDataLoader(name = "resumeItemDataLoader")
public class ResumeItemDataLoader implements MappedBatchLoaderWithContext {

    @Autowired
    private IResumeItemService resumeItemService;

    @Autowired
    private ContextAwarePoolExecutor contextAwarePoolExecutor;

    @Override
    public CompletionStage> load(Set keys, BatchLoaderEnvironment batchLoaderEnvironment) {
        return CompletableFuture.supplyAsync(() -> {
            List ids = CollectionUtils.emptyIfNull(keys)
                .stream()
                .filter(e -> e > 0)
                .collect(Collectors.toList());
            List list = resumeItemService.listByIds(ids);
            return MoreStream.toMap(list, ResumeItem::getId, Function.identity());
        }, contextAwarePoolExecutor);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy