Browse Source

【data文件解析】表头字段兼容优化

zhouy 2 months ago
parent
commit
36b428e74b

+ 12 - 5
src/main/java/com/uas/eis/core/support/SaxDataBatchHandler.java

@@ -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)

+ 2 - 2
src/main/java/com/uas/eis/serviceImpl/FileParse2ServiceImpl.java

@@ -98,7 +98,7 @@ public class FileParse2ServiceImpl {
                     tableName,
                     DB_LINK,
                     dynamicCols,
-                    headerList.size(),
+                    headerList,
                     DATA_START_INDEX,
                     BATCH_ROW_SIZE,
                     sharedStrings
@@ -117,7 +117,7 @@ public class FileParse2ServiceImpl {
 
             logger.info("WaferId:{} 文件处理完成", waferId);
         } catch (Exception e) {
-            logger.error("芯片号:{} 解析异常", waferId, e);
+            logger.error("芯片号:{} 解析异常{}", waferId, e.getMessage());
             // 异常标记失败状态
             String errSql = String.format("UPDATE DATACENTER$MESFILE SET DEALSTATE_=-99 , DEALTIME_=SYSDATE WHERE DBID_=%s", dbId);
             baseDao.execute(errSql);