From b0909dbe3ddd7fb06180704c241b4cebabff6665 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期三, 28 六月 2023 14:27:13 +0800 Subject: [PATCH] !379 合并 客户端授权功能 --- 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