update:建行龙支付账单获取动态提取第一行数据

This commit is contained in:
Elliott
2025-12-29 15:21:09 +08:00
parent 4c416ed691
commit e87fdce9f9
2 changed files with 41 additions and 19 deletions

View File

@@ -1,7 +1,6 @@
package com.saye.hospitalgd.scheduler.jobMethod;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.saye.hospitalgd.commons.date.DateDUtil;
import com.saye.hospitalgd.commons.getBean.GetBeanUtil;
import com.saye.hospitalgd.commons.log.LogUtil;
@@ -24,14 +23,13 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.util.CollectionUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.*;
import java.net.URI;
import java.nio.charset.Charset;
@@ -512,25 +510,53 @@ public class BankGetDataMethodByJHLZF {
log.info("继续执行程序3");
List<BankbillHistory> bankbillHistoryList = new ArrayList<>();
// 跳过前24行Excel的前24行是标题和说明第24行是表头从第25行开始是数据
for (int i = 24; i < txtList.size(); i++) {
int startIndex = -1;
for (int i = 0; i < txtList.size(); i++) {
String line = txtList.get(i);
if (line == null || line.trim().isEmpty()) {
continue;
}
String[] cols = line.split("\t");
if (cols.length < 10) {
continue;
}
dateStr = cols.length > 13 ? cols[13].trim() : "";
if (dateStr == null || dateStr.isEmpty() || !dateStr.contains("-")) {
continue;
}
String firstAmountStr = cols.length > 20 ? cols[20].trim() : "";
if (firstAmountStr.isEmpty() || firstAmountStr.equals("null") || firstAmountStr.equals("0") || firstAmountStr.equals("0.00")) {
continue;
}
try {
String d = txtList.get(i);
double firstAmount = Double.parseDouble(firstAmountStr);
if (Math.abs(firstAmount) < 0.01) {
continue;
}
} catch (NumberFormatException e) {
continue;
}
startIndex = i;
break;
}
if (startIndex == -1) {
startIndex = 24;
}
for (int i = startIndex; i < txtList.size(); i++) {
try {
String d = txtList.get(i);
// 跳过空行
if (d == null || d.trim().isEmpty()) {
continue;
}
String[] s1 = d.split("\t");
String[] s1 = d.split("\t");
// 跳过列数不足的行至少需要10列才能有交易金额
if (s1.length < 10) {
log.debug("" + (i + 1) + " 行列数不足,跳过");
continue;
}
continue;
}
// 检查是否是汇总行(包含"小计"、"合计"、"终端小计"等关键字)
String rowText = d.toLowerCase();
if (rowText.contains("小计") || rowText.contains("合计") ||
rowText.contains("终端小计") || rowText.contains("pos编号") ||
@@ -540,7 +566,6 @@ public class BankGetDataMethodByJHLZF {
continue;
}
// 检查第13列交易日期Excel的N列是否为空
if (s1.length <= 13 || s1[13] == null || s1[13].trim().isEmpty()) {
log.debug("" + (i + 1) + " 行交易日期为空,跳过");
continue;
@@ -548,20 +573,17 @@ public class BankGetDataMethodByJHLZF {
String jyrq = s1[13].trim();
// 检查第13列是否包含日期简单检查是否包含"-"
if (!jyrq.contains("-")) {
log.debug("" + (i + 1) + " 行交易日期不包含日期分隔符,跳过");
continue;
}
// 检查交易金额列第20列对应Excel的U列是否有效
String amountStr = s1.length > 20 ? s1[20].trim() : "";
if (amountStr.isEmpty() || amountStr.equals("null") || amountStr.equals("0") || amountStr.equals("0.00")) {
log.debug("" + (i + 1) + " 行交易金额无效: [" + amountStr + "],跳过");
continue;
}
// 尝试解析金额,确保是有效数字
try {
double amount = Double.parseDouble(amountStr);
if (Math.abs(amount) < 0.01) {
@@ -575,7 +597,7 @@ public class BankGetDataMethodByJHLZF {
log.info("正在处理第 " + (i + 1) + " 行数据");
BankbillHistory bankbillHistory = new BankbillHistory();
BankbillHistory bankbillHistory = new BankbillHistory();
// 根据实际Excel列位置映射从日志分析得出
// 终端号: C列(索引2), 发卡行: E列(索引4), 卡种: I列(索引8),