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
bc7a6070
Commit
bc7a6070
authored
Jun 02, 2024
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel注解新增属性comboReadDict
parent
161cd2b1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
22 deletions
+83
-22
Excel.java
...mmon/src/main/java/com/ruoyi/common/annotation/Excel.java
+5
-0
DictUtils.java
...ommon/src/main/java/com/ruoyi/common/utils/DictUtils.java
+63
-18
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+15
-4
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
View file @
bc7a6070
...
...
@@ -88,6 +88,11 @@ public @interface Excel
*/
public
String
[]
combo
()
default
{};
/**
* 是否从字典读数据到combo,默认不读取,如读取需要设置dictType注解.
*/
public
boolean
comboReadDict
()
default
false
;
/**
* 是否需要纵向合并单元格,应对需求:含有list集合单元格)
*/
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/DictUtils.java
View file @
bc7a6070
...
...
@@ -91,9 +91,10 @@ public class DictUtils
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNotNull
(
datas
))
if
(
StringUtils
.
isNull
(
datas
))
{
return
StringUtils
.
EMPTY
;
}
if
(
StringUtils
.
containsAny
(
separator
,
dictValue
))
{
for
(
SysDictData
dict
:
datas
)
...
...
@@ -118,7 +119,6 @@ public class DictUtils
}
}
}
}
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
);
}
...
...
@@ -134,8 +134,11 @@ public class DictUtils
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
containsAny
(
separator
,
dictLabel
)
&&
StringUtils
.
isNotEmpty
(
datas
))
if
(
StringUtils
.
isNull
(
datas
))
{
return
StringUtils
.
EMPTY
;
}
if
(
StringUtils
.
containsAny
(
separator
,
dictLabel
))
{
for
(
SysDictData
dict
:
datas
)
{
...
...
@@ -162,6 +165,48 @@ public class DictUtils
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
);
}
/**
* 根据字典类型获取字典所有值
*
* @param dictType 字典类型
* @return 字典值
*/
public
static
String
getDictValues
(
String
dictType
)
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNull
(
datas
))
{
return
StringUtils
.
EMPTY
;
}
for
(
SysDictData
dict
:
datas
)
{
propertyString
.
append
(
dict
.
getDictValue
()).
append
(
SEPARATOR
);
}
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
SEPARATOR
);
}
/**
* 根据字典类型获取字典所有标签
*
* @param dictType 字典类型
* @return 字典值
*/
public
static
String
getDictLabels
(
String
dictType
)
{
StringBuilder
propertyString
=
new
StringBuilder
();
List
<
SysDictData
>
datas
=
getDictCache
(
dictType
);
if
(
StringUtils
.
isNull
(
datas
))
{
return
StringUtils
.
EMPTY
;
}
for
(
SysDictData
dict
:
datas
)
{
propertyString
.
append
(
dict
.
getDictLabel
()).
append
(
SEPARATOR
);
}
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
SEPARATOR
);
}
/**
* 删除指定字典缓存
*
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
View file @
bc7a6070
...
...
@@ -1042,17 +1042,28 @@ public class ExcelUtil<T>
// 设置列宽
sheet
.
setColumnWidth
(
column
,
(
int
)
((
attr
.
width
()
+
0.72
)
*
256
));
}
if
(
StringUtils
.
isNotEmpty
(
attr
.
prompt
())
||
attr
.
combo
().
length
>
0
)
if
(
StringUtils
.
isNotEmpty
(
attr
.
prompt
())
||
attr
.
combo
().
length
>
0
||
attr
.
comboReadDict
()
)
{
if
(
attr
.
combo
().
length
>
15
||
StringUtils
.
join
(
attr
.
combo
()).
length
()
>
255
)
String
[]
comboArray
=
attr
.
combo
();
if
(
attr
.
comboReadDict
())
{
if
(!
sysDictMap
.
containsKey
(
"combo_"
+
attr
.
dictType
()))
{
String
labels
=
DictUtils
.
getDictLabels
(
attr
.
dictType
());
sysDictMap
.
put
(
"combo_"
+
attr
.
dictType
(),
labels
);
}
String
val
=
sysDictMap
.
get
(
"combo_"
+
attr
.
dictType
());
comboArray
=
StringUtils
.
split
(
val
,
DictUtils
.
SEPARATOR
);
}
if
(
comboArray
.
length
>
15
||
StringUtils
.
join
(
comboArray
).
length
()
>
255
)
{
// 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到
setXSSFValidationWithHidden
(
sheet
,
attr
.
combo
()
,
attr
.
prompt
(),
1
,
100
,
column
,
column
);
setXSSFValidationWithHidden
(
sheet
,
comboArray
,
attr
.
prompt
(),
1
,
100
,
column
,
column
);
}
else
{
// 提示信息或只能选择不能输入的列内容.
setPromptOrValidation
(
sheet
,
attr
.
combo
()
,
attr
.
prompt
(),
1
,
100
,
column
,
column
);
setPromptOrValidation
(
sheet
,
comboArray
,
attr
.
prompt
(),
1
,
100
,
column
,
column
);
}
}
}
...
...
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