Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-cloud
Overview
Overview
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
data-hook
gic-cloud
Commits
05f55c28
Commit
05f55c28
authored
Jun 30, 2022
by
fudahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:时间格式
parent
8236f0bd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
6 deletions
+64
-6
FreeQueryServiceImpl.java
...ic/cloud/data/hook/service/impl/FreeQueryServiceImpl.java
+64
-6
No files found.
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/impl/FreeQueryServiceImpl.java
View file @
05f55c28
...
...
@@ -20,11 +20,10 @@ import com.google.common.collect.Lists;
import
com.opencsv.CSVWriter
;
import
com.opencsv.ResultSetHelper
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang.time.DateUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.concurrent.BasicThreadFactory
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -604,6 +603,18 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
cell
=
row
.
createCell
(
j
);
cell
.
setCellValue
(
colName
);
}
//日期
CellStyle
yyyyMMddhhmmss
=
wb
.
createCellStyle
();
DataFormat
dataFormat
=
wb
.
createDataFormat
();
yyyyMMddhhmmss
.
setDataFormat
(
dataFormat
.
getFormat
(
"yyyy-MM-dd HH:mm:ss"
));
//日期
CellStyle
yyyyMMdd
=
wb
.
createCellStyle
();
DataFormat
yyyyMMddDataFormat
=
wb
.
createDataFormat
();
yyyyMMdd
.
setDataFormat
(
yyyyMMddDataFormat
.
getFormat
(
"yyyy-MM-dd"
));
// 遍历输出行
int
rowCount
=
0
;
while
(
rowCount
<
limitSize
&&
rs
.
next
())
{
...
...
@@ -622,15 +633,62 @@ public class FreeQueryServiceImpl implements IFreeQueryService {
}
}
else
{
int
cType
=
rs
.
getMetaData
().
getColumnType
(
j
+
1
);
Cell
midCell
=
row
.
createCell
(
j
);
switch
(
cType
)
{
case
Types
.
TIMESTAMP
:
row
.
createCell
(
j
).
setCellValue
(
rs
.
getTimestamp
(
j
+
1
)
!=
null
?
datetimeFormatter
.
format
(
rs
.
getTimestamp
(
j
+
1
))
:
""
);
String
s
=
rs
.
getTimestamp
(
j
+
1
)
!=
null
?
datetimeFormatter
.
format
(
rs
.
getTimestamp
(
j
+
1
))
:
""
;
if
(
StringUtils
.
isBlank
(
s
))
{
midCell
.
setCellValue
(
s
);
}
else
{
midCell
.
setCellStyle
(
yyyyMMddhhmmss
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
s
,
new
String
[]{
"yyyy-MM-dd hh:mm:ss"
}));
}
break
;
case
Types
.
DATE
:
row
.
createCell
(
j
).
setCellValue
(
rs
.
getDate
(
j
+
1
)
!=
null
?
dateFormatter
.
format
(
rs
.
getDate
(
j
+
1
))
:
""
);
String
mid
=
rs
.
getDate
(
j
+
1
)
!=
null
?
dateFormatter
.
format
(
rs
.
getDate
(
j
+
1
))
:
""
;
if
(
StringUtils
.
isBlank
(
mid
))
{
midCell
.
setCellValue
(
mid
);
}
else
{
midCell
.
setCellStyle
(
yyyyMMdd
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
mid
,
new
String
[]{
"yyyy-MM-dd"
}));
}
break
;
case
Types
.
TIME
:
row
.
createCell
(
j
).
setCellValue
(
rs
.
getTimestamp
(
j
+
1
)
!=
null
?
timeFormatter
.
format
(
rs
.
getTimestamp
(
j
+
1
))
:
""
);
String
timeStr
=
rs
.
getTimestamp
(
j
+
1
)
!=
null
?
timeFormatter
.
format
(
rs
.
getTimestamp
(
j
+
1
))
:
""
;
midCell
.
setCellValue
(
timeStr
);
break
;
case
Types
.
INTEGER
:
String
intStr
=
rs
.
getString
(
j
+
1
);
if
(
StringUtils
.
isBlank
(
intStr
)){
midCell
.
setCellValue
(
0
);
}
else
{
midCell
.
setCellValue
(
Integer
.
valueOf
(
intStr
));
}
break
;
case
Types
.
BIGINT
:
String
bigintStr
=
rs
.
getString
(
j
+
1
);
if
(
StringUtils
.
isBlank
(
bigintStr
)){
midCell
.
setCellValue
(
0
);
}
else
{
midCell
.
setCellValue
(
Long
.
valueOf
(
bigintStr
));
}
break
;
case
Types
.
DOUBLE
:
case
Types
.
DECIMAL
:
String
doubleStr
=
rs
.
getString
(
j
+
1
);
if
(
StringUtils
.
isBlank
(
doubleStr
))
{
midCell
.
setCellValue
(
0
);
}
else
{
midCell
.
setCellValue
(
Double
.
valueOf
(
doubleStr
));
}
break
;
case
Types
.
FLOAT
:
String
floatStr
=
rs
.
getString
(
j
+
1
);
if
(
StringUtils
.
isBlank
(
floatStr
))
{
midCell
.
setCellValue
(
0
);
}
else
{
midCell
.
setCellValue
(
Float
.
valueOf
(
floatStr
));
}
break
;
default
:
String
string
=
rs
.
getString
(
j
+
1
);
...
...
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