mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-11-12 04:03:44 +08:00
update 优化 !781Excel 模版动态数据下拉 泛型逻辑
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.dromara.common.excel.annotation;
|
||||
|
||||
import org.dromara.common.excel.core.ExcelOptionsProvider;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
@@ -14,7 +16,8 @@ public @interface ExcelDynamicOptions {
|
||||
|
||||
/**
|
||||
* 提供者类全限定名
|
||||
* 实现org.dromara.common.excel.service.ExcelOptionsProvider实现类接口
|
||||
* <p>
|
||||
* {@link org.dromara.common.excel.core.ExcelOptionsProvider} 接口实现类 class
|
||||
*/
|
||||
Class<?> providerClass();
|
||||
Class<? extends ExcelOptionsProvider> providerClass();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.annotation.ExcelDynamicOptions;
|
||||
import org.dromara.common.excel.annotation.ExcelEnumFormat;
|
||||
import org.dromara.common.excel.service.ExcelOptionsProvider;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
@@ -122,15 +121,12 @@ public class ExcelDownHandler implements SheetWriteHandler {
|
||||
} else if (field.isAnnotationPresent(ExcelDynamicOptions.class)) {
|
||||
// 处理动态下拉选项
|
||||
ExcelDynamicOptions dynamicOptions = field.getDeclaredAnnotation(ExcelDynamicOptions.class);
|
||||
Class<?> providerClass = dynamicOptions.providerClass();
|
||||
if (providerClass == null) {
|
||||
throw new ServiceException("使用ExcelDynamicOptions注解,必须给providerClass赋予ExcelOptionsProvider的实现类" +
|
||||
",字段:{}", field.getName());
|
||||
}
|
||||
// 获取提供者实例
|
||||
ExcelOptionsProvider provider = (ExcelOptionsProvider) SpringUtils.getBean(providerClass);
|
||||
Set<String> optionSets = provider.getOptions();
|
||||
options = new ArrayList<>(CollUtil.isNotEmpty(optionSets) ? new ArrayList<>(optionSets) : Collections.emptyList());
|
||||
ExcelOptionsProvider provider = SpringUtils.getBean(dynamicOptions.providerClass());
|
||||
Set<String> providerOptions = provider.getOptions();
|
||||
if (CollUtil.isNotEmpty(providerOptions)) {
|
||||
options = new ArrayList<>(providerOptions);
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(options)) {
|
||||
// 仅当下拉可选项不为空时执行
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.dromara.common.excel.service;
|
||||
package org.dromara.common.excel.core;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -15,4 +15,5 @@ public interface ExcelOptionsProvider {
|
||||
* @return 下拉选项列表
|
||||
*/
|
||||
Set<String> getOptions();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user