package com.gz.config;

import cn.hutool.core.util.ReUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.File;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * 挂载文件Config
 * @author LiuchangLan
 * @date 2021/3/16 13:21
 */
@Slf4j
@Configuration
public class MountArchiveFileConfig {
    /** 扫描根目录*/
    public static String SCAN_BASE_PATH = "";
    /** 文件传输标识*/
    public static String FILE_RUNNING = "FILE_RUNNING";
    /** pdf队列*/
    public static final LinkedBlockingQueue<File> PDF_QUEUE = new LinkedBlockingQueue<>();
    /** tif队列*/
    public static final LinkedBlockingQueue<File> TIF_QUEUE = new LinkedBlockingQueue<>();
    /** 等待处理的文件*/
    public static final HashMap<String,File> WAIT_HANDLE_FILE = new HashMap<>();
    /** pdf文件偏小 数量偏多 移动文件耗时小 选择newCachedThreadPool线程池*/
    public static final ExecutorService ARCHIVE_HANDLE_JOB_THREAD_POOL = Executors.newCachedThreadPool();
    /** PDF正在执行的任务队列*/
    public static final String SCAN_JOB_QUEUE = "PDF_JOB_QUEUE";
    /** PDF 文件夹命名正则*/
    public static final String PDF_FOLDER_PATTERN = ".*（\\d{4}）-PDF";
    /** TIF 文件夹命名正则*/
    public static final String TIF_FOLDER_PATTERN = ".*（\\d{4}）-TIF";
    /** pdf文件名正则*/
    public static final String PDF_FILE_PATTERN = ".*\\.pdf$";
    /** tif文件名正则*/
    public static final String TIF_FILE_PATTERN = ".*\\.tif$";

    /** 挂载错误redis记录key*/
    public static final String ARCHIVE_FILE_MOUNT_ERROR_FOMAT = "MOUNT_ERROR_%s";

    /** ---------------------redis存储错误信息---------------------*/
    /** 错误信息key*/
    public static final String ERROR_MSG_KEY = "error_msg";
    /** 错误时间key*/
    public static final String ERROR_TIME_KEY = "error_time";
    /** 错误文件key*/
    public static final String ERROR_FILE_PATH_KEY = "error_file_path";


    /** ---------------------专业档案 档号规则---------------------*/

    /** 专业档案-卷内目录档号正则表达式*/
    public static final String ZY_DH_RE = ".*-.*-ZY·.[DC|GH|BH|ZF|DJ]+-[D10|D30|Y]+-.{5}-.{4}";

    @Value("${mount-archive.scan-base-path}")
    public void setArchiveFileRootDirectory(String scanBasePath) {
        log.info("待挂接文件扫描根目录:{}",scanBasePath);
        SCAN_BASE_PATH = scanBasePath;
    }


    public static void main(String[] args) {
        boolean match = ReUtil.isMatch("\\^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\\\.[x|X][m|M][l|L]$", "a.xml");
        System.out.println(match);
    }
}
