From 04139a1a7ddb24c14b7b086666e487062f05de76 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Wed, 9 Apr 2025 14:18:13 +0800 Subject: [PATCH] 'commit' --- .../Tools/JkyNewData/Data/SchoolCount.json | 156 +++++++++--------- .../Tools/JkyNewData/SchoolCountSummary.java | 64 +++---- 2 files changed, 114 insertions(+), 106 deletions(-) diff --git a/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json b/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json index 57979f57..da332478 100644 --- a/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json +++ b/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json @@ -1,83 +1,85 @@ { - "小学": { - "schoolName": { - "index": 1, - "name": "学校名称", - "type": "String" + "2019": { + "小学": { + "schoolName": { + "index": 1, + "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, - "name": "学校类型", - "type": "String" + "初中": { + "schoolName": { + "index": 1, + "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, - "name": "学校数量", - "type": "Integer" - }, - "city": { - "index": 350, - "name": "市", - "type": "String" - }, - "district": { - "index": 351, - "name": "区", - "type": "String" - } - }, - "初中": { - "schoolName": { - "index": 1, - "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" - } - }, - "高中": { - "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" + "高中": { + "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" + } } } } \ No newline at end of file diff --git a/src/main/java/com/dsideal/base/Tools/JkyNewData/SchoolCountSummary.java b/src/main/java/com/dsideal/base/Tools/JkyNewData/SchoolCountSummary.java index cab25294..487f089c 100644 --- a/src/main/java/com/dsideal/base/Tools/JkyNewData/SchoolCountSummary.java +++ b/src/main/java/com/dsideal/base/Tools/JkyNewData/SchoolCountSummary.java @@ -28,44 +28,50 @@ public class SchoolCountSummary { 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)); - String filePath = "D:/dsWork/2025年收集的人口与教育数据库(20250328)/2015-2020年的数据/基础教育/2019.xlsx"; - // 创建一个Map来存储所有处理结果 - Map>> allResults = new HashMap<>(); - - // 循环处理每种学校类型 - for (String schoolType : config.keySet()) { - // 获取当前学校类型的配置 - JSONObject typeConfig = config.getJSONObject(schoolType); - Map columnConfigs = new HashMap<>(); - - // 转换配置为ColumnConfig对象 - for (String key : typeConfig.keySet()) { - JSONObject colConfig = typeConfig.getJSONObject(key); - columnConfigs.put(key, new ColumnConfig( - colConfig.getIntValue("index"), - colConfig.getString("name"), - colConfig.getString("type") - )); + // 遍历年份 + for (String year : config.keySet()) { + JSONObject yearConfig = config.getJSONObject(year); + String filePath = String.format(excelPath + "/%s.xlsx", year); + + // 创建一个Map来存储所有处理结果 + Map>> allResults = new HashMap<>(); + + // 循环处理每种学校类型 + for (String schoolType : yearConfig.keySet()) { + // 获取当前学校类型的配置 + JSONObject typeConfig = yearConfig.getJSONObject(schoolType); + Map columnConfigs = new HashMap<>(); + + // 转换配置为ColumnConfig对象 + for (String key : typeConfig.keySet()) { + 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; - allResults.put(schoolType, processSheet(filePath, sheetName, 7, columnConfigs)); + // 保存统计结果到数据库 + saveToDatabase(allResults, Integer.parseInt(year)); } - - // 保存统计结果到数据库 - saveToDatabase(allResults, 2019); } /** * 处理指定 Sheet 表的数据 * - * @param filePath 文件路径 - * @param sheetName Sheet 表名称 - * @param skipRows 跳过的行数 + * @param filePath 文件路径 + * @param sheetName Sheet 表名称 + * @param skipRows 跳过的行数 * @param columnConfigs 列配置 * @return 处理结果Map */ @@ -107,7 +113,7 @@ public class SchoolCountSummary { * 将统计结果保存到数据库 * * @param allResults 所有处理结果 - * @param year 年份 + * @param year 年份 */ private static void saveToDatabase(Map>> allResults, int year) { // 先删除该年份的旧数据