package com.eyee.community.config;
import com.eyee.community.mapper.mysql.PostingMapper;
import com.eyee.community.queue.BeanContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* @Auther: Jhon Li
* @Date: 2018/12/8 09:57
* @Description:
*/
@Component
public class MyStartupRunner implements CommandLineRunner {
private PostingMapper postingMapper;
@Autowired
private RedisTemplate redisTemplate;
@Override
public void run(String... args) throws Exception {
this.postingMapper = BeanContext.getApplicationContext().getBean(PostingMapper.class);
List<String> stringList= ( List<String>)redisTemplate.opsForList().leftPop("unloadPostingIdList");
if (CollectionUtils.isEmpty(stringList)){
stringList= postingMapper.selectUnLoadAllPostingId();
for (String s : stringList) {
redisTemplate.opsForList().leftPush("unloadPostingIdList",s );
}
redisTemplate.expire("unloadPostingIdList",1000,SECONDS);
}
}
}