All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kangaroohy.plugin.excel.domain.ExcelSelectorResolver Maven / Gradle / Ivy

There is a newer version: 3.1.3
Show newest version
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 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 serviceClass) { ExcelSelectorService excelSelectorService = applicationContext.getBean(serviceClass); if (!StringUtils.hasText(excelSelector.dictKeyValue())) { setSelectorData(excelSelectorService.getSelectorData()); } else { setSelectorData(excelSelectorService.getSelectorData(excelSelector.dictKeyValue())); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy