com.kangaroohy.plugin.excel.domain.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.domain;
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.context.ApplicationContext;
import org.springframework.util.StringUtils;
import java.util.Map;
/**
* 类 ExcelSelectorResolver 功能描述:
*
* @author hy
* @version 0.0.1
* @date 2023/9/7 16:25
*/
@Data
@Slf4j
public class ExcelSelectorResolver {
/**
* 下拉选起始行
*/
private int startRow;
/**
* 下拉选结束行
*/
private int endRow;
/**
* 下拉数据集
*/
private String[] selectorData;
/**
* 解决Excel注解的下拉选数据获取
*
* @param excelSelector Excel下拉选
*/
public ExcelSelectorResolver(ExcelSelector excelSelector, ApplicationContext applicationContext) {
setSelectorData(new String[0]);
if (excelSelector != null) {
setStartRow(excelSelector.firstRow());
setEndRow(excelSelector.lastRow());
String[] fixedSelector = excelSelector.value();
if (fixedSelector.length > 0) {
setSelectorData(fixedSelector);
}
Class extends ExcelSelectorService> serviceClass = excelSelector.serviceClass();
if (serviceClass.isInterface()) {
Map contextBeansOfType = applicationContext.getBeansOfType(serviceClass);
if (contextBeansOfType.keySet().size() == 1) {
getDataByBean(excelSelector, applicationContext, serviceClass);
}
} else {
getDataByBean(excelSelector, applicationContext, serviceClass);
}
}
}
private void getDataByBean(ExcelSelector excelSelector, ApplicationContext applicationContext, Class extends ExcelSelectorService> serviceClass) {
ExcelSelectorService excelSelectorService = applicationContext.getBean(serviceClass);
if (!StringUtils.hasText(excelSelector.dictKeyValue())) {
setSelectorData(excelSelectorService.getSelectorData());
} else {
setSelectorData(excelSelectorService.getSelectorData(excelSelector.dictKeyValue()));
}
}
}