package com.bcxin.service;

import org.springframework.stereotype.Service;

/**
 * Created by kl on 2018/1/19.
 * Content :消费队列中的转换文件
 */
@Service
public class FileConverQueueTask {

    //Logger logger= LoggerFactory.getLogger(getClass());
    //public static final String queueTaskName="FileConverQueueTask";
    //
    //@Autowired
    //private FilePreviewFactory previewFactory;
    //
    //@Autowired
    //private RedissonClient redissonClient;
    //
    //@Autowired
    //private FileUtils fileUtils;
    //
    //@PostConstruct
    //public void startTask(){
    //    ExecutorService executorService = Executors.newFixedThreadPool(3);
    //    executorService.submit(new ConverTask(previewFactory,redissonClient,fileUtils));
    //    logger.info("队列处理文件转换任务启动完成 ");
    //}
    //
    //class  ConverTask implements Runnable{
    //
    //    FilePreviewFactory previewFactory;
    //
    //    RedissonClient redissonClient;
    //
    //    FileUtils fileUtils;
    //
    //    public ConverTask(FilePreviewFactory previewFactory, RedissonClient redissonClient,FileUtils fileUtils) {
    //        this.previewFactory = previewFactory;
    //        this.redissonClient = redissonClient;
    //        this.fileUtils=fileUtils;
    //    }
    //
    //    @Override
    //    public void run() {
    //        while (true) {
    //            try {
    //                final RBlockingQueue<String> queue = redissonClient.getBlockingQueue(FileConverQueueTask.queueTaskName);
    //                String url = queue.take();
    //                if(url!=null){
    //                    FileAttribute fileAttribute=fileUtils.getFileAttribute(url);
    //                    logger.info("正在处理转换任务，文件名称【{}】",fileAttribute.getName());
    //                    FileType fileType=fileAttribute.getType();
    //                    if(fileType.equals(FileType.compress) || fileType.equals(FileType.office)){
    //                        IFilePreview IFilePreview =previewFactory.get(url);
    //                        IFilePreview.filePreviewHandle(url,new ExtendedModelMap());
    //                    }
    //                }
    //            } catch (Exception e) {
    //                try {
    //                    Thread.sleep(1000*10);
    //                }catch (Exception ex){
    //                    ex.printStackTrace();
    //                }
    //                e.printStackTrace();
    //            }
    //        }
    //    }
    //}

}
