init
parent
8698ce1568
commit
dcef8041b2
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>mountain-flood-importer</artifactId>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Excel处理 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>5.2.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 数据库连接 -->
|
||||
<dependency>
|
||||
<groupId>com.dameng</groupId>
|
||||
<artifactId>DmJdbcDriver18</artifactId>
|
||||
<version>8.1.1.193</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 日志 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.36</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.36</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
// MountainFloodDataImporter.java
|
||||
package org.example;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -16,7 +15,7 @@ public class GetWscdDataImporter {
|
|||
}
|
||||
|
||||
// 测试用的固定路径
|
||||
args = new String[]{"I:\\6666-华科26个流域1023-已统一表头-待入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -161,7 +160,7 @@ public class GetWscdDataImporter {
|
|||
for (File subDir : subDirs) {
|
||||
String dirName = subDir.getName();
|
||||
// 包含"水系"或者以HBWFF开头的文件夹都认为是水系文件夹
|
||||
if (dirName.contains("水系") || dirName.startsWith("HBWF")) {
|
||||
if (dirName.contains("水系") || dirName.startsWith("HBW")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class IaEftsTownImporter {
|
|||
// args = new String[]{"F:\\1111-湖工大50条成果-已通过初检-待入库"};
|
||||
// args = new String[]{"F:\\3333-2024年度咸宁市8条20251017-已通过初检-待入库"};
|
||||
// args = new String[]{"F:\\2222-华科-黄石局-14条小流域(10.20)-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"F:\\小流域\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
|
||||
if (args.length == 0) {
|
||||
|
|
@ -248,7 +248,7 @@ public class IaEftsTownImporter {
|
|||
Row row = sheet.getRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
Cell serialCell = row.getCell(0);
|
||||
Cell serialCell = row.getCell(1);
|
||||
if (serialCell == null || isCellEmpty(serialCell)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -542,7 +542,7 @@ public class IaEftsTownImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWFF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class IaGlaInfoDataImporter {
|
|||
// args = new String[]{"F:\\3333-2024年度咸宁市8条20251017-已通过初检-待入库"};
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
// args = new String[]{"F:\\小流域\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\7777-华科-咸宁市8条1027-已通过初检-已统一表头-已入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -128,7 +128,7 @@ public class IaGlaInfoDataImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class IaHdpPointDataImporter {
|
|||
// args = new String[]{"F:\\2222-华科-黄石局-14条小流域(10.20)-已通过初检-已统一表头-已入库"};
|
||||
// args = new String[]{"F:\\3333-华科-地大9条-20251021-已通过初检-已统一表头-已入库"};
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\8888-长科院-孝昌县8条1028-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -134,7 +134,7 @@ public class IaHdpPointDataImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ public class IaHdpPointDataImporter {
|
|||
// 查找Excel文件
|
||||
File excelFile = findExcelFile(reportDir);
|
||||
if (excelFile == null) {
|
||||
System.out.println("在 " + reportDir.getPath() + " 下未找到" + six);
|
||||
System.out.println("在 " + reportDir.getPath() + " 下未找到" + seven);
|
||||
return 0;
|
||||
}
|
||||
System.out.println("找到Excel文件: " + excelFile.getPath());
|
||||
|
|
@ -200,11 +200,11 @@ public class IaHdpPointDataImporter {
|
|||
|
||||
private static File findExcelFile(File reportDir) {
|
||||
File[] files = reportDir.listFiles((dir, name) ->
|
||||
name.equals(six) || name.toLowerCase().endsWith(".xlsx"));
|
||||
name.equals(seven) || name.toLowerCase().endsWith(".xlsx"));
|
||||
|
||||
if (files != null && files.length > 0) {
|
||||
for (File file : files) {
|
||||
if (file.getName().equals(six)) {
|
||||
if (file.getName().equals(seven)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
|
@ -270,7 +270,7 @@ public class IaHdpPointDataImporter {
|
|||
continue;
|
||||
}
|
||||
|
||||
Object[] rowData = parseRowData(row,countyName, watershedCode);
|
||||
Object[] rowData = parseRowData1(row,countyName, watershedCode);
|
||||
if (rowData != null) {
|
||||
dataList.add(rowData);
|
||||
System.out.println("✓ 解析第 " + (i + 1) + " 行数据成功");
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class IaRbadInfoDataImporter {
|
|||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
// args = new String[]{"F:\\3333-华科-地大9条-20251021-已通过初检-已统一表头-待入库"};
|
||||
// args = new String[]{"F:\\小流域\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\8888-长科院-孝昌县8条1028-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -129,7 +129,7 @@ public class IaRbadInfoDataImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class IaShzhHdpDataImporter {
|
|||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
// args = new String[]{"F:\\3333-华科-地大9条-20251021-已通过初检-已统一表头-待入库"};
|
||||
// args = new String[]{"F:\\小流域\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库\\5555-长江科学院20条10.23-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\8888-长科院-孝昌县8条1028-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -540,7 +540,7 @@ public class IaShzhHdpDataImporter {
|
|||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
// 包含"水系"或者是类似HBWF开头的文件夹都认为是水系文件夹
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class IaShzhHsurfaceDataImporter {
|
|||
// args = new String[]{"C:\\Users\\gsiot\\Desktop\\项目资料\\山洪\\小流域\\222"};
|
||||
// args = new String[]{"F:\\1111-湖工大50条成果-已通过初检-待入库"};--湖工大
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\7777-华科-咸宁市8条1027-已通过初检-已统一表头-已入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -794,7 +794,7 @@ public class IaShzhHsurfaceDataImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class IaShzhHsurfaceDataImporter2 {
|
|||
// args = new String[]{"C:\\Users\\gsiot\\Desktop\\项目资料\\山洪\\小流域\\222"};
|
||||
// args = new String[]{"F:\\1111-湖工大50条成果-已通过初检-待入库"};--湖工大
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\7777-华科-咸宁市8条1027-已通过初检-已统一表头-已入库"};
|
||||
args = new String[]{"I:\\11.11长科院待定-已通过初检-空间格式通过-已统一表头-待入库\\长江科学院2024湖北提交数据-11.10"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -807,7 +807,7 @@ public class IaShzhHsurfaceDataImporter2 {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWFF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class IaShzhVsurfaceDataImporter {
|
|||
// args = new String[]{"F:\\3333-2024年度咸宁市8条20251017-已通过初检-待入库"};
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
|
||||
args = new String[]{"I:\\7777-华科-咸宁市8条1027-已通过初检-已统一表头-已入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
return;
|
||||
|
|
@ -738,7 +738,7 @@ public class IaShzhVsurfaceDataImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class IaShzhVsurfaceDataImporter2 {
|
|||
// args = new String[]{"F:\\3333-2024年度咸宁市8条20251017-已通过初检-待入库"};
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
|
||||
args = new String[]{"C:\\Users\\gsiot\\Desktop\\项目资料\\山洪\\小流域\\111"};
|
||||
args = new String[]{"I:\\11.11长科院待定-已通过初检-空间格式通过-已统一表头-待入库\\长江科学院2024湖北提交数据-11.10"};
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
return;
|
||||
|
|
@ -756,7 +756,7 @@ public class IaShzhVsurfaceDataImporter2 {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWFF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class IaStHdpDataImporter {
|
|||
// 测试用的固定路径
|
||||
// args = new String[]{"F:\\1111-湖工大50条成果-已通过初检-待入库"};
|
||||
// args = new String[]{"F:\\4444-长江科学院-黄冈28条-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"I:\\8888-长科院-孝昌县8条1028-已通过初检-已统一表头-待入库"};
|
||||
args = new String[]{"D:\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库\\1111-湖工大-已通过初检-空间格式通过-已统一表头-重新入库"};
|
||||
|
||||
if (args.length == 0) {
|
||||
System.out.println("请提供湖工大9.29目录路径作为参数");
|
||||
|
|
@ -486,7 +486,7 @@ public class IaStHdpDataImporter {
|
|||
if (subDirs != null) {
|
||||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ public class MountainFloodDataImporter {
|
|||
List<File> sxDirs = new ArrayList<>();
|
||||
for (File subDir : subDirs) {
|
||||
// 包含"水系"或者是类似HBWFF开头的文件夹都认为是水系文件夹
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBWFF.*")) {
|
||||
if (subDir.getName().contains("水系") || subDir.getName().matches("^HBW.*")) {
|
||||
sxDirs.add(subDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@ public class WatershedDataCleaner {
|
|||
result.table4Count = deleteFromTable4(conn, watershedCodes);
|
||||
result.table5_7Count = deleteFromTable5_7(conn, watershedCodes);
|
||||
result.table8Count = deleteFromTable8(conn, watershedCodes);
|
||||
result.hsPointCount = deleteFromHSPoint(conn, watershedCodes);
|
||||
// result.hsPointCount = deleteFromHSPoint(conn, watershedCodes);
|
||||
result.hSurfaceCount = deleteFromHSurface(conn, watershedCodes);
|
||||
result.vsPointCount = deleteFromVSPoint(conn, watershedCodes);
|
||||
// result.vsPointCount = deleteFromVSPoint(conn, watershedCodes);
|
||||
result.vSurfaceCount = deleteFromVSurface(conn, watershedCodes);
|
||||
|
||||
// 提交事务
|
||||
|
|
@ -136,10 +136,10 @@ public class WatershedDataCleaner {
|
|||
/**
|
||||
* 横断面点 - IA_M_HSPOINT
|
||||
*/
|
||||
private static int deleteFromHSPoint(Connection conn, List<String> watershedCodes) throws SQLException {
|
||||
String sql = "DELETE FROM \"SHZH_JCSJ\".\"IA_M_HSPOINT\" WHERE \"HSURFACEID\" IN (SELECT GUID FROM \"SHZH_JCSJ\".\"IA_M_HSURFACE\" WHERE \"WSCD\" = ?)";
|
||||
return executeBatchDelete(conn, sql, watershedCodes, "IA_M_HSPOINT");
|
||||
}
|
||||
// private static int deleteFromHSPoint(Connection conn, List<String> watershedCodes) throws SQLException {
|
||||
// String sql = "DELETE FROM \"SHZH_JCSJ\".\"IA_M_HSPOINT\" WHERE \"HSURFACEID\" IN (SELECT GUID FROM \"SHZH_JCSJ\".\"IA_M_HSURFACE\" WHERE \"WSCD\" = ?)";
|
||||
// return executeBatchDelete(conn, sql, watershedCodes, "IA_M_HSPOINT");
|
||||
// }
|
||||
|
||||
/**
|
||||
* 纵断面 - IA_M_VSURFACE
|
||||
|
|
@ -152,10 +152,10 @@ public class WatershedDataCleaner {
|
|||
/**
|
||||
* 纵断面点 - IA_M_VSPOINT
|
||||
*/
|
||||
private static int deleteFromVSPoint(Connection conn, List<String> watershedCodes) throws SQLException {
|
||||
String sql = "DELETE FROM \"SHZH_JCSJ\".\"IA_M_VSPOINT\" WHERE WHERE \"ZSURFACEID\" IN (SELECT GUID FROM \"SHZH_JCSJ\".\"IA_M_VSURFACE\" WHERE \"WSCD\" = ?)";
|
||||
return executeBatchDelete(conn, sql, watershedCodes, "IA_M_VSPOINT");
|
||||
}
|
||||
// private static int deleteFromVSPoint(Connection conn, List<String> watershedCodes) throws SQLException {
|
||||
// String sql = "DELETE FROM \"SHZH_JCSJ\".\"IA_M_VSPOINT\" WHERE WHERE \"ZSURFACEID\" IN (SELECT GUID FROM \"SHZH_JCSJ\".\"IA_M_VSURFACE\" WHERE \"WSCD\" = ?)";
|
||||
// return executeBatchDelete(conn, sql, watershedCodes, "IA_M_VSPOINT");
|
||||
// }
|
||||
|
||||
/**
|
||||
* 执行批量删除操作
|
||||
|
|
@ -273,20 +273,56 @@ public class WatershedDataCleaner {
|
|||
public static void main(String[] args) {
|
||||
// 测试数据
|
||||
List<String> testWatershedCodes = Arrays.asList(
|
||||
"HBWFA8900124H00000",
|
||||
"HBWFA8900125M00000",
|
||||
"HBWFA8900126F00000",
|
||||
"HBWFA8900127000000",
|
||||
"HBWFAA200123o00000",
|
||||
"HBWFAA200125cE0000",
|
||||
"HBWFAA200127c00000",
|
||||
"HBWFAA200127m00000",
|
||||
"HBWFAA200127t00000",
|
||||
"HBWFAA20012g000000",
|
||||
"HBWFAA2103N0000000",
|
||||
"HBWFAA2106F0000000",
|
||||
"HBWFAA210G00000000",
|
||||
"HBWFADJ00125000000"
|
||||
"HBWFF1400123GD0000000",
|
||||
"HBWFF1400125D00000000",
|
||||
"HBWFF1400126000000000",
|
||||
"HBWFF14302PC000000000",
|
||||
"HBWFF14303G0000000000",
|
||||
"HBWFA861031kA00000000",
|
||||
"HBWFA8610l10000000000",
|
||||
"HBWFA86206f0000000000",
|
||||
"HBWFA8300114M00000000",
|
||||
"HBWFA830011GP00000000",
|
||||
"HBWFABV3011I000000000",
|
||||
"HBWFA85001211FC000000",
|
||||
"HBWFA85001231lB000000",
|
||||
"HBWFA85001241LC000000",
|
||||
"HBWFA85001251IC000000",
|
||||
"HBWFA85001261JC000000",
|
||||
"HBWFA85001281dBH00000",
|
||||
"HBWFA8580500000000000",
|
||||
"HBWFA8580C00000000000",
|
||||
"HBWFA85001241hBE00000",
|
||||
"HBWFA850012A1hB000000",
|
||||
"HBWFA850012B1kB000000",
|
||||
"HBWFA85405G0000000000",
|
||||
"HBWFA8540800000000000",
|
||||
"HBWFA7800126000000000",
|
||||
"HBWFA7800127000000000",
|
||||
"HBWFA85001221IA000001",
|
||||
"HBWFA85001241GA000000",
|
||||
"HBWFA850012C100000000",
|
||||
"HBWFE22001261G0000000",
|
||||
"HBWFE2200128100000000",
|
||||
"HBWFE2400121000000000",
|
||||
"HBWFE240012P000000000",
|
||||
"HBWFA85001231SB000001",
|
||||
"HBWFA85202D0000000000",
|
||||
"HBWFA85206E0000000000",
|
||||
"HBWFA8520B00000000000",
|
||||
"HBWFAHV00125000000000",
|
||||
"HBWFA03002016T0000000",
|
||||
"HBWFA03002018Z0000000",
|
||||
"HBWFA8200115P00000000",
|
||||
"HBWFA820011C000000000",
|
||||
"HBWFA85001261RB000000",
|
||||
"HBWFA850012A1dB000000",
|
||||
"HBWFA85001241lA000000",
|
||||
"HBWFF12A0153I00000000",
|
||||
"HBWFF12A0155NE0000000",
|
||||
"HBWFF12A0156L00000000",
|
||||
"HBWFF12A0156N00000000",
|
||||
"HBWFF12A0157M00000000"
|
||||
);
|
||||
|
||||
System.out.println("开始测试删除操作...");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,191 @@
|
|||
package org.example;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
public class WscdUpdater {
|
||||
|
||||
// 数据库配置
|
||||
private static final String DB_URL = "jdbc:dm://10.42.6.248:5236/SHZH_JCSJ";
|
||||
private static final String DB_USER = "SHZH";
|
||||
private static final String DB_PASSWORD = "Shzh_890";
|
||||
|
||||
// 需要更新的表名列表
|
||||
private static final String[] TARGET_TABLES = {
|
||||
"SHZH_JCSJ.IA_RV_INFO"// 替换为实际的表名
|
||||
};
|
||||
|
||||
public static void main(String[] args) {
|
||||
String excelFilePath = "D:\\333.xlsx";
|
||||
|
||||
try {
|
||||
// 1. 读取Excel文件
|
||||
Map<String, String> wscdMapping = readExcelFile(excelFilePath);
|
||||
|
||||
// 2. 连接数据库并更新数据
|
||||
updateDatabase(wscdMapping);
|
||||
|
||||
System.out.println("更新完成!");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Excel文件,构建编码映射关系
|
||||
*/
|
||||
private static Map<String, String> readExcelFile(String filePath) throws IOException {
|
||||
Map<String, String> mapping = new HashMap<>();
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(filePath);
|
||||
Workbook workbook = new XSSFWorkbook(fis)) {
|
||||
|
||||
Sheet sheet = workbook.getSheetAt(0); // 第一个sheet
|
||||
|
||||
// 跳过表头,从第二行开始读取
|
||||
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
||||
Row row = sheet.getRow(i);
|
||||
if (row == null) continue;
|
||||
|
||||
// 获取系统小流域编码(A列)
|
||||
Cell oldCodeCell = row.getCell(0);
|
||||
// 获取新编码(B列)
|
||||
Cell newCodeCell = row.getCell(1);
|
||||
|
||||
if (oldCodeCell != null && newCodeCell != null) {
|
||||
String oldCode = getCellValue(oldCodeCell);
|
||||
String newCode = getCellValue(newCodeCell);
|
||||
|
||||
// 只有当新编码不为空时才添加到映射中
|
||||
if (oldCode != null && !oldCode.trim().isEmpty() &&
|
||||
newCode != null && !newCode.trim().isEmpty()) {
|
||||
mapping.put(oldCode.trim(), newCode.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("成功读取 " + mapping.size() + " 条编码映射关系");
|
||||
return mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单元格的值
|
||||
*/
|
||||
private static String getCellValue(Cell cell) {
|
||||
if (cell == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
return cell.getStringCellValue();
|
||||
case NUMERIC:
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
return cell.getDateCellValue().toString();
|
||||
} else {
|
||||
// 防止科学计数法,转为字符串
|
||||
return String.valueOf((long) cell.getNumericCellValue());
|
||||
}
|
||||
case BOOLEAN:
|
||||
return String.valueOf(cell.getBooleanCellValue());
|
||||
case FORMULA:
|
||||
return cell.getCellFormula();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新数据库
|
||||
*/
|
||||
private static void updateDatabase(Map<String, String> wscdMapping) {
|
||||
Connection conn = null;
|
||||
PreparedStatement pstmt = null;
|
||||
|
||||
try {
|
||||
// 加载DM数据库驱动
|
||||
Class.forName("dm.jdbc.driver.DmDriver");
|
||||
|
||||
// 建立数据库连接
|
||||
conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD);
|
||||
conn.setAutoCommit(false); // 开启事务
|
||||
|
||||
int totalUpdates = 0;
|
||||
|
||||
// 遍历所有目标表进行更新
|
||||
for (String tableName : TARGET_TABLES) {
|
||||
int tableUpdates = updateTable(conn, tableName, wscdMapping);
|
||||
totalUpdates += tableUpdates;
|
||||
System.out.println("表 " + tableName + " 更新了 " + tableUpdates + " 条记录");
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
conn.commit();
|
||||
System.out.println("总共更新了 " + totalUpdates + " 条记录");
|
||||
|
||||
} catch (Exception e) {
|
||||
// 回滚事务
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.rollback();
|
||||
} catch (SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
try {
|
||||
if (pstmt != null) pstmt.close();
|
||||
if (conn != null) conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单个表
|
||||
*/
|
||||
private static int updateTable(Connection conn, String tableName, Map<String, String> wscdMapping) throws SQLException {
|
||||
String sql = "UPDATE " + tableName + " SET WSCD = ? WHERE WSCD = ?";
|
||||
PreparedStatement pstmt = null;
|
||||
int updateCount = 0;
|
||||
|
||||
try {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
|
||||
// 遍历映射关系,执行更新
|
||||
for (Map.Entry<String, String> entry : wscdMapping.entrySet()) {
|
||||
String oldCode = entry.getKey();
|
||||
String newCode = entry.getValue();
|
||||
|
||||
pstmt.setString(1, newCode);
|
||||
pstmt.setString(2, oldCode);
|
||||
pstmt.addBatch();
|
||||
}
|
||||
|
||||
// 执行批量更新
|
||||
int[] results = pstmt.executeBatch();
|
||||
for (int result : results) {
|
||||
if (result >= 0) { // 成功更新的记录数
|
||||
updateCount += result;
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
}
|
||||
|
||||
return updateCount;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue