From 3c2c87364b89de46d12e95abd5bdf8cbd2c6dbf6 Mon Sep 17 00:00:00 2001 From: baoshiwei <baoshiwei@shlanbao.cn> Date: 星期三, 12 三月 2025 08:43:23 +0800 Subject: [PATCH] dev-init --- 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