package com.qiuguo.iot.customer.http.api.mysql;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StopWatch;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class MysqlMain {

    public static String package_name = "com.qiuguo.iot.data.entity";
    public static String package_name_model = "com.chengyi.user.dao";
/*

    //public static String save_path = "C:\\Users\\linzi\\Desktop\\mysql";

    //public static String save_path ="C:\\workspace\\life";
    public static String save_path = "C:\\workspace\\ideaworkspace\\api";

    public static String mysql_url = "jdbc:mysql://rr-bp1ih900km0q3e0ur.mysql.rds.aliyuncs.com:3306";
    public static String pre = "";
    public static String mysql_dbname = "igo";
    public static String mysql_username = "igo_readonly";
    public static String mysql_password = "qEJMAwIjY45F";
*/


    //public static String save_path = "C:\\Users\\linzi\\Desktop\\mysql";
    
    // public static String save_path ="C:\\workspace\\life";
    public static String save_path = System.getProperty("user.dir");

    public static String mysql_url = "jdbc:mysql://192.168.8.146:30416/qiuguo_iot?useSSL=false&serverZoneId=Asia/Shanghai";


    public static String pre = "";


    public static String mysql_dbname = "qiuguo_iot";

    public static String mysql_username = "root";
    public static String mysql_password = "123456";
    public static String dto_exclude = ",is_delete,";//生成dto时排除字段，前后都要加英文逗号
    public static String req_exclude = ",,";//生成Req时排除字段，前后都要加英文逗号

    public static class TestStaticAndHuo{
        public static int compare(Long a, Long b){
            return a.compareTo(b);
        }

        public static boolean isEmpt(String str){
            return str == null || str.length() == 0;
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {




        String path = ResourceUtils.getURL("classpath:").getPath();
        System.out.println(path);
        String dir = null;
        if (path != null && path.length() > 0) {
            dir = path.split("target")[0];
        }
        save_path = dir + "src/test/tmp";
        System.out.println(save_path);
        File file = new File(save_path);
        if (!file.exists()) {
            file.mkdirs();
        }
        List<TablesBean> list = new ArrayList<>();

        list.add(new TablesBean("system_talk_answer_config"));
        list.add(new TablesBean("system_same_talk"));

        List<TablesBean> list2 = new ArrayList<TablesBean>();
        Map<String, String> map = MysqlUtil2ShowCreateTable.getComments();
        for (int i = 0; i < list.size(); i++) {
            TablesBean obj = list.get(i);
            String tableName = list.get(i).getTableName();
            List<FieldBean> itemList = MysqlUtil2ShowCreateTable.readTableDetail(tableName);
            obj.setFieldList(itemList);
            obj.setComment(map.get(tableName));
            list2.add(obj);
        }

        for (int i = 0; i < list2.size(); i++) {
            MysqlUtilTable2Bean.printEntity(list2.get(i));
            MysqlUtilTable2Bean.printReq(list2.get(i));
            MysqlUtilTable2Bean.printDto(list2.get(i));
        }


        for (int i = 0; i < list2.size(); i++) {
            //MysqlUtilTable2Contoller.printController(list2.get(i));
            MysqlUtilTable2Contoller.printReactorController(list2.get(i));
        }


        /*for (int i = 0; i < list2.size(); i++) {
            MysqlUtilTable2Mapper.printDao(list2.get(i));
        }
        for (int i = 0; i < list2.size(); i++) {
            MysqlUtilTable2XML.printXMLForMap(list2.get(i));
        }*/

        for (int i = 0; i < list2.size(); i++) {
            MysqlUtilTable2Service.printReactorService(list2.get(i));
           //MysqlUtilTable2Service.printServiceImpl(list2.get(i));
        }




    }

}
