Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
yifu-mvp
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
fangxinjiang
yifu-mvp
Commits
06afdd10
Commit
06afdd10
authored
Jul 24, 2025
by
fangxinjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化-IO异常处理优化-fxj
parent
a30e3090
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
43 deletions
+42
-43
TDispatchInfoServiceImpl.java
...v1/yifu/social/service/impl/TDispatchInfoServiceImpl.java
+42
-43
No files found.
yifu-social/yifu-social-biz/src/main/java/com/yifu/cloud/plus/v1/yifu/social/service/impl/TDispatchInfoServiceImpl.java
View file @
06afdd10
...
@@ -200,10 +200,9 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
...
@@ -200,10 +200,9 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
//获取要导出的列表
//获取要导出的列表
List
<
TDispatchInfoExportVo
>
list
=
new
ArrayList
<>();
List
<
TDispatchInfoExportVo
>
list
=
new
ArrayList
<>();
long
count
=
noPageCountDiy
(
searchVo
);
long
count
=
noPageCountDiy
(
searchVo
);
ServletOutputStream
out
=
null
;
HashMap
<
String
,
String
>
userMap
=
new
HashMap
<>();
HashMap
<
String
,
String
>
userMap
=
new
HashMap
<>();
ExcelWriter
excelWriter
=
null
;
try
{
try
{
// 获取用户信息
R
<
AllUserNaVo
>
userListR
=
upmsDaprUtils
.
getAllUserName
();
R
<
AllUserNaVo
>
userListR
=
upmsDaprUtils
.
getAllUserName
();
if
(
Common
.
isNotNull
(
userListR
))
{
if
(
Common
.
isNotNull
(
userListR
))
{
AllUserNaVo
userList
=
userListR
.
getData
();
AllUserNaVo
userList
=
userListR
.
getData
();
...
@@ -211,26 +210,28 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
...
@@ -211,26 +210,28 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
userMap
=
userList
.
getUserNames
();
userMap
=
userList
.
getUserNames
();
}
}
}
}
out
=
response
.
getOutputStream
();
// 设置响应头
response
.
setContentType
(
CommonConstants
.
MULTIPART_FORM_DATA
);
response
.
setContentType
(
CommonConstants
.
MULTIPART_FORM_DATA
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setHeader
(
CommonConstants
.
CONTENT_DISPOSITION
,
CommonConstants
.
ATTACHMENT_FILENAME
+
URLEncoder
.
encode
(
fileName
,
"UTF-8"
));
response
.
setHeader
(
CommonConstants
.
CONTENT_DISPOSITION
,
CommonConstants
.
ATTACHMENT_FILENAME
+
URLEncoder
.
encode
(
fileName
,
"UTF-8"
));
//
这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
//
初始化Excel工具
ExcelUtil
<
TDispatchInfoExportVo
>
util
=
new
ExcelUtil
<>(
TDispatchInfoExportVo
.
class
);
ExcelUtil
<
TDispatchInfoExportVo
>
util
=
new
ExcelUtil
<>(
TDispatchInfoExportVo
.
class
);
// 获取所有字典type
Map
<
String
,
String
>
nameAndDicTypeMap
=
util
.
getConverterDicType
();
Map
<
String
,
String
>
nameAndDicTypeMap
=
util
.
getConverterDicType
();
// 获取所有字典对应的值
Map
<
String
,
String
>
redisLabelMap
=
(
Map
<
String
,
String
>)
RedisUtil
.
redis
.
opsForValue
().
get
(
CacheConstants
.
REDIS_DICT_LABLE
);
Map
<
String
,
String
>
redisLabelMap
=
(
Map
<
String
,
String
>)
RedisUtil
.
redis
.
opsForValue
().
get
(
CacheConstants
.
REDIS_DICT_LABLE
);
if
(
redisLabelMap
!=
null
)
{
redisLabelMap
.
putAll
(
userMap
);
redisLabelMap
.
putAll
(
userMap
);
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,然后文件流会自动关闭
}
excelWriter
=
EasyExcel
.
write
(
out
,
TDispatchInfoExportVo
.
class
)
// 使用 try-with-resources 确保输出流正确关闭
try
(
ServletOutputStream
out
=
response
.
getOutputStream
())
{
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
out
,
TDispatchInfoExportVo
.
class
)
.
registerConverter
(
new
DictConverter
(
nameAndDicTypeMap
,
redisLabelMap
))
.
registerConverter
(
new
DictConverter
(
nameAndDicTypeMap
,
redisLabelMap
))
.
includeColumnFieldNames
(
searchVo
.
getExportFields
()).
build
();
.
includeColumnFieldNames
(
searchVo
.
getExportFields
())
.
build
();
int
index
=
0
;
int
index
=
0
;
if
(
count
>
CommonConstants
.
ZERO_INT
)
{
if
(
count
>
CommonConstants
.
ZERO_INT
)
{
WriteSheet
writeSheet
;
WriteSheet
writeSheet
;
for
(
int
i
=
0
;
i
<=
count
;
)
{
for
(
int
i
=
0
;
i
<=
count
;
)
{
// 获取实际记录
searchVo
.
setLimitStart
(
i
);
searchVo
.
setLimitStart
(
i
);
searchVo
.
setLimitEnd
(
CommonConstants
.
EXCEL_EXPORT_LIMIT
);
searchVo
.
setLimitEnd
(
CommonConstants
.
EXCEL_EXPORT_LIMIT
);
list
=
exportDispatch
(
searchVo
);
list
=
exportDispatch
(
searchVo
);
...
@@ -248,22 +249,20 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
...
@@ -248,22 +249,20 @@ public class TDispatchInfoServiceImpl extends ServiceImpl<TDispatchInfoMapper, T
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
(
"派单"
+
index
).
build
();
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
(
"派单"
+
index
).
build
();
excelWriter
.
write
(
list
,
writeSheet
);
excelWriter
.
write
(
list
,
writeSheet
);
}
}
if
(
Common
.
isNotNull
(
list
))
{
list
.
clear
();
}
out
.
flush
();
if
(
null
!=
excelWriter
)
{
excelWriter
.
finish
();
excelWriter
.
finish
();
out
.
flush
();
}
}
}
catch
(
IOException
e
)
{
log
.
error
(
"导出文件时发生IO异常"
,
e
);
throw
new
RuntimeException
(
"导出文件失败"
,
e
);
// 可以根据需要转换为业务异常
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"执行异常"
,
e
);
log
.
error
(
"执行导出时发生未知异常"
,
e
);
throw
new
RuntimeException
(
"导出过程中发生错误"
,
e
);
}
finally
{
}
finally
{
try
{
// 清理列表数据
if
(
null
!=
out
)
{
if
(
Common
.
isNotNull
(
list
))
{
out
.
close
();
list
.
clear
();
}
}
catch
(
IOException
e
)
{
log
.
error
(
"执行异常"
,
e
);
}
}
}
}
}
}
...
...
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