package xyz.wbsite.dbtool.javafx.manger.callable;

import xyz.wbsite.dbtool.javafx.enums.DataBase;
import xyz.wbsite.dbtool.javafx.manger.FreeMarkerManager;
import xyz.wbsite.dbtool.javafx.manger.ManagerFactory;
import xyz.wbsite.dbtool.javafx.manger.ProjectManager;
import xyz.wbsite.dbtool.javafx.manger.XmlManager;
import xyz.wbsite.dbtool.javafx.po.*;
import xyz.wbsite.dbtool.javafx.tool.Tool;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.Callable;

public class SpringBootCallable implements Callable {

    private String root;
    private DataBase dataBase;
    private Project project;
    private String option;
    private boolean cloud;

    private FreeMarkerManager freeMarkerManager;

    public SpringBootCallable(String root, DataBase dataBase, Project project, String option, boolean cloud) {
        this.root = root;
        this.dataBase = dataBase;
        this.project = project;
        this.option = option;
        this.cloud = cloud;
        this.freeMarkerManager = ManagerFactory.getFreeMarkerManager();
    }

    private AbstractDBmapper dBmapper;

    public Boolean call() throws Exception {
        dBmapper = ProjectManager.dBmapper;

        // 创建项目文件夹
        File projectDir = new File(root, project.getProjectName());
        if (!projectDir.exists()) {
            projectDir.mkdir();
        } else {
            Tool.clear(projectDir);
        }

        // 生成POM
        generatePom(projectDir, project, dataBase, option);

        // 生成Maven-java及域名目录
        String basePackage = project.getProjectBasePackage();
        String[] split = basePackage.split("\\.");
        StringBuffer stringBuffer = new StringBuffer(projectDir.getAbsolutePath() + File.separator + "src" + File.separator + "main");
        stringBuffer.append(File.separator).append("java");
        for (String s : split) {
            stringBuffer.append(File.separator).append(s);
        }
        File src = new File(stringBuffer.toString());
        if (!src.exists()) {
            src.mkdirs();
        }
        File moduleDir = new File(src, "module");
        if (!moduleDir.exists()) {
            moduleDir.mkdirs();
        }

        // 生成资源目录
        stringBuffer = new StringBuffer(projectDir.getAbsolutePath() + File.separator + "src" + File.separator + "main");
        stringBuffer.append(File.separator).append("resources");
        File resources = new File(stringBuffer.toString());
        if (!resources.exists()) {
            resources.mkdirs();
        }

        // 生成单元测试java目录
        stringBuffer = new StringBuffer(projectDir.getAbsolutePath());
        stringBuffer.append(File.separator).append("src").append(File.separator).append("test").append(File.separator).append("java");
        for (String s : split) {
            stringBuffer.append(File.separator).append(s);
        }
        File testSrc = new File(stringBuffer.toString());
        if (!testSrc.exists()) {
            testSrc.mkdirs();
        }

        // 生成单元测试resources目录
        stringBuffer = new StringBuffer(projectDir.getAbsolutePath());
        stringBuffer.append(File.separator).append("src").append(File.separator).append("test").append(File.separator).append("resources");
        File testResources = new File(stringBuffer.toString());
        if (!testResources.exists()) {
            testResources.mkdirs();
        }

        {//生成java文件
            //生成Controller
            System.out.println("生成模块:action");
            generateController(new File(src.getAbsolutePath(), "action"), project, dataBase, option);

            //生成Config
            System.out.println("生成模块:config");
            generateConfig(new File(src.getAbsolutePath(), "config"), project, dataBase, option);

            //module
            {
                {

                    Module module = new Module();
                    File api = new File(moduleDir.getAbsolutePath(), "api");
                    api.mkdirs();
                    module.setModuleName("api");
                    module.setProjectAuthor(project.getProjectAuthor());
                    module.setProjectBasePackage(project.getProjectBasePackage());
                    module.setProjectName(project.getProjectName());

                    System.out.println("生成模块:Entity");
                    generateEntity(new File(api.getAbsolutePath(), "ent"), module, dataBase, option);
                    System.out.println("生成模块:Mapper");
                    generateMapper(new File(api.getAbsolutePath(), "mpr"), module, dataBase, option);
                    System.out.println("生成模块:Manager");
                    generateManager(new File(api.getAbsolutePath(), "mgr"), module, dataBase, option);
                    System.out.println("生成模块:Requset");
                    generateRequset(new File(api.getAbsolutePath(), "req"), module, dataBase, option);
                    System.out.println("生成模块:Response");
                    generateResponse(new File(api.getAbsolutePath(), "rsp"), module, dataBase, option);
                }
                for (Module module : project.getModules()) {
                    module.setProjectAuthor(project.getProjectAuthor());
                    module.setProjectBasePackage(project.getProjectBasePackage());
                    module.setProjectName(project.getProjectName());

                    File modulePath = new File(moduleDir.getAbsolutePath(), module.getModuleName());
                    modulePath.mkdirs();

                    System.out.println("生成模块:Entity");
                    generateEntity(new File(modulePath.getAbsolutePath(), "ent"), module, dataBase, option);
                    System.out.println("生成模块:Mapper");
                    generateMapper(new File(modulePath.getAbsolutePath(), "mpr"), module, dataBase, option);
                    System.out.println("生成模块:Manager");
                    generateManager(new File(modulePath.getAbsolutePath(), "mgr"), module, dataBase, option);
                    System.out.println("生成模块:Requset");
                    generateRequset(new File(modulePath.getAbsolutePath(), "req"), module, dataBase, option);
                    System.out.println("生成模块:Response");
                    generateResponse(new File(modulePath.getAbsolutePath(), "rsp"), module, dataBase, option);
                }

                {
                    Module module = new Module();
                    module.setModuleName("system");
                    module.setProjectAuthor(project.getProjectAuthor());
                    module.setProjectBasePackage(project.getProjectBasePackage());
                    module.setProjectName(project.getProjectName());
                    generateSystemModule(new File(moduleDir.getAbsolutePath(), "system"), module, dataBase, option);
                }
            }

            //frame
            System.out.println("生成模块:frame");
            generateFrame(new File(src.getAbsolutePath(), "frame"), project, dataBase, option);

            System.out.println("生成模块:Application");
            generateApplication(new File(src.getAbsolutePath()), project, dataBase, option);
        }

        {//生成resources文件
            System.out.println("生成模块:Resources");
            generateResources(resources, project, dataBase, option);
            System.out.println("生成模块:Static");
            generateStatic(resources, project, dataBase, option);
            System.out.println("生成模块:Templates");
            generateTemplates(resources, project, dataBase, option);
        }

        {//生成test
            System.out.println("生成模块:Test");
            generateTest(testSrc, project, dataBase, option);
            generateTestResources(testResources, project, dataBase, option);
        }
        System.out.println("finish");
        return true;
    }


    /**
     * 生成POM.xml
     *
     * @param root
     * @param project
     */
    public void generatePom(File root, Project project, DataBase dataBase, String option) {
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("projectName", project.getProjectName());
        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("dataBase", dataBase.toString());
        ctx.put("cloud", cloud);

        File file = new File(root.getAbsolutePath(), "pom.xml");

        freeMarkerManager.outputTemp(file, option + "/pom.ftl", ctx);
    }


    /**
     * 生成Controller类
     *
     * @param root
     * @param project
     */
    public void generateController(File root, Project project, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("author", project.getProjectAuthor());
        ctx.put("date", new Date());
        ctx.put("modules", project.getModules());

        File control = new File(root.getAbsolutePath(), "control");
        control.mkdirs();
        File ajax = new File(root.getAbsolutePath(), "ajax");
        ajax.mkdirs();
        File system = new File(ajax.getAbsolutePath(), "system");
        system.mkdirs();
        File screen = new File(root.getAbsolutePath(), "screen");
        screen.mkdirs();

        freeMarkerManager.outputTemp(new File(control.getAbsolutePath(), "Header.java"), option + "/java/action/control/Header.java", ctx);

        freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "AuthAjax.java"), option + "/java/action/ajax/system/AuthAjax.java", ctx);
        freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictAjax.java"), option + "/java/action/ajax/system/DictAjax.java", ctx);
        freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DictItemAjax.java"), option + "/java/action/ajax/system/DictItemAjax.java", ctx);
        freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "FileAjax.java"), option + "/java/action/ajax/system/FileAjax.java", ctx);


        for (Module module : project.getModules()) {
            File m = new File(ajax.getAbsolutePath(), module.getModuleName());
            m.mkdirs();

            for (Table table : module.getTables()) {
                HashMap<String, Object> ctxss = new HashMap<String, Object>();
                ctxss.put("basePackage", project.getProjectBasePackage());
                ctxss.put("module", module.getModuleName());
                ctxss.put("author", project.getProjectAuthor());
                ctxss.put("date", new Date());
                ctxss.put("table", table);

                freeMarkerManager.outputTemp(new File(m.getAbsolutePath(), table.getCName() + "Ajax.java"), option + "/java/action/ajax/Ajax.java", ctxss);
            }
        }


        freeMarkerManager.outputTemp(new File(screen.getAbsolutePath(), "Index.java"), option + "/java/action/screen/Index.java", ctx);

        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "GlobalController.java"), option + "/java/action/GlobalController.java", ctx);

//        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "AjaxController.java"), option + "/java/action/AjaxController.java", ctx);
    }

    public void generateConfig(File root, Project project, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("author", project.getProjectAuthor());
        ctx.put("date", new Date());

        //config
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ActionConfig.java"), option + "/java/config/ActionConfig.java", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "FreeMarkerConfig.java"), option + "/java/config/FreeMarkerConfig.java", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "SecurityConfig.java"), option + "/java/config/SecurityConfig.java", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "TaskConfig.java"), option + "/java/config/TaskConfig.java", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ThreadPoolConfig.java"), option + "/java/config/ThreadPoolConfig.java", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "WebMvcConfig.java"), option + "/java/config/WebMvcConfig.java", ctx);
    }

    /**
     * 生成entity
     *
     * @param root
     * @param md
     */
    public void generateEntity(File root, Module md, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }

        for (Table table : md.getTables()) {
            HashMap<String, Object> ctx = new HashMap<String, Object>();
            ctx.put("tool", Tool.class);
            ctx.put("basePackage", md.getProjectBasePackage());
            ctx.put("moduleName", md.getModuleName());
            ctx.put("table", table);
            ctx.put("author", md.getProjectAuthor());
            ctx.put("date", new Date());

            File file = new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + ".java");

            freeMarkerManager.outputTemp(file, option + "/java/module/ent/entity.ftl", ctx);
        }
    }

    /**
     * 生成Mapper
     *
     * @param root
     * @param md
     */
    public void generateMapper(File root, Module md, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }
        HashMap<String, Object> ctx = new HashMap<String, Object>();

        ctx.put("tool", Tool.class);
        ctx.put("module", md);
        ctx.put("dataBase", dataBase.toString());
        ctx.put("basePackage", md.getProjectBasePackage());
        ctx.put("moduleName", md.getModuleName());
        ctx.put("author", md.getProjectAuthor());
        ctx.put("date", new Date());

        for (Table table : md.getTables()) {
            ctx.put("table", table);
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".java"), option + "/java/module/mpr/mapperJava.ftl", ctx);

            if (md.isHasSysFields()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/module/mpr/mapper.ftl", ctx);
            } else {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Mapper" + ".xml"), option + "/java/module/mpr/mapper_nosys.ftl", ctx);
            }
        }
    }

    public void generateManager(File root, Module md, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }
        HashMap<String, Object> ctx = new HashMap<String, Object>();

        ctx.put("tool", Tool.class);
        ctx.put("module", md);
        ctx.put("basePackage", md.getProjectBasePackage());
        ctx.put("moduleName", md.getModuleName());
        ctx.put("author", md.getProjectAuthor());
        ctx.put("date", new Date());

        if (md.getModuleName().equals("api")) {
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiManager" + ".java"), option + "/java/module/mgr/ApiManager.java", ctx);
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiManagerImpl" + ".java"), option + "/java/module/mgr/ApiManagerImpl.java", ctx);
        }

        for (Table table : md.getTables()) {
            ctx.put("table", table);
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/module/mgr/manager.ftl", ctx);
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "ManagerImpl" + ".java"), option + "/java/module/mgr/managerImpl.ftl", ctx);
        }
    }

    /**
     * 生成Requset
     *
     * @param root
     * @param md
     */
    public void generateRequset(File root, Module md, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }

        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("tool", Tool.class);
        ctx.put("module", md);
        ctx.put("basePackage", md.getProjectBasePackage());
        ctx.put("moduleName", md.getModuleName());
        ctx.put("author", md.getProjectAuthor());
        ctx.put("date", new Date());

        if (md.getModuleName().equals("api")) {
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiExampleRequest" + ".java"), option + "/java/module/req/ApiExampleRequest.java", ctx);
        }

        for (Table table : md.getTables()) {
            ctx.put("table", table);

            if (table.getCreate()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateRequest" + ".java"), option + "/java/module/req/createRequestClass.ftl", ctx);
            }

            if (table.getDelete()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteRequest" + ".java"), option + "/java/module/req/deleteRequestClass.ftl", ctx);
            }

            if (table.getUpdate()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateRequest" + ".java"), option + "/java/module/req/updateRequestClass.ftl", ctx);
            }

            if (table.getFind()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindRequest" + ".java"), option + "/java/module/req/findRequestClass.ftl", ctx);
            }

            if (table.getGet()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetRequest" + ".java"), option + "/java/module/req/getRequestClass.ftl", ctx);
            }

            if (table.getSearch()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchRequest" + ".java"), option + "/java/module/req/searchRequestClass.ftl", ctx);
            }
            if (table.getGetAll()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetAllRequest" + ".java"), option + "/java/module/req/getAllRequestClass.ftl", ctx);
            }
        }
    }

    /**
     * 生成一般文件
     *
     * @param root
     * @param md
     */
    public void generateResponse(File root, Module md, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }

        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("tool", Tool.class);
        ctx.put("module", md);
        ctx.put("basePackage", md.getProjectBasePackage());
        ctx.put("moduleName", md.getModuleName());
        ctx.put("author", md.getProjectAuthor());
        ctx.put("date", new Date());

        if (md.getModuleName().equals("api")) {
            freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "ApiExampleResponse" + ".java"), option + "/java/module/rsp/ApiExampleResponse.java", ctx);
        }

        for (Table table : md.getTables()) {
            ctx.put("table", table);

            if (table.getCreate()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "CreateResponse" + ".java"), option + "/java/module/rsp/createResponseClass.ftl", ctx);
            }

            if (table.getDelete()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "DeleteResponse" + ".java"), option + "/java/module/rsp/deleteResponseClass.ftl", ctx);
            }

            if (table.getUpdate()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "UpdateResponse" + ".java"), option + "/java/module/rsp/updateResponseClass.ftl", ctx);
            }

            if (table.getFind()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "FindResponse" + ".java"), option + "/java/module/rsp/findResponseClass.ftl", ctx);
            }

            if (table.getGet()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetResponse" + ".java"), option + "/java/module/rsp/getResponseClass.ftl", ctx);
            }

            if (table.getSearch()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "SearchResponse" + ".java"), option + "/java/module/rsp/searchResponseClass.ftl", ctx);
            }
            if (table.getGetAll()) {
                freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "GetAllResponse" + ".java"), option + "/java/module/rsp/getAllResponseClass.ftl", ctx);
            }
        }
    }

    public void generateSystemModule(File root, Module md, DataBase dataBase, String option) {
        File ent = new File(root.getAbsolutePath(), "ent");
        ent.mkdirs();
        File mpr = new File(root.getAbsolutePath(), "mpr");
        mpr.mkdirs();
        File mgr = new File(root.getAbsolutePath(), "mgr");
        mgr.mkdirs();
        File req = new File(root.getAbsolutePath(), "req");
        req.mkdirs();
        File rsp = new File(root.getAbsolutePath(), "rsp");
        rsp.mkdirs();

        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("basePackage", md.getProjectBasePackage());
        ctx.put("moduleName", md.getModuleName());
        ctx.put("author", md.getProjectAuthor());
        ctx.put("date", new Date());

        freeMarkerManager.outputTemp(new File(ent.getAbsolutePath(),"Dict.java"), option + "/java/module/system/ent/Dict.java", ctx);
        freeMarkerManager.outputTemp(new File(ent.getAbsolutePath(),"DictItem.java"), option + "/java/module/system/ent/DictItem.java", ctx);

        freeMarkerManager.outputTemp(new File(mgr.getAbsolutePath(),"DictItemManager.java"), option + "/java/module/system/mgr/DictItemManager.java", ctx);
        freeMarkerManager.outputTemp(new File(mgr.getAbsolutePath(),"DictItemManagerImpl.java"), option + "/java/module/system/mgr/DictItemManagerImpl.java", ctx);
        freeMarkerManager.outputTemp(new File(mgr.getAbsolutePath(),"DictManager.java"), option + "/java/module/system/mgr/DictManager.java", ctx);
        freeMarkerManager.outputTemp(new File(mgr.getAbsolutePath(),"DictManagerImpl.java"), option + "/java/module/system/mgr/DictManagerImpl.java", ctx);

        freeMarkerManager.outputTemp(new File(mpr.getAbsolutePath(),"DictItemMapper.java"), option + "/java/module/system/mpr/DictItemMapper.java", ctx);
        freeMarkerManager.outputTemp(new File(mpr.getAbsolutePath(),"DictItemMapper.xml"), option + "/java/module/system/mpr/DictItemMapper.xml", ctx);
        freeMarkerManager.outputTemp(new File(mpr.getAbsolutePath(),"DictMapper.java"), option + "/java/module/system/mpr/DictMapper.java", ctx);
        freeMarkerManager.outputTemp(new File(mpr.getAbsolutePath(),"DictMapper.xml"), option + "/java/module/system/mpr/DictMapper.xml", ctx);

        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictCreateRequest.java"), option + "/java/module/system/req/DictCreateRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictDeleteRequest.java"), option + "/java/module/system/req/DictDeleteRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictFindRequest.java"), option + "/java/module/system/req/DictFindRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictGetRequest.java"), option + "/java/module/system/req/DictGetRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictItemCreateRequest.java"), option + "/java/module/system/req/DictItemCreateRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictItemDeleteRequest.java"), option + "/java/module/system/req/DictItemDeleteRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictItemFindRequest.java"), option + "/java/module/system/req/DictItemFindRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictItemGetRequest.java"), option + "/java/module/system/req/DictItemGetRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictItemUpdateRequest.java"), option + "/java/module/system/req/DictItemUpdateRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictLoadRequest.java"), option + "/java/module/system/req/DictLoadRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(req.getAbsolutePath(),"DictUpdateRequest.java"), option + "/java/module/system/req/DictUpdateRequest.java", ctx);

        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictCreateResponse.java"), option + "/java/module/system/rsp/DictCreateResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictDeleteResponse.java"), option + "/java/module/system/rsp/DictDeleteResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictFindResponse.java"), option + "/java/module/system/rsp/DictFindResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictGetResponse.java"), option + "/java/module/system/rsp/DictGetResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictItemCreateResponse.java"), option + "/java/module/system/rsp/DictItemCreateResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictItemDeleteResponse.java"), option + "/java/module/system/rsp/DictItemDeleteResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictItemFindResponse.java"), option + "/java/module/system/rsp/DictItemFindResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictItemGetResponse.java"), option + "/java/module/system/rsp/DictItemGetResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictItemUpdateResponse.java"), option + "/java/module/system/rsp/DictItemUpdateResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictLoadResponse.java"), option + "/java/module/system/rsp/DictLoadResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(rsp.getAbsolutePath(),"DictUpdateResponse.java"), option + "/java/module/system/rsp/DictUpdateResponse.java", ctx);

    }

    /**
     * 生成frame类
     *
     * @param root
     * @param project
     */
    public void generateFrame(File root, Project project, DataBase dataBase, String option) {
        if (!root.exists()) {
            root.mkdirs();
        } else {
            Tool.clear(root);
        }
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("moduleName", project.getProjectName());
        ctx.put("timestamp", new Date().getTime());

        File auth = new File(root.getAbsolutePath(), "auth");
        auth.mkdirs();
        File base = new File(root.getAbsolutePath(), "base");
        base.mkdirs();
        File excel = new File(root.getAbsolutePath(), "excel");
        excel.mkdirs();
        File excelannotation = new File(excel.getAbsolutePath(), "annotation");
        excelannotation.mkdirs();
        File excelconverter = new File(excel.getAbsolutePath(), "converter");
        excelconverter.mkdirs();
        File exception = new File(excel.getAbsolutePath(), "exception");
        exception.mkdirs();
        File excelstyle = new File(excel.getAbsolutePath(), "style");
        excelstyle.mkdirs();
        File utils = new File(root.getAbsolutePath(), "utils");
        utils.mkdirs();
        File validation = new File(root.getAbsolutePath(), "validation");
        validation.mkdirs();

        //auth
        freeMarkerManager.outputTemp(new File(auth.getAbsolutePath(), "LocalData.java"), option + "/java/frame/auth/LocalData.java", ctx);
        freeMarkerManager.outputTemp(new File(auth.getAbsolutePath(), "Verification.java"), option + "/java/frame/auth/Verification.java", ctx);

        //base
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseEntity.java"), option + "/java/frame/base/BaseEntity.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseFindRequest.java"), option + "/java/frame/base/BaseFindRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseFindResponse.java"), option + "/java/frame/base/BaseFindResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseGetAllRequest.java"), option + "/java/frame/base/BaseGetAllRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseRequest.java"), option + "/java/frame/base/BaseRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseResponse.java"), option + "/java/frame/base/BaseResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseSearchRequest.java"), option + "/java/frame/base/BaseSearchRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "BaseUpdateRequest.java"), option + "/java/frame/base/BaseUpdateRequest.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Control.java"), option + "/java/frame/base/Control.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Error.java"), option + "/java/frame/base/Error.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "ErrorType.java"), option + "/java/frame/base/ErrorType.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "FileUploadResponse.java"), option + "/java/frame/base/FileUploadResponse.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Screen.java"), option + "/java/frame/base/Screen.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "SortType.java"), option + "/java/frame/base/SortType.java", ctx);
        freeMarkerManager.outputTemp(new File(base.getAbsolutePath(), "Token.java"), option + "/java/frame/base/Token.java", ctx);

        //excel
        freeMarkerManager.outputTemp(new File(excel.getAbsolutePath(), "WCell.java"), option + "/java/frame/excel/WCell.java", ctx);
        freeMarkerManager.outputTemp(new File(excel.getAbsolutePath(), "WColumn.java"), option + "/java/frame/excel/WColumn.java", ctx);
        freeMarkerManager.outputTemp(new File(excel.getAbsolutePath(), "WRow.java"), option + "/java/frame/excel/WRow.java", ctx);
        freeMarkerManager.outputTemp(new File(excel.getAbsolutePath(), "WSheet.java"), option + "/java/frame/excel/WSheet.java", ctx);

        freeMarkerManager.outputTemp(new File(excelannotation.getAbsolutePath(), "ColumnDescription.java"), option + "/java/frame/excel/annotation/ColumnDescription.java", ctx);
        freeMarkerManager.outputTemp(new File(excelannotation.getAbsolutePath(), "ColumnName.java"), option + "/java/frame/excel/annotation/ColumnName.java", ctx);
        freeMarkerManager.outputTemp(new File(excelannotation.getAbsolutePath(), "Converter.java"), option + "/java/frame/excel/annotation/Converter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelannotation.getAbsolutePath(), "Ignore.java"), option + "/java/frame/excel/annotation/Ignore.java", ctx);
        freeMarkerManager.outputTemp(new File(excelannotation.getAbsolutePath(), "ParentFirst.java"), option + "/java/frame/excel/annotation/ParentFirst.java", ctx);
        freeMarkerManager.outputTemp(new File(excelannotation.getAbsolutePath(), "SheetName.java"), option + "/java/frame/excel/annotation/SheetName.java", ctx);

        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "BooleanConverter.java"), option + "/java/frame/excel/converter/BooleanConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "ByteConverter.java"), option + "/java/frame/excel/converter/ByteConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "CharacterConverter.java"), option + "/java/frame/excel/converter/CharacterConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "Converter.java"), option + "/java/frame/excel/converter/Converter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "DateConverter.java"), option + "/java/frame/excel/converter/DateConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "DoubleConverter.java"), option + "/java/frame/excel/converter/DoubleConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "FloatConverter.java"), option + "/java/frame/excel/converter/FloatConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "IntegerConverter.java"), option + "/java/frame/excel/converter/IntegerConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "LongConverter.java"), option + "/java/frame/excel/converter/LongConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "ShortConverter.java"), option + "/java/frame/excel/converter/ShortConverter.java", ctx);
        freeMarkerManager.outputTemp(new File(excelconverter.getAbsolutePath(), "StringConverter.java"), option + "/java/frame/excel/converter/StringConverter.java", ctx);

        freeMarkerManager.outputTemp(new File(exception.getAbsolutePath(), "ReadErrorException.java"), option + "/java/frame/excel/exception/ReadErrorException.java", ctx);
        freeMarkerManager.outputTemp(new File(exception.getAbsolutePath(), "TemplateNotMatchException.java"), option + "/java/frame/excel/exception/TemplateNotMatchException.java", ctx);
        freeMarkerManager.outputTemp(new File(exception.getAbsolutePath(), "ValueConverterException.java"), option + "/java/frame/excel/exception/ValueConverterException.java", ctx);

        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "BaseCellStyle.java"), option + "/java/frame/excel/style/BaseCellStyle.java", ctx);
        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "BaseFont.java"), option + "/java/frame/excel/style/BaseFont.java", ctx);
        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "DataCellStyle.java"), option + "/java/frame/excel/style/DataCellStyle.java", ctx);
        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "ErrorCellStyle.java"), option + "/java/frame/excel/style/ErrorCellStyle.java", ctx);
        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "HeadCellStyle.java"), option + "/java/frame/excel/style/HeadCellStyle.java", ctx);
        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "NormalFont.java"), option + "/java/frame/excel/style/NormalFont.java", ctx);
        freeMarkerManager.outputTemp(new File(excelstyle.getAbsolutePath(), "RedFont.java"), option + "/java/frame/excel/style/RedFont.java", ctx);

        //uitls
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "Base64Util.java"), option + "/java/frame/utils/Base64Util.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "AESUtil.java"), option + "/java/frame/utils/AESUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ClassUtil.java"), option + "/java/frame/utils/ClassUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "CookieUtil.java"), option + "/java/frame/utils/CookieUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "FileUtil.java"), option + "/java/frame/utils/FileUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "LogUtil.java"), option + "/java/frame/utils/LogUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MapperUtil.java"), option + "/java/frame/utils/MapperUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "MD5Util.java"), option + "/java/frame/utils/MD5Util.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ProcessUtil.java"), option + "/java/frame/utils/ProcessUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ResponseUtil.java"), option + "/java/frame/utils/ResponseUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "RSAUtil.java"), option + "/java/frame/utils/RSAUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "StringUtil.java"), option + "/java/frame/utils/StringUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "ValidationUtil.java"), option + "/java/frame/utils/ValidationUtil.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "WebUtils.java"), option + "/java/frame/utils/WebUtils.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "IDgenerator.java"), option + "/java/frame/utils/IDgenerator.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "Message.java"), option + "/java/frame/utils/Message.java", ctx);
        freeMarkerManager.outputTemp(new File(utils.getAbsolutePath(), "UrlUtil.java"), option + "/java/frame/utils/UrlUtil.java", ctx);

        //validation
        freeMarkerManager.outputTemp(new File(validation.getAbsolutePath(), "Dict.java"), option + "/java/frame/validation/Dict.java", ctx);
        freeMarkerManager.outputTemp(new File(validation.getAbsolutePath(), "DictValidator.java"), option + "/java/frame/validation/DictValidator.java", ctx);
    }

    /**
     * 生成base类
     *
     * @param root
     * @param project
     */
    public void generateApplication(File root, Project project, DataBase dataBase, String option) {

        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("moduleName", project.getProjectName());
        ctx.put("timestamp", new Date().getTime());

        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "Application.java"), option + "/java/Application.ftl", ctx);
    }

    /**
     * 生成properties
     *
     * @param root
     * @param project
     */
    public void generateResources(File root, Project project, DataBase dataBase, String option) {
        HashMap<String, Object> ctx = new HashMap<String, Object>();

        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("tool", Tool.class);
        ctx.put("dataBase", dataBase.toString());
        ctx.put("author", project.getProjectAuthor());
        ctx.put("dBmapper", dBmapper);
        ctx.put("date", new Date());
        ctx.put("author", project.getProjectAuthor());
        ctx.put("projectName", project.getProjectName());
        ctx.put("cloud", cloud);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "start-dev.bat"), option + "/resources/start-dev.bat", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "start-prod.bat"), option + "/resources/start-prod.bat", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "application-dev.properties"), option + "/resources/application-dev.ftl", ctx);
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "application-prod.properties"), option + "/resources/application-prod.ftl", ctx);
        Tool.outputResource(option + "/resources/banner.txt", new File(root.getAbsolutePath(), "banner.txt"));
        Tool.outputResource(option + "/resources/logback-spring.xml", new File(root.getAbsolutePath(), "logback-spring.xml"));

        if (DataBase.ORACLE == dataBase) {
            File lib = new File(root.getAbsolutePath(), "lib");
            lib.mkdirs();
            Tool.outputResource(option + "/resources/lib/ojdbc7-12.1.0.2.jar", new File(lib.getAbsolutePath(), "ojdbc7-12.1.0.2.jar"));
        }

        File dbtool = new File(root.getAbsolutePath(), "dbtool");
        dbtool.mkdirs();
        {
            XmlManager xmlManager = ManagerFactory.getXmlManager();
            xmlManager.saveAs(dbtool, project);
        }

        for (Module module : project.getModules()) {
            ctx.put("moduleName", module.getModuleName());
            ctx.put("module", module);

            File tableDir = new File(dbtool.getAbsolutePath(), module.getModuleName() + "_table");
            tableDir.mkdirs();

            for (Table table : module.getTables()) {
                ctx.put("table", table);
                freeMarkerManager.outputTemp(new File(tableDir.getAbsolutePath(), table.getTableName() + ".sql"), option + "/resources/dbtool/table.ftl", ctx);
            }
            freeMarkerManager.outputTemp(new File(tableDir.getAbsolutePath(), "ALL_TABLE.sql"), option + "/resources/dbtool/tableAll.ftl", ctx);
        }

        {
            File system = new File(dbtool.getAbsolutePath(), "system");
            system.mkdirs();

            freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DICT.sql"), option + "/resources/dbtool/system/DICT.sql", ctx);
            freeMarkerManager.outputTemp(new File(system.getAbsolutePath(), "DICT_ITEM.sql"), option + "/resources/dbtool/system/DICT_ITEM.sql", ctx);
        }


    }

    public void generateTestResources(File root, Project project, DataBase dataBase, String option) {
        HashMap<String, Object> ctx = new HashMap<String, Object>();

        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("moduleName", project.getProjectName());
        ctx.put("tool", Tool.class);
        ctx.put("dataBase", dataBase.toString());
        ctx.put("author", project.getProjectAuthor());
        ctx.put("dBmapper", dBmapper);
        ctx.put("date", new Date());
        freeMarkerManager.outputTemp(new File(root.getAbsolutePath(), "application.properties"), option + "/test/application.properties", ctx);
        Tool.outputResource(option + "/test/logback-spring.xml", new File(root.getAbsolutePath(), "logback-spring.xml"));
    }

    /**
     * 生成static
     *
     * @param root
     * @param project
     */
    public void generateStatic(File root, Project project, DataBase dataBase, String option) {

        HashMap<String, Object> ctx = new HashMap<String, Object>();
        ctx.put("basePackage", project.getProjectBasePackage());
        ctx.put("tool", Tool.class);
        ctx.put("author", project.getProjectAuthor());
        ctx.put("date", new Date());
        ctx.put("modules", project.getModules());

        File static_ = new File(root.getAbsolutePath(), "static");
        boolean mkdirs = static_.mkdirs();
        File css = new File(static_.getAbsolutePath(), "css");
        boolean mkdirs1 = css.mkdirs();
        File img = new File(static_.getAbsolutePath(), "img");
        boolean mkdirs3 = img.mkdirs();

        File dist = new File(static_.getAbsolutePath(), "dist");
        boolean mkdirs4 = dist.mkdirs();

        {
            Tool.outputResource(option + "/resources/static/favicon.ico", new File(static_.getAbsolutePath(), "favicon.ico"));
        }

        {//css文件
            freeMarkerManager.outputTemp(new File(css.getAbsolutePath(), "base.css"), option + "/resources/static/css/base.css", ctx);
        }

        {//img
            Tool.outputResource(option + "/resources/static/img/logo.png", new File(img.getAbsolutePath(), "logo.png"));
        }

        {//dist文件
            //jquery + vue + vue-router + axios
            Tool.outputResource(option + "/resources/static/dist/lib.min.js", new File(dist.getAbsolutePath(), "lib.min.js"));

            //element-ui
            Tool.outputResource(option + "/resources/static/dist/index.min.js", new File(dist.getAbsolutePath(), "index.min.js"));
            Tool.outputResource(option + "/resources/static/dist/index.min.css", new File(dist.getAbsolutePath(), "index.min.css"));

            //vonic
//            Tool.outputResource(option + "/resources/static/dist/vonic.min.js", new File(dist.getAbsolutePath(), "vonic.min.js"));
//            Tool.outputResource(option + "/resources/static/dist/vonic.min.css", new File(dist.getAbsolutePath(), "vonic.min.css"));

            //mint-ui
//            Tool.outputResource(option + "/resources/static/dist/mint-ui.min.js", new File(dist.getAbsolutePath(), "mint-ui.min.js"));
//            Tool.outputResource(option + "/resources/static/dist/mint-ui.min.css", new File(dist.getAbsolutePath(), "mint-ui.min.css"));

            File fonts = new File(dist.getAbsolutePath(), "fonts");
            fonts.mkdirs();
            Tool.outputResource(option + "/resources/static/dist/fonts/w-e-icon.woff", new File(fonts.getAbsolutePath(), "w-e-icon.woff"));

            Tool.outputResource(option + "/resources/static/dist/fonts/element-icons.woff", new File(fonts.getAbsolutePath(), "element-icons.woff"));

        }
    }

    /**
     * 生成static
     *
     * @param root
     * @param project
     */
    public void generateTemplates(File root, Project project, DataBase dataBase, String option) {
        {//生成
            File templates = new File(root.getAbsolutePath(), "templates");
            templates.mkdirs();

            File control = new File(templates.getAbsolutePath(), "control");
            control.mkdirs();
            File layout = new File(templates.getAbsolutePath(), "layout");
            layout.mkdirs();
            File screen = new File(templates.getAbsolutePath(), "screen");
            screen.mkdirs();
            File system = new File(screen.getAbsolutePath(), "system");
            system.mkdirs();
            Tool.outputResource(option + "/resources/templates/control/nav.ftl", new File(control.getAbsolutePath(), "nav.ftl"));
//            Tool.outputResource(option + "/resources/templates/control/header.ftl", new File(control.getAbsolutePath(), "header.ftl"));
//            Tool.outputResource(option + "/resources/templates/control/footer.ftl", new File(control.getAbsolutePath(), "footer.ftl"));
            Tool.outputResource(option + "/resources/templates/control/macro.ftl", new File(control.getAbsolutePath(), "macro.ftl"));
//            Tool.outputResource(option + "/resources/templates/control/mint-ui-extend.ftl", new File(control.getAbsolutePath(), "mint-ui-extend.ftl"));
            Tool.outputResource(option + "/resources/templates/layout/default.ftl", new File(layout.getAbsolutePath(), "default.ftl"));
            Tool.outputResource(option + "/resources/templates/layout/index.ftl", new File(layout.getAbsolutePath(), "index.ftl"));
//            Tool.outputResource(option + "/resources/templates/layout/app.ftl", new File(layout.getAbsolutePath(), "app.ftl"));
            Tool.outputResource(option + "/resources/templates/screen/home.ftl", new File(screen.getAbsolutePath(), "home.ftl"));
            Tool.outputResource(option + "/resources/templates/screen/login.ftl", new File(screen.getAbsolutePath(), "login.ftl"));
            Tool.outputResource(option + "/resources/templates/403.ftl", new File(templates.getAbsolutePath(), "403.ftl"));
            Tool.outputResource(option + "/resources/templates/404.ftl", new File(templates.getAbsolutePath(), "404.ftl"));
            Tool.outputResource(option + "/resources/templates/500.ftl", new File(templates.getAbsolutePath(), "500.ftl"));

            Tool.outputResource(option + "/resources/templates/screen/module/system/dict.ftl", new File(system.getAbsolutePath(), "dict.ftl"));
            Tool.outputResource(option + "/resources/templates/screen/module/system/dictItem.ftl", new File(system.getAbsolutePath(), "dictItem.ftl"));

            {
                HashMap<String, Object> ctx = new HashMap<String, Object>();
                ctx.put("basePackage", project.getProjectBasePackage());
                ctx.put("tool", new Tool());
                ctx.put("author", project.getProjectAuthor());
                ctx.put("date", new Date());
                ctx.put("modules", project.getModules());
                freeMarkerManager.outputTemp(new File(screen.getAbsolutePath(), "index.ftl"), option + "/resources/templates/screen/index.ftl", ctx);

            }


            for (Module mo : project.getModules()) {
                if (mo.isHasSysFields()) {//标准模型才好生成简单的htm
                    for (Table table : mo.getTables()) {
                        if (table.getHtml()) {
                            File module = new File(screen.getAbsolutePath(), mo.getModuleName());
                            module.mkdirs();
                            HashMap<String, Object> ctx = new HashMap<String, Object>();
                            ctx.put("basePackage", project.getProjectBasePackage());
                            ctx.put("tool", Tool.class);
                            ctx.put("author", project.getProjectAuthor());
                            ctx.put("date", new Date());
                            ctx.put("table", table);
                            ctx.put("module", module.getName());
                            ctx.put("fields", table.getFields());
                            freeMarkerManager.outputTemp(new File(module.getAbsolutePath(), table.getFName() + ".ftl"), option + "/resources/templates/screen/module/mgr.ftl", ctx);
                        }
                    }
                }
            }
        }
    }

    public void generateTest(File root, Project project, DataBase dataBase, String option) {

        {
            File config = new File(root.getAbsolutePath(), "config");
            config.mkdirs();
            HashMap<String, Object> ctx = new HashMap<String, Object>();
            ctx.put("tool", Tool.class);
            ctx.put("basePackage", project.getProjectBasePackage());
            ctx.put("moduleName", project.getProjectName());
            ctx.put("author", project.getProjectAuthor());
            ctx.put("date", new Date());
            freeMarkerManager.outputTemp(new File(config.getAbsolutePath(), "TestConfig" + ".java"), option + "/test/TestConfig.ftl", ctx);
        }

        {
            HashMap<String, Object> ctx = new HashMap<String, Object>();
            ctx.put("tool", Tool.class);
            ctx.put("basePackage", project.getProjectBasePackage());
            ctx.put("moduleName", project.getProjectName());
            ctx.put("author", project.getProjectAuthor());
            ctx.put("date", new Date());
            freeMarkerManager.outputTemp(new File(root, "UtilTest" + ".java"), option + "/test/UtilTest.java", ctx);
        }

        for (Module md : project.getModules()) {
            File module = new File(root.getAbsolutePath(), md.getModuleName());
            module.mkdirs();

            for (Table table : md.getTables()) {
                HashMap<String, Object> ctx = new HashMap<String, Object>();

                ctx.put("tool", Tool.class);
                ctx.put("module", md);
                ctx.put("basePackage", md.getProjectBasePackage());
                ctx.put("moduleName", md.getModuleName());
                ctx.put("table", table);
                ctx.put("author", md.getProjectAuthor());
                ctx.put("date", new Date());

                freeMarkerManager.outputTemp(new File(module.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Test" + ".java"), option + "/test/test.ftl", ctx);
            }
        }

    }
}
