Commit 55af1e94 by zhangxingmin

push

parent 7d8ec826
......@@ -40,7 +40,7 @@ spring:
# 配置中心
config:
# 命名空间id(此处不用public,因public初始化的空间, id为空)
namespace: b3b01715-eb85-4242-992a-5aff03d864d4
namespace: 8fbea9a4-b626-46de-a4e6-9d23f6609318
# nacos的ip地址和端口
server-addr: 139.224.145.34:8848
# 这个就表示 在我们nacos命名空间id为 dev中 有一个data-id 为 demo-service.yml 的配置文件 读取这个里面的配置
......
......@@ -7,6 +7,7 @@ public enum TemplateTypeEnum {
//文件模板类型类型枚举
XCD("保险行程单","XCD"),
YYD("预约信息导出模板","YYD"),
;
//字典项标签(名称)
private String itemLabel;
......
......@@ -102,6 +102,8 @@
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.69.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.69.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.69.Final" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:9.0.60" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-annotations-api:9.0.60" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.13.2" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.yd.oss.service.service.impl;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.alibaba.fastjson.JSON;
import com.yd.oss.feign.result.ImportResult;
import com.yd.oss.feign.result.ValidationResult;
import com.yd.oss.service.service.ExcelImportService;
......@@ -49,6 +50,7 @@ public class ExcelImportServiceImpl implements ExcelImportService {
ExcelImportResult<Map<String, Object>> importResult =
importExcel(file, headerRowNum, dataStartRowNum);
System.out.println(JSON.toJSONString(importResult.getList()));
// 3. 处理导入结果
List<Map<String, Object>> data =
processImportResult(importResult, headers);
......@@ -165,9 +167,9 @@ public class ExcelImportServiceImpl implements ExcelImportService {
return "";
}
}
/**
* 处理导入结果,转换为更友好的数据结构
* 处理导入结果,转换为更友好的数据结构,并过滤空行
* @param result 导入结果
* @param headers 表头信息
* @return 处理后的数据
......@@ -175,24 +177,63 @@ public class ExcelImportServiceImpl implements ExcelImportService {
public static List<Map<String, Object>> processImportResult(
ExcelImportResult<Map<String, Object>> result,
List<String> headers) {
List<Map<String, Object>> processedData = new ArrayList<>();
if (result != null && result.getList() != null) {
for (Map<String, Object> rowData : result.getList()) {
// 检查是否为空行
if (isEmptyRow(rowData, headers)) {
continue; // 跳过空行
}
Map<String, Object> processedRow = new LinkedHashMap<>();
// 按照表头顺序重新组织数据
for (String header : headers) {
processedRow.put(header, rowData.get(header));
}
processedData.add(processedRow);
}
}
return processedData;
}
/**
* 判断一行数据是否为空行
* @param rowData 行数据
* @param headers 表头列表
* @return true-空行, false-非空行
*/
private static boolean isEmptyRow(Map<String, Object> rowData, List<String> headers) {
if (rowData == null || rowData.isEmpty()) {
return true;
}
// 检查所有业务字段是否都为空(排除excelRowNum等系统字段)
for (String header : headers) {
Object value = rowData.get(header);
if (value != null && !value.toString().trim().isEmpty()) {
return false; // 发现非空值,不是空行
}
}
// 额外检查:如果只有系统字段有值,也算空行
boolean hasOnlySystemFields = true;
for (String key : rowData.keySet()) {
if (!key.equals("excelRowNum") && !key.startsWith("_")) {
Object value = rowData.get(key);
if (value != null && !value.toString().trim().isEmpty()) {
hasOnlySystemFields = false;
break;
}
}
}
return hasOnlySystemFields;
}
/**
* 验证导入数据
......
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