Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
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
yaru
fgqyxxlr
Commits
a3bb6033
Commit
a3bb6033
authored
Jun 23, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel支持dictType读取字符串组内容
parent
9ad3cc0b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
25 deletions
+84
-25
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+12
-10
ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java
+72
-15
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
View file @
a3bb6033
...
...
@@ -281,7 +281,7 @@ public class ExcelUtil<T>
}
else
if
(
StringUtils
.
isNotEmpty
(
attr
.
dictType
()))
{
val
=
reverseDictByExp
(
attr
.
dictType
(),
Convert
.
toStr
(
val
));
val
=
reverseDictByExp
(
Convert
.
toStr
(
val
),
attr
.
dictType
(),
attr
.
separator
(
));
}
ReflectUtils
.
invokeSetter
(
entity
,
propertyName
,
val
);
}
...
...
@@ -552,7 +552,7 @@ public class ExcelUtil<T>
}
else
if
(
StringUtils
.
isNotEmpty
(
dictType
))
{
cell
.
setCellValue
(
convertDictByExp
(
dictType
,
Convert
.
toStr
(
value
)
));
cell
.
setCellValue
(
convertDictByExp
(
Convert
.
toStr
(
value
),
dictType
,
separator
));
}
else
{
...
...
@@ -711,31 +711,33 @@ public class ExcelUtil<T>
/**
* 解析字典值
*
* @param dictType 字典类型
* @param dictValue 字典值
* @param dictType 字典类型
* @param separator 分隔符
* @return 字典标签
*/
public
static
String
convertDictByExp
(
String
dict
Type
,
String
dictValue
)
throws
Exception
public
static
String
convertDictByExp
(
String
dict
Value
,
String
dictType
,
String
separator
)
throws
Exception
{
Object
bean
=
SpringUtils
.
getBean
(
"dictUtils"
);
String
methodName
=
"getDictLabel"
;
Method
method
=
bean
.
getClass
().
getDeclaredMethod
(
methodName
,
String
.
class
,
String
.
class
);
return
Convert
.
toStr
(
method
.
invoke
(
bean
,
dictType
,
dictValue
));
Method
method
=
bean
.
getClass
().
getDeclaredMethod
(
methodName
,
String
.
class
,
String
.
class
,
String
.
class
);
return
Convert
.
toStr
(
method
.
invoke
(
bean
,
dictType
,
dictValue
,
separator
));
}
/**
* 反向解析值字典值
*
* @param dictLabel 字典标签
* @param dictType 字典类型
* @param
dictValue 字典标签
* @param
separator 分隔符
* @return 字典值
*/
public
static
String
reverseDictByExp
(
String
dict
Type
,
String
dictLabel
)
throws
Exception
public
static
String
reverseDictByExp
(
String
dict
Label
,
String
dictType
,
String
separator
)
throws
Exception
{
Object
bean
=
SpringUtils
.
getBean
(
"dictUtils"
);
String
methodName
=
"getDictValue"
;
Method
method
=
bean
.
getClass
().
getDeclaredMethod
(
methodName
,
String
.
class
,
String
.
class
);
return
Convert
.
toStr
(
method
.
invoke
(
bean
,
dictType
,
dictLabel
));
Method
method
=
bean
.
getClass
().
getDeclaredMethod
(
methodName
,
String
.
class
,
String
.
class
,
String
.
class
);
return
Convert
.
toStr
(
method
.
invoke
(
bean
,
dictType
,
dictLabel
,
separator
));
}
/**
...
...
ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java
View file @
a3bb6033
...
...
@@ -16,6 +16,11 @@ import com.ruoyi.system.domain.SysDictData;
public
class
DictUtils
{
/**
* 分隔符
*/
public
static
final
String
SEPARATOR
=
","
;
/**
* 设置字典缓存
*
* @param key 参数键
...
...
@@ -52,21 +57,59 @@ public class DictUtils
*/
public
static
String
getDictLabel
(
String
dictType
,
String
dictValue
)
{
if
(
StringUtils
.
isNotEmpty
(
dictType
)
&&
StringUtils
.
isNotEmpty
(
dictValue
))
return
getDictLabel
(
dictType
,
dictValue
,
SEPARATOR
);
}
/**
* 根据字典类型和字典标签获取字典值
*
* @param dictType 字典类型
* @param dictLabel 字典标签
* @return 字典值
*/
public
static
String
getDictValue
(
String
dictType
,
String
dictLabel
)
{
return
getDictValue
(
dictType
,
dictLabel
,
SEPARATOR
);
}
/**
* 根据字典类型和字典值获取字典标签
*
* @param dictType 字典类型
* @param dictValue 字典值
* @param separator 分隔符
* @return 字典标签
*/
public
static
String
getDictLabel
(
String
dictType
,
String
dictValue
,
String
separator
)
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
containsAny
(
separator
,
dictValue
)
&&
StringUtils
.
isNotEmpty
(
datas
))
{
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNotEmpty
(
datas
))
for
(
SysDictData
dict
:
datas
)
{
for
(
S
ysDictData
dict
:
datas
)
for
(
S
tring
value
:
dictValue
.
split
(
separator
)
)
{
if
(
dictV
alue
.
equals
(
dict
.
getDictValue
()))
if
(
v
alue
.
equals
(
dict
.
getDictValue
()))
{
return
dict
.
getDictLabel
();
propertyString
.
append
(
dict
.
getDictLabel
()
+
separator
);
break
;
}
}
}
}
return
dictValue
;
else
{
for
(
SysDictData
dict
:
datas
)
{
if
(
dictValue
.
equals
(
dict
.
getDictValue
()))
{
return
dict
.
getDictLabel
();
}
}
}
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
);
}
/**
...
...
@@ -74,25 +117,39 @@ public class DictUtils
*
* @param dictType 字典类型
* @param dictLabel 字典标签
* @param separator 分隔符
* @return 字典值
*/
public
static
String
getDictValue
(
String
dictType
,
String
dictLabel
)
public
static
String
getDictValue
(
String
dictType
,
String
dictLabel
,
String
separator
)
{
if
(
StringUtils
.
isNotEmpty
(
dictType
)
&&
StringUtils
.
isNotEmpty
(
dictLabel
))
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
containsAny
(
separator
,
dictLabel
)
&&
StringUtils
.
isNotEmpty
(
datas
))
{
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNotEmpty
(
datas
))
for
(
SysDictData
dict
:
datas
)
{
for
(
S
ysDictData
dict
:
datas
)
for
(
S
tring
label
:
dictLabel
.
split
(
separator
)
)
{
if
(
dictL
abel
.
equals
(
dict
.
getDictLabel
()))
if
(
l
abel
.
equals
(
dict
.
getDictLabel
()))
{
return
dict
.
getDictValue
();
propertyString
.
append
(
dict
.
getDictValue
()
+
separator
);
break
;
}
}
}
}
return
dictLabel
;
else
{
for
(
SysDictData
dict
:
datas
)
{
if
(
dictLabel
.
equals
(
dict
.
getDictLabel
()))
{
return
dict
.
getDictValue
();
}
}
}
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
);
}
/**
...
...
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