!65 refactor(bgpartymatter): 合并重复的导入导出接口,通过参数区分会议类型

* refactor(bgpartymatter): 合并重复的导入导出接口,通过参数区分会议类型
* feat(excel): 导入支持收集实体 ID 和注入默认值,新增 BgPartymatter 常量类
This commit is contained in:
wsm
2026-07-02 03:06:21 +00:00
parent e39f39eba9
commit bed7abdf2f
5 changed files with 353 additions and 214 deletions
@@ -177,6 +177,20 @@ public final class ExcelAnnotationUtils {
Consumer<List<T>> batchHandler, int batchSize,
Consumer<List<ValidationError>> errorHandler,
DictQuery dictQuery) {
return read(inputStream, clazz, batchHandler, batchSize, errorHandler, dictQuery, null);
}
/**
* 从 Excel 输入流分批导入数据,基于 @ExcelColumn 注解读取列配置。
*
* @param dictQuery 字典查询接口,可为 null(不启用字典翻译)
* @param idCollector 导入成功后的实体 ID 收集器,在每批 batchHandler 执行后调用(此时实体已被保存,ID 已回填),可为 null
*/
public static <T> int read(InputStream inputStream, Class<T> clazz,
Consumer<List<T>> batchHandler, int batchSize,
Consumer<List<ValidationError>> errorHandler,
DictQuery dictQuery,
Consumer<List<T>> idCollector) {
List<ColumnMeta> columns = parseColumns(clazz, dictQuery);
@@ -189,7 +203,7 @@ public final class ExcelAnnotationUtils {
}
ExcelImportListener<T> listener = new ExcelImportListener<>(
clazz, batchSize, nameToCol, displayToCode, batchHandler, errorHandler
clazz, batchSize, nameToCol, displayToCode, batchHandler, idCollector, errorHandler
);
EasyExcel.read(inputStream, listener).sheet().doRead();
@@ -21,6 +21,7 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
private final Class<T> clazz;
private final int batchSize;
private final Consumer<List<T>> batchHandler;
private final Consumer<List<T>> idCollector;
private final Consumer<List<ValidationError>> errorHandler;
// 外部传入的数据支撑
@@ -40,12 +41,14 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
public ExcelImportListener(Class<T> clazz, int batchSize,
Map<String, ColumnMeta> nameToCol, Map<String, String> displayToCode,
Consumer<List<T>> batchHandler, Consumer<List<ValidationError>> errorHandler) {
Consumer<List<T>> batchHandler, Consumer<List<T>> idCollector,
Consumer<List<ValidationError>> errorHandler) {
this.clazz = clazz;
this.batchSize = batchSize;
this.nameToCol = nameToCol;
this.displayToCode = displayToCode;
this.batchHandler = batchHandler;
this.idCollector = idCollector;
this.errorHandler = errorHandler;
this.batch = batchHandler != null ? new ArrayList<>(batchSize) : null;
this.errorBatch = new ArrayList<>(batchSize);
@@ -138,7 +141,11 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
if (batchHandler != null) {
batch.add(obj);
if (batch.size() >= batchSize) {
batchHandler.accept(new ArrayList<>(batch));
List<T> batchCopy = new ArrayList<>(batch);
batchHandler.accept(batchCopy);
if (idCollector != null) {
idCollector.accept(batchCopy);
}
batch.clear();
}
}
@@ -162,7 +169,11 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
if (batchHandler != null && batch != null && !batch.isEmpty()) {
batchHandler.accept(new ArrayList<>(batch));
List<T> batchCopy = new ArrayList<>(batch);
batchHandler.accept(batchCopy);
if (idCollector != null) {
idCollector.accept(batchCopy);
}
batch.clear();
}
if (!errorBatch.isEmpty()) {