package cn.com.qmth.examcloud.core.questions.service.producer;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.qmth.examcloud.core.questions.base.multithread.Producer;
import cn.com.qmth.examcloud.core.questions.service.bean.CopyDataDto;
import cn.com.qmth.examcloud.core.questions.service.consumer.CopyDataConsumer;
import cn.com.qmth.examcloud.web.redis.RedisClient;

@Service
public class CopyDataProducer extends Producer<CopyDataDto, CopyDataConsumer> {
	private static int cacheLockTimeout=60*10;
	@Autowired
	private RedisClient redisClient;
    @SuppressWarnings("unchecked")
    @Override
    protected CopyDataDto findData(Map<String, Object> param, int index) {
        List<CopyDataDto> ret=(List<CopyDataDto>)param.get("dtos");
        if(index>=ret.size()) {
            return null;
        }
        redisClient.expire("$_COPY_QUESTION_DATA_LOCK", cacheLockTimeout);
        return ret.get(index);
    }

    @Override
    protected String getTaskName() {
        return "数据复制";
    }

}
