|
|
|
|
package com.dsideal.base.Tools;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
|
|
import com.dsideal.base.Tools.Util.SshConnectUtil;
|
|
|
|
|
import com.jcraft.jsch.JSchException;
|
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
public class ExportExcel {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, JSchException {
|
|
|
|
|
|
|
|
|
|
//通过ssh链接到Mysql数据库
|
|
|
|
|
Session session = SshConnectUtil.Init();
|
|
|
|
|
|
|
|
|
|
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 + "个。");
|
|
|
|
|
|
|
|
|
|
session.disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|