com.wuyu.module.hunter.async.AsyncFirmService Maven / Gradle / Ivy
/*--------------------------------------------------------------------------
* Copyright (c) 2010-2020, Elon.su All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the elon developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Elon.su, you can also mail [email protected]
*--------------------------------------------------------------------------
*/
package com.wuyu.module.hunter.async;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.dennisit.vplus.data.enums.common.EnableEnum;
import com.github.dennisit.vplus.data.utils.CollectionUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.wuyu.module.hunter.entity.Firm;
import com.wuyu.module.hunter.entity.Recruit;
import com.wuyu.module.hunter.entity.RecruitInput;
import com.wuyu.module.hunter.service.IFirmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Future;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* Created by Elon.su on 2018/1/9.
*/
@Slf4j
@Service
@EnableAsync
public class AsyncFirmService {
@Autowired
private IFirmService firmService;
@Async
public Future selectById(Long id){
Firm firm = Optional.ofNullable(id)
.map(x -> firmService.selectById(id))
.orElse(null);
return new AsyncResult<>(firm);
}
@Async
public Future> selectByIds(Collection ids){
if(CollectionUtils.isEmpty(ids)){
new AsyncResult(Lists.newArrayList());
}
List list = firmService.selectBatchIds(ids);
return new AsyncResult<>(list);
}
@Async
public Future selectByUuid(String uid){
EntityWrapper wp = new EntityWrapper<>();
wp.eq("uuid", uid).eq("enabled", EnableEnum.ENABLED.getValue());
Firm firm = firmService.selectOne(wp);
return new AsyncResult<>(firm);
}
@Async
public Future> selectByUuids(Collection uuids){
EntityWrapper wp = new EntityWrapper<>();
wp.in("uuid", uuids).eq("enabled", EnableEnum.ENABLED.getValue());
List list = firmService.selectList(wp);
return new AsyncResult<>(list);
}
}