com.kangaroohy.plugin.excel.vo.ExcelSelectorResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of excel-spring-boot-starter Show documentation
Show all versions of excel-spring-boot-starter Show documentation
easy and high performance excel
package com.kangaroohy.plugin.excel.vo;
import com.kangaroohy.plugin.excel.annotation.ExcelSelector;
import com.kangaroohy.plugin.excel.service.ExcelSelectorService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
/**
* 类 ExcelSelectorResolve 功能描述:
*
* @author hy
* @version 0.0.1
* @date 2023/8/21 21:57
*/
@Data
@Slf4j
public class ExcelSelectorResolver {
/**
* 下拉选起始行
*/
private int startRow = 0;
/**
* 下拉选结束行
*/
private int endRow = 500;
/**
* 下拉数据集
*/
private String[] selectorData;
/**
* 解决Excel注解的下拉选数据获取
*
* @param excelSelector Excel下拉选
* @return java.lang.String[]
* @date 2022/9/20 16:58
*/
public String[] resolveExcelSelector(ExcelSelector excelSelector) {
if (excelSelector == null) {
return new String[0];
}
String[] fixedSelector = excelSelector.value();
if (fixedSelector.length > 0) {
return fixedSelector;
}
String[] selectorData = null;
Class extends ExcelSelectorService>[] serviceClass = excelSelector.serviceClass();
if (serviceClass.length > 0) {
ExcelSelectorService excelSelectorService = BeanUtils.instantiateClass(serviceClass[0]);
if (!StringUtils.hasText(excelSelector.dictKeyValue())) {
selectorData = excelSelectorService.getSelectorData();
} else {
selectorData = excelSelectorService.getSelectorData(excelSelector.dictKeyValue());
}
}
return selectorData;
}
}