【积分银行】积分

This commit is contained in:
2026-02-06 17:49:43 +08:00
parent 173eaa1b60
commit 80d1cebc0f
30 changed files with 1487 additions and 15 deletions
@@ -0,0 +1,124 @@
package org.jeecg.common.export;
import cn.hutool.core.collection.CollUtil;
import org.jeecg.enums.ExportExcelEnum;
import org.slf4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.core.task.AsyncTaskExecutor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
/**
* @author PengJ
* @description: 通用导出工具类
* @date 2025/11/18 15:05
*/
public class GenericExportHandler<T, F> implements PoiExportHandler<T, F> {
/**
* 源数据类型
*/
private final Class<T> exportClass;
/**
* 导出编码
*/
private final String code;
/**
* 导出标题
*/
private final String title;
/**
* 保存路径
*/
private final String bizPath;
/**
* 异步任务执行器
*/
private final AsyncTaskExecutor asyncTaskExecutor;
/**
* 日志
*/
private final Logger logger;
/**
* 数据提供者
*/
private final Function<F, List<T>> dataProvider;
public GenericExportHandler(Class<T> exportClass,
ExportExcelEnum excelEnum,
AsyncTaskExecutor asyncTaskExecutor,
Logger logger,
Function<F, List<T>> dataProvider) {
this.exportClass = exportClass;
this.code = excelEnum.getExpTaskCode();
this.title = excelEnum.getTitle();
this.bizPath = excelEnum.getBizPath();
this.asyncTaskExecutor = asyncTaskExecutor;
this.logger = logger;
this.dataProvider = dataProvider;
}
@Override
public Class<T> getExportClass() {
return exportClass;
}
@Override
public String getCode() {
return code;
}
@Override
public String getTitle() {
return title;
}
@Override
public AsyncTaskExecutor getAsyncTaskExecutor() {
return asyncTaskExecutor;
}
@Override
public List<T> getData(F filter) {
return dataProvider.apply(filter);
}
@Override
public Logger getLogger() {
return logger;
}
@Override
public String getBizPath() {
return bizPath;
}
/**
* 处理数据 - 将 VO 转换为 Excel 对象
*
* @param data 源数据列表
* @param targetClass 目标类(通常是Excel实体类)
* @param <E> 源数据类型
* @param <R> 目标数据类型
* @return 转换后的目标数据列表
*/
public static <E, R> List<R> handleData(List<E> data, Class<R> targetClass) {
if (CollUtil.isEmpty(data)) {
return Collections.emptyList();
}
List<R> list = new ArrayList<>();
data.forEach(f -> {
try {
R target = targetClass.newInstance();
BeanUtils.copyProperties(f, target);
list.add(target);
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Failed to copy properties", e);
}
});
return list;
}
}
@@ -0,0 +1,44 @@
package org.jeecg.enums;
import lombok.Getter;
/**
* @author PengJ
* @description: 导出/导出Excel枚举类
* @date 2025/11/18 16:24
*/
@Getter
public enum ExportExcelEnum {
/**
* 积分规则
*/
BANK_POINTS_RULE("bcsStationExportCode", "站点数据", "/bcs/station", null),
;
/**
* 导出任务code
*/
public final String expTaskCode;
/**
* 文件名称
*/
public final String title;
/**
* 文件路径
*/
public final String bizPath;
/**
* 导入任务code
*/
public final String impTaskCode;
ExportExcelEnum(String expTaskCode, String title, String bizPath, String impTaskCode) {
this.expTaskCode = expTaskCode;
this.title = title;
this.bizPath = bizPath;
this.impTaskCode = impTaskCode;
}
}