main
黄海 9 months ago
parent c5336cfff7
commit ed55b5ff9d

@ -283,4 +283,25 @@ public class DataEaseModel {
collectDataSet(parent_name, table_name, dataset_name, dataease_id);
}
}
/**
*
*
* @param area_name
* @return
*/
public Record getAreaByName(String area_name) {
String sql = "select * from t_dm_area where area_name=?";
return Db.findFirst(sql, area_name);
}
/**
* id
* @param parent_id id
* @return
*/
public List<Record> getAreaList(String parent_id){
String sql = "select * from t_dm_area where parent_id=?";
return Db.find(sql, parent_id);
}
}

@ -16,6 +16,7 @@ import com.jfinal.plugin.activerecord.Record;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class InitDataEaseDataSet {
@ -91,17 +92,42 @@ public class InitDataEaseDataSet {
System.out.println("数据集个数=" + list.size());
total += list.size();
for (Record record : list) {
int id = record.getInt("id");
String tableName = record.getStr("table_name");
System.out.println("正在处理数据集:" + tableName);
//对此表中的数据进行直接导出EXCEL
String sql = "select * from `" + tableName + "`";
List<Record> tableData = Db.use(DataEaseModel.DB_NAME).find(sql);
//表tableData中如果有一列叫id,那么去掉这一列
for (Record tableDatum : tableData) {
tableDatum.remove("id");
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);
}
ExcelCommonUtil.writeExcel(tableData, exportPath + "/" + tableName + ".xlsx");
}
}
System.out.println("恭喜,所有数据处理完毕,共生成数据集数量=" + total + "个。");

@ -848,17 +848,25 @@ public class ExcelCommonUtil {
/**
* List<Record>Excel
*
* @param records
* @param tableData
* @param filePath
* @throws IOException
*/
public static void writeExcel(List<Record> records, String filePath) throws IOException {
if (records == null || records.isEmpty()) {
throw new IllegalArgumentException("The list of records must not be empty.");
public static void writeExcel(List<Record> tableData, String filePath, boolean killIdColumns) throws IOException {
if (killIdColumns) {
//表tableData中如果有一列叫id,那么去掉这一列
for (Record tableDatum : tableData) {
tableDatum.remove("id");
}
}
if (tableData == null || tableData.isEmpty()) {
//throw new IllegalArgumentException("The list of records must not be empty.");
return;
}
// 获取第一个Record的元数据以确定列名
Record firstRecord = records.getFirst();
Record firstRecord = tableData.getFirst();
String[] headers = firstRecord.getColumnNames();
int columnCount = headers.length;
@ -899,7 +907,7 @@ public class ExcelCommonUtil {
// 填充数据行
int rowNum = 1;
for (Record record : records) {
for (Record record : tableData) {
Row row = sheet.createRow(rowNum++);
int cellNum = 0;
for (int i = 1; i <= columnCount; i++) {

Loading…
Cancel
Save