package com.test.xxx.mysql;



import com.test.xxx.MysqlMain_insert;
import org.apache.commons.lang3.StringUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class MysqlUtilTable2XML {

    public static String TAB = "    ";

    public static void printXMLForMap(TablesBean bean) {


        String realName = MysqlMain_insert.pre + bean.getSpaceName() + "";
        String realNam2 = MysqlMain_insert.pre + bean.getSpaceName();

        StringBuffer bf = new StringBuffer();

        bf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n");
        bf.append("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">").append("\n");
        bf.append("<mapper namespace=\"" + MysqlMain_insert.dao_package + "." + realName + "Dao\">").append("\n");
        bf.append("\n");


        bf.append("</mapper>").append("\n");
        bf.append("\n");


        String fileName = MysqlMain_insert.save_path + "/" + realNam2 + "Dao.xml";

        if (StringUtils.isNotBlank(MysqlMain_insert.mapper_xml_path)) {
            fileName = MysqlMain_insert.mapper_xml_path + "/" + realNam2 + "Dao.xml";
        }


        try {

            FileOutputStream fos = new FileOutputStream(fileName);
            Writer out = new OutputStreamWriter(fos, "UTF-8");
            out.write(bf.toString());
            out.close();
            fos.close();

            System.out.println("===" + realName + "Dao.xml" + "生成");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getXmlType(String type) {
        if ("date".equals(type.toLowerCase())) {
            return "java.util." + type;
        } else {
            return "java.lang." + type;
        }

    }
}
