|
|
|
|
package com.dsideal.base.Tools.Excel;
|
|
|
|
|
|
|
|
|
|
import ch.qos.logback.classic.Level;
|
|
|
|
|
import ch.qos.logback.classic.Logger;
|
|
|
|
|
import cn.idev.excel.*;
|
|
|
|
|
import com.dsideal.base.Tools.Excel.Bean.BeanSchool2019;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class School2019 {
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
// 设置 com.alibaba.excel 的日志级别为 INFO
|
|
|
|
|
Logger excelLogger = (Logger) LoggerFactory.getLogger("cn.idev.excel");
|
|
|
|
|
excelLogger.setLevel(Level.INFO);
|
|
|
|
|
String filePath = "D:/dsWork/2025年收集的人口与教育数据库(20250328)/2015-2020年的数据/基础教育/2019.xlsx";
|
|
|
|
|
String sheetName = "基教小学";
|
|
|
|
|
//跳过前7行
|
|
|
|
|
int skipRows = 7;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 从第8行开始读取(跳过前7行)
|
|
|
|
|
List<BeanSchool2019> dataList = FastExcel.read(filePath)
|
|
|
|
|
.head(BeanSchool2019.class)
|
|
|
|
|
.sheet(sheetName)
|
|
|
|
|
.headRowNumber(skipRows) // 跳过前skipRows行
|
|
|
|
|
.doReadSync();
|
|
|
|
|
|
|
|
|
|
// 使用 Map 进行分组统计
|
|
|
|
|
Map<String, Map<String, Integer>> cityDistrictMap = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
for (BeanSchool2019 data : dataList) {
|
|
|
|
|
if (data.getSchoolCount() > 0) {
|
|
|
|
|
String city = data.getCity();
|
|
|
|
|
String district = data.getDistrict();
|
|
|
|
|
int count = data.getSchoolCount();
|
|
|
|
|
|
|
|
|
|
// 如果市不存在,创建新的 Map
|
|
|
|
|
cityDistrictMap.putIfAbsent(city, new HashMap<>());
|
|
|
|
|
|
|
|
|
|
// 累加区对应的学校数量
|
|
|
|
|
cityDistrictMap.get(city).merge(district, count, Integer::sum);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 输出分组统计结果
|
|
|
|
|
for (Map.Entry<String, Map<String, Integer>> cityEntry : cityDistrictMap.entrySet()) {
|
|
|
|
|
String city = cityEntry.getKey();
|
|
|
|
|
System.out.println("市: " + city);
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Integer> districtEntry : cityEntry.getValue().entrySet()) {
|
|
|
|
|
System.out.printf(" 区: %s, 学校总数: %d%n",
|
|
|
|
|
districtEntry.getKey(),
|
|
|
|
|
districtEntry.getValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|