From a71e2e4777b412aef735b7c3d547a502b6990ad9 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期四, 23 七月 2020 10:52:59 +0800
Subject: [PATCH] 验证码类型支持(数组计算、字符验证)
---
src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java | 38 ++++++++++++++++++++++++++++++++++++--
1 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
index 623c886..b64e93e 100644
--- a/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+++ b/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -44,6 +44,7 @@
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.reflect.ReflectUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
@@ -270,7 +271,11 @@
}
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
{
- val = reverseByExp(String.valueOf(val), attr.readConverterExp());
+ val = reverseByExp(Convert.toStr(val), attr.readConverterExp());
+ }
+ else if (StringUtils.isNotEmpty(attr.dictType()))
+ {
+ val = reverseDictByExp(attr.dictType(), Convert.toStr(val));
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
@@ -529,13 +534,18 @@
Object value = getTargetValue(vo, field, attr);
String dateFormat = attr.dateFormat();
String readConverterExp = attr.readConverterExp();
+ String dictType = attr.dictType();
if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
{
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
}
else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
{
- cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp));
+ cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp));
+ }
+ else if (StringUtils.isNotEmpty(dictType))
+ {
+ cell.setCellValue(convertDictByExp(dictType, Convert.toStr(value)));
}
else
{
@@ -667,6 +677,30 @@
}
/**
+ * 瑙f瀽瀛楀吀鍊�
+ *
+ * @param dictType 瀛楀吀绫诲瀷
+ * @param dictValue 瀛楀吀鍊�
+ * @return 瀛楀吀鏍囩
+ */
+ public static String convertDictByExp(String dictType, String dictValue) throws Exception
+ {
+ return DictUtils.getDictLabel(dictType, dictValue);
+ }
+
+ /**
+ * 鍙嶅悜瑙f瀽鍊煎瓧鍏稿��
+ *
+ * @param dictType 瀛楀吀绫诲瀷
+ * @param dictValue 瀛楀吀鏍囩
+ * @return 瀛楀吀鍊�
+ */
+ public static String reverseDictByExp(String dictType, String dictLabel) throws Exception
+ {
+ return DictUtils.getDictValue(dictType, dictLabel);
+ }
+
+ /**
* 缂栫爜鏂囦欢鍚�
*/
public String encodingFilename(String filename)
--
Gitblit v1.9.3