|
|
@@ -1,213 +0,0 @@
|
|
|
-package me.zhengjie.application.bank.controller.vo;
|
|
|
-
|
|
|
-import java.sql.Connection;
|
|
|
-import java.sql.DriverManager;
|
|
|
-import java.sql.ResultSet;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.sql.Statement;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-
|
|
|
-import cn.hutool.core.io.file.FileReader;
|
|
|
-
|
|
|
-public class CityDto {
|
|
|
- // MySQL 8.0 以下版本 - JDBC 驱动名及数据库 URL
|
|
|
- static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
|
|
- static final String DB_URL = "jdbc:mysql://114.55.230.80:3306/eladmin";
|
|
|
-
|
|
|
- // MySQL 8.0 以上版本 - JDBC 驱动名及数据库 URL
|
|
|
- // static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
|
|
|
- // static final String DB_URL =
|
|
|
- // "jdbc:mysql://localhost:3306/RUNOOB?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
|
|
|
-
|
|
|
- // 数据库的用户名与密码,需要根据自己的设置
|
|
|
- static final String USER = "root";
|
|
|
- static final String PASS = "QopraffaQWPRPPR123";
|
|
|
-
|
|
|
- public static void main(String[] args) throws SQLException {
|
|
|
- zhixiaoshi();
|
|
|
- }
|
|
|
-
|
|
|
- public static void zhixiaoshi() throws SQLException {
|
|
|
- // show();
|
|
|
- // insert();
|
|
|
- FileReader shanghai = new FileReader("E:\\logs\\node_modules\\china-area-data\\shanghai.txt");
|
|
|
- List<String> strs = shanghai.readLines();
|
|
|
-
|
|
|
- FileReader beijing = new FileReader("E:\\logs\\node_modules\\china-area-data\\beijing.txt");
|
|
|
- strs.addAll(beijing.readLines()) ;
|
|
|
-
|
|
|
- FileReader chongqing = new FileReader("E:\\logs\\node_modules\\china-area-data\\chongqing.txt");
|
|
|
- strs.addAll(chongqing.readLines()) ;
|
|
|
-
|
|
|
- FileReader tianjin = new FileReader("E:\\logs\\node_modules\\china-area-data\\tianjin.txt");
|
|
|
- strs.addAll(tianjin.readLines()) ;
|
|
|
-
|
|
|
-
|
|
|
- Connection conn = null;
|
|
|
- Statement stmt = null;
|
|
|
-
|
|
|
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
|
|
|
-
|
|
|
- // 执行查询
|
|
|
-
|
|
|
- stmt = conn.createStatement();
|
|
|
- for (String str : strs) {
|
|
|
- if (StringUtils.isNotBlank(str)) {
|
|
|
- String code = str.split("\t")[0];
|
|
|
- String index = code.substring(0, 6);
|
|
|
-
|
|
|
- String sql = " insert into area(code,city_code,area_name)values('" + code + "','" + index + "','"
|
|
|
- + str.split("\t")[1] + "')";
|
|
|
- stmt.executeUpdate(sql);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
- public static void insert() {
|
|
|
-
|
|
|
- Connection conn = null;
|
|
|
- Statement stmt = null;
|
|
|
- try {
|
|
|
- // 注册 JDBC 驱动
|
|
|
- Class.forName(JDBC_DRIVER);
|
|
|
-
|
|
|
- // 打开链接
|
|
|
- System.out.println("连接数据库...");
|
|
|
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
|
|
|
-
|
|
|
- // 执行查询
|
|
|
- System.out.println(" 实例化Statement对象...");
|
|
|
- stmt = conn.createStatement();
|
|
|
- JSONObject jsonobj = show();
|
|
|
- List<String> list = new ArrayList<String>();
|
|
|
- for (String str : jsonobj.keySet()) {
|
|
|
- list.add(str);
|
|
|
- }
|
|
|
- Collections.sort(list);
|
|
|
- for (String str : list) {
|
|
|
- String sql = " insert into city(city_id,province_id,name)values('" + str + "','120100','"
|
|
|
- + jsonobj.getString(str) + "')";
|
|
|
- stmt.executeUpdate(sql);
|
|
|
- }
|
|
|
-
|
|
|
- stmt.close();
|
|
|
- conn.close();
|
|
|
- } catch (SQLException se) {
|
|
|
- // 处理 JDBC 错误
|
|
|
- se.printStackTrace();
|
|
|
- } catch (Exception e) {
|
|
|
- // 处理 Class.forName 错误
|
|
|
- e.printStackTrace();
|
|
|
- } finally {
|
|
|
- // 关闭资源
|
|
|
- try {
|
|
|
- if (stmt != null)
|
|
|
- stmt.close();
|
|
|
- } catch (SQLException se2) {
|
|
|
- } // 什么都不做
|
|
|
- try {
|
|
|
- if (conn != null)
|
|
|
- conn.close();
|
|
|
- } catch (SQLException se) {
|
|
|
- se.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- System.out.println("Goodbye!");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public static JSONObject show() throws SQLException {
|
|
|
- FileReader file = new FileReader("E:\\logs\\node_modules\\china-area-data\\data.json");
|
|
|
- List<String> strs = file.readLines();
|
|
|
- StringBuffer sb = new StringBuffer();
|
|
|
- for (String str : strs) {
|
|
|
- sb.append(str);
|
|
|
- }
|
|
|
-
|
|
|
- Connection conn = null;
|
|
|
- Statement stmt = null;
|
|
|
-
|
|
|
- conn = DriverManager.getConnection(DB_URL, USER, PASS);
|
|
|
-
|
|
|
- // 执行查询
|
|
|
- System.out.println(" 实例化Statement对象...");
|
|
|
- stmt = conn.createStatement();
|
|
|
-
|
|
|
- JSONObject jsonObject = JSON.parseObject(sb.toString());
|
|
|
- JSONObject result = jsonObject.getJSONObject("86");
|
|
|
-
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
- // 取省份
|
|
|
- for (String str : result.keySet()) {
|
|
|
- list.add(str);
|
|
|
- }
|
|
|
- Collections.sort(list);
|
|
|
- for (String str : list) {
|
|
|
- List<String> cityList = new ArrayList<>();
|
|
|
- for (String city : jsonObject.getJSONObject(str).keySet()) {
|
|
|
- String value = jsonObject.getJSONObject(str).getString(city);
|
|
|
-
|
|
|
- if (value.equals("市辖区")) {
|
|
|
- // isshi = true;
|
|
|
- // 插入市区
|
|
|
- JSONObject syq = jsonObject.getJSONObject(city);
|
|
|
- List<String> quyu = new ArrayList<>();
|
|
|
- for (String aaa : syq.keySet()) {
|
|
|
- quyu.add(aaa);
|
|
|
- }
|
|
|
- Collections.sort(quyu);
|
|
|
-
|
|
|
- for (String str2 : quyu) {
|
|
|
- String sql = " insert into city(code,province_code,city_name)values('" + str2 + "','" + str
|
|
|
- + "','" + syq.getString(str2) + "')";
|
|
|
- stmt.executeUpdate(sql);
|
|
|
- }
|
|
|
-
|
|
|
- continue;
|
|
|
- }
|
|
|
- cityList.add(city);
|
|
|
- }
|
|
|
- if (cityList != null && cityList.size() > 0) {
|
|
|
- Collections.sort(cityList);
|
|
|
-
|
|
|
- for (String jiedao : cityList) {
|
|
|
- List<String> jiedaoList = new ArrayList<>();
|
|
|
- JSONObject json = jsonObject.getJSONObject(jiedao);
|
|
|
- for (String aa : json.keySet()) {
|
|
|
- jiedaoList.add(aa);
|
|
|
- }
|
|
|
- Collections.sort(jiedaoList);
|
|
|
- for (String str2 : jiedaoList) {
|
|
|
- System.out.println(str2);
|
|
|
- if (str2.equals("130101")) {
|
|
|
- System.out.println("333");
|
|
|
- }
|
|
|
- if (json.getString(str2).equals("市辖区")) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- String sql = " insert into area(code,city_code,area_name)values('" + str2 + "','" + jiedao
|
|
|
- + "','" + json.getString(str2) + "')";
|
|
|
- stmt.executeUpdate(sql);
|
|
|
- }
|
|
|
- String syq = jsonObject.getJSONObject(str).getString(jiedao);
|
|
|
- String sql = " insert into city(code,province_code,city_name)values('" + jiedao + "','" + str
|
|
|
- + "','" + syq + "')";
|
|
|
- stmt.executeUpdate(sql);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return result;
|
|
|
- }
|
|
|
-}
|