|
|
|
@ -3,22 +3,31 @@ package com.dsideal.base.Tools.FillData.Area;
|
|
|
|
|
import com.alibaba.dashscope.exception.InputRequiredException;
|
|
|
|
|
import com.alibaba.dashscope.exception.NoApiKeyException;
|
|
|
|
|
import com.dsideal.base.DataEase.Model.DataEaseModel;
|
|
|
|
|
import com.dsideal.base.Tools.FillData.DataEaseKit.DsKit;
|
|
|
|
|
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
|
import org.jsoup.nodes.Document;
|
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
|
import org.jsoup.select.Elements;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class A14 {
|
|
|
|
|
//示例Excel
|
|
|
|
|
static String sampleExcelPath = "D:\\dsWork\\YunNanDsBase\\Doc\\待处理\\区\\【14】基本县情\\2023年基本县情【成果】.xlsx";
|
|
|
|
|
|
|
|
|
|
public static String getHTML(String url) throws IOException {
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
@ -70,13 +79,55 @@ public class A14 {
|
|
|
|
|
//初始化数据库连接
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
DataEaseModel dm = new DataEaseModel();
|
|
|
|
|
List<Record> list = dm.getProvinceArea("云南省");
|
|
|
|
|
for (Record record : list) {
|
|
|
|
|
String areaName = record.getStr("full_name");
|
|
|
|
|
String cityName = record.getStr("city_name");
|
|
|
|
|
List<String> res = getXq(areaName);
|
|
|
|
|
System.out.println(cityName + "\t" + areaName + "\t" + res);
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileInputStream inputStream = null;
|
|
|
|
|
FileOutputStream outputStream = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
inputStream = new FileInputStream(sampleExcelPath);
|
|
|
|
|
Workbook workbook = new XSSFWorkbook(inputStream); // 打开工作簿
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
|
|
|
|
|
|
|
|
|
|
// 读取数据
|
|
|
|
|
int idx = 0;
|
|
|
|
|
for (Row row : sheet) {
|
|
|
|
|
idx++;
|
|
|
|
|
if (idx == 1) continue;
|
|
|
|
|
String cityName = DsKit.readCell(row.getCell(0)).replace(" ", "");
|
|
|
|
|
String areaName = DsKit.readCell(row.getCell(1)).replace(" ", "");
|
|
|
|
|
if (!StrKit.isBlank(areaName)) {
|
|
|
|
|
System.out.println("正在查询县区:" + cityName + "\t" + areaName);
|
|
|
|
|
List<String> list = getXq(areaName);
|
|
|
|
|
Thread.sleep(1400);
|
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
|
Cell cell2 = row.getCell(2);
|
|
|
|
|
if (cell2 == null) cell2 = row.createCell(2);
|
|
|
|
|
cell2.setCellValue(list.getFirst());
|
|
|
|
|
}
|
|
|
|
|
if (list.size() > 1) {
|
|
|
|
|
Cell cell3 = row.getCell(3);
|
|
|
|
|
if (cell3 == null) cell3 = row.createCell(3);
|
|
|
|
|
cell3.setCellValue(list.get(1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
outputStream = new FileOutputStream(sampleExcelPath);
|
|
|
|
|
workbook.write(outputStream); // 将修改后的工作簿写入文件
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (inputStream != null) {
|
|
|
|
|
inputStream.close();
|
|
|
|
|
}
|
|
|
|
|
if (outputStream != null) {
|
|
|
|
|
outputStream.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("县区所有文件处理完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|