Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
sts网站
Commits
8a076e17
Commit
8a076e17
authored
Jul 20, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel导出导入支持dictType字典类型
parent
cee572f2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
4 deletions
+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
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
View file @
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
View file @
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
View file @
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
);
}
/**
/**
* 编码文件名
* 编码文件名
*/
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment