Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zh-baseversion-project
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
王浩
zh-baseversion-project
Commits
c5d8d798
Commit
c5d8d798
authored
May 31, 2024
by
军师中郎将
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1 燃气企业 -导入 - 企业类型 可以按照 配置的 字典类型 来下拉选取,选取后 导入也可以 按照最新的 字典类型存储并回显
parent
a8671429
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
3 deletions
+111
-3
Excel.java
...mon/src/main/java/com/zehong/common/annotation/Excel.java
+2
-0
DictUtils.java
...mmon/src/main/java/com/zehong/common/utils/DictUtils.java
+56
-0
ExcelUtil.java
.../src/main/java/com/zehong/common/utils/poi/ExcelUtil.java
+49
-2
TEnterpriseInfo.java
...c/main/java/com/zehong/system/domain/TEnterpriseInfo.java
+4
-1
No files found.
zh-baseversion-common/src/main/java/com/zehong/common/annotation/Excel.java
View file @
c5d8d798
...
...
@@ -110,6 +110,8 @@ public @interface Excel
*/
Align
align
()
default
Align
.
AUTO
;
public
enum
Align
{
AUTO
(
0
),
LEFT
(
1
),
CENTER
(
2
),
RIGHT
(
3
);
...
...
zh-baseversion-common/src/main/java/com/zehong/common/utils/DictUtils.java
View file @
c5d8d798
...
...
@@ -180,4 +180,60 @@ public class DictUtils
{
return
Constants
.
SYS_DICT_KEY
+
configKey
;
}
/**
* 根据指定的type ,value 获取 label
* @param value
* @param type
* @param defaultLabel 默认label
* @return
*/
public
static
String
getDictLabelByTypeAndValue
(
String
value
,
String
type
,
String
defaultLabel
){
if
(
StringUtils
.
isNotBlank
(
type
)
&&
StringUtils
.
isNotBlank
(
value
)){
for
(
SysDictData
dict
:
getDictCache
(
type
)){
if
(
type
.
equals
(
dict
.
getDictType
())
&&
value
.
equals
(
dict
.
getDictValue
())){
return
dict
.
getDictLabel
();
}
}
}
return
defaultLabel
;
}
/**
* 根据type,label 获取value
*
* @param label
* @param type
* @param defaultValue
* @return
*/
public
static
String
getDictValueByTypeAndLabel
(
String
label
,
String
type
,
String
defaultValue
)
{
if
(
StringUtils
.
isNotBlank
(
type
)
&&
StringUtils
.
isNotBlank
(
label
))
{
for
(
SysDictData
dict
:
getDictCache
(
type
))
{
if
(
type
.
equals
(
dict
.
getDictType
())
&&
label
.
equals
(
dict
.
getDictLabel
()))
{
return
dict
.
getDictValue
();
}
}
}
return
defaultValue
;
}
/**
* 根据 type 将 lable组成 string数组
* @param type
* @return
*/
public
static
String
[]
getLabelArr
(
String
type
)
{
String
[]
arr0
=
new
String
[
0
];
if
(
StringUtils
.
isNotBlank
(
type
))
{
List
<
SysDictData
>
dictList
=
getDictCache
(
type
);
String
[]
strArr
=
new
String
[
dictList
.
size
()];
for
(
int
i
=
0
;
i
<
dictList
.
size
()
;
i
++)
{
strArr
[
i
]
=
dictList
.
get
(
i
).
getDictLabel
();
}
return
strArr
;
}
return
arr0
;
}
}
zh-baseversion-common/src/main/java/com/zehong/common/utils/poi/ExcelUtil.java
View file @
c5d8d798
...
...
@@ -313,7 +313,8 @@ public class ExcelUtil<T>
}
else
if
(
StringUtils
.
isNotEmpty
(
attr
.
dictType
()))
{
val
=
reverseDictByExp
(
Convert
.
toStr
(
val
),
attr
.
dictType
(),
attr
.
separator
());
// val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
val
=
getDictValueByTypeAndLabel
(
String
.
valueOf
(
val
),
attr
.
dictType
());
}
ReflectUtils
.
invokeSetter
(
entity
,
propertyName
,
val
);
}
...
...
@@ -615,6 +616,16 @@ public class ExcelUtil<T>
// 这里默认设了2-101列只能选择不能输入.
setXSSFValidation
(
sheet
,
attr
.
combo
(),
1
,
100
,
column
,
column
);
}
//有字典 则取字典下拉
if
(
StringUtils
.
isNotEmpty
(
attr
.
dictType
()))
{
setXSSFValidation
(
sheet
,
DictUtils
.
getLabelArr
(
attr
.
dictType
()),
1
,
100
,
column
,
column
);
}
else
if
(
attr
.
combo
().
length
>
0
)
// 如果设置了combo属性则本列只能选择不能输入
{
// 这里默认设了2-101列只能选择不能输入.
setXSSFValidation
(
sheet
,
attr
.
combo
(),
1
,
100
,
column
,
column
);
}
}
/**
...
...
@@ -651,7 +662,8 @@ public class ExcelUtil<T>
}
else
if
(
StringUtils
.
isNotEmpty
(
dictType
)
&&
StringUtils
.
isNotNull
(
value
))
{
cell
.
setCellValue
(
convertDictByExp
(
Convert
.
toStr
(
value
),
dictType
,
separator
));
// cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
cell
.
setCellValue
(
getDictLabelByTypeAndValue
(
String
.
valueOf
(
value
),
dictType
));
}
else
if
(
value
instanceof
BigDecimal
&&
-
1
!=
attr
.
scale
())
{
...
...
@@ -1097,4 +1109,39 @@ public class ExcelUtil<T>
}
return
val
;
}
/* *
* 根据指定的type ,value 获取 label
* @param value
* @param dictType
* @return
* @throws Exception*/
public
static
String
getDictLabelByTypeAndValue
(
String
value
,
String
dictType
)
throws
Exception
{
String
label
=
value
;
try
{
label
=
DictUtils
.
getDictLabelByTypeAndValue
(
value
,
dictType
,
value
);
}
catch
(
Exception
e
)
{
throw
e
;
}
return
label
;
}
/* *
* 根据type,label 获取value
* @param propertyLabel
* @param dictType
* @return
* @throws Exception
*/
public
static
String
getDictValueByTypeAndLabel
(
String
propertyLabel
,
String
dictType
)
throws
Exception
{
String
value
=
propertyLabel
;
try
{
value
=
DictUtils
.
getDictValueByTypeAndLabel
(
propertyLabel
,
dictType
,
propertyLabel
);
}
catch
(
Exception
e
)
{
throw
e
;
}
return
value
;
}
}
\ No newline at end of file
zh-baseversion-system/src/main/java/com/zehong/system/domain/TEnterpriseInfo.java
View file @
c5d8d798
...
...
@@ -21,11 +21,14 @@ public class TEnterpriseInfo extends BaseEntity
/**创建企业id*/
private
String
createEnterpriseId
;
/** 企业名称 */
@Excel
(
name
=
"企业名称"
)
private
String
enterpriseName
;
@Excel
(
name
=
"企业分类"
)
@Excel
(
name
=
"企业分类"
,
dictType
=
"enterprise_type"
)
private
Integer
enterpriseType
;
/** 注册地址 */
...
...
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