Commit c02f3a24 by zhangxingmin

oss-v1版本

parent 0223c57a
...@@ -56,15 +56,6 @@ public class ExcelImportServiceImpl implements ExcelImportService { ...@@ -56,15 +56,6 @@ public class ExcelImportServiceImpl implements ExcelImportService {
ExcelImportResult<Map<String, Object>> importResult = ExcelImportResult<Map<String, Object>> importResult =
importExcel(file, headerRowNum, dataStartRowNum); importExcel(file, headerRowNum, dataStartRowNum);
log.info("EasyPOI导入结果:总行数={}, 成功行数={}, 失败行数={}",
importResult.getList() != null ? importResult.getList().size() : 0,
importResult.getList() != null ? "N/A" : "N/A",
importResult.isVerifyFail());
if (importResult.getList() != null) {
System.out.println("原始数据:" + JSON.toJSONString(importResult.getList()));
}
// 3. 处理导入结果 // 3. 处理导入结果
List<Map<String, Object>> data = List<Map<String, Object>> data =
processImportResult(importResult, headers); processImportResult(importResult, headers);
...@@ -235,37 +226,48 @@ public class ExcelImportServiceImpl implements ExcelImportService { ...@@ -235,37 +226,48 @@ public class ExcelImportServiceImpl implements ExcelImportService {
} }
/** /**
* 判断一行数据是否为空行 * 判断一行数据是否为空行(更严格的条件)
* @param rowData 行数据
* @param headers 表头列表
* @return true-空行, false-非空行
*/ */
private static boolean isEmptyRow(Map<String, Object> rowData, List<String> headers) { private static boolean isEmptyRow(Map<String, Object> rowData, List<String> headers) {
if (rowData == null || rowData.isEmpty()) { if (rowData == null || rowData.isEmpty()) {
return true; return true;
} }
// 检查所有业务字段是否都为空(排除excelRowNum等系统字段) // 方法1:检查所有业务字段是否都为空
for (String header : headers) { for (String header : headers) {
Object value = rowData.get(header); Object value = rowData.get(header);
if (value != null && !value.toString().trim().isEmpty()) { if (value != null) {
return false; // 发现非空值,不是空行 String strValue = value.toString().trim();
// 排除常见的空值表示
if (!strValue.isEmpty() &&
!strValue.equals("-") &&
!strValue.equals("null") &&
!strValue.equals("NULL")) {
return false;
}
} }
} }
// 额外检查:如果只有系统字段有值,也算空行 // 方法2:检查所有键值对(包括系统字段)
boolean hasOnlySystemFields = true; int validCount = 0;
for (String key : rowData.keySet()) { for (Map.Entry<String, Object> entry : rowData.entrySet()) {
if (!key.equals("excelRowNum") && !key.startsWith("_")) { String key = entry.getKey();
Object value = rowData.get(key); Object value = entry.getValue();
if (value != null && !value.toString().trim().isEmpty()) {
hasOnlySystemFields = false; // 跳过系统字段
break; if (key.equals("excelRowNum") || key.startsWith("_")) {
continue;
}
if (value != null) {
String strValue = value.toString().trim();
if (!strValue.isEmpty()) {
validCount++;
} }
} }
} }
return hasOnlySystemFields; return validCount == 0;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment