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
1986ca18
Commit
1986ca18
authored
Jun 22, 2022
by
fudahua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:自定义查询zip测试
parent
7a5a41ce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
17 deletions
+49
-17
FlatQueryResultServiceImpl.java
...ud/data/hook/service/impl/FlatQueryResultServiceImpl.java
+49
-17
No files found.
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/impl/FlatQueryResultServiceImpl.java
View file @
1986ca18
...
...
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSON;
import
com.alibaba.fastjson.JSONObject
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.gic.cloud.common.api.base.Page
;
import
com.gic.cloud.data.hook.api.dto.*
;
import
com.gic.cloud.data.hook.api.entity.*
;
import
com.gic.cloud.data.hook.api.service.DecryptKeyService
;
...
...
@@ -15,45 +14,43 @@ import com.gic.cloud.data.hook.service.*;
import
com.gic.cloud.data.hook.service.dao.FlatQueryTableDao
;
import
com.gic.cloud.data.hook.service.entity.CsvDataFilterMode
;
import
com.gic.cloud.data.hook.service.entity.CsvResultSetHelper
;
import
com.gic.dubbo.entity.ProviderLocalTag
;
import
com.gic.qcloud.BucketNameEnum
;
import
com.gic.qcloud.FileUploadUtil
;
import
com.google.common.collect.Lists
;
import
com.opencsv.CSVWriter
;
import
com.opencsv.ResultSetHelper
;
import
io.netty.handler.codec.http.HttpUtil
;
import
javafx.scene.chart.PieChart
;
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.commons.lang3.tuple.Pair
;
import
org.apache.poi.hssf.usermodel.HSSFCellStyle
;
import
org.apache.poi.hssf.usermodel.HSSFDataFormat
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
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.xssf.streaming.SXSSFWorkbook
;
import
org.datanucleus.store.rdbms.datasource.dbcp.SQLNestedException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
javax.sql.DataSource
;
import
java.io.*
;
import
java.math.BigDecimal
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.nio.charset.Charset
;
import
java.sql.*
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipOutputStream
;
/** 自助指标查询服务实现
* @author Sam
...
...
@@ -969,11 +966,18 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
Sheet
sheet
=
wb
.
createSheet
();
Row
row
=
sheet
.
createRow
(
0
);
Cell
cell
;
String
[]
columnNames
=
helper
.
getColumnNames
(
rs
);
for
(
int
j
=
0
;
j
<
columnNames
.
length
;
j
++){
// String[] columnNames = helper.getColumnNames(rs);
List
<
Pair
<
String
,
Integer
>>
columnMate
=
getColumnMate
(
rs
);
for
(
int
j
=
0
;
j
<
columnMate
.
size
();
j
++){
cell
=
row
.
createCell
(
j
);
cell
.
setCellValue
(
column
Names
[
j
]
);
cell
.
setCellValue
(
column
Mate
.
get
(
j
).
getKey
()
);
}
HSSFWorkbook
demoWorkBook
=
new
HSSFWorkbook
();
HSSFCellStyle
dateStyle
=
demoWorkBook
.
createCellStyle
();
HSSFDataFormat
format
=
demoWorkBook
.
createDataFormat
();
dateStyle
.
setDataFormat
(
format
.
getFormat
(
"yyyy-MM-dd HH:mm:ss"
));
// 遍历输出行
int
rowCount
=
0
;
while
(
rowCount
<
limitSize
&&
rs
.
next
())
{
...
...
@@ -981,7 +985,15 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
row
=
sheet
.
createRow
(
rowCount
);
String
[]
columnValues
=
helper
.
getColumnValues
(
rs
,
true
,
""
,
""
);
for
(
int
j
=
0
;
j
<
columnValues
.
length
;
j
++){
row
.
createCell
(
j
).
setCellValue
(
columnValues
[
j
]);
Integer
type
=
columnMate
.
get
(
j
).
getValue
();
Cell
midCell
=
row
.
createCell
(
j
);
switch
(
type
)
{
case
Types
.
DATE
:
case
Types
.
TIMESTAMP
:
case
Types
.
TIME
:
midCell
.
setCellStyle
(
dateStyle
);
}
midCell
.
setCellValue
(
columnValues
[
j
]);
}
}
// WHILE OVER
FileOutputStream
fileOut
=
new
FileOutputStream
(
originalFilePath
);
...
...
@@ -998,6 +1010,26 @@ public class FlatQueryResultServiceImpl implements IFlatQueryResultService {
}
/**
* 字段类型
* @param resultSet
* @return
* @throws SQLException
*/
private
List
<
Pair
<
String
,
Integer
>>
getColumnMate
(
ResultSet
resultSet
)
throws
SQLException
{
List
<
Pair
<
String
,
Integer
>>
retList
=
new
ArrayList
<>();
int
columnCount
=
resultSet
.
getMetaData
().
getColumnCount
();
if
(
columnCount
>
0
)
{
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
String
rsColumnName
=
resultSet
.
getMetaData
().
getColumnLabel
(
i
+
1
);
int
columnType
=
resultSet
.
getMetaData
().
getColumnType
(
i
+
1
);
retList
.
add
(
Pair
.
of
(
rsColumnName
,
Integer
.
valueOf
(
columnType
)));
}
}
return
retList
;
}
/** 下载申请检查计时器 */
//private Timer applyTimer = new Timer();
...
...
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