package com.jiayue.passback.job;

import com.jiayue.passback.util.FreemarkerUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Value;

import java.io.File;
import java.util.*;

@Slf4j
public abstract class GenerateService {

    @Value("${zxgl.path}")
    private String sxglPath;

    public abstract void GenerateData();
//    public abstract void GenerateLlKyData();

    public void generateFile(Map<String, Object> map, Date date) {
        log.info("====开始生成数据文件====");

        map.put("date",DateFormatUtils.format(date,"yyyyMMddHHmmss"));
        File filePath = new File(sxglPath);
        String fileName = "";
        if (filePath.exists()) {
            try {
                fileName = "BACK_DATA_FILE_"+DateFormatUtils.format(date,"yyyyMMddHHmmss") + ".CIME";
                FreemarkerUtil.genFile(map, sxglPath, fileName);

                log.info("{}目录下，{}文件生成成功！！！", sxglPath, fileName);
            } catch (Exception e) {
                log.info("{}目录下，{}文件生成时发生错误，文件生成失败", sxglPath, fileName);
                log.info(e.getMessage());
            }
        } else {
            log.info("{}正向隔离目录不存在，无法生成文件", sxglPath);
        }
        log.info("====生成数据文件结束====");

    }

//    /**
//     * 理论，可用数据文件回传
//     * @param map
//     * @param date
//     */
//    public void generateLlKyFile(Map<String, Object> map, Date date) {
//        log.info("====开始生成数据文件====");
//
//        map.put("date",DateFormatUtils.format(date,"yyyyMMddHHmmss"));
//        File filePath = new File(sxglPath);
//        String fileName = "";
//        if (filePath.exists()) {
//            try {
//                fileName = "BACK_DATA_LLKY_FILE_"+DateFormatUtils.format(date,"yyyyMMddHHmmss") + ".CIME";
//                FreemarkerUtil.genLlkyFile(map, sxglPath, fileName);
//
//                log.info("{}目录下，{}文件生成成功！！！", sxglPath, fileName);
//            } catch (Exception e) {
//                log.info("{}目录下，{}文件生成时发生错误，文件生成失败", sxglPath, fileName);
//                log.info(e.getMessage());
//            }
//        } else {
//            log.info("{}正向隔离目录不存在，无法生成文件", sxglPath);
//        }
//        log.info("====生成数据文件结束====");
//
//    }

}
