main
HuangHai 4 months ago
parent 29bab5972d
commit 04139a1a7d

@ -1,83 +1,85 @@
{ {
"小学": { "2019": {
"schoolName": { "小学": {
"index": 1, "schoolName": {
"name": "学校名称", "index": 1,
"type": "String" "name": "学校名称",
"type": "String"
},
"schoolType": {
"index": 3,
"name": "学校类型",
"type": "String"
},
"schoolCount": {
"index": 5,
"name": "学校数量",
"type": "Integer"
},
"city": {
"index": 350,
"name": "市",
"type": "String"
},
"district": {
"index": 351,
"name": "区",
"type": "String"
}
}, },
"schoolType": { "初中": {
"index": 3, "schoolName": {
"name": "学校类型", "index": 1,
"type": "String" "name": "学校名称",
"type": "String"
},
"schoolType": {
"index": 3,
"name": "学校类型",
"type": "String"
},
"schoolCount": {
"index": 5,
"name": "学校数量",
"type": "Integer"
},
"city": {
"index": 374,
"name": "市",
"type": "String"
},
"district": {
"index": 375,
"name": "区",
"type": "String"
}
}, },
"schoolCount": { "高中": {
"index": 5, "schoolName": {
"name": "学校数量", "index": 1,
"type": "Integer" "name": "学校名称",
}, "type": "String"
"city": { },
"index": 350, "schoolType": {
"name": "市", "index": 3,
"type": "String" "name": "学校类型",
}, "type": "String"
"district": { },
"index": 351, "schoolCount": {
"name": "区", "index": 5,
"type": "String" "name": "学校数量",
} "type": "Integer"
}, },
"初中": { "city": {
"schoolName": { "index": 320,
"index": 1, "name": "市",
"name": "学校名称", "type": "String"
"type": "String" },
}, "district": {
"schoolType": { "index": 321,
"index": 3, "name": "区",
"name": "学校类型", "type": "String"
"type": "String" }
},
"schoolCount": {
"index": 5,
"name": "学校数量",
"type": "Integer"
},
"city": {
"index": 374,
"name": "市",
"type": "String"
},
"district": {
"index": 375,
"name": "区",
"type": "String"
}
},
"高中": {
"schoolName": {
"index": 1,
"name": "学校名称",
"type": "String"
},
"schoolType": {
"index": 3,
"name": "学校类型",
"type": "String"
},
"schoolCount": {
"index": 5,
"name": "学校数量",
"type": "Integer"
},
"city": {
"index": 320,
"name": "市",
"type": "String"
},
"district": {
"index": 321,
"name": "区",
"type": "String"
} }
} }
} }

@ -28,44 +28,50 @@ public class SchoolCountSummary {
LocalMysqlConnectUtil.Init(); LocalMysqlConnectUtil.Init();
// 读取配置文件 // 读取配置文件
String configPath = "D:/dsWork/YunNanDsBase/src/main/java/com/dsideal/base/Tools/Excel/Data/SchoolCount.json"; String configPath = "D:/dsWork/YunNanDsBase/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json";
String excelPath = "D:/dsWork/2025年收集的人口与教育数据库20250328/2015-2020年的数据/基础教育";
JSONObject config = JSON.parseObject(new FileReader(configPath)); JSONObject config = JSON.parseObject(new FileReader(configPath));
String filePath = "D:/dsWork/2025年收集的人口与教育数据库20250328/2015-2020年的数据/基础教育/2019.xlsx"; // 遍历年份
// 创建一个Map来存储所有处理结果 for (String year : config.keySet()) {
Map<String, Map<String, Map<String, Integer>>> allResults = new HashMap<>(); JSONObject yearConfig = config.getJSONObject(year);
String filePath = String.format(excelPath + "/%s.xlsx", year);
// 循环处理每种学校类型
for (String schoolType : config.keySet()) { // 创建一个Map来存储所有处理结果
// 获取当前学校类型的配置 Map<String, Map<String, Map<String, Integer>>> allResults = new HashMap<>();
JSONObject typeConfig = config.getJSONObject(schoolType);
Map<String, ColumnConfig> columnConfigs = new HashMap<>(); // 循环处理每种学校类型
for (String schoolType : yearConfig.keySet()) {
// 转换配置为ColumnConfig对象 // 获取当前学校类型的配置
for (String key : typeConfig.keySet()) { JSONObject typeConfig = yearConfig.getJSONObject(schoolType);
JSONObject colConfig = typeConfig.getJSONObject(key); Map<String, ColumnConfig> columnConfigs = new HashMap<>();
columnConfigs.put(key, new ColumnConfig(
colConfig.getIntValue("index"), // 转换配置为ColumnConfig对象
colConfig.getString("name"), for (String key : typeConfig.keySet()) {
colConfig.getString("type") JSONObject colConfig = typeConfig.getJSONObject(key);
)); columnConfigs.put(key, new ColumnConfig(
colConfig.getIntValue("index"),
colConfig.getString("name"),
colConfig.getString("type")
));
}
// 处理当前学校类型的数据
String sheetName = "基教" + schoolType;
allResults.put(schoolType, processSheet(filePath, sheetName, 7, columnConfigs));
} }
// 处理当前学校类型的数据 // 保存统计结果到数据库
String sheetName = "基教" + schoolType; saveToDatabase(allResults, Integer.parseInt(year));
allResults.put(schoolType, processSheet(filePath, sheetName, 7, columnConfigs));
} }
// 保存统计结果到数据库
saveToDatabase(allResults, 2019);
} }
/** /**
* Sheet * Sheet
* *
* @param filePath * @param filePath
* @param sheetName Sheet * @param sheetName Sheet
* @param skipRows * @param skipRows
* @param columnConfigs * @param columnConfigs
* @return Map * @return Map
*/ */
@ -107,7 +113,7 @@ public class SchoolCountSummary {
* *
* *
* @param allResults * @param allResults
* @param year * @param year
*/ */
private static void saveToDatabase(Map<String, Map<String, Map<String, Integer>>> allResults, int year) { private static void saveToDatabase(Map<String, Map<String, Map<String, Integer>>> allResults, int year) {
// 先删除该年份的旧数据 // 先删除该年份的旧数据

Loading…
Cancel
Save