main
HuangHai 4 months ago
parent c908478377
commit 7577449831

@ -1,7 +1,7 @@
{
"2019": {
"skipRows": 7,
"基教小学": {
"skipRows": 7,
"schoolName": {
"index": 1,
"name": "学校名称",
@ -29,6 +29,7 @@
}
},
"初中": {
"skipRows": 7,
"schoolName": {
"index": 1,
"name": "学校名称",
@ -56,6 +57,7 @@
}
},
"高中": {
"skipRows": 7,
"schoolName": {
"index": 1,
"name": "学校名称",

@ -23,6 +23,13 @@ public class SchoolCountSummary {
public static final String configPath = "D:/dsWork/YunNanDsBase/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json";
public static final String excelPath = "D:/dsWork/2025年收集的人口与教育数据库20250328/2015-2020年的数据/基础教育";
public static void log(String msg){
//输出当前时间,保留到秒即可然后一个TAB,再输出msg
System.out.println(String.format("%s\t%s",
java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
msg));
}
public static void main(String[] args) throws FileNotFoundException {
// 一、关闭日志输出
CloseLogUtil.Init();
@ -30,12 +37,15 @@ public class SchoolCountSummary {
// 二、初始化数据库连接
LocalMysqlConnectUtil.Init();
// 三、开始读取数据
// 三、清空数据表
String sql="truncate table t_yn_school_count";
Db.update(sql);
// 四、开始读取数据
JSONObject config = JSON.parseObject(new FileReader(configPath));
// 遍历年份
for (String year : config.keySet()) {
//表头的行数
int skipRows = config.getJSONObject(year).getIntValue("skipRows");
log(String.format("开始处理年份:%s", year));
JSONObject yearConfig = config.getJSONObject(year);
String filePath = String.format(excelPath + "/%s.xlsx", year);
@ -48,8 +58,12 @@ public class SchoolCountSummary {
JSONObject typeConfig = yearConfig.getJSONObject(schoolType);
Map<String, ColumnConfig> columnConfigs = new HashMap<>();
//表头的行数
int skipRows = typeConfig.getIntValue("skipRows");
// 转换配置为ColumnConfig对象
for (String key : typeConfig.keySet()) {
if (key.equals("skipRows")) continue;
JSONObject colConfig = typeConfig.getJSONObject(key);
columnConfigs.put(key, new ColumnConfig(
colConfig.getIntValue("index"),
@ -61,10 +75,14 @@ public class SchoolCountSummary {
// 处理当前学校类型的数据
allResults.put(schoolType, processSheet(filePath, schoolType, skipRows, columnConfigs));
}
log(String.format("处理年份:%s完成", year));
// 保存统计结果到数据库
log(String.format("开始保存年份:%s到数据库", year));
saveToDatabase(allResults, Integer.parseInt(year));
log(String.format("保存年份:%s到数据库完成", year));
}
log("所有年份处理完成");
}
/**

Loading…
Cancel
Save