Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
T
topology
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
姜立玮
topology
Commits
8a076e17
提交
8a076e17
authored
7月 20, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Excel导出导入支持dictType字典类型
上级
cee572f2
变更
3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
94 行增加
和
4 行删除
+94
-4
Excel.java
...mmon/src/main/java/com/ruoyi/common/annotation/Excel.java
+6
-1
DictUtils.java
...ommon/src/main/java/com/ruoyi/common/utils/DictUtils.java
+52
-1
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+36
-2
没有找到文件。
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
浏览文件 @
8a076e17
...
@@ -29,6 +29,11 @@ public @interface Excel
...
@@ -29,6 +29,11 @@ public @interface Excel
*/
*/
public
String
dateFormat
()
default
""
;
public
String
dateFormat
()
default
""
;
/**
* 如果是字典类型,请设置字典的type值
*/
public
String
dictType
()
default
""
;
/**
/**
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/
*/
...
@@ -115,4 +120,4 @@ public @interface Excel
...
@@ -115,4 +120,4 @@ public @interface Excel
return
this
.
value
;
return
this
.
value
;
}
}
}
}
}
}
\ No newline at end of file
ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java
浏览文件 @
8a076e17
...
@@ -2,7 +2,6 @@ package com.ruoyi.common.utils;
...
@@ -2,7 +2,6 @@ package com.ruoyi.common.utils;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.core.domain.entity.SysDictData
;
import
com.ruoyi.common.core.domain.entity.SysDictData
;
import
com.ruoyi.common.core.redis.RedisCache
;
import
com.ruoyi.common.core.redis.RedisCache
;
...
@@ -43,6 +42,58 @@ public class DictUtils
...
@@ -43,6 +42,58 @@ public class DictUtils
return
null
;
return
null
;
}
}
/**
* 根据字典类型和字典值获取字典标签
*
* @param dictType 字典类型
* @param dictValue 字典值
* @return 字典标签
*/
public
static
String
getDictLabel
(
String
dictType
,
String
dictValue
)
{
if
(
StringUtils
.
isNotEmpty
(
dictType
)
&&
StringUtils
.
isNotEmpty
(
dictValue
))
{
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNotEmpty
(
datas
))
{
for
(
SysDictData
dict
:
datas
)
{
if
(
dictValue
.
equals
(
dict
.
getDictValue
()))
{
return
dict
.
getDictLabel
();
}
}
}
}
return
dictValue
;
}
/**
* 根据字典类型和字典标签获取字典值
*
* @param dictType 字典类型
* @param dictLabel 字典标签
* @return 字典值
*/
public
static
String
getDictValue
(
String
dictType
,
String
dictLabel
)
{
if
(
StringUtils
.
isNotEmpty
(
dictType
)
&&
StringUtils
.
isNotEmpty
(
dictLabel
))
{
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNotEmpty
(
datas
))
{
for
(
SysDictData
dict
:
datas
)
{
if
(
dictLabel
.
equals
(
dict
.
getDictLabel
()))
{
return
dict
.
getDictValue
();
}
}
}
}
return
dictLabel
;
}
/**
/**
* 清空字典缓存
* 清空字典缓存
*/
*/
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
浏览文件 @
8a076e17
...
@@ -50,6 +50,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
...
@@ -50,6 +50,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
import
com.ruoyi.common.core.text.Convert
;
import
com.ruoyi.common.core.text.Convert
;
import
com.ruoyi.common.exception.CustomException
;
import
com.ruoyi.common.exception.CustomException
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.DictUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.reflect.ReflectUtils
;
import
com.ruoyi.common.utils.reflect.ReflectUtils
;
...
@@ -270,7 +271,11 @@ public class ExcelUtil<T>
...
@@ -270,7 +271,11 @@ public class ExcelUtil<T>
}
}
else
if
(
StringUtils
.
isNotEmpty
(
attr
.
readConverterExp
()))
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
);
ReflectUtils
.
invokeSetter
(
entity
,
propertyName
,
val
);
}
}
...
@@ -529,13 +534,18 @@ public class ExcelUtil<T>
...
@@ -529,13 +534,18 @@ public class ExcelUtil<T>
Object
value
=
getTargetValue
(
vo
,
field
,
attr
);
Object
value
=
getTargetValue
(
vo
,
field
,
attr
);
String
dateFormat
=
attr
.
dateFormat
();
String
dateFormat
=
attr
.
dateFormat
();
String
readConverterExp
=
attr
.
readConverterExp
();
String
readConverterExp
=
attr
.
readConverterExp
();
String
dictType
=
attr
.
dictType
();
if
(
StringUtils
.
isNotEmpty
(
dateFormat
)
&&
StringUtils
.
isNotNull
(
value
))
if
(
StringUtils
.
isNotEmpty
(
dateFormat
)
&&
StringUtils
.
isNotNull
(
value
))
{
{
cell
.
setCellValue
(
DateUtils
.
parseDateToStr
(
dateFormat
,
(
Date
)
value
));
cell
.
setCellValue
(
DateUtils
.
parseDateToStr
(
dateFormat
,
(
Date
)
value
));
}
}
else
if
(
StringUtils
.
isNotEmpty
(
readConverterExp
)
&&
StringUtils
.
isNotNull
(
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
else
{
{
...
@@ -666,6 +676,30 @@ public class ExcelUtil<T>
...
@@ -666,6 +676,30 @@ public class ExcelUtil<T>
return
propertyValue
;
return
propertyValue
;
}
}
/**
* 解析字典值
*
* @param dictType 字典类型
* @param dictValue 字典值
* @return 字典标签
*/
public
static
String
convertDictByExp
(
String
dictType
,
String
dictValue
)
throws
Exception
{
return
DictUtils
.
getDictLabel
(
dictType
,
dictValue
);
}
/**
* 反向解析值字典值
*
* @param dictType 字典类型
* @param dictValue 字典标签
* @return 字典值
*/
public
static
String
reverseDictByExp
(
String
dictType
,
String
dictLabel
)
throws
Exception
{
return
DictUtils
.
getDictValue
(
dictType
,
dictLabel
);
}
/**
/**
* 编码文件名
* 编码文件名
*/
*/
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论