| | |
| | | import com.alibaba.excel.metadata.CellData; |
| | | import com.alibaba.excel.metadata.GlobalConfiguration; |
| | | import com.alibaba.excel.metadata.property.ExcelContentProperty; |
| | | import com.github.xiaoymin.knife4j.core.util.StrUtil; |
| | | import org.springblade.common.cache.DictBizCache; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.modules.system.entity.DictBiz; |
| | | import org.springblade.modules.system.service.IDictBizService; |
| | |
| | | return CellDataTypeEnum.STRING; |
| | | } |
| | | |
| | | /** |
| | | * 导入excel 解析到java 对象 |
| | | * @param cellData |
| | | * @param excelContentProperty |
| | | * @param globalConfiguration |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { |
| | | return null; |
| | | // 获取字典类型 |
| | | Field field = excelContentProperty.getField(); |
| | | ExcelDictItemLabel excel = field.getAnnotation(ExcelDictItemLabel.class); |
| | | String dictType = excel.type(); |
| | | // 为空返回 |
| | | String dictLabel = cellData.getStringValue(); |
| | | if (StrUtil.isBlank(dictLabel)) { |
| | | return dictLabel; |
| | | } |
| | | // 查询字典 |
| | | List<DictBiz> list = DictBizCache.getList(dictType); |
| | | //解析返回 |
| | | String key = ""; |
| | | for (DictBiz dictBiz : list) { |
| | | if (dictBiz.getDictValue().equals(dictLabel)){ |
| | | key = dictBiz.getDictKey(); |
| | | break; |
| | | } |
| | | } |
| | | // 返回key |
| | | return key; |
| | | } |
| | | |
| | | /** |
| | |
| | | Field field = excelContentProperty.getField(); |
| | | ExcelDictItem excel = field.getAnnotation(ExcelDictItem.class); |
| | | String dictType = excel.type(); |
| | | IDictBizService dictBizService = SpringUtils.getBean(IDictBizService.class); |
| | | List<DictBiz> list = dictBizService.getList(dictType); |
| | | List<DictBiz> list = DictBizCache.getList(dictType); |
| | | String value = ""; |
| | | //解析返回 |
| | | for (DictBiz dictBiz : list) { |
| | | if (dictBiz.getDictKey().equals(dictValue)){ |
| | | value = dictBiz.getDictValue(); |
| | | break; |
| | | } |
| | | } |
| | | return new CellData(value); |