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

com.nebula.boxes.mould.fetcher.async.RecruitInputTrunkApi Maven / Gradle / Ivy

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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.Optional;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.nebula.boxes.mould.entity.RecruitInput;
import com.nebula.boxes.mould.service.IRecruitInputService;
import com.spring.boxes.dollar.$;
import com.spring.boxes.dollar.enums.EnableEnum;
import com.spring.boxes.dollar.support.ContextAwarePoolExecutor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import lombok.extern.slf4j.Slf4j;

@Lazy
@Slf4j
@Service
public class RecruitInputTrunkApi {

    @Autowired
    private IRecruitInputService recruitInputService;

    @Autowired
    private ContextAwarePoolExecutor contextAwarePoolExecutor;

    public CompletableFuture selectOneById(Long id) {
        RecruitInput one = Optional.ofNullable(id)
                .map(x -> recruitInputService.getById(id))
                .orElse(null);
        return CompletableFuture.supplyAsync(() -> one, contextAwarePoolExecutor);
    }

    public CompletableFuture> selectListByIds(Collection ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return CompletableFuture.supplyAsync(ArrayList::new, contextAwarePoolExecutor);
        }
        Collection list = recruitInputService.listByIds(ids);
        return CompletableFuture.supplyAsync(() -> list, contextAwarePoolExecutor);
    }

    public CompletableFuture> selectMapByIds(List ids) {
        Collection list = recruitInputService.listByIds(ids);
        if (CollectionUtils.isEmpty(list)) {
            return CompletableFuture.supplyAsync(HashMap::new, contextAwarePoolExecutor);
        }
        // 针对重复key的  覆盖之前的value
        Map map = list.stream().collect(Collectors.toMap(RecruitInput::getId, Function.identity(), (k, v) -> v));
        return CompletableFuture.supplyAsync(() -> map, contextAwarePoolExecutor);
    }

    public CompletableFuture selectOneByUuid(String uuid) {
        QueryWrapper wp = new QueryWrapper<>();
        wp.lambda().eq(RecruitInput::getUuid, uuid);
        RecruitInput one = recruitInputService.getOne(wp);
        return CompletableFuture.supplyAsync(() -> one, contextAwarePoolExecutor);
    }

    public CompletableFuture> selectListByUuids(Collection uuids) {
        QueryWrapper wp = new QueryWrapper<>();
        wp.lambda().in(RecruitInput::getUuid, uuids);
        List list = recruitInputService.list(wp);
        return CompletableFuture.supplyAsync(() -> list, contextAwarePoolExecutor);
    }

    public CompletableFuture> selectMapByUuids(Collection uuids) {
        QueryWrapper wp = new QueryWrapper<>();
        wp.lambda().in(RecruitInput::getUuid, uuids);
        List list = recruitInputService.list(wp);
        if (CollectionUtils.isEmpty(list)) {
            return CompletableFuture.supplyAsync(HashMap::new, contextAwarePoolExecutor);
        }
        // 针对重复key的  覆盖之前的value
        Map map = list.stream().collect(Collectors.toMap(RecruitInput::getUuid, Function.identity(), (k, v) -> v));
        return CompletableFuture.supplyAsync(() -> map, contextAwarePoolExecutor);
    }

    public CompletableFuture> selectListByWrapper(QueryWrapper wp) throws Exception {
        List list = this.recruitInputService.list(wp);
        return CompletableFuture.supplyAsync(() -> list, contextAwarePoolExecutor);
    }

    public CompletableFuture selectUserInput(long userId, long recruitId) {
        LambdaQueryWrapper wp = Wrappers.lambdaQuery();
        wp.eq(RecruitInput::getSeekerId, userId).eq(RecruitInput::getRecruitId, recruitId).eq(RecruitInput::getEnabled, EnableEnum.ENABLED.getValue());
        RecruitInput one = recruitInputService.getOne(wp);
        return CompletableFuture.supplyAsync(() -> one, contextAwarePoolExecutor);
    }

    public CompletableFuture> selectMonthTotalGroupBy(){
        QueryWrapper wp = new QueryWrapper<>();
        wp.select("DATE_FORMAT(create_time,'%Y/%m') date", "count(0) as total");
        wp.groupBy("date").orderByDesc("date");
        List> list = this.recruitInputService.listMaps(wp);
        return CompletableFuture.supplyAsync(() -> $.getPairMap(list, "date", "total"), contextAwarePoolExecutor);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy