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
e33dc72d
Commit
e33dc72d
authored
Jun 30, 2022
by
fudahua
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'developer' into 'master'
Developer See merge request
!51
parents
b6f06a15
8236f0bd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
29 deletions
+114
-29
ExcelUtil.java
.../main/java/com/gic/cloud/data/hook/service/ExcelUtil.java
+27
-0
CsvResultSetHelper.java
...ic/cloud/data/hook/service/entity/CsvResultSetHelper.java
+9
-9
FlatQueryResultServiceImpl.java
...ud/data/hook/service/impl/FlatQueryResultServiceImpl.java
+78
-20
No files found.
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/ExcelUtil.java
0 → 100644
View file @
e33dc72d
package
com
.
gic
.
cloud
.
data
.
hook
.
service
;
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.CellStyle
;
import
java.util.Map
;
public
class
ExcelUtil
{
public
static
HSSFCellStyle
getCellStyle
(
int
type
){
//时间日期
if
(
type
==
0
)
{
HSSFWorkbook
demoWorkBook
=
new
HSSFWorkbook
();
HSSFCellStyle
dateStyle
=
demoWorkBook
.
createCellStyle
();
HSSFDataFormat
format
=
demoWorkBook
.
createDataFormat
();
dateStyle
.
setDataFormat
(
format
.
getFormat
(
"yyyy-MM-dd HH:mm:ss"
));
return
dateStyle
;
}
else
if
(
type
==
1
)
{
}
else
if
(
type
==
2
)
{
}
return
null
;
}
}
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/entity/CsvResultSetHelper.java
View file @
e33dc72d
...
...
@@ -214,15 +214,15 @@ public class CsvResultSetHelper implements ResultSetHelper {
break
;
default
:
String
s2
=
String
.
valueOf
(
resultSet
.
getObject
(
i
+
1
));
if
(
org
.
apache
.
commons
.
lang3
.
StringUtils
.
isNotBlank
(
s2
)){
if
(
s2
.
contains
(
"E0"
)
||
s2
.
startsWith
(
"0"
)){
s2
=
s2
+
"\t"
;
}
s2
=
s2
.
replace
(
"\r"
,
""
);
s2
=
s2
.
replace
(
"\n"
,
""
);
s2
=
s2
.
replace
(
","
,
","
);
s2
=
s2
.
replace
(
"\""
,
""
);
}
//
if(org.apache.commons.lang3.StringUtils.isNotBlank(s2)){
//
if(s2.contains("E0") || s2.startsWith("0")){
//
s2 = s2 + "\t";
//
}
//
s2=s2.replace("\r","");
//
s2=s2.replace("\n","");
//
s2=s2.replace(",",",");
//
s2=s2.replace("\"","");
//
}
result
.
add
(
s2
);
break
;
}
// SWITCH OVER
...
...
gic-cloud-data-hook-service/src/main/java/com/gic/cloud/data/hook/service/impl/FlatQueryResultServiceImpl.java
View file @
e33dc72d
...
...
@@ -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,44 @@ 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.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.apache.hadoop.hive.metastore.api.Decimal
;
import
org.apache.poi.hssf.usermodel.HSSFCell
;
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.*
;
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.DecimalFormat
;
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 +967,24 @@ 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
);
logger
.
info
(
"类型:{}"
,
JSONObject
.
toJSONString
(
columnMate
));
for
(
int
j
=
0
;
j
<
columnMate
.
size
();
j
++){
cell
=
row
.
createCell
(
j
);
cell
.
setCellValue
(
column
Names
[
j
]
);
cell
.
setCellValue
(
column
Mate
.
get
(
j
).
getKey
()
);
}
//日期
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
())
{
...
...
@@ -981,7 +992,34 @@ 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
);
String
columnValue
=
columnValues
[
j
];
switch
(
type
)
{
case
Types
.
DATE
:
midCell
.
setCellStyle
(
yyyyMMdd
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
columnValue
,
new
String
[]{
"yyyy-MM-dd"
}));
break
;
case
Types
.
TIMESTAMP
:
midCell
.
setCellStyle
(
yyyyMMddhhmmss
);
midCell
.
setCellValue
(
DateUtils
.
parseDate
(
columnValue
,
new
String
[]{
"yyyy-MM-dd hh:mm:ss"
}));
break
;
case
Types
.
INTEGER
:
midCell
.
setCellValue
(
Integer
.
valueOf
(
columnValue
));
break
;
case
Types
.
BIGINT
:
midCell
.
setCellValue
(
Long
.
valueOf
(
columnValue
));
break
;
case
Types
.
DOUBLE
:
case
Types
.
DECIMAL
:
midCell
.
setCellValue
(
Double
.
valueOf
(
columnValue
));
break
;
case
Types
.
FLOAT
:
midCell
.
setCellValue
(
Float
.
valueOf
(
columnValue
));
break
;
default
:
midCell
.
setCellValue
(
columnValues
[
j
]);
}
}
}
// WHILE OVER
FileOutputStream
fileOut
=
new
FileOutputStream
(
originalFilePath
);
...
...
@@ -998,6 +1036,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