Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
3203a55b
Commit
3203a55b
authored
Oct 08, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-count-vehicle' into base-modify
parents
bef52e5f
782a04d9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
23 deletions
+39
-23
VehicleCountRecordBiz.java
.../com/xxfc/platform/vehicle/biz/VehicleCountRecordBiz.java
+32
-21
VehicleCountRecordController.java
...c/platform/vehicle/rest/VehicleCountRecordController.java
+7
-2
No files found.
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleCountRecordBiz.java
View file @
3203a55b
...
...
@@ -362,38 +362,49 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
}
}
public
void
export
(
HttpServletResponse
response
,
ExcelParamDto
excelParamDto
)
{
public
String
export
(
ExcelParamDto
excelParamDto
)
{
ExcelExport
ee1
=
new
ExcelExport
();
ee1
.
addSheetByArray
(
excelParamDto
.
getName
(),
excelParamDto
.
getData
(),
excelParamDto
.
getHeader
());
String
fileName
=
"/data/temp/"
+
excelParamDto
.
getName
()
+
".xlsx"
;
OutputStream
fis
;
try
{
fis
=
new
FileOutputStream
(
"/data/temp/"
+
excelParamDto
.
getName
()
+
".xlsx"
);
fis
=
new
FileOutputStream
(
fileName
);
ee1
.
getWorkbook
().
write
(
fis
);
// 下载本地文件
String
fileName
=
excelParamDto
.
getName
()
+
".xlsx"
;
// 文件的默认保存名
// 读到流中
InputStream
inStream
=
new
FileInputStream
(
"/data/temp/"
+
fileName
);
// 文件的存放路径
// 设置输出的格式
response
.
reset
();
response
.
setContentType
(
"bin"
);
response
.
addHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
);
fis
.
flush
();
// 循环取出流中的数据
byte
[]
b
=
new
byte
[
100
];
int
len
;
try
{
while
((
len
=
inStream
.
read
(
b
))
>
0
)
response
.
getOutputStream
().
write
(
b
,
0
,
len
);
inStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
fileName
;
}
public
void
download
(
String
path
,
HttpServletResponse
response
)
{
try
{
// path是指欲下载的文件的路径。
File
file
=
new
File
(
path
);
// 取得文件名。
String
filename
=
file
.
getName
();
// 取得文件的后缀名。
String
ext
=
filename
.
substring
(
filename
.
lastIndexOf
(
"."
)
+
1
).
toUpperCase
();
// 以流的形式下载文件。
InputStream
fis
=
new
BufferedInputStream
(
new
FileInputStream
(
path
));
byte
[]
buffer
=
new
byte
[
fis
.
available
()];
fis
.
read
(
buffer
);
fis
.
close
();
// 清空response
response
.
reset
();
// 设置response的Header
response
.
addHeader
(
"Content-Disposition"
,
"attachment;filename="
+
new
String
(
filename
.
getBytes
()));
response
.
addHeader
(
"Content-Length"
,
""
+
file
.
length
());
OutputStream
toClient
=
new
BufferedOutputStream
(
response
.
getOutputStream
());
response
.
setContentType
(
"application/octet-stream"
);
toClient
.
write
(
buffer
);
toClient
.
flush
();
toClient
.
close
();
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
}
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/rest/VehicleCountRecordController.java
View file @
3203a55b
...
...
@@ -28,8 +28,13 @@ public class VehicleCountRecordController {
}
@PostMapping
(
"/app/unauth/export"
)
public
ObjectRestResponse
export
(
HttpServletResponse
response
,
@RequestBody
ExcelParamDto
excelParamDto
)
{
vehicleCountRecordBiz
.
export
(
response
,
excelParamDto
);
public
ObjectRestResponse
export
(
@RequestBody
ExcelParamDto
excelParamDto
)
{
return
ObjectRestResponse
.
succ
(
vehicleCountRecordBiz
.
export
(
excelParamDto
));
}
@PostMapping
(
"/app/unauth/download"
)
public
ObjectRestResponse
download
(
String
path
,
HttpServletResponse
response
)
{
vehicleCountRecordBiz
.
download
(
path
,
response
);
return
ObjectRestResponse
.
succ
();
}
}
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