bugfix:微信医保数据入库

This commit is contained in:
Yuan
2025-11-17 17:28:01 +08:00
parent 739e6f5368
commit febe81ac00
9 changed files with 179 additions and 1018 deletions

View File

@@ -577,10 +577,10 @@ public class BankGetDataMethodByJHLZF {
BankbillHistory bankbillHistory = new BankbillHistory();
// 根据你提供的Excel列位置映射
// 终端号: CD列(索引2-3), 发卡行: EFGH列(索引4-7), 卡种: IJ列(索引8-9),
// 卡号: KLM列(索引10-12), 交易日期: N列(索引13), 交易时间: P列(索引15),
// 交易类型: QR列(索引16-17), 授权号: ST列(索引18-19), 交易金额: U列(索引20)⭐,
// 根据实际Excel列位置映射(从日志分析得出)
// 终端号: C列(索引2), 发卡行: E列(索引4), 卡种: I列(索引8),
// 卡号: K列(索引10), 交易日期: N列(索引13), 交易时间: O列(索引14)⭐,
// 交易类型: Q列(索引16), 授权号: S列(索引18), 交易金额: U列(索引20)⭐,
// 小费: VW列(索引21-22), 分期期数: X列(索引23), 银行手续费: Y列(索引24),
// DCC返还手续费: Z列(索引25), 划账金额: AA列(索引26), 凭证号: AB列(索引27),
// 批次号: AC列(索引28), POS交易序号: AD列(索引29)⭐, 结算账号: AE列(索引30),
@@ -589,7 +589,7 @@ public class BankGetDataMethodByJHLZF {
// 交易日期和时间
jyrq = s1.length > 13 ? s1[13] : "";
String jysj = s1.length > 15 ? s1[15] : "";
String jysj = s1.length > 14 ? s1[14] : ""; // 交易时间在第14列索引14
// 如果交易时间为空,尝试从交易日期中提取时间部分
if (jysj == null || jysj.trim().isEmpty()) {
@@ -1129,43 +1129,7 @@ public class BankGetDataMethodByJHLZF {
// 输出Excel的基本信息
log.info("Excel总行数: " + sheet.getLastRowNum());
// 输出第24行的表头信息真正的列标题
Row headerRow24 = sheet.getRow(23); // 第24行索引是23
if (headerRow24 != null) {
StringBuilder headerLine = new StringBuilder();
for (int col = 0; col < headerRow24.getLastCellNum(); col++) {
Cell cell = headerRow24.getCell(col);
if (cell != null) {
headerLine.append("[列").append(col).append("]=");
try {
headerLine.append(cell.toString());
} catch (Exception e) {
headerLine.append("ERROR");
}
headerLine.append(" | ");
}
}
log.info("第24行(真正的表头): " + headerLine.toString());
}
// 输出第25行的第一条数据示例
Row dataRow25 = sheet.getRow(24); // 第25行索引是24
if (dataRow25 != null) {
StringBuilder dataLine = new StringBuilder();
for (int col = 0; col < Math.min(20, dataRow25.getLastCellNum()); col++) {
Cell cell = dataRow25.getCell(col);
if (cell != null) {
dataLine.append("[列").append(col).append("]=");
try {
dataLine.append(cell.toString());
} catch (Exception e) {
dataLine.append("ERROR");
}
dataLine.append(" | ");
}
}
log.info("第25行(第1条数据): " + dataLine.toString());
}
// 遍历所有行
for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
@@ -1183,59 +1147,35 @@ public class BankGetDataMethodByJHLZF {
String cellValue = "";
if (cell != null) {
// 根据单元格类型获取值JDK 8兼容方式
int cellType = cell.getCellType();
if (cellType == Cell.CELL_TYPE_STRING) {
cellValue = cell.getStringCellValue();
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
// 检查是否为日期格式
if (DateUtil.isCellDateFormatted(cell)) {
try {
// 使用SimpleDateFormat格式化日期时间
java.util.Date dateValue = cell.getDateCellValue();
// 检查是否只有时间日期部分为1899-12-31或1900-01-01
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.setTime(dateValue);
int year = cal.get(java.util.Calendar.YEAR);
if (year == 1899 || year == 1900) {
// 只有时间,格式化为 HH:mm:ss
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm:ss");
cellValue = sdf.format(dateValue);
} else {
// 完整的日期时间,格式化为 yyyy-MM-dd HH:mm:ss
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cellValue = sdf.format(dateValue);
}
} catch (Exception e) {
cellValue = cell.getDateCellValue().toString();
}
} else {
// 数字格式,避免科学计数法
cellValue = String.valueOf(cell.getNumericCellValue());
// 如果是整数,去掉小数点
if (cellValue.endsWith(".0")) {
cellValue = cellValue.substring(0, cellValue.length() - 2);
}
// 直接使用 toString() 获取单元格显示的文本值,这样可以获取格式化后的值
// 例如时间 "00:22:49"、日期 "2025-10-23" 等都会按显示格式返回
try {
cellValue = cell.toString();
// 如果是空白,设置为空字符串
if (cellValue == null) {
cellValue = "";
}
} else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
cellValue = String.valueOf(cell.getBooleanCellValue());
} else if (cellType == Cell.CELL_TYPE_FORMULA) {
} catch (Exception e) {
// 如果 toString 失败,尝试根据类型获取
int cellType = cell.getCellType();
try {
cellValue = String.valueOf(cell.getNumericCellValue());
} catch (Exception e) {
try {
if (cellType == Cell.CELL_TYPE_STRING) {
cellValue = cell.getStringCellValue();
} catch (Exception e2) {
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
cellValue = String.valueOf(cell.getNumericCellValue());
if (cellValue.endsWith(".0")) {
cellValue = cellValue.substring(0, cellValue.length() - 2);
}
} else if (cellType == Cell.CELL_TYPE_BOOLEAN) {
cellValue = String.valueOf(cell.getBooleanCellValue());
} else if (cellType == Cell.CELL_TYPE_BLANK) {
cellValue = "";
} else {
cellValue = "";
}
} catch (Exception e2) {
cellValue = "";
}
} else if (cellType == Cell.CELL_TYPE_BLANK) {
cellValue = "";
} else {
cellValue = "";
}
}