//package com.ghy.web.core;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.ghy.common.utils.StringUtils;
//import net.sourceforge.pinyin4j.PinyinHelper;
//import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
//import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
//
//import java.io.*;
//import java.util.ArrayList;
//import java.util.List;
//
//import static net.sourceforge.pinyin4j.format.HanyuPinyinToneType.WITHOUT_TONE;
//import static net.sourceforge.pinyin4j.format.HanyuPinyinVCharType.WITH_U_UNICODE;
//
///**
// * @author ydq
// * @date : 2022-06-23 10:56
// */
//public class Trans {
//
//    public static void main(String[] args) throws IOException, BadHanyuPinyinOutputFormatCombination {
//        String json = readFile2String("/Users/ydq/Downloads/Administrative-divisions-of-China-master/dist/pcas-code.json");
//        JSONArray jsonArray = JSON.parseArray(json);
//        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
//        format.setVCharType(WITH_U_UNICODE);
//        format.setToneType(WITHOUT_TONE);
//        List<String> sqlList = getChildSqls(jsonArray, 1, null, "", format);
//        writeLine2File("/Users/ydq/Documents/extraProject/dingdong/sysArea.sql", sqlList);
//    }
//
//    public static String readFile2String(String filePath) {
//        StringBuilder strBuilder = new StringBuilder();
//        File ioFile = new File(filePath);
//        try (InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(ioFile), "UTF-8");
//             BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
//            String line;
//            while ((line = bufferedReader.readLine()) != null) {
//                strBuilder.append(line);
//            }
//        } catch (UnsupportedEncodingException unsupportedEncodingException) {
//            unsupportedEncodingException.printStackTrace();
//        } catch (FileNotFoundException fileNotFoundException) {
//            fileNotFoundException.printStackTrace();
//        } catch (IOException ioException) {
//            ioException.printStackTrace();
//        }
//        return strBuilder.toString();
//    }
//
//    public static void writeLine2File(String filePath, List<String> lines) throws IOException {
//        File ioFile = new File(filePath);
//
//        try (
//            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(ioFile), "UTF-8");
//            BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter); // = FileWriter，默认utf-8
//            ){
//            for (String line: lines) {
//                bufferedWriter.write(line);
//                bufferedWriter.newLine();
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    public static List<String> getChildSqls(JSONArray jsonArray, int levelType, String parentCode, String preMergeName, HanyuPinyinOutputFormat format) throws BadHanyuPinyinOutputFormatCombination {
//        List<String> lineList = new ArrayList<String>();
//        for (Object obj: jsonArray) {
//            StringBuilder sql = new StringBuilder();
//            sql.append("INSERT INTO `sys_area` (`area_id`, `area_code`, `area_name`, `parent_code`, `merger_name`, `short_name`, `merger_short_name`, `level_type`, `pinyin`, `first_char`) VALUES (");
//            JSONObject jObj = (JSONObject) obj;
//            String name = jObj.getString("name");
//            String code = jObj.getString("code");
//            String pinyin = PinyinHelper.toHanYuPinyinString(name, format, "", false);
//            String mergeName = StringUtils.isEmpty(preMergeName) ? name : preMergeName + "," + name;
//            if (parentCode == null) {
//                parentCode = "1";
//            }
//            sql.append(code).append(",")
//                .append("'").append(code).append("'").append(",")
//                .append("'").append(name).append("'").append(",")
//                .append("'").append(parentCode).append("'").append(",")
//                .append("'").append(mergeName).append("'").append(",")
//                .append("'").append(name).append("'").append(",")
//                .append("'").append(name).append("'").append(",")
//                .append(levelType).append(",")
//                .append("'").append(pinyin).append("'").append(",")
//                .append("'").append(pinyin.charAt(0)).append("'")
//                .append(");");
//            System.out.println(sql.toString());
//            lineList.add(sql.toString());
//
//            if (jObj.getJSONArray("children") != null) {
//                lineList.addAll(getChildSqls(jObj.getJSONArray("children"), levelType + 1, code, mergeName, format));
//            }
//        }
//        return lineList;
//    }
//
//}
