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
8da30edd
Commit
8da30edd
authored
Oct 08, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
车辆统计导出bug
parent
7687fc7c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
57 deletions
+33
-57
VehicleCountRecordBiz.java
.../com/xxfc/platform/vehicle/biz/VehicleCountRecordBiz.java
+33
-57
No files found.
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleCountRecordBiz.java
View file @
8da30edd
...
...
@@ -3,6 +3,7 @@ package com.xxfc.platform.vehicle.biz;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.bean.copier.CopyOptions
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.github.wxiaoqi.security.common.exception.BaseException
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.xxfc.platform.order.contant.enumerate.OrderTypeEnum
;
import
com.xxfc.platform.order.entity.OrderRentVehicleDetail
;
...
...
@@ -17,7 +18,6 @@ import com.xxfc.platform.vehicle.mapper.VehicleCountRecordMapper;
import
com.xxfc.platform.vehicle.pojo.ExcelParamDto
;
import
com.xxfc.platform.vehicle.pojo.VehicleBookRecordVo
;
import
com.xxfc.platform.vehicle.util.excel.ExcelExport
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.MapUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.joda.time.DateTime
;
...
...
@@ -28,12 +28,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.math.BigDecimal
;
import
java.net.URLEncoder
;
import
java.sql.Timestamp
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
...
...
@@ -43,7 +40,6 @@ import java.util.stream.Collectors;
* 统计出车,交车数量
*/
@Service
@Slf4j
public
class
VehicleCountRecordBiz
extends
BaseBiz
<
VehicleCountRecordMapper
,
VehicleCountRecord
>
{
public
static
final
DateTimeFormatter
DEFAULT_DATE_TIME_FORMATTER
=
DateTimeFormat
.
forPattern
(
"yyyy-MM-dd"
);
...
...
@@ -367,10 +363,17 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
}
}
public
ObjectRestResponse
export
(
ExcelParamDto
excelParamDto
,
HttpServletRequest
request
)
{
ExcelExport
ee1
=
new
ExcelExport
(
excelParamDto
.
getName
()
+
".xls"
);
public
ObjectRestResponse
export
(
ExcelParamDto
excelParamDto
)
{
ExcelExport
ee1
=
new
ExcelExport
();
ee1
.
addSheetByArray
(
excelParamDto
.
getName
(),
excelParamDto
.
getData
(),
excelParamDto
.
getHeader
());
String
path
=
"/data/temp/"
+
excelParamDto
.
getName
()
+
".xls"
;
Properties
properties
=
System
.
getProperties
();
String
osName
=
properties
.
getProperty
(
"os.name"
);
String
path
=
""
;
if
(
osName
.
contains
(
"Windows"
))
{
path
=
"d://"
+
excelParamDto
.
getName
()
+
".xlsx"
;
}
else
{
path
=
"/data/temp/"
+
excelParamDto
.
getName
()
+
".xlsx"
;
}
File
file
=
new
File
(
path
);
if
(!
file
.
exists
())
{
try
{
...
...
@@ -394,57 +397,30 @@ public class VehicleCountRecordBiz extends BaseBiz<VehicleCountRecordMapper, Veh
return
ObjectRestResponse
.
succ
(
path
);
}
public
void
download
(
String
path
,
HttpServletRequest
req
,
HttpServletResponse
resp
)
{
String
filename
=
"export"
;
DataInputStream
in
=
null
;
OutputStream
out
=
null
;
try
{
resp
.
reset
();
// 清空输出流
String
resultFileName
=
filename
+
System
.
currentTimeMillis
()
+
".xls"
;
resultFileName
=
URLEncoder
.
encode
(
resultFileName
,
"UTF-8"
);
resp
.
setCharacterEncoding
(
"UTF-8"
);
resp
.
setHeader
(
"Content-disposition"
,
"attachment; filename="
+
resultFileName
);
// 设定输出文件头
resp
.
setContentType
(
"application/msexcel"
);
// 定义输出类型
//输入流:本地文件路径
in
=
new
DataInputStream
(
new
FileInputStream
(
new
File
(
path
)));
//输出流
out
=
resp
.
getOutputStream
();
//输出文件
int
bytes
=
0
;
byte
[]
bufferOut
=
new
byte
[
1024
];
while
((
bytes
=
in
.
read
(
bufferOut
))
!=
-
1
)
{
out
.
write
(
bufferOut
,
0
,
bytes
);
}
}
catch
(
Exception
e
){
public
void
download
(
String
path
,
HttpServletResponse
response
){
// 下载本地文件
String
fileName
=
"export.xlsx"
.
toString
();
// 文件的默认保存名
// 读到流中
InputStream
inStream
=
null
;
// 文件的存放路径
try
{
inStream
=
new
FileInputStream
(
path
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
// 设置输出的格式
response
.
reset
();
response
.
setContentType
(
"bin"
);
response
.
addHeader
(
"Content-Disposition"
,
"attachment; filename=\""
+
fileName
+
"\""
);
// 循环取出流中的数据
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
();
resp
.
reset
();
try
{
OutputStreamWriter
writer
=
new
OutputStreamWriter
(
resp
.
getOutputStream
(),
"UTF-8"
);
String
data
=
"<script language='javascript'>alert(\"\\u64cd\\u4f5c\\u5f02\\u5e38\\uff01\");</script>"
;
writer
.
write
(
data
);
writer
.
close
();
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
}
finally
{
if
(
null
!=
in
)
{
try
{
in
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
null
!=
out
)
{
try
{
out
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
...
...
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