|
|
|
@ -0,0 +1,179 @@
|
|
|
|
|
package com.dsideal.base.Tools.FillData.Area;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
|
|
|
|
|
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
|
|
|
|
|
import com.dsideal.base.Tools.Util.ReadDocxUtil;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class A5 {
|
|
|
|
|
|
|
|
|
|
//示例Excel
|
|
|
|
|
static String sampleExcelPath = "D:\\dsWork\\YunNanDsBase\\Doc\\待处理\\区\\【5】普通高中招生总量预测\\普通高中招生总量预测.xlsx";
|
|
|
|
|
|
|
|
|
|
//源文件
|
|
|
|
|
static String parentPath = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\133个县区报告2022\\县区研究报告";
|
|
|
|
|
|
|
|
|
|
//哪些是处理不了的,就不处理了~
|
|
|
|
|
static String[] excludeCityList = {"~$", "磨憨-磨丁", "经开区", "阳宗海"};
|
|
|
|
|
|
|
|
|
|
//有好多EXCEL,啥样的有用?必须带有关键字字样的才有用!
|
|
|
|
|
static String fileNameKey = "发展规模数据";
|
|
|
|
|
|
|
|
|
|
//第二个表格的表头信息
|
|
|
|
|
static String tableKeyword = "自动计算招生数、在校生数";
|
|
|
|
|
//第二个表格的表头有几行
|
|
|
|
|
static int tableHeadRows = 2;
|
|
|
|
|
//第二个表格的最后一列的列名
|
|
|
|
|
static String tableLetterIndex = "K";
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InvalidFormatException {
|
|
|
|
|
//初始化数据库连接
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
//实例化
|
|
|
|
|
ReadDocxUtil ru = new ReadDocxUtil();
|
|
|
|
|
|
|
|
|
|
//结果Excel
|
|
|
|
|
XSSFWorkbook outWorkbook = new XSSFWorkbook();
|
|
|
|
|
//结果Sheet
|
|
|
|
|
XSSFSheet outSheet = ExcelKit.CreateSheet(outWorkbook);
|
|
|
|
|
//样式
|
|
|
|
|
XSSFCellStyle headerStyle = ExcelKit.getHeaderStyle(outWorkbook);
|
|
|
|
|
XSSFCellStyle dataStyle = ExcelKit.getDataStyle(outWorkbook);
|
|
|
|
|
//如果样例文件是xls格式,则转化为xlsx格式
|
|
|
|
|
sampleExcelPath = ExcelKit.ConvertXlsToXlsx(sampleExcelPath);
|
|
|
|
|
//拷贝文件头
|
|
|
|
|
ExcelKit.CopyHead(sampleExcelPath, outSheet, headerStyle);
|
|
|
|
|
|
|
|
|
|
//目标Excel,就是把文件名解析出来后,后面添加上【成果】,需要动态计算获取,不能写死
|
|
|
|
|
String excelPath = sampleExcelPath.replace(".xlsx", "【成果】.xlsx");
|
|
|
|
|
ExcelKit.delExcel(excelPath);
|
|
|
|
|
|
|
|
|
|
//找到parentPath下一级目录中所有文件
|
|
|
|
|
List<File> files = FileUtil.loopFiles(parentPath, file -> true);
|
|
|
|
|
int rowIndex = 0;
|
|
|
|
|
|
|
|
|
|
//处理这个目录
|
|
|
|
|
if (files != null) {
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
//判断file是不是目录,是目录的需要跳过
|
|
|
|
|
if (file.isDirectory()) continue;
|
|
|
|
|
if (!file.getName().endsWith(".xlsx") && !file.getName().endsWith(".xls"))
|
|
|
|
|
continue;
|
|
|
|
|
boolean flag = false;
|
|
|
|
|
for (String s : excludeCityList) {
|
|
|
|
|
if (file.getName().contains(s)) {
|
|
|
|
|
flag = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (flag) continue;
|
|
|
|
|
//只关心发展规模数据的表格
|
|
|
|
|
if (!file.getName().contains(fileNameKey)) continue;
|
|
|
|
|
//县区名称
|
|
|
|
|
String areaName = ru.getCityOrAreaName(file.getName());
|
|
|
|
|
//市州名称
|
|
|
|
|
//此文件的路径中最后一层的目录名称,应该是带着市州名称 ,把最后一层子目录的名称提出
|
|
|
|
|
String parentPathName = file.getParentFile().getName();
|
|
|
|
|
String cityName = ru.getCityOrAreaName(parentPathName);
|
|
|
|
|
if (StrKit.isBlank(cityName) || cityName.equals(areaName)) {
|
|
|
|
|
parentPathName = file.getParentFile().getParentFile().getName();
|
|
|
|
|
cityName = ru.getCityOrAreaName(parentPathName);
|
|
|
|
|
}
|
|
|
|
|
if (StrKit.isBlank(cityName)||StrKit.isBlank(areaName)) {
|
|
|
|
|
System.out.println("发现异常数据,请人工处理:" + file.getName());
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//县区名称
|
|
|
|
|
System.out.println("正在进行" + cityName + "-" + areaName + "的数据填充~");
|
|
|
|
|
String sourceExcel = file.getAbsolutePath();
|
|
|
|
|
List<List<String>> dataList = ExcelKit.readSecondTable(sourceExcel, 3, tableKeyword,
|
|
|
|
|
tableHeadRows, tableLetterIndex);
|
|
|
|
|
|
|
|
|
|
//这个工作表有四个蓝色列:D:预测总招生数,E:修正城区招生A,F:修正镇区招生B,G:修正乡村招生C
|
|
|
|
|
//有时,有也三个蓝色列:D:预测总招生数,E:修正县城内招生,G:修正县城外招生
|
|
|
|
|
//处理办法:先判断是4个的还是3个的,如果是3个的,就把修正县城外招生拆分开两项,第一项=修正县城外招生*30%,第二项=修正县城外招生- 第一项
|
|
|
|
|
//至于是4个还是3个的,可以通过获取第二个table的列宽来获取,4列的时候,整个表的列数应该是11列,3列的时候,整个表的列数应该是9列
|
|
|
|
|
//取出第一行
|
|
|
|
|
if (dataList.isEmpty()) continue;
|
|
|
|
|
List<String> x = dataList.getFirst();
|
|
|
|
|
int cnt = 0;
|
|
|
|
|
for (String s : x) if (s == null) cnt++;
|
|
|
|
|
int colsCount = x.size() - cnt;
|
|
|
|
|
|
|
|
|
|
//入园总数
|
|
|
|
|
for (List<String> stringList : dataList) {
|
|
|
|
|
//年份
|
|
|
|
|
int year = Integer.parseInt(stringList.getFirst());
|
|
|
|
|
//D预测总招生数
|
|
|
|
|
String v = stringList.get(ExcelKit.transLetter2Num("D")).split("\\.")[0];
|
|
|
|
|
Row outRow = outSheet.createRow(++rowIndex);
|
|
|
|
|
ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year), "总招生数", "", v, "", areaName, cityName), dataStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2022入园基数
|
|
|
|
|
for (List<String> ignored : dataList) {
|
|
|
|
|
//年份
|
|
|
|
|
int year = 2022;
|
|
|
|
|
//D预测总招生数
|
|
|
|
|
int v = Integer.parseInt(dataList.getFirst().get(ExcelKit.transLetter2Num("D")).split("\\.")[0]);
|
|
|
|
|
Row outRow = outSheet.createRow(++rowIndex);
|
|
|
|
|
ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year), "2022年基数", "", String.valueOf(v), "", areaName, cityName), dataStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//城区
|
|
|
|
|
for (List<String> stringList : dataList) {
|
|
|
|
|
//年份
|
|
|
|
|
int year = Integer.parseInt(stringList.getFirst());
|
|
|
|
|
//E:修正城区招生A 修正县城内招生
|
|
|
|
|
int v = Integer.parseInt(stringList.get(ExcelKit.transLetter2Num("E")).split("\\.")[0]);
|
|
|
|
|
Row outRow = outSheet.createRow(++rowIndex);
|
|
|
|
|
ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year),
|
|
|
|
|
"", "城区", "", String.valueOf(v), areaName, cityName), dataStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//修正镇区招生B 修正县城外招生*30%
|
|
|
|
|
for (List<String> stringList : dataList) {
|
|
|
|
|
//年份
|
|
|
|
|
int year = Integer.parseInt(stringList.getFirst());
|
|
|
|
|
//F:修正镇区招生B 修正县城内招生
|
|
|
|
|
int v = Integer.parseInt(stringList.get(ExcelKit.transLetter2Num("F")).split("\\.")[0]);
|
|
|
|
|
if (colsCount == 9) {
|
|
|
|
|
v = (int) (v * 0.3);//乘以0.3
|
|
|
|
|
}
|
|
|
|
|
Row outRow = outSheet.createRow(++rowIndex);
|
|
|
|
|
ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year), "", "镇区", "", String.valueOf(v), areaName, cityName), dataStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修正乡村招生C 修正县城外招生-修正县城外招生*30%
|
|
|
|
|
for (List<String> stringList : dataList) {
|
|
|
|
|
//年份
|
|
|
|
|
int year = Integer.parseInt(stringList.getFirst());
|
|
|
|
|
//G:6修正乡村招生G
|
|
|
|
|
int v = Integer.parseInt(stringList.get(ExcelKit.transLetter2Num("G")).split("\\.")[0]);
|
|
|
|
|
if (colsCount == 9) {
|
|
|
|
|
v = Integer.parseInt(stringList.get(ExcelKit.transLetter2Num("F")).split("\\.")[0]);
|
|
|
|
|
int d = (int) (v * 0.3);//乘以0.3
|
|
|
|
|
v = v - d;//剩下70%
|
|
|
|
|
}
|
|
|
|
|
Row outRow = outSheet.createRow(++rowIndex);
|
|
|
|
|
ExcelKit.putData(outRow, Arrays.asList(String.valueOf(year), "", "乡村", "", String.valueOf(v), areaName, cityName), dataStyle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//保存文件
|
|
|
|
|
ExcelKit.saveExcel(excelPath, outWorkbook);
|
|
|
|
|
System.out.println("县区所有文件处理完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|