package com.gz;

import com.gz.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import sun.java2d.opengl.OGLContext;

import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author LiuchangLan
 * @date 2021/3/15 16:24
 */
@Slf4j
public class CopyFIle {

    public static final LinkedBlockingQueue<File> PDFQueue = new LinkedBlockingQueue<>();
    public static final LinkedBlockingQueue<File> TIFQueue = new LinkedBlockingQueue<>();


    public static final ExecutorService executorService = Executors.newCachedThreadPool();

    private final static String basePath = "E:\\cache";

    private final static String TIF_TYPE = "TIF";

    private final static String PDF_TYPE = "PDF";

    public static void main(String[] args) throws InterruptedException {
        init();
        handlePDF();
        handleTIF();
    }

    private static void init() throws InterruptedException {
        File file = new File(basePath);
        if (!file.exists()) {
            throw new BusinessException(500, "目录文件不存在");
        }
        for (File yearDirectory : file.listFiles()) {
            for (File archiveDirectory : yearDirectory.listFiles()) {
                if (archiveDirectory.getName().contains(PDF_TYPE)){
                    PDFQueue.put(archiveDirectory);
                }else if (archiveDirectory.getName().contains(TIF_TYPE)){
                    TIFQueue.put(archiveDirectory);
                }
            }
        }
    }

    private static void handlePDF(){
        executorService.execute(() -> {
            try {
                System.out.println(TIFQueue.take().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }

    private static void handleTIF(){
        executorService.execute(() -> {
            try {
                System.out.println(PDFQueue.take().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
    }



}
