From 25836328835ca4f017658ab546b654a5e5b92c09 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 25 四月 2024 12:50:42 +0800 Subject: [PATCH] update springboot 3.2.4 => 3.2.5 update mybatis-plus 3.5.5 => 3.5.6 适配更改代码 update springdoc 2.4.0 => 2.5.0 update easyexcel 3.3.3 => 3.3.4 update redisson 3.27.2 => 3.29.0 update lombok 1.18.30 => 1.18.32 update sms4j 3.2.0 => 3.2.1 --- ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/convert/ExcelEnumConvert.java | 22 +++++++++++++++++----- 1 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/convert/ExcelEnumConvert.java b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/convert/ExcelEnumConvert.java index 3b52695..b948ea7 100644 --- a/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/convert/ExcelEnumConvert.java +++ b/ruoyi-common/ruoyi-common-excel/src/main/java/org/dromara/common/excel/convert/ExcelEnumConvert.java @@ -37,14 +37,26 @@ @Override public Object convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { - Object codeValue = cellData.getData(); + cellData.checkEmpty(); + // Excel涓~鍏ョ殑鏄灇涓句腑鎸囧畾鐨勬弿杩� + Object textValue = switch (cellData.getType()) { + case STRING, DIRECT_STRING, RICH_TEXT_STRING -> cellData.getStringValue(); + case NUMBER -> cellData.getNumberValue(); + case BOOLEAN -> cellData.getBooleanValue(); + default -> throw new IllegalArgumentException("鍗曞厓鏍肩被鍨嬪紓甯�!"); + }; // 濡傛灉鏄┖鍊� - if (ObjectUtil.isNull(codeValue)) { + if (ObjectUtil.isNull(textValue)) { return null; } - Map<Object, String> enumValueMap = beforeConvert(contentProperty); - String textValue = enumValueMap.get(codeValue); - return Convert.convert(contentProperty.getField().getType(), textValue); + Map<Object, String> enumCodeToTextMap = beforeConvert(contentProperty); + // 浠嶫ava杈撳嚭鑷矱xcel鏄痗ode杞瑃ext + // 鍥犳浠嶦xcel杞琂ava搴旇灏唗ext涓巆ode瀵硅皟 + Map<Object, Object> enumTextToCodeMap = new HashMap<>(); + enumCodeToTextMap.forEach((key, value) -> enumTextToCodeMap.put(value, key)); + // 搴旇浠巘ext -> code涓煡鎵� + Object codeValue = enumTextToCodeMap.get(textValue); + return Convert.convert(contentProperty.getField().getType(), codeValue); } @Override -- Gitblit v1.9.3