|
|
|
@ -5,6 +5,8 @@ import cn.hutool.core.io.file.PathUtil;
|
|
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
|
|
import com.dsideal.base.Plugin.YamlProp;
|
|
|
|
|
import com.dsideal.base.Util.ExcelCommonUtil;
|
|
|
|
|
import com.dsideal.base.Util.SSHConnector;
|
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
|
import com.jfinal.kit.FileKit;
|
|
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
|
|
import com.jfinal.kit.Prop;
|
|
|
|
@ -23,113 +25,132 @@ public class InitDataEaseDataSet {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
//加载配置文件
|
|
|
|
|
String configFile = "application_dev.yaml";
|
|
|
|
|
Prop PropKit = new YamlProp(configFile);
|
|
|
|
|
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
|
|
|
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
|
|
|
|
masterPlugin.start();
|
|
|
|
|
|
|
|
|
|
HikariCpPlugin dataEasePlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl").replace("ds_db", DataEaseModel.DB_NAME), PropKit.get("mysql.user"),
|
|
|
|
|
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
|
|
|
|
dataEasePlugin.start();
|
|
|
|
|
|
|
|
|
|
// 配置ActiveRecord插件
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin("master", masterPlugin);
|
|
|
|
|
arp.setDialect(new MysqlDialect());
|
|
|
|
|
|
|
|
|
|
ActiveRecordPlugin arpDataEase = new ActiveRecordPlugin(DataEaseModel.DB_NAME, dataEasePlugin);
|
|
|
|
|
arpDataEase.setDialect(new MysqlDialect());
|
|
|
|
|
|
|
|
|
|
//遍历sql目录下所有的sql文件
|
|
|
|
|
File sqlDir;
|
|
|
|
|
String basePath = InitDataEaseDataSet.class.getResource("/").getPath();
|
|
|
|
|
sqlDir = new File(basePath + "/Sql");
|
|
|
|
|
File[] sqlFiles = sqlDir.listFiles();
|
|
|
|
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
|
|
|
|
//只加载.sql文件
|
|
|
|
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
|
|
|
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
arpDataEase.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
arp.start();
|
|
|
|
|
arpDataEase.start();
|
|
|
|
|
|
|
|
|
|
DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
|
|
|
|
|
//1、添加到数据集表中
|
|
|
|
|
dm.collectDataSet();
|
|
|
|
|
//2、加上主键
|
|
|
|
|
dm.addPrimaryKey();
|
|
|
|
|
//3、将所有非空列去掉不允许为空的限制
|
|
|
|
|
dm.updateNotNullColumns();
|
|
|
|
|
|
|
|
|
|
//4、遍历所有数据集的表
|
|
|
|
|
int total = 0;
|
|
|
|
|
for (int i = 1; i <= 3; i++) {//1:省管理员,2:市州管理员,3:县区管理员
|
|
|
|
|
switch (i) {
|
|
|
|
|
case 1:
|
|
|
|
|
System.out.println("正在处理省管理员需要看到的数据集~");
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
System.out.println("正在处理市州管理员需要看到的数据集~");
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
System.out.println("正在处理县区管理员需要看到的数据集~");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Excel的保存目录
|
|
|
|
|
String exportPath = "D:/360Downloads/Excel";
|
|
|
|
|
File directory = new File(exportPath);
|
|
|
|
|
// 检查目录是否存在
|
|
|
|
|
if (!directory.exists()) {
|
|
|
|
|
directory.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Record> list = dm.getDataSetByIdentityId(i);
|
|
|
|
|
System.out.println("数据集个数=" + list.size());
|
|
|
|
|
total += list.size();
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
String tableName = record.getStr("table_name");
|
|
|
|
|
String dataSetName = record.getStr("dataset_name");
|
|
|
|
|
System.out.println("正在处理数据集:" + dataSetName);
|
|
|
|
|
|
|
|
|
|
//省的导出全部,市州管理员只导出市州数据,县区管理员只导出县区数据
|
|
|
|
|
List<Record> tableData = new ArrayList<>();
|
|
|
|
|
String excelFileName = "";
|
|
|
|
|
String privinceName = "云南省";
|
|
|
|
|
Record privinceRecord = dm.getAreaByName(privinceName);
|
|
|
|
|
String privinceId = privinceRecord.getStr("id");
|
|
|
|
|
if (i == 1) {
|
|
|
|
|
//对此表中的数据进行直接导出EXCEL
|
|
|
|
|
String sql = "select * from `" + tableName + "`";
|
|
|
|
|
tableData = Db.use(DataEaseModel.DB_NAME).find(sql);
|
|
|
|
|
excelFileName = "【" + privinceName + "】" + dataSetName + ".xlsx";
|
|
|
|
|
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
|
|
|
|
|
} else if (i == 2) {
|
|
|
|
|
//枚举所有的市州数据,然后进行导出EXCEL
|
|
|
|
|
List<Record> cityList = dm.getAreaList(privinceId);
|
|
|
|
|
String cityName = "";
|
|
|
|
|
String cityId = "";
|
|
|
|
|
for (Record rCity : cityList) {
|
|
|
|
|
cityName = rCity.getStr("area_name");
|
|
|
|
|
cityId = rCity.getStr("id");
|
|
|
|
|
if (i == 3) {
|
|
|
|
|
|
|
|
|
|
//枚举所有的县区数据,然后进行导出EXCEL
|
|
|
|
|
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String sql = "select * from `" + tableName + "` where `行政区划`=?";
|
|
|
|
|
System.out.println(tableName);
|
|
|
|
|
tableData = Db.use(DataEaseModel.DB_NAME).find(sql, cityName);
|
|
|
|
|
excelFileName = "【" + cityName + "】" + dataSetName + ".xlsx";
|
|
|
|
|
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
|
|
|
|
|
//远程主机的SSH登录信息
|
|
|
|
|
String sshHost = "117.78.60.214";
|
|
|
|
|
int sshPort = 52025;
|
|
|
|
|
String sshUser = "root";
|
|
|
|
|
String sshPassword = "DsIdeal@123";
|
|
|
|
|
String mysqlHost = "127.0.0.1"; // MySQL server host
|
|
|
|
|
int mysqlPort = 3306; // MySQL server port
|
|
|
|
|
Session session = SSHConnector.createSSHSession(sshHost, sshPort, sshUser, sshPassword);
|
|
|
|
|
try {
|
|
|
|
|
int localPort = 33306; // Local port to forward to MySQL server
|
|
|
|
|
session.setPortForwardingL(localPort, mysqlHost, mysqlPort);
|
|
|
|
|
String jdbcUrl = "jdbc:mysql://localhost:" + localPort + "/ds_db";
|
|
|
|
|
|
|
|
|
|
String user = "root";
|
|
|
|
|
String password = "Password123@mysql";
|
|
|
|
|
String driverClassName = "com.mysql.cj.jdbc.Driver";
|
|
|
|
|
|
|
|
|
|
HikariCpPlugin masterPlugin = new HikariCpPlugin(jdbcUrl, user, password, driverClassName);
|
|
|
|
|
masterPlugin.start();
|
|
|
|
|
|
|
|
|
|
HikariCpPlugin dataEasePlugin = new HikariCpPlugin(jdbcUrl.replace("ds_db", DataEaseModel.DB_NAME), user, password, driverClassName);
|
|
|
|
|
dataEasePlugin.start();
|
|
|
|
|
|
|
|
|
|
// 配置ActiveRecord插件
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(masterPlugin);
|
|
|
|
|
arp.setDialect(new MysqlDialect());
|
|
|
|
|
|
|
|
|
|
ActiveRecordPlugin arpDataEase = new ActiveRecordPlugin(DataEaseModel.DB_NAME, dataEasePlugin);
|
|
|
|
|
arpDataEase.setDialect(new MysqlDialect());
|
|
|
|
|
|
|
|
|
|
//遍历sql目录下所有的sql文件
|
|
|
|
|
File sqlDir;
|
|
|
|
|
String basePath = InitDataEaseDataSet.class.getResource("/").getPath();
|
|
|
|
|
sqlDir = new File(basePath + "/Sql");
|
|
|
|
|
File[] sqlFiles = sqlDir.listFiles();
|
|
|
|
|
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
|
|
|
|
|
//只加载.sql文件
|
|
|
|
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
|
|
|
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
arpDataEase.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
arp.start();
|
|
|
|
|
arpDataEase.start();
|
|
|
|
|
|
|
|
|
|
DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
|
|
|
|
|
//1、添加到数据集表中
|
|
|
|
|
dm.collectDataSet();
|
|
|
|
|
//2、加上主键
|
|
|
|
|
dm.addPrimaryKey();
|
|
|
|
|
//3、将所有非空列去掉不允许为空的限制
|
|
|
|
|
dm.updateNotNullColumns();
|
|
|
|
|
|
|
|
|
|
// //4、遍历所有数据集的表
|
|
|
|
|
// int total = 0;
|
|
|
|
|
// for (int i = 1; i <= 3; i++) {//1:省管理员,2:市州管理员,3:县区管理员
|
|
|
|
|
// switch (i) {
|
|
|
|
|
// case 1:
|
|
|
|
|
// System.out.println("正在处理省管理员需要看到的数据集~");
|
|
|
|
|
// break;
|
|
|
|
|
// case 2:
|
|
|
|
|
// System.out.println("正在处理市州管理员需要看到的数据集~");
|
|
|
|
|
// break;
|
|
|
|
|
// case 3:
|
|
|
|
|
// System.out.println("正在处理县区管理员需要看到的数据集~");
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// //Excel的保存目录
|
|
|
|
|
// String exportPath = "D:/360Downloads/Excel";
|
|
|
|
|
// File directory = new File(exportPath);
|
|
|
|
|
// // 检查目录是否存在
|
|
|
|
|
// if (!directory.exists()) {
|
|
|
|
|
// directory.mkdirs();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// List<Record> list = dm.getDataSetByIdentityId(i);
|
|
|
|
|
// System.out.println("数据集个数=" + list.size());
|
|
|
|
|
// total += list.size();
|
|
|
|
|
// for (Record record : list) {
|
|
|
|
|
// String tableName = record.getStr("table_name");
|
|
|
|
|
// String dataSetName = record.getStr("dataset_name");
|
|
|
|
|
// System.out.println("正在处理数据集:" + dataSetName);
|
|
|
|
|
//
|
|
|
|
|
// //省的导出全部,市州管理员只导出市州数据,县区管理员只导出县区数据
|
|
|
|
|
// List<Record> tableData = new ArrayList<>();
|
|
|
|
|
// String excelFileName = "";
|
|
|
|
|
// String privinceName = "云南省";
|
|
|
|
|
// Record privinceRecord = dm.getAreaByName(privinceName);
|
|
|
|
|
// String privinceId = privinceRecord.getStr("id");
|
|
|
|
|
// if (i == 1) {
|
|
|
|
|
// //对此表中的数据进行直接导出EXCEL
|
|
|
|
|
// String sql = "select * from `" + tableName + "`";
|
|
|
|
|
// tableData = Db.use(DataEaseModel.DB_NAME).find(sql);
|
|
|
|
|
// excelFileName = "【" + privinceName + "】" + dataSetName + ".xlsx";
|
|
|
|
|
// ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
|
|
|
|
|
// } else if (i == 2) {
|
|
|
|
|
// //枚举所有的市州数据,然后进行导出EXCEL
|
|
|
|
|
// List<Record> cityList = dm.getAreaList(privinceId);
|
|
|
|
|
// String cityName = "";
|
|
|
|
|
// String cityId = "";
|
|
|
|
|
// for (Record rCity : cityList) {
|
|
|
|
|
// cityName = rCity.getStr("area_name");
|
|
|
|
|
// cityId = rCity.getStr("id");
|
|
|
|
|
// if (i == 3) {
|
|
|
|
|
//
|
|
|
|
|
// //枚举所有的县区数据,然后进行导出EXCEL
|
|
|
|
|
// ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// String sql = "select * from `" + tableName + "` where `行政区划`=?";
|
|
|
|
|
// System.out.println(tableName);
|
|
|
|
|
// tableData = Db.use(DataEaseModel.DB_NAME).find(sql, cityName);
|
|
|
|
|
// excelFileName = "【" + cityName + "】" + dataSetName + ".xlsx";
|
|
|
|
|
// ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + excelFileName, true);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// System.out.println("恭喜,所有数据处理完毕,共生成数据集数量=" + total + "个。");
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
System.out.println(e.toString());
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
session.disconnect();
|
|
|
|
|
}
|
|
|
|
|
System.out.println("恭喜,所有数据处理完毕,共生成数据集数量=" + total + "个。");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|