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 deleted file mode 100644 index 3274466f..00000000 --- a/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "2019": { - "基教小学": { - "skipRows": 7, - "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" - } - }, - "初中": { - "skipRows": 7, - "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" - } - }, - "高中": { - "skipRows": 7, - "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/Data/SchoolCount_2019.json b/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount_2019.json new file mode 100644 index 00000000..939b41da --- /dev/null +++ b/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/SchoolCount_2019.json @@ -0,0 +1,114 @@ +{ + "基教幼儿园": { + "skipRows": 7, + "schoolName": { + "index": 1, + "name": "学校名称", + "type": "String" + }, + "schoolType": { + "index": 3, + "name": "学校类型", + "type": "String" + }, + "schoolCount": { + "index": 5, + "name": "学校数量", + "type": "Integer" + }, + "city": { + "index": 208, + "name": "市", + "type": "String" + }, + "district": { + "index": 209, + "name": "区", + "type": "String" + } + }, + "基教小学": { + "skipRows": 7, + "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" + } + }, + "基教初中": { + "skipRows": 7, + "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" + } + }, + "基教高中": { + "skipRows": 7, + "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" + } + } +} 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 426d24f8..0763f930 100644 --- a/src/main/java/com/dsideal/base/Tools/JkyNewData/SchoolCountSummary.java +++ b/src/main/java/com/dsideal/base/Tools/JkyNewData/SchoolCountSummary.java @@ -4,6 +4,7 @@ import cn.idev.excel.*; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; @@ -22,11 +23,10 @@ import static com.dsideal.base.Tools.JkyNewData.Util.CommonUtil.log; 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 configDir = "D:/dsWork/YunNanDsBase/src/main/java/com/dsideal/base/Tools/JkyNewData/Data/"; public static final String excelPath = "D:/dsWork/2025年收集的人口与教育数据库(20250328)/2015-2020年的数据/基础教育"; - public static void main(String[] args) throws FileNotFoundException { // 一、关闭日志输出 CloseLogUtil.Init(); @@ -35,55 +35,64 @@ public class SchoolCountSummary { LocalMysqlConnectUtil.Init(); // 三、清空数据表 - String sql="truncate table t_yn_school_count"; + String sql = "truncate table t_yn_school_count"; Db.update(sql); - // 四、开始读取数据 - JSONObject config = JSON.parseObject(new FileReader(configPath)); - // 遍历年份 - for (String year : config.keySet()) { - log(String.format("开始处理年份:%s", year)); - JSONObject yearConfig = config.getJSONObject(year); - String filePath = String.format(excelPath + "/%s.xlsx", year); - - // 创建一个Map来存储所有处理结果 - Map>> allResults = new HashMap<>(); - - // 循环处理每种学校类型 - for (String schoolType : yearConfig.keySet()) { - log(String.format("开始处理学校类型:%s", schoolType)); - // 获取当前学校类型的配置 - JSONObject typeConfig = yearConfig.getJSONObject(schoolType); - Map 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"), - colConfig.getString("name"), - colConfig.getString("type") - )); + // 四、获取所有配置文件 + File dir = new File(configDir); + File[] configFiles = dir.listFiles((d, name) -> name.matches("SchoolCount_\\d{4}\\.json")); + + if (configFiles != null) { + for (File configFile : configFiles) { + // 从文件名中提取年份 + String fileName = configFile.getName(); + String year = fileName.substring("SchoolCount_".length(), fileName.length() - 5); + log(String.format("开始处理年份:%s", year)); + + // 读取配置文件 + JSONObject config = JSON.parseObject(new FileReader(configFile)); + String filePath = String.format(excelPath + "/%s.xlsx", year); + + // 创建一个Map来存储所有处理结果 + Map>> allResults = new HashMap<>(); + + // 循环处理每种学校类型 + for (String schoolType : config.keySet()) { + log(String.format("开始处理学校类型:%s", schoolType)); + // 获取当前学校类型的配置 + JSONObject typeConfig = config.getJSONObject(schoolType); + Map 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"), + colConfig.getString("name"), + colConfig.getString("type") + )); + } + + // 处理当前学校类型的数据 + allResults.put(schoolType, processSheet(filePath, schoolType, skipRows, columnConfigs)); + log(String.format("处理学校类型:%s完成", schoolType)); } + log(String.format("处理年份:%s完成", year)); - // 处理当前学校类型的数据 - allResults.put(schoolType, processSheet(filePath, schoolType, skipRows, columnConfigs)); - log(String.format("处理学校类型:%s完成", schoolType)); + // 保存统计结果到数据库 + log(String.format("开始保存年份:%s到数据库", year)); + saveToDatabase(allResults, Integer.parseInt(year)); + log(String.format("保存年份:%s到数据库完成", year)); } - log(String.format("处理年份:%s完成", year)); - - // 保存统计结果到数据库 - log(String.format("开始保存年份:%s到数据库", year)); - saveToDatabase(allResults, Integer.parseInt(year)); - log(String.format("保存年份:%s到数据库完成", year)); } log("所有年份处理完成"); } + /** * 处理指定 Sheet 表的数据 * diff --git a/src/main/java/com/dsideal/base/Tools/JkyNewData/Util/ExcelUtil.java b/src/main/java/com/dsideal/base/Tools/JkyNewData/Util/ExcelUtil.java index b7156216..c10f8a13 100644 --- a/src/main/java/com/dsideal/base/Tools/JkyNewData/Util/ExcelUtil.java +++ b/src/main/java/com/dsideal/base/Tools/JkyNewData/Util/ExcelUtil.java @@ -53,4 +53,8 @@ public class ExcelUtil { return 0; } } + + public static void main(String[] args) { + System.out.println(columnLetterToIndex("HA")); + } }