|
|
@@ -24,6 +24,7 @@ public class SaxDataBatchHandler extends DefaultHandler {
|
|
|
private final int dataStartRow;
|
|
|
private final int batchRowLimit;
|
|
|
private final SharedStrings sharedStrings;
|
|
|
+ private final List<String> headerList;
|
|
|
|
|
|
// 复用缓冲区,减少GC创建临时对象
|
|
|
private final StringBuilder batchSqlBuffer = new StringBuilder(8192);
|
|
|
@@ -37,7 +38,7 @@ public class SaxDataBatchHandler extends DefaultHandler {
|
|
|
private String currentCellType;
|
|
|
|
|
|
public SaxDataBatchHandler(JdbcTemplate jdbcTemplate, String waferId, String tableName, String dbLinkSuffix, String dynamicItemColumns,
|
|
|
- int maxCellSize,
|
|
|
+ List<String> headerList,
|
|
|
int dataStartRow,
|
|
|
int batchRowLimit,
|
|
|
SharedStrings sharedStrings) {
|
|
|
@@ -46,7 +47,8 @@ public class SaxDataBatchHandler extends DefaultHandler {
|
|
|
this.tableName = tableName;
|
|
|
this.dbLinkSuffix = dbLinkSuffix;
|
|
|
this.dynamicItemColumns = dynamicItemColumns;
|
|
|
- this.maxCellSize = maxCellSize;
|
|
|
+ this.headerList = headerList;
|
|
|
+ this.maxCellSize = headerList.size();
|
|
|
this.dataStartRow = dataStartRow;
|
|
|
this.batchRowLimit = batchRowLimit;
|
|
|
this.sharedStrings = sharedStrings;
|
|
|
@@ -103,18 +105,23 @@ public class SaxDataBatchHandler extends DefaultHandler {
|
|
|
int dataType = detNo == 0 ? 0 : 1;
|
|
|
String firstCellVal = currentRowCells.size() > 0 ? currentRowCells.get(0) : "";
|
|
|
String flag = firstCellVal.startsWith("F") ? "1" : "0";
|
|
|
-
|
|
|
valueBuffer.setLength(0);
|
|
|
+
|
|
|
for (int m = 0; m < maxCellSize; m++) {
|
|
|
- String cellVal = m < currentRowCells.size() ? currentRowCells.get(m).trim() : "";
|
|
|
+ String cellVal = "";
|
|
|
// 转义单引号,防止SQL语法报错
|
|
|
+ //针对无抬头特殊处理取headerList(从第3列开始)
|
|
|
+ if(m > 1 && detNo ==0){
|
|
|
+ cellVal = headerList.get(m);
|
|
|
+ }else {
|
|
|
+ cellVal = m < currentRowCells.size() ? currentRowCells.get(m).trim() : "";
|
|
|
+ }
|
|
|
cellVal = cellVal.replace("'", "''");
|
|
|
valueBuffer.append("'").append(cellVal).append("'");
|
|
|
if (m != maxCellSize - 1) {
|
|
|
valueBuffer.append(",");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
batchSqlBuffer.append("INSERT INTO ")
|
|
|
.append(tableName)
|
|
|
.append(dbLinkSuffix)
|