feat(excel): 添加Excel导入表头别名支持功能
- 新增ExcelHeaderAlias注解用于定义表头别名 - 在CreditExternalImportParam中为认缴出资额字段添加别名映射 - 扩展ExcelImportSupport类支持运行时表头别名解析 - 实现别名到标准表头名称的规范化映射逻辑 - 保持导出模板表头不变的情况下支持多种导入表头格式
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import com.gxwebsoft.credit.excel.ExcelHeaderAlias;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
@@ -353,6 +354,20 @@ public class ExcelImportSupport {
|
||||
// key -> canonical annotation name
|
||||
map.putIfAbsent(key, name);
|
||||
}
|
||||
|
||||
// Allow import-time header aliases without changing the exported template header.
|
||||
ExcelHeaderAlias alias = field.getAnnotation(ExcelHeaderAlias.class);
|
||||
if (alias != null && alias.value() != null) {
|
||||
for (String aliasName : alias.value()) {
|
||||
if (aliasName == null || aliasName.trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
String aliasKey = normalizeHeaderKey(aliasName);
|
||||
if (!aliasKey.isEmpty()) {
|
||||
map.putIfAbsent(aliasKey, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
current = current.getSuperclass();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.gxwebsoft.credit.excel;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Excel 导入表头别名。
|
||||
*
|
||||
* <p>EasyPOI 的 {@code @Excel(name=...)} 仅支持一个表头名;当上游模板存在多种表头写法时,
|
||||
* 可用此注解声明别名,让 {@link com.gxwebsoft.credit.controller.ExcelImportSupport} 在导入前把别名规范化为 canonical 表头。</p>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface ExcelHeaderAlias {
|
||||
|
||||
/**
|
||||
* 允许匹配的表头别名列表(任意一个匹配即视为该列)。
|
||||
*/
|
||||
String[] value();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gxwebsoft.credit.param;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import com.gxwebsoft.credit.excel.ExcelHeaderAlias;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -31,6 +32,7 @@ public class CreditExternalImportParam implements Serializable {
|
||||
private String shareholdingRatio;
|
||||
|
||||
@Excel(name = "认缴出资额")
|
||||
@ExcelHeaderAlias({"认缴出资额/持股数"})
|
||||
private String subscribedInvestmentAmount;
|
||||
|
||||
@Excel(name = "认缴出资日期")
|
||||
|
||||
Reference in New Issue
Block a user